1 /*
2  *  Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@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 #include "kis_experimentop_option.h"
19 #include <klocalizedstring.h>
20 
21 #include <brushengine/kis_paintop_lod_limitations.h>
22 
23 #include "ui_wdgexperimentoptions.h"
24 
25 class KisExperimentOpOptionsWidget: public QWidget, public Ui::WdgExperimentOptions
26 {
27 public:
KisExperimentOpOptionsWidget(QWidget * parent=0)28     KisExperimentOpOptionsWidget(QWidget *parent = 0)
29         : QWidget(parent) {
30         setupUi(this);
31 
32         speed->setRange(0.0, 100.0, 0);
33         speed->setSuffix(QChar(Qt::Key_Percent));
34         speed->setValue(42.0);
35         speed->setSingleStep(1.0);
36 
37         smoothThreshold->setRange(0.0, 100.0, 0);
38         smoothThreshold->setSuffix(i18n(" px"));
39         smoothThreshold->setValue(20.0);
40         smoothThreshold->setSingleStep(1.0);
41 
42         displaceStrength->setRange(0.0, 100.0, 0);
43         displaceStrength->setSuffix(QChar(Qt::Key_Percent));
44         displaceStrength->setValue(42.0);
45         displaceStrength->setSingleStep(1.0);
46     }
47 };
48 
KisExperimentOpOption()49 KisExperimentOpOption::KisExperimentOpOption()
50     : KisPaintOpOption(KisPaintOpOption::GENERAL, false)
51 {
52     setObjectName("KisExperimentOpOption");
53 
54     m_checkable = false;
55     m_options = new KisExperimentOpOptionsWidget();
56 
57     connect(m_options->displaceCHBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
58     connect(m_options->displaceStrength, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
59     connect(m_options->speedCHBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
60     connect(m_options->speed, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
61     connect(m_options->smoothCHBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
62     connect(m_options->smoothThreshold, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
63 
64     connect(m_options->displaceStrength, SIGNAL(valueChanged(qreal)), SLOT(enableDisplacement(qreal)));
65     connect(m_options->speed, SIGNAL(valueChanged(qreal)), SLOT(enableSpeed(qreal)));
66     connect(m_options->smoothThreshold, SIGNAL(valueChanged(qreal)), SLOT(enableSmooth(qreal)));
67 
68     connect(m_options->windingFillCHBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
69     connect(m_options->hardEdgeCHBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
70 
71     connect(m_options->patternButton, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
72     connect(m_options->solidColorButton, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
73 
74     setConfigurationPage(m_options);
75 }
76 
~KisExperimentOpOption()77 KisExperimentOpOption::~KisExperimentOpOption()
78 {
79     delete m_options;
80 }
81 
writeOptionSetting(KisPropertiesConfigurationSP setting) const82 void KisExperimentOpOption::writeOptionSetting(KisPropertiesConfigurationSP setting) const
83 {
84     ExperimentOption op;
85 
86     op.isDisplacementEnabled = m_options->displaceCHBox->isChecked();
87     op.displacement = m_options->displaceStrength->value();
88     op.isSpeedEnabled = m_options->speedCHBox->isChecked();
89     op.speed = m_options->speed->value();
90     op.isSmoothingEnabled = m_options->smoothCHBox->isChecked();
91     op.smoothing = m_options->smoothThreshold->value();
92     op.windingFill = m_options->windingFillCHBox->isChecked();
93     op.hardEdge = m_options->hardEdgeCHBox->isChecked();
94 
95     if (m_options->patternButton->isChecked()) {
96         op.fillType = ExperimentFillType::Pattern;
97     } else {
98         op.fillType = ExperimentFillType::SolidColor;
99     }
100 
101     op.writeOptionSetting(setting);
102 }
103 
readOptionSetting(const KisPropertiesConfigurationSP setting)104 void KisExperimentOpOption::readOptionSetting(const KisPropertiesConfigurationSP setting)
105 {
106     ExperimentOption op;
107     op.readOptionSetting(setting);
108 
109     m_options->displaceStrength->setValue(op.displacement);
110     m_options->speed->setValue(op.speed);
111     m_options->smoothThreshold->setValue(op.smoothing);
112     m_options->windingFillCHBox->setChecked(op.windingFill);
113     m_options->hardEdgeCHBox->setChecked(op.hardEdge);
114 
115     m_options->speedCHBox->setChecked(op.isSpeedEnabled);
116     m_options->smoothCHBox->setChecked(op.isSmoothingEnabled);
117     m_options->displaceCHBox->setChecked(op.isDisplacementEnabled);
118 
119 
120     if (op.fillType == ExperimentFillType::Pattern) {
121         m_options->patternButton->setChecked(true);
122     } else {
123         m_options->solidColorButton->setChecked(true);
124     }
125 }
126 
enableCheckBox(QCheckBox * checkBox,qreal sliderValue)127 inline void enableCheckBox(QCheckBox *checkBox, qreal sliderValue)
128 {
129     checkBox->setChecked(sliderValue > 0);
130 }
131 
enableSpeed(qreal value)132 void KisExperimentOpOption::enableSpeed(qreal value)
133 {
134     enableCheckBox(m_options->speedCHBox, value);
135 }
136 
enableSmooth(qreal value)137 void KisExperimentOpOption::enableSmooth(qreal value)
138 {
139     enableCheckBox(m_options->smoothCHBox, value);
140 }
141 
enableDisplacement(qreal value)142 void KisExperimentOpOption::enableDisplacement(qreal value)
143 {
144     enableCheckBox(m_options->displaceCHBox, value);
145 }
146 
lodLimitations(KisPaintopLodLimitations * l) const147 void KisExperimentOpOption::lodLimitations(KisPaintopLodLimitations *l) const
148 {
149     if (m_options->displaceCHBox->isChecked()) {
150         l->blockers << KoID("experiment-displacement", i18nc("PaintOp instant preview limitation", "Displacement Option"));
151     }
152 }
153