Qt 6.x
The Qt SDK
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
4#include "qcolordialog.h"
5
6#include "qapplication.h"
7#include "qdrawutil.h"
8#include "qevent.h"
9#include "qimage.h"
10#if QT_CONFIG(draganddrop)
11#include <qdrag.h>
12#endif
13#include "qlabel.h"
14#include "qlayout.h"
15#include "qlineedit.h"
16#if QT_CONFIG(menu)
17#include "qmenu.h"
18#endif
19#include "qpainter.h"
20#include "qpixmap.h"
21#include "qpushbutton.h"
22#if QT_CONFIG(regularexpression)
23#include <qregularexpression.h>
24#endif
25#if QT_CONFIG(settings)
26#include "qsettings.h"
27#endif
28#include "qsharedpointer.h"
29#include "qstyle.h"
30#include "qstyleoption.h"
31#include "qvalidator.h"
32#include "qmimedata.h"
33#include "qspinbox.h"
34#include "qdialogbuttonbox.h"
35#include "qscreen.h"
36#include "qcursor.h"
37#include "qtimer.h"
38#include "qwindow.h"
39
40#include "private/qdialog_p.h"
41
42#include <qpa/qplatformintegration.h>
43#include <qpa/qplatformservices.h>
44#include <private/qguiapplication_p.h>
45
46#include <algorithm>
47
49
50using namespace Qt::StringLiterals;
51
52namespace QtPrivate {
54class QColorPicker;
55class QColorShower;
56class QWellArray;
57class QColorWell;
59} // namespace QtPrivate
60
67
69{
70 Q_DECLARE_PUBLIC(QColorDialog)
71
72public:
74 ShowColor = 0x1,
77 };
78
79 QColorDialogPrivate() : options(QColorDialogOptions::create())
80#ifdef Q_OS_WIN32
81 , updateTimer(0)
82#endif
83 {}
84
86 { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); }
87
88 void init(const QColor &initial);
89 void initWidgets();
90 QRgb currentColor() const;
91 QColor currentQColor() const;
92 void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll);
94 void setCurrentQColor(const QColor &color);
95 bool selectColor(const QColor &color);
97
98 int currentAlpha() const;
99 void setCurrentAlpha(int a);
100 void showAlpha(bool b);
101 bool isAlphaVisible() const;
102 void retranslateStrings();
103 bool supportsColorPicking() const;
104
105 void _q_addCustom();
107
108 void _q_newHsv(int h, int s, int v);
110 void _q_nextCustom(int, int);
111 void _q_newCustom(int, int);
112 void _q_newStandard(int, int);
113 void _q_pickScreenColor();
115 void updateColorLabelText(const QPoint &);
116 void updateColorPicking(const QPoint &pos);
117 void releaseColorPicking();
121
122 bool canBeNativeDialog() const override;
123
126
146
149#ifdef Q_OS_WIN32
150 QTimer *updateTimer;
151 QWindow dummyTransparentWindow;
152#endif
153
154private:
155 virtual void initHelper(QPlatformDialogHelper *h) override;
156 virtual void helperPrepareShow(QPlatformDialogHelper *h) override;
157};
158
160
161namespace QtPrivate {
162
163class QWellArray : public QWidget
164{
168
169public:
170 QWellArray(int rows, int cols, QWidget* parent=nullptr);
172 QString cellContent(int row, int col) const;
173
174 int selectedColumn() const { return selCol; }
175 int selectedRow() const { return selRow; }
176
177 virtual void setCurrent(int row, int col);
178 virtual void setSelected(int row, int col);
179
180 QSize sizeHint() const override;
181
182 inline int cellWidth() const
183 { return cellw; }
184
185 inline int cellHeight() const
186 { return cellh; }
187
188 inline int rowAt(int y) const
189 { return y / cellh; }
190
191 inline int columnAt(int x) const
192 { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
193
194 inline int rowY(int row) const
195 { return cellh * row; }
196
197 inline int columnX(int column) const
198 { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
199
200 inline int numRows() const
201 { return nrows; }
202
203 inline int numCols() const
204 {return ncols; }
205
206 inline QRect cellRect() const
207 { return QRect(0, 0, cellw, cellh); }
208
209 inline QSize gridSize() const
210 { return QSize(ncols * cellw, nrows * cellh); }
211
213 {
214 QRect r;
215 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
216 r.setRect(columnX(column), rowY(row), cellw, cellh);
217 return r;
218 }
219
220 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
221
222signals:
223 void selected(int row, int col);
224 void currentChanged(int row, int col);
226
227protected:
228 virtual void paintCell(QPainter *, int row, int col, const QRect&);
229 virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
230
231 void mousePressEvent(QMouseEvent*) override;
232 void mouseReleaseEvent(QMouseEvent*) override;
233 void keyPressEvent(QKeyEvent*) override;
234 void focusInEvent(QFocusEvent*) override;
235 void focusOutEvent(QFocusEvent*) override;
236 void paintEvent(QPaintEvent *) override;
237
238private:
239 Q_DISABLE_COPY(QWellArray)
240
241 int nrows;
242 int ncols;
243 int cellw;
244 int cellh;
245 int curRow;
246 int curCol;
247 int selRow;
248 int selCol;
249};
250
252{
253 QRect r = e->rect();
254 int cx = r.x();
255 int cy = r.y();
256 int ch = r.height();
257 int cw = r.width();
258 int colfirst = columnAt(cx);
259 int collast = columnAt(cx + cw);
260 int rowfirst = rowAt(cy);
261 int rowlast = rowAt(cy + ch);
262
263 if (isRightToLeft()) {
264 int t = colfirst;
265 colfirst = collast;
266 collast = t;
267 }
268
269 QPainter painter(this);
270 QPainter *p = &painter;
271 QRect rect(0, 0, cellWidth(), cellHeight());
272
273
274 if (collast < 0 || collast >= ncols)
275 collast = ncols-1;
276 if (rowlast < 0 || rowlast >= nrows)
277 rowlast = nrows-1;
278
279 // Go through the rows
280 for (int r = rowfirst; r <= rowlast; ++r) {
281 // get row position and height
282 int rowp = rowY(r);
283
284 // Go through the columns in the row r
285 // if we know from where to where, go through [colfirst, collast],
286 // else go through all of them
287 for (int c = colfirst; c <= collast; ++c) {
288 // get position and width of column c
289 int colp = columnX(c);
290 // Translate painter and draw the cell
291 rect.translate(colp, rowp);
292 paintCell(p, r, c, rect);
293 rect.translate(-colp, -rowp);
294 }
295 }
296}
297
299 : QWidget(parent)
300 ,nrows(rows), ncols(cols)
301{
303 cellw = 28;
304 cellh = 24;
305 curCol = 0;
306 curRow = 0;
307 selCol = -1;
308 selRow = -1;
309}
310
312{
314 return gridSize().boundedTo(QSize(640, 480));
315}
316
317
318void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
319{
320 int b = 3; //margin
321
322 const QPalette & g = palette();
324 opt.initFrom(this);
326 opt.lineWidth = dfw;
327 opt.midLineWidth = 1;
328 opt.rect = rect.adjusted(b, b, -b, -b);
329 opt.palette = g;
332 b += dfw;
333
334 if ((row == curRow) && (col == curCol)) {
335 if (hasFocus()) {
337 opt.palette = g;
338 opt.rect = rect;
341 }
342 }
343 paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));
344}
345
346/*
347 Reimplement this function to change the contents of the well array.
348 */
349void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
350{
351 Q_UNUSED(row);
352 Q_UNUSED(col);
353 p->fillRect(r, Qt::white);
354 p->setPen(Qt::black);
355 p->drawLine(r.topLeft(), r.bottomRight());
356 p->drawLine(r.topRight(), r.bottomLeft());
357}
358
360{
361 // The current cell marker is set to the cell the mouse is pressed in
362 QPoint pos = e->position().toPoint();
364}
365
367{
368 // The current cell marker is set to the cell the mouse is clicked in
369 setSelected(curRow, curCol);
370}
371
372
373/*
374 Sets the cell currently having the focus. This is not necessarily
375 the same as the currently selected cell.
376*/
377
378void QWellArray::setCurrent(int row, int col)
379{
380 if ((curRow == row) && (curCol == col))
381 return;
382
383 if (row < 0 || col < 0)
384 row = col = -1;
385
386 int oldRow = curRow;
387 int oldCol = curCol;
388
389 curRow = row;
390 curCol = col;
391
392 updateCell(oldRow, oldCol);
393 updateCell(curRow, curCol);
394
395 emit currentChanged(curRow, curCol);
396}
397
398/*
399 Sets the currently selected cell to \a row, \a column. If \a row or
400 \a column are less than zero, the current cell is unselected.
401
402 Does not set the position of the focus indicator.
403*/
404void QWellArray::setSelected(int row, int col)
405{
406 int oldRow = selRow;
407 int oldCol = selCol;
408
409 if (row < 0 || col < 0)
410 row = col = -1;
411
412 selCol = col;
413 selRow = row;
414
415 updateCell(oldRow, oldCol);
416 updateCell(selRow, selCol);
417 if (row >= 0)
418 emit selected(row, col);
419
420#if QT_CONFIG(menu)
421 if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
422 parentWidget()->close();
423#endif
424}
425
427{
428 updateCell(curRow, curCol);
429 emit currentChanged(curRow, curCol);
430}
431
432
434{
435 updateCell(curRow, curCol);
436}
437
439{
440 switch(e->key()) { // Look at the key code
441 case Qt::Key_Left: // If 'left arrow'-key,
442 if (curCol > 0) // and cr't not in leftmost col
443 setCurrent(curRow, curCol - 1); // set cr't to next left column
444 break;
445 case Qt::Key_Right: // Correspondingly...
446 if (curCol < numCols()-1)
447 setCurrent(curRow, curCol + 1);
448 break;
449 case Qt::Key_Up:
450 if (curRow > 0)
451 setCurrent(curRow - 1, curCol);
452 break;
453 case Qt::Key_Down:
454 if (curRow < numRows()-1)
455 setCurrent(curRow + 1, curCol);
456 break;
457#if 0
458 // bad idea that shouldn't have been implemented; very counterintuitive
459 case Qt::Key_Return:
460 case Qt::Key_Enter:
461 /*
462 ignore the key, so that the dialog get it, but still select
463 the current row/col
464 */
465 e->ignore();
466 // fallthrough intended
467#endif
468 case Qt::Key_Space:
469 setSelected(curRow, curCol);
470 break;
471 default: // If not an interesting key,
472 e->ignore(); // we don't accept the event
473 return;
474 }
475
476} // namespace QtPrivate
477
479
480// Event filter to be installed on the dialog while in color-picking mode.
482public:
484
485 bool eventFilter(QObject *, QEvent *event) override
486 {
487 switch (event->type()) {
489 return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));
491 return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
492 case QEvent::KeyPress:
493 return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
494 default:
495 break;
496 }
497 return false;
498 }
499
500private:
502};
503
504} // unnamed namespace
505
511{
512 return QColorDialogOptions::customColorCount();
513}
514
521{
522 return QColor(QColorDialogOptions::customColor(index));
523}
524
533{
534 QColorDialogOptions::setCustomColor(index, color.rgba());
535}
536
543{
544 return QColor(QColorDialogOptions::standardColor(index));
545}
546
555{
556 QColorDialogOptions::setStandardColor(index, color.rgba());
557}
558
559static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
560{
561 QColor c;
562 c.setRgb(rgb);
563 c.getHsv(&h, &s, &v);
564}
565
566namespace QtPrivate {
567
568class QColorWell : public QWellArray
569{
570public:
571 QColorWell(QWidget *parent, int r, int c, const QRgb *vals)
572 :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1)
574
575protected:
576 void paintCellContents(QPainter *, int row, int col, const QRect&) override;
577 void mousePressEvent(QMouseEvent *e) override;
578 void mouseMoveEvent(QMouseEvent *e) override;
579 void mouseReleaseEvent(QMouseEvent *e) override;
580#if QT_CONFIG(draganddrop)
581 void dragEnterEvent(QDragEnterEvent *e) override;
582 void dragLeaveEvent(QDragLeaveEvent *e) override;
583 void dragMoveEvent(QDragMoveEvent *e) override;
584 void dropEvent(QDropEvent *e) override;
585#endif
586
587private:
588 const QRgb *values;
589 bool mousePressed;
590 QPoint pressPos;
591 QPoint oldCurrent;
592
593};
594
595void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)
596{
597 int i = row + col*numRows();
598 p->fillRect(r, QColor(values[i]));
599}
600
602{
603 oldCurrent = QPoint(selectedRow(), selectedColumn());
605 mousePressed = true;
606 pressPos = e->position().toPoint();
607}
608
610{
612#if QT_CONFIG(draganddrop)
613 if (!mousePressed)
614 return;
615 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
616 setCurrent(oldCurrent.x(), oldCurrent.y());
617 int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows();
618 QColor col(values[i]);
619 QMimeData *mime = new QMimeData;
620 mime->setColorData(col);
622 pix.fill(col);
623 QPainter p(&pix);
624 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
625 p.end();
626 QDrag *drg = new QDrag(this);
627 drg->setMimeData(mime);
628 drg->setPixmap(pix);
629 mousePressed = false;
630 drg->exec(Qt::CopyAction);
631 }
632#endif
633}
634
635#if QT_CONFIG(draganddrop)
636void QColorWell::dragEnterEvent(QDragEnterEvent *e)
637{
638 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
639 e->accept();
640 else
641 e->ignore();
642}
643
644void QColorWell::dragLeaveEvent(QDragLeaveEvent *)
645{
646 if (hasFocus())
648}
649
650void QColorWell::dragMoveEvent(QDragMoveEvent *e)
651{
652 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) {
653 setCurrent(rowAt(e->position().toPoint().y()), columnAt(e->position().toPoint().x()));
654 e->accept();
655 } else {
656 e->ignore();
657 }
658}
659
660void QColorWell::dropEvent(QDropEvent *e)
661{
662 QColor col = qvariant_cast<QColor>(e->mimeData()->colorData());
663 if (col.isValid()) {
664 int i = rowAt(e->position().toPoint().y()) + columnAt(e->position().toPoint().x()) * numRows();
665 emit colorChanged(i, col.rgb());
666 e->accept();
667 } else {
668 e->ignore();
669 }
670}
671
672#endif // QT_CONFIG(draganddrop)
673
675{
676 if (!mousePressed)
677 return;
679 mousePressed = false;
680}
681
682class QColorPicker : public QFrame
683{
685public:
688
689 void setCrossVisible(bool visible);
690public slots:
691 void setCol(int h, int s);
692
693signals:
694 void newCol(int h, int s);
695
696protected:
697 QSize sizeHint() const override;
698 void paintEvent(QPaintEvent*) override;
699 void mouseMoveEvent(QMouseEvent *) override;
700 void mousePressEvent(QMouseEvent *) override;
701 void resizeEvent(QResizeEvent *) override;
702
703private:
704 int hue;
705 int sat;
706
707 QPoint colPt();
708 int huePt(const QPoint &pt);
709 int satPt(const QPoint &pt);
710 void setCol(const QPoint &pt);
711
712 QPixmap pix;
713 bool crossVisible;
714};
715
716} // namespace QtPrivate
717
718static int pWidth = 220;
719static int pHeight = 200;
720
721namespace QtPrivate {
722
724{
726public:
729
730public slots:
731 void setCol(int h, int s, int v);
732 void setCol(int h, int s);
733
734signals:
735 void newHsv(int h, int s, int v);
736
737protected:
738 void paintEvent(QPaintEvent*) override;
739 void mouseMoveEvent(QMouseEvent *) override;
740 void mousePressEvent(QMouseEvent *) override;
741
742private:
743 enum { foff = 3, coff = 4 }; //frame and contents offset
744 int val;
745 int hue;
746 int sat;
747
748 int y2val(int y);
749 int val2y(int val);
750 void setVal(int v);
751
752 QPixmap *pix;
753};
754
755
756int QColorLuminancePicker::y2val(int y)
757{
758 int d = height() - 2*coff - 1;
759 return 255 - (y - coff)*255/d;
760}
761
762int QColorLuminancePicker::val2y(int v)
763{
764 int d = height() - 2*coff - 1;
765 return coff + (255-v)*d/255;
766}
767
770{
771 hue = 100; val = 100; sat = 100;
772 pix = nullptr;
773 // setAttribute(WA_NoErase, true);
774}
775
777{
778 delete pix;
779}
780
782{
783 setVal(y2val(m->position().toPoint().y()));
784}
786{
787 setVal(y2val(m->position().toPoint().y()));
788}
789
790void QColorLuminancePicker::setVal(int v)
791{
792 if (val == v)
793 return;
794 val = qMax(0, qMin(v,255));
795 delete pix; pix=nullptr;
796 repaint();
797 emit newHsv(hue, sat, val);
798}
799
800//receives from a hue,sat chooser and relays.
802{
803 setCol(h, s, val);
804 emit newHsv(h, s, val);
805}
806
808{
809 int w = width() - 5;
810
811 QRect r(0, foff, w, height() - 2*foff);
812 int wi = r.width() - 2;
813 int hi = r.height() - 2;
814 if (!pix || pix->height() != hi || pix->width() != wi) {
815 delete pix;
817 int y;
818 uint *pixel = (uint *) img.scanLine(0);
819 for (y = 0; y < hi; y++) {
820 uint *end = pixel + wi;
821 std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb());
822 pixel = end;
823 }
824 pix = new QPixmap(QPixmap::fromImage(img));
825 }
826 QPainter p(this);
827 p.drawPixmap(1, coff, *pix);
828 const QPalette &g = palette();
829 qDrawShadePanel(&p, r, g, true);
830 p.setPen(g.windowText().color());
831 p.setBrush(g.windowText());
832 QPolygon a;
833 int y = val2y(val);
834 a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
835 p.eraseRect(w, 0, 5, height());
836 p.drawPolygon(a);
837}
838
839void QColorLuminancePicker::setCol(int h, int s , int v)
840{
841 val = v;
842 hue = h;
843 sat = s;
844 delete pix; pix=nullptr;
845 repaint();
846}
847
848QPoint QColorPicker::colPt()
849{
850 QRect r = contentsRect();
851 return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
852}
853
854int QColorPicker::huePt(const QPoint &pt)
855{
856 QRect r = contentsRect();
857 return 360 - pt.x() * 360 / (r.width() - 1);
858}
859
860int QColorPicker::satPt(const QPoint &pt)
861{
862 QRect r = contentsRect();
863 return 255 - pt.y() * 255 / (r.height() - 1);
864}
865
866void QColorPicker::setCol(const QPoint &pt)
867{
868 setCol(huePt(pt), satPt(pt));
869}
870
872 : QFrame(parent)
873 , crossVisible(true)
874{
875 hue = 0; sat = 0;
876 setCol(150, 255);
877
880}
881
883{
884}
885
887{
888 if (crossVisible != visible) {
889 crossVisible = visible;
890 update();
891 }
892}
893
895{
896 return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
897}
898
900{
901 int nhue = qMin(qMax(0,h), 359);
902 int nsat = qMin(qMax(0,s), 255);
903 if (nhue == hue && nsat == sat)
904 return;
905
906 QRect r(colPt(), QSize(20,20));
907 hue = nhue; sat = nsat;
908 r = r.united(QRect(colPt(), QSize(20,20)));
909 r.translate(contentsRect().x()-9, contentsRect().y()-9);
910 // update(r);
911 repaint(r);
912}
913
915{
916 QPoint p = m->position().toPoint() - contentsRect().topLeft();
917 setCol(p);
918 emit newCol(hue, sat);
919}
920
922{
923 QPoint p = m->position().toPoint() - contentsRect().topLeft();
924 setCol(p);
925 emit newCol(hue, sat);
926}
927
929{
930 QPainter p(this);
931 drawFrame(&p);
932 QRect r = contentsRect();
933
934 p.drawPixmap(r.topLeft(), pix);
935
936 if (crossVisible) {
937 QPoint pt = colPt() + r.topLeft();
938 p.setPen(Qt::black);
939 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
940 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
941 }
942}
943
945{
947
948 int w = width() - frameWidth() * 2;
949 int h = height() - frameWidth() * 2;
951 int x, y;
952 uint *pixel = (uint *) img.scanLine(0);
953 for (y = 0; y < h; y++) {
954 const uint *end = pixel + w;
955 x = 0;
956 while (pixel < end) {
957 QPoint p(x, y);
958 QColor c;
959 c.setHsv(huePt(p), satPt(p), 200);
960 *pixel = c.rgb();
961 ++pixel;
962 ++x;
963 }
964 }
965 pix = QPixmap::fromImage(img);
966}
967
968
969class QColSpinBox : public QSpinBox
970{
971public:
973 : QSpinBox(parent) { setRange(0, 255); }
974 void setValue(int i) {
975 const QSignalBlocker blocker(this);
977 }
978};
979
980class QColorShowLabel;
981
982class QColorShower : public QWidget
983{
985public:
987
988 //things that don't emit signals
989 void setHsv(int h, int s, int v);
990
991 int currentAlpha() const
992 { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }
993 void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); }
994 void showAlpha(bool b);
995 bool isAlphaVisible() const;
996
997 QRgb currentColor() const { return curCol; }
998 QColor currentQColor() const { return curQColor; }
999 void retranslateStrings();
1000 void updateQColor();
1001
1002public slots:
1003 void setRgb(QRgb rgb);
1004
1005signals:
1008
1009private slots:
1010 void rgbEd();
1011 void hsvEd();
1012 void htmlEd();
1013
1014private:
1015 void showCurrentColor();
1016 int hue, sat, val;
1017 QRgb curCol;
1018 QColor curQColor;
1019 QLabel *lblHue;
1020 QLabel *lblSat;
1021 QLabel *lblVal;
1022 QLabel *lblRed;
1023 QLabel *lblGreen;
1024 QLabel *lblBlue;
1025 QLabel *lblHtml;
1026 QColSpinBox *hEd;
1027 QColSpinBox *sEd;
1028 QColSpinBox *vEd;
1029 QColSpinBox *rEd;
1030 QColSpinBox *gEd;
1031 QColSpinBox *bEd;
1032 QColSpinBox *alphaEd;
1033 QLabel *alphaLab;
1034 QLineEdit *htEd;
1035 QColorShowLabel *lab;
1036 bool rgbOriginal;
1037 QColorDialog *colorDialog;
1038 QGridLayout *gl;
1039
1040 friend class QT_PREPEND_NAMESPACE(QColorDialog);
1041 friend class QT_PREPEND_NAMESPACE(QColorDialogPrivate);
1042};
1043
1045{
1046 Q_OBJECT
1047
1048public:
1051 setAcceptDrops(true);
1052 mousePressed = false;
1053 }
1054 void setColor(QColor c) { col = c; }
1055
1056signals:
1058
1059protected:
1060 void paintEvent(QPaintEvent *) override;
1061 void mousePressEvent(QMouseEvent *e) override;
1062 void mouseMoveEvent(QMouseEvent *e) override;
1063 void mouseReleaseEvent(QMouseEvent *e) override;
1064#if QT_CONFIG(draganddrop)
1065 void dragEnterEvent(QDragEnterEvent *e) override;
1066 void dragLeaveEvent(QDragLeaveEvent *e) override;
1067 void dropEvent(QDropEvent *e) override;
1068#endif
1069
1070private:
1071 QColor col;
1072 bool mousePressed;
1073 QPoint pressPos;
1074};
1075
1076void QColorShowLabel::paintEvent(QPaintEvent *e)
1077{
1078 QPainter p(this);
1079 drawFrame(&p);
1080 p.fillRect(contentsRect()&e->rect(), col);
1081}
1082
1084{
1085 alphaLab->setVisible(b);
1086 alphaEd->setVisible(b);
1087}
1088
1090{
1091 return alphaLab->isVisible();
1092}
1093
1094void QColorShowLabel::mousePressEvent(QMouseEvent *e)
1095{
1096 mousePressed = true;
1097 pressPos = e->position().toPoint();
1098}
1099
1100void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)
1101{
1102#if !QT_CONFIG(draganddrop)
1103 Q_UNUSED(e);
1104#else
1105 if (!mousePressed)
1106 return;
1107 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
1108 QMimeData *mime = new QMimeData;
1109 mime->setColorData(col);
1110 QPixmap pix(30, 20);
1111 pix.fill(col);
1112 QPainter p(&pix);
1113 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
1114 p.end();
1115 QDrag *drg = new QDrag(this);
1116 drg->setMimeData(mime);
1117 drg->setPixmap(pix);
1118 mousePressed = false;
1119 drg->exec(Qt::CopyAction);
1120 }
1121#endif
1122}
1123
1124#if QT_CONFIG(draganddrop)
1125void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e)
1126{
1127 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
1128 e->accept();
1129 else
1130 e->ignore();
1131}
1132
1133void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *)
1134{
1135}
1136
1137void QColorShowLabel::dropEvent(QDropEvent *e)
1138{
1139 QColor color = qvariant_cast<QColor>(e->mimeData()->colorData());
1140 if (color.isValid()) {
1141 col = color;
1142 repaint();
1143 emit colorDropped(col.rgb());
1144 e->accept();
1145 } else {
1146 e->ignore();
1147 }
1148}
1149#endif // QT_CONFIG(draganddrop)
1150
1151void QColorShowLabel::mouseReleaseEvent(QMouseEvent *)
1152{
1153 if (!mousePressed)
1154 return;
1155 mousePressed = false;
1156}
1157
1159 : QWidget(parent)
1160{
1161 colorDialog = parent;
1162
1163 curCol = qRgb(255, 255, 255);
1164 curQColor = Qt::white;
1165
1166 gl = new QGridLayout(this);
1167 const int s = gl->spacing();
1168 gl->setContentsMargins(s, s, s, s);
1169 lab = new QColorShowLabel(this);
1170
1171#ifdef QT_SMALL_COLORDIALOG
1172 lab->setMinimumHeight(60);
1173#endif
1174 lab->setMinimumWidth(60);
1175
1176// For QVGA screens only the comboboxes and color label are visible.
1177// For nHD screens only color and luminence pickers and color label are visible.
1178#if !defined(QT_SMALL_COLORDIALOG)
1179 gl->addWidget(lab, 0, 0, -1, 1);
1180#else
1181 gl->addWidget(lab, 0, 0, 1, -1);
1182#endif
1185
1186 hEd = new QColSpinBox(this);
1187 hEd->setRange(0, 359);
1188 lblHue = new QLabel(this);
1189#ifndef QT_NO_SHORTCUT
1190 lblHue->setBuddy(hEd);
1191#endif
1193#if !defined(QT_SMALL_COLORDIALOG)
1194 gl->addWidget(lblHue, 0, 1);
1195 gl->addWidget(hEd, 0, 2);
1196#else
1197 gl->addWidget(lblHue, 1, 0);
1198 gl->addWidget(hEd, 2, 0);
1199#endif
1200
1201 sEd = new QColSpinBox(this);
1202 lblSat = new QLabel(this);
1203#ifndef QT_NO_SHORTCUT
1204 lblSat->setBuddy(sEd);
1205#endif
1207#if !defined(QT_SMALL_COLORDIALOG)
1208 gl->addWidget(lblSat, 1, 1);
1209 gl->addWidget(sEd, 1, 2);
1210#else
1211 gl->addWidget(lblSat, 1, 1);
1212 gl->addWidget(sEd, 2, 1);
1213#endif
1214
1215 vEd = new QColSpinBox(this);
1216 lblVal = new QLabel(this);
1217#ifndef QT_NO_SHORTCUT
1218 lblVal->setBuddy(vEd);
1219#endif
1221#if !defined(QT_SMALL_COLORDIALOG)
1222 gl->addWidget(lblVal, 2, 1);
1223 gl->addWidget(vEd, 2, 2);
1224#else
1225 gl->addWidget(lblVal, 1, 2);
1226 gl->addWidget(vEd, 2, 2);
1227#endif
1228
1229 rEd = new QColSpinBox(this);
1230 lblRed = new QLabel(this);
1231#ifndef QT_NO_SHORTCUT
1232 lblRed->setBuddy(rEd);
1233#endif
1235#if !defined(QT_SMALL_COLORDIALOG)
1236 gl->addWidget(lblRed, 0, 3);
1237 gl->addWidget(rEd, 0, 4);
1238#else
1239 gl->addWidget(lblRed, 3, 0);
1240 gl->addWidget(rEd, 4, 0);
1241#endif
1242
1243 gEd = new QColSpinBox(this);
1244 lblGreen = new QLabel(this);
1245#ifndef QT_NO_SHORTCUT
1246 lblGreen->setBuddy(gEd);
1247#endif
1249#if !defined(QT_SMALL_COLORDIALOG)
1250 gl->addWidget(lblGreen, 1, 3);
1251 gl->addWidget(gEd, 1, 4);
1252#else
1253 gl->addWidget(lblGreen, 3, 1);
1254 gl->addWidget(gEd, 4, 1);
1255#endif
1256
1257 bEd = new QColSpinBox(this);
1258 lblBlue = new QLabel(this);
1259#ifndef QT_NO_SHORTCUT
1260 lblBlue->setBuddy(bEd);
1261#endif
1263#if !defined(QT_SMALL_COLORDIALOG)
1264 gl->addWidget(lblBlue, 2, 3);
1265 gl->addWidget(bEd, 2, 4);
1266#else
1267 gl->addWidget(lblBlue, 3, 2);
1268 gl->addWidget(bEd, 4, 2);
1269#endif
1270
1271 alphaEd = new QColSpinBox(this);
1272 alphaLab = new QLabel(this);
1273#ifndef QT_NO_SHORTCUT
1274 alphaLab->setBuddy(alphaEd);
1275#endif
1277#if !defined(QT_SMALL_COLORDIALOG)
1278 gl->addWidget(alphaLab, 3, 1, 1, 3);
1279 gl->addWidget(alphaEd, 3, 4);
1280#else
1281 gl->addWidget(alphaLab, 1, 3, 3, 1);
1282 gl->addWidget(alphaEd, 4, 3);
1283#endif
1284 alphaEd->hide();
1285 alphaLab->hide();
1286 lblHtml = new QLabel(this);
1287 htEd = new QLineEdit(this);
1288 htEd->setObjectName("qt_colorname_lineedit");
1289#ifndef QT_NO_SHORTCUT
1290 lblHtml->setBuddy(htEd);
1291#endif
1292
1293#if QT_CONFIG(regularexpression)
1294 QRegularExpression regExp(QStringLiteral("#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));
1295 QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
1296 htEd->setValidator(validator);
1297#else
1298 htEd->setReadOnly(true);
1299#endif
1301
1303#if defined(QT_SMALL_COLORDIALOG)
1304 gl->addWidget(lblHtml, 5, 0);
1305 gl->addWidget(htEd, 5, 1, 1, /*colspan=*/ 2);
1306#else
1307 gl->addWidget(lblHtml, 5, 1);
1308 gl->addWidget(htEd, 5, 2, 1, /*colspan=*/ 3);
1309#endif
1310
1311 connect(hEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1312 connect(sEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1313 connect(vEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1314
1315 connect(rEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1316 connect(gEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1317 connect(bEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1318 connect(alphaEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1319 connect(htEd, &QLineEdit::textChanged, this, &QColorShower::htmlEd);
1320
1322}
1323
1324} // namespace QtPrivate
1325
1327inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); }
1331
1333{
1336 return cs->currentQColor();
1337}
1338
1339void QColorShower::showCurrentColor()
1340{
1341 lab->setColor(currentColor());
1342 lab->repaint();
1343}
1344
1345void QColorShower::rgbEd()
1346{
1347 rgbOriginal = true;
1348 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1349
1350 rgb2hsv(currentColor(), hue, sat, val);
1351
1352 hEd->setValue(hue);
1353 sEd->setValue(sat);
1354 vEd->setValue(val);
1355
1356 htEd->setText(QColor(curCol).name());
1357
1358 showCurrentColor();
1360 updateQColor();
1361}
1362
1363void QColorShower::hsvEd()
1364{
1365 rgbOriginal = false;
1366 hue = hEd->value();
1367 sat = sEd->value();
1368 val = vEd->value();
1369
1370 QColor c;
1371 c.setHsv(hue, sat, val);
1372 curCol = c.rgb();
1373
1374 rEd->setValue(qRed(currentColor()));
1375 gEd->setValue(qGreen(currentColor()));
1376 bEd->setValue(qBlue(currentColor()));
1377
1378 htEd->setText(c.name());
1379
1380 showCurrentColor();
1382 updateQColor();
1383}
1384
1385void QColorShower::htmlEd()
1386{
1387 QString t = htEd->text();
1388 if (t.isEmpty())
1389 return;
1390
1391 if (!t.startsWith(QStringLiteral("#"))) {
1392 t = QStringLiteral("#") + t;
1393 QSignalBlocker blocker(htEd);
1394 htEd->setText(t);
1395 }
1396
1398 if (!c.isValid())
1399 return;
1400
1401 curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());
1402 rgb2hsv(curCol, hue, sat, val);
1403
1404 hEd->setValue(hue);
1405 sEd->setValue(sat);
1406 vEd->setValue(val);
1407
1408 rEd->setValue(qRed(currentColor()));
1409 gEd->setValue(qGreen(currentColor()));
1410 bEd->setValue(qBlue(currentColor()));
1411
1412 showCurrentColor();
1414 updateQColor();
1415}
1416
1418{
1419 rgbOriginal = true;
1420 curCol = rgb;
1421
1422 rgb2hsv(currentColor(), hue, sat, val);
1423
1424 hEd->setValue(hue);
1425 sEd->setValue(sat);
1426 vEd->setValue(val);
1427
1428 rEd->setValue(qRed(currentColor()));
1429 gEd->setValue(qGreen(currentColor()));
1430 bEd->setValue(qBlue(currentColor()));
1431
1432 htEd->setText(QColor(rgb).name());
1433
1434 showCurrentColor();
1435 updateQColor();
1436}
1437
1438void QColorShower::setHsv(int h, int s, int v)
1439{
1440 if (h < -1 || (uint)s > 255 || (uint)v > 255)
1441 return;
1442
1443 rgbOriginal = false;
1444 hue = h; val = v; sat = s;
1445 QColor c;
1446 c.setHsv(hue, sat, val);
1447 curCol = c.rgb();
1448
1449 hEd->setValue(hue);
1450 sEd->setValue(sat);
1451 vEd->setValue(val);
1452
1453 rEd->setValue(qRed(currentColor()));
1454 gEd->setValue(qGreen(currentColor()));
1455 bEd->setValue(qBlue(currentColor()));
1456
1457 htEd->setText(c.name());
1458
1459 showCurrentColor();
1460 updateQColor();
1461}
1462
1464{
1465 lblHue->setText(QColorDialog::tr("Hu&e:"));
1466 lblSat->setText(QColorDialog::tr("&Sat:"));
1467 lblVal->setText(QColorDialog::tr("&Val:"));
1468 lblRed->setText(QColorDialog::tr("&Red:"));
1469 lblGreen->setText(QColorDialog::tr("&Green:"));
1470 lblBlue->setText(QColorDialog::tr("Bl&ue:"));
1471 alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
1472 lblHtml->setText(QColorDialog::tr("&HTML:"));
1473}
1474
1476{
1477 QColor oldQColor(curQColor);
1478 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1479 if (curQColor != oldQColor)
1480 emit currentColorChanged(curQColor);
1481}
1482
1483//sets all widgets to display h,s,v
1485{
1486 if (!nativeDialogInUse) {
1487 cs->setHsv(h, s, v);
1488 cp->setCol(h, s);
1489 lp->setCol(h, s, v);
1490 }
1491}
1492
1493//sets all widgets to display rgb
1495{
1496 if (!nativeDialogInUse) {
1497 cs->setRgb(rgb);
1498 _q_newColorTypedIn(rgb);
1499 }
1500}
1501
1502// hack; doesn't keep curCol in sync, so use with care
1504{
1505 Q_Q(QColorDialog);
1506 if (cs->curQColor != color) {
1507 cs->curQColor = color;
1508 emit q->currentColorChanged(color);
1509 }
1510}
1511
1512// size of standard and custom color selector
1513enum {
1516 customColorRows = 2
1518
1520{
1521 QRgb color = col.rgb();
1522 // Check standard colors
1523 if (standard) {
1524 const QRgb *standardColors = QColorDialogOptions::standardColors();
1525 const QRgb *standardColorsEnd = standardColors + standardColorRows * colorColumns;
1526 const QRgb *match = std::find(standardColors, standardColorsEnd, color);
1527 if (match != standardColorsEnd) {
1528 const int index = int(match - standardColors);
1529 const int column = index / standardColorRows;
1530 const int row = index % standardColorRows;
1531 _q_newStandard(row, column);
1532 standard->setCurrent(row, column);
1533 standard->setSelected(row, column);
1534 standard->setFocus();
1535 return true;
1536 }
1537 }
1538 // Check custom colors
1539 if (custom) {
1540 const QRgb *customColors = QColorDialogOptions::customColors();
1541 const QRgb *customColorsEnd = customColors + customColorRows * colorColumns;
1542 const QRgb *match = std::find(customColors, customColorsEnd, color);
1543 if (match != customColorsEnd) {
1544 const int index = int(match - customColors);
1545 const int column = index / customColorRows;
1546 const int row = index % customColorRows;
1547 _q_newCustom(row, column);
1548 custom->setCurrent(row, column);
1549 custom->setSelected(row, column);
1550 custom->setFocus();
1551 return true;
1552 }
1553 }
1554 return false;
1555}
1556
1558{
1560 if (!screen)
1562 const QRect screenRect = screen->geometry();
1563 const QPixmap pixmap =
1564 screen->grabWindow(0, p.x() - screenRect.x(), p.y() - screenRect.y(), 1, 1);
1565 const QImage i = pixmap.toImage();
1566 return i.pixel(0, 0);
1567}
1568
1569//sets all widgets except cs to display rgb
1571{
1572 if (!nativeDialogInUse) {
1573 int h, s, v;
1574 rgb2hsv(rgb, h, s, v);
1575 cp->setCol(h, s);
1576 lp->setCol(h, s, v);
1577 }
1578}
1579
1581{
1582 nextCust = r + customColorRows * c;
1583}
1584
1586{
1587 const int i = r + customColorRows * c;
1588 setCurrentRgbColor(QColorDialogOptions::customColor(i));
1589 if (standard)
1590 standard->setSelected(-1,-1);
1591}
1592
1594{
1595 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));
1596 if (custom)
1597 custom->setSelected(-1,-1);
1598}
1599
1601{
1602 Q_Q(QColorDialog);
1603
1604 auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
1605 if (platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) {
1606 if (auto *colorPicker = platformServices->colorPicker(q->windowHandle())) {
1607 q->connect(colorPicker, &QPlatformServiceColorPicker::colorPicked, q,
1608 [q, colorPicker](const QColor &color) {
1609 colorPicker->deleteLater();
1610 q->setCurrentColor(color);
1611 });
1612 colorPicker->pickColor();
1613 return;
1614 }
1615 }
1616
1617 if (!colorPickingEventFilter)
1618 colorPickingEventFilter = new QColorPickingEventFilter(this, q);
1619 q->installEventFilter(colorPickingEventFilter);
1620 // If user pushes Escape, the last color before picking will be restored.
1621 beforeScreenColorPicking = cs->currentColor();
1622#ifndef QT_NO_CURSOR
1623 q->grabMouse(Qt::CrossCursor);
1624#else
1625 q->grabMouse();
1626#endif
1627
1628#ifdef Q_OS_WIN32
1629 // On Windows mouse tracking doesn't work over other processes's windows
1630 updateTimer->start(30);
1631
1632 // HACK: Because mouse grabbing doesn't work across processes, we have to have a dummy,
1633 // invisible window to catch the mouse click, otherwise we will click whatever we clicked
1634 // and loose focus.
1635 dummyTransparentWindow.show();
1636#endif
1637 q->grabKeyboard();
1638 /* With setMouseTracking(true) the desired color can be more precisely picked up,
1639 * and continuously pushing the mouse button is not necessary.
1640 */
1641 q->setMouseTracking(true);
1642
1643 addCusBt->setDisabled(true);
1644 buttons->setDisabled(true);
1645 if (eyeDropperButton) {
1646 eyeDropperButton->setDisabled(true);
1647 const QPoint globalPos = QCursor::pos();
1648 q->setCurrentColor(grabScreenColor(globalPos));
1649 updateColorLabelText(globalPos);
1650 }
1651}
1652
1654{
1655 if (lblScreenColorInfo)
1656 lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")
1657 .arg(globalPos.x())
1658 .arg(globalPos.y()));
1659}
1660
1662{
1663 Q_Q(QColorDialog);
1664 cp->setCrossVisible(true);
1665 q->removeEventFilter(colorPickingEventFilter);
1666 q->releaseMouse();
1667#ifdef Q_OS_WIN32
1668 updateTimer->stop();
1669 dummyTransparentWindow.setVisible(false);
1670#endif
1671 q->releaseKeyboard();
1672 q->setMouseTracking(false);
1673 lblScreenColorInfo->setText("\n"_L1);
1674 addCusBt->setDisabled(false);
1675 buttons->setDisabled(false);
1676 eyeDropperButton->setDisabled(false);
1677}
1678
1680{
1681 Q_Q(QColorDialog);
1682
1683 q->setSizeGripEnabled(false);
1684 q->setWindowTitle(QColorDialog::tr("Select Color"));
1685
1686 // default: use the native dialog if possible. Can be overridden in setOptions()
1687 nativeDialogInUse = (platformColorDialogHelper() != nullptr);
1688 colorPickingEventFilter = nullptr;
1689 nextCust = 0;
1690
1691 if (!nativeDialogInUse)
1692 initWidgets();
1693
1694#ifdef Q_OS_WIN32
1695 dummyTransparentWindow.resize(1, 1);
1696 dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);
1697#endif
1698
1699 q->setCurrentColor(initial);
1700}
1701
1703{
1704 Q_Q(QColorDialog);
1705 QVBoxLayout *mainLay = new QVBoxLayout(q);
1706 // there's nothing in this dialog that benefits from sizing up
1708
1709 QHBoxLayout *topLay = new QHBoxLayout();
1710 mainLay->addLayout(topLay);
1711
1712 leftLay = nullptr;
1713
1714#if defined(QT_SMALL_COLORDIALOG)
1715 smallDisplay = true;
1716 const int lumSpace = 20;
1717#else
1718 // small displays (e.g. PDAs) cannot fit the full color dialog,
1719 // so just use the color picker.
1721 const int lumSpace = topLay->spacing() / 2;
1722#endif
1723
1724 if (!smallDisplay) {
1725 leftLay = new QVBoxLayout;
1726 topLay->addLayout(leftLay);
1727
1728 standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());
1729 lblBasicColors = new QLabel(q);
1730#ifndef QT_NO_SHORTCUT
1731 lblBasicColors->setBuddy(standard);
1732#endif
1733 q->connect(standard, SIGNAL(selected(int,int)), SLOT(_q_newStandard(int,int)));
1734 leftLay->addWidget(lblBasicColors);
1735 leftLay->addWidget(standard);
1736
1737#if !defined(QT_SMALL_COLORDIALOG)
1738 if (supportsColorPicking()) {
1739 eyeDropperButton = new QPushButton();
1740 leftLay->addWidget(eyeDropperButton);
1741 lblScreenColorInfo = new QLabel("\n"_L1);
1742 leftLay->addWidget(lblScreenColorInfo);
1743 q->connect(eyeDropperButton, SIGNAL(clicked()), SLOT(_q_pickScreenColor()));
1744 } else {
1745 eyeDropperButton = nullptr;
1746 lblScreenColorInfo = nullptr;
1747 }
1748#endif
1749
1750 leftLay->addStretch();
1751
1752 custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors());
1753 custom->setAcceptDrops(true);
1754
1755 q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int)));
1756 q->connect(custom, SIGNAL(currentChanged(int,int)), SLOT(_q_nextCustom(int,int)));
1757
1758 q->connect(custom, &QWellArray::colorChanged, q, [this] (int index, QRgb color) {
1759 QColorDialogOptions::setCustomColor(index, color);
1760 if (custom)
1761 custom->update();
1762 });
1763
1764 lblCustomColors = new QLabel(q);
1765#ifndef QT_NO_SHORTCUT
1766 lblCustomColors->setBuddy(custom);
1767#endif
1768 leftLay->addWidget(lblCustomColors);
1769 leftLay->addWidget(custom);
1770
1771 addCusBt = new QPushButton(q);
1772 QObject::connect(addCusBt, SIGNAL(clicked()), q, SLOT(_q_addCustom()));
1773 leftLay->addWidget(addCusBt);
1774 } else {
1775 // better color picker size for small displays
1776#if defined(QT_SMALL_COLORDIALOG)
1778 pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
1779 pHeight -= 20;
1780 if (screenSize.height() > screenSize.width())
1781 pWidth -= 20;
1782#else
1783 pWidth = 150;
1784 pHeight = 100;
1785#endif
1786 custom = nullptr;
1787 standard = nullptr;
1788 }
1789
1790 QVBoxLayout *rightLay = new QVBoxLayout;
1791 topLay->addLayout(rightLay);
1792
1793 QHBoxLayout *pickLay = new QHBoxLayout;
1794 rightLay->addLayout(pickLay);
1795
1796 QVBoxLayout *cLay = new QVBoxLayout;
1797 pickLay->addLayout(cLay);
1798 cp = new QColorPicker(q);
1799
1800 cp->setFrameStyle(QFrame::Panel | QFrame::Sunken);
1801
1802#if defined(QT_SMALL_COLORDIALOG)
1803 cp->hide();
1804#else
1805 cLay->addSpacing(lumSpace);
1806 cLay->addWidget(cp);
1807#endif
1808 cLay->addSpacing(lumSpace);
1809
1810 lp = new QColorLuminancePicker(q);
1811#if defined(QT_SMALL_COLORDIALOG)
1812 lp->hide();
1813#else
1814 lp->setFixedWidth(20);
1815 pickLay->addSpacing(10);
1816 pickLay->addWidget(lp);
1817 pickLay->addStretch();
1818#endif
1819
1820 QObject::connect(cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)));
1821 QObject::connect(lp, SIGNAL(newHsv(int,int,int)), q, SLOT(_q_newHsv(int,int,int)));
1822
1823 rightLay->addStretch();
1824
1825 cs = new QColorShower(q);
1826 pickLay->setContentsMargins(cs->gl->contentsMargins());
1827 QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb)));
1828 QObject::connect(cs, SIGNAL(currentColorChanged(QColor)),
1829 q, SIGNAL(currentColorChanged(QColor)));
1830#if defined(QT_SMALL_COLORDIALOG)
1831 topLay->addWidget(cs);
1832#else
1833 rightLay->addWidget(cs);
1834 if (leftLay)
1835 leftLay->addSpacing(cs->gl->contentsMargins().right());
1836#endif
1837
1838 buttons = new QDialogButtonBox(q);
1839 mainLay->addWidget(buttons);
1840
1841 ok = buttons->addButton(QDialogButtonBox::Ok);
1842 QObject::connect(ok, SIGNAL(clicked()), q, SLOT(accept()));
1843 ok->setDefault(true);
1844 cancel = buttons->addButton(QDialogButtonBox::Cancel);
1845 QObject::connect(cancel, SIGNAL(clicked()), q, SLOT(reject()));
1846
1847#ifdef Q_OS_WIN32
1848 updateTimer = new QTimer(q);
1849 QObject::connect(updateTimer, SIGNAL(timeout()), q, SLOT(_q_updateColorPicking()));
1850#endif
1851 retranslateStrings();
1852}
1853
1855{
1856 QColorDialog *d = q_func();
1857 QObject::connect(h, SIGNAL(currentColorChanged(QColor)), d, SIGNAL(currentColorChanged(QColor)));
1858 QObject::connect(h, SIGNAL(colorSelected(QColor)), d, SIGNAL(colorSelected(QColor)));
1859 static_cast<QPlatformColorDialogHelper *>(h)->setOptions(options);
1860}
1861
1863{
1864 options->setWindowTitle(q_func()->windowTitle());
1865}
1866
1868{
1869 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
1870 if (custom)
1871 custom->update();
1872 nextCust = (nextCust+1) % QColorDialogOptions::customColorCount();
1873}
1874
1876{
1877 if (nativeDialogInUse)
1878 return;
1879
1880 if (!smallDisplay) {
1881 lblBasicColors->setText(QColorDialog::tr("&Basic colors"));
1882 lblCustomColors->setText(QColorDialog::tr("&Custom colors"));
1883 addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));
1884#if !defined(QT_SMALL_COLORDIALOG)
1885 if (eyeDropperButton)
1886 eyeDropperButton->setText(QColorDialog::tr("&Pick Screen Color"));
1887#endif
1888 }
1889
1890 cs->retranslateStrings();
1891}
1892
1894{
1895 const auto integration = QGuiApplicationPrivate::platformIntegration();
1896 return integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
1897 || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking);
1898}
1899
1901{
1902 // Don't use Q_Q here! This function is called from ~QDialog,
1903 // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).
1904 const QDialog * const q = static_cast<const QDialog*>(q_ptr);
1905 if (nativeDialogInUse)
1906 return true;
1908 || q->testAttribute(Qt::WA_DontShowOnScreen)
1909 || (options->options() & QColorDialog::DontUseNativeDialog)) {
1910 return false;
1911 }
1912
1913 return strcmp(QColorDialog::staticMetaObject.className(), q->metaObject()->className()) == 0;
1914}
1915
1916static const Qt::WindowFlags qcd_DefaultWindowFlags =
1919
1965 : QColorDialog(QColor(Qt::white), parent)
1966{
1967}
1968
1977{
1978 Q_D(QColorDialog);
1979 d->init(initial);
1980}
1981
1983{
1984 if (nativeDialogInUse) {
1986 return;
1987 }
1988
1989 if (setColorMode & ShowColor) {
1991 setCurrentAlpha(color.alpha());
1992 }
1993 if (setColorMode & SelectColor)
1995}
1996
2003{
2004 Q_D(QColorDialog);
2005 d->setCurrentColor(color);
2006}
2007
2009{
2010 Q_D(const QColorDialog);
2011 return d->currentQColor();
2012}
2013
2023{
2024 Q_D(const QColorDialog);
2025 return d->selectedQColor;
2026}
2027
2035{
2036 const QColorDialog::ColorDialogOptions previousOptions = options();
2037 if (!(previousOptions & option) != !on)
2038 setOptions(previousOptions ^ option);
2039}
2040
2050{
2051 Q_D(const QColorDialog);
2052 return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
2053}
2054
2067void QColorDialog::setOptions(ColorDialogOptions options)
2068{
2069 Q_D(QColorDialog);
2070
2072 return;
2073
2074 d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));
2075 if ((options & DontUseNativeDialog) && d->nativeDialogInUse) {
2076 d->nativeDialogInUse = false;
2077 d->initWidgets();
2078 }
2079 if (!d->nativeDialogInUse) {
2080 d->buttons->setVisible(!(options & NoButtons));
2081 d->showAlpha(options & ShowAlphaChannel);
2082 if (d->eyeDropperButton)
2083 d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton));
2084 }
2085}
2086
2087QColorDialog::ColorDialogOptions QColorDialog::options() const
2088{
2089 Q_D(const QColorDialog);
2090 return QColorDialog::ColorDialogOptions(int(d->options->options()));
2091}
2092
2133{
2134 Q_D(QColorDialog);
2135
2136 if (visible){
2138 return;
2140 return;
2141
2142 if (visible)
2143 d->selectedQColor = QColor();
2144
2145 if (d->nativeDialogInUse) {
2146 if (d->setNativeDialogVisible(visible)) {
2147 // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
2148 // updates the state correctly, but skips showing the non-native version:
2150 } else {
2151 d->initWidgets();
2152 }
2153 } else {
2155 }
2156
2158}
2159
2168void QColorDialog::open(QObject *receiver, const char *member)
2169{
2170 Q_D(QColorDialog);
2171 connect(this, SIGNAL(colorSelected(QColor)), receiver, member);
2172 d->receiverToDisconnectOnClose = receiver;
2173 d->memberToDisconnectOnClose = member;
2174 QDialog::open();
2175}
2176
2188 ColorDialogOptions options)
2189{
2190 QColorDialog dlg(parent);
2191 if (!title.isEmpty())
2192 dlg.setWindowTitle(title);
2193 dlg.setOptions(options);
2194 dlg.setCurrentColor(initial);
2195 dlg.exec();
2196 return dlg.selectedColor();
2197}
2198
2204{
2205
2206}
2207
2212{
2213 Q_D(QColorDialog);
2214 if (e->type() == QEvent::LanguageChange)
2215 d->retranslateStrings();
2217}
2218
2220{
2221#ifndef QT_NO_CURSOR
2222 Q_Q(QColorDialog);
2223 static QPoint lastGlobalPos;
2224 QPoint newGlobalPos = QCursor::pos();
2225 if (lastGlobalPos == newGlobalPos)
2226 return;
2227 lastGlobalPos = newGlobalPos;
2228
2229 if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called
2230 updateColorPicking(newGlobalPos);
2231#ifdef Q_OS_WIN32
2232 dummyTransparentWindow.setPosition(newGlobalPos);
2233#endif
2234 }
2235#endif // ! QT_NO_CURSOR
2236}
2237
2239{
2240 const QColor color = grabScreenColor(globalPos);
2241 // QTBUG-39792, do not change standard, custom color selectors while moving as
2242 // otherwise it is not possible to pre-select a custom cell for assignment.
2244 updateColorLabelText(globalPos);
2245}
2246
2248{
2249 // If the cross is visible the grabbed color will be black most of the times
2250 cp->setCrossVisible(!cp->geometry().contains(e->position().toPoint()));
2251
2252 updateColorPicking(e->globalPosition().toPoint());
2253 return true;
2254}
2255
2257{
2258 setCurrentColor(grabScreenColor(e->globalPosition().toPoint()), SetColorAll);
2260 return true;
2261}
2262
2264{
2265 Q_Q(QColorDialog);
2266#if QT_CONFIG(shortcut)
2267 if (e->matches(QKeySequence::Cancel)) {
2269 q->setCurrentColor(beforeScreenColorPicking);
2270 } else
2271#endif
2272 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
2273 q->setCurrentColor(grabScreenColor(QCursor::pos()));
2275 }
2276 e->accept();
2277 return true;
2278}
2279
2288{
2289 Q_D(QColorDialog);
2290 if (result == Accepted) {
2291 d->selectedQColor = d->currentQColor();
2292 emit colorSelected(d->selectedQColor);
2293 } else {
2294 d->selectedQColor = QColor();
2295 }
2297 if (d->receiverToDisconnectOnClose) {
2299 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2300 d->receiverToDisconnectOnClose = nullptr;
2301 }
2302 d->memberToDisconnectOnClose.clear();
2303}
2304
2306
2307#include "qcolordialog.moc"
2308#include "moc_qcolordialog.cpp"
int startDragDistance
the minimum distance required for a drag and drop operation to start.
int spacing() const override
Reimplements QLayout::spacing().
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
void addSpacing(int size)
Adds a non-stretchable space (a QSpacerItem) with size size to the end of this box layout.
void addStretch(int stretch=0)
Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end...
void addLayout(QLayout *layout, int stretch=0)
Adds layout to the end of the box, with serial stretch factor stretch.
\inmodule QtCore
Definition qbytearray.h:57
QColor grabScreenColor(const QPoint &p)
void _q_newColorTypedIn(QRgb rgb)
bool selectColor(const QColor &color)
void init(const QColor &initial)
QColorLuminancePicker * lp
void setCurrentAlpha(int a)
bool handleColorPickingMouseButtonRelease(QMouseEvent *e)
QColor currentQColor() const
bool handleColorPickingMouseMove(QMouseEvent *e)
void _q_setCustom(int index, QRgb color)
void updateColorLabelText(const QPoint &)
void setCurrentColor(const QColor &color, SetColorMode setColorMode=SetColorAll)
bool isAlphaVisible() const
void setCurrentQColor(const QColor &color)
bool canBeNativeDialog() const override
void _q_nextCustom(int, int)
void setCurrentRgbColor(QRgb rgb)
QRgb currentColor() const
QPushButton * eyeDropperButton
void _q_newStandard(int, int)
bool handleColorPickingKeyPress(QKeyEvent *e)
void updateColorPicking(const QPoint &pos)
QSharedPointer< QColorDialogOptions > options
QDialogButtonBox * buttons
bool supportsColorPicking() const
QVBoxLayout * leftLay
void _q_newHsv(int h, int s, int v)
virtual void initHelper(QPlatformDialogHelper *h) override
QByteArray memberToDisconnectOnClose
void _q_newCustom(int, int)
QPointer< QObject > receiverToDisconnectOnClose
QPushButton * addCusBt
QColorPickingEventFilter * colorPickingEventFilter
virtual void helperPrepareShow(QPlatformDialogHelper *h) override
QPlatformColorDialogHelper * platformColorDialogHelper() const
The QColorDialog class provides a dialog widget for specifying colors.
static QColor getColor(const QColor &initial=Qt::white, QWidget *parent=nullptr, const QString &title=QString(), ColorDialogOptions options=ColorDialogOptions())
QColor currentColor
the currently selected color in the dialog
bool testOption(ColorDialogOption option) const
static QColor customColor(int index)
void changeEvent(QEvent *event) override
\reimp
void setCurrentColor(const QColor &color)
void setOptions(ColorDialogOptions options)
static int customCount()
Returns the number of custom colors supported by QColorDialog.
QColorDialog(QWidget *parent=nullptr)
~QColorDialog()
Destroys the color dialog.
void colorSelected(const QColor &color)
This signal is emitted just after the user has clicked \uicontrol{OK} to select a color to use.
ColorDialogOptions options
the various options that affect the look and feel of the dialog
static void setCustomColor(int index, QColor color)
Sets the custom color at index to the QColor color value.
static QColor standardColor(int index)
static void setStandardColor(int index, QColor color)
Sets the standard color at index to the QColor color value.
QColor selectedColor() const
Returns the color that the user selected by clicking the \uicontrol{OK} or equivalent button.
virtual void open()
Definition qdialog.cpp:499
void setOption(ColorDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QRgb rgb() const noexcept
Returns the RGB value of the color.
Definition qcolor.cpp:1439
static QColor fromString(QAnyStringView name) noexcept
Definition qcolor.cpp:980
void setRgba(QRgb rgba) noexcept
Sets the RGB value to rgba, including its alpha.
Definition qcolor.cpp:1388
static QColor fromHsv(int h, int s, int v, int a=255)
Static convenience function that returns a QColor constructed from the HSV color values,...
Definition qcolor.cpp:2499
bool isValid() const noexcept
Returns true if the color is valid; otherwise returns false.
Definition qcolor.h:285
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
Definition qcursor.cpp:188
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
QPlatformDialogHelper * platformHelper() const
Definition qdialog.cpp:77
bool nativeDialogInUse
Definition qdialog_p.h:86
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
virtual int exec()
Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
Definition qdialog.cpp:539
@ Accepted
Definition qdialog.h:30
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition qdialog.cpp:598
virtual void open()
Definition qdialog.cpp:499
\inmodule QtGui
Definition qdrag.h:22
Qt::DropAction exec(Qt::DropActions supportedActions=Qt::MoveAction)
Definition qdrag.cpp:199
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
Definition qdrag.cpp:99
void setPixmap(const QPixmap &)
Sets pixmap as the pixmap used to represent the data in a drag and drop operation.
Definition qdrag.cpp:123
\inmodule QtCore
Definition qcoreevent.h:45
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ LanguageChange
Definition qcoreevent.h:123
@ MouseButtonRelease
Definition qcoreevent.h:61
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
The QFrame class is the base class of widgets that can have a frame.
Definition qframe.h:17
@ Sunken
Definition qframe.h:51
int frameWidth
the width of the frame that is drawn.
Definition qframe.h:24
void drawFrame(QPainter *)
Definition qframe.cpp:488
@ Panel
Definition qframe.h:41
The QGridLayout class lays out widgets in a grid.
Definition qgridlayout.h:21
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qgridlayout.h:64
int spacing() const override
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
static QPlatformIntegration * platformIntegration()
QScreen * primaryScreen
the primary (or default) screen of the application.
static QScreen * screenAt(const QPoint &point)
Returns the screen at point, or \nullptr if outside of any screen.
The QHBoxLayout class lines up widgets horizontally.
Definition qboxlayout.h:78
\inmodule QtGui
Definition qimage.h:37
@ Format_RGB32
Definition qimage.h:46
The QKeyEvent class describes a key event.
Definition qevent.h:423
The QLabel widget provides a text or image display.
Definition qlabel.h:20
void setBuddy(QWidget *)
Sets this label's buddy to buddy.
Definition qlabel.cpp:1169
void setText(const QString &)
Definition qlabel.cpp:263
void setAlignment(Qt::Alignment)
Definition qlabel.cpp:442
void setSizeConstraint(SizeConstraint)
Definition qlayout.cpp:1240
@ SetFixedSize
Definition qlayout.h:39
void setContentsMargins(int left, int top, int right, int bottom)
Definition qlayout.cpp:288
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
void setValidator(const QValidator *)
Sets the validator for values of line edit to v.
void setReadOnly(bool)
void textChanged(const QString &)
This signal is emitted whenever the text changes.
void setText(const QString &)
QString text
the line edit's text.
Definition qlineedit.h:32
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtGui
Definition qevent.h:195
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:114
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
int height() const
Returns the height of the pixmap.
Definition qpixmap.cpp:484
int width() const
Returns the width of the pixmap.
Definition qpixmap.cpp:472
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition qpixmap.cpp:854
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1445
The QPlatformColorDialogHelper class allows for platform-specific customization of color dialogs.
virtual void setCurrentColor(const QColor &)=0
virtual QColor currentColor() const =0
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
virtual QPlatformServices * services() const
void colorPicked(const QColor &color)
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\inmodule QtCore
Definition qpointer.h:18
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:23
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:369
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:851
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:184
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
Definition qrect.h:244
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:187
\inmodule QtCore \reentrant
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QRect availableGeometry
the screen's available geometry in pixels
Definition qscreen.h:46
QRect geometry
the screen's geometry in pixels
Definition qscreen.h:45
QPixmap grabWindow(WId window=0, int x=0, int y=0, int w=-1, int h=-1)
Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by Q...
Definition qscreen.cpp:685
QRect virtualGeometry
the pixel geometry of the virtual desktop to which this screen belongs
Definition qscreen.h:47
\inmodule QtCore
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:443
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr QSize boundedTo(const QSize &) const noexcept
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition qsize.h:196
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
The QSpinBox class provides a spin box widget.
Definition qspinbox.h:16
void setValue(int val)
Definition qspinbox.cpp:192
int value
the value of the spin box
Definition qspinbox.h:26
void setRange(int min, int max)
Convenience function to set the minimum, and maximum values with a single function call.
Definition qspinbox.cpp:381
void valueChanged(int)
This signal is emitted whenever the spin box's value is changed.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
\variable QStyleOption::palette
\variable QStyleOptionFocusRect::backgroundColor
QStyle::State state
QPalette palette
void initFrom(const QWidget *w)
@ State_Sunken
Definition qstyle.h:69
@ State_KeyboardFocusChange
Definition qstyle.h:90
@ State_Enabled
Definition qstyle.h:67
@ State_None
Definition qstyle.h:66
@ PM_DefaultFrameWidth
Definition qstyle.h:420
@ PE_Frame
Definition qstyle.h:103
@ PE_FrameFocusRect
Definition qstyle.h:106
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
\inmodule QtCore
Definition qtimer.h:20
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition qwidget.cpp:9507
void setSizePolicy(QSizePolicy)
void setMinimumWidth(int minw)
Definition qwidget.cpp:4119
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QPalette palette
the widget's palette
Definition qwidget.h:132
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7753
bool close()
Closes this widget.
Definition qwidget.cpp:8608
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7904
void hide()
Hides the widget.
Definition qwidget.cpp:8209
void setMinimumHeight(int minh)
Definition qwidget.cpp:4128
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
int y
the y coordinate of the widget relative to its parent and including any window frame
Definition qwidget.h:110
virtual void setVisible(bool visible)
Definition qwidget.cpp:8329
int x
the x coordinate of the widget relative to its parent including any window frame
Definition qwidget.h:109
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
friend class QPixmap
Definition qwidget.h:748
bool isRightToLeft() const
Definition qwidget.h:419
void setWindowTitle(const QString &)
Definition qwidget.cpp:6109
QStyle * style() const
Definition qwidget.cpp:2607
bool hasFocus() const
Definition qwidget.cpp:6471
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9868
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
bool isVisible() const
Definition qwidget.h:874
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
bool visible
whether the widget is visible
Definition qwidget.h:144
\inmodule QtGui
Definition qwindow.h:63
QColSpinBox(QWidget *parent)
QColorLuminancePicker(QWidget *parent=nullptr)
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void setCol(int h, int s, int v)
void newHsv(int h, int s, int v)
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...
QColorPicker(QWidget *parent)
void setCol(int h, int s)
void newCol(int h, int s)
bool eventFilter(QObject *, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent)
QColorShowLabel(QWidget *parent)
QColor currentQColor() const
QColorShower(QColorDialog *parent)
void setHsv(int h, int s, int v)
void newCol(QRgb rgb)
void currentColorChanged(const QColor &color)
QColorWell(QWidget *parent, int r, int c, const QRgb *vals)
void paintCellContents(QPainter *, int row, int col, const QRect &) override
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 mouseReleaseEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void mouseReleaseEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void focusOutEvent(QFocusEvent *) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
void currentChanged(int row, int col)
int columnAt(int x) const
void updateCell(int row, int column)
void selected(int row, int col)
void colorChanged(int index, QRgb color)
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void mousePressEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void focusInEvent(QFocusEvent *) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
virtual void setCurrent(int row, int col)
virtual void setSelected(int row, int col)
int rowAt(int y) const
QWellArray(int rows, int cols, QWidget *parent=nullptr)
QRect cellGeometry(int row, int column)
virtual void paintCell(QPainter *, int row, int col, const QRect &)
int columnX(int column) const
int rowY(int row) const
QSize sizeHint() const override
virtual void paintCellContents(QPainter *, int row, int col, const QRect &)
void keyPressEvent(QKeyEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
QString cellContent(int row, int col) const
double e
rect
[4]
QPixmap pix
QStyleOptionButton opt
Combined button and popup list for selecting options.
\macro QT_NAMESPACE
@ AlignRight
Definition qnamespace.h:145
@ AlignVCenter
Definition qnamespace.h:154
@ WA_WState_ExplicitShowHide
Definition qnamespace.h:334
@ WA_DontShowOnScreen
Definition qnamespace.h:382
@ WA_WState_Hidden
Definition qnamespace.h:296
@ WA_NoSystemBackground
Definition qnamespace.h:290
@ StrongFocus
Definition qnamespace.h:109
@ CrossCursor
@ white
Definition qnamespace.h:30
@ black
Definition qnamespace.h:29
@ Key_Return
Definition qnamespace.h:662
@ Key_Right
Definition qnamespace.h:674
@ Key_Enter
Definition qnamespace.h:663
@ Key_Space
Definition qnamespace.h:512
@ Key_Left
Definition qnamespace.h:672
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ AA_DontUseNativeDialogs
Definition qnamespace.h:457
@ CopyAction
@ FramelessWindowHint
Definition qnamespace.h:224
@ Dialog
Definition qnamespace.h:207
@ Tool
Definition qnamespace.h:211
@ WindowTitleHint
Definition qnamespace.h:225
@ WindowSystemMenuHint
Definition qnamespace.h:226
@ WindowCloseButtonHint
Definition qnamespace.h:240
#define rgb(r, g, b)
Definition qcolor.cpp:124
static int pHeight
static void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
@ customColorRows
@ colorColumns
@ standardColorRows
static const Qt::WindowFlags qcd_DefaultWindowFlags
static int pWidth
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLenum GLsizei GLsizei GLint * values
[15]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLbitfield GLuint64 timeout
[4]
GLboolean GLboolean g
GLuint name
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
const GLubyte * c
GLuint GLfloat * val
GLint void * img
Definition qopenglext.h:233
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
GLuint GLenum option
QT_BEGIN_NAMESPACE QColor grabScreenColor(const QPoint &p)
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
constexpr QRgb qRgb(int r, int g, int b)
Definition qrgb.h:30
constexpr int qRed(QRgb rgb)
Definition qrgb.h:18
constexpr int qGreen(QRgb rgb)
Definition qrgb.h:21
constexpr QRgb qRgba(int r, int g, int b, int a)
Definition qrgb.h:33
constexpr int qBlue(QRgb rgb)
Definition qrgb.h:24
static const struct TessellationWindingOrderTab cw[]
SSL_CTX int(*) void arg)
#define QStringLiteral(str)
QScreen * screen
[1]
Definition main.cpp:29
#define Q_PROPERTY(...)
#define Q_OBJECT
#define slots
#define signals
#define emit
#define Q_UNUSED(x)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
unsigned int uint
Definition qtypes.h:29
static QT_BEGIN_NAMESPACE QString windowTitle(HWND hwnd)
const char className[16]
[1]
Definition qwizard.cpp:100
future cancel()
application x qt windows mime
[2]
QString title
[35]
myObject disconnect()
[26]
widget render & pixmap
QPainter painter(this)
[7]
label setFrameStyle(QFrame::Panel|QFrame::Raised)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent