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/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. 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..0706acc6bac8 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); @@ -262,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 @@ -276,6 +277,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 +326,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 +379,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..ff84db0fb610 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -48,19 +48,7 @@ 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); @@ -68,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; @@ -98,6 +83,7 @@ class WPushButton : public WWidget { // Array of associated pixmaps int m_iNoStates; + int m_iSelectionIndex; QVector m_text; QVector m_pressedPixmaps; QVector m_unpressedPixmaps;