Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAngleSelector.h
Go to the documentation of this file.
1/*
2 * KDE. Krita Project.
3 *
4 * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KISANGLESELECTOR_H
10#define KISANGLESELECTOR_H
11
12#include <QWidget>
13#include <QScopedPointer>
14
15#include <KisAngleGauge.h>
17
18#include "kritawidgets_export.h"
19
20// WORKAROUND
21// QAbstractSpinBox does some strange fixing of the value when it is out of
22// range and the wrapping is set to true. For example, if the range is
23// [-180, 180] and a value > 180 is set, then the spin box changes it to -180
24// (the minimum), and if a value < -180 is set then it is changed to 180
25// (the maximum). This subclass catches the value earlier and changes it to the
26// closest coterminal angle in the range
27class KRITAWIDGETS_EXPORT KisAngleSelectorSpinBox : public KisDoubleParseSpinBox
28{
29 Q_OBJECT
30public:
31 KisAngleSelectorSpinBox(QWidget *parent = 0);
32 ~KisAngleSelectorSpinBox() override;
33 void setRange(double min, double max);
34 double valueFromText(const QString & text) const override;
35 bool isFlat() const;
36 void setFlat(bool newFlat);
37 QSize minimumSizeHint() const override;
38 QSize sizeHint() const override;
39 void refreshStyle();
40protected:
41#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
42 void enterEvent(QEvent *e) override;
43#else
44 void enterEvent(QEnterEvent *e) override;
45#endif
46 void leaveEvent(QEvent *e) override;
47 void focusInEvent(QFocusEvent *e) override;
48 void focusOutEvent(QFocusEvent *e) override;
49private:
50 struct Private;
51 const QScopedPointer<Private> m_d;
52};
53
60class KRITAWIDGETS_EXPORT KisAngleSelector : public QWidget
61{
62 Q_OBJECT
63
64public:
94
99 explicit KisAngleSelector(QWidget *parent = 0);
101
107 qreal angle() const;
116 qreal snapAngle() const;
124 qreal resetAngle() const;
132 int decimals() const;
141 qreal maximum() const;
150 qreal minimum() const;
156 QString prefix() const;
163 bool wrapping() const;
172 FlipOptionsMode flipOptionsMode() const;
179 int widgetsHeight() const;
186 KisAngleGauge::IncreasingDirection increasingDirection() const;
192 bool isUsingFlatSpinBox() const;
193
199 void setSnapAngle(qreal newSnapAngle);
205 void setResetAngle(qreal newResetAngle);
211 void setDecimals(int newNumberOfDecimals);
218 void setMaximum(qreal newMaximum);
225 void setMinimum(qreal newMinimum);
235 void setRange(qreal newMinimum, qreal newMaximum);
241 void setPrefix(const QString &newPrefix);
248 void setWrapping(bool newWrapping);
255 void setFlipOptionsMode(FlipOptionsMode newMode);
262 void setWidgetsHeight(int newHeight);
269 void setIncreasingDirection(KisAngleGauge::IncreasingDirection newIncreasingDirection);
276 void useFlatSpinBox(bool newUseFlatSpinBox);
277
294 static qreal closestCoterminalAngleInRange(qreal angle, qreal minimum, qreal maximum, bool *ok = nullptr);
309 qreal closestCoterminalAngleInRange(qreal angle, bool *ok = nullptr) const;
320 static qreal flipAngle(qreal angle, Qt::Orientations orientations);
336 static qreal flipAngle(qreal angle, qreal minimum, qreal maximum, Qt::Orientations orientations, bool *ok = nullptr);
345 void flip(Qt::Orientations orientations);
346
347public Q_SLOTS:
353 void setAngle(qreal newAngle);
359 void reset();
360
361Q_SIGNALS:
362 void angleChanged(qreal angle);
363
364private:
365 struct Private;
366 const QScopedPointer<Private> m_d;
367
368 bool event(QEvent *e) override;
369 bool eventFilter(QObject *o, QEvent *e) override;
370};
371
372#endif
const QList< QString > FlipOptionsMode
const QScopedPointer< Private > m_d
A widget with several options to select an angle.
FlipOptionsMode
Options to select how the flip options should be presented.
@ FlipOptionsMode_NoFlipOptions
There is no flip options available.
@ FlipOptionsMode_MenuButton
The flip options are shown as a menu accessible via a options button.
@ FlipOptionsMode_Buttons
The flip options are shown as individual buttons.
const QScopedPointer< Private > m_d
void angleChanged(qreal angle)
The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions.
double valueFromText(const QString &text) const override