From f368a499d68490b4a93ef659e673dacbc3c8eb8c Mon Sep 17 00:00:00 2001 From: RJ Ryan Date: Sun, 12 Jan 2014 02:19:59 -0500 Subject: Remove WBaseWidget disabled state. Instead, use QWidget enabled property. As discussed in Bug #1180872, we should allow skin writers to connect controls to the enabled state of a widget to enable/disable widgets. This disables input events for widgets that are disabled or whose parents are disabled. * Remove old OnOff connection type. I haven't seen a single use of it since I joined the project in 2008. * Convert PropertyBinder into a ControlWidgetConnection. * Update WDisplay to check the QWidget enabled property. Currently only WDisplay supports rendering itself in a disabled state. I'll add support to more widgets in the future. --- src/skin/legacyskinparser.cpp | 46 +++++++++++++++++++------------------- src/skin/propertybinder.cpp | 39 -------------------------------- src/skin/propertybinder.h | 29 ------------------------ src/widget/wbasewidget.cpp | 52 ++++++++++++++++++++++++++++++++----------- src/widget/wbasewidget.h | 30 ++++++++++++------------- src/widget/wdisplay.cpp | 2 +- src/widget/wwidget.h | 1 - 7 files changed, 78 insertions(+), 121 deletions(-) delete mode 100644 src/skin/propertybinder.cpp delete mode 100644 src/skin/propertybinder.h (limited to 'src') diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index cf13b01d6e..f21f8593d5 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -25,7 +25,6 @@ #include "controllers/controllermanager.h" #include "skin/colorschemeparser.h" -#include "skin/propertybinder.h" #include "skin/skincontext.h" #include "widget/wbasewidget.h" @@ -1601,33 +1600,27 @@ void LegacySkinParser::setupConnections(QDomNode node, WBaseWidget* pWidget) { // Check that the control exists bool created = false; - ControlObject * control = controlFromConfigKey(configKey, &created); - - QString property = m_pContext->selectString(con, "BindProperty"); - if (property != "") { - qDebug() << "Making property binder for" << property; - // 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->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) { - control->setParent(pBinder); - } - } else if (m_pContext->hasNode(con, "OnOff") && - m_pContext->selectString(con, "OnOff")=="true") { - // Connect control proxy to widget. Parented to pWidget so it is not - // 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. + ControlObject* control = controlFromConfigKey(configKey, &created); + + if (m_pContext->hasNode(con, "BindProperty")) { + QString property = m_pContext->selectString(con, "BindProperty"); + qDebug() << "Making property connection for" << property; + ControlObjectSlave* pControlWidget = new ControlObjectSlave(control->getKey(), pWidget->toQWidget()); + ControlWidgetConnection* pConnection = - new DisabledControlWidgetConnection(pWidget, - pControlWidget); + new PropertyControlWidgetConnection(pWidget, pControlWidget, + m_pConfig, property); pWidget->addConnection(pConnection); + + // If we created this control, bind it to the + // ControlWidgetConnection so that it is deleted when the connection + // is deleted. + if (created) { + control->setParent(pConnection); + } } else { // Default to emit on press ControlWidgetConnection::EmitOption emitOption = @@ -1660,6 +1653,13 @@ void LegacySkinParser::setupConnections(QDomNode node, WBaseWidget* pWidget) { pWidget, pControlWidget, connectValueFromWidget, connectValueToWidget, emitOption); + // If we created this control, bind it to the + // ControlWidgetConnection so that it is deleted when the connection + // is deleted. + if (created) { + control->setParent(pConnection); + } + switch (state) { case Qt::NoButton: pWidget->addConnection(pConnection); diff --git a/src/skin/propertybinder.cpp b/src/skin/propertybinder.cpp deleted file mode 100644 index 811f32282d..0000000000 --- a/src/skin/propertybinder.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "skin/propertybinder.h" - -#include - -#include "controlobject.h" -#include "controlobjectthread.h" - -PropertyBinder::PropertyBinder(QWidget* pWidget, QString propertyName, - ControlObject* pControl, ConfigObject* pConfig) - : QObject(pWidget), - m_propertyName(propertyName), - m_pWidget(pWidget), - m_pControlThread(new ControlObjectThread(pControl->getKey())), - m_pConfig(pConfig) { - connect(m_pControlThread, SIGNAL(valueChanged(double)), - this, SLOT(slotValueChanged(double))); - bool ok; - double dValue = m_pConfig->getValueString(pControl->getKey()).toDouble(&ok); - if (ok) { - pControl->set(dValue); - } else { - dValue = m_pControlThread->get(); - } - slotValueChanged(dValue); -} - -PropertyBinder::~PropertyBinder() { - delete m_pControlThread; -} - -void PropertyBinder::slotValueChanged(double dValue) { - //qDebug() << this << m_propertyName << "valueChanged" << dValue; - QVariant value(dValue); - QByteArray propertyAscii = m_propertyName.toAscii(); - if (!m_pWidget->setProperty(propertyAscii.constData(), value)) { - qDebug() << "Setting property" << m_propertyName << "to widget failed. Value:" << value; - } - m_pConfig->set(m_pControlThread->getKey(), QString::number(dValue)); -} diff --git a/src/skin/propertybinder.h b/src/skin/propertybinder.h deleted file mode 100644 index 81e6e25ab1..0000000000 --- a/src/skin/propertybinder.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef PROPERTYBINDER_H -#define PROPERTYBINDER_H - -#include -#include -#include -#include - -#include "configobject.h" - -class ControlObject; -class ControlObjectThread; - -class PropertyBinder : public QObject { - Q_OBJECT - public: - PropertyBinder(QWidget* pWidget, QString propertyName, - ControlObject* pControl, ConfigObject* pConfig); - virtual ~PropertyBinder(); - private slots: - void slotValueChanged(double dValue); - private: - QString m_propertyName; - QWidget* m_pWidget; - ControlObjectThread* m_pControlThread; - ConfigObject* m_pConfig; -}; - -#endif /* PROPERTYBINDER_H */ diff --git a/src/widget/wbasewidget.cpp b/src/widget/wbasewidget.cpp index af3cde4ff1..e8aac9054d 100644 --- a/src/widget/wbasewidget.cpp +++ b/src/widget/wbasewidget.cpp @@ -78,42 +78,68 @@ void ValueControlWidgetConnection::setControlParameterUp(double v) { } } -DisabledControlWidgetConnection::DisabledControlWidgetConnection(WBaseWidget* pBaseWidget, - ControlObjectSlave* pControl) - : ControlWidgetConnection(pBaseWidget, pControl) { +PropertyControlWidgetConnection::PropertyControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectSlave* pControl, + ConfigObject* pConfig, + const QString& propertyName) + : ControlWidgetConnection(pBaseWidget, pControl), + m_pConfig(pConfig), + m_propertyName(propertyName.toAscii()) { + // Behavior copied from PropertyBinder: load config value for the control on + // creation. + // TODO(rryan): Remove this in favor of a better solution. See discussion on + // Bug #1091147. + bool ok = false; + double dValue = m_pConfig->getValueString(m_pControl->getKey()).toDouble(&ok); + if (ok) { + m_pControl->setParameter(dValue); + } slotControlValueChanged(m_pControl->get()); } -DisabledControlWidgetConnection::~DisabledControlWidgetConnection() { +PropertyControlWidgetConnection::~PropertyControlWidgetConnection() { } -QString DisabledControlWidgetConnection::toDebugString() const { +QString PropertyControlWidgetConnection::toDebugString() const { const ConfigKey& key = m_pControl->getKey(); - return QString("Disabled %1,%2").arg(key.group, key.item); + return QString("%1,%2 Parameter: %3 Property: %4 Value: %5").arg( + key.group, key.item, QString::number(m_pControl->getParameter()), m_propertyName, + m_pWidget->toQWidget()->property( + m_propertyName.constData()).toString()); } -void DisabledControlWidgetConnection::slotControlValueChanged(double v) { - m_pWidget->setControlDisabled(m_pControl->getParameterForValue(v) != 0.0); - m_pWidget->toQWidget()->update(); +void PropertyControlWidgetConnection::slotControlValueChanged(double v) { + double dParameter = m_pControl->getParameterForValue(v); + + if (!m_pWidget->toQWidget()->setProperty(m_propertyName.constData(), + QVariant(dParameter))) { + qDebug() << "Setting property" << m_propertyName + << "to widget failed. Value:" << dParameter; + } + + // Behavior copied from PropertyBinder: save config value for the control on + // every change. + // TODO(rryan): Remove this in favor of a better solution. See discussion on + // Bug #1091147. + m_pConfig->set(m_pControl->getKey(), QString::number(dParameter)); } -void DisabledControlWidgetConnection::resetControl() { +void PropertyControlWidgetConnection::resetControl() { // Do nothing. } -void DisabledControlWidgetConnection::setControlParameterDown(double v) { +void PropertyControlWidgetConnection::setControlParameterDown(double v) { // Do nothing. Q_UNUSED(v); } -void DisabledControlWidgetConnection::setControlParameterUp(double v) { +void PropertyControlWidgetConnection::setControlParameterUp(double v) { // Do nothing. Q_UNUSED(v); } WBaseWidget::WBaseWidget(QWidget* pWidget) : m_pWidget(pWidget), - m_bDisabled(false), m_pDisplayConnection(NULL) { } diff --git a/src/widget/wbasewidget.h b/src/widget/wbasewidget.h index d29acea6b8..0eb5dffef4 100644 --- a/src/widget/wbasewidget.h +++ b/src/widget/wbasewidget.h @@ -3,11 +3,14 @@ #include #include +#include #include #include #include #include +#include "configobject.h" + class ControlObjectSlave; class WBaseWidget; @@ -74,7 +77,7 @@ class ValueControlWidgetConnection : public ControlWidgetConnection { void setControlParameterDown(double v); void setControlParameterUp(double v); - protected slots: + private slots: void slotControlValueChanged(double v); private: @@ -83,12 +86,14 @@ class ValueControlWidgetConnection : public ControlWidgetConnection { EmitOption m_emitOption; }; -class DisabledControlWidgetConnection : public ControlWidgetConnection { +class PropertyControlWidgetConnection : public ControlWidgetConnection { Q_OBJECT public: - DisabledControlWidgetConnection(WBaseWidget* pBaseWidget, - ControlObjectSlave* pControl); - virtual ~DisabledControlWidgetConnection(); + PropertyControlWidgetConnection(WBaseWidget* pBaseWidget, + ControlObjectSlave* pControl, + ConfigObject* pConfig, + const QString& property); + virtual ~PropertyControlWidgetConnection(); QString toDebugString() const; @@ -97,8 +102,12 @@ class DisabledControlWidgetConnection : public ControlWidgetConnection { void setControlParameterDown(double v); void setControlParameterUp(double v); - protected slots: + private slots: void slotControlValueChanged(double v); + + private: + ConfigObject* m_pConfig; + QByteArray m_propertyName; }; class WBaseWidget { @@ -119,14 +128,6 @@ class WBaseWidget { return m_baseTooltip; } - void setControlDisabled(bool disabled) { - m_bDisabled = disabled; - } - - bool controlDisabled() const { - return m_bDisabled; - } - void addLeftConnection(ControlWidgetConnection* pConnection); void addRightConnection(ControlWidgetConnection* pConnection); void addConnection(ControlWidgetConnection* pConnection); @@ -163,7 +164,6 @@ class WBaseWidget { private: QWidget* m_pWidget; - bool m_bDisabled; QString m_baseTooltip; QList m_connections; ControlWidgetConnection* m_pDisplayConnection; diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index baf2b0d52a..40089dbd31 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -160,7 +160,7 @@ void WDisplay::paintEvent(QPaintEvent* ) { // If we are disabled, use the disabled pixmaps. If not, use the regular // pixmaps. - const QVector& pixmaps = (controlDisabled() && m_bDisabledLoaded) ? + const QVector& pixmaps = (!isEnabled() && m_bDisabledLoaded) ? m_disabledPixmaps : m_pixmaps; if (pixmaps.empty()) { diff --git a/src/widget/wwidget.h b/src/widget/wwidget.h index 49821e83f6..4264f27672 100644 --- a/src/widget/wwidget.h +++ b/src/widget/wwidget.h @@ -41,7 +41,6 @@ public: WWidget(QWidget *parent=0, Qt::WindowFlags flags=0); virtual ~WWidget(); - Q_PROPERTY(bool controlDisabled READ controlDisabled); Q_PROPERTY(double value READ getControlParameterDisplay); virtual void onConnectedControlValueChanged(double value); -- cgit v1.2.3