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_standard_uniform_properties_factory.h"
20
21 #include "kis_slider_based_paintop_property.h"
22 #include "kis_paintop_settings.h"
23 #include "kis_paintop_settings_update_proxy.h"
24 #include <kconfig.h>
25 #include <ksharedconfig.h>
26 #include <kconfiggroup.h>
27
28 namespace KisStandardUniformPropertiesFactory {
29
30
31
createProperty(const KoID & id,KisPaintOpSettingsRestrictedSP settings,KisPaintopSettingsUpdateProxy * updateProxy)32 KisUniformPaintOpPropertySP createProperty(const KoID &id,
33 KisPaintOpSettingsRestrictedSP settings,
34 KisPaintopSettingsUpdateProxy *updateProxy)
35 {
36 return createProperty(id.id(), settings, updateProxy);
37 }
38
createProperty(const QString & id,KisPaintOpSettingsRestrictedSP settings,KisPaintopSettingsUpdateProxy * updateProxy)39 KisUniformPaintOpPropertySP createProperty(const QString &id,
40 KisPaintOpSettingsRestrictedSP settings,
41 KisPaintopSettingsUpdateProxy *updateProxy)
42 {
43 KisUniformPaintOpPropertySP result;
44
45
46 if (id == size.id()) {
47 KisDoubleSliderBasedPaintOpPropertyCallback *prop =
48 new KisDoubleSliderBasedPaintOpPropertyCallback(
49 KisDoubleSliderBasedPaintOpPropertyCallback::Double,
50 "size",
51 i18n("Size"),
52 settings, 0);
53
54
55
56 prop->setRange(0, KSharedConfig::openConfig()->group("").readEntry("maximumBrushSize", 1000));
57 prop->setDecimals(2);
58 prop->setSingleStep(1);
59 prop->setExponentRatio(3.0);
60 prop->setSuffix(i18n(" px"));
61
62 prop->setReadCallback(
63 [](KisUniformPaintOpProperty *prop) {
64 prop->setValue(prop->settings()->paintOpSize());
65 });
66 prop->setWriteCallback(
67 [](KisUniformPaintOpProperty *prop) {
68 prop->settings()->setPaintOpSize(prop->value().toReal());
69 });
70
71 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
72 prop->requestReadValue();
73 result = toQShared(prop);
74 } else if (id == opacity.id()) {
75 KisDoubleSliderBasedPaintOpPropertyCallback *prop =
76 new KisDoubleSliderBasedPaintOpPropertyCallback(
77 KisDoubleSliderBasedPaintOpPropertyCallback::Double,
78 opacity.id(),
79 opacity.name(),
80 settings, 0);
81
82 prop->setRange(0.0, 1.0);
83 prop->setSingleStep(0.01);
84
85 prop->setReadCallback(
86 [](KisUniformPaintOpProperty *prop) {
87 prop->setValue(prop->settings()->paintOpOpacity());
88 });
89 prop->setWriteCallback(
90 [](KisUniformPaintOpProperty *prop) {
91 prop->settings()->setPaintOpOpacity(prop->value().toReal());
92 });
93
94 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
95 prop->requestReadValue();
96 result = toQShared(prop);
97 } else if (id == flow.id()) {
98 KisDoubleSliderBasedPaintOpPropertyCallback *prop =
99 new KisDoubleSliderBasedPaintOpPropertyCallback(
100 KisDoubleSliderBasedPaintOpPropertyCallback::Double,
101 flow.id(),
102 flow.name(),
103 settings, 0);
104
105 prop->setRange(0.0, 1.0);
106 prop->setSingleStep(0.01);
107
108 prop->setReadCallback(
109 [](KisUniformPaintOpProperty *prop) {
110 prop->setValue(prop->settings()->paintOpFlow());
111 });
112 prop->setWriteCallback(
113 [](KisUniformPaintOpProperty *prop) {
114 prop->settings()->setPaintOpFlow(prop->value().toReal());
115 });
116
117 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
118 prop->requestReadValue();
119 result = toQShared(prop);
120 } else if (id == angle.id()) {
121 qFatal("Not implemented");
122 } else if (id == spacing.id()) {
123 qFatal("Not implemented");
124 }
125
126 if (!result) {
127 KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "Unknown Uniform property id!");
128 }
129
130 return result;
131 }
132 }
133