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

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