-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgetgradienteditor.h
76 lines (60 loc) · 1.9 KB
/
widgetgradienteditor.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef WIDGETGRADIENTEDITOR_H
#define WIDGETGRADIENTEDITOR_H
#include <QWidget>
struct GradientMarker
{
public:
GradientMarker(const float position, const QColor& color) : hasFocus(false), position(position), color(color) { }
GradientMarker() : hasFocus(false), position(0.5) { }
GradientMarker(const GradientMarker &other) :
hasFocus(other.hasFocus),
color(other.color),
position(other.position) { }
const bool operator<(const GradientMarker& o) const
{
return position < o.position;
}
float position;
bool hasFocus;
QColor color;
};
class WidgetGradientEditor : public QWidget
{
Q_OBJECT
public:
explicit WidgetGradientEditor(QWidget *parent = nullptr);
enum Preset
{
PresetEmpty,
PresetJet,
PresetJetDark,
PresetEarth
};
void removeMarker(int index);
const QMap<float, QColor> getGradient() const;
void setGradient(const QMap<float, QColor> stops);
static const QString gradientToString(const QMap<float, QColor> stops);
static QMap<float, QColor> stringToGradient(const QString config);
protected:
void paintEvent (QPaintEvent *);
void resizeEvent(QResizeEvent * event);
void mousePressEvent (QMouseEvent *);
void mouseMoveEvent (QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
public slots:
void slotReset(const Preset& preset = PresetEmpty);
void slotAddMarker(const QColor &color, float position = 0.5, const bool isMovedByMouse = false);
signals:
void gradientChanged(const QMap<float, QColor>);
private:
QGradient::Spread mSpreadMode;
float mPadding; // the padding area on the outer edges is used to repeat/pad the gradient
bool mMarkerIsReadyToMove;
bool mMarkerHasBeenMoved;
QRect mRectView;
QRect mRectGradient;
QSize viewSize;
QPoint dragStart;
QVector<GradientMarker> mMarkers;
};
#endif // WIDGETGRADIENTEDITOR_H