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