qcolordialog.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qcolordialog.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10namespace {-
11class QColorLuminancePicker;-
12class QColorPicker;-
13class QColorShower;-
14class QWellArray;-
15class QColorPickingEventFilter;-
16}-
17-
18class QColorDialogPrivate : public QDialogPrivate-
19{-
20 inline QColorDialog* q_func() { return static_cast<QColorDialog *>(q_ptr); } inline const QColorDialog* q_func() const { return static_cast<const QColorDialog *>(q_ptr); } friend class QColorDialog;-
21-
22public:-
23 enum SetColorMode {-
24 ShowColor = 0x1,-
25 SelectColor = 0x2,-
26 SetColorAll = ShowColor | SelectColor-
27 };-
28-
29 QColorDialogPrivate() : options(new QColorDialogOptions)-
30-
31-
32-
33 {}-
34-
35 QPlatformColorDialogHelper *platformColorDialogHelper() const-
36 { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); }-
37-
38 void init(const QColor &initial);-
39 void initWidgets();-
40 QRgb currentColor() const;-
41 QColor currentQColor() const;-
42 void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll);-
43 void setCurrentRgbColor(QRgb rgb);-
44 void setCurrentQColor(const QColor &color);-
45 bool selectColor(const QColor &color);-
46 QColor grabScreenColor(const QPoint &p);-
47-
48 int currentAlpha() const;-
49 void setCurrentAlpha(int a);-
50 void showAlpha(bool b);-
51 bool isAlphaVisible() const;-
52 void retranslateStrings();-
53-
54 void _q_addCustom();-
55-
56 void _q_newHsv(int h, int s, int v);-
57 void _q_newColorTypedIn(QRgb rgb);-
58 void _q_nextCustom(int, int);-
59 void _q_newCustom(int, int);-
60 void _q_newStandard(int, int);-
61 void _q_pickScreenColor();-
62 void _q_updateColorPicking();-
63 void updateColorLabelText(const QPoint &);-
64 void updateColorPicking(const QPoint &pos);-
65 void releaseColorPicking();-
66 bool handleColorPickingMouseMove(QMouseEvent *e);-
67 bool handleColorPickingMouseButtonRelease(QMouseEvent *e);-
68 bool handleColorPickingKeyPress(QKeyEvent *e);-
69-
70 bool canBeNativeDialog() const override;-
71-
72 QWellArray *custom;-
73 QWellArray *standard;-
74-
75 QDialogButtonBox *buttons;-
76 QVBoxLayout *leftLay;-
77 QColorPicker *cp;-
78 QColorLuminancePicker *lp;-
79 QColorShower *cs;-
80 QLabel *lblBasicColors;-
81 QLabel *lblCustomColors;-
82 QLabel *lblScreenColorInfo;-
83 QPushButton *ok;-
84 QPushButton *cancel;-
85 QPushButton *addCusBt;-
86 QPushButton *screenColorPickerButton;-
87 QColor selectedQColor;-
88 int nextCust;-
89 bool smallDisplay;-
90 bool screenColorPicking;-
91 QColorPickingEventFilter *colorPickingEventFilter;-
92 QRgb beforeScreenColorPicking;-
93 QSharedPointer<QColorDialogOptions> options;-
94-
95 QPointer<QObject> receiverToDisconnectOnClose;-
96 QByteArray memberToDisconnectOnClose;-
97-
98-
99-
100-
101-
102private:-
103 virtual void initHelper(QPlatformDialogHelper *h) override;-
104 virtual void helperPrepareShow(QPlatformDialogHelper *h) override;-
105};-
106-
107-
108-
109namespace {-
110-
111class QWellArray : public QWidget-
112{-
113 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
114#pragma GCC diagnostic push-
115 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
116#pragma GCC diagnostic pop-
117 struct QPrivateSignal {};-
118 -
119 -
120-
121public:-
122 QWellArray(int rows, int cols, QWidget* parent=0);-
123 ~QWellArray() {}-
124 QString cellContent(int row, int col) const;-
125-
126 int selectedColumn() const { return selCol; }-
127 int selectedRow() const { return selRow; }-
128-
129 virtual void setCurrent(int row, int col);-
130 virtual void setSelected(int row, int col);-
131-
132 QSize sizeHint() const override;-
133-
134 inline int cellWidth() const-
135 { return cellw; }-
136-
137 inline int cellHeight() const-
138 { return cellh; }-
139-
140 inline int rowAt(int y) const-
141 { return y / cellh; }-
142-
143 inline int columnAt(int x) const-
144 { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }-
145-
146 inline int rowY(int row) const-
147 { return cellh * row; }-
148-
149 inline int columnX(int column) const-
150 { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }-
151-
152 inline int numRows() const-
153 { return nrows; }-
154-
155 inline int numCols() const-
156 {return ncols; }-
157-
158 inline QRect cellRect() const-
159 { return QRect(0, 0, cellw, cellh); }-
160-
161 inline QSize gridSize() const-
162 { return QSize(ncols * cellw, nrows * cellh); }-
163-
164 QRect cellGeometry(int row, int column)-
165 {-
166 QRect r;-
167 if (row >= 0 && row < nrows && column >= 0 && column < ncols)-
168 r.setRect(columnX(column), rowY(row), cellw, cellh);-
169 return r;-
170 }-
171-
172 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }-
173-
174public :-
175 void selected(int row, int col);-
176 void currentChanged(int row, int col);-
177-
178protected:-
179 virtual void paintCell(QPainter *, int row, int col, const QRect&);-
180 virtual void paintCellContents(QPainter *, int row, int col, const QRect&);-
181-
182 void mousePressEvent(QMouseEvent*) override;-
183 void mouseReleaseEvent(QMouseEvent*) override;-
184 void keyPressEvent(QKeyEvent*) override;-
185 void focusInEvent(QFocusEvent*) override;-
186 void focusOutEvent(QFocusEvent*) override;-
187 void paintEvent(QPaintEvent *) override;-
188-
189private:-
190 QWellArray(const QWellArray &) = delete; QWellArray &operator=(const QWellArray &) = delete;-
191-
192 int nrows;-
193 int ncols;-
194 int cellw;-
195 int cellh;-
196 int curRow;-
197 int curCol;-
198 int selRow;-
199 int selCol;-
200};-
201-
202void QWellArray::paintEvent(QPaintEvent *e)-
203{-
204 QRect r = e->rect();-
205 int cx = r.x();-
206 int cy = r.y();-
207 int ch = r.height();-
208 int cw = r.width();-
209 int colfirst = columnAt(cx);-
210 int collast = columnAt(cx + cw);-
211 int rowfirst = rowAt(cy);-
212 int rowlast = rowAt(cy + ch);-
213-
214 if (isRightToLeft()) {-
215 int t = colfirst;-
216 colfirst = collast;-
217 collast = t;-
218 }-
219-
220 QPainter painter(this);-
221 QPainter *p = &painter;-
222 QRect rect(0, 0, cellWidth(), cellHeight());-
223-
224-
225 if (collast < 0 || collast >= ncols)-
226 collast = ncols-1;-
227 if (rowlast < 0 || rowlast >= nrows)-
228 rowlast = nrows-1;-
229-
230-
231 for (int r = rowfirst; r <= rowlast; ++r) {-
232-
233 int rowp = rowY(r);-
234-
235-
236-
237-
238 for (int c = colfirst; c <= collast; ++c) {-
239-
240 int colp = columnX(c);-
241-
242 rect.translate(colp, rowp);-
243 paintCell(p, r, c, rect);-
244 rect.translate(-colp, -rowp);-
245 }-
246 }-
247}-
248-
249QWellArray::QWellArray(int rows, int cols, QWidget *parent)-
250 : QWidget(parent)-
251 ,nrows(rows), ncols(cols)-
252{-
253 setFocusPolicy(Qt::StrongFocus);-
254 cellw = 28;-
255 cellh = 24;-
256 curCol = 0;-
257 curRow = 0;-
258 selCol = -1;-
259 selRow = -1;-
260}-
261-
262QSize QWellArray::sizeHint() const-
263{-
264 ensurePolished();-
265 return gridSize().boundedTo(QSize(640, 480));-
266}-
267-
268-
269void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)-
270{-
271 int b = 3;-
272-
273 const QPalette & g = palette();-
274 QStyleOptionFrame opt;-
275 int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);-
276 opt.lineWidth = dfw;-
277 opt.midLineWidth = 1;-
278 opt.rect = rect.adjusted(b, b, -b, -b);-
279 opt.palette = g;-
280 opt.state = QStyle::State_Enabled | QStyle::State_Sunken;-
281 style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this);-
282 b += dfw;-
283-
284 if ((row == curRow) && (col == curCol)) {-
285 if (hasFocus()) {-
286 QStyleOptionFocusRect opt;-
287 opt.palette = g;-
288 opt.rect = rect;-
289 opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange;-
290 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this);-
291 }-
292 }-
293 paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));-
294}-
295-
296-
297-
298-
299void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)-
300{-
301 (void)row;;-
302 (void)col;;-
303 p->fillRect(r, Qt::white);-
304 p->setPen(Qt::black);-
305 p->drawLine(r.topLeft(), r.bottomRight());-
306 p->drawLine(r.topRight(), r.bottomLeft());-
307}-
308-
309void QWellArray::mousePressEvent(QMouseEvent *e)-
310{-
311-
312 QPoint pos = e->pos();-
313 setCurrent(rowAt(pos.y()), columnAt(pos.x()));-
314}-
315-
316void QWellArray::mouseReleaseEvent(QMouseEvent * )-
317{-
318-
319 setSelected(curRow, curCol);-
320}-
321-
322-
323-
324-
325-
326-
327-
328void QWellArray::setCurrent(int row, int col)-
329{-
330 if ((curRow == row) && (curCol == col))-
331 return;-
332-
333 if (row < 0 || col < 0)-
334 row = col = -1;-
335-
336 int oldRow = curRow;-
337 int oldCol = curCol;-
338-
339 curRow = row;-
340 curCol = col;-
341-
342 updateCell(oldRow, oldCol);-
343 updateCell(curRow, curCol);-
344-
345 currentChanged(curRow, curCol);-
346}-
347-
348-
349-
350-
351-
352-
353-
354void QWellArray::setSelected(int row, int col)-
355{-
356 int oldRow = selRow;-
357 int oldCol = selCol;-
358-
359 if (row < 0 || col < 0)-
360 row = col = -1;-
361-
362 selCol = col;-
363 selRow = row;-
364-
365 updateCell(oldRow, oldCol);-
366 updateCell(selRow, selCol);-
367 if (row >= 0)-
368 selected(row, col);-
369-
370-
371 if (isVisible() && qobject_cast<QMenu*>(parentWidget()))-
372 parentWidget()->close();-
373-
374}-
375-
376void QWellArray::focusInEvent(QFocusEvent*)-
377{-
378 updateCell(curRow, curCol);-
379 currentChanged(curRow, curCol);-
380}-
381-
382-
383-
384-
385void QWellArray::focusOutEvent(QFocusEvent*)-
386{-
387 updateCell(curRow, curCol);-
388}-
389-
390-
391-
392void QWellArray::keyPressEvent(QKeyEvent* e)-
393{-
394 switch(e->key()) {-
395 case Qt::Key_Left:-
396 if(curCol > 0)-
397 setCurrent(curRow, curCol - 1);-
398 break;-
399 case Qt::Key_Right:-
400 if(curCol < numCols()-1)-
401 setCurrent(curRow, curCol + 1);-
402 break;-
403 case Qt::Key_Up:-
404 if(curRow > 0)-
405 setCurrent(curRow - 1, curCol);-
406 break;-
407 case Qt::Key_Down:-
408 if(curRow < numRows()-1)-
409 setCurrent(curRow + 1, curCol);-
410 break;-
411 case Qt::Key_Space:-
412 setSelected(curRow, curCol);-
413 break;-
414 default:-
415 e->ignore();-
416 return;-
417 }-
418-
419}-
420-
421-
422-
423-
424class QColorPickingEventFilter : public QObject {-
425public:-
426 explicit QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent = 0) : QObject(parent), m_dp(dp) {}-
427-
428 bool eventFilter(QObject *, QEvent *event) override-
429 {-
430 switch (event->type()) {-
431 case QEvent::MouseMove:-
432 return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));-
433 case QEvent::MouseButtonRelease:-
434 return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));-
435 case QEvent::KeyPress:-
436 return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));-
437 default:-
438 break;-
439 }-
440 return false;-
441 }-
442-
443private:-
444 QColorDialogPrivate *m_dp;-
445};-
446-
447}-
448-
449-
450-
451-
452-
453int QColorDialog::customCount()-
454{-
455 return QColorDialogOptions::customColorCount();-
456}-
457-
458-
459-
460-
461-
462-
463QColor QColorDialog::customColor(int index)-
464{-
465 return QColor(QColorDialogOptions::customColor(index));-
466}-
467void QColorDialog::setCustomColor(int index, QColor color)-
468{-
469 QColorDialogOptions::setCustomColor(index, color.rgba());-
470}-
471-
472-
473-
474-
475-
476-
477QColor QColorDialog::standardColor(int index)-
478{-
479 return QColor(QColorDialogOptions::standardColor(index));-
480}-
481void QColorDialog::setStandardColor(int index, QColor color)-
482{-
483 QColorDialogOptions::setStandardColor(index, color.rgba());-
484}-
485-
486static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)-
487{-
488 QColor c;-
489 c.setRgb(rgb);-
490 c.getHsv(&h, &s, &v);-
491}-
492-
493namespace {-
494-
495class QColorWell : public QWellArray-
496{-
497public:-
498 QColorWell(QWidget *parent, int r, int c, QRgb *vals)-
499 :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1)-
500 { setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); }-
501-
502protected:-
503 void paintCellContents(QPainter *, int row, int col, const QRect&) override;-
504 void mousePressEvent(QMouseEvent *e) override;-
505 void mouseMoveEvent(QMouseEvent *e) override;-
506 void mouseReleaseEvent(QMouseEvent *e) override;-
507-
508 void dragEnterEvent(QDragEnterEvent *e) override;-
509 void dragLeaveEvent(QDragLeaveEvent *e) override;-
510 void dragMoveEvent(QDragMoveEvent *e) override;-
511 void dropEvent(QDropEvent *e) override;-
512-
513-
514private:-
515 QRgb *values;-
516 bool mousePressed;-
517 QPoint pressPos;-
518 QPoint oldCurrent;-
519-
520};-
521-
522void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)-
523{-
524 int i = row + col*numRows();-
525 p->fillRect(r, QColor(values[i]));-
526}-
527-
528void QColorWell::mousePressEvent(QMouseEvent *e)-
529{-
530 oldCurrent = QPoint(selectedRow(), selectedColumn());-
531 QWellArray::mousePressEvent(e);-
532 mousePressed = true;-
533 pressPos = e->pos();-
534}-
535-
536void QColorWell::mouseMoveEvent(QMouseEvent *e)-
537{-
538 QWellArray::mouseMoveEvent(e);-
539-
540 if (!mousePressed)-
541 return;-
542 if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {-
543 setCurrent(oldCurrent.x(), oldCurrent.y());-
544 int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows();-
545 QColor col(values[i]);-
546 QMimeData *mime = new QMimeData;-
547 mime->setColorData(col);-
548 QPixmap pix(cellWidth(), cellHeight());-
549 pix.fill(col);-
550 QPainter p(&pix);-
551 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);-
552 p.end();-
553 QDrag *drg = new QDrag(this);-
554 drg->setMimeData(mime);-
555 drg->setPixmap(pix);-
556 mousePressed = false;-
557 drg->start();-
558 }-
559-
560}-
561-
562-
563void QColorWell::dragEnterEvent(QDragEnterEvent *e)-
564{-
565 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())-
566 e->accept();-
567 else-
568 e->ignore();-
569}-
570-
571void QColorWell::dragLeaveEvent(QDragLeaveEvent *)-
572{-
573 if (hasFocus())-
574 parentWidget()->setFocus();-
575}-
576-
577void QColorWell::dragMoveEvent(QDragMoveEvent *e)-
578{-
579 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) {-
580 setCurrent(rowAt(e->pos().y()), columnAt(e->pos().x()));-
581 e->accept();-
582 } else {-
583 e->ignore();-
584 }-
585}-
586-
587void QColorWell::dropEvent(QDropEvent *e)-
588{-
589 QColor col = qvariant_cast<QColor>(e->mimeData()->colorData());-
590 if (col.isValid()) {-
591 int i = rowAt(e->pos().y()) + columnAt(e->pos().x()) * numRows();-
592 values[i] = col.rgb();-
593 update();-
594 e->accept();-
595 } else {-
596 e->ignore();-
597 }-
598}-
599-
600-
601-
602void QColorWell::mouseReleaseEvent(QMouseEvent *e)-
603{-
604 if (!mousePressed)-
605 return;-
606 QWellArray::mouseReleaseEvent(e);-
607 mousePressed = false;-
608}-
609-
610class QColorPicker : public QFrame-
611{-
612 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
613#pragma GCC diagnostic push-
614 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
615#pragma GCC diagnostic pop-
616 struct QPrivateSignal {};-
617public:-
618 QColorPicker(QWidget* parent);-
619 ~QColorPicker();-
620-
621 void setCrossVisible(bool visible);-
622public :-
623 void setCol(int h, int s);-
624-
625public :-
626 void newCol(int h, int s);-
627-
628protected:-
629 QSize sizeHint() const override;-
630 void paintEvent(QPaintEvent*) override;-
631 void mouseMoveEvent(QMouseEvent *) override;-
632 void mousePressEvent(QMouseEvent *) override;-
633 void resizeEvent(QResizeEvent *) override;-
634-
635private:-
636 int hue;-
637 int sat;-
638-
639 QPoint colPt();-
640 int huePt(const QPoint &pt);-
641 int satPt(const QPoint &pt);-
642 void setCol(const QPoint &pt);-
643-
644 QPixmap pix;-
645 bool crossVisible;-
646};-
647-
648static int pWidth = 220;-
649static int pHeight = 200;-
650-
651class QColorLuminancePicker : public QWidget-
652{-
653 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
654#pragma GCC diagnostic push-
655 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
656#pragma GCC diagnostic pop-
657 struct QPrivateSignal {};-
658public:-
659 QColorLuminancePicker(QWidget* parent=0);-
660 ~QColorLuminancePicker();-
661-
662public :-
663 void setCol(int h, int s, int v);-
664 void setCol(int h, int s);-
665-
666public :-
667 void newHsv(int h, int s, int v);-
668-
669protected:-
670 void paintEvent(QPaintEvent*) override;-
671 void mouseMoveEvent(QMouseEvent *) override;-
672 void mousePressEvent(QMouseEvent *) override;-
673-
674private:-
675 enum { foff = 3, coff = 4 };-
676 int val;-
677 int hue;-
678 int sat;-
679-
680 int y2val(int y);-
681 int val2y(int val);-
682 void setVal(int v);-
683-
684 QPixmap *pix;-
685};-
686-
687-
688int QColorLuminancePicker::y2val(int y)-
689{-
690 int d = height() - 2*coff - 1;-
691 return 255 - (y - coff)*255/d;-
692}-
693-
694int QColorLuminancePicker::val2y(int v)-
695{-
696 int d = height() - 2*coff - 1;-
697 return coff + (255-v)*d/255;-
698}-
699-
700QColorLuminancePicker::QColorLuminancePicker(QWidget* parent)-
701 :QWidget(parent)-
702{-
703 hue = 100; val = 100; sat = 100;-
704 pix = 0;-
705-
706}-
707-
708QColorLuminancePicker::~QColorLuminancePicker()-
709{-
710 delete pix;-
711}-
712-
713void QColorLuminancePicker::mouseMoveEvent(QMouseEvent *m)-
714{-
715 setVal(y2val(m->y()));-
716}-
717void QColorLuminancePicker::mousePressEvent(QMouseEvent *m)-
718{-
719 setVal(y2val(m->y()));-
720}-
721-
722void QColorLuminancePicker::setVal(int v)-
723{-
724 if (val == v)-
725 return;-
726 val = qMax(0, qMin(v,255));-
727 delete pix; pix=0;-
728 repaint();-
729 newHsv(hue, sat, val);-
730}-
731-
732-
733void QColorLuminancePicker::setCol(int h, int s)-
734{-
735 setCol(h, s, val);-
736 newHsv(h, s, val);-
737}-
738-
739void QColorLuminancePicker::paintEvent(QPaintEvent *)-
740{-
741 int w = width() - 5;-
742-
743 QRect r(0, foff, w, height() - 2*foff);-
744 int wi = r.width() - 2;-
745 int hi = r.height() - 2;-
746 if (!pix || pix->height() != hi || pix->width() != wi) {-
747 delete pix;-
748 QImage img(wi, hi, QImage::Format_RGB32);-
749 int y;-
750 uint *pixel = (uint *) img.scanLine(0);-
751 for (y = 0; y < hi; y++) {-
752 uint *end = pixel + wi;-
753 std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb());-
754 pixel = end;-
755 }-
756 pix = new QPixmap(QPixmap::fromImage(img));-
757 }-
758 QPainter p(this);-
759 p.drawPixmap(1, coff, *pix);-
760 const QPalette &g = palette();-
761 qDrawShadePanel(&p, r, g, true);-
762 p.setPen(g.foreground().color());-
763 p.setBrush(g.foreground());-
764 QPolygon a;-
765 int y = val2y(val);-
766 a.setPoints(3, w, y, w+5, y+5, w+5, y-5);-
767 p.eraseRect(w, 0, 5, height());-
768 p.drawPolygon(a);-
769}-
770-
771void QColorLuminancePicker::setCol(int h, int s , int v)-
772{-
773 val = v;-
774 hue = h;-
775 sat = s;-
776 delete pix; pix=0;-
777 repaint();-
778}-
779-
780QPoint QColorPicker::colPt()-
781{-
782 QRect r = contentsRect();-
783 return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);-
784}-
785-
786int QColorPicker::huePt(const QPoint &pt)-
787{-
788 QRect r = contentsRect();-
789 return 360 - pt.x() * 360 / (r.width() - 1);-
790}-
791-
792int QColorPicker::satPt(const QPoint &pt)-
793{-
794 QRect r = contentsRect();-
795 return 255 - pt.y() * 255 / (r.height() - 1);-
796}-
797-
798void QColorPicker::setCol(const QPoint &pt)-
799{-
800 setCol(huePt(pt), satPt(pt));-
801}-
802-
803QColorPicker::QColorPicker(QWidget* parent)-
804 : QFrame(parent)-
805 , crossVisible(true)-
806{-
807 hue = 0; sat = 0;-
808 setCol(150, 255);-
809-
810 setAttribute(Qt::WA_NoSystemBackground);-
811 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );-
812}-
813-
814QColorPicker::~QColorPicker()-
815{-
816}-
817-
818void QColorPicker::setCrossVisible(bool visible)-
819{-
820 if (crossVisible != visible) {-
821 crossVisible = visible;-
822 update();-
823 }-
824}-
825-
826QSize QColorPicker::sizeHint() const-
827{-
828 return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());-
829}-
830-
831void QColorPicker::setCol(int h, int s)-
832{-
833 int nhue = qMin(qMax(0,h), 359);-
834 int nsat = qMin(qMax(0,s), 255);-
835 if (nhue == hue && nsat == sat)-
836 return;-
837-
838 QRect r(colPt(), QSize(20,20));-
839 hue = nhue; sat = nsat;-
840 r = r.united(QRect(colPt(), QSize(20,20)));-
841 r.translate(contentsRect().x()-9, contentsRect().y()-9);-
842-
843 repaint(r);-
844}-
845-
846void QColorPicker::mouseMoveEvent(QMouseEvent *m)-
847{-
848 QPoint p = m->pos() - contentsRect().topLeft();-
849 setCol(p);-
850 newCol(hue, sat);-
851}-
852-
853void QColorPicker::mousePressEvent(QMouseEvent *m)-
854{-
855 QPoint p = m->pos() - contentsRect().topLeft();-
856 setCol(p);-
857 newCol(hue, sat);-
858}-
859-
860void QColorPicker::paintEvent(QPaintEvent* )-
861{-
862 QPainter p(this);-
863 drawFrame(&p);-
864 QRect r = contentsRect();-
865-
866 p.drawPixmap(r.topLeft(), pix);-
867-
868 if (crossVisible) {-
869 QPoint pt = colPt() + r.topLeft();-
870 p.setPen(Qt::black);-
871 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);-
872 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);-
873 }-
874}-
875-
876void QColorPicker::resizeEvent(QResizeEvent *ev)-
877{-
878 QFrame::resizeEvent(ev);-
879-
880 int w = width() - frameWidth() * 2;-
881 int h = height() - frameWidth() * 2;-
882 QImage img(w, h, QImage::Format_RGB32);-
883 int x, y;-
884 uint *pixel = (uint *) img.scanLine(0);-
885 for (y = 0; y < h; y++) {-
886 const uint *end = pixel + w;-
887 x = 0;-
888 while (pixel < end) {-
889 QPoint p(x, y);-
890 QColor c;-
891 c.setHsv(huePt(p), satPt(p), 200);-
892 *pixel = c.rgb();-
893 ++pixel;-
894 ++x;-
895 }-
896 }-
897 pix = QPixmap::fromImage(img);-
898}-
899-
900-
901class QColSpinBox : public QSpinBox-
902{-
903public:-
904 QColSpinBox(QWidget *parent)-
905 : QSpinBox(parent) { setRange(0, 255); }-
906 void setValue(int i) {-
907 const QSignalBlocker blocker(this);-
908 QSpinBox::setValue(i);-
909 }-
910};-
911-
912class QColorShowLabel;-
913-
914class QColorShower : public QWidget-
915{-
916 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
917#pragma GCC diagnostic push-
918 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
919#pragma GCC diagnostic pop-
920 struct QPrivateSignal {};-
921public:-
922 QColorShower(QColorDialog *parent);-
923-
924-
925 void setHsv(int h, int s, int v);-
926-
927 int currentAlpha() const-
928 { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }-
929 void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); }-
930 void showAlpha(bool b);-
931 bool isAlphaVisible() const;-
932-
933 QRgb currentColor() const { return curCol; }-
934 QColor currentQColor() const { return curQColor; }-
935 void retranslateStrings();-
936 void updateQColor();-
937-
938public :-
939 void setRgb(QRgb rgb);-
940-
941public :-
942 void newCol(QRgb rgb);-
943 void currentColorChanged(const QColor &color);-
944-
945private :-
946 void rgbEd();-
947 void hsvEd();-
948 void htmlEd();-
949-
950private:-
951 void showCurrentColor();-
952 int hue, sat, val;-
953 QRgb curCol;-
954 QColor curQColor;-
955 QLabel *lblHue;-
956 QLabel *lblSat;-
957 QLabel *lblVal;-
958 QLabel *lblRed;-
959 QLabel *lblGreen;-
960 QLabel *lblBlue;-
961 QLabel *lblHtml;-
962 QColSpinBox *hEd;-
963 QColSpinBox *sEd;-
964 QColSpinBox *vEd;-
965 QColSpinBox *rEd;-
966 QColSpinBox *gEd;-
967 QColSpinBox *bEd;-
968 QColSpinBox *alphaEd;-
969 QLabel *alphaLab;-
970 QLineEdit *htEd;-
971 QColorShowLabel *lab;-
972 bool rgbOriginal;-
973 QColorDialog *colorDialog;-
974 QGridLayout *gl;-
975-
976 friend class ::QColorDialog;-
977 friend class ::QColorDialogPrivate;-
978};-
979-
980class QColorShowLabel : public QFrame-
981{-
982 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
983#pragma GCC diagnostic push-
984 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
985#pragma GCC diagnostic pop-
986 struct QPrivateSignal {};-
987-
988public:-
989 QColorShowLabel(QWidget *parent) : QFrame(parent) {-
990 setFrameStyle(QFrame::Panel|QFrame::Sunken);-
991 setAcceptDrops(true);-
992 mousePressed = false;-
993 }-
994 void setColor(QColor c) { col = c; }-
995-
996public :-
997 void colorDropped(QRgb);-
998-
999protected:-
1000 void paintEvent(QPaintEvent *) override;-
1001 void mousePressEvent(QMouseEvent *e) override;-
1002 void mouseMoveEvent(QMouseEvent *e) override;-
1003 void mouseReleaseEvent(QMouseEvent *e) override;-
1004-
1005 void dragEnterEvent(QDragEnterEvent *e) override;-
1006 void dragLeaveEvent(QDragLeaveEvent *e) override;-
1007 void dropEvent(QDropEvent *e) override;-
1008-
1009-
1010private:-
1011 QColor col;-
1012 bool mousePressed;-
1013 QPoint pressPos;-
1014};-
1015-
1016void QColorShowLabel::paintEvent(QPaintEvent *e)-
1017{-
1018 QPainter p(this);-
1019 drawFrame(&p);-
1020 p.fillRect(contentsRect()&e->rect(), col);-
1021}-
1022-
1023void QColorShower::showAlpha(bool b)-
1024{-
1025 alphaLab->setVisible(b);-
1026 alphaEd->setVisible(b);-
1027}-
1028-
1029inline bool QColorShower::isAlphaVisible() const-
1030{-
1031 return alphaLab->isVisible();-
1032}-
1033-
1034void QColorShowLabel::mousePressEvent(QMouseEvent *e)-
1035{-
1036 mousePressed = true;-
1037 pressPos = e->pos();-
1038}-
1039-
1040void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)-
1041{-
1042-
1043-
1044-
1045 if (!mousePressed)-
1046 return;-
1047 if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {-
1048 QMimeData *mime = new QMimeData;-
1049 mime->setColorData(col);-
1050 QPixmap pix(30, 20);-
1051 pix.fill(col);-
1052 QPainter p(&pix);-
1053 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);-
1054 p.end();-
1055 QDrag *drg = new QDrag(this);-
1056 drg->setMimeData(mime);-
1057 drg->setPixmap(pix);-
1058 mousePressed = false;-
1059 drg->start();-
1060 }-
1061-
1062}-
1063-
1064-
1065void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e)-
1066{-
1067 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())-
1068 e->accept();-
1069 else-
1070 e->ignore();-
1071}-
1072-
1073void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *)-
1074{-
1075}-
1076-
1077void QColorShowLabel::dropEvent(QDropEvent *e)-
1078{-
1079 QColor color = qvariant_cast<QColor>(e->mimeData()->colorData());-
1080 if (color.isValid()) {-
1081 col = color;-
1082 repaint();-
1083 colorDropped(col.rgb());-
1084 e->accept();-
1085 } else {-
1086 e->ignore();-
1087 }-
1088}-
1089-
1090-
1091void QColorShowLabel::mouseReleaseEvent(QMouseEvent *)-
1092{-
1093 if (!mousePressed)-
1094 return;-
1095 mousePressed = false;-
1096}-
1097-
1098QColorShower::QColorShower(QColorDialog *parent)-
1099 : QWidget(parent)-
1100{-
1101 colorDialog = parent;-
1102-
1103 curCol = qRgb(255, 255, 255);-
1104 curQColor = Qt::white;-
1105-
1106 gl = new QGridLayout(this);-
1107 gl->setMargin(gl->spacing());-
1108 lab = new QColorShowLabel(this);-
1109-
1110-
1111-
1112-
1113-
1114 lab->setMinimumWidth(60);-
1115-
1116-
1117-
1118-
1119-
1120-
1121-
1122 gl->addWidget(lab, 0, 0, -1, 1);-
1123-
1124-
1125-
1126 connect(lab, qFlagLocation("2""colorDropped(QRgb)" "\0" __FILE__ ":" "1193""1199"), this, qFlagLocation("2""newCol(QRgb)" "\0" __FILE__ ":" "1193""1199"));-
1127 connect(lab, qFlagLocation("2""colorDropped(QRgb)" "\0" __FILE__ ":" "1194""1200"), this, qFlagLocation("1""setRgb(QRgb)" "\0" __FILE__ ":" "1194""1200"));-
1128-
1129 hEd = new QColSpinBox(this);-
1130 hEd->setRange(0, 359);-
1131 lblHue = new QLabel(this);-
1132-
1133 lblHue->setBuddy(hEd);-
1134-
1135 lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1136-
1137 gl->addWidget(lblHue, 0, 1);-
1138 gl->addWidget(hEd, 0, 2);-
1139-
1140-
1141-
1142-
1143-
1144 sEd = new QColSpinBox(this);-
1145 lblSat = new QLabel(this);-
1146-
1147 lblSat->setBuddy(sEd);-
1148-
1149 lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1150-
1151 gl->addWidget(lblSat, 1, 1);-
1152 gl->addWidget(sEd, 1, 2);-
1153-
1154-
1155-
1156-
1157-
1158 vEd = new QColSpinBox(this);-
1159 lblVal = new QLabel(this);-
1160-
1161 lblVal->setBuddy(vEd);-
1162-
1163 lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1164-
1165 gl->addWidget(lblVal, 2, 1);-
1166 gl->addWidget(vEd, 2, 2);-
1167-
1168-
1169-
1170-
1171-
1172 rEd = new QColSpinBox(this);-
1173 lblRed = new QLabel(this);-
1174-
1175 lblRed->setBuddy(rEd);-
1176-
1177 lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1178-
1179 gl->addWidget(lblRed, 0, 3);-
1180 gl->addWidget(rEd, 0, 4);-
1181-
1182-
1183-
1184-
1185-
1186 gEd = new QColSpinBox(this);-
1187 lblGreen = new QLabel(this);-
1188-
1189 lblGreen->setBuddy(gEd);-
1190-
1191 lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1192-
1193 gl->addWidget(lblGreen, 1, 3);-
1194 gl->addWidget(gEd, 1, 4);-
1195-
1196-
1197-
1198-
1199-
1200 bEd = new QColSpinBox(this);-
1201 lblBlue = new QLabel(this);-
1202-
1203 lblBlue->setBuddy(bEd);-
1204-
1205 lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1206-
1207 gl->addWidget(lblBlue, 2, 3);-
1208 gl->addWidget(bEd, 2, 4);-
1209-
1210-
1211-
1212-
1213-
1214 alphaEd = new QColSpinBox(this);-
1215 alphaLab = new QLabel(this);-
1216-
1217 alphaLab->setBuddy(alphaEd);-
1218-
1219 alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1220-
1221 gl->addWidget(alphaLab, 3, 1, 1, 3);-
1222 gl->addWidget(alphaEd, 3, 4);-
1223-
1224-
1225-
1226-
1227 alphaEd->hide();-
1228 alphaLab->hide();-
1229 lblHtml = new QLabel(this);-
1230 htEd = new QLineEdit(this);-
1231-
1232 lblHtml->setBuddy(htEd);-
1233-
1234-
1235-
1236 QRegularExpression regExp(([]() -> QString { enum { Size = sizeof(u"" "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
1237 QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);-
1238 htEd->setValidator(validator);-
1239-
1240-
1241-
1242-
1243-
1244-
1245-
1246 htEd->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);-
1247-
1248 lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1249-
1250-
1251-
1252-
1253 gl->addWidget(lblHtml, 5, 1);-
1254 gl->addWidget(htEd, 5, 2, 1, 3);-
1255-
1256-
1257 connect(hEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1324""1330"), this, qFlagLocation("1""hsvEd()" "\0" __FILE__ ":" "1324""1330"));-
1258 connect(sEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1325""1331"), this, qFlagLocation("1""hsvEd()" "\0" __FILE__ ":" "1325""1331"));-
1259 connect(vEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1326""1332"), this, qFlagLocation("1""hsvEd()" "\0" __FILE__ ":" "1326""1332"));-
1260-
1261 connect(rEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1328""1334"), this, qFlagLocation("1""rgbEd()" "\0" __FILE__ ":" "1328""1334"));-
1262 connect(gEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1329""1335"), this, qFlagLocation("1""rgbEd()" "\0" __FILE__ ":" "1329""1335"));-
1263 connect(bEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1330""1336"), this, qFlagLocation("1""rgbEd()" "\0" __FILE__ ":" "1330""1336"));-
1264 connect(alphaEd, qFlagLocation("2""valueChanged(int)" "\0" __FILE__ ":" "1331""1337"), this, qFlagLocation("1""rgbEd()" "\0" __FILE__ ":" "1331""1337"));-
1265 connect(htEd, qFlagLocation("2""textEdited(QString)" "\0" __FILE__ ":" "1332""1338"), this, qFlagLocation("1""htmlEd()" "\0" __FILE__ ":" "1332""1338"));-
1266-
1267 retranslateStrings();-
1268}-
1269-
1270}-
1271-
1272inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); }-
1273inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); }-
1274inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); }-
1275inline void QColorDialogPrivate::showAlpha(bool b) { cs->showAlpha(b); }-
1276inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisible(); }-
1277-
1278QColor QColorDialogPrivate::currentQColor() const-
1279{-
1280 if (nativeDialogInUse)-
1281 return platformColorDialogHelper()->currentColor();-
1282 return cs->currentQColor();-
1283}-
1284-
1285void QColorShower::showCurrentColor()-
1286{-
1287 lab->setColor(currentColor());-
1288 lab->repaint();-
1289}-
1290-
1291void QColorShower::rgbEd()-
1292{-
1293 rgbOriginal = true;-
1294 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());-
1295-
1296 rgb2hsv(currentColor(), hue, sat, val);-
1297-
1298 hEd->setValue(hue);-
1299 sEd->setValue(sat);-
1300 vEd->setValue(val);-
1301-
1302 htEd->setText(QColor(curCol).name());-
1303-
1304 showCurrentColor();-
1305 newCol(currentColor());-
1306 updateQColor();-
1307}-
1308-
1309void QColorShower::hsvEd()-
1310{-
1311 rgbOriginal = false;-
1312 hue = hEd->value();-
1313 sat = sEd->value();-
1314 val = vEd->value();-
1315-
1316 QColor c;-
1317 c.setHsv(hue, sat, val);-
1318 curCol = c.rgb();-
1319-
1320 rEd->setValue(qRed(currentColor()));-
1321 gEd->setValue(qGreen(currentColor()));-
1322 bEd->setValue(qBlue(currentColor()));-
1323-
1324 htEd->setText(c.name());-
1325-
1326 showCurrentColor();-
1327 newCol(currentColor());-
1328 updateQColor();-
1329}-
1330-
1331void QColorShower::htmlEd()-
1332{-
1333 QColor c;-
1334 QString t = htEd->text();-
1335 c.setNamedColor(t);-
1336 if (!c.isValid())-
1337 return;-
1338 curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());-
1339 rgb2hsv(curCol, hue, sat, val);-
1340-
1341 hEd->setValue(hue);-
1342 sEd->setValue(sat);-
1343 vEd->setValue(val);-
1344-
1345 rEd->setValue(qRed(currentColor()));-
1346 gEd->setValue(qGreen(currentColor()));-
1347 bEd->setValue(qBlue(currentColor()));-
1348-
1349 showCurrentColor();-
1350 newCol(currentColor());-
1351 updateQColor();-
1352}-
1353-
1354void QColorShower::setRgb(QRgb rgb)-
1355{-
1356 rgbOriginal = true;-
1357 curCol = rgb;-
1358-
1359 rgb2hsv(currentColor(), hue, sat, val);-
1360-
1361 hEd->setValue(hue);-
1362 sEd->setValue(sat);-
1363 vEd->setValue(val);-
1364-
1365 rEd->setValue(qRed(currentColor()));-
1366 gEd->setValue(qGreen(currentColor()));-
1367 bEd->setValue(qBlue(currentColor()));-
1368-
1369 htEd->setText(QColor(rgb).name());-
1370-
1371 showCurrentColor();-
1372 updateQColor();-
1373}-
1374-
1375void QColorShower::setHsv(int h, int s, int v)-
1376{-
1377 if (h < -1 || (uint)s > 255 || (uint)v > 255)-
1378 return;-
1379-
1380 rgbOriginal = false;-
1381 hue = h; val = v; sat = s;-
1382 QColor c;-
1383 c.setHsv(hue, sat, val);-
1384 curCol = c.rgb();-
1385-
1386 hEd->setValue(hue);-
1387 sEd->setValue(sat);-
1388 vEd->setValue(val);-
1389-
1390 rEd->setValue(qRed(currentColor()));-
1391 gEd->setValue(qGreen(currentColor()));-
1392 bEd->setValue(qBlue(currentColor()));-
1393-
1394 htEd->setText(c.name());-
1395-
1396 showCurrentColor();-
1397 updateQColor();-
1398}-
1399-
1400void QColorShower::retranslateStrings()-
1401{-
1402 lblHue->setText(QColorDialog::tr("Hu&e:"));-
1403 lblSat->setText(QColorDialog::tr("&Sat:"));-
1404 lblVal->setText(QColorDialog::tr("&Val:"));-
1405 lblRed->setText(QColorDialog::tr("&Red:"));-
1406 lblGreen->setText(QColorDialog::tr("&Green:"));-
1407 lblBlue->setText(QColorDialog::tr("Bl&ue:"));-
1408 alphaLab->setText(QColorDialog::tr("A&lpha channel:"));-
1409 lblHtml->setText(QColorDialog::tr("&HTML:"));-
1410}-
1411-
1412void QColorShower::updateQColor()-
1413{-
1414 QColor oldQColor(curQColor);-
1415 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));-
1416 if (curQColor != oldQColor)-
1417 currentColorChanged(curQColor);-
1418}-
1419-
1420-
1421void QColorDialogPrivate::_q_newHsv(int h, int s, int v)-
1422{-
1423 if (!nativeDialogInUse) {-
1424 cs->setHsv(h, s, v);-
1425 cp->setCol(h, s);-
1426 lp->setCol(h, s, v);-
1427 }-
1428}-
1429-
1430-
1431void QColorDialogPrivate::setCurrentRgbColor(QRgb rgb)-
1432{-
1433 if (!nativeDialogInUse) {-
1434 cs->setRgb(rgb);-
1435 _q_newColorTypedIn(rgb);-
1436 }-
1437}-
1438-
1439-
1440void QColorDialogPrivate::setCurrentQColor(const QColor &color)-
1441{-
1442 QColorDialog * const q = q_func();-
1443 if (cs->curQColor != color) {-
1444 cs->curQColor = color;-
1445 q->currentColorChanged(color);-
1446 }-
1447}-
1448-
1449-
1450enum {-
1451 colorColumns = 8,-
1452 standardColorRows = 6,-
1453 customColorRows = 2-
1454};-
1455-
1456bool QColorDialogPrivate::selectColor(const QColor &col)-
1457{-
1458 QRgb color = col.rgb();-
1459-
1460 if (standard) {-
1461 const QRgb *standardColors = QColorDialogOptions::standardColors();-
1462 const QRgb *standardColorsEnd = standardColors + standardColorRows * colorColumns;-
1463 const QRgb *match = std::find(standardColors, standardColorsEnd, color);-
1464 if (match != standardColorsEnd) {-
1465 const int index = int(match - standardColors);-
1466 const int column = index / standardColorRows;-
1467 const int row = index % standardColorRows;-
1468 _q_newStandard(row, column);-
1469 standard->setCurrent(row, column);-
1470 standard->setSelected(row, column);-
1471 standard->setFocus();-
1472 return true;-
1473 }-
1474 }-
1475-
1476 if (custom) {-
1477 const QRgb *customColors = QColorDialogOptions::customColors();-
1478 const QRgb *customColorsEnd = customColors + customColorRows * colorColumns;-
1479 const QRgb *match = std::find(customColors, customColorsEnd, color);-
1480 if (match != customColorsEnd) {-
1481 const int index = int(match - customColors);-
1482 const int column = index / customColorRows;-
1483 const int row = index % customColorRows;-
1484 _q_newCustom(row, column);-
1485 custom->setCurrent(row, column);-
1486 custom->setSelected(row, column);-
1487 custom->setFocus();-
1488 return true;-
1489 }-
1490 }-
1491 return false;-
1492}-
1493-
1494QColor QColorDialogPrivate::grabScreenColor(const QPoint &p)-
1495{-
1496 const QDesktopWidget *desktop = QApplication::desktop();-
1497 const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(),-
1498 p.x(), p.y(), 1, 1);-
1499 QImage i = pixmap.toImage();-
1500 return i.pixel(0, 0);-
1501}-
1502-
1503-
1504void QColorDialogPrivate::_q_newColorTypedIn(QRgb rgb)-
1505{-
1506 if (!nativeDialogInUse) {-
1507 int h, s, v;-
1508 rgb2hsv(rgb, h, s, v);-
1509 cp->setCol(h, s);-
1510 lp->setCol(h, s, v);-
1511 }-
1512}-
1513-
1514void QColorDialogPrivate::_q_nextCustom(int r, int c)-
1515{-
1516 nextCust = r + customColorRows * c;-
1517}-
1518-
1519void QColorDialogPrivate::_q_newCustom(int r, int c)-
1520{-
1521 const int i = r + customColorRows * c;-
1522 setCurrentRgbColor(QColorDialogOptions::customColor(i));-
1523 if (standard)-
1524 standard->setSelected(-1,-1);-
1525}-
1526-
1527void QColorDialogPrivate::_q_newStandard(int r, int c)-
1528{-
1529 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));-
1530 if (custom)-
1531 custom->setSelected(-1,-1);-
1532}-
1533-
1534void QColorDialogPrivate::_q_pickScreenColor()-
1535{-
1536 QColorDialog * const q = q_func();-
1537 if (!colorPickingEventFilter)-
1538 colorPickingEventFilter = new QColorPickingEventFilter(this);-
1539 q->installEventFilter(colorPickingEventFilter);-
1540-
1541 beforeScreenColorPicking = cs->currentColor();-
1542-
1543 q->grabMouse(Qt::CrossCursor);-
1544 q->grabKeyboard();-
1545-
1546-
1547-
1548 q->setMouseTracking(true);-
1549-
1550 addCusBt->setDisabled(true);-
1551 buttons->setDisabled(true);-
1552 screenColorPickerButton->setDisabled(true);-
1553-
1554 const QPoint globalPos = QCursor::pos();-
1555 q->setCurrentColor(grabScreenColor(globalPos));-
1556 updateColorLabelText(globalPos);-
1557}-
1558-
1559void QColorDialogPrivate::updateColorLabelText(const QPoint &globalPos)-
1560{-
1561 lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")-
1562 .arg(globalPos.x())-
1563 .arg(globalPos.y()));-
1564}-
1565-
1566void QColorDialogPrivate::releaseColorPicking()-
1567{-
1568 QColorDialog * const q = q_func();-
1569 cp->setCrossVisible(true);-
1570 q->removeEventFilter(colorPickingEventFilter);-
1571 q->releaseMouse();-
1572-
1573-
1574-
1575-
1576 q->releaseKeyboard();-
1577 q->setMouseTracking(false);-
1578 lblScreenColorInfo->setText(QLatin1String("\n"));-
1579 addCusBt->setDisabled(false);-
1580 buttons->setDisabled(false);-
1581 screenColorPickerButton->setDisabled(false);-
1582}-
1583-
1584void QColorDialogPrivate::init(const QColor &initial)-
1585{-
1586 QColorDialog * const q = q_func();-
1587-
1588 q->setSizeGripEnabled(false);-
1589 q->setWindowTitle(QColorDialog::tr("Select Color"));-
1590-
1591-
1592 nativeDialogInUse = (platformColorDialogHelper() != 0);-
1593 colorPickingEventFilter = 0;-
1594 nextCust = 0;-
1595-
1596 if (!nativeDialogInUse)-
1597 initWidgets();-
1598-
1599-
1600-
1601-
1602-
1603-
1604 q->setCurrentColor(initial);-
1605}-
1606-
1607void QColorDialogPrivate::initWidgets()-
1608{-
1609 QColorDialog * const q = q_func();-
1610 QVBoxLayout *mainLay = new QVBoxLayout(q);-
1611-
1612 mainLay->setSizeConstraint(QLayout::SetFixedSize);-
1613-
1614 QHBoxLayout *topLay = new QHBoxLayout();-
1615 mainLay->addLayout(topLay);-
1616-
1617 leftLay = 0;-
1618-
1619-
1620-
1621-
1622-
1623-
1624-
1625 smallDisplay = (QApplication::desktop()->width() < 480 || QApplication::desktop()->height() < 350);-
1626 const int lumSpace = topLay->spacing() / 2;-
1627-
1628-
1629 if (!smallDisplay) {-
1630 leftLay = new QVBoxLayout;-
1631 topLay->addLayout(leftLay);-
1632-
1633 standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());-
1634 lblBasicColors = new QLabel(q);-
1635-
1636 lblBasicColors->setBuddy(standard);-
1637-
1638 q->connect(standard, qFlagLocation("2""selected(int,int)" "\0" __FILE__ ":" "1718""1724"), qFlagLocation("1""_q_newStandard(int,int)" "\0" __FILE__ ":" "1718""1724"));-
1639 leftLay->addWidget(lblBasicColors);-
1640 leftLay->addWidget(standard);-
1641-
1642-
1643-
1644 screenColorPickerButton = new QPushButton();-
1645 leftLay->addWidget(screenColorPickerButton);-
1646 lblScreenColorInfo = new QLabel(QLatin1String("\n"));-
1647 leftLay->addWidget(lblScreenColorInfo);-
1648 q->connect(screenColorPickerButton, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "1728""1734"), qFlagLocation("1""_q_pickScreenColor()" "\0" __FILE__ ":" "1728""1734"));-
1649-
1650-
1651-
1652 leftLay->addStretch();-
1653-
1654-
1655 custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors());-
1656 custom->setAcceptDrops(true);-
1657-
1658 q->connect(custom, qFlagLocation("2""selected(int,int)" "\0" __FILE__ ":" "1738""1744"), qFlagLocation("1""_q_newCustom(int,int)" "\0" __FILE__ ":" "1738""1744"));-
1659 q->connect(custom, qFlagLocation("2""currentChanged(int,int)" "\0" __FILE__ ":" "1739""1745"), qFlagLocation("1""_q_nextCustom(int,int)" "\0" __FILE__ ":" "1739""1745"));-
1660 lblCustomColors = new QLabel(q);-
1661-
1662 lblCustomColors->setBuddy(custom);-
1663-
1664 leftLay->addWidget(lblCustomColors);-
1665 leftLay->addWidget(custom);-
1666-
1667 addCusBt = new QPushButton(q);-
1668 QObject::connect(addCusBt, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "1748""1754"), q, qFlagLocation("1""_q_addCustom()" "\0" __FILE__ ":" "1748""1754"));-
1669 leftLay->addWidget(addCusBt);-
1670 } else {-
1671 pWidth = 150;-
1672 pHeight = 100;-
1673-
1674 custom = 0;-
1675 standard = 0;-
1676 }-
1677-
1678 QVBoxLayout *rightLay = new QVBoxLayout;-
1679 topLay->addLayout(rightLay);-
1680-
1681 QHBoxLayout *pickLay = new QHBoxLayout;-
1682 rightLay->addLayout(pickLay);-
1683-
1684 QVBoxLayout *cLay = new QVBoxLayout;-
1685 pickLay->addLayout(cLay);-
1686 cp = new QColorPicker(q);-
1687-
1688 cp->setFrameStyle(QFrame::Panel + QFrame::Sunken);-
1689-
1690-
1691-
1692-
1693 cLay->addSpacing(lumSpace);-
1694 cLay->addWidget(cp);-
1695-
1696 cLay->addSpacing(lumSpace);-
1697-
1698 lp = new QColorLuminancePicker(q);-
1699-
1700-
1701-
1702 lp->setFixedWidth(20);-
1703 pickLay->addSpacing(10);-
1704 pickLay->addWidget(lp);-
1705 pickLay->addStretch();-
1706-
1707-
1708 QObject::connect(cp, qFlagLocation("2""newCol(int,int)" "\0" __FILE__ ":" "1796""1802"), lp, qFlagLocation("1""setCol(int,int)" "\0" __FILE__ ":" "1796""1802"));-
1709 QObject::connect(lp, qFlagLocation("2""newHsv(int,int,int)" "\0" __FILE__ ":" "1797""1803"), q, qFlagLocation("1""_q_newHsv(int,int,int)" "\0" __FILE__ ":" "1797""1803"));-
1710-
1711 rightLay->addStretch();-
1712-
1713 cs = new QColorShower(q);-
1714 pickLay->setMargin(cs->gl->margin());-
1715 QObject::connect(cs, qFlagLocation("2""newCol(QRgb)" "\0" __FILE__ ":" "1803""1809"), q, qFlagLocation("1""_q_newColorTypedIn(QRgb)" "\0" __FILE__ ":" "1803""1809"));-
1716 QObject::connect(cs, qFlagLocation("2""currentColorChanged(QColor)" "\0" __FILE__ ":" "1804""1810"),-
1717 q, qFlagLocation("2""currentColorChanged(QColor)" "\0" __FILE__ ":" "1805""1811"));-
1718-
1719-
1720-
1721 rightLay->addWidget(cs);-
1722 if (leftLay)-
1723 leftLay->addSpacing(cs->gl->margin());-
1724-
1725-
1726 buttons = new QDialogButtonBox(q);-
1727 mainLay->addWidget(buttons);-
1728-
1729 ok = buttons->addButton(QDialogButtonBox::Ok);-
1730 QObject::connect(ok, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "1818""1824"), q, qFlagLocation("1""accept()" "\0" __FILE__ ":" "1818""1824"));-
1731 ok->setDefault(true);-
1732 cancel = buttons->addButton(QDialogButtonBox::Cancel);-
1733 QObject::connect(cancel, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "1821""1827"), q, qFlagLocation("1""reject()" "\0" __FILE__ ":" "1821""1827"));-
1734-
1735-
1736-
1737-
1738-
1739 retranslateStrings();-
1740}-
1741-
1742void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h)-
1743{-
1744 QColorDialog *d = q_func();-
1745 QObject::connect(h, qFlagLocation("2""currentColorChanged(QColor)" "\0" __FILE__ ":" "1833""1839"), d, qFlagLocation("2""currentColorChanged(QColor)" "\0" __FILE__ ":" "1833""1839"));-
1746 QObject::connect(h, qFlagLocation("2""colorSelected(QColor)" "\0" __FILE__ ":" "1834""1840"), d, qFlagLocation("2""colorSelected(QColor)" "\0" __FILE__ ":" "1834""1840"));-
1747 static_cast<QPlatformColorDialogHelper *>(h)->setOptions(options);-
1748}-
1749-
1750void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)-
1751{-
1752 options->setWindowTitle(q_func()->windowTitle());-
1753}-
1754-
1755void QColorDialogPrivate::_q_addCustom()-
1756{-
1757 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());-
1758 if (custom)-
1759 custom->update();-
1760 nextCust = (nextCust+1) % 16;-
1761}-
1762-
1763void QColorDialogPrivate::retranslateStrings()-
1764{-
1765 if (!smallDisplay) {-
1766 lblBasicColors->setText(QColorDialog::tr("&Basic colors"));-
1767 lblCustomColors->setText(QColorDialog::tr("&Custom colors"));-
1768 addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));-
1769 screenColorPickerButton->setText(QColorDialog::tr("&Pick Screen Color"));-
1770 }-
1771-
1772 cs->retranslateStrings();-
1773}-
1774-
1775bool QColorDialogPrivate::canBeNativeDialog() const-
1776{-
1777-
1778-
1779 const QDialog * const q = static_cast<const QDialog*>(q_ptr);-
1780 if (nativeDialogInUse
nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1781 return
never executed: return true;
true;
never executed: return true;
0
1782 if (QCoreApplication::testAttribute
QCoreApplicati...NativeDialogs)Description
TRUEnever evaluated
FALSEnever evaluated
(Qt::AA_DontUseNativeDialogs)
QCoreApplicati...NativeDialogs)Description
TRUEnever evaluated
FALSEnever evaluated
0
1783 || q->testAttribute(Qt::WA_DontShowOnScreen))
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
0
return false;
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
if
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
)
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
1784 || (
(options->opti...eNativeDialog)Description
TRUEnever evaluated
FALSEnever evaluated
options->options() & QColorDialog::DontUseNativeDialog))
(options->opti...eNativeDialog)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1785 return
never executed: return false;
false;
never executed: return false;
0
1786 }-
1787-
1788 QLatin1String staticName(QColorDialog::staticMetaObject.className());-
1789 QLatin1String dynamicName(q->metaObject()->className());-
1790 return
never executed: return (staticName == dynamicName);
(staticName == dynamicName);
never executed: return (staticName == dynamicName);
0
1791}-
1792-
1793static const Qt::WindowFlags DefaultWindowFlags =-
1794 Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint-
1795 | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;-
1796QColorDialog::QColorDialog(QWidget *parent)-
1797 : QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)-
1798{-
1799 QColorDialogPrivate * const d = d_func();-
1800 d->init(Qt::white);-
1801}-
1802-
1803-
1804-
1805-
1806-
1807-
1808-
1809QColorDialog::QColorDialog(const QColor &initial, QWidget *parent)-
1810 : QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)-
1811{-
1812 QColorDialogPrivate * const d = d_func();-
1813 d->init(initial);-
1814}-
1815-
1816void QColorDialogPrivate::setCurrentColor(const QColor &color, SetColorMode setColorMode)-
1817{-
1818 if (nativeDialogInUse) {-
1819 platformColorDialogHelper()->setCurrentColor(color);-
1820 return;-
1821 }-
1822-
1823 if (setColorMode & ShowColor) {-
1824 setCurrentRgbColor(color.rgb());-
1825 setCurrentAlpha(color.alpha());-
1826 }-
1827 if (setColorMode & SelectColor)-
1828 selectColor(color);-
1829}-
1830-
1831-
1832-
1833-
1834-
1835-
1836void QColorDialog::setCurrentColor(const QColor &color)-
1837{-
1838 QColorDialogPrivate * const d = d_func();-
1839 d->setCurrentColor(color);-
1840}-
1841-
1842QColor QColorDialog::currentColor() const-
1843{-
1844 const QColorDialogPrivate * const d = d_func();-
1845 return d->currentQColor();-
1846}-
1847QColor QColorDialog::selectedColor() const-
1848{-
1849 const QColorDialogPrivate * const d = d_func();-
1850 return d->selectedQColor;-
1851}-
1852-
1853-
1854-
1855-
1856-
1857-
1858-
1859void QColorDialog::setOption(ColorDialogOption option, bool on)-
1860{-
1861 const QColorDialog::ColorDialogOptions previousOptions = options();-
1862 if (!(previousOptions & option) != !on)-
1863 setOptions(previousOptions ^ option);-
1864}-
1865bool QColorDialog::testOption(ColorDialogOption option) const-
1866{-
1867 const QColorDialogPrivate * const d = d_func();-
1868 return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));-
1869}-
1870void QColorDialog::setOptions(ColorDialogOptions options)-
1871{-
1872 QColorDialogPrivate * const d = d_func();-
1873-
1874 if (QColorDialog::options() == options)-
1875 return;-
1876-
1877 d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));-
1878 if ((options & DontUseNativeDialog) && d->nativeDialogInUse) {-
1879 d->nativeDialogInUse = false;-
1880 d->initWidgets();-
1881 }-
1882 if (!d->nativeDialogInUse) {-
1883 d->buttons->setVisible(!(options & NoButtons));-
1884 d->showAlpha(options & ShowAlphaChannel);-
1885 }-
1886}-
1887-
1888QColorDialog::ColorDialogOptions QColorDialog::options() const-
1889{-
1890 const QColorDialogPrivate * const d = d_func();-
1891 return QColorDialog::ColorDialogOptions(int(d->options->options()));-
1892}-
1893void QColorDialog::setVisible(bool visible)-
1894{-
1895 QColorDialogPrivate * const d = d_func();-
1896-
1897 if (visible){-
1898 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))-
1899 return;-
1900 } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))-
1901 return;-
1902-
1903 if (visible)-
1904 d->selectedQColor = QColor();-
1905-
1906 if (d->nativeDialogInUse) {-
1907 d->setNativeDialogVisible(visible);-
1908-
1909-
1910 setAttribute(Qt::WA_DontShowOnScreen);-
1911 } else {-
1912 setAttribute(Qt::WA_DontShowOnScreen, false);-
1913 }-
1914-
1915 QDialog::setVisible(visible);-
1916}-
1917void QColorDialog::open(QObject *receiver, const char *member)-
1918{-
1919 QColorDialogPrivate * const d = d_func();-
1920 connect(this, qFlagLocation("2""colorSelected(QColor)" "\0" __FILE__ ":" "2132""2139"), receiver, member);-
1921 d->receiverToDisconnectOnClose = receiver;-
1922 d->memberToDisconnectOnClose = member;-
1923 QDialog::open();-
1924}-
1925QColor QColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title,-
1926 ColorDialogOptions options)-
1927{-
1928 QColorDialog dlg(parent);-
1929 if (!title.isEmpty())-
1930 dlg.setWindowTitle(title);-
1931 dlg.setOptions(options);-
1932 dlg.setCurrentColor(initial);-
1933 dlg.exec();-
1934 return dlg.selectedColor();-
1935}-
1936QRgb QColorDialog::getRgba(QRgb initial, bool *ok, QWidget *parent)-
1937{-
1938 const QColor color = getColor(QColor::fromRgba(initial), parent, QString(),-
1939 ShowAlphaChannel);-
1940 QRgb result = color.isValid() ? color.rgba() : initial;-
1941 if (ok)-
1942 *ok = color.isValid();-
1943 return result;-
1944}-
1945-
1946-
1947-
1948-
1949-
1950QColorDialog::~QColorDialog()-
1951{-
1952-
1953}-
1954-
1955-
1956-
1957-
1958void QColorDialog::changeEvent(QEvent *e)-
1959{-
1960 QColorDialogPrivate * const d = d_func();-
1961 if (e->type() == QEvent::LanguageChange)-
1962 d->retranslateStrings();-
1963 QDialog::changeEvent(e);-
1964}-
1965-
1966void QColorDialogPrivate::_q_updateColorPicking()-
1967{-
1968-
1969 QColorDialog * const q = q_func();-
1970 static QPoint lastGlobalPos;-
1971 QPoint newGlobalPos = QCursor::pos();-
1972 if (lastGlobalPos == newGlobalPos)-
1973 return;-
1974 lastGlobalPos = newGlobalPos;-
1975-
1976 if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) {-
1977 updateColorPicking(newGlobalPos);-
1978-
1979-
1980-
1981 }-
1982-
1983}-
1984-
1985void QColorDialogPrivate::updateColorPicking(const QPoint &globalPos)-
1986{-
1987 const QColor color = grabScreenColor(globalPos);-
1988-
1989-
1990 setCurrentColor(color, ShowColor);-
1991 updateColorLabelText(globalPos);-
1992-
1993}-
1994-
1995bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)-
1996{-
1997-
1998 cp->setCrossVisible(!cp->geometry().contains(e->pos()));-
1999-
2000 updateColorPicking(e->globalPos());-
2001 return true;-
2002}-
2003-
2004bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e)-
2005{-
2006 setCurrentColor(grabScreenColor(e->globalPos()), SetColorAll);-
2007 releaseColorPicking();-
2008 return true;-
2009}-
2010-
2011bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e)-
2012{-
2013 QColorDialog * const q = q_func();-
2014 if (e->matches(QKeySequence::Cancel)) {-
2015 releaseColorPicking();-
2016 q->setCurrentColor(beforeScreenColorPicking);-
2017 } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {-
2018 q->setCurrentColor(grabScreenColor(QCursor::pos()));-
2019 releaseColorPicking();-
2020 }-
2021 e->accept();-
2022 return true;-
2023}-
2024void QColorDialog::done(int result)-
2025{-
2026 QColorDialogPrivate * const d = d_func();-
2027 if (result == Accepted) {-
2028 d->selectedQColor = d->currentQColor();-
2029 colorSelected(d->selectedQColor);-
2030 } else {-
2031 d->selectedQColor = QColor();-
2032 }-
2033 QDialog::done(result);-
2034 if (d->receiverToDisconnectOnClose) {-
2035 disconnect(this, qFlagLocation("2""colorSelected(QColor)" "\0" __FILE__ ":" "2283""2290"),-
2036 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);-
2037 d->receiverToDisconnectOnClose = 0;-
2038 }-
2039 d->memberToDisconnectOnClose.clear();-
2040}-
2041-
2042-
2043-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9