Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_multi_integer_filter_widget.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Cyrille Berger <cberger@cberger.net>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include <QLabel>
9#include <QLayout>
10#include <QTimer>
11#include <QSpinBox>
12#include <QGridLayout>
13
15#include <klocalizedstring.h>
17#include "kis_slider_spin_box.h"
19
21 : KisSliderSpinBox(parent)
22{
23 setObjectName(name);
24 m_timer = new QTimer(this);
25 m_timer->setObjectName(name);
26 m_timer->setSingleShot(true);
27 connect(m_timer, SIGNAL(timeout()), SLOT(slotValueChanged()));
28 connect(this, SIGNAL(valueChanged(int)), SLOT(slotTimeToUpdate()));
29}
30
35
40
45
46KisIntegerWidgetParam::KisIntegerWidgetParam(qint32 nmin, qint32 nmax, qint32 ninitvalue, const QString & label, const QString & nname, const QString & lockerName)
47 : min(nmin)
48 , max(nmax)
49 , initvalue(ninitvalue)
50 , label(label)
51 , name(nname)
52 , lockerName(lockerName)
53{
54}
55
57 QWidget* parent,
58 const QString& caption,
60 : KisConfigWidget(parent)
61 , m_filterid(filterid)
62 , m_config(new KisFilterConfiguration(filterid, 0, KisGlobalResourcesInterface::instance()))
63{
64 this->setWindowTitle(caption);
65
66 QGridLayout *widgetLayout = new QGridLayout(this);
67 widgetLayout->setColumnStretch(1, 1);
68 widgetLayout->setContentsMargins(0,0,0,0);
69 widgetLayout->setHorizontalSpacing(0);
70
71 for (uint i = 0; i < iwparam.size(); ++i) {
72 KisDelayedActionIntegerInput *widget = new KisDelayedActionIntegerInput(this, iwparam[i].name);
73
74 widget->setRange(iwparam[i].min, iwparam[i].max);
75 widget->setValue(iwparam[i].initvalue);
76 widget->cancelDelayedSignal();
77
78 connect(widget, SIGNAL(valueChangedDelayed(int)), SIGNAL(sigConfigurationItemChanged()));
79
80 QLabel* lbl = new QLabel(iwparam[i].label + ':', this);
81 widgetLayout->addWidget(lbl, i , 0);
82
83 widgetLayout->addWidget(widget, i , 1);
84
85 m_integerWidgets.append(widget);
86
87 // Add an aspect ratio locker if requested;
88 // it must be requested by the second paired spinbox only.
89 if (!iwparam[i].lockerName.isEmpty()) {
90 KoAspectButton *aspectButton = new KoAspectButton(this);
91 aspectButton->setObjectName(iwparam[i].lockerName);
92 widgetLayout->addWidget(aspectButton, i-1, 2, 2, 1);
93 KisAspectRatioLocker *aspectLocker = new KisAspectRatioLocker(this);
94 aspectLocker->connectSpinBoxes(dynamic_cast<KisSliderSpinBox*>(m_integerWidgets[i-1]), dynamic_cast<KisSliderSpinBox*>(widget), aspectButton);
95
96 m_aspectButtons.append(aspectButton);
97 }
98
99
100 }
101 widgetLayout->setRowStretch(iwparam.size(),1);
102
103 QSpacerItem * sp = new QSpacerItem(1, 1);
104 widgetLayout->addItem(sp, iwparam.size(), 0);
105}
106
110
112{
113 if (!config) return;
114
115 if (!m_config) {
117 }
118
119 m_config->fromXML(config->toXML());
120 for (int i = 0; i < nbValues(); ++i) {
121
122 // Keep aspect must be unset first if false, to not interfere with the values
123 Q_FOREACH(KoAspectButton *aspectButton, m_aspectButtons) {
124 if (!config->getBool(aspectButton->objectName(), true)) {
125 aspectButton->setKeepAspectRatio(false);
126 }
127 }
128
130 if (w) {
131 int val = config->getInt(m_integerWidgets[i]->objectName());
132 m_integerWidgets[i]->setValue(val);
133 m_integerWidgets[i]->cancelDelayedSignal();
134 }
135 }
136
137 // Keep aspect must be set last if true, to not interfere with the values
138 Q_FOREACH(KoAspectButton *aspectButton, m_aspectButtons) {
139 if (config->getBool(aspectButton->objectName(), true)) {
140 aspectButton->setKeepAspectRatio(true);
141 }
142 }
143
144}
145
147{
149 if (m_config) {
150 config->fromXML(m_config->toXML());
151 }
152
153 for (int i = 0; i < nbValues(); ++i) {
155 if (w) {
156 config->setProperty(w->objectName(), w->value());
157 }
158 }
159
160 Q_FOREACH(KoAspectButton *aspectButton, m_aspectButtons) {
161 config->setProperty(aspectButton->objectName(), aspectButton->keepAspectRatio());
162 }
163
164 return config;
165}
166
168 return m_integerWidgets.size();
169}
170
172 if (i < m_integerWidgets.size()) {
173 return m_integerWidgets[i]->value();
174 }
175 else {
176 warnKrita << "Trying to access integer widget" << i << "but there are only" << m_integerWidgets.size() << "widgets";
177 return 0;
178 }
179}
180
181
float value(const T *src, size_t ch)
unsigned int uint
PythonPluginManager * instance
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void connectSpinBoxes(SpinBoxType *spinOne, SpinBoxType *spinTwo, KoAspectButton *aspectButton)
void sigConfigurationItemChanged()
void valueChangedDelayed(int value)
KisDelayedActionIntegerInput(QWidget *parent, const QString &name)
the main resource source in Krita
static KisResourcesInterfaceSP instance()
KisPropertiesConfigurationSP configuration() const override
QVector< KoAspectButton * > m_aspectButtons
QVector< KisDelayedActionIntegerInput * > m_integerWidgets
KisMultiIntegerFilterWidget(const QString &filterid, QWidget *parent, const QString &caption, vKisIntegerWidgetParam iwparam)
void setConfiguration(const KisPropertiesConfigurationSP config) override
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
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 ...
bool keepAspectRatio() const
Returns of keeping aspect ratio is on or off.
void setKeepAspectRatio(bool keep)
#define warnKrita
Definition kis_debug.h:87
std::vector< KisIntegerWidgetParam > vKisIntegerWidgetParam
KisIntegerWidgetParam(qint32 nmin, qint32 nmax, qint32 ninitvalue, const QString &label, const QString &nname, const QString &lockerName=QString())