From cd64f16a3593771c5c843307f8152ecfcfcd6b68 Mon Sep 17 00:00:00 2001 From: be_ Date: Sun, 29 Jan 2017 01:05:13 -0600 Subject: [PATCH 1/3] add SELECTMULTI ControlPushButtonBehavior This is like radio buttons, but 0 (no selection) is a valid state. Clicking an unselected button selects it; clicking it again unselects it (sets the ControlPushButton's value to 0). --- src/control/controlbehavior.h | 3 ++- src/control/controlpushbutton.h | 3 +++ src/widget/wbasewidget.h | 2 +- src/widget/wpushbutton.cpp | 25 ++++++++++++++++++++++++- src/widget/wpushbutton.h | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/control/controlbehavior.h b/src/control/controlbehavior.h index 7185d62a5085..780ccaee68a8 100644 --- a/src/control/controlbehavior.h +++ b/src/control/controlbehavior.h @@ -110,7 +110,8 @@ class ControlPushButtonBehavior : public ControlNumericBehavior { TOGGLE, POWERWINDOW, LONGPRESSLATCHING, - TRIGGER + TRIGGER, + SELECTMULTI, }; ControlPushButtonBehavior(ButtonMode buttonMode, int iNumStates); diff --git a/src/control/controlpushbutton.h b/src/control/controlpushbutton.h index 408ee217b552..250969a42181 100644 --- a/src/control/controlpushbutton.h +++ b/src/control/controlpushbutton.h @@ -33,6 +33,7 @@ class ControlPushButton : public ControlObject { POWERWINDOW, LONGPRESSLATCHING, TRIGGER, + SELECTMULTI, }; static QString buttonModeToString(int mode) { @@ -47,6 +48,8 @@ class ControlPushButton : public ControlObject { return "LONGPRESSLATCHING"; case ControlPushButton::TRIGGER: return "TRIGGER"; + case ControlPushButton::SELECTMULTI: + return "SELECTMULTI"; default: return "UNKNOWN"; } diff --git a/src/widget/wbasewidget.h b/src/widget/wbasewidget.h index 1876c6f389ac..78da3db9db6c 100644 --- a/src/widget/wbasewidget.h +++ b/src/widget/wbasewidget.h @@ -52,7 +52,7 @@ class WBaseWidget { double getControlParameter() const; double getControlParameterLeft() const; double getControlParameterRight() const; - double getControlParameterDisplay() const; + virtual double getControlParameterDisplay() const; protected: // Whenever a connected control is changed, onConnectedControlChanged is diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 750f3872e8b0..d4a7f367995a 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -53,6 +53,8 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { int iNumStates = context.selectInt(node, "NumberStates"); setStates(iNumStates); + m_iSelectionIndex = context.selectInt(node, "SelectionIndex"); + // Set background pixmap if available QDomElement backPathNode = context.selectElement(node, "BackPath"); @@ -155,6 +157,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { break; case ControlPushButton::TOGGLE: case ControlPushButton::TRIGGER: + case ControlPushButton::SELECTMULTI: default: leftConnection->setEmitOption( ControlParameterWidgetConnection::EMIT_ON_PRESS); @@ -276,6 +279,19 @@ void WPushButton::restyleAndRepaint() { repaint(); } +double WPushButton::getControlParameterDisplay() const { + double value = WBaseWidget::getControlParameterDisplay(); + if (!isnan(value) && m_iNoStates > 0) { + if (m_leftButtonMode == ControlPushButton::SELECTMULTI) { + return static_cast( + value == static_cast(m_iSelectionIndex)); + } else { + return static_cast(value) % m_iNoStates; + } + } + return 0.0; +} + void WPushButton::onConnectedControlChanged(double dParameter, double dValue) { Q_UNUSED(dParameter); // Enums are not currently represented using parameter space so it doesn't @@ -312,7 +328,7 @@ void WPushButton::paintEvent(QPaintEvent* e) { return; } - int idx = readDisplayValue(); + int idx = getControlParameterDisplay(); // Just in case m_iNoStates is somehow different from pixmaps.size(). if (idx < 0) { idx = 0; @@ -365,11 +381,18 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { if (leftClick) { double emitValue; + if (m_leftButtonMode == ControlPushButton::PUSH || m_iNoStates == 1) { // This is either forced to behave like a push button on left-click // or this is a push button. emitValue = 1.0; + } else if (m_leftButtonMode == ControlPushButton::SELECTMULTI) { + if (getControlParameterLeft() != static_cast(m_iSelectionIndex)) { + emitValue = static_cast(m_iSelectionIndex); + } else { + emitValue = 0.0; + } } else { // Toggle thru the states emitValue = getControlParameterLeft(); diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index 8da7b74e2a34..378086e415f4 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -61,6 +61,7 @@ class WPushButton : public WWidget { } return 0; } + double getControlParameterDisplay() const override; virtual void setup(const QDomNode& node, const SkinContext& context); @@ -98,6 +99,7 @@ class WPushButton : public WWidget { // Array of associated pixmaps int m_iNoStates; + int m_iSelectionIndex; QVector m_text; QVector m_pressedPixmaps; QVector m_unpressedPixmaps; From 9e09f95d738c3dbbade944234822a57c07a700fe Mon Sep 17 00:00:00 2001 From: be_ Date: Sun, 29 Jan 2017 01:06:11 -0600 Subject: [PATCH 2/3] change focused_effect CO to SELECTMULTI ControlPushButton --- src/effects/effectchainslot.cpp | 5 +++-- src/effects/effectchainslot.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/effects/effectchainslot.cpp b/src/effects/effectchainslot.cpp index 98a9458fbf02..756b45135118 100644 --- a/src/effects/effectchainslot.cpp +++ b/src/effects/effectchainslot.cpp @@ -79,9 +79,10 @@ EffectChainSlot::EffectChainSlot(EffectRack* pRack, const QString& group, true); m_pControlChainShowParameters->setButtonMode(ControlPushButton::TOGGLE); - m_pControlChainFocusedEffect = new ControlObject( + m_pControlChainFocusedEffect = new ControlPushButton( ConfigKey(m_group, "focused_effect"), - true, false, true); + true); + m_pControlChainFocusedEffect->setButtonMode(ControlPushButton::SELECTMULTI); } EffectChainSlot::~EffectChainSlot() { diff --git a/src/effects/effectchainslot.h b/src/effects/effectchainslot.h index bc0ecd642f2c..ba87314377f1 100644 --- a/src/effects/effectchainslot.h +++ b/src/effects/effectchainslot.h @@ -147,7 +147,7 @@ class EffectChainSlot : public QObject { **/ ControlPushButton* m_pControlChainShowFocus; ControlPushButton* m_pControlChainShowParameters; - ControlObject* m_pControlChainFocusedEffect; + ControlPushButton* m_pControlChainFocusedEffect; struct ChannelInfo { // Takes ownership of pEnabled. From 2d3541dc7369ebd353e72162300729c56e6beb9d Mon Sep 17 00:00:00 2001 From: be_ Date: Sun, 29 Jan 2017 01:06:51 -0600 Subject: [PATCH 3/3] remove unused displayValue property from WPushButton It was redundant with the "value" property. --- src/widget/wpushbutton.cpp | 2 -- src/widget/wpushbutton.h | 16 ---------------- 2 files changed, 18 deletions(-) diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index d4a7f367995a..0706acc6bac8 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -265,8 +265,6 @@ void WPushButton::setPixmapBackground(PixmapSource source, } void WPushButton::restyleAndRepaint() { - emit(displayValueChanged(readDisplayValue())); - // According to http://stackoverflow.com/a/3822243 this is the least // expensive way to restyle just this widget. // Since we expect button connections to not change at high frequency we diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index 378086e415f4..ff84db0fb610 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -48,19 +48,6 @@ class WPushButton : public WWidget { return m_bPressed; } - // The displayValue property is used to restyle the pushbutton with CSS. - // The declaration #MyButton[displayValue="0"] { } will define the style - // when the widget is in state 0. This allows for effects like reversing - // background and foreground colors to indicate enabled/disabled state. - Q_PROPERTY(int displayValue READ readDisplayValue NOTIFY displayValueChanged) - - int readDisplayValue() const { - double value = getControlParameterDisplay(); - if (!isnan(value) && m_iNoStates > 0) { - return static_cast(value) % m_iNoStates; - } - return 0; - } double getControlParameterDisplay() const override; virtual void setup(const QDomNode& node, const SkinContext& context); @@ -69,9 +56,6 @@ class WPushButton : public WWidget { // associated pixmaps. void setStates(int iStates); - signals: - void displayValueChanged(int value); - public slots: void onConnectedControlChanged(double dParameter, double dValue) override;