Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/control/controlbehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class ControlPushButtonBehavior : public ControlNumericBehavior {
TOGGLE,
POWERWINDOW,
LONGPRESSLATCHING,
TRIGGER
TRIGGER,
SELECTMULTI,
};

ControlPushButtonBehavior(ButtonMode buttonMode, int iNumStates);
Expand Down
3 changes: 3 additions & 0 deletions src/control/controlpushbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ControlPushButton : public ControlObject {
POWERWINDOW,
LONGPRESSLATCHING,
TRIGGER,
SELECTMULTI,
};

static QString buttonModeToString(int mode) {
Expand All @@ -47,6 +48,8 @@ class ControlPushButton : public ControlObject {
return "LONGPRESSLATCHING";
case ControlPushButton::TRIGGER:
return "TRIGGER";
case ControlPushButton::SELECTMULTI:
return "SELECTMULTI";
default:
return "UNKNOWN";
}
Expand Down
5 changes: 3 additions & 2 deletions src/effects/effectchainslot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/effects/effectchainslot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wbasewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions src/widget/wpushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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<int>(
value == static_cast<double>(m_iSelectionIndex));
} else {
return static_cast<int>(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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<double>(m_iSelectionIndex)) {
emitValue = static_cast<double>(m_iSelectionIndex);
} else {
emitValue = 0.0;
}
} else {
// Toggle thru the states
emitValue = getControlParameterLeft();
Expand Down
18 changes: 2 additions & 16 deletions src/widget/wpushbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,14 @@ 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<int>(value) % m_iNoStates;
}
return 0;
}
double getControlParameterDisplay() const override;

virtual void setup(const QDomNode& node, const SkinContext& context);

// Sets the number of states associated with this button, and removes
// associated pixmaps.
void setStates(int iStates);

signals:
void displayValueChanged(int value);

public slots:
void onConnectedControlChanged(double dParameter, double dValue) override;

Expand Down Expand Up @@ -98,6 +83,7 @@ class WPushButton : public WWidget {

// Array of associated pixmaps
int m_iNoStates;
int m_iSelectionIndex;
QVector<QString> m_text;
QVector<PaintablePointer> m_pressedPixmaps;
QVector<PaintablePointer> m_unpressedPixmaps;
Expand Down