summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widget/wpushbutton.cpp41
-rw-r--r--src/widget/wpushbutton.h9
2 files changed, 28 insertions, 22 deletions
diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp
index 5b57a74f71..294d1503a9 100644
--- a/src/widget/wpushbutton.cpp
+++ b/src/widget/wpushbutton.cpp
@@ -239,19 +239,8 @@ void WPushButton::setPixmapBackground(PixmapSource source,
}
}
-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.
- if (m_iNoStates == 1) {
- m_bPressed = (dValue == 1.0);
- }
-
- double value = getControlParameterDisplay();
- if (!isnan(value) && m_iNoStates > 0) {
- int idx = static_cast<int>(value) % m_iNoStates;
- emit(displayValueChanged(idx));
- }
+void WPushButton::restyleAndRepaint() {
+ emit(displayValueChanged(readDisplayValue()));
// According to http://stackoverflow.com/a/3822243 this is the least
// expensive way to restyle just this widget.
@@ -260,10 +249,22 @@ void WPushButton::onConnectedControlChanged(double dParameter, double dValue) {
// re-render.
style()->unpolish(this);
style()->polish(this);
+
// These calls don't always trigger the repaint, so call it explicitly.
repaint();
}
+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.
+ if (m_iNoStates == 1) {
+ m_bPressed = (dValue == 1.0);
+ }
+
+ restyleAndRepaint();
+}
+
void WPushButton::paintEvent(QPaintEvent* e) {
Q_UNUSED(e);
QStyleOption option;
@@ -321,7 +322,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) {
}
m_bPressed = true;
setControlParameterLeftDown(1.0);
- update();
+ restyleAndRepaint();
}
// discharge right clicks here, because is used for latching in POWERWINDOW mode
return;
@@ -334,7 +335,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) {
|| m_iNoStates == 1) {
m_bPressed = true;
setControlParameterRightDown(1.0);
- update();
+ restyleAndRepaint();
}
return;
}
@@ -359,7 +360,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) {
}
m_bPressed = true;
setControlParameterLeftDown(emitValue);
- update();
+ restyleAndRepaint();
}
}
@@ -370,7 +371,7 @@ void WPushButton::focusOutEvent(QFocusEvent* e) {
// the pressed flag if the Primary touch point is moved to an
// other widget
m_bPressed = false;
- update();
+ restyleAndRepaint();
}
}
@@ -390,7 +391,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) {
} else if (rightClick) {
m_bPressed = false;
}
- update();
+ restyleAndRepaint();
return;
}
@@ -402,7 +403,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) {
|| m_iNoStates == 1) {
m_bPressed = false;
setControlParameterRightUp(0.0);
- update();
+ restyleAndRepaint();
}
return;
}
@@ -426,7 +427,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) {
}
m_bPressed = false;
setControlParameterLeftUp(emitValue);
- update();
+ restyleAndRepaint();
}
}
diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h
index a7d40884d4..99f62f79de 100644
--- a/src/widget/wpushbutton.h
+++ b/src/widget/wpushbutton.h
@@ -32,6 +32,7 @@
#include "controlpushbutton.h"
#include "skin/skincontext.h"
#include "controlwidgetconnection.h"
+#include "util/math.h"
class WPushButton : public WWidget {
Q_OBJECT
@@ -56,8 +57,10 @@ class WPushButton : public WWidget {
int readDisplayValue() const {
double value = getControlParameterDisplay();
- int idx = static_cast<int>(value) % m_iNoStates;
- return idx;
+ if (!isnan(value) && m_iNoStates > 0) {
+ return static_cast<int>(value) % m_iNoStates;
+ }
+ return 0;
}
virtual void setup(QDomNode node, const SkinContext& context);
@@ -80,6 +83,8 @@ class WPushButton : public WWidget {
void fillDebugTooltip(QStringList* debug);
protected:
+ void restyleAndRepaint();
+
// Associates a pixmap of a given state of the button with the widget
void setPixmap(int iState, bool bPressed, PixmapSource source);