fix: middle & right click buttons not working on Button class (#6302)
This commit is contained in:
+1
-1
@@ -60,7 +60,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, #6266)
|
- Dev: Refactored `Button` and friends. (#6102, #6255, #6266, #6302)
|
||||||
- Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267)
|
- Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267)
|
||||||
- Dev: Emoji style / set is now stored lowercase (and matched case-insensitively). Changing emoji style from this point on and then running an old version might mean you will use the Twitter emoji style by default. (#6300)
|
- Dev: Emoji style / set is now stored lowercase (and matched case-insensitively). Changing emoji style from this point on and then running an old version might mean you will use the Twitter emoji style by default. (#6300)
|
||||||
- Dev: `OnceFlag`'s internal flag is now atomic. (#6237)
|
- Dev: `OnceFlag`'s internal flag is now atomic. (#6237)
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ bool Button::mouseOver() const noexcept
|
|||||||
return this->mouseOver_;
|
return this->mouseOver_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Button::mouseDown() const noexcept
|
bool Button::leftMouseButtonDown() const noexcept
|
||||||
{
|
{
|
||||||
return this->mouseDown_;
|
return this->leftMouseButtonDown_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Button::menuVisible() const noexcept
|
bool Button::menuVisible() const noexcept
|
||||||
@@ -167,48 +167,82 @@ void Button::mousePressEvent(QMouseEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->button() != Qt::LeftButton)
|
switch (event->button())
|
||||||
{
|
{
|
||||||
return;
|
case Qt::MouseButton::LeftButton: {
|
||||||
}
|
this->leftMouseButtonDown_ = true;
|
||||||
|
|
||||||
this->addClickEffect(event->pos());
|
this->addClickEffect(event->pos());
|
||||||
|
|
||||||
this->mouseDown_ = true;
|
this->leftMousePress();
|
||||||
|
|
||||||
this->leftMousePress();
|
if (this->menu_ && !this->menuVisible_)
|
||||||
|
{
|
||||||
|
QTimer::singleShot(80, this, [this] {
|
||||||
|
this->showMenu();
|
||||||
|
});
|
||||||
|
this->leftMouseButtonDown_ = false;
|
||||||
|
this->mouseOver_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Qt::MouseButton::RightButton: {
|
||||||
|
this->rightMouseButtonDown_ = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Qt::MouseButton::MiddleButton: {
|
||||||
|
this->middleMouseButtonDown_ = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
if (this->menu_ && !this->menuVisible_)
|
default:
|
||||||
{
|
// Unsupported button
|
||||||
QTimer::singleShot(80, this, [this] {
|
return;
|
||||||
this->showMenu();
|
|
||||||
});
|
|
||||||
this->mouseDown_ = false;
|
|
||||||
this->mouseOver_ = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::mouseReleaseEvent(QMouseEvent *event)
|
void Button::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!this->enabled_ || !this->mouseDown_)
|
// Reset the "mouse button down" state of the released button and store
|
||||||
|
// whether the button was in the down state when this event fired
|
||||||
|
bool hadCorrectButtonPressed = false;
|
||||||
|
switch (event->button())
|
||||||
|
{
|
||||||
|
case Qt::MouseButton::LeftButton: {
|
||||||
|
hadCorrectButtonPressed = this->leftMouseButtonDown_;
|
||||||
|
this->leftMouseButtonDown_ = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Qt::MouseButton::RightButton: {
|
||||||
|
hadCorrectButtonPressed = this->rightMouseButtonDown_;
|
||||||
|
this->rightMouseButtonDown_ = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Qt::MouseButton::MiddleButton: {
|
||||||
|
hadCorrectButtonPressed = this->middleMouseButtonDown_;
|
||||||
|
this->middleMouseButtonDown_ = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Unsupported button
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->enabled_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInside = this->rect().contains(event->pos());
|
bool isInside = this->rect().contains(event->pos());
|
||||||
|
|
||||||
if (event->button() == Qt::LeftButton)
|
if (isInside && hadCorrectButtonPressed)
|
||||||
{
|
{
|
||||||
this->mouseDown_ = false;
|
if (event->button() == Qt::LeftButton)
|
||||||
|
|
||||||
if (isInside)
|
|
||||||
{
|
{
|
||||||
leftClicked();
|
leftClicked();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (isInside)
|
|
||||||
{
|
|
||||||
clicked(event->button());
|
clicked(event->button());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,7 +292,7 @@ void Button::onMouseEffectTimeout()
|
|||||||
for (auto it = this->clickEffects_.begin();
|
for (auto it = this->clickEffects_.begin();
|
||||||
it != this->clickEffects_.end();)
|
it != this->clickEffects_.end();)
|
||||||
{
|
{
|
||||||
it->progress += mouseDown_ ? 0.02 : 0.07;
|
it->progress += this->leftMouseButtonDown_ ? 0.02 : 0.07;
|
||||||
|
|
||||||
if (it->progress >= 1.0)
|
if (it->progress >= 1.0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
[[nodiscard]] bool mouseOver() const noexcept;
|
[[nodiscard]] bool mouseOver() const noexcept;
|
||||||
|
|
||||||
/// Returns true if the left mouse button is held down
|
/// Returns true if the left mouse button is held down
|
||||||
[[nodiscard]] bool mouseDown() const noexcept;
|
[[nodiscard]] bool leftMouseButtonDown() const noexcept;
|
||||||
|
|
||||||
/// @brief Returns true if the menu is visible
|
/// @brief Returns true if the menu is visible
|
||||||
///
|
///
|
||||||
@@ -202,7 +202,9 @@ private:
|
|||||||
|
|
||||||
bool enabled_ = true;
|
bool enabled_ = true;
|
||||||
bool mouseOver_ = false;
|
bool mouseOver_ = false;
|
||||||
bool mouseDown_ = false;
|
bool leftMouseButtonDown_ = false;
|
||||||
|
bool rightMouseButtonDown_ = false;
|
||||||
|
bool middleMouseButtonDown_ = false;
|
||||||
bool menuVisible_ = false;
|
bool menuVisible_ = false;
|
||||||
|
|
||||||
QPixmap cachedPixmap_;
|
QPixmap cachedPixmap_;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void NotebookButton::paintContent(QPainter &painter)
|
|||||||
QColor background;
|
QColor background;
|
||||||
QColor foreground;
|
QColor foreground;
|
||||||
|
|
||||||
if (this->mouseDown() || this->mouseOver())
|
if (this->leftMouseButtonDown() || this->mouseOver())
|
||||||
{
|
{
|
||||||
background = this->theme->tabs.regular.backgrounds.hover;
|
background = this->theme->tabs.regular.backgrounds.hover;
|
||||||
foreground = this->theme->tabs.regular.text;
|
foreground = this->theme->tabs.regular.text;
|
||||||
|
|||||||
Reference in New Issue
Block a user