Krita

AngleSelector.cpp
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
11const QList<QString> FlipOptionsMode = {
12 "NoFlipOptions", // 0 = KisAngleSelector::FlipOptionsMode_NoFlipOptions
13 "MenuButton", // KisAngleSelector::FlipOptionsMode_MenuButton
14 "Buttons", // KisAngleSelector::FlipOptionsMode_Buttons
15 "ContextMenu" // KisAngleSelector::FlipOptionsMode_ContextMenu
16};
17
18const QList<QString> IncreasingDirection = {
19 "CounterClockwise", // 0 = KisAngleGauge::IncreasingDirection_CounterClockwise
20 "Clockwise" // KisAngleGauge::IncreasingDirection_Clockwise
21};
22
23struct AngleSelector::Private {
24 Private() {}
25
26 KisAngleSelector *widget;
27};
28
29AngleSelector::AngleSelector()
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
39AngleSelector::~AngleSelector()
40{
41 delete d;
42}
43
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
80{
81 return d->widget->prefix();
82}
83
85{
86 return d->widget->wrapping();
87}
88
90{
91 KisAngleSelector::FlipOptionsMode mode = d->widget->flipOptionsMode();
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{
106 KisAngleGauge::IncreasingDirection increasingDirection = d->widget->increasingDirection();
107 if (!(0 <= increasingDirection && increasingDirection <= IncreasingDirection.size())) {
108 warnScript << "AngleSelector::increasingDirection() doesn't handle mode '" << increasingDirection << "'!";
109 return "";
110 }
111 return IncreasingDirection[increasingDirection];
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 }
171 d->widget->setFlipOptionsMode((KisAngleSelector::FlipOptionsMode) index);
172}
173
175{
176 d->widget->setWidgetsHeight(newHeight);
177}
178
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 }
186 d->widget->setIncreasingDirection((KisAngleGauge::IncreasingDirection) index);
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{
201 return KisAngleSelector::closestCoterminalAngleInRange(angle, minimum, maximum, ok);
202}
203
204qreal AngleSelector::closestCoterminalAngleInRange(qreal angle, bool *ok) const
205{
206 return d->widget->closestCoterminalAngleInRange(angle, ok);
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
220{
221 bool ok = false;
222 qreal flippedAngle = flipAngle(angle(), minimum(), maximum(), orientations, &ok);
223 if (ok) {
224 setAngle(flippedAngle);
225 }
226}
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.
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.
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.
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.
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.
typedef Orientations
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.