-
Notifications
You must be signed in to change notification settings - Fork 3
/
colorwheel.h
54 lines (38 loc) · 1.42 KB
/
colorwheel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <QtQuick>
class ColorWheel : public QQuickPaintedItem {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY( QColor color MEMBER m_color NOTIFY colorChanged FINAL REQUIRED )
public:
explicit ColorWheel( QQuickItem* parent = nullptr );
void paint( QPainter* painter ) override;
Q_INVOKABLE void setHue( qreal value );
Q_SIGNALS:
void colorChanged();
void editFinished();
private:
enum class HitPosition { IDLE, WHEEL, CHOOSER };
enum class UpDown { UP, DOWN };
UpDown m_quadHit;
HitPosition m_hitMode;
QColor m_color;
QConicalGradient m_wheelGradient;
QRectF m_chooserSize;
QPolygonF m_arrow;
QVector2D m_mouseVec;
qreal m_outerRadius;
qreal m_innerRadius;
qreal m_indicatorSize;
[[nodiscard]] bool isHitMode() noexcept;
[[nodiscard]] QColor hueAt( QVector2D in_mouseVec ) noexcept;
[[nodiscard]] QColor saturationValuePositionLimit( QVector2D position ) noexcept;
[[nodiscard]] QPointF saturationValueFromColor( const QColor& color ) noexcept;
[[nodiscard]] UpDown getQuadrant( QPoint position ) noexcept;
void updateMousePosition( QPoint position );
protected:
void mousePressEvent( QMouseEvent* event ) override;
void mouseMoveEvent( QMouseEvent* event ) override;
void mouseReleaseEvent( QMouseEvent* event ) override;
void geometryChange( const QRectF& newGeometry, const QRectF& oldGeometry ) override;
};