qcolordialog.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qcolordialog.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qcolordialog.h"-
41-
42#ifndef QT_NO_COLORDIALOG-
43-
44#include "qapplication.h"-
45#include "qdesktopwidget.h"-
46#include "qdrawutil.h"-
47#include "qevent.h"-
48#include "qimage.h"-
49#include "qdrag.h"-
50#include "qlabel.h"-
51#include "qlayout.h"-
52#include "qlineedit.h"-
53#include "qmenu.h"-
54#include "qpainter.h"-
55#include "qpixmap.h"-
56#include "qpushbutton.h"-
57#include "qsettings.h"-
58#include "qsharedpointer.h"-
59#include "qstyle.h"-
60#include "qstyleoption.h"-
61#include "qvalidator.h"-
62#include "qmimedata.h"-
63#include "qspinbox.h"-
64#include "qdialogbuttonbox.h"-
65#include "qscreen.h"-
66#include "qcursor.h"-
67#include "qtimer.h"-
68#include "qwindow.h"-
69-
70#include "private/qdialog_p.h"-
71-
72#include <algorithm>-
73-
74QT_BEGIN_NAMESPACE-
75-
76namespace {-
77class QColorLuminancePicker;-
78class QColorPicker;-
79class QColorShower;-
80class QWellArray;-
81class QColorPickingEventFilter;-
82} // unnamed namespace-
83-
84class QColorDialogPrivate : public QDialogPrivate-
85{-
86 Q_DECLARE_PUBLIC(QColorDialog)-
87-
88public:-
89 enum SetColorMode {-
90 ShowColor = 0x1,-
91 SelectColor = 0x2,-
92 SetColorAll = ShowColor | SelectColor-
93 };-
94-
95 QColorDialogPrivate() : options(new QColorDialogOptions)-
96#ifdef Q_OS_WIN32-
97 , updateTimer(0)-
98#endif-
99 {}
never executed: end of block
0
100-
101 QPlatformColorDialogHelper *platformColorDialogHelper() const-
102 { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); }
never executed: return static_cast<QPlatformColorDialogHelper *>(platformHelper());
0
103-
104 void init(const QColor &initial);-
105 void initWidgets();-
106 QRgb currentColor() const;-
107 QColor currentQColor() const;-
108 void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll);-
109 void setCurrentRgbColor(QRgb rgb);-
110 void setCurrentQColor(const QColor &color);-
111 bool selectColor(const QColor &color);-
112 QColor grabScreenColor(const QPoint &p);-
113-
114 int currentAlpha() const;-
115 void setCurrentAlpha(int a);-
116 void showAlpha(bool b);-
117 bool isAlphaVisible() const;-
118 void retranslateStrings();-
119-
120 void _q_addCustom();-
121-
122 void _q_newHsv(int h, int s, int v);-
123 void _q_newColorTypedIn(QRgb rgb);-
124 void _q_nextCustom(int, int);-
125 void _q_newCustom(int, int);-
126 void _q_newStandard(int, int);-
127 void _q_pickScreenColor();-
128 void _q_updateColorPicking();-
129 void updateColorLabelText(const QPoint &);-
130 void updateColorPicking(const QPoint &pos);-
131 void releaseColorPicking();-
132 bool handleColorPickingMouseMove(QMouseEvent *e);-
133 bool handleColorPickingMouseButtonRelease(QMouseEvent *e);-
134 bool handleColorPickingKeyPress(QKeyEvent *e);-
135-
136 bool canBeNativeDialog() const Q_DECL_OVERRIDE;-
137-
138 QWellArray *custom;-
139 QWellArray *standard;-
140-
141 QDialogButtonBox *buttons;-
142 QVBoxLayout *leftLay;-
143 QColorPicker *cp;-
144 QColorLuminancePicker *lp;-
145 QColorShower *cs;-
146 QLabel *lblBasicColors;-
147 QLabel *lblCustomColors;-
148 QLabel *lblScreenColorInfo;-
149 QPushButton *ok;-
150 QPushButton *cancel;-
151 QPushButton *addCusBt;-
152 QPushButton *screenColorPickerButton;-
153 QColor selectedQColor;-
154 int nextCust;-
155 bool smallDisplay;-
156 bool screenColorPicking;-
157 QColorPickingEventFilter *colorPickingEventFilter;-
158 QRgb beforeScreenColorPicking;-
159 QSharedPointer<QColorDialogOptions> options;-
160-
161 QPointer<QObject> receiverToDisconnectOnClose;-
162 QByteArray memberToDisconnectOnClose;-
163#ifdef Q_OS_WIN32-
164 QTimer *updateTimer;-
165 QWindow dummyTransparentWindow;-
166#endif-
167-
168private:-
169 virtual void initHelper(QPlatformDialogHelper *h) Q_DECL_OVERRIDE;-
170 virtual void helperPrepareShow(QPlatformDialogHelper *h) Q_DECL_OVERRIDE;-
171};-
172-
173//////////// QWellArray BEGIN-
174-
175namespace {-
176-
177class QWellArray : public QWidget-
178{-
179 Q_OBJECT-
180 Q_PROPERTY(int selectedColumn READ selectedColumn)-
181 Q_PROPERTY(int selectedRow READ selectedRow)-
182-
183public:-
184 QWellArray(int rows, int cols, QWidget* parent=0);-
185 ~QWellArray() {}-
186 QString cellContent(int row, int col) const;-
187-
188 int selectedColumn() const { return selCol; }
never executed: return selCol;
0
189 int selectedRow() const { return selRow; }
never executed: return selRow;
0
190-
191 virtual void setCurrent(int row, int col);-
192 virtual void setSelected(int row, int col);-
193-
194 QSize sizeHint() const Q_DECL_OVERRIDE;-
195-
196 inline int cellWidth() const-
197 { return cellw; }
never executed: return cellw;
0
198-
199 inline int cellHeight() const-
200 { return cellh; }
never executed: return cellh;
0
201-
202 inline int rowAt(int y) const-
203 { return y / cellh; }
never executed: return y / cellh;
0
204-
205 inline int columnAt(int x) const-
206 { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
never executed: return ncols - (x / cellw) - 1;
never executed: return x / cellw;
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
207-
208 inline int rowY(int row) const-
209 { return cellh * row; }
never executed: return cellh * row;
0
210-
211 inline int columnX(int column) const-
212 { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
never executed: return cellw * (ncols - column - 1);
never executed: return cellw * column;
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
213-
214 inline int numRows() const-
215 { return nrows; }
never executed: return nrows;
0
216-
217 inline int numCols() const-
218 {return ncols; }
never executed: return ncols;
0
219-
220 inline QRect cellRect() const-
221 { return QRect(0, 0, cellw, cellh); }
never executed: return QRect(0, 0, cellw, cellh);
0
222-
223 inline QSize gridSize() const-
224 { return QSize(ncols * cellw, nrows * cellh); }
never executed: return QSize(ncols * cellw, nrows * cellh);
0
225-
226 QRect cellGeometry(int row, int column)-
227 {-
228 QRect r;-
229 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
row < nrowsDescription
TRUEnever evaluated
FALSEnever evaluated
column >= 0Description
TRUEnever evaluated
FALSEnever evaluated
column < ncolsDescription
TRUEnever evaluated
FALSEnever evaluated
0
230 r.setRect(columnX(column), rowY(row), cellw, cellh);
never executed: r.setRect(columnX(column), rowY(row), cellw, cellh);
0
231 return r;
never executed: return r;
0
232 }-
233-
234 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
never executed: end of block
0
235-
236signals:-
237 void selected(int row, int col);-
238 void currentChanged(int row, int col);-
239-
240protected:-
241 virtual void paintCell(QPainter *, int row, int col, const QRect&);-
242 virtual void paintCellContents(QPainter *, int row, int col, const QRect&);-
243-
244 void mousePressEvent(QMouseEvent*) Q_DECL_OVERRIDE;-
245 void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE;-
246 void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE;-
247 void focusInEvent(QFocusEvent*) Q_DECL_OVERRIDE;-
248 void focusOutEvent(QFocusEvent*) Q_DECL_OVERRIDE;-
249 void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;-
250-
251private:-
252 Q_DISABLE_COPY(QWellArray)-
253-
254 int nrows;-
255 int ncols;-
256 int cellw;-
257 int cellh;-
258 int curRow;-
259 int curCol;-
260 int selRow;-
261 int selCol;-
262};-
263-
264void QWellArray::paintEvent(QPaintEvent *e)-
265{-
266 QRect r = e->rect();-
267 int cx = r.x();-
268 int cy = r.y();-
269 int ch = r.height();-
270 int cw = r.width();-
271 int colfirst = columnAt(cx);-
272 int collast = columnAt(cx + cw);-
273 int rowfirst = rowAt(cy);-
274 int rowlast = rowAt(cy + ch);-
275-
276 if (isRightToLeft()) {
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
277 int t = colfirst;-
278 colfirst = collast;-
279 collast = t;-
280 }
never executed: end of block
0
281-
282 QPainter painter(this);-
283 QPainter *p = &painter;-
284 QRect rect(0, 0, cellWidth(), cellHeight());-
285-
286-
287 if (collast < 0 || collast >= ncols)
collast < 0Description
TRUEnever evaluated
FALSEnever evaluated
collast >= ncolsDescription
TRUEnever evaluated
FALSEnever evaluated
0
288 collast = ncols-1;
never executed: collast = ncols-1;
0
289 if (rowlast < 0 || rowlast >= nrows)
rowlast < 0Description
TRUEnever evaluated
FALSEnever evaluated
rowlast >= nrowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
290 rowlast = nrows-1;
never executed: rowlast = nrows-1;
0
291-
292 // Go through the rows-
293 for (int r = rowfirst; r <= rowlast; ++r) {
r <= rowlastDescription
TRUEnever evaluated
FALSEnever evaluated
0
294 // get row position and height-
295 int rowp = rowY(r);-
296-
297 // Go through the columns in the row r-
298 // if we know from where to where, go through [colfirst, collast],-
299 // else go through all of them-
300 for (int c = colfirst; c <= collast; ++c) {
c <= collastDescription
TRUEnever evaluated
FALSEnever evaluated
0
301 // get position and width of column c-
302 int colp = columnX(c);-
303 // Translate painter and draw the cell-
304 rect.translate(colp, rowp);-
305 paintCell(p, r, c, rect);-
306 rect.translate(-colp, -rowp);-
307 }
never executed: end of block
0
308 }
never executed: end of block
0
309}
never executed: end of block
0
310-
311QWellArray::QWellArray(int rows, int cols, QWidget *parent)-
312 : QWidget(parent)-
313 ,nrows(rows), ncols(cols)-
314{-
315 setFocusPolicy(Qt::StrongFocus);-
316 cellw = 28;-
317 cellh = 24;-
318 curCol = 0;-
319 curRow = 0;-
320 selCol = -1;-
321 selRow = -1;-
322}
never executed: end of block
0
323-
324QSize QWellArray::sizeHint() const-
325{-
326 ensurePolished();-
327 return gridSize().boundedTo(QSize(640, 480));
never executed: return gridSize().boundedTo(QSize(640, 480));
0
328}-
329-
330-
331void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)-
332{-
333 int b = 3; //margin-
334-
335 const QPalette & g = palette();-
336 QStyleOptionFrame opt;-
337 int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);-
338 opt.lineWidth = dfw;-
339 opt.midLineWidth = 1;-
340 opt.rect = rect.adjusted(b, b, -b, -b);-
341 opt.palette = g;-
342 opt.state = QStyle::State_Enabled | QStyle::State_Sunken;-
343 style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this);-
344 b += dfw;-
345-
346 if ((row == curRow) && (col == curCol)) {
(row == curRow)Description
TRUEnever evaluated
FALSEnever evaluated
(col == curCol)Description
TRUEnever evaluated
FALSEnever evaluated
0
347 if (hasFocus()) {
hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
0
348 QStyleOptionFocusRect opt;-
349 opt.palette = g;-
350 opt.rect = rect;-
351 opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange;-
352 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this);-
353 }
never executed: end of block
0
354 }
never executed: end of block
0
355 paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));-
356}
never executed: end of block
0
357-
358/*!-
359 Reimplement this function to change the contents of the well array.-
360 */-
361void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)-
362{-
363 Q_UNUSED(row);-
364 Q_UNUSED(col);-
365 p->fillRect(r, Qt::white);-
366 p->setPen(Qt::black);-
367 p->drawLine(r.topLeft(), r.bottomRight());-
368 p->drawLine(r.topRight(), r.bottomLeft());-
369}
never executed: end of block
0
370-
371void QWellArray::mousePressEvent(QMouseEvent *e)-
372{-
373 // The current cell marker is set to the cell the mouse is pressed in-
374 QPoint pos = e->pos();-
375 setCurrent(rowAt(pos.y()), columnAt(pos.x()));-
376}
never executed: end of block
0
377-
378void QWellArray::mouseReleaseEvent(QMouseEvent * /* event */)-
379{-
380 // The current cell marker is set to the cell the mouse is clicked in-
381 setSelected(curRow, curCol);-
382}
never executed: end of block
0
383-
384-
385/*-
386 Sets the cell currently having the focus. This is not necessarily-
387 the same as the currently selected cell.-
388*/-
389-
390void QWellArray::setCurrent(int row, int col)-
391{-
392 if ((curRow == row) && (curCol == col))
(curRow == row)Description
TRUEnever evaluated
FALSEnever evaluated
(curCol == col)Description
TRUEnever evaluated
FALSEnever evaluated
0
393 return;
never executed: return;
0
394-
395 if (row < 0 || col < 0)
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
col < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
396 row = col = -1;
never executed: row = col = -1;
0
397-
398 int oldRow = curRow;-
399 int oldCol = curCol;-
400-
401 curRow = row;-
402 curCol = col;-
403-
404 updateCell(oldRow, oldCol);-
405 updateCell(curRow, curCol);-
406-
407 emit currentChanged(curRow, curCol);-
408}
never executed: end of block
0
409-
410/*-
411 Sets the currently selected cell to \a row, \a column. If \a row or-
412 \a column are less than zero, the current cell is unselected.-
413-
414 Does not set the position of the focus indicator.-
415*/-
416void QWellArray::setSelected(int row, int col)-
417{-
418 int oldRow = selRow;-
419 int oldCol = selCol;-
420-
421 if (row < 0 || col < 0)
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
col < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
422 row = col = -1;
never executed: row = col = -1;
0
423-
424 selCol = col;-
425 selRow = row;-
426-
427 updateCell(oldRow, oldCol);-
428 updateCell(selRow, selCol);-
429 if (row >= 0)
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
430 emit selected(row, col);
never executed: selected(row, col);
0
431-
432#ifndef QT_NO_MENU-
433 if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
qobject_cast<Q...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
434 parentWidget()->close();
never executed: parentWidget()->close();
0
435#endif-
436}
never executed: end of block
0
437-
438void QWellArray::focusInEvent(QFocusEvent*)-
439{-
440 updateCell(curRow, curCol);-
441 emit currentChanged(curRow, curCol);-
442}
never executed: end of block
0
443-
444/*!\reimp-
445*/-
446-
447void QWellArray::focusOutEvent(QFocusEvent*)-
448{-
449 updateCell(curRow, curCol);-
450}
never executed: end of block
0
451-
452/*\reimp-
453*/-
454void QWellArray::keyPressEvent(QKeyEvent* e)-
455{-
456 switch(e->key()) { // Look at the key code-
457 case Qt::Key_Left: // If 'left arrow'-key,
never executed: case Qt::Key_Left:
0
458 if(curCol > 0) // and cr't not in leftmost col
curCol > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
459 setCurrent(curRow, curCol - 1); // set cr't to next left column
never executed: setCurrent(curRow, curCol - 1);
0
460 break;
never executed: break;
0
461 case Qt::Key_Right: // Correspondingly...
never executed: case Qt::Key_Right:
0
462 if(curCol < numCols()-1)
curCol < numCols()-1Description
TRUEnever evaluated
FALSEnever evaluated
0
463 setCurrent(curRow, curCol + 1);
never executed: setCurrent(curRow, curCol + 1);
0
464 break;
never executed: break;
0
465 case Qt::Key_Up:
never executed: case Qt::Key_Up:
0
466 if(curRow > 0)
curRow > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
467 setCurrent(curRow - 1, curCol);
never executed: setCurrent(curRow - 1, curCol);
0
468 break;
never executed: break;
0
469 case Qt::Key_Down:
never executed: case Qt::Key_Down:
0
470 if(curRow < numRows()-1)
curRow < numRows()-1Description
TRUEnever evaluated
FALSEnever evaluated
0
471 setCurrent(curRow + 1, curCol);
never executed: setCurrent(curRow + 1, curCol);
0
472 break;
never executed: break;
0
473#if 0-
474 // bad idea that shouldn't have been implemented; very counterintuitive-
475 case Qt::Key_Return:-
476 case Qt::Key_Enter:-
477 /*-
478 ignore the key, so that the dialog get it, but still select-
479 the current row/col-
480 */-
481 e->ignore();-
482 // fallthrough intended-
483#endif-
484 case Qt::Key_Space:
never executed: case Qt::Key_Space:
0
485 setSelected(curRow, curCol);-
486 break;
never executed: break;
0
487 default: // If not an interesting key,
never executed: default:
0
488 e->ignore(); // we don't accept the event-
489 return;
never executed: return;
0
490 }-
491-
492}-
493-
494//////////// QWellArray END-
495-
496// Event filter to be installed on the dialog while in color-picking mode.-
497class QColorPickingEventFilter : public QObject {-
498public:-
499 explicit QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent = 0) : QObject(parent), m_dp(dp) {}
never executed: end of block
0
500-
501 bool eventFilter(QObject *, QEvent *event) Q_DECL_OVERRIDE-
502 {-
503 switch (event->type()) {-
504 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
505 return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));
never executed: return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));
0
506 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
507 return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
never executed: return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
0
508 case QEvent::KeyPress:
never executed: case QEvent::KeyPress:
0
509 return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
never executed: return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
0
510 default:
never executed: default:
0
511 break;
never executed: break;
0
512 }-
513 return false;
never executed: return false;
0
514 }-
515-
516private:-
517 QColorDialogPrivate *m_dp;-
518};-
519-
520} // unnamed namespace-
521-
522/*!-
523 Returns the number of custom colors supported by QColorDialog. All-
524 color dialogs share the same custom colors.-
525*/-
526int QColorDialog::customCount()-
527{-
528 return QColorDialogOptions::customColorCount();
never executed: return QColorDialogOptions::customColorCount();
0
529}-
530-
531/*!-
532 \since 4.5-
533-
534 Returns the custom color at the given \a index as a QColor value.-
535*/-
536QColor QColorDialog::customColor(int index)-
537{-
538 return QColor(QColorDialogOptions::customColor(index));
never executed: return QColor(QColorDialogOptions::customColor(index));
0
539}-
540-
541/*!-
542 Sets the custom color at \a index to the QColor \a color value.-
543-
544 \note This function does not apply to the Native Color Dialog on the-
545 \macos platform. If you still require this function, use the-
546 QColorDialog::DontUseNativeDialog option.-
547*/-
548void QColorDialog::setCustomColor(int index, QColor color)-
549{-
550 QColorDialogOptions::setCustomColor(index, color.rgba());-
551}
never executed: end of block
0
552-
553/*!-
554 \since 5.0-
555-
556 Returns the standard color at the given \a index as a QColor value.-
557*/-
558QColor QColorDialog::standardColor(int index)-
559{-
560 return QColor(QColorDialogOptions::standardColor(index));
never executed: return QColor(QColorDialogOptions::standardColor(index));
0
561}-
562-
563/*!-
564 Sets the standard color at \a index to the QColor \a color value.-
565-
566 \note This function does not apply to the Native Color Dialog on the-
567 \macos platform. If you still require this function, use the-
568 QColorDialog::DontUseNativeDialog option.-
569*/-
570void QColorDialog::setStandardColor(int index, QColor color)-
571{-
572 QColorDialogOptions::setStandardColor(index, color.rgba());-
573}
never executed: end of block
0
574-
575static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)-
576{-
577 QColor c;-
578 c.setRgb(rgb);-
579 c.getHsv(&h, &s, &v);-
580}
never executed: end of block
0
581-
582namespace {-
583-
584class QColorWell : public QWellArray-
585{-
586public:-
587 QColorWell(QWidget *parent, int r, int c, QRgb *vals)-
588 :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1)-
589 { setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); }
never executed: end of block
0
590-
591protected:-
592 void paintCellContents(QPainter *, int row, int col, const QRect&) Q_DECL_OVERRIDE;-
593 void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;-
594 void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;-
595 void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;-
596#ifndef QT_NO_DRAGANDDROP-
597 void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;-
598 void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;-
599 void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;-
600 void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;-
601#endif-
602-
603private:-
604 QRgb *values;-
605 bool mousePressed;-
606 QPoint pressPos;-
607 QPoint oldCurrent;-
608-
609};-
610-
611void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)-
612{-
613 int i = row + col*numRows();-
614 p->fillRect(r, QColor(values[i]));-
615}
never executed: end of block
0
616-
617void QColorWell::mousePressEvent(QMouseEvent *e)-
618{-
619 oldCurrent = QPoint(selectedRow(), selectedColumn());-
620 QWellArray::mousePressEvent(e);-
621 mousePressed = true;-
622 pressPos = e->pos();-
623}
never executed: end of block
0
624-
625void QColorWell::mouseMoveEvent(QMouseEvent *e)-
626{-
627 QWellArray::mouseMoveEvent(e);-
628#ifndef QT_NO_DRAGANDDROP-
629 if (!mousePressed)
!mousePressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
630 return;
never executed: return;
0
631 if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
(pressPos - e-...DragDistance()Description
TRUEnever evaluated
FALSEnever evaluated
0
632 setCurrent(oldCurrent.x(), oldCurrent.y());-
633 int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows();-
634 QColor col(values[i]);-
635 QMimeData *mime = new QMimeData;-
636 mime->setColorData(col);-
637 QPixmap pix(cellWidth(), cellHeight());-
638 pix.fill(col);-
639 QPainter p(&pix);-
640 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);-
641 p.end();-
642 QDrag *drg = new QDrag(this);-
643 drg->setMimeData(mime);-
644 drg->setPixmap(pix);-
645 mousePressed = false;-
646 drg->start();-
647 }
never executed: end of block
0
648#endif-
649}
never executed: end of block
0
650-
651#ifndef QT_NO_DRAGANDDROP-
652void QColorWell::dragEnterEvent(QDragEnterEvent *e)-
653{-
654 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
qvariant_cast<...a()).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
655 e->accept();
never executed: e->accept();
0
656 else-
657 e->ignore();
never executed: e->ignore();
0
658}-
659-
660void QColorWell::dragLeaveEvent(QDragLeaveEvent *)-
661{-
662 if (hasFocus())
hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
0
663 parentWidget()->setFocus();
never executed: parentWidget()->setFocus();
0
664}
never executed: end of block
0
665-
666void QColorWell::dragMoveEvent(QDragMoveEvent *e)-
667{-
668 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) {
qvariant_cast<...a()).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
669 setCurrent(rowAt(e->pos().y()), columnAt(e->pos().x()));-
670 e->accept();-
671 } else {
never executed: end of block
0
672 e->ignore();-
673 }
never executed: end of block
0
674}-
675-
676void QColorWell::dropEvent(QDropEvent *e)-
677{-
678 QColor col = qvariant_cast<QColor>(e->mimeData()->colorData());-
679 if (col.isValid()) {
col.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
680 int i = rowAt(e->pos().y()) + columnAt(e->pos().x()) * numRows();-
681 values[i] = col.rgb();-
682 update();-
683 e->accept();-
684 } else {
never executed: end of block
0
685 e->ignore();-
686 }
never executed: end of block
0
687}-
688-
689#endif // QT_NO_DRAGANDDROP-
690-
691void QColorWell::mouseReleaseEvent(QMouseEvent *e)-
692{-
693 if (!mousePressed)
!mousePressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
694 return;
never executed: return;
0
695 QWellArray::mouseReleaseEvent(e);-
696 mousePressed = false;-
697}
never executed: end of block
0
698-
699class QColorPicker : public QFrame-
700{-
701 Q_OBJECT-
702public:-
703 QColorPicker(QWidget* parent);-
704 ~QColorPicker();-
705-
706 void setCrossVisible(bool visible);-
707public slots:-
708 void setCol(int h, int s);-
709-
710signals:-
711 void newCol(int h, int s);-
712-
713protected:-
714 QSize sizeHint() const Q_DECL_OVERRIDE;-
715 void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;-
716 void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;-
717 void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;-
718 void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;-
719-
720private:-
721 int hue;-
722 int sat;-
723-
724 QPoint colPt();-
725 int huePt(const QPoint &pt);-
726 int satPt(const QPoint &pt);-
727 void setCol(const QPoint &pt);-
728-
729 QPixmap pix;-
730 bool crossVisible;-
731};-
732-
733static int pWidth = 220;-
734static int pHeight = 200;-
735-
736class QColorLuminancePicker : public QWidget-
737{-
738 Q_OBJECT-
739public:-
740 QColorLuminancePicker(QWidget* parent=0);-
741 ~QColorLuminancePicker();-
742-
743public slots:-
744 void setCol(int h, int s, int v);-
745 void setCol(int h, int s);-
746-
747signals:-
748 void newHsv(int h, int s, int v);-
749-
750protected:-
751 void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;-
752 void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;-
753 void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;-
754-
755private:-
756 enum { foff = 3, coff = 4 }; //frame and contents offset-
757 int val;-
758 int hue;-
759 int sat;-
760-
761 int y2val(int y);-
762 int val2y(int val);-
763 void setVal(int v);-
764-
765 QPixmap *pix;-
766};-
767-
768-
769int QColorLuminancePicker::y2val(int y)-
770{-
771 int d = height() - 2*coff - 1;-
772 return 255 - (y - coff)*255/d;
never executed: return 255 - (y - coff)*255/d;
0
773}-
774-
775int QColorLuminancePicker::val2y(int v)-
776{-
777 int d = height() - 2*coff - 1;-
778 return coff + (255-v)*d/255;
never executed: return coff + (255-v)*d/255;
0
779}-
780-
781QColorLuminancePicker::QColorLuminancePicker(QWidget* parent)-
782 :QWidget(parent)-
783{-
784 hue = 100; val = 100; sat = 100;-
785 pix = 0;-
786 // setAttribute(WA_NoErase, true);-
787}
never executed: end of block
0
788-
789QColorLuminancePicker::~QColorLuminancePicker()-
790{-
791 delete pix;-
792}
never executed: end of block
0
793-
794void QColorLuminancePicker::mouseMoveEvent(QMouseEvent *m)-
795{-
796 setVal(y2val(m->y()));-
797}
never executed: end of block
0
798void QColorLuminancePicker::mousePressEvent(QMouseEvent *m)-
799{-
800 setVal(y2val(m->y()));-
801}
never executed: end of block
0
802-
803void QColorLuminancePicker::setVal(int v)-
804{-
805 if (val == v)
val == vDescription
TRUEnever evaluated
FALSEnever evaluated
0
806 return;
never executed: return;
0
807 val = qMax(0, qMin(v,255));-
808 delete pix; pix=0;-
809 repaint();-
810 emit newHsv(hue, sat, val);-
811}
never executed: end of block
0
812-
813//receives from a hue,sat chooser and relays.-
814void QColorLuminancePicker::setCol(int h, int s)-
815{-
816 setCol(h, s, val);-
817 emit newHsv(h, s, val);-
818}
never executed: end of block
0
819-
820void QColorLuminancePicker::paintEvent(QPaintEvent *)-
821{-
822 int w = width() - 5;-
823-
824 QRect r(0, foff, w, height() - 2*foff);-
825 int wi = r.width() - 2;-
826 int hi = r.height() - 2;-
827 if (!pix || pix->height() != hi || pix->width() != wi) {
!pixDescription
TRUEnever evaluated
FALSEnever evaluated
pix->height() != hiDescription
TRUEnever evaluated
FALSEnever evaluated
pix->width() != wiDescription
TRUEnever evaluated
FALSEnever evaluated
0
828 delete pix;-
829 QImage img(wi, hi, QImage::Format_RGB32);-
830 int y;-
831 uint *pixel = (uint *) img.scanLine(0);-
832 for (y = 0; y < hi; y++) {
y < hiDescription
TRUEnever evaluated
FALSEnever evaluated
0
833 uint *end = pixel + wi;-
834 std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb());-
835 pixel = end;-
836 }
never executed: end of block
0
837 pix = new QPixmap(QPixmap::fromImage(img));-
838 }
never executed: end of block
0
839 QPainter p(this);-
840 p.drawPixmap(1, coff, *pix);-
841 const QPalette &g = palette();-
842 qDrawShadePanel(&p, r, g, true);-
843 p.setPen(g.foreground().color());-
844 p.setBrush(g.foreground());-
845 QPolygon a;-
846 int y = val2y(val);-
847 a.setPoints(3, w, y, w+5, y+5, w+5, y-5);-
848 p.eraseRect(w, 0, 5, height());-
849 p.drawPolygon(a);-
850}
never executed: end of block
0
851-
852void QColorLuminancePicker::setCol(int h, int s , int v)-
853{-
854 val = v;-
855 hue = h;-
856 sat = s;-
857 delete pix; pix=0;-
858 repaint();-
859}
never executed: end of block
0
860-
861QPoint QColorPicker::colPt()-
862{-
863 QRect r = contentsRect();-
864 return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
never executed: return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
0
865}-
866-
867int QColorPicker::huePt(const QPoint &pt)-
868{-
869 QRect r = contentsRect();-
870 return 360 - pt.x() * 360 / (r.width() - 1);
never executed: return 360 - pt.x() * 360 / (r.width() - 1);
0
871}-
872-
873int QColorPicker::satPt(const QPoint &pt)-
874{-
875 QRect r = contentsRect();-
876 return 255 - pt.y() * 255 / (r.height() - 1);
never executed: return 255 - pt.y() * 255 / (r.height() - 1);
0
877}-
878-
879void QColorPicker::setCol(const QPoint &pt)-
880{-
881 setCol(huePt(pt), satPt(pt));-
882}
never executed: end of block
0
883-
884QColorPicker::QColorPicker(QWidget* parent)-
885 : QFrame(parent)-
886 , crossVisible(true)-
887{-
888 hue = 0; sat = 0;-
889 setCol(150, 255);-
890-
891 setAttribute(Qt::WA_NoSystemBackground);-
892 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );-
893}
never executed: end of block
0
894-
895QColorPicker::~QColorPicker()-
896{-
897}-
898-
899void QColorPicker::setCrossVisible(bool visible)-
900{-
901 if (crossVisible != visible) {
crossVisible != visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
902 crossVisible = visible;-
903 update();-
904 }
never executed: end of block
0
905}
never executed: end of block
0
906-
907QSize QColorPicker::sizeHint() const-
908{-
909 return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
never executed: return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
0
910}-
911-
912void QColorPicker::setCol(int h, int s)-
913{-
914 int nhue = qMin(qMax(0,h), 359);-
915 int nsat = qMin(qMax(0,s), 255);-
916 if (nhue == hue && nsat == sat)
nhue == hueDescription
TRUEnever evaluated
FALSEnever evaluated
nsat == satDescription
TRUEnever evaluated
FALSEnever evaluated
0
917 return;
never executed: return;
0
918-
919 QRect r(colPt(), QSize(20,20));-
920 hue = nhue; sat = nsat;-
921 r = r.united(QRect(colPt(), QSize(20,20)));-
922 r.translate(contentsRect().x()-9, contentsRect().y()-9);-
923 // update(r);-
924 repaint(r);-
925}
never executed: end of block
0
926-
927void QColorPicker::mouseMoveEvent(QMouseEvent *m)-
928{-
929 QPoint p = m->pos() - contentsRect().topLeft();-
930 setCol(p);-
931 emit newCol(hue, sat);-
932}
never executed: end of block
0
933-
934void QColorPicker::mousePressEvent(QMouseEvent *m)-
935{-
936 QPoint p = m->pos() - contentsRect().topLeft();-
937 setCol(p);-
938 emit newCol(hue, sat);-
939}
never executed: end of block
0
940-
941void QColorPicker::paintEvent(QPaintEvent* )-
942{-
943 QPainter p(this);-
944 drawFrame(&p);-
945 QRect r = contentsRect();-
946-
947 p.drawPixmap(r.topLeft(), pix);-
948-
949 if (crossVisible) {
crossVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
950 QPoint pt = colPt() + r.topLeft();-
951 p.setPen(Qt::black);-
952 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);-
953 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);-
954 }
never executed: end of block
0
955}
never executed: end of block
0
956-
957void QColorPicker::resizeEvent(QResizeEvent *ev)-
958{-
959 QFrame::resizeEvent(ev);-
960-
961 int w = width() - frameWidth() * 2;-
962 int h = height() - frameWidth() * 2;-
963 QImage img(w, h, QImage::Format_RGB32);-
964 int x, y;-
965 uint *pixel = (uint *) img.scanLine(0);-
966 for (y = 0; y < h; y++) {
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
0
967 const uint *end = pixel + w;-
968 x = 0;-
969 while (pixel < end) {
pixel < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
970 QPoint p(x, y);-
971 QColor c;-
972 c.setHsv(huePt(p), satPt(p), 200);-
973 *pixel = c.rgb();-
974 ++pixel;-
975 ++x;-
976 }
never executed: end of block
0
977 }
never executed: end of block
0
978 pix = QPixmap::fromImage(img);-
979}
never executed: end of block
0
980-
981-
982class QColSpinBox : public QSpinBox-
983{-
984public:-
985 QColSpinBox(QWidget *parent)-
986 : QSpinBox(parent) { setRange(0, 255); }
never executed: end of block
0
987 void setValue(int i) {-
988 const QSignalBlocker blocker(this);-
989 QSpinBox::setValue(i);-
990 }
never executed: end of block
0
991};-
992-
993class QColorShowLabel;-
994-
995class QColorShower : public QWidget-
996{-
997 Q_OBJECT-
998public:-
999 QColorShower(QColorDialog *parent);-
1000-
1001 //things that don't emit signals-
1002 void setHsv(int h, int s, int v);-
1003-
1004 int currentAlpha() const-
1005 { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }
never executed: return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255;
0
1006 void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); }
never executed: end of block
0
1007 void showAlpha(bool b);-
1008 bool isAlphaVisible() const;-
1009-
1010 QRgb currentColor() const { return curCol; }
never executed: return curCol;
0
1011 QColor currentQColor() const { return curQColor; }
never executed: return curQColor;
0
1012 void retranslateStrings();-
1013 void updateQColor();-
1014-
1015public slots:-
1016 void setRgb(QRgb rgb);-
1017-
1018signals:-
1019 void newCol(QRgb rgb);-
1020 void currentColorChanged(const QColor &color);-
1021-
1022private slots:-
1023 void rgbEd();-
1024 void hsvEd();-
1025 void htmlEd();-
1026-
1027private:-
1028 void showCurrentColor();-
1029 int hue, sat, val;-
1030 QRgb curCol;-
1031 QColor curQColor;-
1032 QLabel *lblHue;-
1033 QLabel *lblSat;-
1034 QLabel *lblVal;-
1035 QLabel *lblRed;-
1036 QLabel *lblGreen;-
1037 QLabel *lblBlue;-
1038 QLabel *lblHtml;-
1039 QColSpinBox *hEd;-
1040 QColSpinBox *sEd;-
1041 QColSpinBox *vEd;-
1042 QColSpinBox *rEd;-
1043 QColSpinBox *gEd;-
1044 QColSpinBox *bEd;-
1045 QColSpinBox *alphaEd;-
1046 QLabel *alphaLab;-
1047 QLineEdit *htEd;-
1048 QColorShowLabel *lab;-
1049 bool rgbOriginal;-
1050 QColorDialog *colorDialog;-
1051 QGridLayout *gl;-
1052-
1053 friend class QT_PREPEND_NAMESPACE(QColorDialog);-
1054 friend class QT_PREPEND_NAMESPACE(QColorDialogPrivate);-
1055};-
1056-
1057class QColorShowLabel : public QFrame-
1058{-
1059 Q_OBJECT-
1060-
1061public:-
1062 QColorShowLabel(QWidget *parent) : QFrame(parent) {-
1063 setFrameStyle(QFrame::Panel|QFrame::Sunken);-
1064 setAcceptDrops(true);-
1065 mousePressed = false;-
1066 }
never executed: end of block
0
1067 void setColor(QColor c) { col = c; }
never executed: end of block
0
1068-
1069signals:-
1070 void colorDropped(QRgb);-
1071-
1072protected:-
1073 void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;-
1074 void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;-
1075 void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;-
1076 void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;-
1077#ifndef QT_NO_DRAGANDDROP-
1078 void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;-
1079 void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;-
1080 void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;-
1081#endif-
1082-
1083private:-
1084 QColor col;-
1085 bool mousePressed;-
1086 QPoint pressPos;-
1087};-
1088-
1089void QColorShowLabel::paintEvent(QPaintEvent *e)-
1090{-
1091 QPainter p(this);-
1092 drawFrame(&p);-
1093 p.fillRect(contentsRect()&e->rect(), col);-
1094}
never executed: end of block
0
1095-
1096void QColorShower::showAlpha(bool b)-
1097{-
1098 alphaLab->setVisible(b);-
1099 alphaEd->setVisible(b);-
1100}
never executed: end of block
0
1101-
1102inline bool QColorShower::isAlphaVisible() const-
1103{-
1104 return alphaLab->isVisible();
never executed: return alphaLab->isVisible();
0
1105}-
1106-
1107void QColorShowLabel::mousePressEvent(QMouseEvent *e)-
1108{-
1109 mousePressed = true;-
1110 pressPos = e->pos();-
1111}
never executed: end of block
0
1112-
1113void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)-
1114{-
1115#ifdef QT_NO_DRAGANDDROP-
1116 Q_UNUSED(e);-
1117#else-
1118 if (!mousePressed)
!mousePressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1119 return;
never executed: return;
0
1120 if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
(pressPos - e-...DragDistance()Description
TRUEnever evaluated
FALSEnever evaluated
0
1121 QMimeData *mime = new QMimeData;-
1122 mime->setColorData(col);-
1123 QPixmap pix(30, 20);-
1124 pix.fill(col);-
1125 QPainter p(&pix);-
1126 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);-
1127 p.end();-
1128 QDrag *drg = new QDrag(this);-
1129 drg->setMimeData(mime);-
1130 drg->setPixmap(pix);-
1131 mousePressed = false;-
1132 drg->start();-
1133 }
never executed: end of block
0
1134#endif-
1135}
never executed: end of block
0
1136-
1137#ifndef QT_NO_DRAGANDDROP-
1138void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e)-
1139{-
1140 if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
qvariant_cast<...a()).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1141 e->accept();
never executed: e->accept();
0
1142 else-
1143 e->ignore();
never executed: e->ignore();
0
1144}-
1145-
1146void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *)-
1147{-
1148}-
1149-
1150void QColorShowLabel::dropEvent(QDropEvent *e)-
1151{-
1152 QColor color = qvariant_cast<QColor>(e->mimeData()->colorData());-
1153 if (color.isValid()) {
color.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1154 col = color;-
1155 repaint();-
1156 emit colorDropped(col.rgb());-
1157 e->accept();-
1158 } else {
never executed: end of block
0
1159 e->ignore();-
1160 }
never executed: end of block
0
1161}-
1162#endif // QT_NO_DRAGANDDROP-
1163-
1164void QColorShowLabel::mouseReleaseEvent(QMouseEvent *)-
1165{-
1166 if (!mousePressed)
!mousePressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1167 return;
never executed: return;
0
1168 mousePressed = false;-
1169}
never executed: end of block
0
1170-
1171QColorShower::QColorShower(QColorDialog *parent)-
1172 : QWidget(parent)-
1173{-
1174 colorDialog = parent;-
1175-
1176 curCol = qRgb(255, 255, 255);-
1177 curQColor = Qt::white;-
1178-
1179 gl = new QGridLayout(this);-
1180 gl->setMargin(gl->spacing());-
1181 lab = new QColorShowLabel(this);-
1182-
1183#ifndef Q_OS_WINCE-
1184#ifdef QT_SMALL_COLORDIALOG-
1185 lab->setMinimumHeight(60);-
1186#endif-
1187 lab->setMinimumWidth(60);-
1188#else-
1189 lab->setMinimumWidth(20);-
1190#endif-
1191-
1192// For QVGA screens only the comboboxes and color label are visible.-
1193// For nHD screens only color and luminence pickers and color label are visible.-
1194#if !defined(QT_SMALL_COLORDIALOG)-
1195 gl->addWidget(lab, 0, 0, -1, 1);-
1196#else-
1197 gl->addWidget(lab, 0, 0, 1, -1);-
1198#endif-
1199 connect(lab, SIGNAL(colorDropped(QRgb)), this, SIGNAL(newCol(QRgb)));-
1200 connect(lab, SIGNAL(colorDropped(QRgb)), this, SLOT(setRgb(QRgb)));-
1201-
1202 hEd = new QColSpinBox(this);-
1203 hEd->setRange(0, 359);-
1204 lblHue = new QLabel(this);-
1205#ifndef QT_NO_SHORTCUT-
1206 lblHue->setBuddy(hEd);-
1207#endif-
1208 lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1209#if !defined(QT_SMALL_COLORDIALOG)-
1210 gl->addWidget(lblHue, 0, 1);-
1211 gl->addWidget(hEd, 0, 2);-
1212#else-
1213 gl->addWidget(lblHue, 1, 0);-
1214 gl->addWidget(hEd, 2, 0);-
1215#endif-
1216-
1217 sEd = new QColSpinBox(this);-
1218 lblSat = new QLabel(this);-
1219#ifndef QT_NO_SHORTCUT-
1220 lblSat->setBuddy(sEd);-
1221#endif-
1222 lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1223#if !defined(QT_SMALL_COLORDIALOG)-
1224 gl->addWidget(lblSat, 1, 1);-
1225 gl->addWidget(sEd, 1, 2);-
1226#else-
1227 gl->addWidget(lblSat, 1, 1);-
1228 gl->addWidget(sEd, 2, 1);-
1229#endif-
1230-
1231 vEd = new QColSpinBox(this);-
1232 lblVal = new QLabel(this);-
1233#ifndef QT_NO_SHORTCUT-
1234 lblVal->setBuddy(vEd);-
1235#endif-
1236 lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1237#if !defined(QT_SMALL_COLORDIALOG)-
1238 gl->addWidget(lblVal, 2, 1);-
1239 gl->addWidget(vEd, 2, 2);-
1240#else-
1241 gl->addWidget(lblVal, 1, 2);-
1242 gl->addWidget(vEd, 2, 2);-
1243#endif-
1244-
1245 rEd = new QColSpinBox(this);-
1246 lblRed = new QLabel(this);-
1247#ifndef QT_NO_SHORTCUT-
1248 lblRed->setBuddy(rEd);-
1249#endif-
1250 lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1251#if !defined(QT_SMALL_COLORDIALOG)-
1252 gl->addWidget(lblRed, 0, 3);-
1253 gl->addWidget(rEd, 0, 4);-
1254#else-
1255 gl->addWidget(lblRed, 3, 0);-
1256 gl->addWidget(rEd, 4, 0);-
1257#endif-
1258-
1259 gEd = new QColSpinBox(this);-
1260 lblGreen = new QLabel(this);-
1261#ifndef QT_NO_SHORTCUT-
1262 lblGreen->setBuddy(gEd);-
1263#endif-
1264 lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1265#if !defined(QT_SMALL_COLORDIALOG)-
1266 gl->addWidget(lblGreen, 1, 3);-
1267 gl->addWidget(gEd, 1, 4);-
1268#else-
1269 gl->addWidget(lblGreen, 3, 1);-
1270 gl->addWidget(gEd, 4, 1);-
1271#endif-
1272-
1273 bEd = new QColSpinBox(this);-
1274 lblBlue = new QLabel(this);-
1275#ifndef QT_NO_SHORTCUT-
1276 lblBlue->setBuddy(bEd);-
1277#endif-
1278 lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1279#if !defined(QT_SMALL_COLORDIALOG)-
1280 gl->addWidget(lblBlue, 2, 3);-
1281 gl->addWidget(bEd, 2, 4);-
1282#else-
1283 gl->addWidget(lblBlue, 3, 2);-
1284 gl->addWidget(bEd, 4, 2);-
1285#endif-
1286-
1287 alphaEd = new QColSpinBox(this);-
1288 alphaLab = new QLabel(this);-
1289#ifndef QT_NO_SHORTCUT-
1290 alphaLab->setBuddy(alphaEd);-
1291#endif-
1292 alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1293#if !defined(QT_SMALL_COLORDIALOG)-
1294 gl->addWidget(alphaLab, 3, 1, 1, 3);-
1295 gl->addWidget(alphaEd, 3, 4);-
1296#else-
1297 gl->addWidget(alphaLab, 1, 3, 3, 1);-
1298 gl->addWidget(alphaEd, 4, 3);-
1299#endif-
1300 alphaEd->hide();-
1301 alphaLab->hide();-
1302 lblHtml = new QLabel(this);-
1303 htEd = new QLineEdit(this);-
1304#ifndef QT_NO_SHORTCUT-
1305 lblHtml->setBuddy(htEd);-
1306#endif-
1307-
1308#if !defined(QT_NO_REGULAREXPRESSION)-
1309 QRegularExpression regExp(QStringLiteral("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));
never executed: return qstring_literal_temp;
0
1310 QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);-
1311 htEd->setValidator(validator);-
1312#elif !defined(QT_NO_REGEXP)-
1313 QRegExp regExp(QStringLiteral("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));-
1314 QRegExpValidator *validator = new QRegExpValidator(regExp, this);-
1315 htEd->setValidator(validator);-
1316#else-
1317 htEd->setReadOnly(true);-
1318#endif-
1319 htEd->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);-
1320-
1321 lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter);-
1322#if defined(QT_SMALL_COLORDIALOG)-
1323 gl->addWidget(lblHtml, 5, 0);-
1324 gl->addWidget(htEd, 5, 1, 1, /*colspan=*/ 2);-
1325#else-
1326 gl->addWidget(lblHtml, 5, 1);-
1327 gl->addWidget(htEd, 5, 2, 1, /*colspan=*/ 3);-
1328#endif-
1329-
1330 connect(hEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));-
1331 connect(sEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));-
1332 connect(vEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));-
1333-
1334 connect(rEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));-
1335 connect(gEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));-
1336 connect(bEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));-
1337 connect(alphaEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));-
1338 connect(htEd, SIGNAL(textEdited(QString)), this, SLOT(htmlEd()));-
1339-
1340 retranslateStrings();-
1341}
never executed: end of block
0
1342-
1343} // unnamed namespace-
1344-
1345inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); }
never executed: return cs->currentColor();
0
1346inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); }
never executed: return cs->currentAlpha();
0
1347inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); }
never executed: end of block
0
1348inline void QColorDialogPrivate::showAlpha(bool b) { cs->showAlpha(b); }
never executed: end of block
0
1349inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisible(); }
never executed: return cs->isAlphaVisible();
0
1350-
1351QColor QColorDialogPrivate::currentQColor() const-
1352{-
1353 if (nativeDialogInUse)
nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1354 return platformColorDialogHelper()->currentColor();
never executed: return platformColorDialogHelper()->currentColor();
0
1355 return cs->currentQColor();
never executed: return cs->currentQColor();
0
1356}-
1357-
1358void QColorShower::showCurrentColor()-
1359{-
1360 lab->setColor(currentColor());-
1361 lab->repaint();-
1362}
never executed: end of block
0
1363-
1364void QColorShower::rgbEd()-
1365{-
1366 rgbOriginal = true;-
1367 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());-
1368-
1369 rgb2hsv(currentColor(), hue, sat, val);-
1370-
1371 hEd->setValue(hue);-
1372 sEd->setValue(sat);-
1373 vEd->setValue(val);-
1374-
1375 htEd->setText(QColor(curCol).name());-
1376-
1377 showCurrentColor();-
1378 emit newCol(currentColor());-
1379 updateQColor();-
1380}
never executed: end of block
0
1381-
1382void QColorShower::hsvEd()-
1383{-
1384 rgbOriginal = false;-
1385 hue = hEd->value();-
1386 sat = sEd->value();-
1387 val = vEd->value();-
1388-
1389 QColor c;-
1390 c.setHsv(hue, sat, val);-
1391 curCol = c.rgb();-
1392-
1393 rEd->setValue(qRed(currentColor()));-
1394 gEd->setValue(qGreen(currentColor()));-
1395 bEd->setValue(qBlue(currentColor()));-
1396-
1397 htEd->setText(c.name());-
1398-
1399 showCurrentColor();-
1400 emit newCol(currentColor());-
1401 updateQColor();-
1402}
never executed: end of block
0
1403-
1404void QColorShower::htmlEd()-
1405{-
1406 QColor c;-
1407 QString t = htEd->text();-
1408 c.setNamedColor(t);-
1409 if (!c.isValid())
!c.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1410 return;
never executed: return;
0
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();-
1423 emit newCol(currentColor());-
1424 updateQColor();-
1425}
never executed: end of block
0
1426-
1427void QColorShower::setRgb(QRgb rgb)-
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}
never executed: end of block
0
1447-
1448void QColorShower::setHsv(int h, int s, int v)-
1449{-
1450 if (h < -1 || (uint)s > 255 || (uint)v > 255)
h < -1Description
TRUEnever evaluated
FALSEnever evaluated
(uint)s > 255Description
TRUEnever evaluated
FALSEnever evaluated
(uint)v > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
1451 return;
never executed: return;
0
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}
never executed: end of block
0
1472-
1473void QColorShower::retranslateStrings()-
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}
never executed: end of block
0
1484-
1485void QColorShower::updateQColor()-
1486{-
1487 QColor oldQColor(curQColor);-
1488 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));-
1489 if (curQColor != oldQColor)
curQColor != oldQColorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1490 emit currentColorChanged(curQColor);
never executed: currentColorChanged(curQColor);
0
1491}
never executed: end of block
0
1492-
1493//sets all widgets to display h,s,v-
1494void QColorDialogPrivate::_q_newHsv(int h, int s, int v)-
1495{-
1496 if (!nativeDialogInUse) {
!nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1497 cs->setHsv(h, s, v);-
1498 cp->setCol(h, s);-
1499 lp->setCol(h, s, v);-
1500 }
never executed: end of block
0
1501}
never executed: end of block
0
1502-
1503//sets all widgets to display rgb-
1504void QColorDialogPrivate::setCurrentRgbColor(QRgb rgb)-
1505{-
1506 if (!nativeDialogInUse) {
!nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1507 cs->setRgb(rgb);-
1508 _q_newColorTypedIn(rgb);-
1509 }
never executed: end of block
0
1510}
never executed: end of block
0
1511-
1512// hack; doesn't keep curCol in sync, so use with care-
1513void QColorDialogPrivate::setCurrentQColor(const QColor &color)-
1514{-
1515 Q_Q(QColorDialog);-
1516 if (cs->curQColor != color) {
cs->curQColor != colorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1517 cs->curQColor = color;-
1518 emit q->currentColorChanged(color);-
1519 }
never executed: end of block
0
1520}
never executed: end of block
0
1521-
1522// size of standard and custom color selector-
1523enum {-
1524 colorColumns = 8,-
1525 standardColorRows = 6,-
1526 customColorRows = 2-
1527};-
1528-
1529bool QColorDialogPrivate::selectColor(const QColor &col)-
1530{-
1531 QRgb color = col.rgb();-
1532 // Check standard colors-
1533 if (standard) {
standardDescription
TRUEnever evaluated
FALSEnever evaluated
0
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) {
match != standardColorsEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
1538 const int index = int(match - standardColors);-
1539 const int column = index / standardColorRows;-
1540 const int row = index % standardColorRows;-
1541 _q_newStandard(row, column);-
1542 standard->setCurrent(row, column);-
1543 standard->setSelected(row, column);-
1544 standard->setFocus();-
1545 return true;
never executed: return true;
0
1546 }-
1547 }
never executed: end of block
0
1548 // Check custom colors-
1549 if (custom) {
customDescription
TRUEnever evaluated
FALSEnever evaluated
0
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) {
match != customColorsEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
1554 const int index = int(match - customColors);-
1555 const int column = index / customColorRows;-
1556 const int row = index % customColorRows;-
1557 _q_newCustom(row, column);-
1558 custom->setCurrent(row, column);-
1559 custom->setSelected(row, column);-
1560 custom->setFocus();-
1561 return true;
never executed: return true;
0
1562 }-
1563 }
never executed: end of block
0
1564 return false;
never executed: return false;
0
1565}-
1566-
1567QColor QColorDialogPrivate::grabScreenColor(const QPoint &p)-
1568{-
1569 const QDesktopWidget *desktop = QApplication::desktop();-
1570 const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(),-
1571 p.x(), p.y(), 1, 1);-
1572 QImage i = pixmap.toImage();-
1573 return i.pixel(0, 0);
never executed: return i.pixel(0, 0);
0
1574}-
1575-
1576//sets all widgets except cs to display rgb-
1577void QColorDialogPrivate::_q_newColorTypedIn(QRgb rgb)-
1578{-
1579 if (!nativeDialogInUse) {
!nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1580 int h, s, v;-
1581 rgb2hsv(rgb, h, s, v);-
1582 cp->setCol(h, s);-
1583 lp->setCol(h, s, v);-
1584 }
never executed: end of block
0
1585}
never executed: end of block
0
1586-
1587void QColorDialogPrivate::_q_nextCustom(int r, int c)-
1588{-
1589 nextCust = r + customColorRows * c;-
1590}
never executed: end of block
0
1591-
1592void QColorDialogPrivate::_q_newCustom(int r, int c)-
1593{-
1594 const int i = r + customColorRows * c;-
1595 setCurrentRgbColor(QColorDialogOptions::customColor(i));-
1596 if (standard)
standardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1597 standard->setSelected(-1,-1);
never executed: standard->setSelected(-1,-1);
0
1598}
never executed: end of block
0
1599-
1600void QColorDialogPrivate::_q_newStandard(int r, int c)-
1601{-
1602 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));-
1603 if (custom)
customDescription
TRUEnever evaluated
FALSEnever evaluated
0
1604 custom->setSelected(-1,-1);
never executed: custom->setSelected(-1,-1);
0
1605}
never executed: end of block
0
1606-
1607void QColorDialogPrivate::_q_pickScreenColor()-
1608{-
1609 Q_Q(QColorDialog);-
1610 if (!colorPickingEventFilter)
!colorPickingEventFilterDescription
TRUEnever evaluated
FALSEnever evaluated
0
1611 colorPickingEventFilter = new QColorPickingEventFilter(this);
never executed: colorPickingEventFilter = new QColorPickingEventFilter(this);
0
1612 q->installEventFilter(colorPickingEventFilter);-
1613 // If user pushes Escape, the last color before picking will be restored.-
1614 beforeScreenColorPicking = cs->currentColor();-
1615#ifndef QT_NO_CURSOR-
1616 q->grabMouse(Qt::CrossCursor);-
1617#else-
1618 q->grabMouse();-
1619#endif-
1620-
1621#ifdef Q_OS_WIN32 // excludes WinCE and WinRT-
1622 // On Windows mouse tracking doesn't work over other processes's windows-
1623 updateTimer->start(30);-
1624-
1625 // HACK: Because mouse grabbing doesn't work across processes, we have to have a dummy,-
1626 // invisible window to catch the mouse click, otherwise we will click whatever we clicked-
1627 // and loose focus.-
1628 dummyTransparentWindow.show();-
1629#endif-
1630 q->grabKeyboard();-
1631 /* With setMouseTracking(true) the desired color can be more precisely picked up,-
1632 * and continuously pushing the mouse button is not necessary.-
1633 */-
1634 q->setMouseTracking(true);-
1635-
1636 addCusBt->setDisabled(true);-
1637 buttons->setDisabled(true);-
1638 screenColorPickerButton->setDisabled(true);-
1639-
1640 const QPoint globalPos = QCursor::pos();-
1641 q->setCurrentColor(grabScreenColor(globalPos));-
1642 updateColorLabelText(globalPos);-
1643}
never executed: end of block
0
1644-
1645void QColorDialogPrivate::updateColorLabelText(const QPoint &globalPos)-
1646{-
1647 lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")-
1648 .arg(globalPos.x())-
1649 .arg(globalPos.y()));-
1650}
never executed: end of block
0
1651-
1652void QColorDialogPrivate::releaseColorPicking()-
1653{-
1654 Q_Q(QColorDialog);-
1655 cp->setCrossVisible(true);-
1656 q->removeEventFilter(colorPickingEventFilter);-
1657 q->releaseMouse();-
1658#ifdef Q_OS_WIN32-
1659 updateTimer->stop();-
1660 dummyTransparentWindow.setVisible(false);-
1661#endif-
1662 q->releaseKeyboard();-
1663 q->setMouseTracking(false);-
1664 lblScreenColorInfo->setText(QLatin1String("\n"));-
1665 addCusBt->setDisabled(false);-
1666 buttons->setDisabled(false);-
1667 screenColorPickerButton->setDisabled(false);-
1668}
never executed: end of block
0
1669-
1670void QColorDialogPrivate::init(const QColor &initial)-
1671{-
1672 Q_Q(QColorDialog);-
1673-
1674 q->setSizeGripEnabled(false);-
1675 q->setWindowTitle(QColorDialog::tr("Select Color"));-
1676-
1677 // default: use the native dialog if possible. Can be overridden in setOptions()-
1678 nativeDialogInUse = (platformColorDialogHelper() != 0);-
1679 colorPickingEventFilter = 0;-
1680 nextCust = 0;-
1681-
1682 if (!nativeDialogInUse)
!nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1683 initWidgets();
never executed: initWidgets();
0
1684-
1685#ifdef Q_OS_WIN32-
1686 dummyTransparentWindow.resize(1, 1);-
1687 dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);-
1688#endif-
1689-
1690 q->setCurrentColor(initial);-
1691}
never executed: end of block
0
1692-
1693void QColorDialogPrivate::initWidgets()-
1694{-
1695 Q_Q(QColorDialog);-
1696 QVBoxLayout *mainLay = new QVBoxLayout(q);-
1697 // there's nothing in this dialog that benefits from sizing up-
1698 mainLay->setSizeConstraint(QLayout::SetFixedSize);-
1699-
1700 QHBoxLayout *topLay = new QHBoxLayout();-
1701 mainLay->addLayout(topLay);-
1702-
1703 leftLay = 0;-
1704-
1705#if defined(Q_OS_WINCE) || defined(QT_SMALL_COLORDIALOG)-
1706 smallDisplay = true;-
1707 const int lumSpace = 20;-
1708#else-
1709 // small displays (e.g. PDAs) cannot fit the full color dialog,-
1710 // so just use the color picker.-
1711 smallDisplay = (QApplication::desktop()->width() < 480 || QApplication::desktop()->height() < 350);
QApplication::...>width() < 480Description
TRUEnever evaluated
FALSEnever evaluated
QApplication::...height() < 350Description
TRUEnever evaluated
FALSEnever evaluated
0
1712 const int lumSpace = topLay->spacing() / 2;-
1713#endif-
1714-
1715 if (!smallDisplay) {
!smallDisplayDescription
TRUEnever evaluated
FALSEnever evaluated
0
1716 leftLay = new QVBoxLayout;-
1717 topLay->addLayout(leftLay);-
1718-
1719 standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());-
1720 lblBasicColors = new QLabel(q);-
1721#ifndef QT_NO_SHORTCUT-
1722 lblBasicColors->setBuddy(standard);-
1723#endif-
1724 q->connect(standard, SIGNAL(selected(int,int)), SLOT(_q_newStandard(int,int)));-
1725 leftLay->addWidget(lblBasicColors);-
1726 leftLay->addWidget(standard);-
1727-
1728#if !defined(Q_OS_WINCE) && !defined(QT_SMALL_COLORDIALOG)-
1729 // The screen color picker button-
1730 screenColorPickerButton = new QPushButton();-
1731 leftLay->addWidget(screenColorPickerButton);-
1732 lblScreenColorInfo = new QLabel(QLatin1String("\n"));-
1733 leftLay->addWidget(lblScreenColorInfo);-
1734 q->connect(screenColorPickerButton, SIGNAL(clicked()), SLOT(_q_pickScreenColor()));-
1735#endif-
1736-
1737#if !defined(Q_OS_WINCE)-
1738 leftLay->addStretch();-
1739#endif-
1740-
1741 custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors());-
1742 custom->setAcceptDrops(true);-
1743-
1744 q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int)));-
1745 q->connect(custom, SIGNAL(currentChanged(int,int)), SLOT(_q_nextCustom(int,int)));-
1746 lblCustomColors = new QLabel(q);-
1747#ifndef QT_NO_SHORTCUT-
1748 lblCustomColors->setBuddy(custom);-
1749#endif-
1750 leftLay->addWidget(lblCustomColors);-
1751 leftLay->addWidget(custom);-
1752-
1753 addCusBt = new QPushButton(q);-
1754 QObject::connect(addCusBt, SIGNAL(clicked()), q, SLOT(_q_addCustom()));-
1755 leftLay->addWidget(addCusBt);-
1756 } else {
never executed: end of block
0
1757 // better color picker size for small displays-
1758#if defined(QT_SMALL_COLORDIALOG)-
1759 QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();-
1760 pWidth = pHeight = qMin(screenSize.width(), screenSize.height());-
1761 pHeight -= 20;-
1762 if(screenSize.height() > screenSize.width())-
1763 pWidth -= 20;-
1764#else-
1765 pWidth = 150;-
1766 pHeight = 100;-
1767#endif-
1768 custom = 0;-
1769 standard = 0;-
1770 }
never executed: end of block
0
1771-
1772 QVBoxLayout *rightLay = new QVBoxLayout;-
1773 topLay->addLayout(rightLay);-
1774-
1775 QHBoxLayout *pickLay = new QHBoxLayout;-
1776 rightLay->addLayout(pickLay);-
1777-
1778 QVBoxLayout *cLay = new QVBoxLayout;-
1779 pickLay->addLayout(cLay);-
1780 cp = new QColorPicker(q);-
1781-
1782 cp->setFrameStyle(QFrame::Panel + QFrame::Sunken);-
1783-
1784#if defined(QT_SMALL_COLORDIALOG)-
1785 cp->hide();-
1786#else-
1787 cLay->addSpacing(lumSpace);-
1788 cLay->addWidget(cp);-
1789#endif-
1790 cLay->addSpacing(lumSpace);-
1791-
1792 lp = new QColorLuminancePicker(q);-
1793#if defined(QT_SMALL_COLORDIALOG)-
1794 lp->hide();-
1795#else-
1796 lp->setFixedWidth(20);-
1797 pickLay->addSpacing(10);-
1798 pickLay->addWidget(lp);-
1799 pickLay->addStretch();-
1800#endif-
1801-
1802 QObject::connect(cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)));-
1803 QObject::connect(lp, SIGNAL(newHsv(int,int,int)), q, SLOT(_q_newHsv(int,int,int)));-
1804-
1805 rightLay->addStretch();-
1806-
1807 cs = new QColorShower(q);-
1808 pickLay->setMargin(cs->gl->margin());-
1809 QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb)));-
1810 QObject::connect(cs, SIGNAL(currentColorChanged(QColor)),-
1811 q, SIGNAL(currentColorChanged(QColor)));-
1812#if defined(QT_SMALL_COLORDIALOG)-
1813 topLay->addWidget(cs);-
1814#else-
1815 rightLay->addWidget(cs);-
1816 if (leftLay)
leftLayDescription
TRUEnever evaluated
FALSEnever evaluated
0
1817 leftLay->addSpacing(cs->gl->margin());
never executed: leftLay->addSpacing(cs->gl->margin());
0
1818#endif-
1819-
1820 buttons = new QDialogButtonBox(q);-
1821 mainLay->addWidget(buttons);-
1822-
1823 ok = buttons->addButton(QDialogButtonBox::Ok);-
1824 QObject::connect(ok, SIGNAL(clicked()), q, SLOT(accept()));-
1825 ok->setDefault(true);-
1826 cancel = buttons->addButton(QDialogButtonBox::Cancel);-
1827 QObject::connect(cancel, SIGNAL(clicked()), q, SLOT(reject()));-
1828-
1829#ifdef Q_OS_WIN32-
1830 updateTimer = new QTimer(q);-
1831 QObject::connect(updateTimer, SIGNAL(timeout()), q, SLOT(_q_updateColorPicking()));-
1832#endif-
1833 retranslateStrings();-
1834}
never executed: end of block
0
1835-
1836void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h)-
1837{-
1838 QColorDialog *d = q_func();-
1839 QObject::connect(h, SIGNAL(currentColorChanged(QColor)), d, SIGNAL(currentColorChanged(QColor)));-
1840 QObject::connect(h, SIGNAL(colorSelected(QColor)), d, SIGNAL(colorSelected(QColor)));-
1841 static_cast<QPlatformColorDialogHelper *>(h)->setOptions(options);-
1842}
never executed: end of block
0
1843-
1844void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)-
1845{-
1846 options->setWindowTitle(q_func()->windowTitle());-
1847}
never executed: end of block
0
1848-
1849void QColorDialogPrivate::_q_addCustom()-
1850{-
1851 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());-
1852 if (custom)
customDescription
TRUEnever evaluated
FALSEnever evaluated
0
1853 custom->update();
never executed: custom->update();
0
1854 nextCust = (nextCust+1) % 16;-
1855}
never executed: end of block
0
1856-
1857void QColorDialogPrivate::retranslateStrings()-
1858{-
1859 if (!smallDisplay) {
!smallDisplayDescription
TRUEnever evaluated
FALSEnever evaluated
0
1860 lblBasicColors->setText(QColorDialog::tr("&Basic colors"));-
1861 lblCustomColors->setText(QColorDialog::tr("&Custom colors"));-
1862 addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));-
1863 screenColorPickerButton->setText(QColorDialog::tr("&Pick Screen Color"));-
1864 }
never executed: end of block
0
1865-
1866 cs->retranslateStrings();-
1867}
never executed: end of block
0
1868-
1869bool QColorDialogPrivate::canBeNativeDialog() const-
1870{-
1871 // Don't use Q_Q here! This function is called from ~QDialog,-
1872 // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).-
1873 const QDialog * const q = static_cast<const QDialog*>(q_ptr);-
1874 if (nativeDialogInUse)
nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1875 return true;
never executed: return true;
0
1876 if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs)
QCoreApplicati...NativeDialogs)Description
TRUEnever evaluated
FALSEnever evaluated
0
1877 || q->testAttribute(Qt::WA_DontShowOnScreen)
q->testAttribu...tShowOnScreen)Description
TRUEnever evaluated
FALSEnever evaluated
0
1878 || (options->options() & QColorDialog::DontUseNativeDialog)) {
(options->opti...eNativeDialog)Description
TRUEnever evaluated
FALSEnever evaluated
0
1879 return false;
never executed: return false;
0
1880 }-
1881-
1882 QLatin1String staticName(QColorDialog::staticMetaObject.className());-
1883 QLatin1String dynamicName(q->metaObject()->className());-
1884 return (staticName == dynamicName);
never executed: return (staticName == dynamicName);
0
1885}-
1886-
1887static const Qt::WindowFlags DefaultWindowFlags =-
1888 Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint-
1889 | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;-
1890-
1891/*!-
1892 \class QColorDialog-
1893 \brief The QColorDialog class provides a dialog widget for specifying colors.-
1894-
1895 \ingroup standard-dialogs-
1896 \inmodule QtWidgets-
1897-
1898 The color dialog's function is to allow users to choose colors.-
1899 For example, you might use this in a drawing program to allow the-
1900 user to set the brush color.-
1901-
1902 The static functions provide modal color dialogs.-
1903 \omit-
1904 If you require a modeless dialog, use the QColorDialog constructor.-
1905 \endomit-
1906-
1907 The static getColor() function shows the dialog, and allows the user to-
1908 specify a color. This function can also be used to let users choose a-
1909 color with a level of transparency: pass the ShowAlphaChannel option as-
1910 an additional argument.-
1911-
1912 The user can store customCount() different custom colors. The-
1913 custom colors are shared by all color dialogs, and remembered-
1914 during the execution of the program. Use setCustomColor() to set-
1915 the custom colors, and use customColor() to get them.-
1916-
1917 When pressing the "Pick Screen Color" button, the cursor changes to a haircross-
1918 and the colors on the screen are scanned. The user can pick up one by clicking-
1919 the mouse or the Enter button. Pressing Escape restores the last color selected-
1920 before entering this mode.-
1921-
1922 The \l{dialogs/standarddialogs}{Standard Dialogs} example shows-
1923 how to use QColorDialog as well as other built-in Qt dialogs.-
1924-
1925 \image fusion-colordialog.png A color dialog in the Fusion widget style.-
1926-
1927 \sa QColor, QFileDialog, QFontDialog, {Standard Dialogs Example}-
1928*/-
1929-
1930/*!-
1931 \since 4.5-
1932-
1933 Constructs a color dialog with the given \a parent.-
1934*/-
1935QColorDialog::QColorDialog(QWidget *parent)-
1936 : QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)-
1937{-
1938 Q_D(QColorDialog);-
1939 d->init(Qt::white);-
1940}
never executed: end of block
0
1941-
1942/*!-
1943 \since 4.5-
1944-
1945 Constructs a color dialog with the given \a parent and specified-
1946 \a initial color.-
1947*/-
1948QColorDialog::QColorDialog(const QColor &initial, QWidget *parent)-
1949 : QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)-
1950{-
1951 Q_D(QColorDialog);-
1952 d->init(initial);-
1953}
never executed: end of block
0
1954-
1955void QColorDialogPrivate::setCurrentColor(const QColor &color, SetColorMode setColorMode)-
1956{-
1957 if (nativeDialogInUse) {
nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1958 platformColorDialogHelper()->setCurrentColor(color);-
1959 return;
never executed: return;
0
1960 }-
1961-
1962 if (setColorMode & ShowColor) {
setColorMode & ShowColorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1963 setCurrentRgbColor(color.rgb());-
1964 setCurrentAlpha(color.alpha());-
1965 }
never executed: end of block
0
1966 if (setColorMode & SelectColor)
setColorMode & SelectColorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1967 selectColor(color);
never executed: selectColor(color);
0
1968}
never executed: end of block
0
1969-
1970/*!-
1971 \property QColorDialog::currentColor-
1972 \brief the currently selected color in the dialog-
1973*/-
1974-
1975void QColorDialog::setCurrentColor(const QColor &color)-
1976{-
1977 Q_D(QColorDialog);-
1978 d->setCurrentColor(color);-
1979}
never executed: end of block
0
1980-
1981QColor QColorDialog::currentColor() const-
1982{-
1983 Q_D(const QColorDialog);-
1984 return d->currentQColor();
never executed: return d->currentQColor();
0
1985}-
1986-
1987/*!-
1988 Returns the color that the user selected by clicking the \uicontrol{OK}-
1989 or equivalent button.-
1990-
1991 \note This color is not always the same as the color held by the-
1992 \l currentColor property since the user can choose different colors-
1993 before finally selecting the one to use.-
1994*/-
1995QColor QColorDialog::selectedColor() const-
1996{-
1997 Q_D(const QColorDialog);-
1998 return d->selectedQColor;
never executed: return d->selectedQColor;
0
1999}-
2000-
2001/*!-
2002 Sets the given \a option to be enabled if \a on is true;-
2003 otherwise, clears the given \a option.-
2004-
2005 \sa options, testOption()-
2006*/-
2007void QColorDialog::setOption(ColorDialogOption option, bool on)-
2008{-
2009 const QColorDialog::ColorDialogOptions previousOptions = options();-
2010 if (!(previousOptions & option) != !on)
!(previousOpti...option) != !onDescription
TRUEnever evaluated
FALSEnever evaluated
0
2011 setOptions(previousOptions ^ option);
never executed: setOptions(previousOptions ^ option);
0
2012}
never executed: end of block
0
2013-
2014/*!-
2015 \since 4.5-
2016-
2017 Returns \c true if the given \a option is enabled; otherwise, returns-
2018 false.-
2019-
2020 \sa options, setOption()-
2021*/-
2022bool QColorDialog::testOption(ColorDialogOption option) const-
2023{-
2024 Q_D(const QColorDialog);-
2025 return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
never executed: return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
0
2026}-
2027-
2028/*!-
2029 \property QColorDialog::options-
2030 \brief the various options that affect the look and feel of the dialog-
2031-
2032 By default, all options are disabled.-
2033-
2034 Options should be set before showing the dialog. Setting them while the-
2035 dialog is visible is not guaranteed to have an immediate effect on the-
2036 dialog (depending on the option and on the platform).-
2037-
2038 \sa setOption(), testOption()-
2039*/-
2040void QColorDialog::setOptions(ColorDialogOptions options)-
2041{-
2042 Q_D(QColorDialog);-
2043-
2044 if (QColorDialog::options() == options)
QColorDialog::...s() == optionsDescription
TRUEnever evaluated
FALSEnever evaluated
0
2045 return;
never executed: return;
0
2046-
2047 d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));-
2048 if ((options & DontUseNativeDialog) && d->nativeDialogInUse) {
(options & Don...eNativeDialog)Description
TRUEnever evaluated
FALSEnever evaluated
d->nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
2049 d->nativeDialogInUse = false;-
2050 d->initWidgets();-
2051 }
never executed: end of block
0
2052 if (!d->nativeDialogInUse) {
!d->nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
2053 d->buttons->setVisible(!(options & NoButtons));-
2054 d->showAlpha(options & ShowAlphaChannel);-
2055 }
never executed: end of block
0
2056}
never executed: end of block
0
2057-
2058QColorDialog::ColorDialogOptions QColorDialog::options() const-
2059{-
2060 Q_D(const QColorDialog);-
2061 return QColorDialog::ColorDialogOptions(int(d->options->options()));
never executed: return QColorDialog::ColorDialogOptions(int(d->options->options()));
0
2062}-
2063-
2064/*!-
2065 \enum QColorDialog::ColorDialogOption-
2066-
2067 \since 4.5-
2068-
2069 This enum specifies various options that affect the look and feel-
2070 of a color dialog.-
2071-
2072 \value ShowAlphaChannel Allow the user to select the alpha component of a color.-
2073 \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)-
2074 \value DontUseNativeDialog Use Qt's standard color dialog instead of the operating system-
2075 native color dialog.-
2076-
2077 \sa options, setOption(), testOption(), windowModality()-
2078*/-
2079-
2080/*!-
2081 \fn void QColorDialog::currentColorChanged(const QColor &color)-
2082-
2083 This signal is emitted whenever the current color changes in the dialog.-
2084 The current color is specified by \a color.-
2085-
2086 \sa color, colorSelected()-
2087*/-
2088-
2089/*!-
2090 \fn void QColorDialog::colorSelected(const QColor &color);-
2091-
2092 This signal is emitted just after the user has clicked \uicontrol{OK} to-
2093 select a color to use. The chosen color is specified by \a color.-
2094-
2095 \sa color, currentColorChanged()-
2096*/-
2097-
2098/*!-
2099 Changes the visibility of the dialog. If \a visible is true, the dialog-
2100 is shown; otherwise, it is hidden.-
2101*/-
2102void QColorDialog::setVisible(bool visible)-
2103{-
2104 Q_D(QColorDialog);-
2105-
2106 if (visible){
visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
2107 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
testAttribute(...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
!testAttribute...WState_Hidden)Description
TRUEnever evaluated
FALSEnever evaluated
0
2108 return;
never executed: return;
0
2109 } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
never executed: end of block
testAttribute(...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
testAttribute(...WState_Hidden)Description
TRUEnever evaluated
FALSEnever evaluated
0
2110 return;
never executed: return;
0
2111-
2112 if (visible)
visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
2113 d->selectedQColor = QColor();
never executed: d->selectedQColor = QColor();
0
2114-
2115 if (d->nativeDialogInUse) {
d->nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
0
2116 d->setNativeDialogVisible(visible);-
2117 // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below-
2118 // updates the state correctly, but skips showing the non-native version:-
2119 setAttribute(Qt::WA_DontShowOnScreen);-
2120 } else {
never executed: end of block
0
2121 setAttribute(Qt::WA_DontShowOnScreen, false);-
2122 }
never executed: end of block
0
2123-
2124 QDialog::setVisible(visible);-
2125}
never executed: end of block
0
2126-
2127/*!-
2128 \overload-
2129 \since 4.5-
2130-
2131 Opens the dialog and connects its colorSelected() signal to the slot specified-
2132 by \a receiver and \a member.-
2133-
2134 The signal will be disconnected from the slot when the dialog is closed.-
2135*/-
2136void QColorDialog::open(QObject *receiver, const char *member)-
2137{-
2138 Q_D(QColorDialog);-
2139 connect(this, SIGNAL(colorSelected(QColor)), receiver, member);-
2140 d->receiverToDisconnectOnClose = receiver;-
2141 d->memberToDisconnectOnClose = member;-
2142 QDialog::open();-
2143}
never executed: end of block
0
2144-
2145/*!-
2146 \since 4.5-
2147-
2148 Pops up a modal color dialog with the given window \a title (or "Select Color" if none is-
2149 specified), lets the user choose a color, and returns that color. The color is initially set-
2150 to \a initial. The dialog is a child of \a parent. It returns an invalid (see-
2151 QColor::isValid()) color if the user cancels the dialog.-
2152-
2153 The \a options argument allows you to customize the dialog.-
2154*/-
2155QColor QColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title,-
2156 ColorDialogOptions options)-
2157{-
2158 QColorDialog dlg(parent);-
2159 if (!title.isEmpty())
!title.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2160 dlg.setWindowTitle(title);
never executed: dlg.setWindowTitle(title);
0
2161 dlg.setOptions(options);-
2162 dlg.setCurrentColor(initial);-
2163 dlg.exec();-
2164 return dlg.selectedColor();
never executed: return dlg.selectedColor();
0
2165}-
2166-
2167/*!-
2168 \obsolete-
2169-
2170 Pops up a modal color dialog to allow the user to choose a color-
2171 and an alpha channel (transparency) value. The color+alpha is-
2172 initially set to \a initial. The dialog is a child of \a parent.-
2173-
2174 If \a ok is non-null, \e *\a ok is set to true if the user clicked-
2175 \uicontrol{OK}, and to false if the user clicked Cancel.-
2176-
2177 If the user clicks Cancel, the \a initial value is returned.-
2178-
2179 Use QColorDialog::getColor() instead, passing the-
2180 QColorDialog::ShowAlphaChannel option.-
2181*/-
2182-
2183QRgb QColorDialog::getRgba(QRgb initial, bool *ok, QWidget *parent)-
2184{-
2185 const QColor color = getColor(QColor::fromRgba(initial), parent, QString(),-
2186 ShowAlphaChannel);-
2187 QRgb result = color.isValid() ? color.rgba() : initial;
color.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2188 if (ok)
okDescription
TRUEnever evaluated
FALSEnever evaluated
0
2189 *ok = color.isValid();
never executed: *ok = color.isValid();
0
2190 return result;
never executed: return result;
0
2191}-
2192-
2193/*!-
2194 Destroys the color dialog.-
2195*/-
2196-
2197QColorDialog::~QColorDialog()-
2198{-
2199-
2200}-
2201-
2202/*!-
2203 \reimp-
2204*/-
2205void QColorDialog::changeEvent(QEvent *e)-
2206{-
2207 Q_D(QColorDialog);-
2208 if (e->type() == QEvent::LanguageChange)
e->type() == Q...LanguageChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2209 d->retranslateStrings();
never executed: d->retranslateStrings();
0
2210 QDialog::changeEvent(e);-
2211}
never executed: end of block
0
2212-
2213void QColorDialogPrivate::_q_updateColorPicking()-
2214{-
2215#ifndef QT_NO_CURSOR-
2216 Q_Q(QColorDialog);-
2217 static QPoint lastGlobalPos;-
2218 QPoint newGlobalPos = QCursor::pos();-
2219 if (lastGlobalPos == newGlobalPos)
lastGlobalPos == newGlobalPosDescription
TRUEnever evaluated
FALSEnever evaluated
0
2220 return;
never executed: return;
0
2221 lastGlobalPos = newGlobalPos;-
2222-
2223 if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called
!q->rect().con...newGlobalPos))Description
TRUEnever evaluated
FALSEnever evaluated
0
2224 updateColorPicking(newGlobalPos);-
2225#ifdef Q_OS_WIN32-
2226 dummyTransparentWindow.setPosition(newGlobalPos);-
2227#endif-
2228 }
never executed: end of block
0
2229#endif // ! QT_NO_CURSOR-
2230}
never executed: end of block
0
2231-
2232void QColorDialogPrivate::updateColorPicking(const QPoint &globalPos)-
2233{-
2234 const QColor color = grabScreenColor(globalPos);-
2235 // QTBUG-39792, do not change standard, custom color selectors while moving as-
2236 // otherwise it is not possible to pre-select a custom cell for assignment.-
2237 setCurrentColor(color, ShowColor);-
2238 updateColorLabelText(globalPos);-
2239-
2240}
never executed: end of block
0
2241-
2242bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)-
2243{-
2244 // If the cross is visible the grabbed color will be black most of the times-
2245 cp->setCrossVisible(!cp->geometry().contains(e->pos()));-
2246-
2247 updateColorPicking(e->globalPos());-
2248 return true;
never executed: return true;
0
2249}-
2250-
2251bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e)-
2252{-
2253 setCurrentColor(grabScreenColor(e->globalPos()), SetColorAll);-
2254 releaseColorPicking();-
2255 return true;
never executed: return true;
0
2256}-
2257-
2258bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e)-
2259{-
2260 Q_Q(QColorDialog);-
2261 if (e->matches(QKeySequence::Cancel)) {
e->matches(QKe...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
0
2262 releaseColorPicking();-
2263 q->setCurrentColor(beforeScreenColorPicking);-
2264 } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
never executed: end of block
e->key() == Qt::Key_ReturnDescription
TRUEnever evaluated
FALSEnever evaluated
e->key() == Qt::Key_EnterDescription
TRUEnever evaluated
FALSEnever evaluated
0
2265 q->setCurrentColor(grabScreenColor(QCursor::pos()));-
2266 releaseColorPicking();-
2267 }
never executed: end of block
0
2268 e->accept();-
2269 return true;
never executed: return true;
0
2270}-
2271-
2272/*!-
2273 Closes the dialog and sets its result code to \a result. If this dialog-
2274 is shown with exec(), done() causes the local event loop to finish,-
2275 and exec() to return \a result.-
2276-
2277 \sa QDialog::done()-
2278*/-
2279void QColorDialog::done(int result)-
2280{-
2281 Q_D(QColorDialog);-
2282 if (result == Accepted) {
result == AcceptedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2283 d->selectedQColor = d->currentQColor();-
2284 emit colorSelected(d->selectedQColor);-
2285 } else {
never executed: end of block
0
2286 d->selectedQColor = QColor();-
2287 }
never executed: end of block
0
2288 QDialog::done(result);-
2289 if (d->receiverToDisconnectOnClose) {
d->receiverToDisconnectOnCloseDescription
TRUEnever evaluated
FALSEnever evaluated
0
2290 disconnect(this, SIGNAL(colorSelected(QColor)),-
2291 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);-
2292 d->receiverToDisconnectOnClose = 0;-
2293 }
never executed: end of block
0
2294 d->memberToDisconnectOnClose.clear();-
2295}
never executed: end of block
0
2296-
2297QT_END_NAMESPACE-
2298-
2299#include "qcolordialog.moc"-
2300#include "moc_qcolordialog.cpp"-
2301-
2302#endif // QT_NO_COLORDIALOG-
2303-
Source codeSwitch to Preprocessed file

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