Krita Source Code Documentation
Loading...
Searching...
No Matches
AngleSelector.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "AngleSelector.h"
7
8#include "kis_debug.h"
9
10
12 "NoFlipOptions", // 0 = KisAngleSelector::FlipOptionsMode_NoFlipOptions
13 "MenuButton", // KisAngleSelector::FlipOptionsMode_MenuButton
14 "Buttons", // KisAngleSelector::FlipOptionsMode_Buttons
15 "ContextMenu" // KisAngleSelector::FlipOptionsMode_ContextMenu
16};
17
19 "CounterClockwise", // 0 = KisAngleGauge::IncreasingDirection_CounterClockwise
20 "Clockwise" // KisAngleGauge::IncreasingDirection_Clockwise
21};
22
28
30 : QObject()
31 , d(new Private)
32{
33 d->widget = new KisAngleSelector();
34
35 // Forward KisAngleSelector::angleChanged to AngleSelector::angleChanged
36 connect(d->widget, SIGNAL(angleChanged(qreal)), this, SIGNAL(angleChanged(qreal)));
37}
38
40{
41 delete d;
42}
43
44QWidget* AngleSelector::widget() const
45{
46 return d->widget;
47}
48
50{
51 return d->widget->angle();
52}
53
55{
56 return d->widget->snapAngle();
57}
58
60{
61 return d->widget->resetAngle();
62}
63
65{
66 return d->widget->decimals();
67}
68
70{
71 return d->widget->maximum();
72}
73
75{
76 return d->widget->minimum();
77}
78
79QString AngleSelector::prefix() const
80{
81 return d->widget->prefix();
82}
83
85{
86 return d->widget->wrapping();
87}
88
90{
92 if (!(0 <= mode && mode <= FlipOptionsMode.size())) {
93 warnScript << "AngleSelector::flipOptionsMode() doesn't handle mode '" << mode << "'!";
94 return "";
95 }
96 return FlipOptionsMode[mode];
97}
98
100{
101 return d->widget->widgetsHeight();
102}
103
105{
108 warnScript << "AngleSelector::increasingDirection() doesn't handle mode '" << increasingDirection << "'!";
109 return "";
110 }
112}
113
115{
116 return d->widget->isUsingFlatSpinBox();
117}
118
119void AngleSelector::setAngle(qreal newAngle)
120{
121 d->widget->setAngle(newAngle);
122}
123
124void AngleSelector::setSnapAngle(qreal newSnapAngle)
125{
126 d->widget->setSnapAngle(newSnapAngle);
127}
128
129void AngleSelector::setResetAngle(qreal newResetAngle)
130{
131 d->widget->setResetAngle(newResetAngle);
132}
133
134void AngleSelector::setDecimals(int newNumberOfDecimals)
135{
136 d->widget->setDecimals(newNumberOfDecimals);
137}
138
139void AngleSelector::setMaximum(qreal newMaximum)
140{
141 d->widget->setMaximum(newMaximum);
142}
143
144void AngleSelector::setMinimum(qreal newMinimum)
145{
146 d->widget->setMinimum(newMinimum);
147}
148
149void AngleSelector::setRange(qreal newMinimum, qreal newMaximum)
150{
151 d->widget->setRange(newMinimum, newMaximum);
152}
153
154void AngleSelector::setPrefix(const QString &newPrefix)
155{
156 d->widget->setPrefix(newPrefix);
157}
158
159void AngleSelector::setWrapping(bool newWrapping)
160{
161 d->widget->setWrapping(newWrapping);
162}
163
165{
166 int index = FlipOptionsMode.indexOf(newMode);
167 if (index == -1) {
168 dbgScript << "Script using AngleSelector.setFlipOptionsMode() passed invalid mode '" << newMode << "', ignoring.";
169 return;
170 }
172}
173
175{
176 d->widget->setWidgetsHeight(newHeight);
177}
178
179void AngleSelector::setIncreasingDirection(QString newIncreasingDirection)
180{
181 int index = IncreasingDirection.indexOf(newIncreasingDirection);
182 if (index == -1) {
183 dbgScript << "Script using AngleSelector.setIncreasingDirection() passed invalid mode '" << newIncreasingDirection << "', ignoring.";
184 return;
185 }
187}
188
189void AngleSelector::useFlatSpinBox(bool newUseFlatSpinBox)
190{
191 d->widget->useFlatSpinBox(newUseFlatSpinBox);
192}
193
195{
196 d->widget->reset();
197}
198
199qreal AngleSelector::closestCoterminalAngleInRange(qreal angle, qreal minimum, qreal maximum, bool *ok)
200{
202}
203
204qreal AngleSelector::closestCoterminalAngleInRange(qreal angle, bool *ok) const
205{
207}
208
209qreal AngleSelector::flipAngle(qreal angle, Qt::Orientations orientations)
210{
211 return KisAngleSelector::flipAngle(angle, orientations);
212}
213
214qreal AngleSelector::flipAngle(qreal angle, qreal minimum, qreal maximum, Qt::Orientations orientations, bool *ok)
215{
216 return KisAngleSelector::flipAngle(angle, minimum, maximum, orientations, ok);
217}
218
219void AngleSelector::flip(Qt::Orientations orientations)
220{
221 bool ok = false;
222 qreal flippedAngle = flipAngle(angle(), minimum(), maximum(), orientations, &ok);
223 if (ok) {
224 setAngle(flippedAngle);
225 }
226}
const QList< QString > FlipOptionsMode
const QList< QString > IncreasingDirection
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
qreal angle() const
Gets the current angle.
qreal minimum() const
Gets the minimum value for the angle.
qreal maximum() const
Gets the maximum value for the angle.
~AngleSelector() override
int widgetsHeight() const
Gets the common height of the widgets inside this angle selector.
void setMinimum(qreal newMinimum)
Sets the minimum value for the angle.
Private *const d
QString increasingDirection() const
Gets the direction in which the angle increases in the angle gauge.
QString prefix() const
Gets the prefix shown in the spin box.
void reset()
Sets the current angle to the reset angle.
void setRange(qreal newMinimum, qreal newMaximum)
Sets the minimum and maximum values for the angle.
static qreal flipAngle(qreal angle, Qt::Orientations orientations)
Flips an angle horizontally, vertically, or both.
void setPrefix(const QString &newPrefix)
Sets the prefix shown in the spin box.
void useFlatSpinBox(bool newUseFlatSpinBox)
Sets if the spin box should be flat.
void setIncreasingDirection(QString newIncreasingDirection)
Sets the increasing direction in the angle gauge.
QString flipOptionsMode() const
Gets the mode in which the flip options should be shown.
qreal snapAngle() const
Gets the angle to which multiples the selected angle will snap.
void setFlipOptionsMode(QString newMode)
Sets the mode in which the flip options should be shown.
void flip(Qt::Orientations orientations)
Flips the angle horizontally, vertically, or both.
void setResetAngle(qreal newResetAngle)
Sets the angle that is used to reset the current angle.
bool wrapping() const
Gets if the angle should wrap pass the minimum or maximum angles.
void setSnapAngle(qreal newSnapAngle)
Sets the angle to which multiples the selected angle will snap.
void setMaximum(qreal newMaximum)
Sets the maximum value for the angle.
QWidget * widget() const
Get the internal KisAngleSelector as a QWidget, so it may be added to a UI.
bool isUsingFlatSpinBox() const
Gets if the spin box is flat (no border or background)
qreal resetAngle() const
Gets the angle that is used to reset the current angle.
void angleChanged(qreal angle)
int decimals() const
Gets the number of decimals (precision) used by the angle.
void setWidgetsHeight(int newHeight)
Sets the common height of the widgets inside this angle selector. Use 0 to reset widgets to default h...
static qreal closestCoterminalAngleInRange(qreal angle, qreal minimum, qreal maximum, bool *ok=nullptr)
Gets the closest coterminal angle to the provided angle that is in the range provided.
void setDecimals(int newNumberOfDecimals)
Sets the number of decimals (precision) used by the angle.
void setAngle(qreal newAngle)
Sets the current angle.
void setWrapping(bool newWrapping)
Sets if the angle should wrap pass the minimum or maximum angles.
A widget with several options to select an angle.
void setResetAngle(qreal newResetAngle)
Sets the angle that is used to reset the current angle.
static qreal flipAngle(qreal angle, Qt::Orientations orientations)
Flips an angle horizontally, vertically, or both.
FlipOptionsMode
Options to select how the flip options should be presented.
void setPrefix(const QString &newPrefix)
Sets the prefix shown in the spin box.
bool wrapping() const
Gets if the angle should wrap pass the minimum or maximum angles.
int widgetsHeight() const
Gets the common height of the widgets inside this angle selector.
void setWrapping(bool newWrapping)
Sets if the angle should wrap pass the minimum or maximum angles.
qreal angle() const
Gets the current angle.
void setFlipOptionsMode(FlipOptionsMode newMode)
Sets the mode in which the flip options should be shown.
FlipOptionsMode flipOptionsMode() const
Gets the mode in which the flip options should be shown.
void setSnapAngle(qreal newSnapAngle)
Sets the angle to which multiples the selected angle will snap.
void setIncreasingDirection(KisAngleGauge::IncreasingDirection newIncreasingDirection)
Sets the increasing direction in the angle gauge.
qreal resetAngle() const
Gets the angle that is used to reset the current angle.
QString prefix() const
Gets the prefix shown in the spin box.
void useFlatSpinBox(bool newUseFlatSpinBox)
Sets if the spin box should be flat.
qreal maximum() const
Gets the maximum value for the angle.
qreal minimum() const
Gets the minimum value for the angle.
void setAngle(qreal newAngle)
Sets the current angle.
void setRange(qreal newMinimum, qreal newMaximum)
Sets the minimum and maximum values for the angle.
void setMaximum(qreal newMaximum)
Sets the maximum value for the angle.
qreal snapAngle() const
Gets the angle to which multiples the selected angle will snap.
void setWidgetsHeight(int newHeight)
Sets the common height of the widgets inside this angle selector. Use 0 to reset widgets to default h...
static qreal closestCoterminalAngleInRange(qreal angle, qreal minimum, qreal maximum, bool *ok=nullptr)
Gets the closest coterminal angle to the provided angle that is in the range provided.
void setDecimals(int newNumberOfDecimals)
Sets the number of decimals (precision) used by the angle.
void reset()
Sets the current angle to the reset angle.
bool isUsingFlatSpinBox() const
Gets if the spin box is flat (no border or background)
KisAngleGauge::IncreasingDirection increasingDirection() const
Gets the direction in which the angle increases in the angle gauge.
void setMinimum(qreal newMinimum)
Sets the minimum value for the angle.
int decimals() const
Gets the number of decimals (precision) used by the angle.
#define dbgScript
Definition kis_debug.h:56
#define warnScript
Definition kis_debug.h:98