Perceptual Color

multispinboxsection.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4// Own headers
5// First the interface, which forces the header to be self-contained.
6#include "multispinboxsection.h"
7// Second, the private implementation.
8#include "multispinboxsection_p.h" // IWYU pragma: associated
9
10#include "constpropagatinguniquepointer.h"
11#include "helpermath.h"
12#include <qglobal.h>
13
14namespace PerceptualColor
15{
16/** @brief Constructor
17 *
18 * The object is initialized with default values. */
20 : d_pointer(new MultiSpinBoxSectionPrivate())
21{
22}
23
24/** @brief Destructor */
28
29/** @brief Copy constructor
30 *
31 * @param other the object to be copied */
33{
34 d_pointer.reset(
35 // Create a copy of the private implementation object
36 new MultiSpinBoxSectionPrivate(*other.d_pointer));
37}
38
39/** @brief Copy assignment operator
40 *
41 * @returns By convention, always returns <tt>*this</tt>.
42 *
43 * @param other the object to be copied */
45{
46 if (this != &other) { // protect against invalid self-assignment
47 d_pointer.reset(
48 // Create a copy of the private implementation object
49 new MultiSpinBoxSectionPrivate(*other.d_pointer));
50 }
51
52 return *this; // By convention, always return *this.
53}
54
55/** @brief Move constructor
56 *
57 * @param other the object to move */
59{
60 d_pointer.swap(other.d_pointer);
61}
62
63/** @brief Move assignment operator
64 *
65 * @returns By convention, always returns <tt>*this</tt>.
66 *
67 * @param other the object to move-assign */
69{
70 if (this != &other) { // protect against invalid self-assignment
71 d_pointer.swap(other.d_pointer);
72 }
73
74 return *this; // By convention, always return *this.
75}
76
77/** @brief The number of digits after the decimal point.
78 *
79 * This value can also be <tt>0</tt> to get integer-like behavior.
80 *
81 * @returns The property value.
82 *
83 * @sa @ref setDecimals */
85{
86 return d_pointer->m_decimals;
87}
88
89/** @brief Setter for @ref decimals property.
90 *
91 * @param newDecimals The new decimals values. */
93{
94 d_pointer->m_decimals = qBound(0, newDecimals, 323);
95}
96
97/** @brief Holds whether or not @ref MultiSpinBox::sectionValues wrap
98 * around when they reaches @ref minimum or @ref maximum.
99 *
100 * The default is <tt>false</tt>.
101 *
102 * If <tt>false</tt>, @ref MultiSpinBox::sectionValues shall be bound
103 * between @ref minimum and @ref maximum. If <tt>true</tt>,
104 * @ref MultiSpinBox::sectionValues shall be treated as a circular.
105 *
106 * Example: You have a section that displays a value measured in
107 * degree. @ref minimum is <tt>0</tt>. @ref maximum is <tt>360</tt>.
108 * The following corrections would be applied to input:
109 * | Input | isWrapping == false | isWrapping == true |
110 * | ----: | ------------------: | -----------------: |
111 * | -5 | 0 | 355 |
112 * | 0 | 0 | 0 |
113 * | 5 | 5 | 5 |
114 * | 355 | 355 | 355 |
115 * | 360 | 360 | 0 |
116 * | 365 | 360 | 5 |
117 * | 715 | 360 | 355 |
118 * | 720 | 360 | 0 |
119 * | 725 | 360 | 5 |
120 *
121 * @returns The property value.
122 *
123 * @sa @ref setWrapping */
125{
126 return d_pointer->m_isWrapping;
127}
128
129/** @brief Setter for @ref isWrapping property.
130 *
131 * @param newIsWrapping The new isWrapping value. */
132void MultiSpinBoxSection::setWrapping(bool newIsWrapping)
133{
134 d_pointer->m_isWrapping = newIsWrapping;
135}
136
137/** @brief The maximum possible value of the section.
138 *
139 * @returns The property value.
140 *
141 * @sa @ref setMaximum */
143{
144 return roundToDigits(d_pointer->m_maximum, d_pointer->m_decimals);
145}
146
147/** @brief Setter for @ref maximum property.
148 *
149 * @param newMaximum The new maximum value. */
150void MultiSpinBoxSection::setMaximum(double newMaximum)
151{
152 d_pointer->m_maximum = newMaximum;
153 if (d_pointer->m_minimum > d_pointer->m_maximum) {
154 d_pointer->m_minimum = d_pointer->m_maximum;
155 }
156}
157
158/** @brief The minimum possible value of the section.
159 *
160 * @returns The property value.
161 *
162 * @sa @ref setMinimum */
164{
165 return roundToDigits(d_pointer->m_minimum, d_pointer->m_decimals);
166}
167
168/** @brief Setter for @ref minimum property.
169 *
170 * @param newMinimum The new minimum value. */
171void MultiSpinBoxSection::setMinimum(double newMinimum)
172{
173 d_pointer->m_minimum = newMinimum;
174 if (d_pointer->m_maximum < d_pointer->m_minimum) {
175 d_pointer->m_maximum = d_pointer->m_minimum;
176 }
177}
178
179/** @brief A prefix to be displayed before the value.
180 *
181 * @returns The property value.
182 *
183 * @sa @ref setPrefix */
185{
186 return d_pointer->m_prefix;
187}
188
189/** @brief Setter for @ref prefix property.
190 *
191 * @param newPrefix The new prefix value. */
193{
194 d_pointer->m_prefix = newPrefix;
195}
196
197/** @brief A smaller of two natural steps.
198 *
199 * Valid range: >= 0
200 *
201 * When the user uses the arrows to change the spin box’s value
202 * the value will be incremented/decremented by the amount of the
203 * @ref singleStep.
204 *
205 * @returns The property value.
206 *
207 * @sa @ref setSingleStep */
209{
210 return d_pointer->m_singleStep;
211}
212
213/** @brief Setter for @ref singleStep property.
214 *
215 * @param newSingleStep The new single step value. */
216void MultiSpinBoxSection::setSingleStep(double newSingleStep)
217{
218 d_pointer->m_singleStep = qMax<double>(0, newSingleStep);
219}
220
221/** @brief The suffix to be displayed behind the value.
222 *
223 * @returns The property value.
224 *
225 * @sa @ref setSuffix */
227{
228 return d_pointer->m_suffix;
229}
230
231/** @brief Setter for @ref suffix property.
232 *
233 * @param newSuffix The new suffix value. */
235{
236 d_pointer->m_suffix = newSuffix;
237}
238
239/** @brief Adds QDebug() support for data type
240 * @ref PerceptualColor::MultiSpinBoxSection
241 *
242 * @param dbg Existing debug object
243 * @param value Value to stream into the debug object
244 * @returns Debug object with value streamed in */
246{
247 dbg.nospace() << "\nMultiSpinBoxSection(" // Opening line
248 << "\n prefix: " << value.prefix() //
249 << "\n minimum: " << value.minimum() //
250 << "\n decimals: " << value.decimals() //
251 << "\n isWrapping: " << value.isWrapping() //
252 << "\n maximum: " << value.maximum() //
253 << "\n suffix: " << value.suffix() //
254 << "\n)" // Closing line
255 ;
256 return dbg.maybeSpace();
257}
258
259} // namespace PerceptualColor
The configuration of a single section within a MultiSpinBox.
MultiSpinBoxSection & operator=(const MultiSpinBoxSection &other)
Copy assignment operator.
QString prefix() const
A prefix to be displayed before the value.
int decimals() const
The number of digits after the decimal point.
double singleStep() const
A smaller of two natural steps.
double maximum() const
The maximum possible value of the section.
void setDecimals(int newDecimals)
Setter for decimals property.
double minimum() const
The minimum possible value of the section.
void setMaximum(double newMaximum)
Setter for maximum property.
void setMinimum(double newMinimum)
Setter for minimum property.
void setSuffix(const QString &newSuffix)
Setter for suffix property.
QString suffix() const
The suffix to be displayed behind the value.
void setWrapping(bool newIsWrapping)
Setter for isWrapping property.
bool isWrapping() const
Holds whether or not MultiSpinBox::sectionValues wrap around when they reaches minimum or maximum.
void setSingleStep(double newSingleStep)
Setter for singleStep property.
void setPrefix(const QString &newPrefix)
Setter for prefix property.
The namespace of this library.
QDebug & maybeSpace()
QDebug & nospace()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:36 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.