diff options
author | Daniel Schürmann <daschuer@mixxx.org> | 2020-03-05 00:35:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-05 00:35:15 +0100 |
commit | 787d4c89a606fde041dd9258789d7d08d88776be (patch) | |
tree | d3e3cabf8ad8ffdf80f1539dc6b8863cff0e1189 /src/widget/wpushbutton.cpp | |
parent | 1e0a1f58c423f06faf7ddc9962250fae0ba5dada (diff) | |
parent | 31ac96d53c3b9f7678f13878dbde759b76b8231c (diff) |
Merge pull request #2460 from ronso0/pushbutton-pressed-state
Prevent pushbuttons with 'blocked' controls getting stuck pressed
Diffstat (limited to 'src/widget/wpushbutton.cpp')
-rw-r--r-- | src/widget/wpushbutton.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index fcb60dd2e2..6a590836f5 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -390,10 +390,10 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { if (leftClick) { m_clickTimer.setSingleShot(true); m_clickTimer.start(ControlPushButtonBehavior::kPowerWindowTimeMillis); + m_bPressed = true; double emitValue = getControlParameterLeft() == 0.0 ? 1.0 : 0.0; setControlParameterLeftDown(emitValue); - m_bPressed = true; restyleAndRepaint(); } // discharge right clicks here, because is used for latching in POWERWINDOW mode @@ -414,6 +414,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { } if (leftClick) { + m_bPressed = true; double emitValue; if (m_leftButtonMode == ControlPushButton::PUSH || m_iNoStates == 1) { @@ -431,21 +432,32 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { m_clickTimer.start(ControlPushButtonBehavior::kLongPressLatchingTimeMillis); } } - m_bPressed = true; setControlParameterLeftDown(emitValue); restyleAndRepaint(); } } +bool WPushButton::event(QEvent* e) { + if (e->type() == QEvent::WindowDeactivate) { + // if the window is deactivated while in pressed state + if (m_bPressed) { + m_bPressed = false; + restyleAndRepaint(); + } + } + return QWidget::event(e); +} + void WPushButton::focusOutEvent(QFocusEvent* e) { - Q_UNUSED(e); - if (e->reason() != Qt::MouseFocusReason) { + qDebug() << "focusOutEvent" << e->reason(); + if (m_bPressed && e->reason() != Qt::MouseFocusReason) { // Since we support multi touch there is no reason to reset // the pressed flag if the Primary touch point is moved to an // other widget m_bPressed = false; restyleAndRepaint(); } + QWidget::focusOutEvent(e); } void WPushButton::mouseReleaseEvent(QMouseEvent * e) { @@ -455,13 +467,13 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { if (m_leftButtonMode == ControlPushButton::POWERWINDOW && m_iNoStates == 2) { if (leftClick) { + m_bPressed = false; const bool rightButtonDown = QApplication::mouseButtons() & Qt::RightButton; if (m_bPressed && !m_clickTimer.isActive() && !rightButtonDown) { // Release button after timer, but not if right button is clicked double emitValue = getControlParameterLeft() == 0.0 ? 1.0 : 0.0; setControlParameterLeftUp(emitValue); } - m_bPressed = false; } else if (rightClick) { m_bPressed = false; } @@ -483,6 +495,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { } if (leftClick) { + m_bPressed = false; double emitValue = getControlParameterLeft(); if (m_leftButtonMode == ControlPushButton::PUSH || m_iNoStates == 1) { @@ -499,7 +512,6 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { // Nothing special happens when releasing a normal toggle button } } - m_bPressed = false; setControlParameterLeftUp(emitValue); restyleAndRepaint(); } |