diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-01-08 15:17:40 -0500 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-01-08 15:17:40 -0500 |
commit | 6863f5305d56f6da20efd8396894419848fae5c8 (patch) | |
tree | e33dace87d4e1c3cf1e262d915aefb0605e3aba9 | |
parent | 1554df44d1d45a2e8ab7a2645091f553c1acb645 (diff) |
Remove direct access to WWidget::m_value from child classes.
-rw-r--r-- | src/widget/wdisplay.cpp | 2 | ||||
-rw-r--r-- | src/widget/wpushbutton.cpp | 35 | ||||
-rw-r--r-- | src/widget/wslidercomposed.cpp | 19 | ||||
-rw-r--r-- | src/widget/wstatuslight.cpp | 2 | ||||
-rw-r--r-- | src/widget/wvumeter.cpp | 4 | ||||
-rw-r--r-- | src/widget/wwidget.h | 7 |
6 files changed, 38 insertions, 31 deletions
diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index b0076cb183..59df7775d3 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -145,7 +145,7 @@ int WDisplay::getActivePixmapIndex() const { // Subtracting an epsilon prevents out of bound values at the end of the // range and biases the middle value towards the lower of the 2 center // pixmaps when there are an even number of pixmaps. - return static_cast<int>(m_value * numPixmaps() - 0.00001); + return static_cast<int>(getValue() * numPixmaps() - 0.00001); } void WDisplay::paintEvent(QPaintEvent* ) { diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index f9ec5e45dc..b099f1e1d0 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -126,7 +126,7 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { } void WPushButton::setStates(int iStates) { - m_value = 0.; + setValue(0.0); m_bPressed = false; m_iNoStates = 0; @@ -173,10 +173,10 @@ void WPushButton::setPixmapBackground(const QString &filename) { } void WPushButton::slotConnectedValueChanged(double v) { - m_value = v; + setValue(v); if (m_iNoStates == 1) { - if (m_value == 1.0) { + if (v == 1.0) { m_bPressed = true; } else { m_bPressed = false; @@ -192,7 +192,7 @@ void WPushButton::paintEvent(QPaintEvent* e) { QStylePainter p(this); p.drawPrimitive(QStyle::PE_Widget, option); - double value = m_value; + double value = getValue(); if (m_iNoStates == 0) { return; } @@ -230,11 +230,11 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { if (leftPowerWindowStyle && m_iNoStates == 2) { if (leftClick) { - if (m_value == 0.0f) { + if (getValue() == 0.0) { m_clickTimer.setSingleShot(true); m_clickTimer.start(ControlPushButtonBehavior::kPowerWindowTimeMillis); } - m_value = 1.0f; + setValue(1.0); m_bPressed = true; emit(valueChangedLeftDown(1.0f)); update(); @@ -252,7 +252,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { update(); } else if (m_iNoStates == 1) { // This is a Pushbutton - m_value = 1.0f; + setValue(1.0); m_bPressed = true; emit(valueChangedRightDown(1.0f)); update(); @@ -273,13 +273,14 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { if (m_bLeftClickForcePush) { // This may a button with different functions on each mouse button // m_value is changed by a separate feedback connection - emitValue = 1.0f; + emitValue = 1.0; } else if (m_iNoStates == 1) { // This is a Pushbutton - m_value = emitValue = 1.0f; + emitValue = 1.0; + setValue(emitValue); } else { // Toggle thru the states - m_value = emitValue = (int)(m_value + 1.) % m_iNoStates; + emitValue = (int)(getValue() + 1.) % m_iNoStates; if (leftLongPressLatchingStyle) { m_clickTimer.setSingleShot(true); m_clickTimer.start(ControlPushButtonBehavior::kLongPressLatchingTimeMillis); @@ -308,7 +309,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { 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 - m_value = 0.0f; + setValue(0.0); emit(valueChangedLeftUp(0.0f)); } m_bPressed = false; @@ -336,18 +337,20 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { } if (leftClick) { - double emitValue = m_value; + double emitValue = getValue(); if (m_bLeftClickForcePush) { // This may a klickButton with different functions on each mouse button // m_fValue is changed by a separate feedback connection - emitValue = 0.0f; + emitValue = 0.0; } else if (m_iNoStates == 1) { // This is a Pushbutton - m_value = emitValue = 0.0f; + emitValue = 0.0; + setValue(emitValue); } else { - if (leftLongPressLatchingStyle && m_clickTimer.isActive() && m_value >= 1.0) { + if (leftLongPressLatchingStyle && m_clickTimer.isActive() && emitValue >= 1.0) { // revert toggle if button is released too early - m_value = emitValue = (int)(m_value - 1.0) % m_iNoStates; + emitValue = (int)(emitValue - 1.0) % m_iNoStates; + setValue(emitValue); } else { // Nothing special happens when releasing a normal toggle button } diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index ce61be1198..fe31366556 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -81,7 +81,7 @@ void WSliderComposed::setHandlePixmap(bool bHorizontal, const QString& filenameH m_iHandleLength = m_bHorizontal ? m_pHandle->width() : m_pHandle->height(); - slotConnectedValueChanged(m_value); + slotConnectedValueChanged(getValue()); update(); } } @@ -113,18 +113,19 @@ void WSliderComposed::mouseMoveEvent(QMouseEvent * e) { // Divide by (sliderLength - m_iHandleLength) to produce a normalized // value in the range of [0.0, 1.0]. 1.0 - m_value = static_cast<double>(m_iPos) / + double newValue = static_cast<double>(m_iPos) / static_cast<double>(sliderLength - m_iHandleLength); if (!m_bHorizontal) { - m_value = 1.0 - m_value; + newValue = 1.0 - newValue; } + setValue(newValue); // Emit valueChanged signal if (m_bEventWhileDrag) { if (e->button() == Qt::RightButton) { - emit(valueChangedRightUp(m_value)); + emit(valueChangedRightUp(newValue)); } else { - emit(valueChangedLeftUp(m_value)); + emit(valueChangedLeftUp(newValue)); } } @@ -153,9 +154,9 @@ void WSliderComposed::mouseReleaseEvent(QMouseEvent * e) { mouseMoveEvent(e); if (e->button() == Qt::RightButton) { - emit(valueChangedRightUp(m_value)); + emit(valueChangedRightUp(getValue())); } else { - emit(valueChangedLeftUp(m_value)); + emit(valueChangedLeftUp(getValue())); } m_bDrag = false; @@ -204,10 +205,10 @@ void WSliderComposed::paintEvent(QPaintEvent *) { } void WSliderComposed::slotConnectedValueChanged(double dValue) { - if (!m_bDrag && m_value != dValue) { + if (!m_bDrag && getValue() != dValue) { // Set value without emitting a valueChanged signal // and force display update - m_value = dValue; + setValue(dValue); // Calculate handle position if (!m_bHorizontal) { diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index e33ade3016..7bf5a814cc 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -45,7 +45,7 @@ void WStatusLight::setNoPos(int iNoPos) { iNoPos = 2; } m_pixmaps.resize(iNoPos); - m_value = 0.; + setValue(0.0); } void WStatusLight::setup(QDomNode node, const SkinContext& context) { diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index ecc8217880..d2ac72ed26 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -112,7 +112,7 @@ void WVuMeter::slotConnectedValueChanged(double dValue) { idx = 0; setPeak(idx); - m_value = dValue; + setValue(dValue); QTime currentTime = QTime::currentTime(); int msecsElapsed = m_lastUpdate.msecsTo(currentTime); @@ -159,7 +159,7 @@ void WVuMeter::paintEvent(QPaintEvent *) { } if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) { - int idx = static_cast<int>(m_value * m_iNoPos); + int idx = static_cast<int>(getValue() * m_iNoPos); // Range check if (idx > m_iNoPos) diff --git a/src/widget/wwidget.h b/src/widget/wwidget.h index d6076395a9..492a8258c9 100644 --- a/src/widget/wwidget.h +++ b/src/widget/wwidget.h @@ -55,6 +55,10 @@ public: return m_value; } + void setValue(double value) { + m_value = value; + } + public slots: virtual void slotConnectedValueChanged(double value); void updateValue(double value); @@ -73,11 +77,10 @@ public: void valueChangedRightDown(double); void valueChangedRightUp(double); - protected: + private: // Value/state of widget double m_value; - private: // Is true if widget is off bool m_bOff; }; |