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 || pix.isNull())
798 return;
799
800 Q_ASSERT(pix.height());
801 Q_ASSERT(pix.width());
802
803 QRect r(m_pos, QSize(20, 20));
804 m_pos.setX(std::clamp(pt.x(), 0, pix.width() - 1));
805 m_pos.setY(std::clamp(pt.y(), 0, pix.height() - 1));
806 r = r.united(QRect(m_pos, QSize(20, 20)));
807 r.translate(contentsRect().x() - 9, contentsRect().y() - 9);
808 // update(r);
809 repaint(r);
810
811 if (notify)
812 emit newCol(huePt(m_pos), satPt(m_pos));
813}
814
815QColorPicker::QColorPicker(QWidget* parent)
816 : QFrame(parent)
817 , crossVisible(true)
818{
819 setAttribute(Qt::WA_NoSystemBackground);
820 setFocusPolicy(Qt::StrongFocus);
821 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
822 adjustSize();
823
824 pix = createColorsPixmap();
825
826 setCol(150, 255);
827}
828
832
833void QColorPicker::setCrossVisible(bool visible)
834{
835 if (crossVisible != visible) {
836 crossVisible = visible;
837 update();
838 }
839}
840
842{
843 return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
844}
845
846void QColorPicker::setCol(int h, int s)
847{
848 int nhue = qMin(qMax(0,h), 359);
849 int nsat = qMin(qMax(0,s), 255);
850 if (nhue == huePt(m_pos) && nsat == satPt(m_pos))
851 return;
852
853 setCol(colPt(nhue, nsat), false);
854}
855
856void QColorPicker::keyPressEvent(QKeyEvent *event)
857{
858 switch (event->key()) {
859 case Qt::Key_Down:
860 setCol(m_pos + QPoint(0, 1));
861 break;
862 case Qt::Key_Left:
863 setCol(m_pos + QPoint(-1, 0));
864 break;
865 case Qt::Key_Right:
866 setCol(m_pos + QPoint(1, 0));
867 break;
868 case Qt::Key_Up:
869 setCol(m_pos + QPoint(0, -1));
870 break;
871 default:
872 QFrame::keyPressEvent(event);
873 break;
874 }
875}
876
877void QColorPicker::mouseMoveEvent(QMouseEvent *m)
878{
879 QPoint p = m->position().toPoint() - contentsRect().topLeft();
880 if (m->buttons() == Qt::NoButton) {
881 m->ignore();
882 return;
883 }
884 setCol(p);
885}
886
887void QColorPicker::mousePressEvent(QMouseEvent *m)
888{
889 QPoint p = m->position().toPoint() - contentsRect().topLeft();
890 setCol(p);
891}
892
893void QColorPicker::paintEvent(QPaintEvent* )
894{
895 QPainter p(this);
896 drawFrame(&p);
897 QRect r = contentsRect();
898
899 p.drawPixmap(r.topLeft(), pix);
900
901 if (crossVisible) {
902 QPoint pt = m_pos + r.topLeft();
903 p.setPen(Qt::black);
904 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
905 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
906 }
907}
908
909void QColorPicker::resizeEvent(QResizeEvent *ev)
910{
911 QFrame::resizeEvent(ev);
912
913 pix = createColorsPixmap();
914
915 const QSize &oldSize = ev->oldSize();
916 if (!oldSize.isValid())
917 return;
918
919 // calculate hue/saturation based on previous widget size
920 // and update position accordingly
921 const int hue = huePt(m_pos, oldSize);
922 const int sat = satPt(m_pos, oldSize);
923 setCol(hue, sat);
924}
925
926QPixmap QColorPicker::createColorsPixmap()
927{
928 int w = width() - frameWidth() * 2;
929 int h = height() - frameWidth() * 2;
930 QImage img(w, h, QImage::Format_RGB32);
931 int x, y;
932 uint *pixel = (uint *) img.scanLine(0);
933 for (y = 0; y < h; y++) {
934 const uint *end = pixel + w;
935 x = 0;
936 while (pixel < end) {
937 QPoint p(x, y);
938 QColor c;
939 c.setHsv(huePt(p), satPt(p), 200);
940 *pixel = c.rgb();
941 ++pixel;
942 ++x;
943 }
944 }
945 return QPixmap::fromImage(img);
946}
947
948class QColSpinBox : public QSpinBox
949{
950public:
951 QColSpinBox(QWidget *parent)
952 : QSpinBox(parent) { setRange(0, 255); }
953 void setValue(int i) {
954 const QSignalBlocker blocker(this);
955 QSpinBox::setValue(i);
956 }
957};
958
959class QColorShowLabel;
960
961class QColorShower : public QWidget
962{
964public:
966
967 //things that don't emit signals
968 void setHsv(int h, int s, int v);
969
970 int currentAlpha() const
971 { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }
972 void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); }
973 void showAlpha(bool b);
974 bool isAlphaVisible() const;
975
976 QRgb currentColor() const { return curCol; }
977 QColor currentQColor() const { return curQColor; }
980
981public slots:
983
984signals:
986 void currentColorChanged(const QColor &color);
987
988private slots:
989 void rgbEd();
990 void hsvEd();
991 void htmlEd();
992
993private:
994 void showCurrentColor();
995 int hue, sat, val;
996 QRgb curCol;
997 QColor curQColor;
998 QLabel *lblHue;
999 QLabel *lblSat;
1000 QLabel *lblVal;
1001 QLabel *lblRed;
1002 QLabel *lblGreen;
1003 QLabel *lblBlue;
1004 QLabel *lblHtml;
1005 QColSpinBox *hEd;
1006 QColSpinBox *sEd;
1007 QColSpinBox *vEd;
1008 QColSpinBox *rEd;
1009 QColSpinBox *gEd;
1010 QColSpinBox *bEd;
1011 QColSpinBox *alphaEd;
1012 QLabel *alphaLab;
1013 QLineEdit *htEd;
1014 QColorShowLabel *lab;
1015 bool rgbOriginal;
1016 QColorDialog *colorDialog;
1017 QGridLayout *gl;
1018
1021};
1022
1024{
1025 Q_OBJECT
1026
1027public:
1033 void setColor(QColor c) { col = c; }
1034
1035signals:
1037
1038protected:
1039 void paintEvent(QPaintEvent *) override;
1040 void mousePressEvent(QMouseEvent *e) override;
1041 void mouseMoveEvent(QMouseEvent *e) override;
1042 void mouseReleaseEvent(QMouseEvent *e) override;
1043#if QT_CONFIG(draganddrop)
1047#endif
1048
1049private:
1050 QColor col;
1051 bool mousePressed;
1052 QPoint pressPos;
1053};
1054
1055void QColorShowLabel::paintEvent(QPaintEvent *e)
1056{
1057 QPainter p(this);
1058 drawFrame(&p);
1059 p.fillRect(contentsRect()&e->rect(), col);
1060}
1061
1063{
1064 alphaLab->setVisible(b);
1065 alphaEd->setVisible(b);
1066}
1067
1068inline bool QColorShower::isAlphaVisible() const
1069{
1070 return alphaLab->isVisible();
1071}
1072
1074{
1075 mousePressed = true;
1076 pressPos = e->position().toPoint();
1077}
1078
1079void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)
1080{
1081#if !QT_CONFIG(draganddrop)
1082 Q_UNUSED(e);
1083#else
1084 if (!mousePressed)
1085 return;
1086 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
1087 QMimeData *mime = new QMimeData;
1088 mime->setColorData(col);
1089 QPixmap pix(30, 20);
1090 pix.fill(col);
1091 QPainter p(&pix);
1092 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
1093 p.end();
1094 QDrag *drg = new QDrag(this);
1095 drg->setMimeData(mime);
1096 drg->setPixmap(pix);
1097 mousePressed = false;
1098 drg->exec(Qt::CopyAction);
1099 }
1100#endif
1101}
1102
1103#if QT_CONFIG(draganddrop)
1105{
1107 e->accept();
1108 else
1109 e->ignore();
1110}
1111
1113{
1114}
1115
1117{
1119 if (color.isValid()) {
1120 col = color;
1121 repaint();
1123 e->accept();
1124 } else {
1125 e->ignore();
1126 }
1127}
1128#endif // QT_CONFIG(draganddrop)
1129
1131{
1132 if (!mousePressed)
1133 return;
1134 mousePressed = false;
1135}
1136
1137QColorShower::QColorShower(QColorDialog *parent)
1138 : QWidget(parent)
1139{
1140 colorDialog = parent;
1141
1142 curCol = qRgb(255, 255, 255);
1143 curQColor = Qt::white;
1144
1145 gl = new QGridLayout(this);
1146 const int s = gl->spacing();
1147 gl->setContentsMargins(s, s, s, s);
1148 lab = new QColorShowLabel(this);
1149
1150#ifdef QT_SMALL_COLORDIALOG
1151 lab->setMinimumHeight(60);
1152#endif
1153 lab->setMinimumWidth(60);
1154
1155// For QVGA screens only the comboboxes and color label are visible.
1156// For nHD screens only color and luminence pickers and color label are visible.
1157#if !defined(QT_SMALL_COLORDIALOG)
1158 gl->addWidget(lab, 0, 0, -1, 1);
1159#else
1160 gl->addWidget(lab, 0, 0, 1, -1);
1161#endif
1162 connect(lab, &QColorShowLabel::colorDropped, this, &QColorShower::newCol);
1163 connect(lab, &QColorShowLabel::colorDropped, this, &QColorShower::setRgb);
1164
1165 hEd = new QColSpinBox(this);
1166 hEd->setRange(0, 359);
1167 lblHue = new QLabel(this);
1168#ifndef QT_NO_SHORTCUT
1169 lblHue->setBuddy(hEd);
1170#endif
1171 lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1172#if !defined(QT_SMALL_COLORDIALOG)
1173 gl->addWidget(lblHue, 0, 1);
1174 gl->addWidget(hEd, 0, 2);
1175#else
1176 gl->addWidget(lblHue, 1, 0);
1177 gl->addWidget(hEd, 2, 0);
1178#endif
1179
1180 sEd = new QColSpinBox(this);
1181 lblSat = new QLabel(this);
1182#ifndef QT_NO_SHORTCUT
1183 lblSat->setBuddy(sEd);
1184#endif
1185 lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1186#if !defined(QT_SMALL_COLORDIALOG)
1187 gl->addWidget(lblSat, 1, 1);
1188 gl->addWidget(sEd, 1, 2);
1189#else
1190 gl->addWidget(lblSat, 1, 1);
1191 gl->addWidget(sEd, 2, 1);
1192#endif
1193
1194 vEd = new QColSpinBox(this);
1195 lblVal = new QLabel(this);
1196#ifndef QT_NO_SHORTCUT
1197 lblVal->setBuddy(vEd);
1198#endif
1199 lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1200#if !defined(QT_SMALL_COLORDIALOG)
1201 gl->addWidget(lblVal, 2, 1);
1202 gl->addWidget(vEd, 2, 2);
1203#else
1204 gl->addWidget(lblVal, 1, 2);
1205 gl->addWidget(vEd, 2, 2);
1206#endif
1207
1208 rEd = new QColSpinBox(this);
1209 lblRed = new QLabel(this);
1210#ifndef QT_NO_SHORTCUT
1211 lblRed->setBuddy(rEd);
1212#endif
1213 lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1214#if !defined(QT_SMALL_COLORDIALOG)
1215 gl->addWidget(lblRed, 0, 3);
1216 gl->addWidget(rEd, 0, 4);
1217#else
1218 gl->addWidget(lblRed, 3, 0);
1219 gl->addWidget(rEd, 4, 0);
1220#endif
1221
1222 gEd = new QColSpinBox(this);
1223 lblGreen = new QLabel(this);
1224#ifndef QT_NO_SHORTCUT
1225 lblGreen->setBuddy(gEd);
1226#endif
1227 lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1228#if !defined(QT_SMALL_COLORDIALOG)
1229 gl->addWidget(lblGreen, 1, 3);
1230 gl->addWidget(gEd, 1, 4);
1231#else
1232 gl->addWidget(lblGreen, 3, 1);
1233 gl->addWidget(gEd, 4, 1);
1234#endif
1235
1236 bEd = new QColSpinBox(this);
1237 lblBlue = new QLabel(this);
1238#ifndef QT_NO_SHORTCUT
1239 lblBlue->setBuddy(bEd);
1240#endif
1241 lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1242#if !defined(QT_SMALL_COLORDIALOG)
1243 gl->addWidget(lblBlue, 2, 3);
1244 gl->addWidget(bEd, 2, 4);
1245#else
1246 gl->addWidget(lblBlue, 3, 2);
1247 gl->addWidget(bEd, 4, 2);
1248#endif
1249
1250 alphaEd = new QColSpinBox(this);
1251 alphaLab = new QLabel(this);
1252#ifndef QT_NO_SHORTCUT
1253 alphaLab->setBuddy(alphaEd);
1254#endif
1255 alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1256#if !defined(QT_SMALL_COLORDIALOG)
1257 gl->addWidget(alphaLab, 3, 1, 1, 3);
1258 gl->addWidget(alphaEd, 3, 4);
1259#else
1260 gl->addWidget(alphaLab, 1, 3, 3, 1);
1261 gl->addWidget(alphaEd, 4, 3);
1262#endif
1263 alphaEd->hide();
1264 alphaLab->hide();
1265 lblHtml = new QLabel(this);
1266 htEd = new QLineEdit(this);
1267 htEd->setObjectName("qt_colorname_lineedit");
1268#ifndef QT_NO_SHORTCUT
1269 lblHtml->setBuddy(htEd);
1270#endif
1271
1272#if QT_CONFIG(regularexpression)
1273 QRegularExpression regExp(QStringLiteral("#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));
1274 QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
1275 htEd->setValidator(validator);
1276#else
1277 htEd->setReadOnly(true);
1278#endif
1279 htEd->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
1280
1281 lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1282#if defined(QT_SMALL_COLORDIALOG)
1283 gl->addWidget(lblHtml, 5, 0);
1284 gl->addWidget(htEd, 5, 1, 1, /*colspan=*/ 2);
1285#else
1286 gl->addWidget(lblHtml, 5, 1);
1287 gl->addWidget(htEd, 5, 2, 1, /*colspan=*/ 3);
1288#endif
1289
1290 connect(hEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1291 connect(sEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1292 connect(vEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1293
1294 connect(rEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1295 connect(gEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1296 connect(bEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1297 connect(alphaEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1298 connect(htEd, &QLineEdit::textEdited, this, &QColorShower::htmlEd);
1299
1301}
1302
1303} // namespace QtPrivate
1304
1305inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); }
1310
1312{
1313 if (nativeDialogInUse)
1314 return platformColorDialogHelper()->currentColor();
1315 return cs->currentQColor();
1316}
1317
1318void QColorShower::showCurrentColor()
1319{
1320 lab->setColor(currentColor());
1321 lab->repaint();
1322}
1323
1324void QColorShower::rgbEd()
1325{
1326 rgbOriginal = true;
1327 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1328
1329 rgb2hsv(currentColor(), hue, sat, val);
1330
1331 hEd->setValue(hue);
1332 sEd->setValue(sat);
1333 vEd->setValue(val);
1334
1335 htEd->setText(QColor(curCol).name());
1336
1337 showCurrentColor();
1338 emit newCol(currentColor());
1340}
1341
1342void QColorShower::hsvEd()
1343{
1344 rgbOriginal = false;
1345 hue = hEd->value();
1346 sat = sEd->value();
1347 val = vEd->value();
1348
1349 QColor c;
1350 c.setHsv(hue, sat, val);
1351 curCol = c.rgb();
1352
1353 rEd->setValue(qRed(currentColor()));
1354 gEd->setValue(qGreen(currentColor()));
1355 bEd->setValue(qBlue(currentColor()));
1356
1357 htEd->setText(c.name());
1358
1359 showCurrentColor();
1360 emit newCol(currentColor());
1362}
1363
1364void QColorShower::htmlEd()
1365{
1366 QString t = htEd->text();
1367 if (t.isEmpty())
1368 return;
1369
1370 if (!t.startsWith(u"#")) {
1371 t.prepend(u"#");
1372 QSignalBlocker blocker(htEd);
1373 htEd->setText(t);
1374 }
1375
1376 QColor c = QColor::fromString(t);
1377 if (!c.isValid())
1378 return;
1379
1380 curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());
1381 rgb2hsv(curCol, hue, sat, val);
1382
1383 hEd->setValue(hue);
1384 sEd->setValue(sat);
1385 vEd->setValue(val);
1386
1387 rEd->setValue(qRed(currentColor()));
1388 gEd->setValue(qGreen(currentColor()));
1389 bEd->setValue(qBlue(currentColor()));
1390
1391 showCurrentColor();
1392 emit newCol(currentColor());
1394}
1395
1396void QColorShower::setRgb(QRgb rgb)
1397{
1398 rgbOriginal = true;
1399 curCol = rgb;
1400
1401 rgb2hsv(currentColor(), hue, sat, val);
1402
1403 hEd->setValue(hue);
1404 sEd->setValue(sat);
1405 vEd->setValue(val);
1406
1407 rEd->setValue(qRed(currentColor()));
1408 gEd->setValue(qGreen(currentColor()));
1409 bEd->setValue(qBlue(currentColor()));
1410
1411 htEd->setText(QColor(rgb).name());
1412
1413 showCurrentColor();
1415}
1416
1417void QColorShower::setHsv(int h, int s, int v)
1418{
1419 if (h < -1 || (uint)s > 255 || (uint)v > 255)
1420 return;
1421
1422 rgbOriginal = false;
1423 hue = h; val = v; sat = s;
1424 QColor c;
1425 c.setHsv(hue, sat, val);
1426 curCol = c.rgb();
1427
1428 hEd->setValue(hue);
1429 sEd->setValue(sat);
1430 vEd->setValue(val);
1431
1432 rEd->setValue(qRed(currentColor()));
1433 gEd->setValue(qGreen(currentColor()));
1434 bEd->setValue(qBlue(currentColor()));
1435
1436 htEd->setText(c.name());
1437
1438 showCurrentColor();
1440}
1441
1443{
1444 lblHue->setText(QColorDialog::tr("Hu&e:"));
1445 lblSat->setText(QColorDialog::tr("&Sat:"));
1446 lblVal->setText(QColorDialog::tr("&Val:"));
1447 lblRed->setText(QColorDialog::tr("&Red:"));
1448 lblGreen->setText(QColorDialog::tr("&Green:"));
1449 lblBlue->setText(QColorDialog::tr("Bl&ue:"));
1450 alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
1451 lblHtml->setText(QColorDialog::tr("&HTML:"));
1452}
1453
1455{
1456 QColor oldQColor(curQColor);
1457 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1458 if (curQColor != oldQColor)
1459 emit currentColorChanged(curQColor);
1460}
1461
1462//sets all widgets to display h,s,v
1463void QColorDialogPrivate::newHsv(int h, int s, int v)
1464{
1465 if (!nativeDialogInUse) {
1466 cs->setHsv(h, s, v);
1467 cp->setCol(h, s);
1468 lp->setCol(h, s, v);
1469 }
1470}
1471
1472//sets all widgets to display rgb
1474{
1475 if (!nativeDialogInUse) {
1476 cs->setRgb(rgb);
1477 newColorTypedIn(rgb);
1478 }
1479}
1480
1481// hack; doesn't keep curCol in sync, so use with care
1482void QColorDialogPrivate::setCurrentQColor(const QColor &color)
1483{
1484 Q_Q(QColorDialog);
1485 if (cs->curQColor != color) {
1486 cs->curQColor = color;
1487 emit q->currentColorChanged(color);
1488 }
1489}
1490
1491// size of standard and custom color selector
1492enum {
1496};
1497
1498bool QColorDialogPrivate::selectColor(const QColor &col)
1499{
1500 QRgb color = col.rgb();
1501 // Check standard colors
1502 if (standard) {
1503 const QRgb *standardColors = QColorDialogOptions::standardColors();
1504 const QRgb *standardColorsEnd = standardColors + standardColorRows * colorColumns;
1505 const QRgb *match = std::find(standardColors, standardColorsEnd, color);
1506 if (match != standardColorsEnd) {
1507 const int index = int(match - standardColors);
1508 const int column = index / standardColorRows;
1509 const int row = index % standardColorRows;
1510 newStandard(row, column);
1511 standard->setCurrent(row, column);
1512 standard->setSelected(row, column);
1513 standard->setFocus();
1514 return true;
1515 }
1516 }
1517 // Check custom colors
1518 if (custom) {
1519 const QRgb *customColors = QColorDialogOptions::customColors();
1520 const QRgb *customColorsEnd = customColors + customColorRows * colorColumns;
1521 const QRgb *match = std::find(customColors, customColorsEnd, color);
1522 if (match != customColorsEnd) {
1523 const int index = int(match - customColors);
1524 const int column = index / customColorRows;
1525 const int row = index % customColorRows;
1526 newCustom(row, column);
1527 custom->setCurrent(row, column);
1528 custom->setSelected(row, column);
1529 custom->setFocus();
1530 return true;
1531 }
1532 }
1533 return false;
1534}
1535
1537{
1538 QScreen *screen = QGuiApplication::screenAt(p);
1539 if (!screen)
1540 screen = QGuiApplication::primaryScreen();
1541 const QRect screenRect = screen->geometry();
1542 const QPixmap pixmap =
1543 screen->grabWindow(0, p.x() - screenRect.x(), p.y() - screenRect.y(), 1, 1);
1544 const QImage i = pixmap.toImage();
1545 return i.pixel(0, 0);
1546}
1547
1548//sets all widgets except cs to display rgb
1550{
1551 if (!nativeDialogInUse) {
1552 int h, s, v;
1553 rgb2hsv(rgb, h, s, v);
1554 cp->setCol(h, s);
1555 lp->setCol(h, s, v);
1556 }
1557}
1558
1560{
1561 nextCust = r + customColorRows * c;
1562}
1563
1565{
1566 const int i = r + customColorRows * c;
1567 setCurrentRgbColor(QColorDialogOptions::customColor(i));
1568 if (standard)
1569 standard->setSelected(-1,-1);
1570}
1571
1573{
1574 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));
1575 if (custom)
1576 custom->setSelected(-1,-1);
1577}
1578
1580{
1581 Q_Q(QColorDialog);
1582
1583 auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
1584 if (platformServices && platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) {
1585 if (auto *colorPicker = platformServices->colorPicker(q->windowHandle())) {
1586 q->connect(colorPicker, &QPlatformServiceColorPicker::colorPicked, q,
1587 [q, colorPicker](const QColor &color) {
1588 colorPicker->deleteLater();
1589 q->setCurrentColor(color);
1590 });
1591 colorPicker->pickColor();
1592 return;
1593 }
1594 }
1595
1596 if (!colorPickingEventFilter)
1597 colorPickingEventFilter = new QColorPickingEventFilter(this, q);
1598 q->installEventFilter(colorPickingEventFilter);
1599 QObject::connect(qApp, &QGuiApplication::applicationStateChanged,
1600 colorPickingEventFilter, &QColorPickingEventFilter::applicationStateChanged);
1601 // If user pushes Escape, the last color before picking will be restored.
1602 beforeScreenColorPicking = cs->currentColor();
1603#ifndef QT_NO_CURSOR
1604 q->grabMouse(Qt::CrossCursor);
1605#else
1606 q->grabMouse();
1607#endif
1608
1609#ifdef Q_OS_WIN32
1610 // On Windows mouse tracking doesn't work over other processes's windows
1611 updateTimer->start(30);
1612
1613 // HACK: Because mouse grabbing doesn't work across processes, we have to have a dummy,
1614 // invisible window to catch the mouse click, otherwise we will click whatever we clicked
1615 // and loose focus.
1616 dummyTransparentWindow.show();
1617#endif
1618 q->grabKeyboard();
1619 /* With setMouseTracking(true) the desired color can be more precisely picked up,
1620 * and continuously pushing the mouse button is not necessary.
1621 */
1622 q->setMouseTracking(true);
1623
1624 addCusBt->setDisabled(true);
1625 buttons->setDisabled(true);
1626 if (eyeDropperButton) {
1627 eyeDropperButton->setDisabled(true);
1628 const QPoint globalPos = QCursor::pos();
1629 q->setCurrentColor(grabScreenColor(globalPos));
1630 updateColorLabelText(globalPos);
1631 }
1632}
1633
1635{
1636 if (lblScreenColorInfo)
1637 lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")
1638 .arg(globalPos.x())
1639 .arg(globalPos.y()));
1640}
1641
1643{
1644 Q_Q(QColorDialog);
1646 q->removeEventFilter(colorPickingEventFilter);
1647 QObject::disconnect(qApp, &QGuiApplication::applicationStateChanged,
1648 colorPickingEventFilter, &QColorPickingEventFilter::applicationStateChanged);
1649 q->releaseMouse();
1650#ifdef Q_OS_WIN32
1651 updateTimer->stop();
1652 dummyTransparentWindow.setVisible(false);
1653#endif
1654 q->releaseKeyboard();
1655 q->setMouseTracking(false);
1656 lblScreenColorInfo->setText("\n"_L1);
1657 addCusBt->setDisabled(false);
1658 buttons->setDisabled(false);
1659 eyeDropperButton->setDisabled(false);
1660}
1661
1662void QColorDialogPrivate::init(const QColor &initial)
1663{
1664 Q_Q(QColorDialog);
1665
1666 q->setSizeGripEnabled(false);
1667 q->setWindowTitle(QColorDialog::tr("Select Color"));
1668
1669 // default: use the native dialog if possible. Can be overridden in setOptions()
1670 nativeDialogInUse = (platformColorDialogHelper() != nullptr);
1671 colorPickingEventFilter = nullptr;
1672 nextCust = 0;
1673
1674 if (!nativeDialogInUse)
1676
1677#ifdef Q_OS_WIN32
1678 dummyTransparentWindow.resize(1, 1);
1679 dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);
1680#endif
1681
1682 q->setCurrentColor(initial);
1683}
1684
1686{
1687 Q_Q(QColorDialog);
1688 QVBoxLayout *mainLay = new QVBoxLayout(q);
1689 // there's nothing in this dialog that benefits from sizing up
1690 mainLay->setSizeConstraint(QLayout::SetFixedSize);
1691
1692 QHBoxLayout *topLay = new QHBoxLayout();
1693 mainLay->addLayout(topLay);
1694
1695 leftLay = nullptr;
1696
1697#if defined(QT_SMALL_COLORDIALOG)
1698 smallDisplay = true;
1699 const int lumSpace = 20;
1700#else
1701 // small displays (e.g. PDAs) cannot fit the full color dialog,
1702 // so just use the color picker.
1703 smallDisplay = (QGuiApplication::primaryScreen()->virtualGeometry().width() < 480 || QGuiApplication::primaryScreen()->virtualGeometry().height() < 350);
1704 const int lumSpace = topLay->spacing() / 2;
1705#endif
1706
1707 if (!smallDisplay) {
1708 leftLay = new QVBoxLayout;
1709 topLay->addLayout(leftLay);
1710
1711 standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());
1712 lblBasicColors = new QLabel(q);
1713#ifndef QT_NO_SHORTCUT
1714 lblBasicColors->setBuddy(standard);
1715#endif
1716 QObjectPrivate::connect(standard, &QColorWell::selected,
1717 this, &QColorDialogPrivate::newStandard);
1718 leftLay->addWidget(lblBasicColors);
1719 leftLay->addWidget(standard);
1720
1721#if !defined(QT_SMALL_COLORDIALOG)
1723 eyeDropperButton = new QPushButton();
1724 leftLay->addWidget(eyeDropperButton);
1725 lblScreenColorInfo = new QLabel("\n"_L1);
1726 leftLay->addWidget(lblScreenColorInfo);
1727 QObjectPrivate::connect(eyeDropperButton, &QPushButton::clicked,
1728 this, &QColorDialogPrivate::pickScreenColor);
1729 } else {
1730 eyeDropperButton = nullptr;
1731 lblScreenColorInfo = nullptr;
1732 }
1733#endif
1734
1735 leftLay->addStretch();
1736
1737 custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors());
1738 custom->setAcceptDrops(true);
1739
1740 QObjectPrivate::connect(custom, &QColorWell::selected, this, &QColorDialogPrivate::newCustom);
1741 QObjectPrivate::connect(custom, &QColorWell::currentChanged, this, &QColorDialogPrivate::nextCustom);
1742
1743 QObject::connect(custom, &QWellArray::colorChanged, q, [this] (int index, QRgb color) {
1744 QColorDialogOptions::setCustomColor(index, color);
1745 if (custom)
1746 custom->update();
1747 });
1748
1749 lblCustomColors = new QLabel(q);
1750#ifndef QT_NO_SHORTCUT
1751 lblCustomColors->setBuddy(custom);
1752#endif
1753 leftLay->addWidget(lblCustomColors);
1754 leftLay->addWidget(custom);
1755
1756 addCusBt = new QPushButton(q);
1757 QObjectPrivate::connect(addCusBt, &QPushButton::clicked, this, &QColorDialogPrivate::addCustom);
1758 leftLay->addWidget(addCusBt);
1759 } else {
1760 // better color picker size for small displays
1761#if defined(QT_SMALL_COLORDIALOG)
1762 QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size();
1763 pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
1764 pHeight -= 20;
1765 if (screenSize.height() > screenSize.width())
1766 pWidth -= 20;
1767#else
1768 pWidth = 150;
1769 pHeight = 100;
1770#endif
1771 custom = nullptr;
1772 standard = nullptr;
1773 }
1774
1775 QVBoxLayout *rightLay = new QVBoxLayout;
1776 topLay->addLayout(rightLay);
1777
1778 QHBoxLayout *pickLay = new QHBoxLayout;
1779 rightLay->addLayout(pickLay);
1780
1781 QVBoxLayout *cLay = new QVBoxLayout;
1782 pickLay->addLayout(cLay);
1783 cp = new QColorPicker(q);
1784
1785 cp->setFrameStyle(QFrame::Panel | QFrame::Sunken);
1786
1787#if defined(QT_SMALL_COLORDIALOG)
1788 cp->hide();
1789#else
1790 cLay->addSpacing(lumSpace);
1791 cLay->addWidget(cp);
1792#endif
1793 cLay->addSpacing(lumSpace);
1794
1795 lp = new QColorLuminancePicker(q);
1796#if defined(QT_SMALL_COLORDIALOG)
1797 lp->hide();
1798#else
1799 lp->setFixedWidth(20);
1800 pickLay->addSpacing(10);
1801 pickLay->addWidget(lp);
1802 pickLay->addStretch();
1803#endif
1804
1805 QObject::connect(cp, &QColorPicker::newCol, lp, qOverload<int, int>(&QColorLuminancePicker::setCol));
1806 QObjectPrivate::connect(lp, &QColorLuminancePicker::newHsv, this, &QColorDialogPrivate::newHsv);
1807
1808 rightLay->addStretch();
1809
1810 cs = new QColorShower(q);
1811 pickLay->setContentsMargins(cs->gl->contentsMargins());
1812 QObjectPrivate::connect(cs, &QColorShower::newCol,
1813 this, &QColorDialogPrivate::newColorTypedIn);
1814 QObject::connect(cs, &QColorShower::currentColorChanged,
1815 q, &QColorDialog::currentColorChanged);
1816#if defined(QT_SMALL_COLORDIALOG)
1817 topLay->addWidget(cs);
1818#else
1819 rightLay->addWidget(cs);
1820 if (leftLay)
1821 leftLay->addSpacing(cs->gl->contentsMargins().right());
1822#endif
1823
1824 buttons = new QDialogButtonBox(q);
1825 mainLay->addWidget(buttons);
1826
1827 ok = buttons->addButton(QDialogButtonBox::Ok);
1828 QObject::connect(ok, &QPushButton::clicked, q, &QColorDialog::accept);
1829 ok->setDefault(true);
1830 cancel = buttons->addButton(QDialogButtonBox::Cancel);
1831 QObject::connect(cancel, &QPushButton::clicked, q, &QColorDialog::reject);
1832
1833#ifdef Q_OS_WIN32
1834 updateTimer = new QTimer(q);
1835 QObjectPrivate::connect(updateTimer, &QTimer::timeout,
1836 this, qOverload<>(&QColorDialogPrivate::updateColorPicking));
1837#endif
1839}
1840
1841void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h)
1842{
1843 QColorDialog *d = q_func();
1844 auto *colorDialogHelper = static_cast<QPlatformColorDialogHelper*>(h);
1845 QObject::connect(colorDialogHelper, &QPlatformColorDialogHelper::currentColorChanged,
1846 d, &QColorDialog::currentColorChanged);
1847 QObject::connect(colorDialogHelper, &QPlatformColorDialogHelper::colorSelected,
1848 d, &QColorDialog::colorSelected);
1849 colorDialogHelper->setOptions(options);
1850}
1851
1852void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
1853{
1854 options->setWindowTitle(q_func()->windowTitle());
1855}
1856
1858{
1859 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
1860 if (custom)
1861 custom->update();
1862 nextCust = (nextCust+1) % QColorDialogOptions::customColorCount();
1863}
1864
1866{
1867 if (nativeDialogInUse)
1868 return;
1869
1870 if (!smallDisplay) {
1871 lblBasicColors->setText(QColorDialog::tr("&Basic colors"));
1872 lblCustomColors->setText(QColorDialog::tr("&Custom colors"));
1873 addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));
1874#if !defined(QT_SMALL_COLORDIALOG)
1875 if (eyeDropperButton)
1876 eyeDropperButton->setText(QColorDialog::tr("&Pick Screen Color"));
1877#endif
1878 }
1879
1881}
1882
1884{
1885 const auto integration = QGuiApplicationPrivate::platformIntegration();
1886 return integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
1887 || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking);
1888}
1889
1891{
1892 // Don't use Q_Q here! This function is called from ~QDialog,
1893 // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).
1894 const QDialog * const q = static_cast<const QDialog*>(q_ptr);
1895 if (nativeDialogInUse)
1896 return true;
1897 if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs)
1898 || q->testAttribute(Qt::WA_DontShowOnScreen)
1899 || (options->options() & QColorDialog::DontUseNativeDialog)) {
1900 return false;
1901 }
1902
1903 return strcmp(QColorDialog::staticMetaObject.className(), q->metaObject()->className()) == 0;
1904}
1905
1907 Qt::Dialog | Qt::WindowTitleHint
1908 | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
1909
1910/*!
1911 \class QColorDialog
1912 \brief The QColorDialog class provides a dialog widget for specifying colors.
1913
1914 \ingroup standard-dialogs
1915 \inmodule QtWidgets
1916
1917 The color dialog's function is to allow users to choose colors.
1918 For example, you might use this in a drawing program to allow the
1919 user to set the brush color.
1920
1921 The static functions provide modal color dialogs.
1922 \omit
1923 If you require a modeless dialog, use the QColorDialog constructor.
1924 \endomit
1925
1926 The static getColor() function shows the dialog, and allows the user to
1927 specify a color. This function can also be used to let users choose a
1928 color with a level of transparency: pass the ShowAlphaChannel option as
1929 an additional argument.
1930
1931 The user can store customCount() different custom colors. The
1932 custom colors are shared by all color dialogs, and remembered
1933 during the execution of the program. Use setCustomColor() to set
1934 the custom colors, and use customColor() to get them.
1935
1936 When pressing the "Pick Screen Color" button, the cursor changes to a haircross
1937 and the colors on the screen are scanned. The user can pick up one by clicking
1938 the mouse or the Enter button. Pressing Escape restores the last color selected
1939 before entering this mode.
1940
1941 The \l{dialogs/standarddialogs}{Standard Dialogs} example shows
1942 how to use QColorDialog as well as other built-in Qt dialogs.
1943
1944 \image fusion-colordialog.png A color dialog in the Fusion widget style.
1945
1946 \sa QColor, QFileDialog, QFontDialog, {Standard Dialogs Example}
1947*/
1948
1949/*!
1950 Constructs a color dialog with the given \a parent.
1951*/
1952QColorDialog::QColorDialog(QWidget *parent)
1953 : QColorDialog(QColor(Qt::white), parent)
1954{
1955}
1956
1957/*!
1958 Constructs a color dialog with the given \a parent and specified
1959 \a initial color.
1960*/
1961QColorDialog::QColorDialog(const QColor &initial, QWidget *parent)
1962 : QDialog(*new QColorDialogPrivate, parent, qcd_DefaultWindowFlags)
1963{
1964 Q_D(QColorDialog);
1965 d->init(initial);
1966}
1967
1968void QColorDialogPrivate::setCurrentColor(const QColor &color, SetColorMode setColorMode)
1969{
1970 if (nativeDialogInUse) {
1971 platformColorDialogHelper()->setCurrentColor(color);
1972 return;
1973 }
1974
1975 if (setColorMode & ShowColor) {
1976 setCurrentRgbColor(color.rgb());
1977 setCurrentAlpha(color.alpha());
1978 }
1979 if (setColorMode & SelectColor)
1980 selectColor(color);
1981}
1982
1983/*!
1984 \property QColorDialog::currentColor
1985 \brief the currently selected color in the dialog
1986*/
1987
1988void QColorDialog::setCurrentColor(const QColor &color)
1989{
1990 Q_D(QColorDialog);
1991 d->setCurrentColor(color);
1992}
1993
1994QColor QColorDialog::currentColor() const
1995{
1996 Q_D(const QColorDialog);
1997 return d->currentQColor();
1998}
1999
2000/*!
2001 Returns the color that the user selected by clicking the \uicontrol{OK}
2002 or equivalent button.
2003
2004 \note This color is not always the same as the color held by the
2005 \l currentColor property since the user can choose different colors
2006 before finally selecting the one to use.
2007*/
2008QColor QColorDialog::selectedColor() const
2009{
2010 Q_D(const QColorDialog);
2011 return d->selectedQColor;
2012}
2013
2014/*!
2015 Sets the given \a option to be enabled if \a on is true;
2016 otherwise, clears the given \a option.
2017
2018 \sa options, testOption()
2019*/
2020void QColorDialog::setOption(ColorDialogOption option, bool on)
2021{
2022 const QColorDialog::ColorDialogOptions previousOptions = options();
2023 if (!(previousOptions & option) != !on)
2024 setOptions(previousOptions ^ option);
2025}
2026
2027/*!
2028 Returns \c true if the given \a option is enabled; otherwise, returns
2029 false.
2030
2031 \sa options, setOption()
2032*/
2033bool QColorDialog::testOption(ColorDialogOption option) const
2034{
2035 Q_D(const QColorDialog);
2036 return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
2037}
2038
2039/*!
2040 \property QColorDialog::options
2041 \brief the various options that affect the look and feel of the dialog
2042
2043 By default, all options are disabled.
2044
2045 Options should be set before showing the dialog. Setting them while the
2046 dialog is visible is not guaranteed to have an immediate effect on the
2047 dialog (depending on the option and on the platform).
2048
2049 \sa setOption(), testOption()
2050*/
2051void QColorDialog::setOptions(ColorDialogOptions options)
2052{
2053 Q_D(QColorDialog);
2054
2055 if (QColorDialog::options() == options)
2056 return;
2057
2058 d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));
2059 if ((options & DontUseNativeDialog) && d->nativeDialogInUse) {
2060 d->nativeDialogInUse = false;
2061 d->initWidgets();
2062 }
2063 if (!d->nativeDialogInUse) {
2064 d->buttons->setVisible(!(options & NoButtons));
2065 d->showAlpha(options & ShowAlphaChannel);
2066 if (d->eyeDropperButton)
2067 d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton));
2068 }
2069}
2070
2071QColorDialog::ColorDialogOptions QColorDialog::options() const
2072{
2073 Q_D(const QColorDialog);
2074 return QColorDialog::ColorDialogOptions(int(d->options->options()));
2075}
2076
2077/*!
2078 \enum QColorDialog::ColorDialogOption
2079
2080 This enum specifies various options that affect the look and feel
2081 of a color dialog.
2082
2083 \value ShowAlphaChannel Allow the user to select the alpha component of a color.
2084 \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
2085 \value NoEyeDropperButton Hide the \uicontrol{Eye Dropper} button. This value was added in Qt 6.6.
2086 \value DontUseNativeDialog Use Qt's standard color dialog instead of the operating system
2087 native color dialog.
2088
2089 \sa options, setOption(), testOption(), windowModality()
2090*/
2091
2092/*!
2093 \fn void QColorDialog::currentColorChanged(const QColor &color)
2094
2095 This signal is emitted whenever the current color changes in the dialog.
2096 The current color is specified by \a color.
2097
2098 \sa color, colorSelected()
2099*/
2100
2101/*!
2102 \fn void QColorDialog::colorSelected(const QColor &color);
2103
2104 This signal is emitted just after the user has clicked \uicontrol{OK} to
2105 select a color to use. The chosen color is specified by \a color.
2106
2107 \sa color, currentColorChanged()
2108*/
2109
2110/*!
2111 Changes the visibility of the dialog. If \a visible is true, the dialog
2112 is shown; otherwise, it is hidden.
2113*/
2114void QColorDialog::setVisible(bool visible)
2115{
2116 // will call QColorDialogPrivate::setVisible override
2117 QDialog::setVisible(visible);
2118}
2119
2120/*!
2121 \internal
2122
2123 The implementation of QColorDialog::setVisible() has to live here so that the call
2124 to hide() in ~QDialog calls this function; it wouldn't call the override of
2125 QDialog::setVisible().
2126*/
2128{
2129 // Don't use Q_Q here! This function is called from ~QDialog,
2130 // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).
2131 const auto q = static_cast<QDialog *>(q_ptr);
2132
2133 if (visible)
2134 selectedQColor = QColor();
2135
2136 if (nativeDialogInUse) {
2137 if (setNativeDialogVisible(visible)) {
2138 // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
2139 // updates the state correctly, but skips showing the non-native version:
2140 q->setAttribute(Qt::WA_DontShowOnScreen);
2141 } else if (visible) {
2143 }
2144 } else {
2145 q->setAttribute(Qt::WA_DontShowOnScreen, false);
2146 }
2147
2148 QDialogPrivate::setVisible(visible);
2149}
2150
2151/*!
2152 Opens the dialog and connects its colorSelected() signal to the slot specified
2153 by \a receiver and \a member.
2154
2155 The signal will be disconnected from the slot when the dialog is closed.
2156*/
2157void QColorDialog::open(QObject *receiver, const char *member)
2158{
2159 Q_D(QColorDialog);
2160 connect(this, SIGNAL(colorSelected(QColor)), receiver, member);
2161 d->receiverToDisconnectOnClose = receiver;
2162 d->memberToDisconnectOnClose = member;
2163 QDialog::open();
2164}
2165
2166/*!
2167 Pops up a modal color dialog with the given window \a title (or "Select Color" if none is
2168 specified), lets the user choose a color, and returns that color. The color is initially set
2169 to \a initial. The dialog is a child of \a parent. It returns an invalid (see
2170 QColor::isValid()) color if the user cancels the dialog.
2171
2172 The \a options argument allows you to customize the dialog.
2173*/
2174QColor QColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title,
2175 ColorDialogOptions options)
2176{
2177 QAutoPointer<QColorDialog> dlg(new QColorDialog(parent));
2178 if (!title.isEmpty())
2179 dlg->setWindowTitle(title);
2180 dlg->setOptions(options);
2181 dlg->setCurrentColor(initial);
2182
2183 // If the dlg was deleted with a parent window,
2184 // dlg == nullptr after leaving the exec().
2185 dlg->exec();
2186 if (bool(dlg))
2187 return dlg->selectedColor();
2188 else
2189 return QColor();
2190}
2191
2192/*!
2193 Destroys the color dialog.
2194*/
2195
2196QColorDialog::~QColorDialog()
2197{
2198}
2199
2200/*!
2201 \reimp
2202*/
2203void QColorDialog::changeEvent(QEvent *e)
2204{
2205 Q_D(QColorDialog);
2206 if (e->type() == QEvent::LanguageChange)
2207 d->retranslateStrings();
2208 QDialog::changeEvent(e);
2209}
2210
2212{
2213#ifndef QT_NO_CURSOR
2214 Q_Q(QColorDialog);
2215 static QPoint lastGlobalPos;
2216 QPoint newGlobalPos = QCursor::pos();
2217 if (lastGlobalPos == newGlobalPos)
2218 return;
2219 lastGlobalPos = newGlobalPos;
2220
2221 if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called
2222 updateColorPicking(newGlobalPos);
2223#ifdef Q_OS_WIN32
2224 dummyTransparentWindow.setPosition(newGlobalPos);
2225#endif
2226 }
2227#endif // ! QT_NO_CURSOR
2228}
2229
2231{
2232 const QColor color = grabScreenColor(globalPos);
2233 // QTBUG-39792, do not change standard, custom color selectors while moving as
2234 // otherwise it is not possible to pre-select a custom cell for assignment.
2235 setCurrentColor(color, ShowColor);
2236 updateColorLabelText(globalPos);
2237}
2238
2240{
2241 // If the cross is visible the grabbed color will be black most of the times
2242 cp->setCrossVisible(!cp->geometry().contains(e->position().toPoint()));
2243
2244 updateColorPicking(e->globalPosition().toPoint());
2245 return true;
2246}
2247
2249{
2250 setCurrentColor(grabScreenColor(e->globalPosition().toPoint()), SetColorAll);
2252 return true;
2253}
2254
2256{
2257 Q_Q(QColorDialog);
2258#if QT_CONFIG(shortcut)
2259 if (e->matches(QKeySequence::Cancel)) {
2260 releaseColorPicking();
2261 q->setCurrentColor(beforeScreenColorPicking);
2262 } else
2263#endif
2264 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
2265 q->setCurrentColor(grabScreenColor(QCursor::pos()));
2267 }
2268 e->accept();
2269 return true;
2270}
2271
2272/*!
2273 Closes the dialog and sets its result code to \a result. If this dialog
2274 is shown with exec(), done() causes the local event loop to finish,
2275 and exec() to return \a result.
2276
2277 \sa QDialog::done()
2278*/
2279void QColorDialog::done(int result)
2280{
2281 Q_D(QColorDialog);
2282 if (result == Accepted) {
2283 d->selectedQColor = d->currentQColor();
2284 emit colorSelected(d->selectedQColor);
2285 } else {
2286 d->selectedQColor = QColor();
2287 }
2288 QDialog::done(result);
2289 if (d->receiverToDisconnectOnClose) {
2290 disconnect(this, SIGNAL(colorSelected(QColor)),
2291 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2292 d->receiverToDisconnectOnClose = nullptr;
2293 }
2294 d->memberToDisconnectOnClose.clear();
2295}
2296
2297QT_END_NAMESPACE
2298
2299#include "qcolordialog.moc"
2300#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