/
circlepalette.h
157 lines (129 loc) · 3.54 KB
/
circlepalette.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef CIRCLEPALETTE_H
#define CIRCLEPALETTE_H
#include <QLabel>
#include <QPoint>
#include <QSoundEffect>
#include <QJsonObject>
namespace PrestoPalette
{
enum GlobalGamutShape
{
GamutShapeNone,
GamutShapeLine,
GamutShapeTriangle,
GamutShapeSquare,
GamutShapeLast
};
enum GlobalWheelShape
{
WheelShapeCoarse,
WheelShapeFine,
WheelShapeLast
};
}
class ColorPoint
{
public:
QColor color;
QPoint point;
qreal angle; // in radians
bool secondaryOn;
ColorPoint(QPoint p)
{
this->point = p;
this->angle = 0;
this->secondaryOn = false; // secondaries are off by default
this->color = QColor();
}
void SaveState(QJsonObject &saveState)
{
saveState["secondary"] = this->secondaryOn;
saveState["x"] = this->point.x();
saveState["y"] = this->point.y();
}
void LoadState(QJsonObject &loadState)
{
this->secondaryOn = loadState["secondary"].toBool();
this->point.setX(loadState["x"].toInt());
this->point.setY(loadState["y"].toInt());
}
};
class CirclePalette : public QWidget
{
Q_OBJECT
public:
explicit CirclePalette(QWidget *parent = 0);
~CirclePalette(void);
QWidget *drawnElements;
QLabel *colorWheel;
QLabel *backgroundWheel;
QVector<QColor> selectedColors;
QColor lightingColor;
PrestoPalette::GlobalGamutShape gamutShape;
PrestoPalette::GlobalWheelShape wheelShape;
QSoundEffect controlOffClick;
QSoundEffect controlOnClick;
bool enableLighting;
void ChangeGamutShape(PrestoPalette::GlobalGamutShape shape);
void ChangeWheelShape(PrestoPalette::GlobalWheelShape shape);
void CalculateCentroid(int circleRadius);
void SaveState(QJsonObject &saveState);
void LoadState(QJsonObject &loadState);
signals:
void selectedColorsChanged();
void hoverColor(const QColor &color);
void lightingColorChanged(const QColor &color);
private slots:
private:
bool eventFilter(QObject *watched, QEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private:
int primaryRadius = 15;
int secondaryRadius = 6;
int centroidRadius = 5;
std::vector<ColorPoint *> pointsLine;
std::vector<ColorPoint *> pointsTriangle;
std::vector<ColorPoint *> pointsQuad;
QPoint centroidTriangle;
QPoint centroidQuad;
bool centroidTriangleOn;
bool centroidQuadOn;
std::vector<ColorPoint *> *points;
QPoint *lighting;
QPoint *centroid;
QPoint dragStartPosition;
bool isDragging;
QPoint *dragPoint;
QPoint relativeDistance;
QPixmap circlePic;
QPixmap lightingPic;
void create_gamut_line();
void create_gamut_triangle();
void create_gamut_square();
void destroy_gamut();
QPointF FindIntersectionWithCircle(const QPoint &p1, const QPoint &p2, const qreal radius);
void _draw_primary_imp(QPainter &painter, const QPoint &p, int circleRadius, bool isCentroid);
void _draw_line_imp(QPainter &painter, const QPoint &p1, const QPoint &p2, int circleRadius, bool secondaryOn);
void _draw_centroid(QPainter &painter, int circleRadius, bool secondaryOn);
bool _is_collision(const QPoint &circle, int circleRadius, const QPoint &hitTest);
public:
struct Less
{
Less(CirclePalette &c)
: circlePalette(c)
{
}
bool operator()(const ColorPoint &i1, const ColorPoint &i2)
{
return circlePalette.sort_angles(i1, i2);
}
CirclePalette &circlePalette;
};
bool sort_angles(const ColorPoint i, const ColorPoint j);
QColor getColorAt(const QPoint &p);
QColor getMidPointColor(QPoint p1, QPoint p2);
QPoint getMidPoint(QPoint &p1, QPoint &p2);
};
#endif // CIRCLEPALETTE_H