Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use QEvent::WindowDeactivate to reset the press state #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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