File indexing completed on 2024-05-12 16:01:34

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_multinode_property.h"
0008 
0009 /******************************************************************/
0010 /*               MultinodePropertyConnectorInterface              */
0011 /******************************************************************/
0012 
0013 MultinodePropertyConnectorInterface::~MultinodePropertyConnectorInterface()
0014 {
0015 }
0016 
0017 void MultinodePropertyConnectorInterface::connectValueChangedSignal(const QObject *receiver, const char *method, Qt::ConnectionType type) {
0018     connect(this, SIGNAL(sigValueChanged()), receiver, method, type);
0019     notifyValueChanged();
0020 }
0021 
0022 void MultinodePropertyConnectorInterface::notifyValueChanged() {
0023     emit sigValueChanged();
0024 }
0025 
0026 void MultinodePropertyConnectorInterface::connectAutoEnableWidget(QWidget *widget)
0027 {
0028     Q_UNUSED(widget);
0029 }
0030 
0031 /******************************************************************/
0032 /*               MultinodePropertyBaseConnector                   */
0033 /******************************************************************/
0034 
0035 MultinodePropertyBaseConnector::MultinodePropertyBaseConnector(KisMultinodePropertyInterface *parent)
0036     : m_parent(parent)
0037 {
0038 }
0039 
0040 void MultinodePropertyBaseConnector::connectIgnoreCheckBox(QCheckBox *ignoreBox) {
0041     m_ignoreBox = ignoreBox;
0042 
0043     if (!m_parent->isIgnored() && !m_parent->savedValuesDiffer()) {
0044         m_ignoreBox->setEnabled(false);
0045         m_ignoreBox->setChecked(true);
0046 
0047         if (m_parent->haveTheOnlyNode()) {
0048             m_ignoreBox->setVisible(false);
0049         }
0050     } else {
0051         connect(m_ignoreBox, SIGNAL(stateChanged(int)), SLOT(slotIgnoreCheckBoxChanged(int)));
0052         m_ignoreBox->setEnabled(true);
0053         m_ignoreBox->setChecked(!m_parent->isIgnored());
0054     }
0055 }
0056 
0057 #include <QEvent>
0058 
0059 struct AutoEnabler : public QObject {
0060     Q_OBJECT
0061 public:
0062     AutoEnabler(QObject *watched, KisMultinodePropertyInterface *property, QObject *parent)
0063         : QObject(parent), m_watched(watched), m_property(property)
0064     {
0065         watched->installEventFilter(this);
0066     }
0067 
0068     bool eventFilter(QObject *watched, QEvent * event) override {
0069         if (watched != m_watched) return false;
0070         if (!m_property->isIgnored()) return false;
0071 
0072         if (event->type() == QEvent::MouseButtonPress ||
0073             event->type() == QEvent::TabletPress) {
0074 
0075             emit enableWidget(true);
0076         }
0077 
0078         return false;
0079     }
0080 Q_SIGNALS:
0081     void enableWidget(bool value);
0082 
0083 private:
0084     QObject *m_watched;
0085     KisMultinodePropertyInterface *m_property;
0086 };
0087 
0088 void MultinodePropertyBaseConnector::connectAutoEnableWidget(QWidget *widget)
0089 {
0090     KIS_SAFE_ASSERT_RECOVER_RETURN(m_ignoreBox);
0091 
0092     AutoEnabler *enabler = new AutoEnabler(widget, m_parent, this);
0093     connect(enabler, SIGNAL(enableWidget(bool)), m_ignoreBox, SLOT(setChecked(bool)));
0094 }
0095 
0096 void MultinodePropertyBaseConnector::slotIgnoreCheckBoxChanged(int state) {
0097     m_parent->setIgnored(state != Qt::Checked);
0098 }
0099 
0100 void MultinodePropertyBaseConnector::notifyIgnoreChanged() {
0101     if (!m_ignoreBox) return;
0102 
0103     if (m_ignoreBox->isChecked() != !m_parent->isIgnored()) {
0104         m_ignoreBox->setChecked(!m_parent->isIgnored());
0105     }
0106 }
0107 
0108 /******************************************************************/
0109 /*               KisMultinodePropertyInterface                    */
0110 /******************************************************************/
0111 
0112 KisMultinodePropertyInterface::KisMultinodePropertyInterface()
0113 {
0114 }
0115 
0116 KisMultinodePropertyInterface::~KisMultinodePropertyInterface()
0117 {
0118 }
0119 
0120 #include "kis_multinode_property.moc"