Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_uniform_paintop_property_widget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QVBoxLayout>
10#include <QCheckBox>
11#include <QComboBox>
12
13#include "kis_slider_spin_box.h"
14#include <KisAngleSelector.h>
18#include "kis_debug.h"
19
20/****************************************************************/
21/* KisUniformPaintOpPropertyWidget */
22/****************************************************************/
23
32
34 : QWidget(parent),
35 m_d(new Private(property))
36{
38 conn->connectForwardVariant(property.data(), SIGNAL(valueChanged(QVariant)),
39 this, SLOT(setValue(QVariant)));
40
41 conn->connectBackwardVariant(this, SIGNAL(valueChanged(QVariant)),
42 property.data(), SLOT(setValue(QVariant)));
43}
44
48
53
55{
56 for(int i=0; i<this->children().size(); i++) {
57 QWidget *w = qobject_cast<QWidget*>(this->children().at(i));
58 if (w) {
59 w->setPalette(pal);
60 }
61 }
62}
63
64/****************************************************************/
65/* KisUniformPaintOpPropertyIntSlider */
66/****************************************************************/
67
69 : KisUniformPaintOpPropertyWidget(property, parent)
70{
71 const QString prefix = QString("%1: ").arg(property->name());
72 QVBoxLayout *layout = new QVBoxLayout(this);
73
74 KisIntSliderBasedPaintOpProperty *sliderProperty =
75 dynamic_cast<KisIntSliderBasedPaintOpProperty*>(property.data());
76 KIS_ASSERT_RECOVER_RETURN(sliderProperty);
77
80
82 KisAngleSelector *slider = new KisAngleSelector(this);
83 slider->setPrefix(prefix);
84 slider->setDecimals(0);
85 slider->setRange(static_cast<qreal>(sliderProperty->min()), static_cast<qreal>(sliderProperty->max()));
87
88 slider->setAngle(static_cast<qreal>(sliderProperty->value().toInt()));
89 connect(slider, &KisAngleSelector::angleChanged, this, [this](qreal angle) { slotSliderChanged(static_cast<int>(angle)); });
90
91 m_slider = slider;
92 } else {
93 KisSliderSpinBox *slider = new KisSliderSpinBox(this);
94 slider->setBlockUpdateSignalOnDrag(true);
95 slider->setRange(sliderProperty->min(), sliderProperty->max());
96 slider->setSingleStep(sliderProperty->singleStep());
97 slider->setPageStep(sliderProperty->pageStep());
98 slider->setPrefix(prefix);
99 slider->setSuffix(sliderProperty->suffix());
100 slider->setExponentRatio(sliderProperty->exponentRatio());
101
102 slider->setValue(sliderProperty->value().toInt());
103 connect(slider, SIGNAL(valueChanged(int)), SLOT(slotSliderChanged(int)));
104
105 m_slider = slider;
106 }
107
108 layout->addWidget(m_slider);
109}
110
112{
113 if (dynamic_cast<KisAngleSelector*>(m_slider)) {
114 dynamic_cast<KisAngleSelector*>(m_slider)->setAngle(static_cast<qreal>(value.toInt()));
115 } else {
117 dynamic_cast<KisSliderSpinBox*>(m_slider)->setValue(value.toInt());
118 }
119}
120
125
127{
128 KisIntSliderBasedPaintOpProperty *sliderProperty =
129 dynamic_cast<KisIntSliderBasedPaintOpProperty*>(property().data());
130 KIS_ASSERT_RECOVER_RETURN(sliderProperty);
131
132 if (KisAngleSelector *slider = dynamic_cast<KisAngleSelector*>(m_slider)) {
133 slider->setRange(sliderProperty->min(), sliderProperty->max());
134 } else if (KisSliderSpinBox *slider = dynamic_cast<KisSliderSpinBox*>(m_slider)) {
135 slider->setRange(sliderProperty->min(), sliderProperty->max());
136 }
137}
138
139/****************************************************************/
140/* KisUniformPaintOpPropertyDoubleSlider */
141/****************************************************************/
142
144 : KisUniformPaintOpPropertyWidget(property, parent)
145{
146 const QString prefix = QString("%1: ").arg(property->name());
147 QVBoxLayout *layout = new QVBoxLayout(this);
148
150 dynamic_cast<KisDoubleSliderBasedPaintOpProperty*>(property.data());
151 KIS_ASSERT_RECOVER_RETURN(sliderProperty);
152
155
157 KisAngleSelector *slider = new KisAngleSelector(this);
158 slider->setPrefix(prefix);
159 slider->setDecimals(sliderProperty->decimals());
160 slider->setRange(sliderProperty->min(), sliderProperty->max());
162
163 slider->setAngle(sliderProperty->value().toReal());
164 connect(slider, SIGNAL(angleChanged(qreal)), SLOT(slotSliderChanged(qreal)));
165
166 m_slider = slider;
167 } else {
169 slider->setBlockUpdateSignalOnDrag(true);
170 slider->setRange(sliderProperty->min(), sliderProperty->max(), sliderProperty->decimals());
171 slider->setSingleStep(sliderProperty->singleStep());
172 slider->setPrefix(prefix);
173 slider->setSuffix(sliderProperty->suffix());
174 slider->setExponentRatio(sliderProperty->exponentRatio());
175
176 slider->setValue(sliderProperty->value().toReal());
177 connect(slider, SIGNAL(valueChanged(qreal)), SLOT(slotSliderChanged(qreal)));
178
179 m_slider = slider;
180 }
181
182 layout->addWidget(m_slider);
183}
184
186{
187 if (dynamic_cast<KisAngleSelector*>(m_slider)) {
188 dynamic_cast<KisAngleSelector*>(m_slider)->setAngle(value.toInt());
189 } else {
191 dynamic_cast<KisDoubleSliderSpinBox*>(m_slider)->setValue(value.toReal());
192 }
193}
194
199
201{
203 dynamic_cast<KisDoubleSliderBasedPaintOpProperty*>(property().data());
204 KIS_ASSERT_RECOVER_RETURN(sliderProperty);
205
206 if (KisAngleSelector *slider = dynamic_cast<KisAngleSelector*>(m_slider)) {
207 slider->setRange(sliderProperty->min(), sliderProperty->max());
208 } else if (KisDoubleSliderSpinBox *slider = dynamic_cast<KisDoubleSliderSpinBox*>(m_slider)) {
209 slider->setRange(sliderProperty->min(), sliderProperty->max());
210 }
211}
212
213/****************************************************************/
214/* KisUniformPaintOpPropertyCheckBox */
215/****************************************************************/
216
218 : KisUniformPaintOpPropertyWidget(property, parent)
219{
220 QVBoxLayout *layout = new QVBoxLayout(this);
221
222 m_checkBox = new QCheckBox(property->name(), this);
223 m_checkBox->setChecked(property->value().toBool());
224 connect(m_checkBox, SIGNAL(toggled(bool)), SLOT(slotCheckBoxChanged(bool)));
225
226 layout->addWidget(m_checkBox);
227}
228
230{
231 m_checkBox->setChecked(value.toBool());
232}
233
238
239/****************************************************************/
240/* KisUniformPaintOpPropertyComboBox */
241/****************************************************************/
242
244 : KisUniformPaintOpPropertyWidget(property, parent)
245{
246 QVBoxLayout *layout = new QVBoxLayout(this);
247
248 KisComboBasedPaintOpProperty *comboProperty =
249 dynamic_cast<KisComboBasedPaintOpProperty*>(property.data());
250 KIS_ASSERT_RECOVER_RETURN(comboProperty);
251
252 const QList<QString> items = comboProperty->items();
253 const QList<QIcon> icons = comboProperty->icons();
254
255 m_comboBox = new QComboBox(this);
256
257 KIS_SAFE_ASSERT_RECOVER_RETURN(icons.isEmpty() ||
258 items.size() == icons.size());
259
260 if (!icons.isEmpty()) {
261 auto itemIt = items.constBegin();
262 auto iconIt = icons.constBegin();
263
264 while (itemIt != items.constEnd() &&
265 iconIt != icons.constEnd()) {
266
267 m_comboBox->addItem(*iconIt, *itemIt);
268
269 ++itemIt;
270 ++iconIt;
271 }
272 } else {
273 Q_FOREACH (const QString &item, items) {
274 m_comboBox->addItem(item);
275 }
276 }
277
278 m_comboBox->setCurrentIndex(property->value().toInt());
279 connect(m_comboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotComboBoxChanged(int)));
280
281 layout->addWidget(m_comboBox);
282}
283
285{
286 m_comboBox->setCurrentIndex(value.toInt());
287}
288
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void connectBackwardVariant(QObject *sender, const char *signal, QObject *receiver, const char *method)
void connectForwardVariant(QObject *sender, const char *signal, QObject *receiver, const char *method)
A widget with several options to select an angle.
@ FlipOptionsMode_MenuButton
The flip options are shown as a menu accessible via a options button.
void setPrefix(const QString &newPrefix)
Sets the prefix shown in the spin box.
void setFlipOptionsMode(FlipOptionsMode newMode)
Sets the mode in which the flip options should be shown.
void setAngle(qreal newAngle)
Sets the current angle.
void setRange(qreal newMinimum, qreal newMaximum)
Sets the minimum and maximum values for the angle.
void setDecimals(int newNumberOfDecimals)
Sets the number of decimals (precision) used by the angle.
void angleChanged(qreal angle)
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
void setValue(qreal newValue)
void setRange(qreal newMinimum, qreal newMaximum, int newNumberOfDecimals=0, bool computeNewFastSliderStep=true)
Set the minimum and the maximum values of the range.
void setBlockUpdateSignalOnDrag(bool newBlockUpdateSignalOnDrag)
void setExponentRatio(qreal newExponentRatio)
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
void setBlockUpdateSignalOnDrag(bool newBlockUpdateSignalOnDrag)
Set if the spinbox should not Q_EMIT signals when dragging the slider.
void setExponentRatio(qreal newExponentRatio)
Set the exponent used by a power function to modify the values as a function of the horizontal positi...
void setValue(int newValue)
void setRange(int newMinimum, int newMaximum, bool computeNewFastSliderStep=true)
Set the minimum and the maximum values of the range, computing a new "fast slider step" based on the ...
void setPageStep(int newPageStep)
Does nothing currently.
KisUniformPaintOpPropertyCheckBox(KisUniformPaintOpPropertySP property, QWidget *parent)
KisUniformPaintOpPropertyComboBox(KisUniformPaintOpPropertySP property, QWidget *parent)
KisUniformPaintOpPropertyDoubleSlider(KisUniformPaintOpPropertySP property, QWidget *parent)
KisUniformPaintOpPropertyIntSlider(KisUniformPaintOpPropertySP property, QWidget *parent)
void valueChanged(const QVariant &value)
virtual void setValue(const QVariant &value)=0
KisUniformPaintOpPropertyWidget(KisUniformPaintOpPropertySP property, QWidget *parent)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75