File indexing completed on 2024-05-12 16:02:01

0001 /*
0002  * KDE. Krita Project.
0003  *
0004  * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef KISANGLEGAUGE_H
0010 #define KISANGLEGAUGE_H
0011 
0012 #include <QWidget>
0013 #include <QScopedPointer>
0014 
0015 #include "kritawidgets_export.h"
0016 
0017 /**
0018  * @brief A circular widget that allows to choose an angle
0019  */
0020 class KRITAWIDGETS_EXPORT KisAngleGauge : public QWidget
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     enum IncreasingDirection
0026     {
0027         IncreasingDirection_CounterClockwise,
0028         IncreasingDirection_Clockwise
0029     };
0030 
0031     /**
0032      * @brief Construct a new KisAngleGauge widget
0033      * @param parent the parent widget
0034      */
0035     explicit KisAngleGauge(QWidget *parent = 0);
0036     ~KisAngleGauge();
0037     
0038     /**
0039      * @brief Gets the current angle
0040      * @return The current angle 
0041      * @see setAngle(qreal)
0042      */
0043     qreal angle() const;
0044     /**
0045      * @brief Gets the angle to which multiples the selected angle will snap
0046      * 
0047      * The default snap angle is 15 degrees so the selected angle will snap
0048      * to its multiples (0, 15, 30, 45, etc.)
0049      * @return The angle to which multiples the selected angle will snap
0050      * @see setSnapAngle(qreal)
0051      */
0052     qreal snapAngle() const;
0053     /**
0054      * @brief Gets the angle that is used to reset the current angle
0055      * 
0056      * This angle is used when the user double clicks on the widget
0057      * @return The angle that is used to reset the current angle
0058      * @see setResetAngle(qreal)
0059      */
0060     qreal resetAngle() const;
0061     /**
0062      * @brief Gets the direction in which the angle increases
0063      * @return The direction in which the angle increases
0064      * @see IcreasingDirection
0065      * @see setIncreasingDirection(IcreasingDirection)
0066      */
0067     IncreasingDirection increasingDirection() const;
0068     
0069     /**
0070      * @brief Sets the angle to which multiples the selected angle will snap
0071      * @param newSnapAngle the new angle to which multiples the selected angle will snap
0072      * @see snapAngle() const
0073      */
0074     void setSnapAngle(qreal newSnapAngle);
0075     /**
0076      * @brief Sets the angle that is used to reset the current angle
0077      * @param newResetAngle the new angle that is used to reset the current angle
0078      * @see resetAngle() const
0079      */
0080     void setResetAngle(qreal newResetAngle);
0081     /**
0082      * @brief Sets the increasing direction
0083      * @param newIncreasingDirection The new increasing direction
0084      * @see IcreasingDirection
0085      * @see increasingDirection() const
0086      */
0087     void setIncreasingDirection(IncreasingDirection newIncreasingDirection);
0088 
0089 public Q_SLOTS:
0090     /**
0091      * @brief Sets the current angle
0092      * @param newAngle the new angle
0093      * @see angle() const
0094      */
0095     void setAngle(qreal newAngle);
0096     /**
0097      * @brief Sets the current angle to the reset angle
0098      * @see resetAngle() const
0099      * @see setResetAngle(qreal) const
0100      */
0101     void reset();
0102 
0103 Q_SIGNALS:
0104     /**
0105      * @brief Signal emitted when the angle has changed
0106      * @param angle The new angle
0107      */
0108     void angleChanged(qreal angle);
0109 
0110 protected:
0111     void paintEvent(QPaintEvent *e) override;
0112     void mousePressEvent(QMouseEvent *e) override;
0113     void mouseReleaseEvent(QMouseEvent *e) override;
0114     void mouseMoveEvent(QMouseEvent *e) override;
0115     void mouseDoubleClickEvent(QMouseEvent *e) override;
0116     void wheelEvent(QWheelEvent *e) override;
0117     void keyPressEvent(QKeyEvent *e) override;
0118     void enterEvent(QEvent *e) override;
0119     void leaveEvent(QEvent *e) override;
0120 
0121 private:
0122     struct Private;
0123     const QScopedPointer<Private> m_d;
0124 };
0125 
0126 #endif