1 /*
2  *  Copyright (c) 2008-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_hairy_bristle_option.h"
19 #include <klocalizedstring.h>
20 
21 #include "ui_wdgbristleoptions.h"
22 #include <brushengine/kis_paintop_lod_limitations.h>
23 
24 
25 class KisBristleOptionsWidget: public QWidget, public Ui::WdgBristleOptions
26 {
27 public:
KisBristleOptionsWidget(QWidget * parent=0)28     KisBristleOptionsWidget(QWidget *parent = 0)
29         : QWidget(parent) {
30         setupUi(this);
31 
32         rndBox->setRange(-10.0, 10.0, 2);
33         rndBox->setValue(2.0);
34 
35         scaleBox->setRange(-10.0, 10.0, 2);
36         scaleBox->setValue(2.0);
37 
38         shearBox->setRange(-2.0, 2.0, 2);
39         shearBox->setValue(0.0);
40 
41         densityBox->setRange(0.0, 100.0, 0);
42         densityBox->setValue(100.0);
43         densityBox->setSuffix(QChar(Qt::Key_Percent));
44     }
45 };
46 
KisHairyBristleOption()47 KisHairyBristleOption::KisHairyBristleOption()
48     : KisPaintOpOption(KisPaintOpOption::GENERAL, false)
49 {
50     setObjectName("KisHairyBristleOption");
51 
52 
53     m_checkable = false;
54     m_options = new KisBristleOptionsWidget();
55 
56     // signals
57     connect(m_options->mousePressureCBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
58     connect(m_options->thresholdCBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
59     connect(m_options->rndBox, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
60     connect(m_options->scaleBox, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
61     connect(m_options->shearBox, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
62     connect(m_options->densityBox, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged()));
63     connect(m_options->connectedCBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
64     connect(m_options->antialiasCBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
65     connect(m_options->compositingCBox, SIGNAL(toggled(bool)), SLOT(emitSettingChanged()));
66     setConfigurationPage(m_options);
67 }
68 
~KisHairyBristleOption()69 KisHairyBristleOption::~KisHairyBristleOption()
70 {
71     delete m_options;
72 }
73 
readOptionSetting(const KisPropertiesConfigurationSP config)74 void KisHairyBristleOption::readOptionSetting(const KisPropertiesConfigurationSP config)
75 {
76     m_options->thresholdCBox->setChecked(config->getBool(HAIRY_BRISTLE_THRESHOLD));
77     m_options->mousePressureCBox->setChecked(config->getBool(HAIRY_BRISTLE_USE_MOUSEPRESSURE));
78     m_options->shearBox->setValue(config->getDouble(HAIRY_BRISTLE_SHEAR));
79     m_options->rndBox->setValue(config->getDouble(HAIRY_BRISTLE_RANDOM));
80     m_options->scaleBox->setValue(config->getDouble(HAIRY_BRISTLE_SCALE));
81     m_options->densityBox->setValue(config->getDouble(HAIRY_BRISTLE_DENSITY));
82     m_options->connectedCBox->setChecked(config->getBool(HAIRY_BRISTLE_CONNECTED));
83     m_options->antialiasCBox->setChecked(config->getBool(HAIRY_BRISTLE_ANTI_ALIASING));
84     m_options->compositingCBox->setChecked(config->getBool(HAIRY_BRISTLE_USE_COMPOSITING));
85 }
86 
87 
writeOptionSetting(KisPropertiesConfigurationSP config) const88 void KisHairyBristleOption::writeOptionSetting(KisPropertiesConfigurationSP config) const
89 {
90     config->setProperty(HAIRY_BRISTLE_THRESHOLD, m_options->thresholdCBox->isChecked());
91     config->setProperty(HAIRY_BRISTLE_USE_MOUSEPRESSURE, m_options->mousePressureCBox->isChecked());
92     config->setProperty(HAIRY_BRISTLE_SCALE, m_options->scaleBox->value());
93     config->setProperty(HAIRY_BRISTLE_SHEAR, m_options->shearBox->value());
94     config->setProperty(HAIRY_BRISTLE_RANDOM, m_options->rndBox->value());
95     config->setProperty(HAIRY_BRISTLE_DENSITY, m_options->densityBox->value());
96     config->setProperty(HAIRY_BRISTLE_CONNECTED, m_options->connectedCBox->isChecked());
97     config->setProperty(HAIRY_BRISTLE_ANTI_ALIASING, m_options->antialiasCBox->isChecked());
98     config->setProperty(HAIRY_BRISTLE_USE_COMPOSITING, m_options->compositingCBox->isChecked());
99 }
100 
lodLimitations(KisPaintopLodLimitations * l) const101 void KisHairyBristleOption::lodLimitations(KisPaintopLodLimitations *l) const
102 {
103     l->limitations << KoID("hairy-brush", i18nc("PaintOp instant preview limitation", "Bristle Brush (the lines will be thinner than on preview)"));
104 }
105