summaryrefslogtreecommitdiffstats
path: root/src/widget
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2014-01-12 02:19:59 -0500
committerRJ Ryan <rryan@mixxx.org>2014-01-12 02:19:59 -0500
commitf368a499d68490b4a93ef659e673dacbc3c8eb8c (patch)
treef6cd5be1bf996555a7bd454888e8618a98c001d0 /src/widget
parent574ed3b042f9cb50cdb509c55642a970820935b8 (diff)
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.
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/wbasewidget.cpp52
-rw-r--r--src/widget/wbasewidget.h30
-rw-r--r--src/widget/wdisplay.cpp2
-rw-r--r--src/widget/wwidget.h1
4 files changed, 55 insertions, 30 deletions
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<ConfigValue>* 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 <QString>
#include <QWidget>
+#include <QByteArray>
#include <QList>
#include <QObject>
#include <QScopedPointer>
#include <QDomNode>
+#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<ConfigValue>* 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<ConfigValue>* 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<ControlWidgetConnection*> 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<PaintablePointer>& pixmaps = (controlDisabled() && m_bDisabledLoaded) ?
+ const QVector<PaintablePointer>& 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);