dialogs/qcolordialog.cpp

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

Generated by Squish Coco Non-Commercial