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