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
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"
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
50QT_BEGIN_NAMESPACE
51
52using namespace Qt::StringLiterals;
53
54namespace QtPrivate {
56class QColorPicker;
57class QColorShower;
58class QWellArray;
59class QColorWell;
61} // namespace QtPrivate
62
63using QColorLuminancePicker = QtPrivate::QColorLuminancePicker;
64using QColorPicker = QtPrivate::QColorPicker;
65using QColorShower = QtPrivate::QColorShower;
66using QWellArray = QtPrivate::QWellArray;
67using QColorWell = QtPrivate::QColorWell;
68using QColorPickingEventFilter = QtPrivate::QColorPickingEventFilter;
69
71{
72 Q_DECLARE_PUBLIC(QColorDialog)
73
74public:
80
82#ifdef Q_OS_WIN32
83 , updateTimer(0)
84#endif
85 {}
86
88 { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); }
89
90 void init(const QColor &initial);
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;
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);
118 void updateColorPicking(const QPoint &pos);
120 bool handleColorPickingMouseMove(QMouseEvent *e);
122 bool handleColorPickingKeyPress(QKeyEvent *e);
123
125 void setVisible(bool visible) override;
126
127 QWellArray *custom;
128 QWellArray *standard;
129
132 QColorPicker *cp;
133 QColorLuminancePicker *lp;
134 QColorShower *cs;
138 QPushButton *ok;
139 QPushButton *cancel;
140 QPushButton *addCusBt;
141 QPushButton *eyeDropperButton = nullptr;
146 QColorPickingEventFilter *colorPickingEventFilter;
149
152#ifdef Q_OS_WIN32
155#endif
156
157private:
158 virtual void initHelper(QPlatformDialogHelper *h) override;
159 virtual void helperPrepareShow(QPlatformDialogHelper *h) override;
160};
161
162//////////// QWellArray BEGIN
163
164namespace QtPrivate {
165
166class QWellArray : public QWidget
167{
168 Q_OBJECT
169 Q_PROPERTY(int selectedColumn READ selectedColumn)
171
172public:
173 QWellArray(int rows, int cols, QWidget* parent=nullptr);
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(columnX(column), rowY(row), cellw, cellh);
220 return r;
221 }
222
223 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
224
225signals:
226 void selected(int row, int col);
227 void currentChanged(int row, int col);
228 void colorChanged(int index, QRgb color);
229
230protected:
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
241private:
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
254void 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(cx);
262 int collast = columnAt(cx + cw);
263 int rowfirst = rowAt(cy);
264 int rowlast = rowAt(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(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(c);
293 // Translate painter and draw the cell
294 rect.translate(colp, rowp);
295 paintCell(p, r, c, rect);
296 rect.translate(-colp, -rowp);
297 }
298 }
299}
300
301QWellArray::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
315{
316 ensurePolished();
317 return gridSize().boundedTo(QSize(640, 480));
318}
319
320
321void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
322{
323 int b = 3; //margin
324
325 const QPalette & g = palette();
327 opt.initFrom(this);
328 int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, this);
329 opt.lineWidth = dfw;
330 opt.midLineWidth = 1;
331 opt.rect = rect.adjusted(b, b, -b, -b);
332 opt.palette = g;
333 opt.state = QStyle::State_Enabled | QStyle::State_Sunken;
334 style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this);
335 b += dfw;
336
337 if ((row == curRow) && (col == curCol)) {
338 if (hasFocus()) {
340 opt.palette = g;
341 opt.rect = rect;
342 opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange;
343 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this);
344 }
345 }
346 paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));
347}
348
349/*
350 Reimplement this function to change the contents of the well array.
351 */
352void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
353{
354 Q_UNUSED(row);
355 Q_UNUSED(col);
356 p->fillRect(r, Qt::white);
357 p->setPen(Qt::black);
358 p->drawLine(r.topLeft(), r.bottomRight());
359 p->drawLine(r.topRight(), r.bottomLeft());
360}
361
362void 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(rowAt(pos.y()), columnAt(pos.x()));
367}
368
369void QWellArray::mouseReleaseEvent(QMouseEvent * /* event */)
370{
371 // The current cell marker is set to the cell the mouse is clicked in
372 setSelected(curRow, 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
381void 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(oldRow, oldCol);
396 updateCell(curRow, curCol);
397
398 emit currentChanged(curRow, 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*/
407void 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(oldRow, oldCol);
419 updateCell(selRow, selCol);
420 if (row >= 0)
421 emit selected(row, col);
422
423#if QT_CONFIG(menu)
424 if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
425 parentWidget()->close();
426#endif
427}
428
429void QWellArray::focusInEvent(QFocusEvent*)
430{
431 updateCell(curRow, curCol);
432 emit currentChanged(curRow, curCol);
433}
434
435
436void QWellArray::focusOutEvent(QFocusEvent*)
437{
438 updateCell(curRow, curCol);
439}
440
441void 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(curRow, curCol - 1); // set cr't to next left column
447 break;
448 case Qt::Key_Right: // Correspondingly...
449 if (curCol < numCols()-1)
450 setCurrent(curRow, curCol + 1);
451 break;
452 case Qt::Key_Up:
453 if (curRow > 0)
454 setCurrent(curRow - 1, curCol);
455 break;
456 case Qt::Key_Down:
457 if (curRow < numRows()-1)
458 setCurrent(curRow + 1, 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(curRow, 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.
485public:
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(static_cast<QMouseEvent *>(event));
493 case QEvent::MouseButtonRelease:
494 return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
495 case QEvent::KeyPress:
496 return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
497 default:
498 break;
499 }
500 return false;
501 }
502
503private:
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*/
513int 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*/
521QColor 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*/
533void QColorDialog::setCustomColor(int index, QColor color)
534{
535 QColorDialogOptions::setCustomColor(index, 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*/
543QColor 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*/
555void QColorDialog::setStandardColor(int index, QColor color)
556{
557 QColorDialogOptions::setStandardColor(index, color.rgba());
558}
559
560static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
561{
562 QColor c;
563 c.setRgb(rgb);
564 c.getHsv(&h, &s, &v);
565}
566
567namespace QtPrivate {
568
569class QColorWell : public QWellArray
570{
571public:
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
576protected:
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)
586#endif
587
588private:
589 const QRgb *values;
590 bool mousePressed;
591 QPoint pressPos;
592 QPoint oldCurrent;
593
594};
595
596void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)
597{
598 int i = row + col*numRows();
599 p->fillRect(r, QColor(values[i]));
600}
601
602void QColorWell::mousePressEvent(QMouseEvent *e)
603{
604 oldCurrent = QPoint(selectedRow(), selectedColumn());
606 mousePressed = true;
607 pressPos = e->position().toPoint();
608}
609
610void QColorWell::mouseMoveEvent(QMouseEvent *e)
611{
612 QWellArray::mouseMoveEvent(e);
613#if QT_CONFIG(draganddrop)
614 if (!mousePressed)
615 return;
616 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
617 setCurrent(oldCurrent.x(), oldCurrent.y());
618 int i = rowAt(pressPos.y()) + columnAt(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(col);
624 QPainter p(&pix);
625 p.drawRect(0, 0, pix.width() - 1, 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(Qt::CopyAction);
632 }
633#endif
634}
635
636#if QT_CONFIG(draganddrop)
638{
640 e->accept();
641 else
642 e->ignore();
643}
644
646{
647 if (hasFocus())
649}
650
652{
655 e->accept();
656 } else {
657 e->ignore();
658 }
659}
660
662{
664 if (col.isValid()) {
665 int i = rowAt(e->position().toPoint().y()) + columnAt(e->position().toPoint().x()) * numRows();
667 e->accept();
668 } else {
669 e->ignore();
670 }
671}
672
673#endif // QT_CONFIG(draganddrop)
674
675void QColorWell::mouseReleaseEvent(QMouseEvent *e)
676{
677 if (!mousePressed)
678 return;
680 mousePressed = false;
681}
682
683class QColorPicker : public QFrame
684{
686public:
689
690 void setCrossVisible(bool visible);
691public slots:
692 void setCol(int h, int s);
693
694signals:
695 void newCol(int h, int s);
696
697protected:
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
704private:
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
719static int pWidth = 220;
720static int pHeight = 200;
721
722namespace QtPrivate {
723
725{
727public:
730
731public slots:
732 void setCol(int h, int s, int v);
733 void setCol(int h, int s);
734
735signals:
736 void newHsv(int h, int s, int v);
737
738protected:
739 void paintEvent(QPaintEvent*) override;
740 void mouseMoveEvent(QMouseEvent *) override;
741 void mousePressEvent(QMouseEvent *) override;
742
743private:
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
757int QColorLuminancePicker::y2val(int y)
758{
759 int d = height() - 2*coff - 1;
760 return 255 - (y - coff)*255/d;
761}
762
763int QColorLuminancePicker::val2y(int v)
764{
765 int d = height() - 2*coff - 1;
766 return coff + (255-v)*d/255;
767}
768
769QColorLuminancePicker::QColorLuminancePicker(QWidget* parent)
770 :QWidget(parent)
771{
772 hue = 100; val = 100; sat = 100;
773 pix = nullptr;
774 // setAttribute(WA_NoErase, true);
775}
776
778{
779 delete pix;
780}
781
783{
784 if (m->buttons() == Qt::NoButton) {
785 m->ignore();
786 return;
787 }
788 setVal(y2val(m->position().toPoint().y()));
789}
791{
792 setVal(y2val(m->position().toPoint().y()));
793}
794
795void QColorLuminancePicker::setVal(int v)
796{
797 if (val == v)
798 return;
799 val = qMax(0, qMin(v,255));
800 delete pix; pix=nullptr;
801 repaint();
802 emit newHsv(hue, sat, val);
803}
804
805//receives from a hue,sat chooser and relays.
806void QColorLuminancePicker::setCol(int h, int s)
807{
808 setCol(h, s, val);
809 emit newHsv(h, s, val);
810}
811
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(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb());
827 pixel = end;
828 }
829 pix = new QPixmap(QPixmap::fromImage(img));
830 }
831 QPainter p(this);
832 p.drawPixmap(1, coff, *pix);
833 const QPalette &g = palette();
834 qDrawShadePanel(&p, r, g, true);
835 p.setPen(g.windowText().color());
836 p.setBrush(g.windowText());
837 p.eraseRect(w, 0, 5, height());
838 const int y = val2y(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.data(), static_cast<int>(points.size()));
841}
842
843void 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
852QPoint QColorPicker::colPt()
853{
854 QRect r = contentsRect();
855 return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
856}
857
858int QColorPicker::huePt(const QPoint &pt)
859{
860 QRect r = contentsRect();
861 return 360 - pt.x() * 360 / (r.width() - 1);
862}
863
864int QColorPicker::satPt(const QPoint &pt)
865{
866 QRect r = contentsRect();
867 return 255 - pt.y() * 255 / (r.height() - 1);
868}
869
870void QColorPicker::setCol(const QPoint &pt)
871{
872 setCol(huePt(pt), satPt(pt));
873}
874
875QColorPicker::QColorPicker(QWidget* parent)
876 : QFrame(parent)
877 , crossVisible(true)
878{
879 hue = 0; sat = 0;
880 setCol(150, 255);
881
882 setAttribute(Qt::WA_NoSystemBackground);
883 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
884}
885
889
890void QColorPicker::setCrossVisible(bool visible)
891{
892 if (crossVisible != visible) {
893 crossVisible = visible;
894 update();
895 }
896}
897
899{
900 return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
901}
902
903void QColorPicker::setCol(int h, int s)
904{
905 int nhue = qMin(qMax(0,h), 359);
906 int nsat = qMin(qMax(0,s), 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(QRect(colPt(), QSize(20,20)));
913 r.translate(contentsRect().x()-9, contentsRect().y()-9);
914 // update(r);
915 repaint(r);
916}
917
918void 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(hue, sat);
927}
928
929void QColorPicker::mousePressEvent(QMouseEvent *m)
930{
931 QPoint p = m->position().toPoint() - contentsRect().topLeft();
932 setCol(p);
933 emit newCol(hue, sat);
934}
935
936void QColorPicker::paintEvent(QPaintEvent* )
937{
938 QPainter p(this);
939 drawFrame(&p);
940 QRect r = contentsRect();
941
942 p.drawPixmap(r.topLeft(), pix);
943
944 if (crossVisible) {
945 QPoint pt = colPt() + r.topLeft();
946 p.setPen(Qt::black);
947 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
948 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
949 }
950}
951
952void QColorPicker::resizeEvent(QResizeEvent *ev)
953{
954 QFrame::resizeEvent(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(huePt(p), satPt(p), 200);
968 *pixel = c.rgb();
969 ++pixel;
970 ++x;
971 }
972 }
973 pix = QPixmap::fromImage(img);
974}
975
976
977class QColSpinBox : public QSpinBox
978{
979public:
980 QColSpinBox(QWidget *parent)
981 : QSpinBox(parent) { setRange(0, 255); }
982 void setValue(int i) {
983 const QSignalBlocker blocker(this);
984 QSpinBox::setValue(i);
985 }
986};
987
988class QColorShowLabel;
989
990class QColorShower : public QWidget
991{
993public:
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; }
1009
1010public slots:
1012
1013signals:
1015 void currentColorChanged(const QColor &color);
1016
1017private slots:
1018 void rgbEd();
1019 void hsvEd();
1020 void htmlEd();
1021
1022private:
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
1050};
1051
1053{
1054 Q_OBJECT
1055
1056public:
1062 void setColor(QColor c) { col = c; }
1063
1064signals:
1066
1067protected:
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)
1076#endif
1077
1078private:
1079 QColor col;
1080 bool mousePressed;
1081 QPoint pressPos;
1082};
1083
1084void QColorShowLabel::paintEvent(QPaintEvent *e)
1085{
1086 QPainter p(this);
1087 drawFrame(&p);
1088 p.fillRect(contentsRect()&e->rect(), col);
1089}
1090
1092{
1093 alphaLab->setVisible(b);
1094 alphaEd->setVisible(b);
1095}
1096
1097inline bool QColorShower::isAlphaVisible() const
1098{
1099 return alphaLab->isVisible();
1100}
1101
1103{
1104 mousePressed = true;
1105 pressPos = e->position().toPoint();
1106}
1107
1108void 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(col);
1120 QPainter p(&pix);
1121 p.drawRect(0, 0, pix.width() - 1, 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(Qt::CopyAction);
1128 }
1129#endif
1130}
1131
1132#if QT_CONFIG(draganddrop)
1134{
1136 e->accept();
1137 else
1138 e->ignore();
1139}
1140
1142{
1143}
1144
1146{
1148 if (color.isValid()) {
1149 col = color;
1150 repaint();
1152 e->accept();
1153 } else {
1154 e->ignore();
1155 }
1156}
1157#endif // QT_CONFIG(draganddrop)
1158
1160{
1161 if (!mousePressed)
1162 return;
1163 mousePressed = false;
1164}
1165
1166QColorShower::QColorShower(QColorDialog *parent)
1167 : QWidget(parent)
1168{
1169 colorDialog = parent;
1170
1171 curCol = qRgb(255, 255, 255);
1172 curQColor = Qt::white;
1173
1174 gl = new QGridLayout(this);
1175 const int s = gl->spacing();
1176 gl->setContentsMargins(s, s, s, 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, 0, 0, -1, 1);
1188#else
1189 gl->addWidget(lab, 0, 0, 1, -1);
1190#endif
1191 connect(lab, &QColorShowLabel::colorDropped, this, &QColorShower::newCol);
1192 connect(lab, &QColorShowLabel::colorDropped, this, &QColorShower::setRgb);
1193
1194 hEd = new QColSpinBox(this);
1195 hEd->setRange(0, 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, 0, 1);
1203 gl->addWidget(hEd, 0, 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, 1, 1);
1217 gl->addWidget(sEd, 1, 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, 2, 1);
1231 gl->addWidget(vEd, 2, 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, 0, 3);
1245 gl->addWidget(rEd, 0, 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, 1, 3);
1259 gl->addWidget(gEd, 1, 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, 2, 3);
1273 gl->addWidget(bEd, 2, 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, 3, 1, 1, 3);
1287 gl->addWidget(alphaEd, 3, 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(QSizePolicy::Maximum, 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, 5, 1);
1316 gl->addWidget(htEd, 5, 2, 1, /*colspan=*/ 3);
1317#endif
1318
1319 connect(hEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1320 connect(sEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1321 connect(vEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1322
1323 connect(rEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1324 connect(gEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1325 connect(bEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1326 connect(alphaEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1327 connect(htEd, &QLineEdit::textEdited, this, &QColorShower::htmlEd);
1328
1330}
1331
1332} // namespace QtPrivate
1333
1334inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); }
1339
1341{
1342 if (nativeDialogInUse)
1343 return platformColorDialogHelper()->currentColor();
1344 return cs->currentQColor();
1345}
1346
1347void QColorShower::showCurrentColor()
1348{
1349 lab->setColor(currentColor());
1350 lab->repaint();
1351}
1352
1353void QColorShower::rgbEd()
1354{
1355 rgbOriginal = true;
1356 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1357
1358 rgb2hsv(currentColor(), hue, sat, 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(currentColor());
1369}
1370
1371void 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(hue, sat, val);
1380 curCol = c.rgb();
1381
1382 rEd->setValue(qRed(currentColor()));
1383 gEd->setValue(qGreen(currentColor()));
1384 bEd->setValue(qBlue(currentColor()));
1385
1386 htEd->setText(c.name());
1387
1388 showCurrentColor();
1389 emit newCol(currentColor());
1391}
1392
1393void QColorShower::htmlEd()
1394{
1395 QString t = htEd->text();
1396 if (t.isEmpty())
1397 return;
1398
1399 if (!t.startsWith(u"#")) {
1400 t.prepend(u"#");
1401 QSignalBlocker blocker(htEd);
1402 htEd->setText(t);
1403 }
1404
1405 QColor c = QColor::fromString(t);
1406 if (!c.isValid())
1407 return;
1408
1409 curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());
1410 rgb2hsv(curCol, hue, sat, val);
1411
1412 hEd->setValue(hue);
1413 sEd->setValue(sat);
1414 vEd->setValue(val);
1415
1416 rEd->setValue(qRed(currentColor()));
1417 gEd->setValue(qGreen(currentColor()));
1418 bEd->setValue(qBlue(currentColor()));
1419
1420 showCurrentColor();
1421 emit newCol(currentColor());
1423}
1424
1425void QColorShower::setRgb(QRgb rgb)
1426{
1427 rgbOriginal = true;
1428 curCol = rgb;
1429
1430 rgb2hsv(currentColor(), hue, sat, val);
1431
1432 hEd->setValue(hue);
1433 sEd->setValue(sat);
1434 vEd->setValue(val);
1435
1436 rEd->setValue(qRed(currentColor()));
1437 gEd->setValue(qGreen(currentColor()));
1438 bEd->setValue(qBlue(currentColor()));
1439
1440 htEd->setText(QColor(rgb).name());
1441
1442 showCurrentColor();
1444}
1445
1446void 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(hue, sat, val);
1455 curCol = c.rgb();
1456
1457 hEd->setValue(hue);
1458 sEd->setValue(sat);
1459 vEd->setValue(val);
1460
1461 rEd->setValue(qRed(currentColor()));
1462 gEd->setValue(qGreen(currentColor()));
1463 bEd->setValue(qBlue(currentColor()));
1464
1465 htEd->setText(c.name());
1466
1467 showCurrentColor();
1469}
1470
1471void QColorShower::retranslateStrings()
1472{
1473 lblHue->setText(QColorDialog::tr("Hu&e:"));
1474 lblSat->setText(QColorDialog::tr("&Sat:"));
1475 lblVal->setText(QColorDialog::tr("&Val:"));
1476 lblRed->setText(QColorDialog::tr("&Red:"));
1477 lblGreen->setText(QColorDialog::tr("&Green:"));
1478 lblBlue->setText(QColorDialog::tr("Bl&ue:"));
1479 alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
1480 lblHtml->setText(QColorDialog::tr("&HTML:"));
1481}
1482
1483void QColorShower::updateQColor()
1484{
1485 QColor oldQColor(curQColor);
1486 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1487 if (curQColor != oldQColor)
1488 emit currentColorChanged(curQColor);
1489}
1490
1491//sets all widgets to display h,s,v
1492void 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
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
1511void 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
1521enum {
1525};
1526
1527bool 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(standardColors, standardColorsEnd, 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, column);
1541 standard->setSelected(row, 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(customColors, customColorsEnd, 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, column);
1557 custom->setSelected(row, column);
1558 custom->setFocus();
1559 return true;
1560 }
1561 }
1562 return false;
1563}
1564
1566{
1567 QScreen *screen = QGuiApplication::screenAt(p);
1568 if (!screen)
1569 screen = QGuiApplication::primaryScreen();
1570 const QRect screenRect = screen->geometry();
1571 const QPixmap pixmap =
1572 screen->grabWindow(0, p.x() - screenRect.x(), p.y() - screenRect.y(), 1, 1);
1573 const QImage i = pixmap.toImage();
1574 return i.pixel(0, 0);
1575}
1576
1577//sets all widgets except cs to display 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
1589{
1590 nextCust = r + customColorRows * c;
1591}
1592
1594{
1595 const int i = r + customColorRows * c;
1596 setCurrentRgbColor(QColorDialogOptions::customColor(i));
1597 if (standard)
1599}
1600
1602{
1603 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));
1604 if (custom)
1606}
1607
1609{
1610 Q_Q(QColorDialog);
1611
1612 auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
1613 if (platformServices && platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) {
1614 if (auto *colorPicker = platformServices->colorPicker(q->windowHandle())) {
1615 q->connect(colorPicker, &QPlatformServiceColorPicker::colorPicked, q,
1616 [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(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(globalPos));
1657 updateColorLabelText(globalPos);
1658 }
1659}
1660
1662{
1663 if (lblScreenColorInfo)
1664 lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")
1665 .arg(globalPos.x())
1666 .arg(globalPos.y()));
1667}
1668
1670{
1671 Q_Q(QColorDialog);
1673 q->removeEventFilter(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
1687void QColorDialogPrivate::init(const QColor &initial)
1688{
1689 Q_Q(QColorDialog);
1690
1691 q->setSizeGripEnabled(false);
1692 q->setWindowTitle(QColorDialog::tr("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)
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
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(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(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(standard, &QColorWell::selected,
1742 this, &QColorDialogPrivate::newStandard);
1743 leftLay->addWidget(lblBasicColors);
1744 leftLay->addWidget(standard);
1745
1746#if !defined(QT_SMALL_COLORDIALOG)
1748 eyeDropperButton = new QPushButton();
1749 leftLay->addWidget(eyeDropperButton);
1750 lblScreenColorInfo = new QLabel("\n"_L1);
1751 leftLay->addWidget(lblScreenColorInfo);
1752 QObjectPrivate::connect(eyeDropperButton, &QPushButton::clicked,
1753 this, &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(custom, &QColorWell::selected, this, &QColorDialogPrivate::newCustom);
1766 QObjectPrivate::connect(custom, &QColorWell::currentChanged, this, &QColorDialogPrivate::nextCustom);
1767
1768 QObject::connect(custom, &QWellArray::colorChanged, q, [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(addCusBt, &QPushButton::clicked, this, &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(rightLay);
1802
1803 QHBoxLayout *pickLay = new QHBoxLayout;
1804 rightLay->addLayout(pickLay);
1805
1806 QVBoxLayout *cLay = new QVBoxLayout;
1807 pickLay->addLayout(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(lumSpace);
1816 cLay->addWidget(cp);
1817#endif
1818 cLay->addSpacing(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(10);
1826 pickLay->addWidget(lp);
1827 pickLay->addStretch();
1828#endif
1829
1830 QObject::connect(cp, &QColorPicker::newCol, lp, qOverload<int, int>(&QColorLuminancePicker::setCol));
1831 QObjectPrivate::connect(lp, &QColorLuminancePicker::newHsv, this, &QColorDialogPrivate::newHsv);
1832
1833 rightLay->addStretch();
1834
1835 cs = new QColorShower(q);
1836 pickLay->setContentsMargins(cs->gl->contentsMargins());
1837 QObjectPrivate::connect(cs, &QColorShower::newCol,
1838 this, &QColorDialogPrivate::newColorTypedIn);
1839 QObject::connect(cs, &QColorShower::currentColorChanged,
1840 q, &QColorDialog::currentColorChanged);
1841#if defined(QT_SMALL_COLORDIALOG)
1842 topLay->addWidget(cs);
1843#else
1844 rightLay->addWidget(cs);
1845 if (leftLay)
1846 leftLay->addSpacing(cs->gl->contentsMargins().right());
1847#endif
1848
1849 buttons = new QDialogButtonBox(q);
1850 mainLay->addWidget(buttons);
1851
1852 ok = buttons->addButton(QDialogButtonBox::Ok);
1853 QObject::connect(ok, &QPushButton::clicked, q, &QColorDialog::accept);
1854 ok->setDefault(true);
1855 cancel = buttons->addButton(QDialogButtonBox::Cancel);
1856 QObject::connect(cancel, &QPushButton::clicked, q, &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
1864}
1865
1866void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h)
1867{
1868 QColorDialog *d = q_func();
1869 auto *colorDialogHelper = static_cast<QPlatformColorDialogHelper*>(h);
1870 QObject::connect(colorDialogHelper, &QPlatformColorDialogHelper::currentColorChanged,
1871 d, &QColorDialog::currentColorChanged);
1872 QObject::connect(colorDialogHelper, &QPlatformColorDialogHelper::colorSelected,
1873 d, &QColorDialog::colorSelected);
1874 colorDialogHelper->setOptions(options);
1875}
1876
1877void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
1878{
1879 options->setWindowTitle(q_func()->windowTitle());
1880}
1881
1883{
1884 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
1885 if (custom)
1886 custom->update();
1887 nextCust = (nextCust+1) % QColorDialogOptions::customColorCount();
1888}
1889
1891{
1892 if (nativeDialogInUse)
1893 return;
1894
1895 if (!smallDisplay) {
1896 lblBasicColors->setText(QColorDialog::tr("&Basic colors"));
1897 lblCustomColors->setText(QColorDialog::tr("&Custom colors"));
1898 addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));
1899#if !defined(QT_SMALL_COLORDIALOG)
1900 if (eyeDropperButton)
1901 eyeDropperButton->setText(QColorDialog::tr("&Pick Screen Color"));
1902#endif
1903 }
1904
1906}
1907
1909{
1910 const auto integration = QGuiApplicationPrivate::platformIntegration();
1911 return integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
1912 || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking);
1913}
1914
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(Qt::AA_DontUseNativeDialogs)
1923 || q->testAttribute(Qt::WA_DontShowOnScreen)
1924 || (options->options() & QColorDialog::DontUseNativeDialog)) {
1925 return false;
1926 }
1927
1928 return strcmp(QColorDialog::staticMetaObject.className(), q->metaObject()->className()) == 0;
1929}
1930
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*/
1977QColorDialog::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*/
1986QColorDialog::QColorDialog(const QColor &initial, QWidget *parent)
1987 : QDialog(*new QColorDialogPrivate, parent, qcd_DefaultWindowFlags)
1988{
1989 Q_D(QColorDialog);
1990 d->init(initial);
1991}
1992
1993void 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(color);
2006}
2007
2008/*!
2009 \property QColorDialog::currentColor
2010 \brief the currently selected color in the dialog
2011*/
2012
2013void QColorDialog::setCurrentColor(const QColor &color)
2014{
2015 Q_D(QColorDialog);
2016 d->setCurrentColor(color);
2017}
2018
2019QColor 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*/
2033QColor 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*/
2045void 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*/
2058bool QColorDialog::testOption(ColorDialogOption option) const
2059{
2060 Q_D(const QColorDialog);
2061 return d->options->testOption(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*/
2076void 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(options & ShowAlphaChannel);
2091 if (d->eyeDropperButton)
2092 d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton));
2093 }
2094}
2095
2096QColorDialog::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*/
2139void 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*/
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 {
2166 }
2167 } else {
2168 q->setAttribute(Qt::WA_DontShowOnScreen, 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*/
2180void QColorDialog::open(QObject *receiver, const char *member)
2181{
2182 Q_D(QColorDialog);
2183 connect(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*/
2197QColor 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
2219QColorDialog::~QColorDialog()
2220{
2221}
2222
2223/*!
2224 \reimp
2225*/
2226void QColorDialog::changeEvent(QEvent *e)
2227{
2228 Q_D(QColorDialog);
2229 if (e->type() == QEvent::LanguageChange)
2230 d->retranslateStrings();
2231 QDialog::changeEvent(e);
2232}
2233
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(q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called
2245 updateColorPicking(newGlobalPos);
2246#ifdef Q_OS_WIN32
2247 dummyTransparentWindow.setPosition(newGlobalPos);
2248#endif
2249 }
2250#endif // ! QT_NO_CURSOR
2251}
2252
2254{
2255 const QColor color = grabScreenColor(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, ShowColor);
2259 updateColorLabelText(globalPos);
2260}
2261
2263{
2264 // If the cross is visible the grabbed color will be black most of the times
2265 cp->setCrossVisible(!cp->geometry().contains(e->position().toPoint()));
2266
2267 updateColorPicking(e->globalPosition().toPoint());
2268 return true;
2269}
2270
2272{
2273 setCurrentColor(grabScreenColor(e->globalPosition().toPoint()), SetColorAll);
2275 return true;
2276}
2277
2279{
2280 Q_Q(QColorDialog);
2281#if QT_CONFIG(shortcut)
2282 if (e->matches(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(QCursor::pos()));
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*/
2302void QColorDialog::done(int result)
2303{
2304 Q_D(QColorDialog);
2305 if (result == Accepted) {
2306 d->selectedQColor = d->currentQColor();
2307 emit colorSelected(d->selectedQColor);
2308 } else {
2309 d->selectedQColor = QColor();
2310 }
2311 QDialog::done(result);
2312 if (d->receiverToDisconnectOnClose) {
2313 disconnect(this, SIGNAL(colorSelected(QColor)),
2314 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2315 d->receiverToDisconnectOnClose = nullptr;
2316 }
2317 d->memberToDisconnectOnClose.clear();
2318}
2319
2320QT_END_NAMESPACE
2321
2322#include "qcolordialog.moc"
2323#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:28
\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.
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
static void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
static int pHeight
static int pWidth
static const Qt::WindowFlags qcd_DefaultWindowFlags
@ colorColumns
@ standardColorRows
@ customColorRows