1 /*
2 * Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "kis_uniform_paintop_property.h"
20
21 #include <QVariant>
22 #include "kis_debug.h"
23 #include "kis_paintop_settings.h"
24
25 struct KisUniformPaintOpProperty::Private
26 {
PrivateKisUniformPaintOpProperty::Private27 Private(Type _type,
28 const QString &_id,
29 const QString &_name,
30 KisPaintOpSettingsSP _settings)
31 : type(_type),
32 id(_id),
33 name(_name),
34 settings(_settings),
35 isReadingValue(false),
36 isWritingValue(false) {}
37
38 Type type;
39 QString id;
40 QString name;
41
42 QVariant value;
43
44 KisPaintOpSettingsSP settings;
45 bool isReadingValue;
46 bool isWritingValue;
47 };
48
KisUniformPaintOpProperty(Type type,const QString & id,const QString & name,KisPaintOpSettingsRestrictedSP settings,QObject * parent)49 KisUniformPaintOpProperty::KisUniformPaintOpProperty(Type type,
50 const QString &id,
51 const QString &name,
52 KisPaintOpSettingsRestrictedSP settings,
53 QObject *parent)
54 : QObject(parent),
55 m_d(new Private(type, id, name, settings))
56 {
57 }
58
KisUniformPaintOpProperty(const QString & id,const QString & name,KisPaintOpSettingsRestrictedSP settings,QObject * parent)59 KisUniformPaintOpProperty::KisUniformPaintOpProperty(const QString &id,
60 const QString &name,
61 KisPaintOpSettingsRestrictedSP settings,
62 QObject *parent)
63 : QObject(parent),
64 m_d(new Private(Bool, id, name, settings))
65 {
66 }
67
~KisUniformPaintOpProperty()68 KisUniformPaintOpProperty::~KisUniformPaintOpProperty()
69 {
70 }
71
id() const72 QString KisUniformPaintOpProperty::id() const
73 {
74 return m_d->id;
75 }
76
name() const77 QString KisUniformPaintOpProperty::name() const
78 {
79 return m_d->name;
80 }
81
type() const82 KisUniformPaintOpProperty::Type KisUniformPaintOpProperty::type() const
83 {
84 return m_d->type;
85 }
86
value() const87 QVariant KisUniformPaintOpProperty::value() const
88 {
89 return m_d->value;
90 }
91
createPropertyWidget()92 QWidget *KisUniformPaintOpProperty::createPropertyWidget()
93 {
94 return 0;
95 }
96
setValue(const QVariant & value)97 void KisUniformPaintOpProperty::setValue(const QVariant &value)
98 {
99 if (m_d->value == value) return;
100 m_d->value = value;
101
102 emit valueChanged(value);
103
104 if (!m_d->isReadingValue) {
105 m_d->isWritingValue = true;
106 writeValueImpl();
107 m_d->isWritingValue = false;
108 }
109 }
110
requestReadValue()111 void KisUniformPaintOpProperty::requestReadValue()
112 {
113 if (m_d->isWritingValue) return;
114
115 m_d->isReadingValue = true;
116 readValueImpl();
117 m_d->isReadingValue = false;
118 }
119
settings() const120 KisPaintOpSettingsSP KisUniformPaintOpProperty::settings() const
121 {
122 // correct conversion weak-to-strong shared pointer
123 return m_d->settings ? m_d->settings : KisPaintOpSettingsSP();
124 }
125
isVisible() const126 bool KisUniformPaintOpProperty::isVisible() const
127 {
128 return true;
129 }
130
readValueImpl()131 void KisUniformPaintOpProperty::readValueImpl()
132 {
133 }
134
writeValueImpl()135 void KisUniformPaintOpProperty::writeValueImpl()
136 {
137 }
138
139 #include "kis_callback_based_paintop_property_impl.h"
140 template class KisCallbackBasedPaintopProperty<KisUniformPaintOpProperty>;
141