fix: stop click when dragging over notebook buttons (#6266)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2025-06-15 13:00:57 +02:00
committed by GitHub
parent 62c93d1d98
commit 04ba83b90f
6 changed files with 41 additions and 51 deletions
+1 -1
View File
@@ -55,7 +55,7 @@
- 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: 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: `OnceFlag`'s internal flag is now atomic. (#6237)
- Dev: Bumped clang-format requirement to 19. (#6236)
+2 -4
View File
@@ -38,10 +38,8 @@ namespace chatterino {
Notebook::Notebook(QWidget *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->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this);
@@ -1298,7 +1296,7 @@ SplitNotebook::SplitNotebook(Window *parent)
getSettings()->tabVisibility.connect(
[this](int val, auto) {
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
// filter returns, so no need to include `tab->isSelected()` in the
// predicate. See Notebook::setTabVisibilityFilter.
+7 -2
View File
@@ -172,7 +172,7 @@ void Button::mousePressEvent(QMouseEvent *event)
return;
}
this->clickEffects_.emplace_back(event->pos());
this->addClickEffect(event->pos());
this->mouseDown_ = true;
@@ -190,7 +190,7 @@ void Button::mousePressEvent(QMouseEvent *event)
void Button::mouseReleaseEvent(QMouseEvent *event)
{
if (!this->enabled_)
if (!this->enabled_ || !this->mouseDown_)
{
return;
}
@@ -223,6 +223,11 @@ void Button::mouseMoveEvent(QMouseEvent *event)
}
}
void Button::addClickEffect(QPoint position)
{
this->clickEffects_.emplace_back(position);
}
void Button::onMouseEffectTimeout()
{
bool performUpdate = false;
+3
View File
@@ -180,6 +180,9 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
/// Queue up the click animation at the given position
void addClickEffect(QPoint position);
private:
void onMouseEffectTimeout();
void showMenu();
+25 -36
View File
@@ -16,23 +16,18 @@
namespace chatterino {
NotebookButton::NotebookButton(Notebook *parent)
NotebookButton::NotebookButton(Type type_, Notebook *parent)
: Button(parent)
, parent_(parent)
, type(type_)
{
this->setAcceptDrops(true);
}
void NotebookButton::setIcon(Icon icon)
{
this->icon_ = icon;
this->update();
}
NotebookButton::Icon NotebookButton::getIcon() const
{
return this->icon_;
switch (this->type)
{
case Type::Plus: {
this->setAcceptDrops(true);
}
break;
}
}
void NotebookButton::themeChangedEvent()
@@ -60,9 +55,9 @@ void NotebookButton::paintContent(QPainter &painter)
float h = height(), w = width();
switch (icon_)
switch (this->type)
{
case Plus: {
case Type::Plus: {
painter.setPen([&] {
QColor tmp = foreground;
if (isDraggingSplit())
@@ -88,13 +83,16 @@ void NotebookButton::paintContent(QPainter &painter)
rect.top() + rect.height() / 2 + (s / 2));
}
break;
default:;
}
}
void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
{
if (this->type != Type::Plus)
{
return;
}
if (!event->mimeData()->hasFormat("chatterino/split"))
{
return;
@@ -102,28 +100,19 @@ void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
event->acceptProposedAction();
auto *e =
new QMouseEvent(QMouseEvent::MouseButtonPress,
QPointF(this->width() / 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;
this->addClickEffect(QPoint{
this->width() / 2,
this->height() / 2,
});
}
void NotebookButton::dropEvent(QDropEvent *event)
{
if (this->type != Type::Plus)
{
return;
}
auto *draggedSplit = dynamic_cast<Split *>(event->source());
if (!draggedSplit)
{
+3 -8
View File
@@ -13,22 +13,17 @@ class NotebookButton : public Button
Q_OBJECT
public:
enum Icon {
None,
enum class Type : std::uint8_t {
Plus,
};
explicit NotebookButton(Notebook *parent);
void setIcon(Icon icon);
Icon getIcon() const;
NotebookButton(Type type_, Notebook *parent);
protected:
void paintContent(QPainter &painter) override;
void themeChangedEvent() override;
void dragEnterEvent(QDragEnterEvent *) override;
void dragLeaveEvent(QDragLeaveEvent *) override;
void dropEvent(QDropEvent *) override;
void hideEvent(QHideEvent *) override;
@@ -37,7 +32,7 @@ protected:
private:
Notebook *parent_ = nullptr;
QPoint mousePos_;
Icon icon_ = None;
Type type = Type::Plus;
};
} // namespace chatterino