3#include "qml_material/input/interactive_item.hpp"
9class QML_MATERIAL_API ColorInput :
public InteractiveItem {
12 Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged FINAL)
13 Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged FINAL)
14 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL)
16 explicit ColorInput(QQuickItem* parent =
nullptr);
17 qreal hue()
const {
return m_hue; }
18 qreal saturation()
const {
return m_saturation; }
19 qreal value()
const {
return m_value; }
21 void setSaturation(qreal);
23 Q_SIGNAL
void hueChanged();
24 Q_SIGNAL
void saturationChanged();
25 Q_SIGNAL
void valueChanged();
26 Q_SIGNAL
void svChangeRequested(qreal saturation, qreal value);
27 Q_SIGNAL
void geometryChanged();
30 void activate()
override {}
31 virtual void requestAt(QPointF) = 0;
32 void geometryChange(
const QRectF&,
const QRectF&)
override;
35 qreal m_hue = 0, m_saturation = 1, m_value = 1;
36 std::optional<QPointF> m_lastPoint;
40class QML_MATERIAL_API ColorTriangle :
public ColorInput {
42 QML_NAMED_ELEMENT(ColorTriangleBase)
43 Q_PROPERTY(QPointF hueVertex READ hueVertex NOTIFY geometryChanged FINAL)
44 Q_PROPERTY(QPointF whiteVertex READ whiteVertex NOTIFY geometryChanged FINAL)
45 Q_PROPERTY(QPointF blackVertex READ blackVertex NOTIFY geometryChanged FINAL)
46 Q_PROPERTY(QPointF handlePosition READ handlePosition NOTIFY handlePositionChanged FINAL)
48 explicit ColorTriangle(QQuickItem* parent =
nullptr);
49 QPointF hueVertex()
const;
50 QPointF whiteVertex()
const;
51 QPointF blackVertex()
const;
52 QPointF handlePosition()
const;
53 bool contains(
const QPointF&)
const override;
54 Q_SIGNAL
void handlePositionChanged();
57 void requestAt(QPointF)
override;
58 void keyPressEvent(QKeyEvent*)
override;
61 QPointF vertex(qreal angle)
const;
62 std::optional<std::array<qreal, 3>> coordinates(QPointF)
const;
66class QML_MATERIAL_API ColorWheel :
public ColorInput {
68 QML_NAMED_ELEMENT(ColorWheelBase)
69 Q_PROPERTY(qreal thickness READ thickness WRITE setThickness NOTIFY geometryChanged FINAL)
70 Q_PROPERTY(qreal outerRadius READ outerRadius NOTIFY geometryChanged FINAL)
71 Q_PROPERTY(qreal innerRadius READ innerRadius NOTIFY geometryChanged FINAL)
72 Q_PROPERTY(QPointF handlePosition READ handlePosition NOTIFY geometryChanged FINAL)
73 Q_PROPERTY(ColorTriangle* triangle READ triangle WRITE setTriangle NOTIFY triangleChanged FINAL)
75 explicit ColorWheel(QQuickItem* parent =
nullptr);
76 ~ColorWheel()
override;
77 qreal thickness()
const {
return m_thickness; }
78 void setThickness(qreal);
79 qreal outerRadius()
const;
80 qreal innerRadius()
const;
81 QPointF handlePosition()
const;
82 bool contains(
const QPointF&)
const override;
83 ColorTriangle* triangle()
const {
return m_triangle; }
84 void setTriangle(ColorTriangle*);
85 Q_INVOKABLE
void requestHue(qreal);
86 Q_SIGNAL
void triangleChanged();
87 Q_SIGNAL
void hueChangeRequested(qreal hue);
90 void requestAt(QPointF)
override;
91 void keyPressEvent(QKeyEvent*)
override;
94 qreal m_thickness = 22;
95 QPointer<ColorTriangle> m_triangle;
96 QList<QMetaObject::Connection> m_triangleConnections;