Krita

SliderSpinBox.h
1/*
2 * SPDX-FileCopyrightText: 2010 Justin Noel <justin@ics.com>
3 * SPDX-FileCopyrightText: 2021 Deif Lou <ginoba@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#ifndef LIBKIS_SLIDERSPINBOX_H
9#define LIBKIS_SLIDERSPINBOX_H
10
11#include "kis_slider_spin_box.h"
12#include "IntParseSpinBox.h"
13#include "DoubleParseSpinBox.h"
14
15#include "kritalibkis_export.h"
16#include "libkis.h"
17
18template <typename SpinBoxTypeTP, typename BaseSpinBoxTypeTP>
19class KisSliderSpinBoxPrivate;
20
21/**
22 * @brief This class is a wrapper around KisSliderSpinBox, a spinbox in which
23 * you can click and drag to set the value, with a slider like bar displayed
24 * inside. The widget itself is accessed with the widget() function.
25 *
26 * The value can be set by click and dragging with the mouse or pen or by
27 * typing in with the keyboard. To enter the edit mode, in which the keyboard
28 * can be used, one has to right-click inside the spinbox or click and hold
29 * the pointer inside or press the enter key. To leave the edit mode, one
30 * can press the enter key again, in which case the value is committed, or
31 * press the escape key, in which case the value is rejected.
32 *
33 * When dragging with the pointer, one can fine tune the value by dragging
34 * far away vertically from the spinbox. The farther the pointer is, the
35 * slower the value will change. If the pointer is inside the spinbox plus
36 * a certain margin, the value will not be scaled.
37 * By pressing the shift key the slow down will be even more pronounced and
38 * by pressing the control key the value will snap to the increment set by
39 * @ref setFastSliderStep. The two keys can be used at the same time.
40 *
41 * A "soft range" can be set to make the slider display only a sub-range of the
42 * spinbox range. This way one can have a large range but display and set with
43 * the pointer and with more precision only the most commonly used sub-set
44 * of values.
45 * A value outside the "soft range" can be set by entering the edit
46 * mode and using the keyboard.
47 * The "soft range" is considered valid if the "soft maximum" is greater than
48 * the "soft minimum".
49 */
50class KRITALIBKIS_EXPORT SliderSpinBox : public IntParseSpinBox
51{
52 Q_OBJECT
53 Q_DISABLE_COPY(SliderSpinBox)
54
55
56public:
57 explicit SliderSpinBox();
58 ~SliderSpinBox() override;
59
60public Q_SLOTS:
61
62 /**
63 * @brief Get the internal KisSliderSpinBox as a QWidget, so it may be
64 * added to a UI
65 *
66 * @return the internal KisSliderSpinBox as a QWidget
67 */
68 QWidget* widget() const;
69
70 /**
71 * @brief Get the value to which multiples the spinbox value snaps when
72 * the control key is pressed
73 *
74 * @return the value to which multiples the spinbox value snaps when
75 * the control key is pressed
76 * @see setFastSliderStep(int)
77 */
78 int fastSliderStep() const;
79 /**
80 * @brief Get the minimum value of the "soft range"
81 * @return the minimum value of the "soft range"
82 * @see setSoftMinimum(int)
83 * @see setSoftRange(int, int)
84 * @see softMaximum() const
85 */
86 int softMinimum() const;
87 /**
88 * @brief Get the maximum value of the "soft range"
89 * @return the maximum value of the "soft range"
90 * @see setSoftMaximum(int)
91 * @see setSoftRange(int, int)
92 * @see softMinimum) const
93 */
94 int softMaximum() const;
95 /**
96 * @brief Get if the user is currently dragging the slider with the pointer
97 * @return true if the user is currently dragging the slider with the
98 * pointer, false otherwise
99 */
100 bool isDragging() const;
101 /**
102 * @brief Set the value
103 * @param newValue the new value
104 */
105 void setValue(int newValue);
106 /**
107 * @brief Set the minimum and the maximum values of the range, computing
108 * a new "fast slider step" based on the range if required
109 *
110 * The soft range will be adapted to fit inside the range
111 * @param newMinimum the new minimum value
112 * @param newMaximum the new maximum value
113 * @param computeNewFastSliderStep true if a new "fast slider step"
114 * must be computed based on the range
115 * @see setMinimum(int)
116 * @see setMaximum(int)
117 */
118 void setRange(int newMinimum, int newMaximum, bool computeNewFastSliderStep = true);
119 /**
120 * @brief Set the minimum value of the range
121 *
122 * The soft range will be adapted to fit inside the range
123 * @param newMinimum the new minimum value
124 * @param computeNewFastSliderStep true if a new "fast slider step"
125 * must be computed based on the range
126 * @see setRange(int,int)
127 * @see setMaximum(int)
128 */
129 void setMinimum(int newMinimum, bool computeNewFastSliderStep = true);
130 /**
131 * @brief Set the maximum value of the range
132 *
133 * The soft range will be adapted to fit inside the range
134 * @param newMaximum the new maximum value
135 * @param computeNewFastSliderStep true if a new "fast slider step"
136 * must be computed based on the range
137 * @see setRange(int,int)
138 * @see setMinimum(int)
139 */
140 void setMaximum(int newMaximum, bool computeNewFastSliderStep = true);
141 /**
142 * @brief Set the exponent used by a power function to modify the values
143 * as a function of the horizontal position.
144 *
145 * This allows having more values concentrated in one side of the
146 * slider than the other
147 * @param newExponentRatio the new exponent to be used by the power function
148 */
149 void setExponentRatio(qreal newExponentRatio);
150 /**
151 * @brief Set if the spinbox should not Q_EMIT signals when dragging the
152 * slider.
153 *
154 * This is useful to prevent multiple updates when changing the value if
155 * the update operation is costly.
156 * A valueChanged signal will be emitted when the pointer is released from
157 * the slider.
158 * @param newBlockUpdateSignalOnDrag true if the spinbox should not emit
159 * signals when dragging the slider. false otherwise
160 */
161 void setBlockUpdateSignalOnDrag(bool newBlockUpdateSignalOnDrag);
162 /**
163 * @brief Set the value to which multiples the spinbox value snaps when
164 * the control key is pressed
165 * @param newFastSliderStep value to which multiples the spinbox value
166 * snaps when the control key is pressed
167 * @see fastSliderStep() const
168 */
169 void setFastSliderStep(int newFastSliderStep);
170 /**
171 * @brief Set the minimum and the maximum values of the soft range
172 * @param newSoftMinimum the new minimum value
173 * @param newSoftMaximum the new maximum value
174 * @see setSoftMinimum(int)
175 * @see setSoftMaximum(int)
176 * @see softMinimum() const
177 * @see softMaximum() const
178 */
179 void setSoftRange(int newSoftMinimum, int newSoftMaximum);
180 /**
181 * @brief Set the minimum value of the soft range
182 * @param newSoftMinimum the new minimum value
183 * @see setSoftRange(int,int)
184 * @see setSoftMaximum(int)
185 * @see softMinimum() const
186 * @see softMaximum() const
187 */
188 void setSoftMinimum(int newSoftMinimum);
189 /**
190 * @brief Set the maximum value of the soft range
191 * @param newSoftMaximum the new maximum value
192 * @see setSoftRange(int,int)
193 * @see setSoftMinimum(int)
194 * @see softMinimum() const
195 * @see softMaximum() const
196 */
197 void setSoftMaximum(int newSoftMaximum);
198
200 void draggingFinished();
201
202private:
203 struct Private;
204 Private *const d;
205};
206
207/**
208 * @brief This class is a wrapper around KisDoubleSliderSpinBox, a spinbox in
209 * which you can click and drag to set the value, with a slider like bar
210 * displayed inside. The widget itself is accessed with the widget() function.
211 *
212 * @see SliderSpinBox
213 */
214class KRITALIBKIS_EXPORT DoubleSliderSpinBox : public DoubleParseSpinBox
215{
216 Q_OBJECT
217 Q_DISABLE_COPY(DoubleSliderSpinBox)
218
219public:
220 explicit DoubleSliderSpinBox();
221 ~DoubleSliderSpinBox() override;
222
223public Q_SLOTS:
224
225 /**
226 * @brief Get the internal KisDoubleSliderSpinBox as a QWidget, so it may be
227 * added to a UI
228 *
229 * @return the internal KisDoubleSliderSpinBox as a QWidget
230 */
231 QWidget* widget() const;
232
233 qreal fastSliderStep() const;
234 qreal softMinimum() const;
235 qreal softMaximum() const;
236 bool isDragging() const;
237 void setValue(qreal newValue);
238 /**
239 * @brief Set the minimum and the maximum values of the range
240 *
241 * The soft range will be adapted to fit inside the range
242 * The number of decimals used can be changed with the newNumberOfDecimals
243 * parameter
244 * @param newMinimum the new minimum value
245 * @param newMaximum the new maximum value
246 * @param newNumberOfDecimals the new number of decimals
247 * @param computeNewFastSliderStep true if a new "fast slider step"
248 * must be computed based on the range
249 * @see setMinimum(qreal)
250 * @see setMaximum(qreal)
251 */
252 void setRange(qreal newMinimum, qreal newMaximum, int newNumberOfDecimals = 0, bool computeNewFastSliderStep = true);
253 void setMinimum(qreal newMinimum, bool computeNewFastSliderStep = true);
254 void setMaximum(qreal newMaximum, bool computeNewFastSliderStep = true);
255 void setExponentRatio(qreal newExponentRatio);
256 void setBlockUpdateSignalOnDrag(bool newBlockUpdateSignalOnDrag);
257 void setFastSliderStep(qreal newFastSliderStep);
258 void setSoftRange(qreal newSoftMinimum, qreal newSoftMaximum);
259 void setSoftMinimum(qreal newSoftMinimum);
260 void setSoftMaximum(qreal newSoftMaximum);
261
263 void draggingFinished();
264
265private:
266 struct Private;
267 Private *const d;
268};
269
270#endif // LIBKIS_SLIDERSPINBOX_H
A wrapper around KisDoubleParseSpinBox, which is a cleverer doubleSpinBox, able to parse arithmetic e...
This class is a wrapper around KisDoubleSliderSpinBox, a spinbox in which you can click and drag to s...
A wrapper around KisIntParseSpinBox, which is a cleverer SpinBox, able to parse arithmetic expression...
QSpinBox * widget() const
Get the internal KisIntParseSpinBox as a QWidget, so it may be added to a UI.
void setValue(int value, bool overwriteExpression=false)
Set the value of the spinbox.
This class is a wrapper around KisSliderSpinBox, a spinbox in which you can click and drag to set the...
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:53:16 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.