Skip to content

Commit

Permalink
Merge pull request #6 from daschuer/pushbutton-pressed-state
Browse files Browse the repository at this point in the history
use QEvent::WindowDeactivate to reset the press state
  • Loading branch information
ronso0 authored Feb 4, 2020
2 parents 17b5c47 + 5e84866 commit 31ac96d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/widget/wpushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ void WPushButton::onConnectedControlChanged(double dParameter, double dValue) {
Q_UNUSED(dParameter);
// Enums are not currently represented using parameter space so it doesn't
// make sense to use the parameter here yet.
m_bPressed = (dValue == 1.0);
if (m_iNoStates == 1) {
m_bPressed = (dValue == 1.0);
}

restyleAndRepaint();
}
Expand Down Expand Up @@ -395,15 +397,27 @@ void WPushButton::mousePressEvent(QMouseEvent * e) {
}
}

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) {
Expand Down
3 changes: 2 additions & 1 deletion src/widget/wpushbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class WPushButton : public WWidget {
void onConnectedControlChanged(double dParameter, double dValue) override;

protected:
void paintEvent(QPaintEvent* /*unused*/) override;
bool event(QEvent* e) override;
void paintEvent(QPaintEvent* e) override;
void mousePressEvent(QMouseEvent* e) override;
void mouseReleaseEvent(QMouseEvent* e) override;
void focusOutEvent(QFocusEvent* e) override;
Expand Down

0 comments on commit 31ac96d

Please sign in to comment.