Krita Source Code Documentation
Loading...
Searching...
No Matches
rnuminput.cpp
Go to the documentation of this file.
1
28#include "rnuminput.h"
29
30// C++ includes
31
32#include <cmath>
33
34// Qt includes
35
36#include <QToolButton>
37#include <QApplication>
38#include <QStyle>
39#include <QHBoxLayout>
40
41// KDE includes
42
43#include <klocalizedstring.h>
44
45// Local includes
46
47#include "rsliderspinbox.h"
48
49#include <kis_icon_utils.h>
50
51namespace KDcrawIface
52{
53
54class Q_DECL_HIDDEN RIntNumInput::Private
55{
56
57public:
58
60 {
61 defaultValue = 0;
62 resetButton = 0;
63 input = 0;
64 }
65
67
68 QToolButton* resetButton;
69
71};
72
73RIntNumInput::RIntNumInput(QWidget* const parent)
74 : QWidget(parent),
75 d(new Private)
76{
77 QHBoxLayout* const hlay = new QHBoxLayout(this);
78 d->input = new RSliderSpinBox(this);
79 d->resetButton = new QToolButton(this);
80 d->resetButton->setAutoRaise(true);
81 d->resetButton->setFocusPolicy(Qt::NoFocus);
82 d->resetButton->setIcon(KisIconUtils::loadIcon("document-revert").pixmap(16, 16));
83 d->resetButton->setToolTip(i18nc("@info:tooltip", "Reset to default value"));
84
85 hlay->addWidget(d->input);
86 hlay->addWidget(d->resetButton);
87 hlay->setContentsMargins(QMargins());
88 hlay->setStretchFactor(d->input, 10);
89 hlay->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing));
90
91 // -------------------------------------------------------------
92
93 connect(d->resetButton, &QToolButton::clicked,
95
98}
99
101{
102 delete d;
103}
104
105void RIntNumInput::setRange(int min, int max, int step)
106{
107 d->input->setRange(min, max);
108 d->input->setSingleStep(step);
109}
110
112{
113 return d->input->value();
114}
115
117{
118 d->input->setValue(v);
119}
120
122{
123 return d->defaultValue;
124}
125
127{
128 d->defaultValue = v;
129 d->input->setValue(d->defaultValue);
131}
132
133void RIntNumInput::setSuffix(const QString& suffix)
134{
135 d->input->setSuffix(suffix);
136}
137
139{
140 d->input->setValue(d->defaultValue);
141 d->resetButton->setEnabled(false);
142 Q_EMIT reset();
143}
144
146{
147 d->resetButton->setEnabled(v != d->defaultValue);
148 Q_EMIT valueChanged(v);
149}
150
151// ----------------------------------------------------
152
153class Q_DECL_HIDDEN RDoubleNumInput::Private
154{
155
156public:
157
159 {
160 defaultValue = 0.0;
161 resetButton = 0;
162 input = 0;
163 }
164
166
167 QToolButton* resetButton;
168
170};
171
173 : QWidget(parent),
174 d(new Private)
175{
176 QHBoxLayout* const hlay = new QHBoxLayout(this);
177 d->input = new RDoubleSliderSpinBox(this);
178 d->resetButton = new QToolButton(this);
179 d->resetButton->setAutoRaise(true);
180 d->resetButton->setFocusPolicy(Qt::NoFocus);
181 d->resetButton->setIcon(KisIconUtils::loadIcon("document-revert").pixmap(16, 16));
182 d->resetButton->setToolTip(i18nc("@info:tooltip", "Reset to default value"));
183
184 hlay->addWidget(d->input);
185 hlay->addWidget(d->resetButton);
186 hlay->setContentsMargins(QMargins());
187 hlay->setStretchFactor(d->input, 10);
188 hlay->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing));
189
190 // -------------------------------------------------------------
191
192 connect(d->resetButton, &QToolButton::clicked,
194
197}
198
200{
201 delete d;
202}
203
205{
206 d->input->setRange(d->input->minimum(), d->input->maximum(), p);
207}
208
209void RDoubleNumInput::setRange(double min, double max, double step)
210{
211 d->input->setRange(min, max, (int) -floor(log10(step)));
212 d->input->setFastSliderStep(5 * step);
213 d->input->setSingleStep(step);
214}
215
217{
218 return d->input->value();
219}
220
222{
223 d->input->setValue(v);
224}
225
227{
228 return d->defaultValue;
229}
230
232{
233 d->defaultValue = v;
234 d->input->setValue(d->defaultValue);
236}
237
238void RDoubleNumInput::setSuffix(const QString& suffix)
239{
240 d->input->setSuffix(suffix);
241}
242
244{
245 d->input->setValue(d->defaultValue);
246 d->resetButton->setEnabled(false);
247 Q_EMIT reset();
248}
249
251{
252 d->resetButton->setEnabled(v != d->defaultValue);
253 Q_EMIT valueChanged(v);
254}
255
256} // namespace KDcrawIface
const Params2D p
qreal v
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setRange(double min, double max, double step)
RDoubleSliderSpinBox * input
void setSuffix(const QString &suffix)
RDoubleNumInput(QWidget *const parent=0)
QToolButton * resetButton
Definition rnuminput.cpp:68
RSliderSpinBox * input
Definition rnuminput.cpp:70
RIntNumInput(QWidget *const parent=0)
Definition rnuminput.cpp:73
void setRange(int min, int max, int step)
void setSuffix(const QString &suffix)
void valueChanged(int value)
QIcon loadIcon(const QString &name)
Integer and double num input widget re-implemented with a reset button to switch to a default value.
Save space slider widget.