fix: stop click when dragging over notebook buttons (#6266)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
+1
-1
@@ -55,7 +55,7 @@
|
|||||||
- Dev: Simplified string literals to be a re-export of Qt functions. (#6175)
|
- Dev: Simplified string literals to be a re-export of Qt functions. (#6175)
|
||||||
- Dev: Fixed incorrect lua generation of static methods for typescript plugins. (#6190, #6223)
|
- Dev: Fixed incorrect lua generation of static methods for typescript plugins. (#6190, #6223)
|
||||||
- Dev: Merged top/bottom and left/right notebook layouts. (#6215)
|
- Dev: Merged top/bottom and left/right notebook layouts. (#6215)
|
||||||
- Dev: Refactored `Button` and friends. (#6102, #6255)
|
- Dev: Refactored `Button` and friends. (#6102, #6255, #6266)
|
||||||
- Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267)
|
- Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267)
|
||||||
- Dev: `OnceFlag`'s internal flag is now atomic. (#6237)
|
- Dev: `OnceFlag`'s internal flag is now atomic. (#6237)
|
||||||
- Dev: Bumped clang-format requirement to 19. (#6236)
|
- Dev: Bumped clang-format requirement to 19. (#6236)
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ namespace chatterino {
|
|||||||
|
|
||||||
Notebook::Notebook(QWidget *parent)
|
Notebook::Notebook(QWidget *parent)
|
||||||
: BaseWidget(parent)
|
: BaseWidget(parent)
|
||||||
, addButton_(new NotebookButton(this))
|
, addButton_(new NotebookButton(NotebookButton::Type::Plus, this))
|
||||||
{
|
{
|
||||||
this->addButton_->setIcon(NotebookButton::Icon::Plus);
|
|
||||||
|
|
||||||
this->addButton_->setHidden(true);
|
this->addButton_->setHidden(true);
|
||||||
|
|
||||||
this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this);
|
this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this);
|
||||||
@@ -1298,7 +1296,7 @@ SplitNotebook::SplitNotebook(Window *parent)
|
|||||||
getSettings()->tabVisibility.connect(
|
getSettings()->tabVisibility.connect(
|
||||||
[this](int val, auto) {
|
[this](int val, auto) {
|
||||||
auto visibility = NotebookTabVisibility(val);
|
auto visibility = NotebookTabVisibility(val);
|
||||||
// Set the correct TabVisibilityFilter for the given visiblity setting.
|
// Set the correct TabVisibilityFilter for the given visibility setting.
|
||||||
// Note that selected tabs are always shown regardless of what the tab
|
// Note that selected tabs are always shown regardless of what the tab
|
||||||
// filter returns, so no need to include `tab->isSelected()` in the
|
// filter returns, so no need to include `tab->isSelected()` in the
|
||||||
// predicate. See Notebook::setTabVisibilityFilter.
|
// predicate. See Notebook::setTabVisibilityFilter.
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ void Button::mousePressEvent(QMouseEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->clickEffects_.emplace_back(event->pos());
|
this->addClickEffect(event->pos());
|
||||||
|
|
||||||
this->mouseDown_ = true;
|
this->mouseDown_ = true;
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ void Button::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void Button::mouseReleaseEvent(QMouseEvent *event)
|
void Button::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!this->enabled_)
|
if (!this->enabled_ || !this->mouseDown_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -223,6 +223,11 @@ void Button::mouseMoveEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Button::addClickEffect(QPoint position)
|
||||||
|
{
|
||||||
|
this->clickEffects_.emplace_back(position);
|
||||||
|
}
|
||||||
|
|
||||||
void Button::onMouseEffectTimeout()
|
void Button::onMouseEffectTimeout()
|
||||||
{
|
{
|
||||||
bool performUpdate = false;
|
bool performUpdate = false;
|
||||||
|
|||||||
@@ -180,6 +180,9 @@ protected:
|
|||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
|
/// Queue up the click animation at the given position
|
||||||
|
void addClickEffect(QPoint position);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onMouseEffectTimeout();
|
void onMouseEffectTimeout();
|
||||||
void showMenu();
|
void showMenu();
|
||||||
|
|||||||
@@ -16,23 +16,18 @@
|
|||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
NotebookButton::NotebookButton(Notebook *parent)
|
NotebookButton::NotebookButton(Type type_, Notebook *parent)
|
||||||
: Button(parent)
|
: Button(parent)
|
||||||
, parent_(parent)
|
, parent_(parent)
|
||||||
|
, type(type_)
|
||||||
{
|
{
|
||||||
this->setAcceptDrops(true);
|
switch (this->type)
|
||||||
}
|
{
|
||||||
|
case Type::Plus: {
|
||||||
void NotebookButton::setIcon(Icon icon)
|
this->setAcceptDrops(true);
|
||||||
{
|
}
|
||||||
this->icon_ = icon;
|
break;
|
||||||
|
}
|
||||||
this->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
NotebookButton::Icon NotebookButton::getIcon() const
|
|
||||||
{
|
|
||||||
return this->icon_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotebookButton::themeChangedEvent()
|
void NotebookButton::themeChangedEvent()
|
||||||
@@ -60,9 +55,9 @@ void NotebookButton::paintContent(QPainter &painter)
|
|||||||
|
|
||||||
float h = height(), w = width();
|
float h = height(), w = width();
|
||||||
|
|
||||||
switch (icon_)
|
switch (this->type)
|
||||||
{
|
{
|
||||||
case Plus: {
|
case Type::Plus: {
|
||||||
painter.setPen([&] {
|
painter.setPen([&] {
|
||||||
QColor tmp = foreground;
|
QColor tmp = foreground;
|
||||||
if (isDraggingSplit())
|
if (isDraggingSplit())
|
||||||
@@ -88,13 +83,16 @@ void NotebookButton::paintContent(QPainter &painter)
|
|||||||
rect.top() + rect.height() / 2 + (s / 2));
|
rect.top() + rect.height() / 2 + (s / 2));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
|
void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
|
||||||
{
|
{
|
||||||
|
if (this->type != Type::Plus)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!event->mimeData()->hasFormat("chatterino/split"))
|
if (!event->mimeData()->hasFormat("chatterino/split"))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -102,28 +100,19 @@ void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
|
|||||||
|
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
|
|
||||||
auto *e =
|
this->addClickEffect(QPoint{
|
||||||
new QMouseEvent(QMouseEvent::MouseButtonPress,
|
this->width() / 2,
|
||||||
QPointF(this->width() / 2, this->height() / 2),
|
this->height() / 2,
|
||||||
QCursor::pos(), Qt::LeftButton, Qt::LeftButton, {});
|
});
|
||||||
Button::mousePressEvent(e);
|
|
||||||
delete e;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::dragLeaveEvent(QDragLeaveEvent *)
|
|
||||||
{
|
|
||||||
this->update();
|
|
||||||
|
|
||||||
auto *e =
|
|
||||||
new QMouseEvent(QMouseEvent::MouseButtonRelease,
|
|
||||||
QPointF(this->width() / 2, this->height() / 2),
|
|
||||||
QCursor::pos(), Qt::LeftButton, Qt::LeftButton, {});
|
|
||||||
Button::mouseReleaseEvent(e);
|
|
||||||
delete e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotebookButton::dropEvent(QDropEvent *event)
|
void NotebookButton::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
|
if (this->type != Type::Plus)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto *draggedSplit = dynamic_cast<Split *>(event->source());
|
auto *draggedSplit = dynamic_cast<Split *>(event->source());
|
||||||
if (!draggedSplit)
|
if (!draggedSplit)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,22 +13,17 @@ class NotebookButton : public Button
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Icon {
|
enum class Type : std::uint8_t {
|
||||||
None,
|
|
||||||
Plus,
|
Plus,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit NotebookButton(Notebook *parent);
|
NotebookButton(Type type_, Notebook *parent);
|
||||||
|
|
||||||
void setIcon(Icon icon);
|
|
||||||
Icon getIcon() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintContent(QPainter &painter) override;
|
void paintContent(QPainter &painter) override;
|
||||||
|
|
||||||
void themeChangedEvent() override;
|
void themeChangedEvent() override;
|
||||||
void dragEnterEvent(QDragEnterEvent *) override;
|
void dragEnterEvent(QDragEnterEvent *) override;
|
||||||
void dragLeaveEvent(QDragLeaveEvent *) override;
|
|
||||||
void dropEvent(QDropEvent *) override;
|
void dropEvent(QDropEvent *) override;
|
||||||
|
|
||||||
void hideEvent(QHideEvent *) override;
|
void hideEvent(QHideEvent *) override;
|
||||||
@@ -37,7 +32,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
Notebook *parent_ = nullptr;
|
Notebook *parent_ = nullptr;
|
||||||
QPoint mousePos_;
|
QPoint mousePos_;
|
||||||
Icon icon_ = None;
|
Type type = Type::Plus;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
Reference in New Issue
Block a user