[krita] libs/ui: Allow auto-enabling the multiproperty widget by just clicking on it

Dmitry Kazakov dimula73 at gmail.com
Fri Jun 3 13:25:48 UTC 2016


Git commit 575f0912552b4ea0754879670bdd0db2b1f2f042 by Dmitry Kazakov.
Committed on 03/06/2016 at 13:25.
Pushed by dkazakov into branch 'master'.

Allow auto-enabling the multiproperty widget by just clicking on it

If you open the Properties dialog for multiple layers, the controls
for the properties that vary among the layers (e.g. layer name) will
be initially disabled. Before this patch you should have enabled
them manually by clicking on a checkbox nearby, now it is perfectly
enough just to click on the control itself and it will become enabled.

Ref T106
CC:kimageshop at kde.org

M  +4    -0    libs/ui/dialogs/kis_dlg_layer_properties.cc
M  +46   -0    libs/ui/kis_multinode_property.cpp
M  +16   -0    libs/ui/kis_multinode_property.h

http://commits.kde.org/krita/575f0912552b4ea0754879670bdd0db2b1f2f042

diff --git a/libs/ui/dialogs/kis_dlg_layer_properties.cc b/libs/ui/dialogs/kis_dlg_layer_properties.cc
index 5c0343a..32d387c 100644
--- a/libs/ui/dialogs/kis_dlg_layer_properties.cc
+++ b/libs/ui/dialogs/kis_dlg_layer_properties.cc
@@ -101,6 +101,7 @@ KisDlgLayerProperties::KisDlgLayerProperties(KisNodeList nodes, KisViewManager *
     d->page->editName->setFocus();
     d->nameProperty.reset(new KisMultinodeNameProperty(nodes));
     d->nameProperty->connectIgnoreCheckBox(d->page->chkName);
+    d->nameProperty->connectAutoEnableWidget(d->page->editName);
     d->nameProperty->connectValueChangedSignal(this, SLOT(slotNameValueChangedInternally()));
     connect(d->page->editName, SIGNAL(textChanged(const QString &)), SLOT(slotNameValueChangedExternally()));
 
@@ -108,12 +109,14 @@ KisDlgLayerProperties::KisDlgLayerProperties(KisNodeList nodes, KisViewManager *
     d->page->intOpacity->setSuffix("%");
     d->opacityProperty.reset(new KisMultinodeOpacityProperty(nodes));
     d->opacityProperty->connectIgnoreCheckBox(d->page->chkOpacity);
+    d->opacityProperty->connectAutoEnableWidget(d->page->intOpacity);
     d->opacityProperty->connectValueChangedSignal(this, SLOT(slotOpacityValueChangedInternally()));
     d->opacityProperty->connectValueChangedSignal(&d->updatesCompressor, SLOT(start()));
     connect(d->page->intOpacity, SIGNAL(valueChanged(int)), SLOT(slotOpacityValueChangedExternally()));
 
     d->compositeOpProperty.reset(new KisMultinodeCompositeOpProperty(nodes));
     d->compositeOpProperty->connectIgnoreCheckBox(d->page->chkCompositeOp);
+    d->compositeOpProperty->connectAutoEnableWidget(d->page->cmbComposite);
     d->compositeOpProperty->connectValueChangedSignal(this, SLOT(slotCompositeOpValueChangedInternally()));
     d->compositeOpProperty->connectValueChangedSignal(&d->updatesCompressor, SLOT(start()));
     connect(d->page->cmbComposite, SIGNAL(currentIndexChanged(int)), SLOT(slotCompositeOpValueChangedExternally()));
@@ -121,6 +124,7 @@ KisDlgLayerProperties::KisDlgLayerProperties(KisNodeList nodes, KisViewManager *
     d->page->colorLabelSelector->setFocusPolicy(Qt::StrongFocus);
     d->colorLabelProperty.reset(new KisMultinodeColorLabelProperty(nodes));
     d->colorLabelProperty->connectIgnoreCheckBox(d->page->chkColorLabel);
+    d->colorLabelProperty->connectAutoEnableWidget(d->page->colorLabelSelector);
     d->colorLabelProperty->connectValueChangedSignal(this, SLOT(slotColorLabelValueChangedInternally()));
     d->colorLabelProperty->connectValueChangedSignal(&d->updatesCompressor, SLOT(start()));
     connect(d->page->colorLabelSelector, SIGNAL(currentIndexChanged(int)), SLOT(slotColorLabelValueChangedExternally()));
diff --git a/libs/ui/kis_multinode_property.cpp b/libs/ui/kis_multinode_property.cpp
index 78d62c0..1bfee50 100644
--- a/libs/ui/kis_multinode_property.cpp
+++ b/libs/ui/kis_multinode_property.cpp
@@ -35,6 +35,11 @@ void MultinodePropertyConnectorInterface::notifyValueChanged() {
     emit sigValueChanged();
 }
 
+void MultinodePropertyConnectorInterface::connectAutoEnableWidget(QWidget *widget)
+{
+    Q_UNUSED(widget);
+}
+
 /******************************************************************/
 /*               MultinodePropertyBaseConnector                   */
 /******************************************************************/
@@ -61,6 +66,45 @@ void MultinodePropertyBaseConnector::connectIgnoreCheckBox(QCheckBox *ignoreBox)
     }
 }
 
+#include <QEvent>
+
+struct AutoEnabler : public QObject {
+    Q_OBJECT
+public:
+    AutoEnabler(QObject *watched, KisMultinodePropertyInterface *property, QObject *parent)
+        : QObject(parent), m_watched(watched), m_property(property)
+    {
+        watched->installEventFilter(this);
+    }
+
+    bool eventFilter(QObject *watched, QEvent * event) {
+        if (watched != m_watched) return false;
+        if (!m_property->isIgnored()) return false;
+
+        if (event->type() == QEvent::MouseButtonPress ||
+            event->type() == QEvent::TabletPress) {
+
+            emit enableWidget(true);
+        }
+
+        return false;
+    }
+Q_SIGNALS:
+    void enableWidget(bool value);
+
+private:
+    QObject *m_watched;
+    KisMultinodePropertyInterface *m_property;
+};
+
+void MultinodePropertyBaseConnector::connectAutoEnableWidget(QWidget *widget)
+{
+    KIS_SAFE_ASSERT_RECOVER_RETURN(m_ignoreBox);
+
+    AutoEnabler *enabler = new AutoEnabler(widget, m_parent, this);
+    connect(enabler, SIGNAL(enableWidget(bool)), m_ignoreBox, SLOT(setChecked(bool)));
+}
+
 void MultinodePropertyBaseConnector::slotIgnoreCheckBoxChanged(int state) {
     m_parent->setIgnored(state != Qt::Checked);
 }
@@ -84,3 +128,5 @@ KisMultinodePropertyInterface::KisMultinodePropertyInterface()
 KisMultinodePropertyInterface::~KisMultinodePropertyInterface()
 {
 }
+
+#include "kis_multinode_property.moc"
diff --git a/libs/ui/kis_multinode_property.h b/libs/ui/kis_multinode_property.h
index 9cd03fe..dc0223c 100644
--- a/libs/ui/kis_multinode_property.h
+++ b/libs/ui/kis_multinode_property.h
@@ -307,6 +307,14 @@ public:
     virtual void connectIgnoreCheckBox(QCheckBox *ignoreBox) = 0;
     void connectValueChangedSignal(const QObject *receiver, const char *method, Qt::ConnectionType type = Qt::AutoConnection);
 
+    /**
+     * Clicking on this widget will automatically enable it,
+     * setting "Ignored" property to false.
+     *
+     * Default implementation does nothing.
+     */
+    virtual void connectAutoEnableWidget(QWidget *widget);
+
 Q_SIGNALS:
     void sigValueChanged();
 
@@ -333,6 +341,8 @@ public:
     void connectIgnoreCheckBox(QCheckBox *ignoreBox);
     void notifyIgnoreChanged();
 
+    void connectAutoEnableWidget(QWidget *widget);
+
 protected:
     void slotIgnoreCheckBoxChanged(int state);
 
@@ -467,6 +477,8 @@ public:
     virtual void connectValueChangedSignal(const QObject *receiver, const char *method, Qt::ConnectionType type = Qt::AutoConnection) = 0;
     virtual void connectIgnoreCheckBox(QCheckBox *ignoreBox) = 0;
 
+    virtual void connectAutoEnableWidget(QWidget *widget) = 0;
+
     virtual KUndo2Command* createPostExecutionUndoCommand() = 0;
 };
 
@@ -594,6 +606,10 @@ public:
         m_connector->connectValueChangedSignal(receiver, method, type);
     }
 
+    void connectAutoEnableWidget(QWidget *widget) {
+        m_connector->connectAutoEnableWidget(widget);
+    }
+
     /**
      * Interface for the connector
      */



More information about the kimageshop mailing list