1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qcolordialog.h" |
5 | |
6 | #include "qapplication.h" |
7 | #include "qdrawutil.h" |
8 | #include "qevent.h" |
9 | #include "qimage.h" |
10 | #if QT_CONFIG(draganddrop) |
11 | #include <qdrag.h> |
12 | #endif |
13 | #include "qlabel.h" |
14 | #include "qlayout.h" |
15 | #include "qlineedit.h" |
16 | #if QT_CONFIG(menu) |
17 | #include "qmenu.h" |
18 | #endif |
19 | #include "qpainter.h" |
20 | #include "qpixmap.h" |
21 | #include "qpushbutton.h" |
22 | #if QT_CONFIG(regularexpression) |
23 | #include <qregularexpression.h> |
24 | #endif |
25 | #if QT_CONFIG(settings) |
26 | #include "qsettings.h" |
27 | #endif |
28 | #include "qsharedpointer.h" |
29 | #include "qstyle.h" |
30 | #include "qstyleoption.h" |
31 | #include "qvalidator.h" |
32 | #include "qmimedata.h" |
33 | #include "qspinbox.h" |
34 | #include "qdialogbuttonbox.h" |
35 | #include "qscreen.h" |
36 | #include "qcursor.h" |
37 | #include "qtimer.h" |
38 | #include "qwindow.h" |
39 | |
40 | #include "private/qdialog_p.h" |
41 | |
42 | #include <qpa/qplatformintegration.h> |
43 | #include <qpa/qplatformservices.h> |
44 | #include <private/qguiapplication_p.h> |
45 | |
46 | #include <QtCore/qpointer.h> |
47 | |
48 | #include <algorithm> |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | using namespace Qt::StringLiterals; |
53 | |
54 | namespace QtPrivate { |
55 | class QColorLuminancePicker; |
56 | class QColorPicker; |
57 | class QColorShower; |
58 | class QWellArray; |
59 | class QColorWell; |
60 | class QColorPickingEventFilter; |
61 | } // namespace QtPrivate |
62 | |
63 | using QColorLuminancePicker = QtPrivate::QColorLuminancePicker; |
64 | using QColorPicker = QtPrivate::QColorPicker; |
65 | using QColorShower = QtPrivate::QColorShower; |
66 | using QWellArray = QtPrivate::QWellArray; |
67 | using QColorWell = QtPrivate::QColorWell; |
68 | using QColorPickingEventFilter = QtPrivate::QColorPickingEventFilter; |
69 | |
70 | class QColorDialogPrivate : public QDialogPrivate |
71 | { |
72 | Q_DECLARE_PUBLIC(QColorDialog) |
73 | |
74 | public: |
75 | enum SetColorMode { |
76 | ShowColor = 0x1, |
77 | SelectColor = 0x2, |
78 | SetColorAll = ShowColor | SelectColor |
79 | }; |
80 | |
81 | QColorDialogPrivate() : options(QColorDialogOptions::create()) |
82 | #ifdef Q_OS_WIN32 |
83 | , updateTimer(0) |
84 | #endif |
85 | {} |
86 | |
87 | QPlatformColorDialogHelper *platformColorDialogHelper() const |
88 | { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); } |
89 | |
90 | void init(const QColor &initial); |
91 | void initWidgets(); |
92 | QRgb currentColor() const; |
93 | QColor currentQColor() const; |
94 | void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll); |
95 | void setCurrentRgbColor(QRgb rgb); |
96 | void setCurrentQColor(const QColor &color); |
97 | bool selectColor(const QColor &color); |
98 | QColor grabScreenColor(const QPoint &p); |
99 | |
100 | int currentAlpha() const; |
101 | void setCurrentAlpha(int a); |
102 | void showAlpha(bool b); |
103 | bool isAlphaVisible() const; |
104 | void retranslateStrings(); |
105 | bool supportsColorPicking() const; |
106 | |
107 | void addCustom(); |
108 | void _q_setCustom(int index, QRgb color); |
109 | |
110 | void newHsv(int h, int s, int v); |
111 | void newColorTypedIn(QRgb rgb); |
112 | void nextCustom(int, int); |
113 | void newCustom(int, int); |
114 | void newStandard(int, int); |
115 | void pickScreenColor(); |
116 | void updateColorPicking(); |
117 | void updateColorLabelText(const QPoint &); |
118 | void updateColorPicking(const QPoint &pos); |
119 | void releaseColorPicking(); |
120 | bool handleColorPickingMouseMove(QMouseEvent *e); |
121 | bool handleColorPickingMouseButtonRelease(QMouseEvent *e); |
122 | bool handleColorPickingKeyPress(QKeyEvent *e); |
123 | |
124 | bool canBeNativeDialog() const override; |
125 | void setVisible(bool visible) override; |
126 | |
127 | QWellArray *custom; |
128 | QWellArray *standard; |
129 | |
130 | QDialogButtonBox *buttons; |
131 | QVBoxLayout *leftLay; |
132 | QColorPicker *cp; |
133 | QColorLuminancePicker *lp; |
134 | QColorShower *cs; |
135 | QLabel *lblBasicColors; |
136 | QLabel *lblCustomColors; |
137 | QLabel *lblScreenColorInfo; |
138 | QPushButton *ok; |
139 | QPushButton *cancel; |
140 | QPushButton *addCusBt; |
141 | QPushButton *eyeDropperButton = nullptr; |
142 | QColor selectedQColor; |
143 | int nextCust; |
144 | bool smallDisplay; |
145 | bool screenColorPicking; |
146 | QColorPickingEventFilter *colorPickingEventFilter; |
147 | QRgb beforeScreenColorPicking; |
148 | QSharedPointer<QColorDialogOptions> options; |
149 | |
150 | QPointer<QObject> receiverToDisconnectOnClose; |
151 | QByteArray memberToDisconnectOnClose; |
152 | #ifdef Q_OS_WIN32 |
153 | QTimer *updateTimer; |
154 | QWindow dummyTransparentWindow; |
155 | #endif |
156 | |
157 | private: |
158 | virtual void initHelper(QPlatformDialogHelper *h) override; |
159 | virtual void helperPrepareShow(QPlatformDialogHelper *h) override; |
160 | }; |
161 | |
162 | //////////// QWellArray BEGIN |
163 | |
164 | namespace QtPrivate { |
165 | |
166 | class QWellArray : public QWidget |
167 | { |
168 | Q_OBJECT |
169 | Q_PROPERTY(int selectedColumn READ selectedColumn) |
170 | Q_PROPERTY(int selectedRow READ selectedRow) |
171 | |
172 | public: |
173 | QWellArray(int rows, int cols, QWidget* parent=nullptr); |
174 | ~QWellArray() {} |
175 | QString cellContent(int row, int col) const; |
176 | |
177 | int selectedColumn() const { return selCol; } |
178 | int selectedRow() const { return selRow; } |
179 | |
180 | virtual void setCurrent(int row, int col); |
181 | virtual void setSelected(int row, int col); |
182 | |
183 | QSize sizeHint() const override; |
184 | |
185 | inline int cellWidth() const |
186 | { return cellw; } |
187 | |
188 | inline int cellHeight() const |
189 | { return cellh; } |
190 | |
191 | inline int rowAt(int y) const |
192 | { return y / cellh; } |
193 | |
194 | inline int columnAt(int x) const |
195 | { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; } |
196 | |
197 | inline int rowY(int row) const |
198 | { return cellh * row; } |
199 | |
200 | inline int columnX(int column) const |
201 | { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; } |
202 | |
203 | inline int numRows() const |
204 | { return nrows; } |
205 | |
206 | inline int numCols() const |
207 | {return ncols; } |
208 | |
209 | inline QRect cellRect() const |
210 | { return QRect(0, 0, cellw, cellh); } |
211 | |
212 | inline QSize gridSize() const |
213 | { return QSize(ncols * cellw, nrows * cellh); } |
214 | |
215 | QRect cellGeometry(int row, int column) |
216 | { |
217 | QRect r; |
218 | if (row >= 0 && row < nrows && column >= 0 && column < ncols) |
219 | r.setRect(ax: columnX(column), ay: rowY(row), aw: cellw, ah: cellh); |
220 | return r; |
221 | } |
222 | |
223 | inline void updateCell(int row, int column) { update(cellGeometry(row, column)); } |
224 | |
225 | signals: |
226 | void selected(int row, int col); |
227 | void currentChanged(int row, int col); |
228 | void colorChanged(int index, QRgb color); |
229 | |
230 | protected: |
231 | virtual void paintCell(QPainter *, int row, int col, const QRect&); |
232 | virtual void paintCellContents(QPainter *, int row, int col, const QRect&); |
233 | |
234 | void mousePressEvent(QMouseEvent*) override; |
235 | void mouseReleaseEvent(QMouseEvent*) override; |
236 | void keyPressEvent(QKeyEvent*) override; |
237 | void focusInEvent(QFocusEvent*) override; |
238 | void focusOutEvent(QFocusEvent*) override; |
239 | void paintEvent(QPaintEvent *) override; |
240 | |
241 | private: |
242 | Q_DISABLE_COPY(QWellArray) |
243 | |
244 | int nrows; |
245 | int ncols; |
246 | int cellw; |
247 | int cellh; |
248 | int curRow; |
249 | int curCol; |
250 | int selRow; |
251 | int selCol; |
252 | }; |
253 | |
254 | void QWellArray::paintEvent(QPaintEvent *e) |
255 | { |
256 | QRect r = e->rect(); |
257 | int cx = r.x(); |
258 | int cy = r.y(); |
259 | int ch = r.height(); |
260 | int cw = r.width(); |
261 | int colfirst = columnAt(x: cx); |
262 | int collast = columnAt(x: cx + cw); |
263 | int rowfirst = rowAt(y: cy); |
264 | int rowlast = rowAt(y: cy + ch); |
265 | |
266 | if (isRightToLeft()) { |
267 | int t = colfirst; |
268 | colfirst = collast; |
269 | collast = t; |
270 | } |
271 | |
272 | QPainter painter(this); |
273 | QPainter *p = &painter; |
274 | QRect rect(0, 0, cellWidth(), cellHeight()); |
275 | |
276 | |
277 | if (collast < 0 || collast >= ncols) |
278 | collast = ncols-1; |
279 | if (rowlast < 0 || rowlast >= nrows) |
280 | rowlast = nrows-1; |
281 | |
282 | // Go through the rows |
283 | for (int r = rowfirst; r <= rowlast; ++r) { |
284 | // get row position and height |
285 | int rowp = rowY(row: r); |
286 | |
287 | // Go through the columns in the row r |
288 | // if we know from where to where, go through [colfirst, collast], |
289 | // else go through all of them |
290 | for (int c = colfirst; c <= collast; ++c) { |
291 | // get position and width of column c |
292 | int colp = columnX(column: c); |
293 | // Translate painter and draw the cell |
294 | rect.translate(dx: colp, dy: rowp); |
295 | paintCell(p, row: r, col: c, rect); |
296 | rect.translate(dx: -colp, dy: -rowp); |
297 | } |
298 | } |
299 | } |
300 | |
301 | QWellArray::QWellArray(int rows, int cols, QWidget *parent) |
302 | : QWidget(parent) |
303 | ,nrows(rows), ncols(cols) |
304 | { |
305 | setFocusPolicy(Qt::StrongFocus); |
306 | cellw = 28; |
307 | cellh = 24; |
308 | curCol = 0; |
309 | curRow = 0; |
310 | selCol = -1; |
311 | selRow = -1; |
312 | } |
313 | |
314 | QSize QWellArray::sizeHint() const |
315 | { |
316 | ensurePolished(); |
317 | return gridSize().boundedTo(otherSize: QSize(640, 480)); |
318 | } |
319 | |
320 | |
321 | void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect) |
322 | { |
323 | int b = 3; //margin |
324 | |
325 | const QPalette & g = palette(); |
326 | QStyleOptionFrame opt; |
327 | opt.initFrom(w: this); |
328 | int dfw = style()->pixelMetric(metric: QStyle::PM_DefaultFrameWidth, option: &opt, widget: this); |
329 | opt.lineWidth = dfw; |
330 | opt.midLineWidth = 1; |
331 | opt.rect = rect.adjusted(xp1: b, yp1: b, xp2: -b, yp2: -b); |
332 | opt.palette = g; |
333 | opt.state = QStyle::State_Enabled | QStyle::State_Sunken; |
334 | style()->drawPrimitive(pe: QStyle::PE_Frame, opt: &opt, p, w: this); |
335 | b += dfw; |
336 | |
337 | if ((row == curRow) && (col == curCol)) { |
338 | if (hasFocus()) { |
339 | QStyleOptionFocusRect opt; |
340 | opt.palette = g; |
341 | opt.rect = rect; |
342 | opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange; |
343 | style()->drawPrimitive(pe: QStyle::PE_FrameFocusRect, opt: &opt, p, w: this); |
344 | } |
345 | } |
346 | paintCellContents(p, row, col, opt.rect.adjusted(xp1: dfw, yp1: dfw, xp2: -dfw, yp2: -dfw)); |
347 | } |
348 | |
349 | /* |
350 | Reimplement this function to change the contents of the well array. |
351 | */ |
352 | void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r) |
353 | { |
354 | Q_UNUSED(row); |
355 | Q_UNUSED(col); |
356 | p->fillRect(r, c: Qt::white); |
357 | p->setPen(Qt::black); |
358 | p->drawLine(p1: r.topLeft(), p2: r.bottomRight()); |
359 | p->drawLine(p1: r.topRight(), p2: r.bottomLeft()); |
360 | } |
361 | |
362 | void QWellArray::mousePressEvent(QMouseEvent *e) |
363 | { |
364 | // The current cell marker is set to the cell the mouse is pressed in |
365 | QPoint pos = e->position().toPoint(); |
366 | setCurrent(row: rowAt(y: pos.y()), col: columnAt(x: pos.x())); |
367 | } |
368 | |
369 | void QWellArray::mouseReleaseEvent(QMouseEvent * /* event */) |
370 | { |
371 | // The current cell marker is set to the cell the mouse is clicked in |
372 | setSelected(row: curRow, col: curCol); |
373 | } |
374 | |
375 | |
376 | /* |
377 | Sets the cell currently having the focus. This is not necessarily |
378 | the same as the currently selected cell. |
379 | */ |
380 | |
381 | void QWellArray::setCurrent(int row, int col) |
382 | { |
383 | if ((curRow == row) && (curCol == col)) |
384 | return; |
385 | |
386 | if (row < 0 || col < 0) |
387 | row = col = -1; |
388 | |
389 | int oldRow = curRow; |
390 | int oldCol = curCol; |
391 | |
392 | curRow = row; |
393 | curCol = col; |
394 | |
395 | updateCell(row: oldRow, column: oldCol); |
396 | updateCell(row: curRow, column: curCol); |
397 | |
398 | emit currentChanged(row: curRow, col: curCol); |
399 | } |
400 | |
401 | /* |
402 | Sets the currently selected cell to \a row, \a column. If \a row or |
403 | \a column are less than zero, the current cell is unselected. |
404 | |
405 | Does not set the position of the focus indicator. |
406 | */ |
407 | void QWellArray::setSelected(int row, int col) |
408 | { |
409 | int oldRow = selRow; |
410 | int oldCol = selCol; |
411 | |
412 | if (row < 0 || col < 0) |
413 | row = col = -1; |
414 | |
415 | selCol = col; |
416 | selRow = row; |
417 | |
418 | updateCell(row: oldRow, column: oldCol); |
419 | updateCell(row: selRow, column: selCol); |
420 | if (row >= 0) |
421 | emit selected(row, col); |
422 | |
423 | #if QT_CONFIG(menu) |
424 | if (isVisible() && qobject_cast<QMenu*>(object: parentWidget())) |
425 | parentWidget()->close(); |
426 | #endif |
427 | } |
428 | |
429 | void QWellArray::focusInEvent(QFocusEvent*) |
430 | { |
431 | updateCell(row: curRow, column: curCol); |
432 | emit currentChanged(row: curRow, col: curCol); |
433 | } |
434 | |
435 | |
436 | void QWellArray::focusOutEvent(QFocusEvent*) |
437 | { |
438 | updateCell(row: curRow, column: curCol); |
439 | } |
440 | |
441 | void QWellArray::keyPressEvent(QKeyEvent* e) |
442 | { |
443 | switch(e->key()) { // Look at the key code |
444 | case Qt::Key_Left: // If 'left arrow'-key, |
445 | if (curCol > 0) // and cr't not in leftmost col |
446 | setCurrent(row: curRow, col: curCol - 1); // set cr't to next left column |
447 | break; |
448 | case Qt::Key_Right: // Correspondingly... |
449 | if (curCol < numCols()-1) |
450 | setCurrent(row: curRow, col: curCol + 1); |
451 | break; |
452 | case Qt::Key_Up: |
453 | if (curRow > 0) |
454 | setCurrent(row: curRow - 1, col: curCol); |
455 | break; |
456 | case Qt::Key_Down: |
457 | if (curRow < numRows()-1) |
458 | setCurrent(row: curRow + 1, col: curCol); |
459 | break; |
460 | #if 0 |
461 | // bad idea that shouldn't have been implemented; very counterintuitive |
462 | case Qt::Key_Return: |
463 | case Qt::Key_Enter: |
464 | /* |
465 | ignore the key, so that the dialog get it, but still select |
466 | the current row/col |
467 | */ |
468 | e->ignore(); |
469 | // fallthrough intended |
470 | #endif |
471 | case Qt::Key_Space: |
472 | setSelected(row: curRow, col: curCol); |
473 | break; |
474 | default: // If not an interesting key, |
475 | e->ignore(); // we don't accept the event |
476 | return; |
477 | } |
478 | |
479 | } // namespace QtPrivate |
480 | |
481 | //////////// QWellArray END |
482 | |
483 | // Event filter to be installed on the dialog while in color-picking mode. |
484 | class QColorPickingEventFilter : public QObject { |
485 | public: |
486 | explicit QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent) : QObject(parent), m_dp(dp) {} |
487 | |
488 | bool eventFilter(QObject *, QEvent *event) override |
489 | { |
490 | switch (event->type()) { |
491 | case QEvent::MouseMove: |
492 | return m_dp->handleColorPickingMouseMove(e: static_cast<QMouseEvent *>(event)); |
493 | case QEvent::MouseButtonRelease: |
494 | return m_dp->handleColorPickingMouseButtonRelease(e: static_cast<QMouseEvent *>(event)); |
495 | case QEvent::KeyPress: |
496 | return m_dp->handleColorPickingKeyPress(e: static_cast<QKeyEvent *>(event)); |
497 | default: |
498 | break; |
499 | } |
500 | return false; |
501 | } |
502 | |
503 | private: |
504 | QColorDialogPrivate *m_dp; |
505 | }; |
506 | |
507 | } // unnamed namespace |
508 | |
509 | /*! |
510 | Returns the number of custom colors supported by QColorDialog. All |
511 | color dialogs share the same custom colors. |
512 | */ |
513 | int QColorDialog::customCount() |
514 | { |
515 | return QColorDialogOptions::customColorCount(); |
516 | } |
517 | |
518 | /*! |
519 | Returns the custom color at the given \a index as a QColor value. |
520 | */ |
521 | QColor QColorDialog::customColor(int index) |
522 | { |
523 | return QColor(QColorDialogOptions::customColor(index)); |
524 | } |
525 | |
526 | /*! |
527 | Sets the custom color at \a index to the QColor \a color value. |
528 | |
529 | \note This function does not apply to the Native Color Dialog on the |
530 | \macos platform. If you still require this function, use the |
531 | QColorDialog::DontUseNativeDialog option. |
532 | */ |
533 | void QColorDialog::setCustomColor(int index, QColor color) |
534 | { |
535 | QColorDialogOptions::setCustomColor(index, color: color.rgba()); |
536 | } |
537 | |
538 | /*! |
539 | \since 5.0 |
540 | |
541 | Returns the standard color at the given \a index as a QColor value. |
542 | */ |
543 | QColor QColorDialog::standardColor(int index) |
544 | { |
545 | return QColor(QColorDialogOptions::standardColor(index)); |
546 | } |
547 | |
548 | /*! |
549 | Sets the standard color at \a index to the QColor \a color value. |
550 | |
551 | \note This function does not apply to the Native Color Dialog on the |
552 | \macos platform. If you still require this function, use the |
553 | QColorDialog::DontUseNativeDialog option. |
554 | */ |
555 | void QColorDialog::setStandardColor(int index, QColor color) |
556 | { |
557 | QColorDialogOptions::setStandardColor(index, color: color.rgba()); |
558 | } |
559 | |
560 | static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v) |
561 | { |
562 | QColor c; |
563 | c.setRgb(rgb); |
564 | c.getHsv(h: &h, s: &s, v: &v); |
565 | } |
566 | |
567 | namespace QtPrivate { |
568 | |
569 | class QColorWell : public QWellArray |
570 | { |
571 | public: |
572 | QColorWell(QWidget *parent, int r, int c, const QRgb *vals) |
573 | :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1) |
574 | { setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); } |
575 | |
576 | protected: |
577 | void paintCellContents(QPainter *, int row, int col, const QRect&) override; |
578 | void mousePressEvent(QMouseEvent *e) override; |
579 | void mouseMoveEvent(QMouseEvent *e) override; |
580 | void mouseReleaseEvent(QMouseEvent *e) override; |
581 | #if QT_CONFIG(draganddrop) |
582 | void dragEnterEvent(QDragEnterEvent *e) override; |
583 | void dragLeaveEvent(QDragLeaveEvent *e) override; |
584 | void dragMoveEvent(QDragMoveEvent *e) override; |
585 | void dropEvent(QDropEvent *e) override; |
586 | #endif |
587 | |
588 | private: |
589 | const QRgb *values; |
590 | bool mousePressed; |
591 | QPoint pressPos; |
592 | QPoint oldCurrent; |
593 | |
594 | }; |
595 | |
596 | void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r) |
597 | { |
598 | int i = row + col*numRows(); |
599 | p->fillRect(r, color: QColor(values[i])); |
600 | } |
601 | |
602 | void QColorWell::mousePressEvent(QMouseEvent *e) |
603 | { |
604 | oldCurrent = QPoint(selectedRow(), selectedColumn()); |
605 | QWellArray::mousePressEvent(e); |
606 | mousePressed = true; |
607 | pressPos = e->position().toPoint(); |
608 | } |
609 | |
610 | void QColorWell::mouseMoveEvent(QMouseEvent *e) |
611 | { |
612 | QWellArray::mouseMoveEvent(event: e); |
613 | #if QT_CONFIG(draganddrop) |
614 | if (!mousePressed) |
615 | return; |
616 | if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) { |
617 | setCurrent(row: oldCurrent.x(), col: oldCurrent.y()); |
618 | int i = rowAt(y: pressPos.y()) + columnAt(x: pressPos.x()) * numRows(); |
619 | QColor col(values[i]); |
620 | QMimeData *mime = new QMimeData; |
621 | mime->setColorData(col); |
622 | QPixmap pix(cellWidth(), cellHeight()); |
623 | pix.fill(fillColor: col); |
624 | QPainter p(&pix); |
625 | p.drawRect(x: 0, y: 0, w: pix.width() - 1, h: pix.height() - 1); |
626 | p.end(); |
627 | QDrag *drg = new QDrag(this); |
628 | drg->setMimeData(mime); |
629 | drg->setPixmap(pix); |
630 | mousePressed = false; |
631 | drg->exec(supportedActions: Qt::CopyAction); |
632 | } |
633 | #endif |
634 | } |
635 | |
636 | #if QT_CONFIG(draganddrop) |
637 | void QColorWell::dragEnterEvent(QDragEnterEvent *e) |
638 | { |
639 | if (qvariant_cast<QColor>(v: e->mimeData()->colorData()).isValid()) |
640 | e->accept(); |
641 | else |
642 | e->ignore(); |
643 | } |
644 | |
645 | void QColorWell::dragLeaveEvent(QDragLeaveEvent *) |
646 | { |
647 | if (hasFocus()) |
648 | parentWidget()->setFocus(); |
649 | } |
650 | |
651 | void QColorWell::dragMoveEvent(QDragMoveEvent *e) |
652 | { |
653 | if (qvariant_cast<QColor>(v: e->mimeData()->colorData()).isValid()) { |
654 | setCurrent(row: rowAt(y: e->position().toPoint().y()), col: columnAt(x: e->position().toPoint().x())); |
655 | e->accept(); |
656 | } else { |
657 | e->ignore(); |
658 | } |
659 | } |
660 | |
661 | void QColorWell::dropEvent(QDropEvent *e) |
662 | { |
663 | QColor col = qvariant_cast<QColor>(v: e->mimeData()->colorData()); |
664 | if (col.isValid()) { |
665 | int i = rowAt(y: e->position().toPoint().y()) + columnAt(x: e->position().toPoint().x()) * numRows(); |
666 | emit colorChanged(index: i, color: col.rgb()); |
667 | e->accept(); |
668 | } else { |
669 | e->ignore(); |
670 | } |
671 | } |
672 | |
673 | #endif // QT_CONFIG(draganddrop) |
674 | |
675 | void QColorWell::mouseReleaseEvent(QMouseEvent *e) |
676 | { |
677 | if (!mousePressed) |
678 | return; |
679 | QWellArray::mouseReleaseEvent(e); |
680 | mousePressed = false; |
681 | } |
682 | |
683 | class QColorPicker : public QFrame |
684 | { |
685 | Q_OBJECT |
686 | public: |
687 | QColorPicker(QWidget* parent); |
688 | ~QColorPicker(); |
689 | |
690 | void setCrossVisible(bool visible); |
691 | public slots: |
692 | void setCol(int h, int s); |
693 | |
694 | signals: |
695 | void newCol(int h, int s); |
696 | |
697 | protected: |
698 | QSize sizeHint() const override; |
699 | void paintEvent(QPaintEvent*) override; |
700 | void mouseMoveEvent(QMouseEvent *) override; |
701 | void mousePressEvent(QMouseEvent *) override; |
702 | void resizeEvent(QResizeEvent *) override; |
703 | |
704 | private: |
705 | int hue; |
706 | int sat; |
707 | |
708 | QPoint colPt(); |
709 | int huePt(const QPoint &pt); |
710 | int satPt(const QPoint &pt); |
711 | void setCol(const QPoint &pt); |
712 | |
713 | QPixmap pix; |
714 | bool crossVisible; |
715 | }; |
716 | |
717 | } // namespace QtPrivate |
718 | |
719 | static int pWidth = 220; |
720 | static int pHeight = 200; |
721 | |
722 | namespace QtPrivate { |
723 | |
724 | class QColorLuminancePicker : public QWidget |
725 | { |
726 | Q_OBJECT |
727 | public: |
728 | QColorLuminancePicker(QWidget* parent=nullptr); |
729 | ~QColorLuminancePicker(); |
730 | |
731 | public slots: |
732 | void setCol(int h, int s, int v); |
733 | void setCol(int h, int s); |
734 | |
735 | signals: |
736 | void newHsv(int h, int s, int v); |
737 | |
738 | protected: |
739 | void paintEvent(QPaintEvent*) override; |
740 | void mouseMoveEvent(QMouseEvent *) override; |
741 | void mousePressEvent(QMouseEvent *) override; |
742 | |
743 | private: |
744 | enum { foff = 3, coff = 4 }; //frame and contents offset |
745 | int val; |
746 | int hue; |
747 | int sat; |
748 | |
749 | int y2val(int y); |
750 | int val2y(int val); |
751 | void setVal(int v); |
752 | |
753 | QPixmap *pix; |
754 | }; |
755 | |
756 | |
757 | int QColorLuminancePicker::y2val(int y) |
758 | { |
759 | int d = height() - 2*coff - 1; |
760 | return 255 - (y - coff)*255/d; |
761 | } |
762 | |
763 | int QColorLuminancePicker::val2y(int v) |
764 | { |
765 | int d = height() - 2*coff - 1; |
766 | return coff + (255-v)*d/255; |
767 | } |
768 | |
769 | QColorLuminancePicker::QColorLuminancePicker(QWidget* parent) |
770 | :QWidget(parent) |
771 | { |
772 | hue = 100; val = 100; sat = 100; |
773 | pix = nullptr; |
774 | // setAttribute(WA_NoErase, true); |
775 | } |
776 | |
777 | QColorLuminancePicker::~QColorLuminancePicker() |
778 | { |
779 | delete pix; |
780 | } |
781 | |
782 | void QColorLuminancePicker::mouseMoveEvent(QMouseEvent *m) |
783 | { |
784 | if (m->buttons() == Qt::NoButton) { |
785 | m->ignore(); |
786 | return; |
787 | } |
788 | setVal(y2val(y: m->position().toPoint().y())); |
789 | } |
790 | void QColorLuminancePicker::mousePressEvent(QMouseEvent *m) |
791 | { |
792 | setVal(y2val(y: m->position().toPoint().y())); |
793 | } |
794 | |
795 | void QColorLuminancePicker::setVal(int v) |
796 | { |
797 | if (val == v) |
798 | return; |
799 | val = qMax(a: 0, b: qMin(a: v,b: 255)); |
800 | delete pix; pix=nullptr; |
801 | repaint(); |
802 | emit newHsv(h: hue, s: sat, v: val); |
803 | } |
804 | |
805 | //receives from a hue,sat chooser and relays. |
806 | void QColorLuminancePicker::setCol(int h, int s) |
807 | { |
808 | setCol(h, s, v: val); |
809 | emit newHsv(h, s, v: val); |
810 | } |
811 | |
812 | void QColorLuminancePicker::paintEvent(QPaintEvent *) |
813 | { |
814 | int w = width() - 5; |
815 | |
816 | QRect r(0, foff, w, height() - 2*foff); |
817 | int wi = r.width() - 2; |
818 | int hi = r.height() - 2; |
819 | if (!pix || pix->height() != hi || pix->width() != wi) { |
820 | delete pix; |
821 | QImage img(wi, hi, QImage::Format_RGB32); |
822 | int y; |
823 | uint *pixel = (uint *) img.scanLine(0); |
824 | for (y = 0; y < hi; y++) { |
825 | uint *end = pixel + wi; |
826 | std::fill(first: pixel, last: end, value: QColor::fromHsv(h: hue, s: sat, v: y2val(y: y + coff)).rgb()); |
827 | pixel = end; |
828 | } |
829 | pix = new QPixmap(QPixmap::fromImage(image: img)); |
830 | } |
831 | QPainter p(this); |
832 | p.drawPixmap(x: 1, y: coff, pm: *pix); |
833 | const QPalette &g = palette(); |
834 | qDrawShadePanel(p: &p, r, pal: g, sunken: true); |
835 | p.setPen(g.windowText().color()); |
836 | p.setBrush(g.windowText()); |
837 | p.eraseRect(x: w, y: 0, w: 5, h: height()); |
838 | const int y = val2y(v: val); |
839 | const std::array<QPoint, 3> points = {QPoint(w, y), QPoint(w + 5, y + 5), QPoint(w + 5, y - 5)}; |
840 | p.drawPolygon(points: points.data(), pointCount: static_cast<int>(points.size())); |
841 | } |
842 | |
843 | void QColorLuminancePicker::setCol(int h, int s , int v) |
844 | { |
845 | val = v; |
846 | hue = h; |
847 | sat = s; |
848 | delete pix; pix=nullptr; |
849 | repaint(); |
850 | } |
851 | |
852 | QPoint QColorPicker::colPt() |
853 | { |
854 | QRect r = contentsRect(); |
855 | return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255); |
856 | } |
857 | |
858 | int QColorPicker::huePt(const QPoint &pt) |
859 | { |
860 | QRect r = contentsRect(); |
861 | return 360 - pt.x() * 360 / (r.width() - 1); |
862 | } |
863 | |
864 | int QColorPicker::satPt(const QPoint &pt) |
865 | { |
866 | QRect r = contentsRect(); |
867 | return 255 - pt.y() * 255 / (r.height() - 1); |
868 | } |
869 | |
870 | void QColorPicker::setCol(const QPoint &pt) |
871 | { |
872 | setCol(h: huePt(pt), s: satPt(pt)); |
873 | } |
874 | |
875 | QColorPicker::QColorPicker(QWidget* parent) |
876 | : QFrame(parent) |
877 | , crossVisible(true) |
878 | { |
879 | hue = 0; sat = 0; |
880 | setCol(h: 150, s: 255); |
881 | |
882 | setAttribute(Qt::WA_NoSystemBackground); |
883 | setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) ); |
884 | } |
885 | |
886 | QColorPicker::~QColorPicker() |
887 | { |
888 | } |
889 | |
890 | void QColorPicker::setCrossVisible(bool visible) |
891 | { |
892 | if (crossVisible != visible) { |
893 | crossVisible = visible; |
894 | update(); |
895 | } |
896 | } |
897 | |
898 | QSize QColorPicker::sizeHint() const |
899 | { |
900 | return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth()); |
901 | } |
902 | |
903 | void QColorPicker::setCol(int h, int s) |
904 | { |
905 | int nhue = qMin(a: qMax(a: 0,b: h), b: 359); |
906 | int nsat = qMin(a: qMax(a: 0,b: s), b: 255); |
907 | if (nhue == hue && nsat == sat) |
908 | return; |
909 | |
910 | QRect r(colPt(), QSize(20,20)); |
911 | hue = nhue; sat = nsat; |
912 | r = r.united(r: QRect(colPt(), QSize(20,20))); |
913 | r.translate(dx: contentsRect().x()-9, dy: contentsRect().y()-9); |
914 | // update(r); |
915 | repaint(r); |
916 | } |
917 | |
918 | void QColorPicker::mouseMoveEvent(QMouseEvent *m) |
919 | { |
920 | QPoint p = m->position().toPoint() - contentsRect().topLeft(); |
921 | if (m->buttons() == Qt::NoButton) { |
922 | m->ignore(); |
923 | return; |
924 | } |
925 | setCol(p); |
926 | emit newCol(h: hue, s: sat); |
927 | } |
928 | |
929 | void QColorPicker::mousePressEvent(QMouseEvent *m) |
930 | { |
931 | QPoint p = m->position().toPoint() - contentsRect().topLeft(); |
932 | setCol(p); |
933 | emit newCol(h: hue, s: sat); |
934 | } |
935 | |
936 | void QColorPicker::paintEvent(QPaintEvent* ) |
937 | { |
938 | QPainter p(this); |
939 | drawFrame(&p); |
940 | QRect r = contentsRect(); |
941 | |
942 | p.drawPixmap(p: r.topLeft(), pm: pix); |
943 | |
944 | if (crossVisible) { |
945 | QPoint pt = colPt() + r.topLeft(); |
946 | p.setPen(Qt::black); |
947 | p.fillRect(x: pt.x()-9, y: pt.y(), w: 20, h: 2, c: Qt::black); |
948 | p.fillRect(x: pt.x(), y: pt.y()-9, w: 2, h: 20, c: Qt::black); |
949 | } |
950 | } |
951 | |
952 | void QColorPicker::resizeEvent(QResizeEvent *ev) |
953 | { |
954 | QFrame::resizeEvent(event: ev); |
955 | |
956 | int w = width() - frameWidth() * 2; |
957 | int h = height() - frameWidth() * 2; |
958 | QImage img(w, h, QImage::Format_RGB32); |
959 | int x, y; |
960 | uint *pixel = (uint *) img.scanLine(0); |
961 | for (y = 0; y < h; y++) { |
962 | const uint *end = pixel + w; |
963 | x = 0; |
964 | while (pixel < end) { |
965 | QPoint p(x, y); |
966 | QColor c; |
967 | c.setHsv(h: huePt(pt: p), s: satPt(pt: p), v: 200); |
968 | *pixel = c.rgb(); |
969 | ++pixel; |
970 | ++x; |
971 | } |
972 | } |
973 | pix = QPixmap::fromImage(image: img); |
974 | } |
975 | |
976 | |
977 | class QColSpinBox : public QSpinBox |
978 | { |
979 | public: |
980 | QColSpinBox(QWidget *parent) |
981 | : QSpinBox(parent) { setRange(min: 0, max: 255); } |
982 | void setValue(int i) { |
983 | const QSignalBlocker blocker(this); |
984 | QSpinBox::setValue(i); |
985 | } |
986 | }; |
987 | |
988 | class QColorShowLabel; |
989 | |
990 | class QColorShower : public QWidget |
991 | { |
992 | Q_OBJECT |
993 | public: |
994 | QColorShower(QColorDialog *parent); |
995 | |
996 | //things that don't emit signals |
997 | void setHsv(int h, int s, int v); |
998 | |
999 | int currentAlpha() const |
1000 | { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; } |
1001 | void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); } |
1002 | void showAlpha(bool b); |
1003 | bool isAlphaVisible() const; |
1004 | |
1005 | QRgb currentColor() const { return curCol; } |
1006 | QColor currentQColor() const { return curQColor; } |
1007 | void retranslateStrings(); |
1008 | void updateQColor(); |
1009 | |
1010 | public slots: |
1011 | void setRgb(QRgb rgb); |
1012 | |
1013 | signals: |
1014 | void newCol(QRgb rgb); |
1015 | void currentColorChanged(const QColor &color); |
1016 | |
1017 | private slots: |
1018 | void rgbEd(); |
1019 | void hsvEd(); |
1020 | void htmlEd(); |
1021 | |
1022 | private: |
1023 | void showCurrentColor(); |
1024 | int hue, sat, val; |
1025 | QRgb curCol; |
1026 | QColor curQColor; |
1027 | QLabel *lblHue; |
1028 | QLabel *lblSat; |
1029 | QLabel *lblVal; |
1030 | QLabel *lblRed; |
1031 | QLabel *lblGreen; |
1032 | QLabel *lblBlue; |
1033 | QLabel *lblHtml; |
1034 | QColSpinBox *hEd; |
1035 | QColSpinBox *sEd; |
1036 | QColSpinBox *vEd; |
1037 | QColSpinBox *rEd; |
1038 | QColSpinBox *gEd; |
1039 | QColSpinBox *bEd; |
1040 | QColSpinBox *alphaEd; |
1041 | QLabel *alphaLab; |
1042 | QLineEdit *htEd; |
1043 | QColorShowLabel *lab; |
1044 | bool rgbOriginal; |
1045 | QColorDialog *colorDialog; |
1046 | QGridLayout *gl; |
1047 | |
1048 | friend class QT_PREPEND_NAMESPACE(QColorDialog); |
1049 | friend class QT_PREPEND_NAMESPACE(QColorDialogPrivate); |
1050 | }; |
1051 | |
1052 | class QColorShowLabel : public QFrame |
1053 | { |
1054 | Q_OBJECT |
1055 | |
1056 | public: |
1057 | QColorShowLabel(QWidget *parent) : QFrame(parent) { |
1058 | setFrameStyle(QFrame::Panel|QFrame::Sunken); |
1059 | setAcceptDrops(true); |
1060 | mousePressed = false; |
1061 | } |
1062 | void setColor(QColor c) { col = c; } |
1063 | |
1064 | signals: |
1065 | void colorDropped(QRgb); |
1066 | |
1067 | protected: |
1068 | void paintEvent(QPaintEvent *) override; |
1069 | void mousePressEvent(QMouseEvent *e) override; |
1070 | void mouseMoveEvent(QMouseEvent *e) override; |
1071 | void mouseReleaseEvent(QMouseEvent *e) override; |
1072 | #if QT_CONFIG(draganddrop) |
1073 | void dragEnterEvent(QDragEnterEvent *e) override; |
1074 | void dragLeaveEvent(QDragLeaveEvent *e) override; |
1075 | void dropEvent(QDropEvent *e) override; |
1076 | #endif |
1077 | |
1078 | private: |
1079 | QColor col; |
1080 | bool mousePressed; |
1081 | QPoint pressPos; |
1082 | }; |
1083 | |
1084 | void QColorShowLabel::paintEvent(QPaintEvent *e) |
1085 | { |
1086 | QPainter p(this); |
1087 | drawFrame(&p); |
1088 | p.fillRect(contentsRect()&e->rect(), color: col); |
1089 | } |
1090 | |
1091 | void QColorShower::showAlpha(bool b) |
1092 | { |
1093 | alphaLab->setVisible(b); |
1094 | alphaEd->setVisible(b); |
1095 | } |
1096 | |
1097 | inline bool QColorShower::isAlphaVisible() const |
1098 | { |
1099 | return alphaLab->isVisible(); |
1100 | } |
1101 | |
1102 | void QColorShowLabel::mousePressEvent(QMouseEvent *e) |
1103 | { |
1104 | mousePressed = true; |
1105 | pressPos = e->position().toPoint(); |
1106 | } |
1107 | |
1108 | void QColorShowLabel::mouseMoveEvent(QMouseEvent *e) |
1109 | { |
1110 | #if !QT_CONFIG(draganddrop) |
1111 | Q_UNUSED(e); |
1112 | #else |
1113 | if (!mousePressed) |
1114 | return; |
1115 | if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) { |
1116 | QMimeData *mime = new QMimeData; |
1117 | mime->setColorData(col); |
1118 | QPixmap pix(30, 20); |
1119 | pix.fill(fillColor: col); |
1120 | QPainter p(&pix); |
1121 | p.drawRect(x: 0, y: 0, w: pix.width() - 1, h: pix.height() - 1); |
1122 | p.end(); |
1123 | QDrag *drg = new QDrag(this); |
1124 | drg->setMimeData(mime); |
1125 | drg->setPixmap(pix); |
1126 | mousePressed = false; |
1127 | drg->exec(supportedActions: Qt::CopyAction); |
1128 | } |
1129 | #endif |
1130 | } |
1131 | |
1132 | #if QT_CONFIG(draganddrop) |
1133 | void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e) |
1134 | { |
1135 | if (qvariant_cast<QColor>(v: e->mimeData()->colorData()).isValid()) |
1136 | e->accept(); |
1137 | else |
1138 | e->ignore(); |
1139 | } |
1140 | |
1141 | void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *) |
1142 | { |
1143 | } |
1144 | |
1145 | void QColorShowLabel::dropEvent(QDropEvent *e) |
1146 | { |
1147 | QColor color = qvariant_cast<QColor>(v: e->mimeData()->colorData()); |
1148 | if (color.isValid()) { |
1149 | col = color; |
1150 | repaint(); |
1151 | emit colorDropped(col.rgb()); |
1152 | e->accept(); |
1153 | } else { |
1154 | e->ignore(); |
1155 | } |
1156 | } |
1157 | #endif // QT_CONFIG(draganddrop) |
1158 | |
1159 | void QColorShowLabel::mouseReleaseEvent(QMouseEvent *) |
1160 | { |
1161 | if (!mousePressed) |
1162 | return; |
1163 | mousePressed = false; |
1164 | } |
1165 | |
1166 | QColorShower::QColorShower(QColorDialog *parent) |
1167 | : QWidget(parent) |
1168 | { |
1169 | colorDialog = parent; |
1170 | |
1171 | curCol = qRgb(r: 255, g: 255, b: 255); |
1172 | curQColor = Qt::white; |
1173 | |
1174 | gl = new QGridLayout(this); |
1175 | const int s = gl->spacing(); |
1176 | gl->setContentsMargins(left: s, top: s, right: s, bottom: s); |
1177 | lab = new QColorShowLabel(this); |
1178 | |
1179 | #ifdef QT_SMALL_COLORDIALOG |
1180 | lab->setMinimumHeight(60); |
1181 | #endif |
1182 | lab->setMinimumWidth(60); |
1183 | |
1184 | // For QVGA screens only the comboboxes and color label are visible. |
1185 | // For nHD screens only color and luminence pickers and color label are visible. |
1186 | #if !defined(QT_SMALL_COLORDIALOG) |
1187 | gl->addWidget(lab, row: 0, column: 0, rowSpan: -1, columnSpan: 1); |
1188 | #else |
1189 | gl->addWidget(lab, 0, 0, 1, -1); |
1190 | #endif |
1191 | connect(sender: lab, signal: &QColorShowLabel::colorDropped, context: this, slot: &QColorShower::newCol); |
1192 | connect(sender: lab, signal: &QColorShowLabel::colorDropped, context: this, slot: &QColorShower::setRgb); |
1193 | |
1194 | hEd = new QColSpinBox(this); |
1195 | hEd->setRange(min: 0, max: 359); |
1196 | lblHue = new QLabel(this); |
1197 | #ifndef QT_NO_SHORTCUT |
1198 | lblHue->setBuddy(hEd); |
1199 | #endif |
1200 | lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1201 | #if !defined(QT_SMALL_COLORDIALOG) |
1202 | gl->addWidget(lblHue, row: 0, column: 1); |
1203 | gl->addWidget(hEd, row: 0, column: 2); |
1204 | #else |
1205 | gl->addWidget(lblHue, 1, 0); |
1206 | gl->addWidget(hEd, 2, 0); |
1207 | #endif |
1208 | |
1209 | sEd = new QColSpinBox(this); |
1210 | lblSat = new QLabel(this); |
1211 | #ifndef QT_NO_SHORTCUT |
1212 | lblSat->setBuddy(sEd); |
1213 | #endif |
1214 | lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1215 | #if !defined(QT_SMALL_COLORDIALOG) |
1216 | gl->addWidget(lblSat, row: 1, column: 1); |
1217 | gl->addWidget(sEd, row: 1, column: 2); |
1218 | #else |
1219 | gl->addWidget(lblSat, 1, 1); |
1220 | gl->addWidget(sEd, 2, 1); |
1221 | #endif |
1222 | |
1223 | vEd = new QColSpinBox(this); |
1224 | lblVal = new QLabel(this); |
1225 | #ifndef QT_NO_SHORTCUT |
1226 | lblVal->setBuddy(vEd); |
1227 | #endif |
1228 | lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1229 | #if !defined(QT_SMALL_COLORDIALOG) |
1230 | gl->addWidget(lblVal, row: 2, column: 1); |
1231 | gl->addWidget(vEd, row: 2, column: 2); |
1232 | #else |
1233 | gl->addWidget(lblVal, 1, 2); |
1234 | gl->addWidget(vEd, 2, 2); |
1235 | #endif |
1236 | |
1237 | rEd = new QColSpinBox(this); |
1238 | lblRed = new QLabel(this); |
1239 | #ifndef QT_NO_SHORTCUT |
1240 | lblRed->setBuddy(rEd); |
1241 | #endif |
1242 | lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1243 | #if !defined(QT_SMALL_COLORDIALOG) |
1244 | gl->addWidget(lblRed, row: 0, column: 3); |
1245 | gl->addWidget(rEd, row: 0, column: 4); |
1246 | #else |
1247 | gl->addWidget(lblRed, 3, 0); |
1248 | gl->addWidget(rEd, 4, 0); |
1249 | #endif |
1250 | |
1251 | gEd = new QColSpinBox(this); |
1252 | lblGreen = new QLabel(this); |
1253 | #ifndef QT_NO_SHORTCUT |
1254 | lblGreen->setBuddy(gEd); |
1255 | #endif |
1256 | lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1257 | #if !defined(QT_SMALL_COLORDIALOG) |
1258 | gl->addWidget(lblGreen, row: 1, column: 3); |
1259 | gl->addWidget(gEd, row: 1, column: 4); |
1260 | #else |
1261 | gl->addWidget(lblGreen, 3, 1); |
1262 | gl->addWidget(gEd, 4, 1); |
1263 | #endif |
1264 | |
1265 | bEd = new QColSpinBox(this); |
1266 | lblBlue = new QLabel(this); |
1267 | #ifndef QT_NO_SHORTCUT |
1268 | lblBlue->setBuddy(bEd); |
1269 | #endif |
1270 | lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1271 | #if !defined(QT_SMALL_COLORDIALOG) |
1272 | gl->addWidget(lblBlue, row: 2, column: 3); |
1273 | gl->addWidget(bEd, row: 2, column: 4); |
1274 | #else |
1275 | gl->addWidget(lblBlue, 3, 2); |
1276 | gl->addWidget(bEd, 4, 2); |
1277 | #endif |
1278 | |
1279 | alphaEd = new QColSpinBox(this); |
1280 | alphaLab = new QLabel(this); |
1281 | #ifndef QT_NO_SHORTCUT |
1282 | alphaLab->setBuddy(alphaEd); |
1283 | #endif |
1284 | alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1285 | #if !defined(QT_SMALL_COLORDIALOG) |
1286 | gl->addWidget(alphaLab, row: 3, column: 1, rowSpan: 1, columnSpan: 3); |
1287 | gl->addWidget(alphaEd, row: 3, column: 4); |
1288 | #else |
1289 | gl->addWidget(alphaLab, 1, 3, 3, 1); |
1290 | gl->addWidget(alphaEd, 4, 3); |
1291 | #endif |
1292 | alphaEd->hide(); |
1293 | alphaLab->hide(); |
1294 | lblHtml = new QLabel(this); |
1295 | htEd = new QLineEdit(this); |
1296 | htEd->setObjectName("qt_colorname_lineedit"); |
1297 | #ifndef QT_NO_SHORTCUT |
1298 | lblHtml->setBuddy(htEd); |
1299 | #endif |
1300 | |
1301 | #if QT_CONFIG(regularexpression) |
1302 | QRegularExpression regExp(QStringLiteral("#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})")); |
1303 | QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this); |
1304 | htEd->setValidator(validator); |
1305 | #else |
1306 | htEd->setReadOnly(true); |
1307 | #endif |
1308 | htEd->setSizePolicy(hor: QSizePolicy::Maximum, ver: QSizePolicy::Fixed); |
1309 | |
1310 | lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter); |
1311 | #if defined(QT_SMALL_COLORDIALOG) |
1312 | gl->addWidget(lblHtml, 5, 0); |
1313 | gl->addWidget(htEd, 5, 1, 1, /*colspan=*/ 2); |
1314 | #else |
1315 | gl->addWidget(lblHtml, row: 5, column: 1); |
1316 | gl->addWidget(htEd, row: 5, column: 2, rowSpan: 1, /*colspan=*/ columnSpan: 3); |
1317 | #endif |
1318 | |
1319 | connect(sender: hEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::hsvEd); |
1320 | connect(sender: sEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::hsvEd); |
1321 | connect(sender: vEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::hsvEd); |
1322 | |
1323 | connect(sender: rEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::rgbEd); |
1324 | connect(sender: gEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::rgbEd); |
1325 | connect(sender: bEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::rgbEd); |
1326 | connect(sender: alphaEd, signal: &QSpinBox::valueChanged, context: this, slot: &QColorShower::rgbEd); |
1327 | connect(sender: htEd, signal: &QLineEdit::textEdited, context: this, slot: &QColorShower::htmlEd); |
1328 | |
1329 | retranslateStrings(); |
1330 | } |
1331 | |
1332 | } // namespace QtPrivate |
1333 | |
1334 | inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); } |
1335 | inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); } |
1336 | inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); } |
1337 | inline void QColorDialogPrivate::showAlpha(bool b) { cs->showAlpha(b); } |
1338 | inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisible(); } |
1339 | |
1340 | QColor QColorDialogPrivate::currentQColor() const |
1341 | { |
1342 | if (nativeDialogInUse) |
1343 | return platformColorDialogHelper()->currentColor(); |
1344 | return cs->currentQColor(); |
1345 | } |
1346 | |
1347 | void QColorShower::showCurrentColor() |
1348 | { |
1349 | lab->setColor(currentColor()); |
1350 | lab->repaint(); |
1351 | } |
1352 | |
1353 | void QColorShower::rgbEd() |
1354 | { |
1355 | rgbOriginal = true; |
1356 | curCol = qRgba(r: rEd->value(), g: gEd->value(), b: bEd->value(), a: currentAlpha()); |
1357 | |
1358 | rgb2hsv(rgb: currentColor(), h&: hue, s&: sat, v&: val); |
1359 | |
1360 | hEd->setValue(hue); |
1361 | sEd->setValue(sat); |
1362 | vEd->setValue(val); |
1363 | |
1364 | htEd->setText(QColor(curCol).name()); |
1365 | |
1366 | showCurrentColor(); |
1367 | emit newCol(rgb: currentColor()); |
1368 | updateQColor(); |
1369 | } |
1370 | |
1371 | void QColorShower::hsvEd() |
1372 | { |
1373 | rgbOriginal = false; |
1374 | hue = hEd->value(); |
1375 | sat = sEd->value(); |
1376 | val = vEd->value(); |
1377 | |
1378 | QColor c; |
1379 | c.setHsv(h: hue, s: sat, v: val); |
1380 | curCol = c.rgb(); |
1381 | |
1382 | rEd->setValue(qRed(rgb: currentColor())); |
1383 | gEd->setValue(qGreen(rgb: currentColor())); |
1384 | bEd->setValue(qBlue(rgb: currentColor())); |
1385 | |
1386 | htEd->setText(c.name()); |
1387 | |
1388 | showCurrentColor(); |
1389 | emit newCol(rgb: currentColor()); |
1390 | updateQColor(); |
1391 | } |
1392 | |
1393 | void QColorShower::htmlEd() |
1394 | { |
1395 | QString t = htEd->text(); |
1396 | if (t.isEmpty()) |
1397 | return; |
1398 | |
1399 | if (!t.startsWith(s: u"#")) { |
1400 | t.prepend(v: u"#"); |
1401 | QSignalBlocker blocker(htEd); |
1402 | htEd->setText(t); |
1403 | } |
1404 | |
1405 | QColor c = QColor::fromString(name: t); |
1406 | if (!c.isValid()) |
1407 | return; |
1408 | |
1409 | curCol = qRgba(r: c.red(), g: c.green(), b: c.blue(), a: currentAlpha()); |
1410 | rgb2hsv(rgb: curCol, h&: hue, s&: sat, v&: val); |
1411 | |
1412 | hEd->setValue(hue); |
1413 | sEd->setValue(sat); |
1414 | vEd->setValue(val); |
1415 | |
1416 | rEd->setValue(qRed(rgb: currentColor())); |
1417 | gEd->setValue(qGreen(rgb: currentColor())); |
1418 | bEd->setValue(qBlue(rgb: currentColor())); |
1419 | |
1420 | showCurrentColor(); |
1421 | emit newCol(rgb: currentColor()); |
1422 | updateQColor(); |
1423 | } |
1424 | |
1425 | void QColorShower::setRgb(QRgb rgb) |
1426 | { |
1427 | rgbOriginal = true; |
1428 | curCol = rgb; |
1429 | |
1430 | rgb2hsv(rgb: currentColor(), h&: hue, s&: sat, v&: val); |
1431 | |
1432 | hEd->setValue(hue); |
1433 | sEd->setValue(sat); |
1434 | vEd->setValue(val); |
1435 | |
1436 | rEd->setValue(qRed(rgb: currentColor())); |
1437 | gEd->setValue(qGreen(rgb: currentColor())); |
1438 | bEd->setValue(qBlue(rgb: currentColor())); |
1439 | |
1440 | htEd->setText(QColor(rgb).name()); |
1441 | |
1442 | showCurrentColor(); |
1443 | updateQColor(); |
1444 | } |
1445 | |
1446 | void QColorShower::setHsv(int h, int s, int v) |
1447 | { |
1448 | if (h < -1 || (uint)s > 255 || (uint)v > 255) |
1449 | return; |
1450 | |
1451 | rgbOriginal = false; |
1452 | hue = h; val = v; sat = s; |
1453 | QColor c; |
1454 | c.setHsv(h: hue, s: sat, v: val); |
1455 | curCol = c.rgb(); |
1456 | |
1457 | hEd->setValue(hue); |
1458 | sEd->setValue(sat); |
1459 | vEd->setValue(val); |
1460 | |
1461 | rEd->setValue(qRed(rgb: currentColor())); |
1462 | gEd->setValue(qGreen(rgb: currentColor())); |
1463 | bEd->setValue(qBlue(rgb: currentColor())); |
1464 | |
1465 | htEd->setText(c.name()); |
1466 | |
1467 | showCurrentColor(); |
1468 | updateQColor(); |
1469 | } |
1470 | |
1471 | void QColorShower::retranslateStrings() |
1472 | { |
1473 | lblHue->setText(QColorDialog::tr(s: "Hu&e:")); |
1474 | lblSat->setText(QColorDialog::tr(s: "&Sat:")); |
1475 | lblVal->setText(QColorDialog::tr(s: "&Val:")); |
1476 | lblRed->setText(QColorDialog::tr(s: "&Red:")); |
1477 | lblGreen->setText(QColorDialog::tr(s: "&Green:")); |
1478 | lblBlue->setText(QColorDialog::tr(s: "Bl&ue:")); |
1479 | alphaLab->setText(QColorDialog::tr(s: "A&lpha channel:")); |
1480 | lblHtml->setText(QColorDialog::tr(s: "&HTML:")); |
1481 | } |
1482 | |
1483 | void QColorShower::updateQColor() |
1484 | { |
1485 | QColor oldQColor(curQColor); |
1486 | curQColor.setRgba(qRgba(r: qRed(rgb: curCol), g: qGreen(rgb: curCol), b: qBlue(rgb: curCol), a: currentAlpha())); |
1487 | if (curQColor != oldQColor) |
1488 | emit currentColorChanged(color: curQColor); |
1489 | } |
1490 | |
1491 | //sets all widgets to display h,s,v |
1492 | void QColorDialogPrivate::newHsv(int h, int s, int v) |
1493 | { |
1494 | if (!nativeDialogInUse) { |
1495 | cs->setHsv(h, s, v); |
1496 | cp->setCol(h, s); |
1497 | lp->setCol(h, s, v); |
1498 | } |
1499 | } |
1500 | |
1501 | //sets all widgets to display rgb |
1502 | void QColorDialogPrivate::setCurrentRgbColor(QRgb rgb) |
1503 | { |
1504 | if (!nativeDialogInUse) { |
1505 | cs->setRgb(rgb); |
1506 | newColorTypedIn(rgb); |
1507 | } |
1508 | } |
1509 | |
1510 | // hack; doesn't keep curCol in sync, so use with care |
1511 | void QColorDialogPrivate::setCurrentQColor(const QColor &color) |
1512 | { |
1513 | Q_Q(QColorDialog); |
1514 | if (cs->curQColor != color) { |
1515 | cs->curQColor = color; |
1516 | emit q->currentColorChanged(color); |
1517 | } |
1518 | } |
1519 | |
1520 | // size of standard and custom color selector |
1521 | enum { |
1522 | colorColumns = 8, |
1523 | standardColorRows = 6, |
1524 | customColorRows = 2 |
1525 | }; |
1526 | |
1527 | bool QColorDialogPrivate::selectColor(const QColor &col) |
1528 | { |
1529 | QRgb color = col.rgb(); |
1530 | // Check standard colors |
1531 | if (standard) { |
1532 | const QRgb *standardColors = QColorDialogOptions::standardColors(); |
1533 | const QRgb *standardColorsEnd = standardColors + standardColorRows * colorColumns; |
1534 | const QRgb *match = std::find(first: standardColors, last: standardColorsEnd, val: color); |
1535 | if (match != standardColorsEnd) { |
1536 | const int index = int(match - standardColors); |
1537 | const int column = index / standardColorRows; |
1538 | const int row = index % standardColorRows; |
1539 | newStandard(row, column); |
1540 | standard->setCurrent(row, col: column); |
1541 | standard->setSelected(row, col: column); |
1542 | standard->setFocus(); |
1543 | return true; |
1544 | } |
1545 | } |
1546 | // Check custom colors |
1547 | if (custom) { |
1548 | const QRgb *customColors = QColorDialogOptions::customColors(); |
1549 | const QRgb *customColorsEnd = customColors + customColorRows * colorColumns; |
1550 | const QRgb *match = std::find(first: customColors, last: customColorsEnd, val: color); |
1551 | if (match != customColorsEnd) { |
1552 | const int index = int(match - customColors); |
1553 | const int column = index / customColorRows; |
1554 | const int row = index % customColorRows; |
1555 | newCustom(row, column); |
1556 | custom->setCurrent(row, col: column); |
1557 | custom->setSelected(row, col: column); |
1558 | custom->setFocus(); |
1559 | return true; |
1560 | } |
1561 | } |
1562 | return false; |
1563 | } |
1564 | |
1565 | QColor QColorDialogPrivate::grabScreenColor(const QPoint &p) |
1566 | { |
1567 | QScreen *screen = QGuiApplication::screenAt(point: p); |
1568 | if (!screen) |
1569 | screen = QGuiApplication::primaryScreen(); |
1570 | const QRect screenRect = screen->geometry(); |
1571 | const QPixmap pixmap = |
1572 | screen->grabWindow(window: 0, x: p.x() - screenRect.x(), y: p.y() - screenRect.y(), w: 1, h: 1); |
1573 | const QImage i = pixmap.toImage(); |
1574 | return i.pixel(x: 0, y: 0); |
1575 | } |
1576 | |
1577 | //sets all widgets except cs to display rgb |
1578 | void QColorDialogPrivate::newColorTypedIn(QRgb rgb) |
1579 | { |
1580 | if (!nativeDialogInUse) { |
1581 | int h, s, v; |
1582 | rgb2hsv(rgb, h, s, v); |
1583 | cp->setCol(h, s); |
1584 | lp->setCol(h, s, v); |
1585 | } |
1586 | } |
1587 | |
1588 | void QColorDialogPrivate::nextCustom(int r, int c) |
1589 | { |
1590 | nextCust = r + customColorRows * c; |
1591 | } |
1592 | |
1593 | void QColorDialogPrivate::newCustom(int r, int c) |
1594 | { |
1595 | const int i = r + customColorRows * c; |
1596 | setCurrentRgbColor(QColorDialogOptions::customColor(index: i)); |
1597 | if (standard) |
1598 | standard->setSelected(row: -1,col: -1); |
1599 | } |
1600 | |
1601 | void QColorDialogPrivate::newStandard(int r, int c) |
1602 | { |
1603 | setCurrentRgbColor(QColorDialogOptions::standardColor(index: r + c * 6)); |
1604 | if (custom) |
1605 | custom->setSelected(row: -1,col: -1); |
1606 | } |
1607 | |
1608 | void QColorDialogPrivate::pickScreenColor() |
1609 | { |
1610 | Q_Q(QColorDialog); |
1611 | |
1612 | auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services(); |
1613 | if (platformServices->hasCapability(capability: QPlatformServices::Capability::ColorPicking)) { |
1614 | if (auto *colorPicker = platformServices->colorPicker(parent: q->windowHandle())) { |
1615 | q->connect(sender: colorPicker, signal: &QPlatformServiceColorPicker::colorPicked, context: q, |
1616 | slot: [q, colorPicker](const QColor &color) { |
1617 | colorPicker->deleteLater(); |
1618 | q->setCurrentColor(color); |
1619 | }); |
1620 | colorPicker->pickColor(); |
1621 | return; |
1622 | } |
1623 | } |
1624 | |
1625 | if (!colorPickingEventFilter) |
1626 | colorPickingEventFilter = new QColorPickingEventFilter(this, q); |
1627 | q->installEventFilter(filterObj: colorPickingEventFilter); |
1628 | // If user pushes Escape, the last color before picking will be restored. |
1629 | beforeScreenColorPicking = cs->currentColor(); |
1630 | #ifndef QT_NO_CURSOR |
1631 | q->grabMouse(Qt::CrossCursor); |
1632 | #else |
1633 | q->grabMouse(); |
1634 | #endif |
1635 | |
1636 | #ifdef Q_OS_WIN32 |
1637 | // On Windows mouse tracking doesn't work over other processes's windows |
1638 | updateTimer->start(30); |
1639 | |
1640 | // HACK: Because mouse grabbing doesn't work across processes, we have to have a dummy, |
1641 | // invisible window to catch the mouse click, otherwise we will click whatever we clicked |
1642 | // and loose focus. |
1643 | dummyTransparentWindow.show(); |
1644 | #endif |
1645 | q->grabKeyboard(); |
1646 | /* With setMouseTracking(true) the desired color can be more precisely picked up, |
1647 | * and continuously pushing the mouse button is not necessary. |
1648 | */ |
1649 | q->setMouseTracking(true); |
1650 | |
1651 | addCusBt->setDisabled(true); |
1652 | buttons->setDisabled(true); |
1653 | if (eyeDropperButton) { |
1654 | eyeDropperButton->setDisabled(true); |
1655 | const QPoint globalPos = QCursor::pos(); |
1656 | q->setCurrentColor(grabScreenColor(p: globalPos)); |
1657 | updateColorLabelText(globalPos); |
1658 | } |
1659 | } |
1660 | |
1661 | void QColorDialogPrivate::updateColorLabelText(const QPoint &globalPos) |
1662 | { |
1663 | if (lblScreenColorInfo) |
1664 | lblScreenColorInfo->setText(QColorDialog::tr(s: "Cursor at %1, %2\nPress ESC to cancel") |
1665 | .arg(a: globalPos.x()) |
1666 | .arg(a: globalPos.y())); |
1667 | } |
1668 | |
1669 | void QColorDialogPrivate::releaseColorPicking() |
1670 | { |
1671 | Q_Q(QColorDialog); |
1672 | cp->setCrossVisible(true); |
1673 | q->removeEventFilter(obj: colorPickingEventFilter); |
1674 | q->releaseMouse(); |
1675 | #ifdef Q_OS_WIN32 |
1676 | updateTimer->stop(); |
1677 | dummyTransparentWindow.setVisible(false); |
1678 | #endif |
1679 | q->releaseKeyboard(); |
1680 | q->setMouseTracking(false); |
1681 | lblScreenColorInfo->setText("\n"_L1); |
1682 | addCusBt->setDisabled(false); |
1683 | buttons->setDisabled(false); |
1684 | eyeDropperButton->setDisabled(false); |
1685 | } |
1686 | |
1687 | void QColorDialogPrivate::init(const QColor &initial) |
1688 | { |
1689 | Q_Q(QColorDialog); |
1690 | |
1691 | q->setSizeGripEnabled(false); |
1692 | q->setWindowTitle(QColorDialog::tr(s: "Select Color")); |
1693 | |
1694 | // default: use the native dialog if possible. Can be overridden in setOptions() |
1695 | nativeDialogInUse = (platformColorDialogHelper() != nullptr); |
1696 | colorPickingEventFilter = nullptr; |
1697 | nextCust = 0; |
1698 | |
1699 | if (!nativeDialogInUse) |
1700 | initWidgets(); |
1701 | |
1702 | #ifdef Q_OS_WIN32 |
1703 | dummyTransparentWindow.resize(1, 1); |
1704 | dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint); |
1705 | #endif |
1706 | |
1707 | q->setCurrentColor(initial); |
1708 | } |
1709 | |
1710 | void QColorDialogPrivate::initWidgets() |
1711 | { |
1712 | Q_Q(QColorDialog); |
1713 | QVBoxLayout *mainLay = new QVBoxLayout(q); |
1714 | // there's nothing in this dialog that benefits from sizing up |
1715 | mainLay->setSizeConstraint(QLayout::SetFixedSize); |
1716 | |
1717 | QHBoxLayout *topLay = new QHBoxLayout(); |
1718 | mainLay->addLayout(layout: topLay); |
1719 | |
1720 | leftLay = nullptr; |
1721 | |
1722 | #if defined(QT_SMALL_COLORDIALOG) |
1723 | smallDisplay = true; |
1724 | const int lumSpace = 20; |
1725 | #else |
1726 | // small displays (e.g. PDAs) cannot fit the full color dialog, |
1727 | // so just use the color picker. |
1728 | smallDisplay = (QGuiApplication::primaryScreen()->virtualGeometry().width() < 480 || QGuiApplication::primaryScreen()->virtualGeometry().height() < 350); |
1729 | const int lumSpace = topLay->spacing() / 2; |
1730 | #endif |
1731 | |
1732 | if (!smallDisplay) { |
1733 | leftLay = new QVBoxLayout; |
1734 | topLay->addLayout(layout: leftLay); |
1735 | |
1736 | standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors()); |
1737 | lblBasicColors = new QLabel(q); |
1738 | #ifndef QT_NO_SHORTCUT |
1739 | lblBasicColors->setBuddy(standard); |
1740 | #endif |
1741 | QObjectPrivate::connect(sender: standard, signal: &QColorWell::selected, |
1742 | receiverPrivate: this, slot: &QColorDialogPrivate::newStandard); |
1743 | leftLay->addWidget(lblBasicColors); |
1744 | leftLay->addWidget(standard); |
1745 | |
1746 | #if !defined(QT_SMALL_COLORDIALOG) |
1747 | if (supportsColorPicking()) { |
1748 | eyeDropperButton = new QPushButton(); |
1749 | leftLay->addWidget(eyeDropperButton); |
1750 | lblScreenColorInfo = new QLabel("\n"_L1); |
1751 | leftLay->addWidget(lblScreenColorInfo); |
1752 | QObjectPrivate::connect(sender: eyeDropperButton, signal: &QPushButton::clicked, |
1753 | receiverPrivate: this, slot: &QColorDialogPrivate::pickScreenColor); |
1754 | } else { |
1755 | eyeDropperButton = nullptr; |
1756 | lblScreenColorInfo = nullptr; |
1757 | } |
1758 | #endif |
1759 | |
1760 | leftLay->addStretch(); |
1761 | |
1762 | custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors()); |
1763 | custom->setAcceptDrops(true); |
1764 | |
1765 | QObjectPrivate::connect(sender: custom, signal: &QColorWell::selected, receiverPrivate: this, slot: &QColorDialogPrivate::newCustom); |
1766 | QObjectPrivate::connect(sender: custom, signal: &QColorWell::currentChanged, receiverPrivate: this, slot: &QColorDialogPrivate::nextCustom); |
1767 | |
1768 | QObject::connect(sender: custom, signal: &QWellArray::colorChanged, context: q, slot: [this] (int index, QRgb color) { |
1769 | QColorDialogOptions::setCustomColor(index, color); |
1770 | if (custom) |
1771 | custom->update(); |
1772 | }); |
1773 | |
1774 | lblCustomColors = new QLabel(q); |
1775 | #ifndef QT_NO_SHORTCUT |
1776 | lblCustomColors->setBuddy(custom); |
1777 | #endif |
1778 | leftLay->addWidget(lblCustomColors); |
1779 | leftLay->addWidget(custom); |
1780 | |
1781 | addCusBt = new QPushButton(q); |
1782 | QObjectPrivate::connect(sender: addCusBt, signal: &QPushButton::clicked, receiverPrivate: this, slot: &QColorDialogPrivate::addCustom); |
1783 | leftLay->addWidget(addCusBt); |
1784 | } else { |
1785 | // better color picker size for small displays |
1786 | #if defined(QT_SMALL_COLORDIALOG) |
1787 | QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size(); |
1788 | pWidth = pHeight = qMin(screenSize.width(), screenSize.height()); |
1789 | pHeight -= 20; |
1790 | if (screenSize.height() > screenSize.width()) |
1791 | pWidth -= 20; |
1792 | #else |
1793 | pWidth = 150; |
1794 | pHeight = 100; |
1795 | #endif |
1796 | custom = nullptr; |
1797 | standard = nullptr; |
1798 | } |
1799 | |
1800 | QVBoxLayout *rightLay = new QVBoxLayout; |
1801 | topLay->addLayout(layout: rightLay); |
1802 | |
1803 | QHBoxLayout *pickLay = new QHBoxLayout; |
1804 | rightLay->addLayout(layout: pickLay); |
1805 | |
1806 | QVBoxLayout *cLay = new QVBoxLayout; |
1807 | pickLay->addLayout(layout: cLay); |
1808 | cp = new QColorPicker(q); |
1809 | |
1810 | cp->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
1811 | |
1812 | #if defined(QT_SMALL_COLORDIALOG) |
1813 | cp->hide(); |
1814 | #else |
1815 | cLay->addSpacing(size: lumSpace); |
1816 | cLay->addWidget(cp); |
1817 | #endif |
1818 | cLay->addSpacing(size: lumSpace); |
1819 | |
1820 | lp = new QColorLuminancePicker(q); |
1821 | #if defined(QT_SMALL_COLORDIALOG) |
1822 | lp->hide(); |
1823 | #else |
1824 | lp->setFixedWidth(20); |
1825 | pickLay->addSpacing(size: 10); |
1826 | pickLay->addWidget(lp); |
1827 | pickLay->addStretch(); |
1828 | #endif |
1829 | |
1830 | QObject::connect(sender: cp, signal: &QColorPicker::newCol, context: lp, slot: qOverload<int, int>(&QColorLuminancePicker::setCol)); |
1831 | QObjectPrivate::connect(sender: lp, signal: &QColorLuminancePicker::newHsv, receiverPrivate: this, slot: &QColorDialogPrivate::newHsv); |
1832 | |
1833 | rightLay->addStretch(); |
1834 | |
1835 | cs = new QColorShower(q); |
1836 | pickLay->setContentsMargins(cs->gl->contentsMargins()); |
1837 | QObjectPrivate::connect(sender: cs, signal: &QColorShower::newCol, |
1838 | receiverPrivate: this, slot: &QColorDialogPrivate::newColorTypedIn); |
1839 | QObject::connect(sender: cs, signal: &QColorShower::currentColorChanged, |
1840 | context: q, slot: &QColorDialog::currentColorChanged); |
1841 | #if defined(QT_SMALL_COLORDIALOG) |
1842 | topLay->addWidget(cs); |
1843 | #else |
1844 | rightLay->addWidget(cs); |
1845 | if (leftLay) |
1846 | leftLay->addSpacing(size: cs->gl->contentsMargins().right()); |
1847 | #endif |
1848 | |
1849 | buttons = new QDialogButtonBox(q); |
1850 | mainLay->addWidget(buttons); |
1851 | |
1852 | ok = buttons->addButton(button: QDialogButtonBox::Ok); |
1853 | QObject::connect(sender: ok, signal: &QPushButton::clicked, context: q, slot: &QColorDialog::accept); |
1854 | ok->setDefault(true); |
1855 | cancel = buttons->addButton(button: QDialogButtonBox::Cancel); |
1856 | QObject::connect(sender: cancel, signal: &QPushButton::clicked, context: q, slot: &QColorDialog::reject); |
1857 | |
1858 | #ifdef Q_OS_WIN32 |
1859 | updateTimer = new QTimer(q); |
1860 | QObjectPrivate::connect(updateTimer, &QTimer::timeout, |
1861 | this, qOverload<>(&QColorDialogPrivate::updateColorPicking)); |
1862 | #endif |
1863 | retranslateStrings(); |
1864 | } |
1865 | |
1866 | void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h) |
1867 | { |
1868 | QColorDialog *d = q_func(); |
1869 | auto *colorDialogHelper = static_cast<QPlatformColorDialogHelper*>(h); |
1870 | QObject::connect(sender: colorDialogHelper, signal: &QPlatformColorDialogHelper::currentColorChanged, |
1871 | context: d, slot: &QColorDialog::currentColorChanged); |
1872 | QObject::connect(sender: colorDialogHelper, signal: &QPlatformColorDialogHelper::colorSelected, |
1873 | context: d, slot: &QColorDialog::colorSelected); |
1874 | colorDialogHelper->setOptions(options); |
1875 | } |
1876 | |
1877 | void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) |
1878 | { |
1879 | options->setWindowTitle(q_func()->windowTitle()); |
1880 | } |
1881 | |
1882 | void QColorDialogPrivate::addCustom() |
1883 | { |
1884 | QColorDialogOptions::setCustomColor(index: nextCust, color: cs->currentColor()); |
1885 | if (custom) |
1886 | custom->update(); |
1887 | nextCust = (nextCust+1) % QColorDialogOptions::customColorCount(); |
1888 | } |
1889 | |
1890 | void QColorDialogPrivate::retranslateStrings() |
1891 | { |
1892 | if (nativeDialogInUse) |
1893 | return; |
1894 | |
1895 | if (!smallDisplay) { |
1896 | lblBasicColors->setText(QColorDialog::tr(s: "&Basic colors")); |
1897 | lblCustomColors->setText(QColorDialog::tr(s: "&Custom colors")); |
1898 | addCusBt->setText(QColorDialog::tr(s: "&Add to Custom Colors")); |
1899 | #if !defined(QT_SMALL_COLORDIALOG) |
1900 | if (eyeDropperButton) |
1901 | eyeDropperButton->setText(QColorDialog::tr(s: "&Pick Screen Color")); |
1902 | #endif |
1903 | } |
1904 | |
1905 | cs->retranslateStrings(); |
1906 | } |
1907 | |
1908 | bool QColorDialogPrivate::supportsColorPicking() const |
1909 | { |
1910 | const auto integration = QGuiApplicationPrivate::platformIntegration(); |
1911 | return integration->hasCapability(cap: QPlatformIntegration::ScreenWindowGrabbing) |
1912 | || integration->services()->hasCapability(capability: QPlatformServices::Capability::ColorPicking); |
1913 | } |
1914 | |
1915 | bool QColorDialogPrivate::canBeNativeDialog() const |
1916 | { |
1917 | // Don't use Q_Q here! This function is called from ~QDialog, |
1918 | // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). |
1919 | const QDialog * const q = static_cast<const QDialog*>(q_ptr); |
1920 | if (nativeDialogInUse) |
1921 | return true; |
1922 | if (QCoreApplication::testAttribute(attribute: Qt::AA_DontUseNativeDialogs) |
1923 | || q->testAttribute(attribute: Qt::WA_DontShowOnScreen) |
1924 | || (options->options() & QColorDialog::DontUseNativeDialog)) { |
1925 | return false; |
1926 | } |
1927 | |
1928 | return strcmp(s1: QColorDialog::staticMetaObject.className(), s2: q->metaObject()->className()) == 0; |
1929 | } |
1930 | |
1931 | static const Qt::WindowFlags qcd_DefaultWindowFlags = |
1932 | Qt::Dialog | Qt::WindowTitleHint |
1933 | | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; |
1934 | |
1935 | /*! |
1936 | \class QColorDialog |
1937 | \brief The QColorDialog class provides a dialog widget for specifying colors. |
1938 | |
1939 | \ingroup standard-dialogs |
1940 | \inmodule QtWidgets |
1941 | |
1942 | The color dialog's function is to allow users to choose colors. |
1943 | For example, you might use this in a drawing program to allow the |
1944 | user to set the brush color. |
1945 | |
1946 | The static functions provide modal color dialogs. |
1947 | \omit |
1948 | If you require a modeless dialog, use the QColorDialog constructor. |
1949 | \endomit |
1950 | |
1951 | The static getColor() function shows the dialog, and allows the user to |
1952 | specify a color. This function can also be used to let users choose a |
1953 | color with a level of transparency: pass the ShowAlphaChannel option as |
1954 | an additional argument. |
1955 | |
1956 | The user can store customCount() different custom colors. The |
1957 | custom colors are shared by all color dialogs, and remembered |
1958 | during the execution of the program. Use setCustomColor() to set |
1959 | the custom colors, and use customColor() to get them. |
1960 | |
1961 | When pressing the "Pick Screen Color" button, the cursor changes to a haircross |
1962 | and the colors on the screen are scanned. The user can pick up one by clicking |
1963 | the mouse or the Enter button. Pressing Escape restores the last color selected |
1964 | before entering this mode. |
1965 | |
1966 | The \l{dialogs/standarddialogs}{Standard Dialogs} example shows |
1967 | how to use QColorDialog as well as other built-in Qt dialogs. |
1968 | |
1969 | \image fusion-colordialog.png A color dialog in the Fusion widget style. |
1970 | |
1971 | \sa QColor, QFileDialog, QFontDialog, {Standard Dialogs Example} |
1972 | */ |
1973 | |
1974 | /*! |
1975 | Constructs a color dialog with the given \a parent. |
1976 | */ |
1977 | QColorDialog::QColorDialog(QWidget *parent) |
1978 | : QColorDialog(QColor(Qt::white), parent) |
1979 | { |
1980 | } |
1981 | |
1982 | /*! |
1983 | Constructs a color dialog with the given \a parent and specified |
1984 | \a initial color. |
1985 | */ |
1986 | QColorDialog::QColorDialog(const QColor &initial, QWidget *parent) |
1987 | : QDialog(*new QColorDialogPrivate, parent, qcd_DefaultWindowFlags) |
1988 | { |
1989 | Q_D(QColorDialog); |
1990 | d->init(initial); |
1991 | } |
1992 | |
1993 | void QColorDialogPrivate::setCurrentColor(const QColor &color, SetColorMode setColorMode) |
1994 | { |
1995 | if (nativeDialogInUse) { |
1996 | platformColorDialogHelper()->setCurrentColor(color); |
1997 | return; |
1998 | } |
1999 | |
2000 | if (setColorMode & ShowColor) { |
2001 | setCurrentRgbColor(color.rgb()); |
2002 | setCurrentAlpha(color.alpha()); |
2003 | } |
2004 | if (setColorMode & SelectColor) |
2005 | selectColor(col: color); |
2006 | } |
2007 | |
2008 | /*! |
2009 | \property QColorDialog::currentColor |
2010 | \brief the currently selected color in the dialog |
2011 | */ |
2012 | |
2013 | void QColorDialog::setCurrentColor(const QColor &color) |
2014 | { |
2015 | Q_D(QColorDialog); |
2016 | d->setCurrentColor(color); |
2017 | } |
2018 | |
2019 | QColor QColorDialog::currentColor() const |
2020 | { |
2021 | Q_D(const QColorDialog); |
2022 | return d->currentQColor(); |
2023 | } |
2024 | |
2025 | /*! |
2026 | Returns the color that the user selected by clicking the \uicontrol{OK} |
2027 | or equivalent button. |
2028 | |
2029 | \note This color is not always the same as the color held by the |
2030 | \l currentColor property since the user can choose different colors |
2031 | before finally selecting the one to use. |
2032 | */ |
2033 | QColor QColorDialog::selectedColor() const |
2034 | { |
2035 | Q_D(const QColorDialog); |
2036 | return d->selectedQColor; |
2037 | } |
2038 | |
2039 | /*! |
2040 | Sets the given \a option to be enabled if \a on is true; |
2041 | otherwise, clears the given \a option. |
2042 | |
2043 | \sa options, testOption() |
2044 | */ |
2045 | void QColorDialog::setOption(ColorDialogOption option, bool on) |
2046 | { |
2047 | const QColorDialog::ColorDialogOptions previousOptions = options(); |
2048 | if (!(previousOptions & option) != !on) |
2049 | setOptions(previousOptions ^ option); |
2050 | } |
2051 | |
2052 | /*! |
2053 | Returns \c true if the given \a option is enabled; otherwise, returns |
2054 | false. |
2055 | |
2056 | \sa options, setOption() |
2057 | */ |
2058 | bool QColorDialog::testOption(ColorDialogOption option) const |
2059 | { |
2060 | Q_D(const QColorDialog); |
2061 | return d->options->testOption(option: static_cast<QColorDialogOptions::ColorDialogOption>(option)); |
2062 | } |
2063 | |
2064 | /*! |
2065 | \property QColorDialog::options |
2066 | \brief the various options that affect the look and feel of the dialog |
2067 | |
2068 | By default, all options are disabled. |
2069 | |
2070 | Options should be set before showing the dialog. Setting them while the |
2071 | dialog is visible is not guaranteed to have an immediate effect on the |
2072 | dialog (depending on the option and on the platform). |
2073 | |
2074 | \sa setOption(), testOption() |
2075 | */ |
2076 | void QColorDialog::setOptions(ColorDialogOptions options) |
2077 | { |
2078 | Q_D(QColorDialog); |
2079 | |
2080 | if (QColorDialog::options() == options) |
2081 | return; |
2082 | |
2083 | d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options))); |
2084 | if ((options & DontUseNativeDialog) && d->nativeDialogInUse) { |
2085 | d->nativeDialogInUse = false; |
2086 | d->initWidgets(); |
2087 | } |
2088 | if (!d->nativeDialogInUse) { |
2089 | d->buttons->setVisible(!(options & NoButtons)); |
2090 | d->showAlpha(b: options & ShowAlphaChannel); |
2091 | if (d->eyeDropperButton) |
2092 | d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton)); |
2093 | } |
2094 | } |
2095 | |
2096 | QColorDialog::ColorDialogOptions QColorDialog::options() const |
2097 | { |
2098 | Q_D(const QColorDialog); |
2099 | return QColorDialog::ColorDialogOptions(int(d->options->options())); |
2100 | } |
2101 | |
2102 | /*! |
2103 | \enum QColorDialog::ColorDialogOption |
2104 | |
2105 | This enum specifies various options that affect the look and feel |
2106 | of a color dialog. |
2107 | |
2108 | \value ShowAlphaChannel Allow the user to select the alpha component of a color. |
2109 | \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".) |
2110 | \value NoEyeDropperButton Hide the \uicontrol{Eye Dropper} button. This value was added in Qt 6.6. |
2111 | \value DontUseNativeDialog Use Qt's standard color dialog instead of the operating system |
2112 | native color dialog. |
2113 | |
2114 | \sa options, setOption(), testOption(), windowModality() |
2115 | */ |
2116 | |
2117 | /*! |
2118 | \fn void QColorDialog::currentColorChanged(const QColor &color) |
2119 | |
2120 | This signal is emitted whenever the current color changes in the dialog. |
2121 | The current color is specified by \a color. |
2122 | |
2123 | \sa color, colorSelected() |
2124 | */ |
2125 | |
2126 | /*! |
2127 | \fn void QColorDialog::colorSelected(const QColor &color); |
2128 | |
2129 | This signal is emitted just after the user has clicked \uicontrol{OK} to |
2130 | select a color to use. The chosen color is specified by \a color. |
2131 | |
2132 | \sa color, currentColorChanged() |
2133 | */ |
2134 | |
2135 | /*! |
2136 | Changes the visibility of the dialog. If \a visible is true, the dialog |
2137 | is shown; otherwise, it is hidden. |
2138 | */ |
2139 | void QColorDialog::setVisible(bool visible) |
2140 | { |
2141 | // will call QColorDialogPrivate::setVisible override |
2142 | QDialog::setVisible(visible); |
2143 | } |
2144 | |
2145 | /*! |
2146 | \internal |
2147 | |
2148 | The implementation of QColorDialog::setVisible() has to live here so that the call |
2149 | to hide() in ~QDialog calls this function; it wouldn't call the override of |
2150 | QDialog::setVisible(). |
2151 | */ |
2152 | void QColorDialogPrivate::setVisible(bool visible) |
2153 | { |
2154 | Q_Q(QColorDialog); |
2155 | |
2156 | if (visible) |
2157 | selectedQColor = QColor(); |
2158 | |
2159 | if (nativeDialogInUse) { |
2160 | if (setNativeDialogVisible(visible)) { |
2161 | // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below |
2162 | // updates the state correctly, but skips showing the non-native version: |
2163 | q->setAttribute(Qt::WA_DontShowOnScreen); |
2164 | } else { |
2165 | initWidgets(); |
2166 | } |
2167 | } else { |
2168 | q->setAttribute(Qt::WA_DontShowOnScreen, on: false); |
2169 | } |
2170 | |
2171 | QDialogPrivate::setVisible(visible); |
2172 | } |
2173 | |
2174 | /*! |
2175 | Opens the dialog and connects its colorSelected() signal to the slot specified |
2176 | by \a receiver and \a member. |
2177 | |
2178 | The signal will be disconnected from the slot when the dialog is closed. |
2179 | */ |
2180 | void QColorDialog::open(QObject *receiver, const char *member) |
2181 | { |
2182 | Q_D(QColorDialog); |
2183 | connect(sender: this, SIGNAL(colorSelected(QColor)), receiver, member); |
2184 | d->receiverToDisconnectOnClose = receiver; |
2185 | d->memberToDisconnectOnClose = member; |
2186 | QDialog::open(); |
2187 | } |
2188 | |
2189 | /*! |
2190 | Pops up a modal color dialog with the given window \a title (or "Select Color" if none is |
2191 | specified), lets the user choose a color, and returns that color. The color is initially set |
2192 | to \a initial. The dialog is a child of \a parent. It returns an invalid (see |
2193 | QColor::isValid()) color if the user cancels the dialog. |
2194 | |
2195 | The \a options argument allows you to customize the dialog. |
2196 | */ |
2197 | QColor QColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title, |
2198 | ColorDialogOptions options) |
2199 | { |
2200 | QAutoPointer<QColorDialog> dlg(new QColorDialog(parent)); |
2201 | if (!title.isEmpty()) |
2202 | dlg->setWindowTitle(title); |
2203 | dlg->setOptions(options); |
2204 | dlg->setCurrentColor(initial); |
2205 | |
2206 | // If the dlg was deleted with a parent window, |
2207 | // dlg == nullptr after leaving the exec(). |
2208 | dlg->exec(); |
2209 | if (bool(dlg)) |
2210 | return dlg->selectedColor(); |
2211 | else |
2212 | return QColor(); |
2213 | } |
2214 | |
2215 | /*! |
2216 | Destroys the color dialog. |
2217 | */ |
2218 | |
2219 | QColorDialog::~QColorDialog() |
2220 | { |
2221 | } |
2222 | |
2223 | /*! |
2224 | \reimp |
2225 | */ |
2226 | void QColorDialog::changeEvent(QEvent *e) |
2227 | { |
2228 | Q_D(QColorDialog); |
2229 | if (e->type() == QEvent::LanguageChange) |
2230 | d->retranslateStrings(); |
2231 | QDialog::changeEvent(e); |
2232 | } |
2233 | |
2234 | void QColorDialogPrivate::updateColorPicking() |
2235 | { |
2236 | #ifndef QT_NO_CURSOR |
2237 | Q_Q(QColorDialog); |
2238 | static QPoint lastGlobalPos; |
2239 | QPoint newGlobalPos = QCursor::pos(); |
2240 | if (lastGlobalPos == newGlobalPos) |
2241 | return; |
2242 | lastGlobalPos = newGlobalPos; |
2243 | |
2244 | if (!q->rect().contains(p: q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called |
2245 | updateColorPicking(pos: newGlobalPos); |
2246 | #ifdef Q_OS_WIN32 |
2247 | dummyTransparentWindow.setPosition(newGlobalPos); |
2248 | #endif |
2249 | } |
2250 | #endif // ! QT_NO_CURSOR |
2251 | } |
2252 | |
2253 | void QColorDialogPrivate::updateColorPicking(const QPoint &globalPos) |
2254 | { |
2255 | const QColor color = grabScreenColor(p: globalPos); |
2256 | // QTBUG-39792, do not change standard, custom color selectors while moving as |
2257 | // otherwise it is not possible to pre-select a custom cell for assignment. |
2258 | setCurrentColor(color, setColorMode: ShowColor); |
2259 | updateColorLabelText(globalPos); |
2260 | } |
2261 | |
2262 | bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e) |
2263 | { |
2264 | // If the cross is visible the grabbed color will be black most of the times |
2265 | cp->setCrossVisible(!cp->geometry().contains(p: e->position().toPoint())); |
2266 | |
2267 | updateColorPicking(globalPos: e->globalPosition().toPoint()); |
2268 | return true; |
2269 | } |
2270 | |
2271 | bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e) |
2272 | { |
2273 | setCurrentColor(color: grabScreenColor(p: e->globalPosition().toPoint()), setColorMode: SetColorAll); |
2274 | releaseColorPicking(); |
2275 | return true; |
2276 | } |
2277 | |
2278 | bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e) |
2279 | { |
2280 | Q_Q(QColorDialog); |
2281 | #if QT_CONFIG(shortcut) |
2282 | if (e->matches(key: QKeySequence::Cancel)) { |
2283 | releaseColorPicking(); |
2284 | q->setCurrentColor(beforeScreenColorPicking); |
2285 | } else |
2286 | #endif |
2287 | if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { |
2288 | q->setCurrentColor(grabScreenColor(p: QCursor::pos())); |
2289 | releaseColorPicking(); |
2290 | } |
2291 | e->accept(); |
2292 | return true; |
2293 | } |
2294 | |
2295 | /*! |
2296 | Closes the dialog and sets its result code to \a result. If this dialog |
2297 | is shown with exec(), done() causes the local event loop to finish, |
2298 | and exec() to return \a result. |
2299 | |
2300 | \sa QDialog::done() |
2301 | */ |
2302 | void QColorDialog::done(int result) |
2303 | { |
2304 | Q_D(QColorDialog); |
2305 | if (result == Accepted) { |
2306 | d->selectedQColor = d->currentQColor(); |
2307 | emit colorSelected(color: d->selectedQColor); |
2308 | } else { |
2309 | d->selectedQColor = QColor(); |
2310 | } |
2311 | QDialog::done(result); |
2312 | if (d->receiverToDisconnectOnClose) { |
2313 | disconnect(sender: this, SIGNAL(colorSelected(QColor)), |
2314 | receiver: d->receiverToDisconnectOnClose, member: d->memberToDisconnectOnClose); |
2315 | d->receiverToDisconnectOnClose = nullptr; |
2316 | } |
2317 | d->memberToDisconnectOnClose.clear(); |
2318 | } |
2319 | |
2320 | QT_END_NAMESPACE |
2321 | |
2322 | #include "qcolordialog.moc" |
2323 | #include "moc_qcolordialog.cpp" |
2324 |
Definitions
- QColorDialogPrivate
- SetColorMode
- QColorDialogPrivate
- platformColorDialogHelper
- QWellArray
- ~QWellArray
- selectedColumn
- selectedRow
- cellWidth
- cellHeight
- rowAt
- columnAt
- rowY
- columnX
- numRows
- numCols
- cellRect
- gridSize
- cellGeometry
- updateCell
- QWellArray
- paintEvent
- QWellArray
- sizeHint
- paintCell
- paintCellContents
- mousePressEvent
- mouseReleaseEvent
- setCurrent
- setSelected
- focusInEvent
- focusOutEvent
- keyPressEvent
- QColorPickingEventFilter
- QColorPickingEventFilter
- eventFilter
- customCount
- customColor
- setCustomColor
- standardColor
- setStandardColor
- rgb2hsv
- QColorWell
- QColorWell
- paintCellContents
- mousePressEvent
- mouseMoveEvent
- dragEnterEvent
- dragLeaveEvent
- dragMoveEvent
- dropEvent
- mouseReleaseEvent
- QColorPicker
- pWidth
- pHeight
- QColorLuminancePicker
- y2val
- val2y
- QColorLuminancePicker
- ~QColorLuminancePicker
- mouseMoveEvent
- mousePressEvent
- setVal
- setCol
- paintEvent
- setCol
- colPt
- huePt
- satPt
- setCol
- QColorPicker
- ~QColorPicker
- setCrossVisible
- sizeHint
- setCol
- mouseMoveEvent
- mousePressEvent
- paintEvent
- resizeEvent
- QColSpinBox
- QColSpinBox
- setValue
- QColorShower
- currentAlpha
- setCurrentAlpha
- currentColor
- currentQColor
- QColorShowLabel
- QColorShowLabel
- setColor
- paintEvent
- showAlpha
- isAlphaVisible
- mousePressEvent
- mouseMoveEvent
- dragEnterEvent
- dragLeaveEvent
- dropEvent
- mouseReleaseEvent
- QColorShower
- currentColor
- currentAlpha
- setCurrentAlpha
- showAlpha
- isAlphaVisible
- currentQColor
- showCurrentColor
- rgbEd
- hsvEd
- htmlEd
- setRgb
- setHsv
- retranslateStrings
- updateQColor
- newHsv
- setCurrentRgbColor
- setCurrentQColor
- selectColor
- grabScreenColor
- newColorTypedIn
- nextCustom
- newCustom
- newStandard
- pickScreenColor
- updateColorLabelText
- releaseColorPicking
- init
- initWidgets
- initHelper
- helperPrepareShow
- addCustom
- retranslateStrings
- supportsColorPicking
- canBeNativeDialog
- qcd_DefaultWindowFlags
- QColorDialog
- QColorDialog
- setCurrentColor
- setCurrentColor
- currentColor
- selectedColor
- setOption
- testOption
- setOptions
- options
- setVisible
- setVisible
- open
- getColor
- ~QColorDialog
- changeEvent
- updateColorPicking
- updateColorPicking
- handleColorPickingMouseMove
- handleColorPickingMouseButtonRelease
- handleColorPickingKeyPress
Learn to use CMake with our Intro Training
Find out more