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