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