Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 <QtCore/qpointer.h>
47
48#include <algorithm>
49
51
52using namespace Qt::StringLiterals;
53
54namespace QtPrivate {
56class QColorPicker;
57class QColorShower;
58class QWellArray;
59class QColorWell;
61} // namespace QtPrivate
62
69
71{
72 Q_DECLARE_PUBLIC(QColorDialog)
73
74public:
80
81 QColorDialogPrivate() : options(QColorDialogOptions::create())
82#ifdef Q_OS_WIN32
83 , updateTimer(0)
84#endif
85 {}
86
89
90 void init(const QColor &initial);
91 void initWidgets();
92 QRgb currentColor() const;
93 QColor currentQColor() const;
94 void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll);
96 void setCurrentQColor(const QColor &color);
97 bool selectColor(const QColor &color);
99
100 int currentAlpha() const;
101 void setCurrentAlpha(int a);
102 void showAlpha(bool b);
103 bool isAlphaVisible() const;
104 void retranslateStrings();
105 bool supportsColorPicking() const;
106
107 void addCustom();
109
110 void newHsv(int h, int s, int v);
112 void nextCustom(int, int);
113 void newCustom(int, int);
114 void newStandard(int, int);
115 void pickScreenColor();
116 void updateColorPicking();
117 void updateColorLabelText(const QPoint &);
118 void updateColorPicking(const QPoint &pos);
119 void releaseColorPicking();
123
124 bool canBeNativeDialog() const override;
125 void setVisible(bool visible) override;
126
129
148 QSharedPointer<QColorDialogOptions> options;
149
152#ifdef Q_OS_WIN32
153 QTimer *updateTimer;
154 QWindow dummyTransparentWindow;
155#endif
156
157private:
158 virtual void initHelper(QPlatformDialogHelper *h) override;
159 virtual void helperPrepareShow(QPlatformDialogHelper *h) override;
160};
161
163
164namespace QtPrivate {
165
166class QWellArray : public QWidget
167{
171
172public:
173 QWellArray(int rows, int cols, QWidget* parent=nullptr);
175 QString cellContent(int row, int col) const;
176
177 int selectedColumn() const { return selCol; }
178 int selectedRow() const { return selRow; }
179
180 virtual void setCurrent(int row, int col);
181 virtual void setSelected(int row, int col);
182
183 QSize sizeHint() const override;
184
185 inline int cellWidth() const
186 { return cellw; }
187
188 inline int cellHeight() const
189 { return cellh; }
190
191 inline int rowAt(int y) const
192 { return y / cellh; }
193
194 inline int columnAt(int x) const
195 { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
196
197 inline int rowY(int row) const
198 { return cellh * row; }
199
200 inline int columnX(int column) const
201 { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
202
203 inline int numRows() const
204 { return nrows; }
205
206 inline int numCols() const
207 {return ncols; }
208
209 inline QRect cellRect() const
210 { return QRect(0, 0, cellw, cellh); }
211
212 inline QSize gridSize() const
213 { return QSize(ncols * cellw, nrows * cellh); }
214
216 {
217 QRect r;
218 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
219 r.setRect(columnX(column), rowY(row), cellw, cellh);
220 return r;
221 }
222
223 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
224
225signals:
226 void selected(int row, int col);
227 void currentChanged(int row, int col);
229
230protected:
231 virtual void paintCell(QPainter *, int row, int col, const QRect&);
232 virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
233
234 void mousePressEvent(QMouseEvent*) override;
235 void mouseReleaseEvent(QMouseEvent*) override;
236 void keyPressEvent(QKeyEvent*) override;
237 void focusInEvent(QFocusEvent*) override;
238 void focusOutEvent(QFocusEvent*) override;
239 void paintEvent(QPaintEvent *) override;
240
241private:
242 Q_DISABLE_COPY(QWellArray)
243
244 int nrows;
245 int ncols;
246 int cellw;
247 int cellh;
248 int curRow;
249 int curCol;
250 int selRow;
251 int selCol;
252};
253
255{
256 QRect r = e->rect();
257 int cx = r.x();
258 int cy = r.y();
259 int ch = r.height();
260 int cw = r.width();
261 int colfirst = columnAt(cx);
262 int collast = columnAt(cx + cw);
263 int rowfirst = rowAt(cy);
264 int rowlast = rowAt(cy + ch);
265
266 if (isRightToLeft()) {
267 int t = colfirst;
268 colfirst = collast;
269 collast = t;
270 }
271
272 QPainter painter(this);
273 QPainter *p = &painter;
274 QRect rect(0, 0, cellWidth(), cellHeight());
275
276
277 if (collast < 0 || collast >= ncols)
278 collast = ncols-1;
279 if (rowlast < 0 || rowlast >= nrows)
280 rowlast = nrows-1;
281
282 // Go through the rows
283 for (int r = rowfirst; r <= rowlast; ++r) {
284 // get row position and height
285 int rowp = rowY(r);
286
287 // Go through the columns in the row r
288 // if we know from where to where, go through [colfirst, collast],
289 // else go through all of them
290 for (int c = colfirst; c <= collast; ++c) {
291 // get position and width of column c
292 int colp = columnX(c);
293 // Translate painter and draw the cell
294 rect.translate(colp, rowp);
295 paintCell(p, r, c, rect);
296 rect.translate(-colp, -rowp);
297 }
298 }
299}
300
301QWellArray::QWellArray(int rows, int cols, QWidget *parent)
302 : QWidget(parent)
303 ,nrows(rows), ncols(cols)
304{
306 cellw = 28;
307 cellh = 24;
308 curCol = 0;
309 curRow = 0;
310 selCol = -1;
311 selRow = -1;
312}
313
315{
317 return gridSize().boundedTo(QSize(640, 480));
318}
319
320
321void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
322{
323 int b = 3; //margin
324
325 const QPalette & g = palette();
327 opt.initFrom(this);
329 opt.lineWidth = dfw;
330 opt.midLineWidth = 1;
331 opt.rect = rect.adjusted(b, b, -b, -b);
332 opt.palette = g;
335 b += dfw;
336
337 if ((row == curRow) && (col == curCol)) {
338 if (hasFocus()) {
340 opt.palette = g;
341 opt.rect = rect;
344 }
345 }
346 paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));
347}
348
349/*
350 Reimplement this function to change the contents of the well array.
351 */
352void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
353{
354 Q_UNUSED(row);
355 Q_UNUSED(col);
356 p->fillRect(r, Qt::white);
357 p->setPen(Qt::black);
358 p->drawLine(r.topLeft(), r.bottomRight());
359 p->drawLine(r.topRight(), r.bottomLeft());
360}
361
363{
364 // The current cell marker is set to the cell the mouse is pressed in
365 QPoint pos = e->position().toPoint();
367}
368
370{
371 // The current cell marker is set to the cell the mouse is clicked in
372 setSelected(curRow, curCol);
373}
374
375
376/*
377 Sets the cell currently having the focus. This is not necessarily
378 the same as the currently selected cell.
379*/
380
381void QWellArray::setCurrent(int row, int col)
382{
383 if ((curRow == row) && (curCol == col))
384 return;
385
386 if (row < 0 || col < 0)
387 row = col = -1;
388
389 int oldRow = curRow;
390 int oldCol = curCol;
391
392 curRow = row;
393 curCol = col;
394
395 updateCell(oldRow, oldCol);
396 updateCell(curRow, curCol);
397
398 emit currentChanged(curRow, curCol);
399}
400
401/*
402 Sets the currently selected cell to \a row, \a column. If \a row or
403 \a column are less than zero, the current cell is unselected.
404
405 Does not set the position of the focus indicator.
406*/
407void QWellArray::setSelected(int row, int col)
408{
409 int oldRow = selRow;
410 int oldCol = selCol;
411
412 if (row < 0 || col < 0)
413 row = col = -1;
414
415 selCol = col;
416 selRow = row;
417
418 updateCell(oldRow, oldCol);
419 updateCell(selRow, selCol);
420 if (row >= 0)
421 emit selected(row, col);
422
423#if QT_CONFIG(menu)
424 if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
425 parentWidget()->close();
426#endif
427}
428
430{
431 updateCell(curRow, curCol);
432 emit currentChanged(curRow, curCol);
433}
434
435
437{
438 updateCell(curRow, curCol);
439}
440
442{
443 switch(e->key()) { // Look at the key code
444 case Qt::Key_Left: // If 'left arrow'-key,
445 if (curCol > 0) // and cr't not in leftmost col
446 setCurrent(curRow, curCol - 1); // set cr't to next left column
447 break;
448 case Qt::Key_Right: // Correspondingly...
449 if (curCol < numCols()-1)
450 setCurrent(curRow, curCol + 1);
451 break;
452 case Qt::Key_Up:
453 if (curRow > 0)
454 setCurrent(curRow - 1, curCol);
455 break;
456 case Qt::Key_Down:
457 if (curRow < numRows()-1)
458 setCurrent(curRow + 1, curCol);
459 break;
460#if 0
461 // bad idea that shouldn't have been implemented; very counterintuitive
462 case Qt::Key_Return:
463 case Qt::Key_Enter:
464 /*
465 ignore the key, so that the dialog get it, but still select
466 the current row/col
467 */
468 e->ignore();
469 // fallthrough intended
470#endif
471 case Qt::Key_Space:
472 setSelected(curRow, curCol);
473 break;
474 default: // If not an interesting key,
475 e->ignore(); // we don't accept the event
476 return;
477 }
478
479} // namespace QtPrivate
480
482
483// Event filter to be installed on the dialog while in color-picking mode.
485public:
487
488 bool eventFilter(QObject *, QEvent *event) override
489 {
490 switch (event->type()) {
492 return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));
494 return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
495 case QEvent::KeyPress:
496 return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
497 default:
498 break;
499 }
500 return false;
501 }
502
503private:
505};
506
507} // unnamed namespace
508
514{
515 return QColorDialogOptions::customColorCount();
516}
517
524{
525 return QColor(QColorDialogOptions::customColor(index));
526}
527
536{
537 QColorDialogOptions::setCustomColor(index, color.rgba());
538}
539
546{
547 return QColor(QColorDialogOptions::standardColor(index));
548}
549
558{
559 QColorDialogOptions::setStandardColor(index, color.rgba());
560}
561
562static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
563{
564 QColor c;
565 c.setRgb(rgb);
566 c.getHsv(&h, &s, &v);
567}
568
569namespace QtPrivate {
570
571class QColorWell : public QWellArray
572{
573public:
574 QColorWell(QWidget *parent, int r, int c, const QRgb *vals)
575 :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1)
577
578protected:
579 void paintCellContents(QPainter *, int row, int col, const QRect&) override;
580 void mousePressEvent(QMouseEvent *e) override;
581 void mouseMoveEvent(QMouseEvent *e) override;
582 void mouseReleaseEvent(QMouseEvent *e) override;
583#if QT_CONFIG(draganddrop)
584 void dragEnterEvent(QDragEnterEvent *e) override;
585 void dragLeaveEvent(QDragLeaveEvent *e) override;
586 void dragMoveEvent(QDragMoveEvent *e) override;
587 void dropEvent(QDropEvent *e) override;
588#endif
589
590private:
591 const QRgb *values;
592 bool mousePressed;
593 QPoint pressPos;
594 QPoint oldCurrent;
595
596};
597
598void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)
599{
600 int i = row + col*numRows();
601 p->fillRect(r, QColor(values[i]));
602}
603
605{
606 oldCurrent = QPoint(selectedRow(), selectedColumn());
608 mousePressed = true;
609 pressPos = e->position().toPoint();
610}
611
613{
615#if QT_CONFIG(draganddrop)
616 if (!mousePressed)
617 return;
618 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
619 setCurrent(oldCurrent.x(), oldCurrent.y());
620 int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows();
621 QColor col(values[i]);
622 QMimeData *mime = new QMimeData;
623 mime->setColorData(col);
625 pix.fill(col);
626 QPainter p(&pix);
627 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
628 p.end();
629 QDrag *drg = new QDrag(this);
630 drg->setMimeData(mime);
631 drg->setPixmap(pix);
632 mousePressed = false;
633 drg->exec(Qt::CopyAction);
634 }
635#endif
636}
637
638#if QT_CONFIG(draganddrop)
639void QColorWell::dragEnterEvent(QDragEnterEvent *e)
640{
641 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
642 e->accept();
643 else
644 e->ignore();
645}
646
647void QColorWell::dragLeaveEvent(QDragLeaveEvent *)
648{
649 if (hasFocus())
651}
652
653void QColorWell::dragMoveEvent(QDragMoveEvent *e)
654{
655 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) {
656 setCurrent(rowAt(e->position().toPoint().y()), columnAt(e->position().toPoint().x()));
657 e->accept();
658 } else {
659 e->ignore();
660 }
661}
662
663void QColorWell::dropEvent(QDropEvent *e)
664{
665 QColor col = qvariant_cast<QColor>(e->mimeData()->colorData());
666 if (col.isValid()) {
667 int i = rowAt(e->position().toPoint().y()) + columnAt(e->position().toPoint().x()) * numRows();
668 emit colorChanged(i, col.rgb());
669 e->accept();
670 } else {
671 e->ignore();
672 }
673}
674
675#endif // QT_CONFIG(draganddrop)
676
678{
679 if (!mousePressed)
680 return;
682 mousePressed = false;
683}
684
685class QColorPicker : public QFrame
686{
688public:
691
692 void setCrossVisible(bool visible);
693public slots:
694 void setCol(int h, int s);
695
696signals:
697 void newCol(int h, int s);
698
699protected:
700 QSize sizeHint() const override;
701 void paintEvent(QPaintEvent*) override;
702 void mouseMoveEvent(QMouseEvent *) override;
703 void mousePressEvent(QMouseEvent *) override;
704 void resizeEvent(QResizeEvent *) override;
705
706private:
707 int hue;
708 int sat;
709
710 QPoint colPt();
711 int huePt(const QPoint &pt);
712 int satPt(const QPoint &pt);
713 void setCol(const QPoint &pt);
714
715 QPixmap pix;
716 bool crossVisible;
717};
718
719} // namespace QtPrivate
720
721static int pWidth = 220;
722static int pHeight = 200;
723
724namespace QtPrivate {
725
727{
729public:
732
733public slots:
734 void setCol(int h, int s, int v);
735 void setCol(int h, int s);
736
737signals:
738 void newHsv(int h, int s, int v);
739
740protected:
741 void paintEvent(QPaintEvent*) override;
742 void mouseMoveEvent(QMouseEvent *) override;
743 void mousePressEvent(QMouseEvent *) override;
744
745private:
746 enum { foff = 3, coff = 4 }; //frame and contents offset
747 int val;
748 int hue;
749 int sat;
750
751 int y2val(int y);
752 int val2y(int val);
753 void setVal(int v);
754
755 QPixmap *pix;
756};
757
758
759int QColorLuminancePicker::y2val(int y)
760{
761 int d = height() - 2*coff - 1;
762 return 255 - (y - coff)*255/d;
763}
764
765int QColorLuminancePicker::val2y(int v)
766{
767 int d = height() - 2*coff - 1;
768 return coff + (255-v)*d/255;
769}
770
772 :QWidget(parent)
773{
774 hue = 100; val = 100; sat = 100;
775 pix = nullptr;
776 // setAttribute(WA_NoErase, true);
777}
778
783
785{
786 if (m->buttons() == Qt::NoButton) {
787 m->ignore();
788 return;
789 }
790 setVal(y2val(m->position().toPoint().y()));
791}
793{
794 setVal(y2val(m->position().toPoint().y()));
795}
796
797void QColorLuminancePicker::setVal(int v)
798{
799 if (val == v)
800 return;
801 val = qMax(0, qMin(v,255));
802 delete pix; pix=nullptr;
803 repaint();
804 emit newHsv(hue, sat, val);
805}
806
807//receives from a hue,sat chooser and relays.
809{
810 setCol(h, s, val);
811 emit newHsv(h, s, val);
812}
813
815{
816 int w = width() - 5;
817
818 QRect r(0, foff, w, height() - 2*foff);
819 int wi = r.width() - 2;
820 int hi = r.height() - 2;
821 if (!pix || pix->height() != hi || pix->width() != wi) {
822 delete pix;
824 int y;
825 uint *pixel = (uint *) img.scanLine(0);
826 for (y = 0; y < hi; y++) {
827 uint *end = pixel + wi;
828 std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb());
829 pixel = end;
830 }
831 pix = new QPixmap(QPixmap::fromImage(img));
832 }
833 QPainter p(this);
834 p.drawPixmap(1, coff, *pix);
835 const QPalette &g = palette();
836 qDrawShadePanel(&p, r, g, true);
837 p.setPen(g.windowText().color());
838 p.setBrush(g.windowText());
839 p.eraseRect(w, 0, 5, height());
840 const int y = val2y(val);
841 const std::array<QPoint, 3> points = {QPoint(w, y), QPoint(w + 5, y + 5), QPoint(w + 5, y - 5)};
842 p.drawPolygon(points.data(), static_cast<int>(points.size()));
843}
844
845void QColorLuminancePicker::setCol(int h, int s , int v)
846{
847 val = v;
848 hue = h;
849 sat = s;
850 delete pix; pix=nullptr;
851 repaint();
852}
853
854QPoint QColorPicker::colPt()
855{
856 QRect r = contentsRect();
857 return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
858}
859
860int QColorPicker::huePt(const QPoint &pt)
861{
862 QRect r = contentsRect();
863 return 360 - pt.x() * 360 / (r.width() - 1);
864}
865
866int QColorPicker::satPt(const QPoint &pt)
867{
868 QRect r = contentsRect();
869 return 255 - pt.y() * 255 / (r.height() - 1);
870}
871
872void QColorPicker::setCol(const QPoint &pt)
873{
874 setCol(huePt(pt), satPt(pt));
875}
876
878 : QFrame(parent)
879 , crossVisible(true)
880{
881 hue = 0; sat = 0;
882 setCol(150, 255);
883
886}
887
891
893{
894 if (crossVisible != visible) {
895 crossVisible = visible;
896 update();
897 }
898}
899
901{
902 return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
903}
904
906{
907 int nhue = qMin(qMax(0,h), 359);
908 int nsat = qMin(qMax(0,s), 255);
909 if (nhue == hue && nsat == sat)
910 return;
911
912 QRect r(colPt(), QSize(20,20));
913 hue = nhue; sat = nsat;
914 r = r.united(QRect(colPt(), QSize(20,20)));
915 r.translate(contentsRect().x()-9, contentsRect().y()-9);
916 // update(r);
917 repaint(r);
918}
919
921{
922 QPoint p = m->position().toPoint() - contentsRect().topLeft();
923 if (m->buttons() == Qt::NoButton) {
924 m->ignore();
925 return;
926 }
927 setCol(p);
928 emit newCol(hue, sat);
929}
930
932{
933 QPoint p = m->position().toPoint() - contentsRect().topLeft();
934 setCol(p);
935 emit newCol(hue, sat);
936}
937
939{
940 QPainter p(this);
941 drawFrame(&p);
942 QRect r = contentsRect();
943
944 p.drawPixmap(r.topLeft(), pix);
945
946 if (crossVisible) {
947 QPoint pt = colPt() + r.topLeft();
948 p.setPen(Qt::black);
949 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
950 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
951 }
952}
953
955{
957
958 int w = width() - frameWidth() * 2;
959 int h = height() - frameWidth() * 2;
961 int x, y;
962 uint *pixel = (uint *) img.scanLine(0);
963 for (y = 0; y < h; y++) {
964 const uint *end = pixel + w;
965 x = 0;
966 while (pixel < end) {
967 QPoint p(x, y);
968 QColor c;
969 c.setHsv(huePt(p), satPt(p), 200);
970 *pixel = c.rgb();
971 ++pixel;
972 ++x;
973 }
974 }
975 pix = QPixmap::fromImage(img);
976}
977
978
979class QColSpinBox : public QSpinBox
980{
981public:
984 void setValue(int i) {
985 const QSignalBlocker blocker(this);
987 }
988};
989
990class QColorShowLabel;
991
992class QColorShower : public QWidget
993{
995public:
997
998 //things that don't emit signals
999 void setHsv(int h, int s, int v);
1000
1001 int currentAlpha() const
1002 { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }
1003 void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); }
1004 void showAlpha(bool b);
1005 bool isAlphaVisible() const;
1006
1007 QRgb currentColor() const { return curCol; }
1008 QColor currentQColor() const { return curQColor; }
1009 void retranslateStrings();
1010 void updateQColor();
1011
1012public slots:
1013 void setRgb(QRgb rgb);
1014
1015signals:
1018
1019private slots:
1020 void rgbEd();
1021 void hsvEd();
1022 void htmlEd();
1023
1024private:
1025 void showCurrentColor();
1026 int hue, sat, val;
1027 QRgb curCol;
1028 QColor curQColor;
1029 QLabel *lblHue;
1030 QLabel *lblSat;
1031 QLabel *lblVal;
1032 QLabel *lblRed;
1033 QLabel *lblGreen;
1034 QLabel *lblBlue;
1035 QLabel *lblHtml;
1036 QColSpinBox *hEd;
1037 QColSpinBox *sEd;
1038 QColSpinBox *vEd;
1039 QColSpinBox *rEd;
1040 QColSpinBox *gEd;
1041 QColSpinBox *bEd;
1042 QColSpinBox *alphaEd;
1043 QLabel *alphaLab;
1044 QLineEdit *htEd;
1045 QColorShowLabel *lab;
1046 bool rgbOriginal;
1047 QColorDialog *colorDialog;
1048 QGridLayout *gl;
1049
1050 friend class QT_PREPEND_NAMESPACE(QColorDialog);
1051 friend class QT_PREPEND_NAMESPACE(QColorDialogPrivate);
1052};
1053
1055{
1056 Q_OBJECT
1057
1058public:
1059 QColorShowLabel(QWidget *parent) : QFrame(parent) {
1061 setAcceptDrops(true);
1062 mousePressed = false;
1063 }
1064 void setColor(QColor c) { col = c; }
1065
1066signals:
1068
1069protected:
1070 void paintEvent(QPaintEvent *) override;
1071 void mousePressEvent(QMouseEvent *e) override;
1072 void mouseMoveEvent(QMouseEvent *e) override;
1073 void mouseReleaseEvent(QMouseEvent *e) override;
1074#if QT_CONFIG(draganddrop)
1075 void dragEnterEvent(QDragEnterEvent *e) override;
1076 void dragLeaveEvent(QDragLeaveEvent *e) override;
1077 void dropEvent(QDropEvent *e) override;
1078#endif
1079
1080private:
1081 QColor col;
1082 bool mousePressed;
1083 QPoint pressPos;
1084};
1085
1086void QColorShowLabel::paintEvent(QPaintEvent *e)
1087{
1088 QPainter p(this);
1089 drawFrame(&p);
1090 p.fillRect(contentsRect()&e->rect(), col);
1091}
1092
1094{
1095 alphaLab->setVisible(b);
1096 alphaEd->setVisible(b);
1097}
1098
1100{
1101 return alphaLab->isVisible();
1102}
1103
1104void QColorShowLabel::mousePressEvent(QMouseEvent *e)
1105{
1106 mousePressed = true;
1107 pressPos = e->position().toPoint();
1108}
1109
1110void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)
1111{
1112#if !QT_CONFIG(draganddrop)
1113 Q_UNUSED(e);
1114#else
1115 if (!mousePressed)
1116 return;
1117 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
1118 QMimeData *mime = new QMimeData;
1119 mime->setColorData(col);
1120 QPixmap pix(30, 20);
1121 pix.fill(col);
1122 QPainter p(&pix);
1123 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
1124 p.end();
1125 QDrag *drg = new QDrag(this);
1126 drg->setMimeData(mime);
1127 drg->setPixmap(pix);
1128 mousePressed = false;
1129 drg->exec(Qt::CopyAction);
1130 }
1131#endif
1132}
1133
1134#if QT_CONFIG(draganddrop)
1135void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e)
1136{
1137 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
1138 e->accept();
1139 else
1140 e->ignore();
1141}
1142
1143void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *)
1144{
1145}
1146
1147void QColorShowLabel::dropEvent(QDropEvent *e)
1148{
1149 QColor color = qvariant_cast<QColor>(e->mimeData()->colorData());
1150 if (color.isValid()) {
1151 col = color;
1152 repaint();
1153 emit colorDropped(col.rgb());
1154 e->accept();
1155 } else {
1156 e->ignore();
1157 }
1158}
1159#endif // QT_CONFIG(draganddrop)
1160
1161void QColorShowLabel::mouseReleaseEvent(QMouseEvent *)
1162{
1163 if (!mousePressed)
1164 return;
1165 mousePressed = false;
1166}
1167
1169 : QWidget(parent)
1170{
1171 colorDialog = parent;
1172
1173 curCol = qRgb(255, 255, 255);
1174 curQColor = Qt::white;
1175
1176 gl = new QGridLayout(this);
1177 const int s = gl->spacing();
1178 gl->setContentsMargins(s, s, s, s);
1179 lab = new QColorShowLabel(this);
1180
1181#ifdef QT_SMALL_COLORDIALOG
1182 lab->setMinimumHeight(60);
1183#endif
1184 lab->setMinimumWidth(60);
1185
1186// For QVGA screens only the comboboxes and color label are visible.
1187// For nHD screens only color and luminence pickers and color label are visible.
1188#if !defined(QT_SMALL_COLORDIALOG)
1189 gl->addWidget(lab, 0, 0, -1, 1);
1190#else
1191 gl->addWidget(lab, 0, 0, 1, -1);
1192#endif
1195
1196 hEd = new QColSpinBox(this);
1197 hEd->setRange(0, 359);
1198 lblHue = new QLabel(this);
1199#ifndef QT_NO_SHORTCUT
1200 lblHue->setBuddy(hEd);
1201#endif
1203#if !defined(QT_SMALL_COLORDIALOG)
1204 gl->addWidget(lblHue, 0, 1);
1205 gl->addWidget(hEd, 0, 2);
1206#else
1207 gl->addWidget(lblHue, 1, 0);
1208 gl->addWidget(hEd, 2, 0);
1209#endif
1210
1211 sEd = new QColSpinBox(this);
1212 lblSat = new QLabel(this);
1213#ifndef QT_NO_SHORTCUT
1214 lblSat->setBuddy(sEd);
1215#endif
1217#if !defined(QT_SMALL_COLORDIALOG)
1218 gl->addWidget(lblSat, 1, 1);
1219 gl->addWidget(sEd, 1, 2);
1220#else
1221 gl->addWidget(lblSat, 1, 1);
1222 gl->addWidget(sEd, 2, 1);
1223#endif
1224
1225 vEd = new QColSpinBox(this);
1226 lblVal = new QLabel(this);
1227#ifndef QT_NO_SHORTCUT
1228 lblVal->setBuddy(vEd);
1229#endif
1231#if !defined(QT_SMALL_COLORDIALOG)
1232 gl->addWidget(lblVal, 2, 1);
1233 gl->addWidget(vEd, 2, 2);
1234#else
1235 gl->addWidget(lblVal, 1, 2);
1236 gl->addWidget(vEd, 2, 2);
1237#endif
1238
1239 rEd = new QColSpinBox(this);
1240 lblRed = new QLabel(this);
1241#ifndef QT_NO_SHORTCUT
1242 lblRed->setBuddy(rEd);
1243#endif
1245#if !defined(QT_SMALL_COLORDIALOG)
1246 gl->addWidget(lblRed, 0, 3);
1247 gl->addWidget(rEd, 0, 4);
1248#else
1249 gl->addWidget(lblRed, 3, 0);
1250 gl->addWidget(rEd, 4, 0);
1251#endif
1252
1253 gEd = new QColSpinBox(this);
1254 lblGreen = new QLabel(this);
1255#ifndef QT_NO_SHORTCUT
1256 lblGreen->setBuddy(gEd);
1257#endif
1259#if !defined(QT_SMALL_COLORDIALOG)
1260 gl->addWidget(lblGreen, 1, 3);
1261 gl->addWidget(gEd, 1, 4);
1262#else
1263 gl->addWidget(lblGreen, 3, 1);
1264 gl->addWidget(gEd, 4, 1);
1265#endif
1266
1267 bEd = new QColSpinBox(this);
1268 lblBlue = new QLabel(this);
1269#ifndef QT_NO_SHORTCUT
1270 lblBlue->setBuddy(bEd);
1271#endif
1273#if !defined(QT_SMALL_COLORDIALOG)
1274 gl->addWidget(lblBlue, 2, 3);
1275 gl->addWidget(bEd, 2, 4);
1276#else
1277 gl->addWidget(lblBlue, 3, 2);
1278 gl->addWidget(bEd, 4, 2);
1279#endif
1280
1281 alphaEd = new QColSpinBox(this);
1282 alphaLab = new QLabel(this);
1283#ifndef QT_NO_SHORTCUT
1284 alphaLab->setBuddy(alphaEd);
1285#endif
1287#if !defined(QT_SMALL_COLORDIALOG)
1288 gl->addWidget(alphaLab, 3, 1, 1, 3);
1289 gl->addWidget(alphaEd, 3, 4);
1290#else
1291 gl->addWidget(alphaLab, 1, 3, 3, 1);
1292 gl->addWidget(alphaEd, 4, 3);
1293#endif
1294 alphaEd->hide();
1295 alphaLab->hide();
1296 lblHtml = new QLabel(this);
1297 htEd = new QLineEdit(this);
1298 htEd->setObjectName("qt_colorname_lineedit");
1299#ifndef QT_NO_SHORTCUT
1300 lblHtml->setBuddy(htEd);
1301#endif
1302
1303#if QT_CONFIG(regularexpression)
1304 QRegularExpression regExp(QStringLiteral("#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));
1305 QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
1306 htEd->setValidator(validator);
1307#else
1308 htEd->setReadOnly(true);
1309#endif
1311
1313#if defined(QT_SMALL_COLORDIALOG)
1314 gl->addWidget(lblHtml, 5, 0);
1315 gl->addWidget(htEd, 5, 1, 1, /*colspan=*/ 2);
1316#else
1317 gl->addWidget(lblHtml, 5, 1);
1318 gl->addWidget(htEd, 5, 2, 1, /*colspan=*/ 3);
1319#endif
1320
1321 connect(hEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1322 connect(sEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1323 connect(vEd, &QSpinBox::valueChanged, this, &QColorShower::hsvEd);
1324
1325 connect(rEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1326 connect(gEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1327 connect(bEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1328 connect(alphaEd, &QSpinBox::valueChanged, this, &QColorShower::rgbEd);
1329 connect(htEd, &QLineEdit::textEdited, this, &QColorShower::htmlEd);
1330
1332}
1333
1334} // namespace QtPrivate
1335
1337inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); }
1341
1348
1349void QColorShower::showCurrentColor()
1350{
1351 lab->setColor(currentColor());
1352 lab->repaint();
1353}
1354
1355void QColorShower::rgbEd()
1356{
1357 rgbOriginal = true;
1358 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1359
1360 rgb2hsv(currentColor(), hue, sat, val);
1361
1362 hEd->setValue(hue);
1363 sEd->setValue(sat);
1364 vEd->setValue(val);
1365
1366 htEd->setText(QColor(curCol).name());
1367
1368 showCurrentColor();
1370 updateQColor();
1371}
1372
1373void QColorShower::hsvEd()
1374{
1375 rgbOriginal = false;
1376 hue = hEd->value();
1377 sat = sEd->value();
1378 val = vEd->value();
1379
1380 QColor c;
1381 c.setHsv(hue, sat, val);
1382 curCol = c.rgb();
1383
1384 rEd->setValue(qRed(currentColor()));
1385 gEd->setValue(qGreen(currentColor()));
1386 bEd->setValue(qBlue(currentColor()));
1387
1388 htEd->setText(c.name());
1389
1390 showCurrentColor();
1392 updateQColor();
1393}
1394
1395void QColorShower::htmlEd()
1396{
1397 QString t = htEd->text();
1398 if (t.isEmpty())
1399 return;
1400
1401 if (!t.startsWith(u"#")) {
1402 t.prepend(u"#");
1403 QSignalBlocker blocker(htEd);
1404 htEd->setText(t);
1405 }
1406
1408 if (!c.isValid())
1409 return;
1410
1411 curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());
1412 rgb2hsv(curCol, hue, sat, val);
1413
1414 hEd->setValue(hue);
1415 sEd->setValue(sat);
1416 vEd->setValue(val);
1417
1418 rEd->setValue(qRed(currentColor()));
1419 gEd->setValue(qGreen(currentColor()));
1420 bEd->setValue(qBlue(currentColor()));
1421
1422 showCurrentColor();
1424 updateQColor();
1425}
1426
1428{
1429 rgbOriginal = true;
1430 curCol = rgb;
1431
1432 rgb2hsv(currentColor(), hue, sat, val);
1433
1434 hEd->setValue(hue);
1435 sEd->setValue(sat);
1436 vEd->setValue(val);
1437
1438 rEd->setValue(qRed(currentColor()));
1439 gEd->setValue(qGreen(currentColor()));
1440 bEd->setValue(qBlue(currentColor()));
1441
1442 htEd->setText(QColor(rgb).name());
1443
1444 showCurrentColor();
1445 updateQColor();
1446}
1447
1448void QColorShower::setHsv(int h, int s, int v)
1449{
1450 if (h < -1 || (uint)s > 255 || (uint)v > 255)
1451 return;
1452
1453 rgbOriginal = false;
1454 hue = h; val = v; sat = s;
1455 QColor c;
1456 c.setHsv(hue, sat, val);
1457 curCol = c.rgb();
1458
1459 hEd->setValue(hue);
1460 sEd->setValue(sat);
1461 vEd->setValue(val);
1462
1463 rEd->setValue(qRed(currentColor()));
1464 gEd->setValue(qGreen(currentColor()));
1465 bEd->setValue(qBlue(currentColor()));
1466
1467 htEd->setText(c.name());
1468
1469 showCurrentColor();
1470 updateQColor();
1471}
1472
1474{
1475 lblHue->setText(QColorDialog::tr("Hu&e:"));
1476 lblSat->setText(QColorDialog::tr("&Sat:"));
1477 lblVal->setText(QColorDialog::tr("&Val:"));
1478 lblRed->setText(QColorDialog::tr("&Red:"));
1479 lblGreen->setText(QColorDialog::tr("&Green:"));
1480 lblBlue->setText(QColorDialog::tr("Bl&ue:"));
1481 alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
1482 lblHtml->setText(QColorDialog::tr("&HTML:"));
1483}
1484
1486{
1487 QColor oldQColor(curQColor);
1488 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1489 if (curQColor != oldQColor)
1490 emit currentColorChanged(curQColor);
1491}
1492
1493//sets all widgets to display h,s,v
1495{
1496 if (!nativeDialogInUse) {
1497 cs->setHsv(h, s, v);
1498 cp->setCol(h, s);
1499 lp->setCol(h, s, v);
1500 }
1501}
1502
1503//sets all widgets to display rgb
1505{
1506 if (!nativeDialogInUse) {
1507 cs->setRgb(rgb);
1508 newColorTypedIn(rgb);
1509 }
1510}
1511
1512// hack; doesn't keep curCol in sync, so use with care
1514{
1515 Q_Q(QColorDialog);
1516 if (cs->curQColor != color) {
1517 cs->curQColor = color;
1518 emit q->currentColorChanged(color);
1519 }
1520}
1521
1522// size of standard and custom color selector
1523enum {
1526 customColorRows = 2
1528
1530{
1531 QRgb color = col.rgb();
1532 // Check standard colors
1533 if (standard) {
1534 const QRgb *standardColors = QColorDialogOptions::standardColors();
1535 const QRgb *standardColorsEnd = standardColors + standardColorRows * colorColumns;
1536 const QRgb *match = std::find(standardColors, standardColorsEnd, color);
1537 if (match != standardColorsEnd) {
1538 const int index = int(match - standardColors);
1539 const int column = index / standardColorRows;
1540 const int row = index % standardColorRows;
1541 newStandard(row, column);
1542 standard->setCurrent(row, column);
1543 standard->setSelected(row, column);
1544 standard->setFocus();
1545 return true;
1546 }
1547 }
1548 // Check custom colors
1549 if (custom) {
1550 const QRgb *customColors = QColorDialogOptions::customColors();
1551 const QRgb *customColorsEnd = customColors + customColorRows * colorColumns;
1552 const QRgb *match = std::find(customColors, customColorsEnd, color);
1553 if (match != customColorsEnd) {
1554 const int index = int(match - customColors);
1555 const int column = index / customColorRows;
1556 const int row = index % customColorRows;
1557 newCustom(row, column);
1558 custom->setCurrent(row, column);
1559 custom->setSelected(row, column);
1560 custom->setFocus();
1561 return true;
1562 }
1563 }
1564 return false;
1565}
1566
1568{
1570 if (!screen)
1572 const QRect screenRect = screen->geometry();
1573 const QPixmap pixmap =
1574 screen->grabWindow(0, p.x() - screenRect.x(), p.y() - screenRect.y(), 1, 1);
1575 const QImage i = pixmap.toImage();
1576 return i.pixel(0, 0);
1577}
1578
1579//sets all widgets except cs to display rgb
1581{
1582 if (!nativeDialogInUse) {
1583 int h, s, v;
1584 rgb2hsv(rgb, h, s, v);
1585 cp->setCol(h, s);
1586 lp->setCol(h, s, v);
1587 }
1588}
1589
1591{
1592 nextCust = r + customColorRows * c;
1593}
1594
1596{
1597 const int i = r + customColorRows * c;
1598 setCurrentRgbColor(QColorDialogOptions::customColor(i));
1599 if (standard)
1600 standard->setSelected(-1,-1);
1601}
1602
1604{
1605 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));
1606 if (custom)
1607 custom->setSelected(-1,-1);
1608}
1609
1611{
1612 Q_Q(QColorDialog);
1613
1614 auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
1615 if (platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) {
1616 if (auto *colorPicker = platformServices->colorPicker(q->windowHandle())) {
1617 q->connect(colorPicker, &QPlatformServiceColorPicker::colorPicked, q,
1618 [q, colorPicker](const QColor &color) {
1619 colorPicker->deleteLater();
1620 q->setCurrentColor(color);
1621 });
1622 colorPicker->pickColor();
1623 return;
1624 }
1625 }
1626
1627 if (!colorPickingEventFilter)
1628 colorPickingEventFilter = new QColorPickingEventFilter(this, q);
1629 q->installEventFilter(colorPickingEventFilter);
1630 // If user pushes Escape, the last color before picking will be restored.
1631 beforeScreenColorPicking = cs->currentColor();
1632#ifndef QT_NO_CURSOR
1633 q->grabMouse(Qt::CrossCursor);
1634#else
1635 q->grabMouse();
1636#endif
1637
1638#ifdef Q_OS_WIN32
1639 // On Windows mouse tracking doesn't work over other processes's windows
1640 updateTimer->start(30);
1641
1642 // HACK: Because mouse grabbing doesn't work across processes, we have to have a dummy,
1643 // invisible window to catch the mouse click, otherwise we will click whatever we clicked
1644 // and loose focus.
1645 dummyTransparentWindow.show();
1646#endif
1647 q->grabKeyboard();
1648 /* With setMouseTracking(true) the desired color can be more precisely picked up,
1649 * and continuously pushing the mouse button is not necessary.
1650 */
1651 q->setMouseTracking(true);
1652
1653 addCusBt->setDisabled(true);
1654 buttons->setDisabled(true);
1655 if (eyeDropperButton) {
1656 eyeDropperButton->setDisabled(true);
1657 const QPoint globalPos = QCursor::pos();
1658 q->setCurrentColor(grabScreenColor(globalPos));
1659 updateColorLabelText(globalPos);
1660 }
1661}
1662
1664{
1665 if (lblScreenColorInfo)
1666 lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")
1667 .arg(globalPos.x())
1668 .arg(globalPos.y()));
1669}
1670
1672{
1673 Q_Q(QColorDialog);
1674 cp->setCrossVisible(true);
1675 q->removeEventFilter(colorPickingEventFilter);
1676 q->releaseMouse();
1677#ifdef Q_OS_WIN32
1678 updateTimer->stop();
1679 dummyTransparentWindow.setVisible(false);
1680#endif
1681 q->releaseKeyboard();
1682 q->setMouseTracking(false);
1683 lblScreenColorInfo->setText("\n"_L1);
1684 addCusBt->setDisabled(false);
1685 buttons->setDisabled(false);
1686 eyeDropperButton->setDisabled(false);
1687}
1688
1690{
1691 Q_Q(QColorDialog);
1692
1693 q->setSizeGripEnabled(false);
1694 q->setWindowTitle(QColorDialog::tr("Select Color"));
1695
1696 // default: use the native dialog if possible. Can be overridden in setOptions()
1697 nativeDialogInUse = (platformColorDialogHelper() != nullptr);
1698 colorPickingEventFilter = nullptr;
1699 nextCust = 0;
1700
1701 if (!nativeDialogInUse)
1702 initWidgets();
1703
1704#ifdef Q_OS_WIN32
1705 dummyTransparentWindow.resize(1, 1);
1706 dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);
1707#endif
1708
1709 q->setCurrentColor(initial);
1710}
1711
1713{
1714 Q_Q(QColorDialog);
1715 QVBoxLayout *mainLay = new QVBoxLayout(q);
1716 // there's nothing in this dialog that benefits from sizing up
1717 mainLay->setSizeConstraint(QLayout::SetFixedSize);
1718
1719 QHBoxLayout *topLay = new QHBoxLayout();
1720 mainLay->addLayout(topLay);
1721
1722 leftLay = nullptr;
1723
1724#if defined(QT_SMALL_COLORDIALOG)
1725 smallDisplay = true;
1726 const int lumSpace = 20;
1727#else
1728 // small displays (e.g. PDAs) cannot fit the full color dialog,
1729 // so just use the color picker.
1731 const int lumSpace = topLay->spacing() / 2;
1732#endif
1733
1734 if (!smallDisplay) {
1735 leftLay = new QVBoxLayout;
1736 topLay->addLayout(leftLay);
1737
1738 standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());
1739 lblBasicColors = new QLabel(q);
1740#ifndef QT_NO_SHORTCUT
1741 lblBasicColors->setBuddy(standard);
1742#endif
1745 leftLay->addWidget(lblBasicColors);
1746 leftLay->addWidget(standard);
1747
1748#if !defined(QT_SMALL_COLORDIALOG)
1749 if (supportsColorPicking()) {
1750 eyeDropperButton = new QPushButton();
1751 leftLay->addWidget(eyeDropperButton);
1752 lblScreenColorInfo = new QLabel("\n"_L1);
1753 leftLay->addWidget(lblScreenColorInfo);
1756 } else {
1757 eyeDropperButton = nullptr;
1758 lblScreenColorInfo = nullptr;
1759 }
1760#endif
1761
1762 leftLay->addStretch();
1763
1764 custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors());
1765 custom->setAcceptDrops(true);
1766
1769
1770 QObject::connect(custom, &QWellArray::colorChanged, q, [this] (int index, QRgb color) {
1771 QColorDialogOptions::setCustomColor(index, color);
1772 if (custom)
1773 custom->update();
1774 });
1775
1776 lblCustomColors = new QLabel(q);
1777#ifndef QT_NO_SHORTCUT
1778 lblCustomColors->setBuddy(custom);
1779#endif
1780 leftLay->addWidget(lblCustomColors);
1781 leftLay->addWidget(custom);
1782
1783 addCusBt = new QPushButton(q);
1785 leftLay->addWidget(addCusBt);
1786 } else {
1787 // better color picker size for small displays
1788#if defined(QT_SMALL_COLORDIALOG)
1789 QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size();
1790 pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
1791 pHeight -= 20;
1792 if (screenSize.height() > screenSize.width())
1793 pWidth -= 20;
1794#else
1795 pWidth = 150;
1796 pHeight = 100;
1797#endif
1798 custom = nullptr;
1799 standard = nullptr;
1800 }
1801
1802 QVBoxLayout *rightLay = new QVBoxLayout;
1803 topLay->addLayout(rightLay);
1804
1805 QHBoxLayout *pickLay = new QHBoxLayout;
1806 rightLay->addLayout(pickLay);
1807
1808 QVBoxLayout *cLay = new QVBoxLayout;
1809 pickLay->addLayout(cLay);
1810 cp = new QColorPicker(q);
1811
1812 cp->setFrameStyle(QFrame::Panel | QFrame::Sunken);
1813
1814#if defined(QT_SMALL_COLORDIALOG)
1815 cp->hide();
1816#else
1817 cLay->addSpacing(lumSpace);
1818 cLay->addWidget(cp);
1819#endif
1820 cLay->addSpacing(lumSpace);
1821
1822 lp = new QColorLuminancePicker(q);
1823#if defined(QT_SMALL_COLORDIALOG)
1824 lp->hide();
1825#else
1826 lp->setFixedWidth(20);
1827 pickLay->addSpacing(10);
1828 pickLay->addWidget(lp);
1829 pickLay->addStretch();
1830#endif
1831
1834
1835 rightLay->addStretch();
1836
1837 cs = new QColorShower(q);
1838 pickLay->setContentsMargins(cs->gl->contentsMargins());
1843#if defined(QT_SMALL_COLORDIALOG)
1844 topLay->addWidget(cs);
1845#else
1846 rightLay->addWidget(cs);
1847 if (leftLay)
1848 leftLay->addSpacing(cs->gl->contentsMargins().right());
1849#endif
1850
1851 buttons = new QDialogButtonBox(q);
1852 mainLay->addWidget(buttons);
1853
1854 ok = buttons->addButton(QDialogButtonBox::Ok);
1856 ok->setDefault(true);
1857 cancel = buttons->addButton(QDialogButtonBox::Cancel);
1859
1860#ifdef Q_OS_WIN32
1861 updateTimer = new QTimer(q);
1863 this, qOverload<>(&QColorDialogPrivate::updateColorPicking));
1864#endif
1865 retranslateStrings();
1866}
1867
1869{
1870 QColorDialog *d = q_func();
1871 auto *colorDialogHelper = static_cast<QPlatformColorDialogHelper*>(h);
1876 colorDialogHelper->setOptions(options);
1877}
1878
1880{
1881 options->setWindowTitle(q_func()->windowTitle());
1882}
1883
1885{
1886 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
1887 if (custom)
1888 custom->update();
1889 nextCust = (nextCust+1) % QColorDialogOptions::customColorCount();
1890}
1891
1893{
1894 if (nativeDialogInUse)
1895 return;
1896
1897 if (!smallDisplay) {
1898 lblBasicColors->setText(QColorDialog::tr("&Basic colors"));
1899 lblCustomColors->setText(QColorDialog::tr("&Custom colors"));
1900 addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));
1901#if !defined(QT_SMALL_COLORDIALOG)
1902 if (eyeDropperButton)
1903 eyeDropperButton->setText(QColorDialog::tr("&Pick Screen Color"));
1904#endif
1905 }
1906
1907 cs->retranslateStrings();
1908}
1909
1911{
1912 const auto integration = QGuiApplicationPrivate::platformIntegration();
1913 return integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
1914 || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking);
1915}
1916
1918{
1919 // Don't use Q_Q here! This function is called from ~QDialog,
1920 // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).
1921 const QDialog * const q = static_cast<const QDialog*>(q_ptr);
1922 if (nativeDialogInUse)
1923 return true;
1925 || q->testAttribute(Qt::WA_DontShowOnScreen)
1926 || (options->options() & QColorDialog::DontUseNativeDialog)) {
1927 return false;
1928 }
1929
1930 return strcmp(QColorDialog::staticMetaObject.className(), q->metaObject()->className()) == 0;
1931}
1932
1933static const Qt::WindowFlags qcd_DefaultWindowFlags =
1936
1982 : QColorDialog(QColor(Qt::white), parent)
1983{
1984}
1985
1994{
1995 Q_D(QColorDialog);
1996 d->init(initial);
1997}
1998
2000{
2001 if (nativeDialogInUse) {
2003 return;
2004 }
2005
2006 if (setColorMode & ShowColor) {
2008 setCurrentAlpha(color.alpha());
2009 }
2010 if (setColorMode & SelectColor)
2012}
2013
2020{
2021 Q_D(QColorDialog);
2022 d->setCurrentColor(color);
2023}
2024
2026{
2027 Q_D(const QColorDialog);
2028 return d->currentQColor();
2029}
2030
2040{
2041 Q_D(const QColorDialog);
2042 return d->selectedQColor;
2043}
2044
2052{
2053 const QColorDialog::ColorDialogOptions previousOptions = options();
2054 if (!(previousOptions & option) != !on)
2055 setOptions(previousOptions ^ option);
2056}
2057
2067{
2068 Q_D(const QColorDialog);
2069 return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
2070}
2071
2084void QColorDialog::setOptions(ColorDialogOptions options)
2085{
2086 Q_D(QColorDialog);
2087
2089 return;
2090
2091 d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));
2092 if ((options & DontUseNativeDialog) && d->nativeDialogInUse) {
2093 d->nativeDialogInUse = false;
2094 d->initWidgets();
2095 }
2096 if (!d->nativeDialogInUse) {
2097 d->buttons->setVisible(!(options & NoButtons));
2098 d->showAlpha(options & ShowAlphaChannel);
2099 if (d->eyeDropperButton)
2100 d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton));
2101 }
2102}
2103
2104QColorDialog::ColorDialogOptions QColorDialog::options() const
2105{
2106 Q_D(const QColorDialog);
2107 return QColorDialog::ColorDialogOptions(int(d->options->options()));
2108}
2109
2150{
2151 // will call QColorDialogPrivate::setVisible override
2153}
2154
2163{
2164 Q_Q(QColorDialog);
2165
2166 if (visible)
2168
2169 if (nativeDialogInUse) {
2170 if (setNativeDialogVisible(visible)) {
2171 // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
2172 // updates the state correctly, but skips showing the non-native version:
2173 q->setAttribute(Qt::WA_DontShowOnScreen);
2174 } else {
2175 initWidgets();
2176 }
2177 } else {
2178 q->setAttribute(Qt::WA_DontShowOnScreen, false);
2179 }
2180
2182}
2183
2192void QColorDialog::open(QObject *receiver, const char *member)
2193{
2194 Q_D(QColorDialog);
2195 connect(this, SIGNAL(colorSelected(QColor)), receiver, member);
2196 d->receiverToDisconnectOnClose = receiver;
2197 d->memberToDisconnectOnClose = member;
2198 QDialog::open();
2199}
2200
2212 ColorDialogOptions options)
2213{
2214 QColorDialog dlg(parent);
2215 if (!title.isEmpty())
2216 dlg.setWindowTitle(title);
2217 dlg.setOptions(options);
2218 dlg.setCurrentColor(initial);
2219 dlg.exec();
2220 return dlg.selectedColor();
2221}
2222
2230
2235{
2236 Q_D(QColorDialog);
2237 if (e->type() == QEvent::LanguageChange)
2238 d->retranslateStrings();
2240}
2241
2243{
2244#ifndef QT_NO_CURSOR
2245 Q_Q(QColorDialog);
2246 static QPoint lastGlobalPos;
2247 QPoint newGlobalPos = QCursor::pos();
2248 if (lastGlobalPos == newGlobalPos)
2249 return;
2250 lastGlobalPos = newGlobalPos;
2251
2252 if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called
2253 updateColorPicking(newGlobalPos);
2254#ifdef Q_OS_WIN32
2255 dummyTransparentWindow.setPosition(newGlobalPos);
2256#endif
2257 }
2258#endif // ! QT_NO_CURSOR
2259}
2260
2262{
2263 const QColor color = grabScreenColor(globalPos);
2264 // QTBUG-39792, do not change standard, custom color selectors while moving as
2265 // otherwise it is not possible to pre-select a custom cell for assignment.
2267 updateColorLabelText(globalPos);
2268}
2269
2271{
2272 // If the cross is visible the grabbed color will be black most of the times
2274
2276 return true;
2277}
2278
2285
2287{
2288 Q_Q(QColorDialog);
2289#if QT_CONFIG(shortcut)
2290 if (e->matches(QKeySequence::Cancel)) {
2292 q->setCurrentColor(beforeScreenColorPicking);
2293 } else
2294#endif
2295 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
2296 q->setCurrentColor(grabScreenColor(QCursor::pos()));
2298 }
2299 e->accept();
2300 return true;
2301}
2302
2311{
2312 Q_D(QColorDialog);
2313 if (result == Accepted) {
2314 d->selectedQColor = d->currentQColor();
2315 emit colorSelected(d->selectedQColor);
2316 } else {
2317 d->selectedQColor = QColor();
2318 }
2320 if (d->receiverToDisconnectOnClose) {
2322 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2323 d->receiverToDisconnectOnClose = nullptr;
2324 }
2325 d->memberToDisconnectOnClose.clear();
2326}
2327
2329
2330#include "qcolordialog.moc"
2331#include "moc_qcolordialog.cpp"
void clicked(bool checked=false)
This signal is emitted when the button is activated (i.e., pressed down then released while the mouse...
int startDragDistance
the minimum distance required for a drag and drop operation to start.
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)
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 setCurrentRgbColor(QRgb rgb)
QRgb currentColor() const
QPushButton * eyeDropperButton
void newColorTypedIn(QRgb rgb)
bool handleColorPickingKeyPress(QKeyEvent *e)
void newStandard(int, int)
QSharedPointer< QColorDialogOptions > options
void setVisible(bool visible) override
QDialogButtonBox * buttons
bool supportsColorPicking() const
QVBoxLayout * leftLay
virtual void initHelper(QPlatformDialogHelper *h) override
QByteArray memberToDisconnectOnClose
QPointer< QObject > receiverToDisconnectOnClose
QPushButton * addCusBt
void newHsv(int h, int s, int v)
QColorPickingEventFilter * colorPickingEventFilter
virtual void helperPrepareShow(QPlatformDialogHelper *h) override
void newCustom(int, int)
QPlatformColorDialogHelper * platformColorDialogHelper() const
void nextCustom(int, int)
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
void setVisible(bool visible) override
Changes the visibility of the dialog.
static QColor customColor(int index)
void changeEvent(QEvent *event) override
\reimp
void setCurrentColor(const QColor &color)
void currentColorChanged(const QColor &color)
This signal is emitted whenever the current color changes in the dialog.
void setOptions(ColorDialogOptions options)
static int customCount()
Returns the number of custom colors supported by QColorDialog.
QColorDialog(QWidget *parent=nullptr)
void done(int result) override
Closes the dialog and sets its result code to result.
~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:503
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...
bool setNativeDialogVisible(bool visible)
Definition qdialog.cpp:162
virtual void setVisible(bool visible)
Definition qdialog.cpp:754
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 void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition qdialog.cpp:639
@ Accepted
Definition qdialog.h:30
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition qdialog.cpp:602
virtual void open()
Definition qdialog.cpp:503
void setVisible(bool visible) override
\reimp
Definition qdialog.cpp:744
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition qdialog.cpp:628
\inmodule QtGui
Definition qdrag.h:22
\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
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
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
QRgb pixel(int x, int y) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qimage.cpp:2493
@ Format_RGB32
Definition qimage.h:46
The QKeyEvent class describes a key event.
Definition qevent.h:424
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
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
@ 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 textEdited(const QString &)
This signal is emitted whenever the text is edited.
void setValidator(const QValidator *)
Sets the validator for values of line edit to v.
void setReadOnly(bool)
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:196
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition qevent.h:492
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:480
int width() const
Returns the width of the pixmap.
Definition qpixmap.cpp:468
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition qpixmap.cpp:850
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:1437
The QPlatformColorDialogHelper class allows for platform-specific customization of color dialogs.
virtual void setCurrentColor(const QColor &)=0
void currentColorChanged(const QColor &color)
void colorSelected(const QColor &color)
virtual QColor currentColor() const =0
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
void colorPicked(const QColor &color)
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
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:239
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
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:370
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:855
constexpr void setRect(int x, int y, int w, int h) noexcept
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
Definition qrect.h:346
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
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:245
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
\inmodule QtCore \reentrant
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
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
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:483
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
Definition qevent.h:123
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
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:197
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
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:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
QString & prepend(QChar c)
Definition qstring.h:478
\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
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
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:9461
void setSizePolicy(QSizePolicy)
void setMinimumWidth(int minw)
Definition qwidget.cpp:4112
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:7667
bool close()
Closes this widget.
Definition qwidget.cpp:8562
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7822
void hide()
Hides the widget.
Definition qwidget.cpp:8135
void setMinimumHeight(int minh)
Definition qwidget.cpp:4121
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
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:9382
friend class QPixmap
Definition qwidget.h:748
bool isRightToLeft() const
Definition qwidget.h:419
QStyle * style() const
Definition qwidget.cpp:2600
bool hasFocus() const
Definition qwidget.cpp:6446
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:9822
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 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)
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
QPushButton
[1]
void colorChanged()
rect
[4]
QPixmap pix
QStyleOptionButton opt
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
Definition qcompare.h:63
@ AlignRight
Definition qnamespace.h:146
@ AlignVCenter
Definition qnamespace.h:155
@ NoButton
Definition qnamespace.h:57
@ WA_DontShowOnScreen
Definition qnamespace.h:383
@ WA_NoSystemBackground
Definition qnamespace.h:291
@ StrongFocus
Definition qnamespace.h:110
@ CrossCursor
@ white
Definition qnamespace.h:31
@ black
Definition qnamespace.h:30
@ Key_Return
Definition qnamespace.h:667
@ Key_Right
Definition qnamespace.h:679
@ Key_Enter
Definition qnamespace.h:668
@ Key_Space
Definition qnamespace.h:513
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ AA_DontUseNativeDialogs
Definition qnamespace.h:458
@ CopyAction
@ FramelessWindowHint
Definition qnamespace.h:225
@ Dialog
Definition qnamespace.h:208
@ Tool
Definition qnamespace.h:212
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowSystemMenuHint
Definition qnamespace.h:227
@ WindowCloseButtonHint
Definition qnamespace.h:241
#define rgb(r, g, b)
Definition qcolor.cpp:124
static int pHeight
QtPrivate::QColorShower QColorShower
static void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
QtPrivate::QColorWell QColorWell
static const Qt::WindowFlags qcd_DefaultWindowFlags
QtPrivate::QColorPickingEventFilter QColorPickingEventFilter
QtPrivate::QColorLuminancePicker QColorLuminancePicker
QtPrivate::QColorPicker QColorPicker
static int pWidth
@ customColorRows
@ colorColumns
@ standardColorRows
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 SIGNAL(a)
Definition qobjectdefs.h:53
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
GLuint color
[2]
GLboolean GLboolean g
GLuint name
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
GLdouble s
[6]
Definition qopenglext.h:235
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]
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:34
static 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)