From 0a4d97b7cafb9ca92798f3b53165359f5055c220 Mon Sep 17 00:00:00 2001 From: RJ Ryan Date: Thu, 9 Jan 2014 15:18:34 -0500 Subject: Expose widget connections directly to WBaseWidget rather than using Qt signals. This paves the way for getting rid of widget values and adding the concept of a display value vs. a left/right connected widget value. An added benefit is that ControlObjectThreadWidget is now nothing more than a parameter-space translator on top of ControlObjectThreadMain. --- src/controllers/controllerlearningeventfilter.cpp | 2 +- src/controllers/controllerlearningeventfilter.h | 15 ++- src/controlobjectthreadwidget.cpp | 59 --------- src/controlobjectthreadwidget.h | 14 -- src/skin/legacyskinparser.cpp | 61 ++++++--- src/skin/legacyskinparser.h | 4 +- src/widget/knobeventhandler.h | 10 +- src/widget/wbasewidget.cpp | 150 ++++++++++++++++++++++ src/widget/wbasewidget.h | 97 ++++++++++++++ src/widget/wkey.cpp | 4 + src/widget/wkey.h | 2 + src/widget/wnumber.cpp | 4 + src/widget/wnumber.h | 2 + src/widget/woverview.cpp | 8 +- src/widget/woverview.h | 2 +- src/widget/wpushbutton.cpp | 18 +-- src/widget/wpushbutton.h | 2 +- src/widget/wslidercomposed.cpp | 14 +- src/widget/wslidercomposed.h | 2 +- src/widget/wstatuslight.cpp | 2 +- src/widget/wstatuslight.h | 2 +- src/widget/wvumeter.cpp | 2 +- src/widget/wvumeter.h | 2 +- src/widget/wwaveformviewer.cpp | 8 +- src/widget/wwaveformviewer.h | 1 - src/widget/wwidget.cpp | 27 +--- src/widget/wwidget.h | 17 +-- 27 files changed, 355 insertions(+), 176 deletions(-) diff --git a/src/controllers/controllerlearningeventfilter.cpp b/src/controllers/controllerlearningeventfilter.cpp index be29dd605a..97b62995da 100644 --- a/src/controllers/controllerlearningeventfilter.cpp +++ b/src/controllers/controllerlearningeventfilter.cpp @@ -87,7 +87,7 @@ bool ControllerLearningEventFilter::eventFilter(QObject* pObject, QEvent* pEvent void ControllerLearningEventFilter::addWidgetClickInfo( QWidget* pWidget, Qt::MouseButton buttonState, ControlObject* pControl, - ControlObjectThreadWidget::EmitOption emitOption) { + ControlWidgetConnection::EmitOption emitOption) { ControlInfo& info = m_widgetControlInfo[pWidget]; if (buttonState == Qt::LeftButton) { diff --git a/src/controllers/controllerlearningeventfilter.h b/src/controllers/controllerlearningeventfilter.h index e0a69dcdf6..c3976bb5c4 100644 --- a/src/controllers/controllerlearningeventfilter.h +++ b/src/controllers/controllerlearningeventfilter.h @@ -6,23 +6,24 @@ #include "controlobject.h" #include "controlobjectthreadwidget.h" +#include "widget/wbasewidget.h" struct ControlInfo { ControlInfo() : clickControl(NULL), - emitOption(ControlObjectThreadWidget::EMIT_ON_PRESS_AND_RELEASE), + emitOption(ControlWidgetConnection::EMIT_ON_PRESS_AND_RELEASE), leftClickControl(NULL), - leftEmitOption(ControlObjectThreadWidget::EMIT_ON_PRESS_AND_RELEASE), + leftEmitOption(ControlWidgetConnection::EMIT_ON_PRESS_AND_RELEASE), rightClickControl(NULL), - rightEmitOption(ControlObjectThreadWidget::EMIT_ON_PRESS_AND_RELEASE) { + rightEmitOption(ControlWidgetConnection::EMIT_ON_PRESS_AND_RELEASE) { } ControlObject* clickControl; - ControlObjectThreadWidget::EmitOption emitOption; + ControlWidgetConnection::EmitOption emitOption; ControlObject* leftClickControl; - ControlObjectThreadWidget::EmitOption leftEmitOption; + ControlWidgetConnection::EmitOption leftEmitOption; ControlObject* rightClickControl; - ControlObjectThreadWidget::EmitOption rightEmitOption; + ControlWidgetConnection::EmitOption rightEmitOption; }; class ControllerLearningEventFilter : public QObject { @@ -35,7 +36,7 @@ class ControllerLearningEventFilter : public QObject { void addWidgetClickInfo(QWidget* pWidget, Qt::MouseButton buttonState, ControlObject* pControl, - ControlObjectThreadWidget::EmitOption emitOption); + ControlWidgetConnection::EmitOption emitOption); public slots: void startListening(); diff --git a/src/controlobjectthreadwidget.cpp b/src/controlobjectthreadwidget.cpp index 493b45d0ea..d8bcb3875a 100644 --- a/src/controlobjectthreadwidget.cpp +++ b/src/controlobjectthreadwidget.cpp @@ -20,65 +20,6 @@ ControlObjectThreadWidget::ControlObjectThreadWidget(const QString& g, const QSt ControlObjectThreadWidget::~ControlObjectThreadWidget() { } -void ControlObjectThreadWidget::setWidget(QWidget * widget, bool connectValueFromWidget, - bool connectValueToWidget, - EmitOption emitOption, Qt::MouseButton state) { - if (connectValueFromWidget) { - connect(widget, SIGNAL(valueReset()), - this, SLOT(reset())); - - if (emitOption & EMIT_ON_PRESS) { - switch (state) { - case Qt::NoButton: - connect(widget, SIGNAL(valueChangedDown(double)), - this, SLOT(slotSet(double))); - break; - case Qt::LeftButton: - connect(widget, SIGNAL(valueChangedLeftDown(double)), - this, SLOT(slotSet(double))); - break; - case Qt::RightButton: - connect(widget, SIGNAL(valueChangedRightDown(double)), - this, SLOT(slotSet(double))); - break; - default: - break; - } - } - - if (emitOption & EMIT_ON_RELEASE) { - switch (state) { - case Qt::NoButton: - connect(widget, SIGNAL(valueChangedUp(double)), - this, SLOT(slotSet(double))); - break; - case Qt::LeftButton: - connect(widget, SIGNAL(valueChangedLeftUp(double)), - this, SLOT(slotSet(double))); - break; - case Qt::RightButton: - connect(widget, SIGNAL(valueChangedRightUp(double)), - this, SLOT(slotSet(double))); - break; - default: - break; - } - } - } - - if (connectValueToWidget) { - connect(this, SIGNAL(valueChanged(double)), - widget, SLOT(slotConnectedValueChanged(double))); - } - emit(valueChanged(get())); -} - -void ControlObjectThreadWidget::setWidgetOnOff(QWidget* widget) { - connect(this, SIGNAL(valueChanged(double)), - widget, SLOT(setOnOff(double))); - emit(valueChanged(get())); -} - double ControlObjectThreadWidget::get() { return m_pControl ? m_pControl->getParameter() : 0.0; } diff --git a/src/controlobjectthreadwidget.h b/src/controlobjectthreadwidget.h index 0af53e9478..a917dfe1eb 100644 --- a/src/controlobjectthreadwidget.h +++ b/src/controlobjectthreadwidget.h @@ -24,24 +24,10 @@ class ControlObjectThreadWidget : public ControlObjectThreadMain { Q_OBJECT public: - - enum EmitOption { - EMIT_NEVER = 0x00, - EMIT_ON_PRESS = 0x01, - EMIT_ON_RELEASE = 0x02, - EMIT_ON_PRESS_AND_RELEASE = 0x03 - }; - ControlObjectThreadWidget(const ConfigKey& key, QObject* pParent = NULL); ControlObjectThreadWidget(const char* g, const char* i, QObject* pParent = NULL); ControlObjectThreadWidget(const QString& g, const QString& i, QObject* pParent = NULL); virtual ~ControlObjectThreadWidget(); - // Associates a QWidget with the ControlObject. - void setWidget(QWidget *widget, - bool connectValueFromWidget=true, bool connectValueToWidget = true, - EmitOption emitOption=EMIT_ON_PRESS, Qt::MouseButton state=Qt::NoButton); - // Associates a the enabled/disabled state of a widget with the state of a ControlObject. */ - void setWidgetOnOff(QWidget *widget); virtual double get(); diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 484ca9171c..ca61517757 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -731,11 +731,11 @@ QWidget* LegacySkinParser::parseVisual(QDomElement node) { viewer->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); // Connect control proxy to widget, so delete can be handled by the QT object tree - ControlObjectThreadWidget * p = new ControlObjectThreadWidget( + ControlObjectThreadWidget* p = new ControlObjectThreadWidget( channelStr, "wheel", viewer); - - p->setWidget((QWidget *)viewer, true, false, - ControlObjectThreadWidget::EMIT_ON_PRESS, Qt::RightButton); + ControlWidgetConnection* pConnection = new ValueControlWidgetConnection( + viewer, p, true, false, ControlWidgetConnection::EMIT_ON_PRESS); + viewer->addRightConnection(pConnection); setupBaseWidget(node, viewer); setupWidget(node, viewer); @@ -1589,7 +1589,7 @@ void LegacySkinParser::setupWidget(QDomNode node, } } -void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { +void LegacySkinParser::setupConnections(QDomNode node, WBaseWidget* pWidget) { // For each connection QDomNode con = m_pContext->selectNode(node, "Connection"); @@ -1610,7 +1610,7 @@ void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { // Bind this control to a property. Not leaked because it is // parented to the widget and so it dies with it. PropertyBinder* pBinder = new PropertyBinder( - pWidget, property, control, m_pConfig); + pWidget->toQWidget(), property, control, m_pConfig); // If we created this control, bind it to the PropertyBinder so that // it is deleted when the binder is deleted. if (created) { @@ -1622,17 +1622,24 @@ void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { // leaked. OnOff controls do not use the value of the widget at all // so we do not give this control's info to the // ControllerLearningEventFilter. - (new ControlObjectThreadWidget(control->getKey(), pWidget))->setWidgetOnOff(pWidget); + ControlObjectThreadWidget* pControlWidget = + new ControlObjectThreadWidget(control->getKey(), + pWidget->toQWidget()); + ControlWidgetConnection* pConnection = + new DisabledControlWidgetConnection(pWidget, + pControlWidget); + pWidget->addConnection(pConnection); } else { // Default to emit on press - ControlObjectThreadWidget::EmitOption emitOption = ControlObjectThreadWidget::EMIT_ON_PRESS; + ControlWidgetConnection::EmitOption emitOption = + ControlWidgetConnection::EMIT_ON_PRESS; // Get properties from XML, or use defaults if (m_pContext->selectBool(con, "EmitOnPressAndRelease", false)) - emitOption = ControlObjectThreadWidget::EMIT_ON_PRESS_AND_RELEASE; + emitOption = ControlWidgetConnection::EMIT_ON_PRESS_AND_RELEASE; if (!m_pContext->selectBool(con, "EmitOnDownPress", true)) - emitOption = ControlObjectThreadWidget::EMIT_ON_RELEASE; + emitOption = ControlWidgetConnection::EMIT_ON_RELEASE; bool connectValueFromWidget = m_pContext->selectBool(con, "ConnectValueFromWidget", true); bool connectValueToWidget = m_pContext->selectBool(con, "ConnectValueToWidget", true); @@ -1648,15 +1655,31 @@ void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { // Connect control proxy to widget. Parented to pWidget so it is not // leaked. - (new ControlObjectThreadWidget(control->getKey(), pWidget))->setWidget( - pWidget, connectValueFromWidget, connectValueToWidget, - emitOption, state); + ControlObjectThreadWidget* pControlWidget = new ControlObjectThreadWidget( + control->getKey(), pWidget->toQWidget()); + ControlWidgetConnection* pConnection = new ValueControlWidgetConnection( + pWidget, pControlWidget, connectValueFromWidget, + connectValueToWidget, emitOption); + + switch (state) { + case Qt::NoButton: + pWidget->addConnection(pConnection); + break; + case Qt::LeftButton: + pWidget->addLeftConnection(pConnection); + break; + case Qt::RightButton: + pWidget->addRightConnection(pConnection); + break; + default: + break; + } // We only add info for controls that this widget affects, not // controls that only affect the widget. if (connectValueFromWidget) { m_pControllerManager->getControllerLearningEventFilter() - ->addWidgetClickInfo(pWidget, state, control, emitOption); + ->addWidgetClickInfo(pWidget->toQWidget(), state, control, emitOption); } // Add keyboard shortcut info to tooltip string @@ -1667,7 +1690,7 @@ void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { const WSliderComposed* pSlider; - if (qobject_cast(pWidget)) { + if (qobject_cast(pWidget->toQWidget())) { // check for "_activate", "_toggle" ConfigKey subkey; QString shortcut; @@ -1681,7 +1704,7 @@ void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { subkey.item += "_toggle"; shortcut = m_pKeyboard->getKeyboardConfig()->getValueString(subkey); addShortcutToToolTip(pWidget, shortcut, tr("toggle")); - } else if ((pSlider = qobject_cast(pWidget))) { + } else if ((pSlider = qobject_cast(pWidget->toQWidget()))) { // check for "_up", "_down", "_up_small", "_down_small" ConfigKey subkey; QString shortcut; @@ -1734,12 +1757,12 @@ void LegacySkinParser::setupConnections(QDomNode node, QWidget* pWidget) { } } -void LegacySkinParser::addShortcutToToolTip(QWidget* pWidget, const QString& shortcut, const QString& cmd) { +void LegacySkinParser::addShortcutToToolTip(WBaseWidget* pWidget, const QString& shortcut, const QString& cmd) { if (shortcut.isEmpty()) { return; } - QString tooltip = pWidget->toolTip(); + QString tooltip = pWidget->baseTooltip(); // translate shortcut to native text #if QT_VERSION >= 0x040700 @@ -1757,5 +1780,5 @@ void LegacySkinParser::addShortcutToToolTip(QWidget* pWidget, const QString& sho } tooltip += ": "; tooltip += nativeShortcut; - pWidget->setToolTip(tooltip); + pWidget->setBaseTooltip(tooltip); } diff --git a/src/skin/legacyskinparser.h b/src/skin/legacyskinparser.h index dfe7da9947..691ce5bfba 100644 --- a/src/skin/legacyskinparser.h +++ b/src/skin/legacyskinparser.h @@ -84,8 +84,8 @@ class LegacySkinParser : public QObject, public SkinParser { void setupBaseWidget(QDomNode node, WBaseWidget* pBaseWidget); void setupWidget(QDomNode node, QWidget* pWidget, bool setupPosition=true); - void setupConnections(QDomNode node, QWidget* pWidget); - void addShortcutToToolTip(QWidget* pWidget, const QString& shortcut, const QString& cmd); + void setupConnections(QDomNode node, WBaseWidget* pWidget); + void addShortcutToToolTip(WBaseWidget* pWidget, const QString& shortcut, const QString& cmd); QString getLibraryStyle(QDomNode node); QString getStyleFromNode(QDomNode node); diff --git a/src/widget/knobeventhandler.h b/src/widget/knobeventhandler.h index 4a47d69ecc..b67aab9eb1 100644 --- a/src/widget/knobeventhandler.h +++ b/src/widget/knobeventhandler.h @@ -38,8 +38,8 @@ class KnobEventHandler { // Clamp to [0.0, 1.0] value = math_max(0.0, math_min(1.0, value)); - pWidget->slotConnectedValueChanged(value); - emit(pWidget->valueChangedLeftDown(value)); + pWidget->onConnectedControlValueChanged(value); + pWidget->setConnectedControlLeftDown(value); pWidget->update(); } } @@ -47,7 +47,7 @@ class KnobEventHandler { void mousePressEvent(T* pWidget, QMouseEvent* e) { switch (e->button()) { case Qt::RightButton: - emit(pWidget->valueReset()); + pWidget->resetConnectedControls(); m_bRightButtonPressed = true; break; case Qt::LeftButton: @@ -66,11 +66,11 @@ class KnobEventHandler { case Qt::MidButton: QCursor::setPos(m_startPos); QApplication::restoreOverrideCursor(); - emit(pWidget->valueChangedLeftUp(pWidget->getValue())); + pWidget->setConnectedControlLeftUp(pWidget->getValue()); break; case Qt::RightButton: m_bRightButtonPressed = false; - //emit(pWidget->valueChangedRightUp(m_fValue)); + //pWidget->setConnectedControlRightUp(pWidget->getValue()); break; default: break; diff --git a/src/widget/wbasewidget.cpp b/src/widget/wbasewidget.cpp index 24ce9f4d0b..27c372ce4c 100644 --- a/src/widget/wbasewidget.cpp +++ b/src/widget/wbasewidget.cpp @@ -1,5 +1,91 @@ +#include + #include "widget/wbasewidget.h" +#include "controlobjectthreadwidget.h" + +ControlWidgetConnection::ControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectThreadWidget* pControl) + : m_pWidget(pBaseWidget), + m_pControl(pControl) { + connect(pControl, SIGNAL(valueChanged(double)), + this, SLOT(slotControlValueChanged(double))); +} + +ControlWidgetConnection::~ControlWidgetConnection() { +} + +ValueControlWidgetConnection::ValueControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectThreadWidget* pControl, + bool connectValueFromWidget, + bool connectValueToWidget, + EmitOption emitOption) + : ControlWidgetConnection(pBaseWidget, pControl), + m_bConnectValueFromWidget(connectValueFromWidget), + m_bConnectValueToWidget(connectValueToWidget), + m_emitOption(emitOption) { + if (m_bConnectValueToWidget) { + slotControlValueChanged(m_pControl->get()); + } +} + +ValueControlWidgetConnection::~ValueControlWidgetConnection() { +} + +void ValueControlWidgetConnection::slotControlValueChanged(double v) { + if (m_bConnectValueToWidget) { + m_pWidget->onConnectedControlValueChanged(v); + // TODO(rryan): copied from WWidget. Keep? + //m_pWidget->toQWidget()->update(); + } +} + +void ValueControlWidgetConnection::reset() { + if (m_bConnectValueFromWidget) { + m_pControl->reset(); + } +} + +void ValueControlWidgetConnection::setDown(double v) { + if (m_bConnectValueFromWidget && m_emitOption & EMIT_ON_PRESS) { + m_pControl->slotSet(v); + } +} + +void ValueControlWidgetConnection::setUp(double v) { + if (m_bConnectValueFromWidget && m_emitOption & EMIT_ON_RELEASE) { + m_pControl->slotSet(v); + } +} + +DisabledControlWidgetConnection::DisabledControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectThreadWidget* pControl) + : ControlWidgetConnection(pBaseWidget, pControl) { + slotControlValueChanged(m_pControl->get()); +} + +DisabledControlWidgetConnection::~DisabledControlWidgetConnection() { +} + +void DisabledControlWidgetConnection::slotControlValueChanged(double v) { + m_pWidget->setControlDisabled(v != 0.0); + m_pWidget->toQWidget()->update(); +} + +void DisabledControlWidgetConnection::reset() { + // Do nothing. +} + +void DisabledControlWidgetConnection::setDown(double v) { + // Do nothing. + Q_UNUSED(v); +} + +void DisabledControlWidgetConnection::setUp(double v) { + // Do nothing. + Q_UNUSED(v); +} + WBaseWidget::WBaseWidget(QWidget* pWidget) : m_pWidget(pWidget), m_bDisabled(false) { @@ -7,3 +93,67 @@ WBaseWidget::WBaseWidget(QWidget* pWidget) WBaseWidget::~WBaseWidget() { } + +void WBaseWidget::addConnection(ControlWidgetConnection* pConnection) { + m_connections.append(pConnection); +} + +void WBaseWidget::addLeftConnection(ControlWidgetConnection* pConnection) { + m_leftConnections.append(pConnection); +} + +void WBaseWidget::addRightConnection(ControlWidgetConnection* pConnection) { + m_rightConnections.append(pConnection); +} + +void WBaseWidget::resetConnectedControls() { + foreach (ControlWidgetConnection* pControlConnection, m_leftConnections) { + pControlConnection->reset(); + } + foreach (ControlWidgetConnection* pControlConnection, m_rightConnections) { + pControlConnection->reset(); + } + foreach (ControlWidgetConnection* pControlConnection, m_connections) { + pControlConnection->reset(); + } +} + +void WBaseWidget::setConnectedControlDown(double v) { + foreach (ControlWidgetConnection* pControlConnection, m_connections) { + pControlConnection->setDown(v); + } +} + +void WBaseWidget::setConnectedControlUp(double v) { + foreach (ControlWidgetConnection* pControlConnection, m_connections) { + pControlConnection->setUp(v); + } +} + +void WBaseWidget::setConnectedControlLeftDown(double v) { + foreach (ControlWidgetConnection* pControlConnection, m_leftConnections) { + pControlConnection->setDown(v); + } + setConnectedControlDown(v); +} + +void WBaseWidget::setConnectedControlLeftUp(double v) { + foreach (ControlWidgetConnection* pControlConnection, m_leftConnections) { + pControlConnection->setUp(v); + } + setConnectedControlUp(v); +} + +void WBaseWidget::setConnectedControlRightDown(double v) { + foreach (ControlWidgetConnection* pControlConnection, m_rightConnections) { + pControlConnection->setDown(v); + } + setConnectedControlDown(v); +} + +void WBaseWidget::setConnectedControlRightUp(double v) { + foreach (ControlWidgetConnection* pControlConnection, m_rightConnections) { + pControlConnection->setUp(v); + } + setConnectedControlUp(v); +} diff --git a/src/widget/wbasewidget.h b/src/widget/wbasewidget.h index faa06cde8b..a29cb98922 100644 --- a/src/widget/wbasewidget.h +++ b/src/widget/wbasewidget.h @@ -3,6 +3,80 @@ #include #include +#include +#include +#include +#include + +class ControlObjectThreadWidget; + +class WBaseWidget; +class ControlWidgetConnection : public QObject { + Q_OBJECT + public: + enum EmitOption { + EMIT_NEVER = 0x00, + EMIT_ON_PRESS = 0x01, + EMIT_ON_RELEASE = 0x02, + EMIT_ON_PRESS_AND_RELEASE = 0x03 + }; + + // Takes ownership of pControl. + ControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectThreadWidget* pControl); + virtual ~ControlWidgetConnection(); + + virtual void reset() = 0; + virtual void setDown(double v) = 0; + virtual void setUp(double v) = 0; + + protected slots: + virtual void slotControlValueChanged(double v) = 0; + + protected: + WBaseWidget* m_pWidget; + QScopedPointer m_pControl; +}; + +class ValueControlWidgetConnection : public ControlWidgetConnection { + Q_OBJECT + public: + ValueControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectThreadWidget* pControl, + bool connectValueFromWidget, + bool connectValueToWidget, + EmitOption emitOption); + virtual ~ValueControlWidgetConnection(); + + protected: + void reset(); + void setDown(double v); + void setUp(double v); + + protected slots: + void slotControlValueChanged(double v); + + private: + bool m_bConnectValueFromWidget; + bool m_bConnectValueToWidget; + EmitOption m_emitOption; +}; + +class DisabledControlWidgetConnection : public ControlWidgetConnection { + Q_OBJECT + public: + DisabledControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectThreadWidget* pControl); + virtual ~DisabledControlWidgetConnection(); + + protected: + void reset(); + void setDown(double v); + void setUp(double v); + + protected slots: + void slotControlValueChanged(double v); +}; class WBaseWidget { public: @@ -30,10 +104,33 @@ class WBaseWidget { return m_bDisabled; } + void addLeftConnection(ControlWidgetConnection* pConnection); + void addRightConnection(ControlWidgetConnection* pConnection); + void addConnection(ControlWidgetConnection* pConnection); + + protected: + virtual void onConnectedControlValueChanged(double v) { + Q_UNUSED(v); + } + + void resetConnectedControls(); + void setConnectedControlDown(double v); + void setConnectedControlUp(double v); + void setConnectedControlLeftDown(double v); + void setConnectedControlLeftUp(double v); + void setConnectedControlRightDown(double v); + void setConnectedControlRightUp(double v); + private: QWidget* m_pWidget; bool m_bDisabled; QString m_baseTooltip; + QList m_connections; + QList m_leftConnections; + QList m_rightConnections; + + friend class ValueControlWidgetConnection; + friend class DisabledControlWidgetConnection; }; #endif /* WBASEWIDGET_H */ diff --git a/src/widget/wkey.cpp b/src/widget/wkey.cpp index 84fc6ab99d..b271e08283 100644 --- a/src/widget/wkey.cpp +++ b/src/widget/wkey.cpp @@ -15,6 +15,10 @@ WKey::WKey(QWidget* pParent) WKey::~WKey() { } +void WKey::onConnectedControlValueChanged(double v) { + setValue(v); +} + void WKey::setValue(double dValue) { m_dOldValue = dValue; mixxx::track::io::key::ChromaticKey key = diff --git a/src/widget/wkey.h b/src/widget/wkey.h index 88c828e9d8..5e58a01cae 100644 --- a/src/widget/wkey.h +++ b/src/widget/wkey.h @@ -12,6 +12,8 @@ class WKey : public WLabel { WKey(QWidget* pParent=NULL); virtual ~WKey(); + virtual void onConnectedControlValueChanged(double v); + private slots: void setValue(double dValue); void preferencesUpdated(double dValue); diff --git a/src/widget/wnumber.cpp b/src/widget/wnumber.cpp index a3a862ab5b..45c4f34c02 100644 --- a/src/widget/wnumber.cpp +++ b/src/widget/wnumber.cpp @@ -47,6 +47,10 @@ void WNumber::setup(QDomNode node, const SkinContext& context) { setValue(0.); } +void WNumber::onConnectedControlValueChanged(double v) { + setValue(v); +} + void WNumber::setValue(double dValue) { double v = dValue + m_dConstFactor; int d1 = (int)floor((v-floor(v))*10.); diff --git a/src/widget/wnumber.h b/src/widget/wnumber.h index f3d7504342..c542473c83 100644 --- a/src/widget/wnumber.h +++ b/src/widget/wnumber.h @@ -31,6 +31,8 @@ class WNumber : public WLabel { virtual void setup(QDomNode node, const SkinContext& context); + virtual void onConnectedControlValueChanged(double v); + public slots: virtual void setValue(double dValue); diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index 4bb06f2529..5ece68ce72 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -120,14 +120,14 @@ void WOverview::setup(QDomNode node, const SkinContext& context) { //qDebug() << "WOverview : m_markRanges" << m_markRanges.size(); } -void WOverview::slotConnectedValueChanged(double dValue) { +void WOverview::onConnectedControlValueChanged(double dValue) { if (!m_bDrag) { // Calculate handle position int iPos = valueToPosition(dValue); if (iPos != m_iPos) { m_iPos = iPos; - //qDebug() << "WOverview::slotConnectedValueChanged" << dValue << ">>" << m_iPos; + //qDebug() << "WOverview::onConnectedControlValueChanged" << dValue << ">>" << m_iPos; update(); } } @@ -252,9 +252,9 @@ void WOverview::mouseReleaseEvent(QMouseEvent* e) { //qDebug() << "WOverview::mouseReleaseEvent" << e->pos() << m_iPos << ">>" << dValue; if (e->button() == Qt::RightButton) { - emit(valueChangedRightUp(dValue)); + setConnectedControlRightUp(dValue); } else { - emit(valueChangedLeftUp(dValue)); + setConnectedControlLeftUp(dValue); } m_bDrag = false; } diff --git a/src/widget/woverview.h b/src/widget/woverview.h index 9ebe8b5b77..5ec505bf8c 100644 --- a/src/widget/woverview.h +++ b/src/widget/woverview.h @@ -40,7 +40,7 @@ class WOverview : public WWidget { void setup(QDomNode node, const SkinContext& context); public slots: - void slotConnectedValueChanged(double); + void onConnectedControlValueChanged(double); void slotLoadNewTrack(TrackPointer pTrack); void slotTrackLoaded(TrackPointer pTrack); void slotUnloadTrack(TrackPointer pTrack); diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 566b26ac4e..7ca392f4ae 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -172,7 +172,7 @@ void WPushButton::setPixmapBackground(const QString &filename) { } } -void WPushButton::slotConnectedValueChanged(double v) { +void WPushButton::onConnectedControlValueChanged(double v) { setValue(v); if (m_iNoStates == 1) { @@ -236,7 +236,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { } setValue(1.0); m_bPressed = true; - emit(valueChangedLeftDown(1.0f)); + setConnectedControlLeftDown(1.0); update(); } // discharge right clicks here, because is used for latching in POWERWINDOW mode @@ -248,13 +248,13 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { // due the leak of visual feedback we do not allow a toggle function if (m_bRightClickForcePush) { m_bPressed = true; - emit(valueChangedRightDown(1.0f)); + setConnectedControlRightDown(1.0); update(); } else if (m_iNoStates == 1) { // This is a Pushbutton setValue(1.0); m_bPressed = true; - emit(valueChangedRightDown(1.0f)); + setConnectedControlRightDown(1.0); update(); } @@ -288,7 +288,7 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { } } m_bPressed = true; - emit(valueChangedLeftDown(emitValue)); + setConnectedControlLeftDown(emitValue); update(); } } @@ -311,7 +311,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { if (m_bPressed && !m_clickTimer.isActive() && !rightButtonDown) { // Release button after timer, but not if right button is clicked setValue(0.0); - emit(valueChangedLeftUp(0.0f)); + setConnectedControlLeftUp(0.0); } m_bPressed = false; } else if (rightClick) { @@ -327,11 +327,11 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { // function if (m_bRightClickForcePush) { m_bPressed = false; - emit(valueChangedRightUp(0.0f)); + setConnectedControlRightUp(0.0); update(); } else if (m_iNoStates == 1) { m_bPressed = false; - emit(valueChangedRightUp(0.0f)); + setConnectedControlRightUp(0.0); update(); } return; @@ -357,7 +357,7 @@ void WPushButton::mouseReleaseEvent(QMouseEvent * e) { } } m_bPressed = false; - emit(valueChangedLeftUp(emitValue)); + setConnectedControlLeftUp(emitValue); update(); } } diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index 65bdd020a4..868c29e90f 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -54,7 +54,7 @@ class WPushButton : public WWidget { void setStates(int iStatesW); public slots: - void slotConnectedValueChanged(double); + void onConnectedControlValueChanged(double); protected: virtual void paintEvent(QPaintEvent *); diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index fe31366556..515170feec 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(getValue()); + onConnectedControlValueChanged(getValue()); update(); } } @@ -123,9 +123,9 @@ void WSliderComposed::mouseMoveEvent(QMouseEvent * e) { // Emit valueChanged signal if (m_bEventWhileDrag) { if (e->button() == Qt::RightButton) { - emit(valueChangedRightUp(newValue)); + setConnectedControlRightUp(newValue); } else { - emit(valueChangedLeftUp(newValue)); + setConnectedControlLeftUp(newValue); } } @@ -154,9 +154,9 @@ void WSliderComposed::mouseReleaseEvent(QMouseEvent * e) { mouseMoveEvent(e); if (e->button() == Qt::RightButton) { - emit(valueChangedRightUp(getValue())); + setConnectedControlRightUp(getValue()); } else { - emit(valueChangedLeftUp(getValue())); + setConnectedControlLeftUp(getValue()); } m_bDrag = false; @@ -174,7 +174,7 @@ void WSliderComposed::mousePressEvent(QMouseEvent * e) { m_bDrag = true; } else { if (e->button() == Qt::RightButton) { - emit(valueReset()); + resetConnectedControls(); m_bRightButtonPressed = true; } else { if (m_bHorizontal) { @@ -204,7 +204,7 @@ void WSliderComposed::paintEvent(QPaintEvent *) { } } -void WSliderComposed::slotConnectedValueChanged(double dValue) { +void WSliderComposed::onConnectedControlValueChanged(double dValue) { if (!m_bDrag && getValue() != dValue) { // Set value without emitting a valueChanged signal // and force display update diff --git a/src/widget/wslidercomposed.h b/src/widget/wslidercomposed.h index f17ad2337d..86ce224184 100644 --- a/src/widget/wslidercomposed.h +++ b/src/widget/wslidercomposed.h @@ -51,7 +51,7 @@ class WSliderComposed : public WWidget { void wheelEvent(QWheelEvent *e); inline bool isHorizontal() const { return m_bHorizontal; }; public slots: - void slotConnectedValueChanged(double); + void onConnectedControlValueChanged(double); private: void unsetPixmaps(); diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index 7bf5a814cc..44f3128c87 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -86,7 +86,7 @@ void WStatusLight::setPixmap(int iState, const QString& filename) { } } -void WStatusLight::slotConnectedValueChanged(double v) { +void WStatusLight::onConnectedControlValueChanged(double v) { int val = static_cast(v); if (m_iPos == val) { return; diff --git a/src/widget/wstatuslight.h b/src/widget/wstatuslight.h index 0f42f0fbce..721dd1a520 100644 --- a/src/widget/wstatuslight.h +++ b/src/widget/wstatuslight.h @@ -40,7 +40,7 @@ class WStatusLight : public WWidget { void setup(QDomNode node, const SkinContext& context); public slots: - void slotConnectedValueChanged(double v); + void onConnectedControlValueChanged(double v); protected: void paintEvent(QPaintEvent *); diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index d2ac72ed26..f3dab29e8c 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -103,7 +103,7 @@ void WVuMeter::setPixmaps(const QString &vuFilename, } } -void WVuMeter::slotConnectedValueChanged(double dValue) { +void WVuMeter::onConnectedControlValueChanged(double dValue) { int idx = static_cast(dValue * m_iNoPos); // Range check if (idx > m_iNoPos) diff --git a/src/widget/wvumeter.h b/src/widget/wvumeter.h index bab5bca9b0..44e94319ed 100644 --- a/src/widget/wvumeter.h +++ b/src/widget/wvumeter.h @@ -39,7 +39,7 @@ class WVuMeter : public WWidget { void setPixmapBackground(const QString& filename); void setPixmaps(const QString &vuFilename, bool bHorizontal=false); - void slotConnectedValueChanged(double fValue); + void onConnectedControlValueChanged(double fValue); protected slots: void updateState(int msecsElapsed); diff --git a/src/widget/wwaveformviewer.cpp b/src/widget/wwaveformviewer.cpp index 764e3c80ef..543636c681 100644 --- a/src/widget/wwaveformviewer.cpp +++ b/src/widget/wwaveformviewer.cpp @@ -68,7 +68,7 @@ void WWaveformViewer::mousePressEvent(QMouseEvent* event) { // If we are pitch-bending then disable and reset because the two // shouldn't be used at once. if (m_bBending) { - emit(valueChangedRightDown(0.5)); + setConnectedControlRightDown(0.5); m_bBending = false; } m_bScratching = true; @@ -83,7 +83,7 @@ void WWaveformViewer::mousePressEvent(QMouseEvent* event) { m_pScratchPositionEnable->slotSet(0.0f); m_bScratching = false; } - emit(valueChangedRightDown(0.5)); + setConnectedControlRightDown(0.5); m_bBending = true; } @@ -111,7 +111,7 @@ void WWaveformViewer::mouseMoveEvent(QMouseEvent* event) { double v = 0.5 + (diff.x() / 1270.0); // clamp to [0.0, 1.0] v = math_min(1.0, math_max(0.0, v)); - emit(valueChangedRightDown(v)); + setConnectedControlRightDown(v); } } @@ -121,7 +121,7 @@ void WWaveformViewer::mouseReleaseEvent(QMouseEvent* /*event*/) { m_bScratching = false; } if (m_bBending) { - emit(valueChangedRightDown(0.5)); + setConnectedControlRightDown(0.5); m_bBending = false; } m_mouseAnchor = QPoint(); diff --git a/src/widget/wwaveformviewer.h b/src/widget/wwaveformviewer.h index bb2dadd53c..1a7a2821fa 100644 --- a/src/widget/wwaveformviewer.h +++ b/src/widget/wwaveformviewer.h @@ -35,7 +35,6 @@ class WWaveformViewer : public WWidget { signals: void trackDropped(QString filename, QString group); - void valueReset(); public slots: void onTrackLoaded( TrackPointer track); diff --git a/src/widget/wwidget.cpp b/src/widget/wwidget.cpp index 6cbd15392d..bed27531b1 100644 --- a/src/widget/wwidget.cpp +++ b/src/widget/wwidget.cpp @@ -25,11 +25,6 @@ WWidget::WWidget(QWidget* parent, Qt::WindowFlags flags) : QWidget(parent, flags), WBaseWidget(this), m_value(0.0) { - connect(this, SIGNAL(valueChangedLeftDown(double)), this, SLOT(slotReEmitValueDown(double))); - connect(this, SIGNAL(valueChangedRightDown(double)), this, SLOT(slotReEmitValueDown(double))); - connect(this, SIGNAL(valueChangedLeftUp(double)), this, SLOT(slotReEmitValueUp(double))); - connect(this, SIGNAL(valueChangedRightUp(double)), this, SLOT(slotReEmitValueUp(double))); - setAttribute(Qt::WA_StaticContents); setFocusPolicy(Qt::ClickFocus); } @@ -37,26 +32,14 @@ WWidget::WWidget(QWidget* parent, Qt::WindowFlags flags) WWidget::~WWidget() { } -void WWidget::slotConnectedValueChanged(double value) { +void WWidget::onConnectedControlValueChanged(double value) { m_value = value; update(); } -void WWidget::setOnOff(double d) { - setDisabled(d != 0.0); - update(); -} - -void WWidget::slotReEmitValueDown(double value) { - emit(valueChangedDown(value)); -} - -void WWidget::slotReEmitValueUp(double value) { - emit(valueChangedUp(value)); -} - void WWidget::updateValue(double value) { - slotConnectedValueChanged(value); - emit(valueChangedUp(value)); - emit(valueChangedDown(value)); + onConnectedControlValueChanged(value); + // TODO(rryan): Why is this up then down versus down then up? + setConnectedControlUp(value); + setConnectedControlDown(value); } diff --git a/src/widget/wwidget.h b/src/widget/wwidget.h index ffb8021383..05169bd762 100644 --- a/src/widget/wwidget.h +++ b/src/widget/wwidget.h @@ -52,23 +52,10 @@ public: m_value = value; } + virtual void onConnectedControlValueChanged(double value); + public slots: - virtual void slotConnectedValueChanged(double value); void updateValue(double value); - void setOnOff(double); - - private slots: - void slotReEmitValueDown(double); - void slotReEmitValueUp(double); - - signals: - void valueReset(); - void valueChangedDown(double); - void valueChangedUp(double); - void valueChangedLeftDown(double); - void valueChangedLeftUp(double); - void valueChangedRightDown(double); - void valueChangedRightUp(double); private: // Value/state of widget -- cgit v1.2.3