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