Debian Codegraph @

examples/widgets/painting/gradients/gradients.h

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 #ifndef GRADIENTS_H
5 #define GRADIENTS_H
6
7 #include "arthurwidgets.h"
8
9 QT_BEGIN_NAMESPACE
10 class QRadioButton;
11 QT_END_NAMESPACE
12
13 class HoverPoints;
14
15
16 class ShadeWidget : public QWidget
17 {
18 Q_OBJECT
19
20 public:
21 enum ShadeType {
22 RedShade,
23 GreenShade,
24 BlueShade,
25 ARGBShade
26 };
27
28 ShadeWidget(ShadeType type, QWidget *parent);
29
30 void setGradientStops(const QGradientStops &stops);
31
32 void paintEvent(QPaintEvent *e) override;
33
34 QSize sizeHint() const override { return QSize(150, 40); }
35 QPolygonF points() const;
36
37 HoverPoints *hoverPoints() const { return m_hoverPoints; }
38
39 uint colorAt(int x);
40
41 signals:
42 void colorsChanged();
43
44 private:
45 void generateShade();
46
47 ShadeType m_shade_type;
48 QImage m_shade;
49 HoverPoints *m_hoverPoints;
50 QLinearGradient m_alpha_gradient;
51 };
52
53 class GradientEditor : public QWidget
54 {
55 Q_OBJECT
56
57 public:
58 GradientEditor(QWidget *parent);
59
60 void setGradientStops(const QGradientStops &stops);
61
62 public slots:
63 void pointsUpdated();
64
65 signals:
66 void gradientStopsChanged(const QGradientStops &stops);
67
68 private:
69 ShadeWidget *m_red_shade;
70 ShadeWidget *m_green_shade;
71 ShadeWidget *m_blue_shade;
72 ShadeWidget *m_alpha_shade;
73 };
74
75 class GradientRenderer : public ArthurFrame
76 {
77 Q_OBJECT
78
79 public:
80 GradientRenderer(QWidget *parent);
81 void paint(QPainter *p) override;
82
83 QSize sizeHint() const override { return QSize(400, 400); }
84
85 HoverPoints *hoverPoints() const { return m_hoverPoints; }
86 void mousePressEvent(QMouseEvent *e) override;
87
88 public slots:
89 void setGradientStops(const QGradientStops &stops);
90
91 void setPadSpread() { m_spread = QGradient::PadSpread; update(); }
92 void setRepeatSpread() { m_spread = QGradient::RepeatSpread; update(); }
93 void setReflectSpread() { m_spread = QGradient::ReflectSpread; update(); }
94
95 void setLinearGradient() { m_gradientType = Qt::LinearGradientPattern; update(); }
96 void setRadialGradient() { m_gradientType = Qt::RadialGradientPattern; update(); }
97 void setConicalGradient() { m_gradientType = Qt::ConicalGradientPattern; update(); }
98
99
100 private:
101 QGradientStops m_stops;
102 HoverPoints *m_hoverPoints;
103
104 QGradient::Spread m_spread;
105 Qt::BrushStyle m_gradientType;
106 };
107
108 class GradientWidget : public QWidget
109 {
110 Q_OBJECT
111
112 public:
113 GradientWidget(QWidget *parent = nullptr);
114
115 public slots:
116 void setDefault1() { setDefault(1); }
117 void setDefault2() { setDefault(2); }
118 void setDefault3() { setDefault(3); }
119 void setDefault4() { setDefault(4); }
120 void setPreset() { changePresetBy(0); }
121 void setPrevPreset() { changePresetBy(-1); }
122 void setNextPreset() { changePresetBy(1); }
123
124 private:
125 void setDefault(int i);
126 void updatePresetName();
127 void changePresetBy(int indexOffset);
128
129 GradientRenderer *m_renderer;
130 GradientEditor *m_editor;
131
132 QRadioButton *m_linearButton;
133 QRadioButton *m_radialButton;
134 QRadioButton *m_conicalButton;
135 QRadioButton *m_padSpreadButton;
136 QRadioButton *m_reflectSpreadButton;
137 QRadioButton *m_repeatSpreadButton;
138 QPushButton *m_presetButton;
139
140 int m_presetIndex = 0;
141 };
142
143 #endif // GRADIENTS_H