API Documentation
Loading...
Searching...
No Matches
CustomColorDialogWidgets.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/QCustomLineEdit.h>
3#include <QWidget>
4#include <QColorDialog>
5#include <QPointer>
6#include <QWindow>
7class QGridLayout;
8class QTimer;
9class QVBoxLayout;
10namespace NDEVR
11{
12 class QCustomColorDialog;
13 class QColorLuminancePicker;
14 class QColorPicker;
15 class QColorShower;
16 class QWellArray;
17 class Button;
18 class QColorPickingEventFilter;
19 class QCustomLabel;
20 class QColorShowLabel;
21 class QWellArray : public QWidget
22 {
23 Q_OBJECT
24 Q_PROPERTY(int selectedColumn READ selectedColumn)
25 Q_PROPERTY(int selectedRow READ selectedRow)
26 public:
27 QWellArray(int rows, int cols, QWidget* parent = 0);
29 QString cellContent(int row, int col) const;
30 int selectedColumn() const { return selCol; }
31 int selectedRow() const { return selRow; }
32 virtual void setCurrent(int row, int col);
33 virtual void setSelected(int row, int col);
34 virtual QSize minimumSizeHint() const override { return QSize(5, 5); }
35 QSize sizeHint() const override;
36 inline int cellWidth() const
37 {
38 return getMax(1, width() / numCols());
39 }
40 inline int cellHeight() const
41 {
42 return getMax(1, height() / numRows());
43 }
44 inline int rowAt(fltp04 y) const
45 {
46 return cast<int>(y / cellHeight());
47 }
48 inline int columnAt(fltp04 x) const
49 {
50 if (isRightToLeft())
51 return ncols - (x / cellWidth()) - 1;
52 return cast<int>(x / cellWidth());
53 }
54 inline int rowY(int row) const
55 {
56 return cellHeight() * row;
57 }
58 inline int columnX(int column) const
59 {
60 if (isRightToLeft())
61 return cellWidth() * (ncols - column - 1);
62 return cellWidth() * column;
63 }
64 inline int numRows() const
65 {
66 return nrows;
67 }
68 inline int numCols() const
69 {
70 return ncols;
71 }
72 inline QRect cellRect() const
73 {
74 return QRect(0, 0, cellWidth(), cellHeight());
75 }
76 inline QSize gridSize() const
77 {
78 return QSize(ncols * cellWidth(), nrows * cellHeight());
79 }
80 QRect cellGeometry(int row, int column)
81 {
82 QRect r;
83 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
84 r.setRect(columnX(column), rowY(row), cellWidth(), cellHeight());
85 return r;
86 }
87 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
88 signals:
89 void selected(int row, int col);
90 void currentChanged(int row, int col);
91 void colorChanged(int index, QRgb color);
92 protected:
93 virtual void paintCell(QPainter*, int row, int col, const QRect&);
94 virtual void paintCellContents(QPainter*, int row, int col, const QRect&);
95 void mousePressEvent(QMouseEvent*) override;
96 void mouseReleaseEvent(QMouseEvent*) override;
97 void keyPressEvent(QKeyEvent*) override;
98 void focusInEvent(QFocusEvent*) override;
99 void focusOutEvent(QFocusEvent*) override;
100 void paintEvent(QPaintEvent*) override;
101 private:
102 Q_DISABLE_COPY(QWellArray)
103 int nrows;
104 int ncols;
105 int curRow;
106 int curCol;
107 int selRow;
108 int selCol;
109 };
110 class QColorLuminancePicker : public QWidget
111 {
112 Q_OBJECT
113 public:
114 QColorLuminancePicker(QWidget* parent = 0);
116 virtual QSize minimumSizeHint() const override { return QSize(5, 5); }
117 public slots:
118 void setCol(int h, int s, int v);
119 void setCol(int h, int s);
120 signals:
121 void newHsv(int h, int s, int v);
122 protected:
123 void paintEvent(QPaintEvent*) override;
124 void mouseMoveEvent(QMouseEvent*) override;
125 void mousePressEvent(QMouseEvent*) override;
126 private:
127 enum { foff = 3, coff = 4 }; //frame and contents offset
128 int val;
129 int hue;
130 int sat;
131 int y2val(int y);
132 int val2y(int val);
133 void setVal(int v);
134 QPixmap* pix;
135 };
136
137 class QColorPicker : public QFrame
138 {
139 Q_OBJECT
140 public:
141 QColorPicker(QWidget* parent);
143 void setCrossVisible(bool visible);
144 virtual QSize minimumSizeHint() const override { return QSize(5, 5); }
145 public slots:
146 void setCol(int h, int s);
147 signals:
148 void newCol(int h, int s);
149 protected:
150 QSize sizeHint() const override;
151 void paintEvent(QPaintEvent*) override;
152 void mouseMoveEvent(QMouseEvent*) override;
153 void mousePressEvent(QMouseEvent*) override;
154 void resizeEvent(QResizeEvent*) override;
155 private:
156 int hue;
157 int sat;
158 QPoint colPt(int width, int height);
159 int huePt(const QPoint& pt, int width, int height);
160 int satPt(const QPoint& pt, int width, int height);
161 void setCol(const QPoint& pt, int width, int height);
162 QPixmap pix;
163 bool crossVisible;
164 };
166 {
167 public:
168 QColorValueBox(QWidget* parent)
169 : QCustomLineEdit(parent)
170 {
171 setup<uint02>(_t("Color Channel"));
173 customValidator().setMax(255);
174 }
175 };
176 class QColorShower : public QWidget
177 {
178 Q_OBJECT
179 public:
180 QColorShower(QCustomColorDialog* parent, bool small_display);
181 //things that don't emit signals
182 void setHsv(int h, int s, int v);
183 int currentAlpha() const;
184 void setCurrentAlpha(int a);
185 void showAlpha(bool b);
186 bool isAlphaVisible() const;
187 QRgb currentColor() const { return curCol; }
188 QColor currentQColor() const { return curQColor; }
189 void retranslateStrings();
190 void updateQColor();
191 void addWidget(QWidget* widget);
192 public slots:
193 void setRgb(QRgb rgb);
194 signals:
195 void newCol(QRgb rgb);
196 void currentColorChanged(const QColor& color);
197 private slots:
198 void rgbEd();
199 void hsvEd();
200 void htmlEd();
201 public:
202 void showCurrentColor();
203 int hue, sat, val;
204 QRgb curCol;
205 QColor curQColor;
206 QLabel* lblHue;
207 QLabel* lblSat;
208 QLabel* lblVal;
209 QLabel* lblRed;
210 QLabel* lblGreen;
211 QLabel* lblBlue;
212 QLabel* lblHtml;
220 QLabel* alphaLab;
225 QGridLayout* gl;
226 };
227 class QColorShowLabel : public QFrame
228 {
229 Q_OBJECT
230 public:
231 QColorShowLabel(QWidget* parent) : QFrame(parent) {
232 setFrameStyle(QFrame::Panel | QFrame::Sunken);
233 setAcceptDrops(true);
234 mousePressed = false;
235 }
236 void setColor(QColor c) { col = c; }
237 signals:
238 void colorDropped(QRgb);
239 protected:
240 void paintEvent(QPaintEvent*) override;
241 void mousePressEvent(QMouseEvent* e) override;
242 void mouseMoveEvent(QMouseEvent* e) override;
243 void mouseReleaseEvent(QMouseEvent* e) override;
244#if QT_CONFIG(draganddrop)
245 void dragEnterEvent(QDragEnterEvent* e) override;
246 void dragLeaveEvent(QDragLeaveEvent* e) override;
247 void dropEvent(QDropEvent* e) override;
248#endif
249 private:
250 QColor col;
251 bool mousePressed;
252 QPoint pressPos;
253 };
254
255 class QCustomColorDialogPrivate : public QObject
256 {
257 Q_OBJECT
258 public:
265 void init(const QColor& initial);
266 void initWidgets();
267 QRgb currentColor() const;
268 QColor currentQColor() const;
269 void setCurrentColor(const QColor& color, SetColorMode setColorMode = SetColorAll);
270 void setCurrentRgbColor(QRgb rgb);
271 bool selectColor(const QColor& color);
272 QColor grabScreenColor(const QPointF& p);
273 int currentAlpha() const;
274 void setCurrentAlpha(int a);
275 void showAlpha(bool b);
276 bool isAlphaVisible() const;
277 void retranslateStrings();
278 public slots:
279 void _q_addCustom();
280 void _q_newHsv(int h, int s, int v);
281 void _q_newColorTypedIn(QRgb rgb);
282 void _q_nextCustom(int, int);
283 void _q_newCustom(int, int);
284 void _q_newStandard(int, int);
285 void _q_pickScreenColor();
287 public:
288 void updateColorPicking(const QPointF& pos);
289 void releaseColorPicking();
290 bool handleColorPickingMouseMove(QMouseEvent* e);
291 bool handleColorPickingMouseButtonRelease(QMouseEvent* e);
292 bool handleColorPickingKeyPress(QKeyEvent* e);
293
295 QColorDialog::ColorDialogOptions options;
299
300 QWellArray* custom = nullptr;
302 QVBoxLayout* m_right_layout = nullptr;
303 QWidget* m_button_widget = nullptr;
304 QColorPicker* cp = nullptr;
309 Button* m_ok_button = nullptr;
314
317#ifdef Q_OS_WIN32
318 QTimer* update_timer;
319 QWindow dummyTransparentWindow;
320#endif
323 };
324}
#define _t(english_string)
Definition Translator.h:87
Definition Button.h:60
Definition CustomColorDialogWidgets.h:111
void paintEvent(QPaintEvent *) override
Definition QCustomColorDialog.cpp:466
void mousePressEvent(QMouseEvent *) override
Definition QCustomColorDialog.cpp:447
virtual QSize minimumSizeHint() const override
Definition CustomColorDialogWidgets.h:116
~QColorLuminancePicker()
Definition QCustomColorDialog.cpp:439
void setCol(int h, int s, int v)
Definition QCustomColorDialog.cpp:499
void mouseMoveEvent(QMouseEvent *) override
Definition QCustomColorDialog.cpp:443
void newHsv(int h, int s, int v)
QColorLuminancePicker(QWidget *parent=0)
Definition QCustomColorDialog.cpp:432
Definition CustomColorDialogWidgets.h:138
QColorPicker(QWidget *parent)
Definition QCustomColorDialog.cpp:525
void paintEvent(QPaintEvent *) override
Definition QCustomColorDialog.cpp:574
QSize sizeHint() const override
Definition QCustomColorDialog.cpp:544
void mousePressEvent(QMouseEvent *) override
Definition QCustomColorDialog.cpp:567
void resizeEvent(QResizeEvent *) override
Definition QCustomColorDialog.cpp:589
virtual QSize minimumSizeHint() const override
Definition CustomColorDialogWidgets.h:144
~QColorPicker()
Definition QCustomColorDialog.cpp:534
void setCrossVisible(bool visible)
Definition QCustomColorDialog.cpp:537
void newCol(int h, int s)
void setCol(int h, int s)
Definition QCustomColorDialog.cpp:548
void mouseMoveEvent(QMouseEvent *) override
Definition QCustomColorDialog.cpp:560
Definition QCustomColorDialog.cpp:237
Definition CustomColorDialogWidgets.h:228
void paintEvent(QPaintEvent *) override
Definition QCustomColorDialog.cpp:617
void setColor(QColor c)
Definition CustomColorDialogWidgets.h:236
QColorShowLabel(QWidget *parent)
Definition CustomColorDialogWidgets.h:231
void mousePressEvent(QMouseEvent *e) override
Definition QCustomColorDialog.cpp:642
void mouseMoveEvent(QMouseEvent *e) override
Definition QCustomColorDialog.cpp:647
void mouseReleaseEvent(QMouseEvent *e) override
Definition QCustomColorDialog.cpp:695
Definition CustomColorDialogWidgets.h:177
QColorValueBox * gEd
Definition CustomColorDialogWidgets.h:217
void currentColorChanged(const QColor &color)
bool isAlphaVisible() const
Definition QCustomColorDialog.cpp:638
void addWidget(QWidget *widget)
Definition QCustomColorDialog.cpp:989
int currentAlpha() const
Definition QCustomColorDialog.cpp:634
QLabel * lblVal
Definition CustomColorDialogWidgets.h:208
QRgb currentColor() const
Definition CustomColorDialogWidgets.h:187
void setRgb(QRgb rgb)
Definition QCustomColorDialog.cpp:937
QColorValueBox * sEd
Definition CustomColorDialogWidgets.h:214
QLabel * lblBlue
Definition CustomColorDialogWidgets.h:211
void setCurrentAlpha(int a)
Definition QCustomColorDialog.cpp:624
void retranslateStrings()
Definition QCustomColorDialog.cpp:971
int hue
Definition CustomColorDialogWidgets.h:203
QColorShower(QCustomColorDialog *parent, bool small_display)
Definition QCustomColorDialog.cpp:701
void setHsv(int h, int s, int v)
Definition QCustomColorDialog.cpp:952
QColor currentQColor() const
Definition CustomColorDialogWidgets.h:188
QColorValueBox * rEd
Definition CustomColorDialogWidgets.h:216
QColorValueBox * hEd
Definition CustomColorDialogWidgets.h:213
void newCol(QRgb rgb)
QLabel * lblGreen
Definition CustomColorDialogWidgets.h:210
void showCurrentColor()
Definition QCustomColorDialog.cpp:883
int val
Definition CustomColorDialogWidgets.h:203
QLabel * lblRed
Definition CustomColorDialogWidgets.h:209
QCustomColorDialog * colorDialog
Definition CustomColorDialogWidgets.h:224
QColorValueBox * alphaEd
Definition CustomColorDialogWidgets.h:219
QRgb curCol
Definition CustomColorDialogWidgets.h:204
void updateQColor()
Definition QCustomColorDialog.cpp:982
QColorShowLabel * color_show_label
Definition CustomColorDialogWidgets.h:222
bool rgbOriginal
Definition CustomColorDialogWidgets.h:223
QLabel * lblHtml
Definition CustomColorDialogWidgets.h:212
QLabel * alphaLab
Definition CustomColorDialogWidgets.h:220
QCustomLineEdit * htEd
Definition CustomColorDialogWidgets.h:221
QColorValueBox * vEd
Definition CustomColorDialogWidgets.h:215
QLabel * lblSat
Definition CustomColorDialogWidgets.h:207
void showAlpha(bool b)
Definition QCustomColorDialog.cpp:629
QColor curQColor
Definition CustomColorDialogWidgets.h:205
QColorValueBox * bEd
Definition CustomColorDialogWidgets.h:218
QGridLayout * gl
Definition CustomColorDialogWidgets.h:225
int sat
Definition CustomColorDialogWidgets.h:203
QLabel * lblHue
Definition CustomColorDialogWidgets.h:206
Definition CustomColorDialogWidgets.h:166
QColorValueBox(QWidget *parent)
Definition CustomColorDialogWidgets.h:168
Definition QCustomColorDialog.h:18
Definition CustomColorDialogWidgets.h:256
Button * add_custom_color_button
Definition CustomColorDialogWidgets.h:311
void setCurrentRgbColor(QRgb rgb)
Definition QCustomColorDialog.cpp:1004
void _q_updateColorPicking()
Definition QCustomColorDialog.cpp:1457
QCustomLabel * lbl_basic_colors
Definition CustomColorDialogWidgets.h:307
QColorPicker * cp
Definition CustomColorDialogWidgets.h:304
bool handleColorPickingMouseButtonRelease(QMouseEvent *e)
Definition QCustomColorDialog.cpp:1489
void _q_newStandard(int, int)
Definition QCustomColorDialog.cpp:1093
bool isAlphaVisible() const
Definition QCustomColorDialog.cpp:878
void initWidgets()
Definition QCustomColorDialog.cpp:1177
SetColorMode
Definition CustomColorDialogWidgets.h:259
@ ShowColor
Definition CustomColorDialogWidgets.h:260
@ SetColorAll
Definition CustomColorDialogWidgets.h:262
@ SelectColor
Definition CustomColorDialogWidgets.h:261
int next_cust
Definition CustomColorDialogWidgets.h:298
int currentAlpha() const
Definition QCustomColorDialog.cpp:875
Button * m_cancel_button
Definition CustomColorDialogWidgets.h:310
QRgb currentColor() const
Definition QCustomColorDialog.cpp:874
bool screenColorPicking
Definition CustomColorDialogWidgets.h:322
QColor selected_color
Definition CustomColorDialogWidgets.h:297
QColorPickingEventFilter * colorPickingEventFilter
Definition CustomColorDialogWidgets.h:313
QCustomColorDialog * q
Definition CustomColorDialogWidgets.h:316
void setCurrentAlpha(int a)
Definition QCustomColorDialog.cpp:876
QColorShower * m_color_shower
Definition CustomColorDialogWidgets.h:306
void _q_pickScreenColor()
Definition QCustomColorDialog.cpp:1099
QWellArray * custom
Definition CustomColorDialogWidgets.h:300
Button * m_ok_button
Definition CustomColorDialogWidgets.h:309
void retranslateStrings()
Definition QCustomColorDialog.cpp:1314
void _q_newHsv(int h, int s, int v)
Definition QCustomColorDialog.cpp:995
void _q_nextCustom(int, int)
Definition QCustomColorDialog.cpp:1082
bool smallDisplay
Definition CustomColorDialogWidgets.h:321
QColor currentQColor() const
Definition QCustomColorDialog.cpp:879
QByteArray memberToDisconnectOnClose
Definition CustomColorDialogWidgets.h:315
QRgb beforeScreenColorPicking
Definition CustomColorDialogWidgets.h:294
void _q_addCustom()
Definition QCustomColorDialog.cpp:1303
QCustomLabel * lbl_custom_colors
Definition CustomColorDialogWidgets.h:308
Button * screen_color_picker_button
Definition CustomColorDialogWidgets.h:312
void _q_newCustom(int, int)
Definition QCustomColorDialog.cpp:1086
void releaseColorPicking()
Definition QCustomColorDialog.cpp:1133
QColorDialog::ColorDialogOptions options
Definition CustomColorDialogWidgets.h:295
void setCurrentColor(const QColor &color, SetColorMode setColorMode=SetColorAll)
Definition QCustomColorDialog.cpp:1347
QWellArray * standard
Definition CustomColorDialogWidgets.h:301
QColor grabScreenColor(const QPointF &p)
Definition QCustomColorDialog.cpp:1056
QCustomColorDialogPrivate(QCustomColorDialog *dialog)
Definition QCustomColorDialog.cpp:1150
QVBoxLayout * m_right_layout
Definition CustomColorDialogWidgets.h:302
QWidget * m_button_widget
Definition CustomColorDialogWidgets.h:303
void init(const QColor &initial)
Definition QCustomColorDialog.cpp:1163
void showAlpha(bool b)
Definition QCustomColorDialog.cpp:877
void updateColorPicking(const QPointF &pos)
Definition QCustomColorDialog.cpp:1473
QColorLuminancePicker * lp
Definition CustomColorDialogWidgets.h:305
bool handleColorPickingKeyPress(QKeyEvent *e)
Definition QCustomColorDialog.cpp:1495
bool selectColor(const QColor &color)
Definition QCustomColorDialog.cpp:1017
QPointer< QObject > receiverToDisconnectOnClose
Definition CustomColorDialogWidgets.h:296
void _q_newColorTypedIn(QRgb rgb)
Definition QCustomColorDialog.cpp:1075
bool handleColorPickingMouseMove(QMouseEvent *e)
Definition QCustomColorDialog.cpp:1481
Definition QCustomLabel.h:42
Definition QCustomLineEdit.h:118
void setup(const TranslatedString &title)
Definition QCustomLineEdit.h:156
QCustomValidator & customValidator()
Definition QCustomLineEdit.cpp:56
void setMax(fltp08 max)
Definition QCustomValidator.h:77
void setMin(fltp08 min)
Definition QCustomValidator.h:78
Definition CustomColorDialogWidgets.h:22
int numRows() const
Definition CustomColorDialogWidgets.h:64
void paintEvent(QPaintEvent *) override
Definition QCustomColorDialog.cpp:48
int cellHeight() const
Definition CustomColorDialogWidgets.h:40
QString cellContent(int row, int col) const
int columnAt(fltp04 x) const
Definition CustomColorDialogWidgets.h:48
virtual void setCurrent(int row, int col)
Definition QCustomColorDialog.cpp:156
QSize gridSize() const
Definition CustomColorDialogWidgets.h:76
QSize sizeHint() const override
Definition QCustomColorDialog.cpp:103
void mousePressEvent(QMouseEvent *) override
Definition QCustomColorDialog.cpp:145
void currentChanged(int row, int col)
int selectedColumn() const
Definition CustomColorDialogWidgets.h:30
void focusOutEvent(QFocusEvent *) override
Definition QCustomColorDialog.cpp:192
int numCols() const
Definition CustomColorDialogWidgets.h:68
int cellWidth() const
Definition CustomColorDialogWidgets.h:36
virtual QSize minimumSizeHint() const override
Definition CustomColorDialogWidgets.h:34
void keyPressEvent(QKeyEvent *) override
Definition QCustomColorDialog.cpp:196
int rowY(int row) const
Definition CustomColorDialogWidgets.h:54
void focusInEvent(QFocusEvent *) override
Definition QCustomColorDialog.cpp:187
int selectedRow() const
Definition CustomColorDialogWidgets.h:31
void colorChanged(int index, QRgb color)
int columnX(int column) const
Definition CustomColorDialogWidgets.h:58
int selectedRow
Definition CustomColorDialogWidgets.h:25
virtual void paintCellContents(QPainter *, int row, int col, const QRect &)
Definition QCustomColorDialog.cpp:136
int rowAt(fltp04 y) const
Definition CustomColorDialogWidgets.h:44
QRect cellRect() const
Definition CustomColorDialogWidgets.h:72
virtual void setSelected(int row, int col)
Definition QCustomColorDialog.cpp:170
void mouseReleaseEvent(QMouseEvent *) override
Definition QCustomColorDialog.cpp:151
int selectedColumn
Definition CustomColorDialogWidgets.h:24
void selected(int row, int col)
void updateCell(int row, int column)
Definition CustomColorDialogWidgets.h:87
QRect cellGeometry(int row, int column)
Definition CustomColorDialogWidgets.h:80
virtual void paintCell(QPainter *, int row, int col, const QRect &)
Definition QCustomColorDialog.cpp:108
Definition ACIColor.h:37
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator.
Definition BaseFunctions.hpp:116
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514