1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#include "qcolordialog_p.h"
44
#ifndef QT_NO_COLORDIALOG
46
#include "qapplication.h"
47
#include "qdesktopwidget.h"
48
#include "qdrawutil.h"
54
#include "qlineedit.h"
58
#include "qpushbutton.h"
59
#include "qsettings.h"
61
#include "qstyleoption.h"
62
#include "qvalidator.h"
63
#include "qmimedata.h"
65
#include "qdialogbuttonbox.h"
69
//////////// QWellArray BEGIN
71
struct QWellArrayData;
73
class QWellArray : public QWidget
76
Q_PROPERTY(int selectedColumn READ selectedColumn)
77
Q_PROPERTY(int selectedRow READ selectedRow)
80
QWellArray(int rows, int cols, QWidget* parent=0);
82
QString cellContent(int row, int col) const;
84
int selectedColumn() const { return selCol; }
85
int selectedRow() const { return selRow; }
87
virtual void setCurrent(int row, int col);
88
virtual void setSelected(int row, int col);
90
QSize sizeHint() const;
92
virtual void setCellBrush(int row, int col, const QBrush &);
93
QBrush cellBrush(int row, int col);
95
inline int cellWidth() const
98
inline int cellHeight() const
101
inline int rowAt(int y) const
102
{ return y / cellh; }
104
inline int columnAt(int x) const
105
{ if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
107
inline int rowY(int row) const
108
{ return cellh * row; }
110
inline int columnX(int column) const
111
{ if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
113
inline int numRows() const
116
inline int numCols() const
119
inline QRect cellRect() const
120
{ return QRect(0, 0, cellw, cellh); }
122
inline QSize gridSize() const
123
{ return QSize(ncols * cellw, nrows * cellh); }
125
QRect cellGeometry(int row, int column)
128
if (row >= 0 && row < nrows && column >= 0 && column < ncols)
129
r.setRect(columnX(column), rowY(row), cellw, cellh);
133
inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
136
void selected(int row, int col);
139
virtual void paintCell(QPainter *, int row, int col, const QRect&);
140
virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
142
void mousePressEvent(QMouseEvent*);
143
void mouseReleaseEvent(QMouseEvent*);
144
void keyPressEvent(QKeyEvent*);
145
void focusInEvent(QFocusEvent*);
146
void focusOutEvent(QFocusEvent*);
147
void paintEvent(QPaintEvent *);
150
Q_DISABLE_COPY(QWellArray)
163
void QWellArray::paintEvent(QPaintEvent *e)
170
int colfirst = columnAt(cx);
171
int collast = columnAt(cx + cw);
172
int rowfirst = rowAt(cy);
173
int rowlast = rowAt(cy + ch);
175
if (isRightToLeft()) {
181
QPainter painter(this);
182
QPainter *p = &painter;
183
QRect rect(0, 0, cellWidth(), cellHeight());
186
if (collast < 0 || collast >= ncols)
188
if (rowlast < 0 || rowlast >= nrows)
191
// Go through the rows
192
for (int r = rowfirst; r <= rowlast; ++r) {
193
// get row position and height
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);
210
struct QWellArrayData {
214
QWellArray::QWellArray(int rows, int cols, QWidget *parent)
216
,nrows(rows), ncols(cols)
219
setFocusPolicy(Qt::StrongFocus);
228
QSize QWellArray::sizeHint() const
231
return gridSize().boundedTo(QSize(640, 480));
235
void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
239
const QPalette & g = palette();
240
QStyleOptionFrame opt;
241
int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
243
opt.midLineWidth = 1;
244
opt.rect = rect.adjusted(b, b, -b, -b);
246
opt.state = QStyle::State_Enabled | QStyle::State_Sunken;
247
style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this);
250
if ((row == curRow) && (col == curCol)) {
252
QStyleOptionFocusRect opt;
255
opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange;
256
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this);
259
paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));
263
Reimplement this function to change the contents of the well array.
265
void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
268
p->fillRect(r, d->brush[row*numCols()+col]);
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());
277
void QWellArray::mousePressEvent(QMouseEvent *e)
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()));
284
void QWellArray::mouseReleaseEvent(QMouseEvent * /* event */)
286
// The current cell marker is set to the cell the mouse is clicked in
287
setSelected(curRow, curCol);
292
Sets the cell currently having the focus. This is not necessarily
293
the same as the currently selected cell.
296
void QWellArray::setCurrent(int row, int col)
298
if ((curRow == row) && (curCol == col))
301
if (row < 0 || col < 0)
310
updateCell(oldRow, oldCol);
311
updateCell(curRow, curCol);
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.
318
Does not set the position of the focus indicator.
320
void QWellArray::setSelected(int row, int col)
325
if (row < 0 || col < 0)
331
updateCell(oldRow, oldCol);
332
updateCell(selRow, selCol);
334
emit selected(row, col);
337
if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
338
parentWidget()->close();
342
void QWellArray::focusInEvent(QFocusEvent*)
344
updateCell(curRow, curCol);
347
void QWellArray::setCellBrush(int row, int col, const QBrush &b)
350
d = new QWellArrayData;
351
int i = numRows()*numCols();
352
d->brush = new QBrush[i];
354
if (row >= 0 && row < numRows() && col >= 0 && col < numCols())
355
d->brush[row*numCols()+col] = b;
359
Returns the brush set for the cell at \a row, \a column. If no brush is
360
set, Qt::NoBrush is returned.
363
QBrush QWellArray::cellBrush(int row, int col)
365
if (d && row >= 0 && row < numRows() && col >= 0 && col < numCols())
366
return d->brush[row*numCols()+col];
375
void QWellArray::focusOutEvent(QFocusEvent*)
377
updateCell(curRow, curCol);
382
void QWellArray::keyPressEvent(QKeyEvent* e)
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
389
case Qt::Key_Right: // Correspondingly...
390
if(curCol < numCols()-1)
391
setCurrent(curRow, curCol + 1);
395
setCurrent(curRow - 1, curCol);
398
if(curRow < numRows()-1)
399
setCurrent(curRow + 1, curCol);
402
// bad idea that shouldn't have been implemented; very counterintuitive
406
ignore the key, so that the dialog get it, but still select
410
// fallthrough intended
413
setSelected(curRow, curCol);
415
default: // If not an interesting key,
416
e->ignore(); // we don't accept the event
422
//////////// QWellArray END
425
Returns the number of custom colors supported by QColorDialog. All
426
color dialogs share the same custom colors.
428
int QColorDialog::customCount()
430
return QColorDialogOptions::customColorCount();
436
Returns the custom color at the given \a index as a QColor value.
438
QColor QColorDialog::customColor(int index)
440
return QColor(QColorDialogOptions::customColor(index));
444
Sets the custom color at \a index to the QColor \a color value.
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.
450
void QColorDialog::setCustomColor(int index, QColor color)
452
QColorDialogOptions::setCustomColor(index, color.rgba());
458
Returns the standard color at the given \a index as a QColor value.
460
QColor QColorDialog::standardColor(int index)
462
return QColor(QColorDialogOptions::standardColor(index));
466
Sets the standard color at \a index to the QColor \a color value.
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.
472
void QColorDialog::setStandardColor(int index, QColor color)
474
QColorDialogOptions::setStandardColor(index, color.rgba());
477
static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
481
c.getHsv(&h, &s, &v);
484
class QColorWell : public QWellArray
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)); }
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);
511
void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)
513
int i = row + col*numRows();
514
p->fillRect(r, QColor(values[i]));
517
void QColorWell::mousePressEvent(QMouseEvent *e)
519
oldCurrent = QPoint(selectedRow(), selectedColumn());
520
QWellArray::mousePressEvent(e);
525
void QColorWell::mouseMoveEvent(QMouseEvent *e)
527
QWellArray::mouseMoveEvent(e);
528
#ifndef QT_NO_DRAGANDDROP
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());
540
p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
542
QDrag *drg = new QDrag(this);
543
drg->setMimeData(mime);
545
mousePressed = false;
551
#ifndef QT_NO_DRAGANDDROP
552
void QColorWell::dragEnterEvent(QDragEnterEvent *e)
554
if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
560
void QColorWell::dragLeaveEvent(QDragLeaveEvent *)
563
parentWidget()->setFocus();
566
void QColorWell::dragMoveEvent(QDragMoveEvent *e)
568
if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) {
569
setCurrent(rowAt(e->pos().y()), columnAt(e->pos().x()));
576
void QColorWell::dropEvent(QDropEvent *e)
578
QColor col = qvariant_cast<QColor>(e->mimeData()->colorData());
580
int i = rowAt(e->pos().y()) + columnAt(e->pos().x()) * numRows();
581
values[i] = col.rgb();
589
#endif // QT_NO_DRAGANDDROP
591
void QColorWell::mouseReleaseEvent(QMouseEvent *e)
595
QWellArray::mouseReleaseEvent(e);
596
mousePressed = false;
599
class QColorPicker : public QFrame
603
QColorPicker(QWidget* parent);
607
void setCol(int h, int s);
610
void newCol(int h, int s);
613
QSize sizeHint() const;
614
void paintEvent(QPaintEvent*);
615
void mouseMoveEvent(QMouseEvent *);
616
void mousePressEvent(QMouseEvent *);
617
void resizeEvent(QResizeEvent *);
624
int huePt(const QPoint &pt);
625
int satPt(const QPoint &pt);
626
void setCol(const QPoint &pt);
631
static int pWidth = 220;
632
static int pHeight = 200;
634
class QColorLuminancePicker : public QWidget
638
QColorLuminancePicker(QWidget* parent=0);
639
~QColorLuminancePicker();
642
void setCol(int h, int s, int v);
643
void setCol(int h, int s);
646
void newHsv(int h, int s, int v);
649
void paintEvent(QPaintEvent*);
650
void mouseMoveEvent(QMouseEvent *);
651
void mousePressEvent(QMouseEvent *);
654
enum { foff = 3, coff = 4 }; //frame and contents offset
667
int QColorLuminancePicker::y2val(int y)
669
int d = height() - 2*coff - 1;
670
return 255 - (y - coff)*255/d;
673
int QColorLuminancePicker::val2y(int v)
675
int d = height() - 2*coff - 1;
676
return coff + (255-v)*d/255;
679
QColorLuminancePicker::QColorLuminancePicker(QWidget* parent)
682
hue = 100; val = 100; sat = 100;
684
// setAttribute(WA_NoErase, true);
687
QColorLuminancePicker::~QColorLuminancePicker()
692
void QColorLuminancePicker::mouseMoveEvent(QMouseEvent *m)
694
setVal(y2val(m->y()));
696
void QColorLuminancePicker::mousePressEvent(QMouseEvent *m)
698
setVal(y2val(m->y()));
701
void QColorLuminancePicker::setVal(int v)
705
val = qMax(0, qMin(v,255));
708
emit newHsv(hue, sat, val);
711
//receives from a hue,sat chooser and relays.
712
void QColorLuminancePicker::setCol(int h, int s)
715
emit newHsv(h, s, val);
718
void QColorLuminancePicker::paintEvent(QPaintEvent *)
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) {
727
QImage img(wi, hi, QImage::Format_RGB32);
729
uint *pixel = (uint *) img.scanLine(0);
730
for (y = 0; y < hi; y++) {
731
const uint *end = pixel + wi;
732
while (pixel < end) {
734
c.setHsv(hue, sat, y2val(y+coff));
739
pix = new QPixmap(QPixmap::fromImage(img));
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());
749
a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
750
p.eraseRect(w, 0, 5, height());
754
void QColorLuminancePicker::setCol(int h, int s , int v)
763
QPoint QColorPicker::colPt()
765
QRect r = contentsRect();
766
return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
769
int QColorPicker::huePt(const QPoint &pt)
771
QRect r = contentsRect();
772
return 360 - pt.x() * 360 / (r.width() - 1);
775
int QColorPicker::satPt(const QPoint &pt)
777
QRect r = contentsRect();
778
return 255 - pt.y() * 255 / (r.height() - 1);
781
void QColorPicker::setCol(const QPoint &pt)
783
setCol(huePt(pt), satPt(pt));
786
QColorPicker::QColorPicker(QWidget* parent)
792
setAttribute(Qt::WA_NoSystemBackground);
793
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
796
QColorPicker::~QColorPicker()
800
QSize QColorPicker::sizeHint() const
802
return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
805
void QColorPicker::setCol(int h, int s)
807
int nhue = qMin(qMax(0,h), 359);
808
int nsat = qMin(qMax(0,s), 255);
809
if (nhue == hue && nsat == sat)
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);
820
void QColorPicker::mouseMoveEvent(QMouseEvent *m)
822
QPoint p = m->pos() - contentsRect().topLeft();
824
emit newCol(hue, sat);
827
void QColorPicker::mousePressEvent(QMouseEvent *m)
829
QPoint p = m->pos() - contentsRect().topLeft();
831
emit newCol(hue, sat);
834
void QColorPicker::paintEvent(QPaintEvent* )
838
QRect r = contentsRect();
840
p.drawPixmap(r.topLeft(), pix);
841
QPoint pt = colPt() + r.topLeft();
844
p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
845
p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
849
void QColorPicker::resizeEvent(QResizeEvent *ev)
851
QFrame::resizeEvent(ev);
853
int w = width() - frameWidth() * 2;
854
int h = height() - frameWidth() * 2;
855
QImage img(w, h, QImage::Format_RGB32);
857
uint *pixel = (uint *) img.scanLine(0);
858
for (y = 0; y < h; y++) {
859
const uint *end = pixel + w;
861
while (pixel < end) {
864
c.setHsv(huePt(p), satPt(p), 200);
870
pix = QPixmap::fromImage(img);
874
class QColSpinBox : public QSpinBox
877
QColSpinBox(QWidget *parent)
878
: QSpinBox(parent) { setRange(0, 255); }
879
void setValue(int i) {
880
bool block = signalsBlocked();
882
QSpinBox::setValue(i);
887
class QColorShowLabel;
889
class QColorShower : public QWidget
893
QColorShower(QColorDialog *parent);
895
//things that don't emit signals
896
void setHsv(int h, int s, int v);
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;
904
QRgb currentColor() const { return curCol; }
905
QColor currentQColor() const { return curQColor; }
906
void retranslateStrings();
910
void setRgb(QRgb rgb);
913
void newCol(QRgb rgb);
914
void currentColorChanged(const QColor &color);
920
void showCurrentColor();
936
QColSpinBox *alphaEd;
938
QColorShowLabel *lab;
940
QColorDialog *colorDialog;
942
friend class QColorDialog;
943
friend class QColorDialogPrivate;
946
class QColorShowLabel : public QFrame
951
QColorShowLabel(QWidget *parent) : QFrame(parent) {
952
setFrameStyle(QFrame::Panel|QFrame::Sunken);
953
setAcceptDrops(true);
954
mousePressed = false;
956
void setColor(QColor c) { col = c; }
959
void colorDropped(QRgb);
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);
978
void QColorShowLabel::paintEvent(QPaintEvent *e)
982
p.fillRect(contentsRect()&e->rect(), col);
985
void QColorShower::showAlpha(bool b)
987
alphaLab->setVisible(b);
988
alphaEd->setVisible(b);
991
inline bool QColorShower::isAlphaVisible() const
993
return alphaLab->isVisible();
996
void QColorShowLabel::mousePressEvent(QMouseEvent *e)
1002
void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)
1004
#ifdef QT_NO_DRAGANDDROP
1009
if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
1010
QMimeData *mime = new QMimeData;
1011
mime->setColorData(col);
1012
QPixmap pix(30, 20);
1015
p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
1017
QDrag *drg = new QDrag(this);
1018
drg->setMimeData(mime);
1019
drg->setPixmap(pix);
1020
mousePressed = false;
1026
#ifndef QT_NO_DRAGANDDROP
1027
void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e)
1029
if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
1035
void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *)
1039
void QColorShowLabel::dropEvent(QDropEvent *e)
1041
QColor color = qvariant_cast<QColor>(e->mimeData()->colorData());
1042
if (color.isValid()) {
1045
emit colorDropped(col.rgb());
1051
#endif // QT_NO_DRAGANDDROP
1053
void QColorShowLabel::mouseReleaseEvent(QMouseEvent *)
1057
mousePressed = false;
1060
QColorShower::QColorShower(QColorDialog *parent)
1063
colorDialog = parent;
1065
curCol = qRgb(255, 255, 255);
1066
curQColor = Qt::white;
1068
QGridLayout *gl = new QGridLayout(this);
1069
gl->setMargin(gl->spacing());
1070
lab = new QColorShowLabel(this);
1073
#ifdef QT_SMALL_COLORDIALOG
1074
lab->setMinimumHeight(60);
1076
lab->setMinimumWidth(60);
1078
lab->setMinimumWidth(20);
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);
1087
gl->addWidget(lab, 0, 0, 1, -1);
1089
gl->addWidget(lab, 0, 0, -1, 1);
1091
connect(lab, SIGNAL(colorDropped(QRgb)), this, SIGNAL(newCol(QRgb)));
1092
connect(lab, SIGNAL(colorDropped(QRgb)), this, SLOT(setRgb(QRgb)));
1094
hEd = new QColSpinBox(this);
1095
hEd->setRange(0, 359);
1096
lblHue = new QLabel(this);
1097
#ifndef QT_NO_SHORTCUT
1098
lblHue->setBuddy(hEd);
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);
1106
gl->addWidget(lblHue, 1, 0);
1107
gl->addWidget(hEd, 2, 0);
1114
sEd = new QColSpinBox(this);
1115
lblSat = new QLabel(this);
1116
#ifndef QT_NO_SHORTCUT
1117
lblSat->setBuddy(sEd);
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);
1125
gl->addWidget(lblSat, 1, 1);
1126
gl->addWidget(sEd, 2, 1);
1133
vEd = new QColSpinBox(this);
1134
lblVal = new QLabel(this);
1135
#ifndef QT_NO_SHORTCUT
1136
lblVal->setBuddy(vEd);
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);
1144
gl->addWidget(lblVal, 1, 2);
1145
gl->addWidget(vEd, 2, 2);
1152
rEd = new QColSpinBox(this);
1153
lblRed = new QLabel(this);
1154
#ifndef QT_NO_SHORTCUT
1155
lblRed->setBuddy(rEd);
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);
1163
gl->addWidget(lblRed, 3, 0);
1164
gl->addWidget(rEd, 4, 0);
1171
gEd = new QColSpinBox(this);
1172
lblGreen = new QLabel(this);
1173
#ifndef QT_NO_SHORTCUT
1174
lblGreen->setBuddy(gEd);
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);
1182
gl->addWidget(lblGreen, 3, 1);
1183
gl->addWidget(gEd, 4, 1);
1190
bEd = new QColSpinBox(this);
1191
lblBlue = new QLabel(this);
1192
#ifndef QT_NO_SHORTCUT
1193
lblBlue->setBuddy(bEd);
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);
1201
gl->addWidget(lblBlue, 3, 2);
1202
gl->addWidget(bEd, 4, 2);
1209
alphaEd = new QColSpinBox(this);
1210
alphaLab = new QLabel(this);
1211
#ifndef QT_NO_SHORTCUT
1212
alphaLab->setBuddy(alphaEd);
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);
1220
gl->addWidget(alphaLab, 1, 3, 3, 1);
1221
gl->addWidget(alphaEd, 4, 3);
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()));
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()));
1239
retranslateStrings();
1242
inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); }
1243
inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); }
1244
inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); }
1245
inline void QColorDialogPrivate::showAlpha(bool b) { cs->showAlpha(b); }
1246
inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisible(); }
1248
QColor QColorDialogPrivate::currentQColor() const
1250
if (!options->testOption(QColorDialogOptions::DontUseNativeDialog) && nativeDialogInUse)
1251
return platformColorDialogHelper()->currentColor();
1252
return cs->currentQColor();
1255
void QColorShower::showCurrentColor()
1257
lab->setColor(currentColor());
1261
void QColorShower::rgbEd()
1264
curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1266
rgb2hsv(currentColor(), hue, sat, val);
1273
emit newCol(currentColor());
1277
void QColorShower::hsvEd()
1279
rgbOriginal = false;
1285
c.setHsv(hue, sat, val);
1288
rEd->setValue(qRed(currentColor()));
1289
gEd->setValue(qGreen(currentColor()));
1290
bEd->setValue(qBlue(currentColor()));
1293
emit newCol(currentColor());
1297
void QColorShower::setRgb(QRgb rgb)
1302
rgb2hsv(currentColor(), hue, sat, val);
1308
rEd->setValue(qRed(currentColor()));
1309
gEd->setValue(qGreen(currentColor()));
1310
bEd->setValue(qBlue(currentColor()));
1316
void QColorShower::setHsv(int h, int s, int v)
1318
if (h < -1 || (uint)s > 255 || (uint)v > 255)
1321
rgbOriginal = false;
1322
hue = h; val = v; sat = s;
1324
c.setHsv(hue, sat, val);
1331
rEd->setValue(qRed(currentColor()));
1332
gEd->setValue(qGreen(currentColor()));
1333
bEd->setValue(qBlue(currentColor()));
1339
void QColorShower::retranslateStrings()
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:"));
1350
void QColorShower::updateQColor()
1352
QColor oldQColor(curQColor);
1353
curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1354
if (curQColor != oldQColor)
1355
emit currentColorChanged(curQColor);
1358
//sets all widgets to display h,s,v
1359
void QColorDialogPrivate::_q_newHsv(int h, int s, int v)
1361
cs->setHsv(h, s, v);
1363
lp->setCol(h, s, v);
1366
//sets all widgets to display rgb
1367
void QColorDialogPrivate::setCurrentColor(QRgb rgb)
1370
_q_newColorTypedIn(rgb);
1373
// hack; doesn't keep curCol in sync, so use with care
1374
void QColorDialogPrivate::setCurrentQColor(const QColor &color)
1377
if (cs->curQColor != color) {
1378
cs->curQColor = color;
1379
emit q->currentColorChanged(color);
1383
bool QColorDialogPrivate::selectColor(const QColor &col)
1385
QRgb color = col.rgb();
1387
// Check standard colors
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();
1402
// Check custom colors
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]) {
1409
custom->setCurrent(i, j);
1410
custom->setSelected(i, j);
1420
//sets all widgets except cs to display rgb
1421
void QColorDialogPrivate::_q_newColorTypedIn(QRgb rgb)
1424
rgb2hsv(rgb, h, s, v);
1426
lp->setCol(h, s, v);
1429
void QColorDialogPrivate::_q_newCustom(int r, int c)
1431
const int i = r + 2 * c;
1432
setCurrentColor(QColorDialogOptions::customColor(i));
1435
standard->setSelected(-1,-1);
1438
void QColorDialogPrivate::_q_newStandard(int r, int c)
1440
setCurrentColor(QColorDialogOptions::standardColor(r + c * 6));
1442
custom->setSelected(-1,-1);
1445
void QColorDialogPrivate::init(const QColor &initial)
1449
q->setSizeGripEnabled(false);
1450
q->setWindowTitle(QColorDialog::tr("Select Color"));
1452
nativeDialogInUse = (platformColorDialogHelper() != 0);
1455
QVBoxLayout *mainLay = new QVBoxLayout(q);
1456
// there's nothing in this dialog that benefits from sizing up
1457
mainLay->setSizeConstraint(QLayout::SetFixedSize);
1459
QHBoxLayout *topLay = new QHBoxLayout();
1460
mainLay->addLayout(topLay);
1464
#if defined(Q_OS_WINCE) || defined(QT_SMALL_COLORDIALOG)
1465
smallDisplay = true;
1466
const int lumSpace = 20;
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;
1474
if (!smallDisplay) {
1475
leftLay = new QVBoxLayout;
1476
topLay->addLayout(leftLay);
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);
1485
q->connect(standard, SIGNAL(selected(int,int)), SLOT(_q_newStandard(int,int)));
1486
leftLay->addWidget(lblBasicColors);
1487
leftLay->addWidget(standard);
1489
#if !defined(Q_OS_WINCE)
1490
leftLay->addStretch();
1493
custom = new QColorWell(q, 2, 8, QColorDialogOptions::customColors());
1494
custom->setAcceptDrops(true);
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);
1501
leftLay->addWidget(lblCustomColors);
1502
leftLay->addWidget(custom);
1504
addCusBt = new QPushButton(q);
1505
QObject::connect(addCusBt, SIGNAL(clicked()), q, SLOT(_q_addCustom()));
1506
leftLay->addWidget(addCusBt);
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());
1513
if(screenSize.height() > screenSize.width())
1523
QVBoxLayout *rightLay = new QVBoxLayout;
1524
topLay->addLayout(rightLay);
1526
QHBoxLayout *pickLay = new QHBoxLayout;
1527
rightLay->addLayout(pickLay);
1529
QVBoxLayout *cLay = new QVBoxLayout;
1530
pickLay->addLayout(cLay);
1531
cp = new QColorPicker(q);
1533
cp->setFrameStyle(QFrame::Panel + QFrame::Sunken);
1535
#if defined(QT_SMALL_COLORDIALOG)
1537
pickLay->addWidget(cp);
1538
cLay->addSpacing(lumSpace);
1543
cLay->addSpacing(lumSpace);
1544
cLay->addWidget(cp);
1546
cLay->addSpacing(lumSpace);
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);
1556
pickLay->addWidget(lp);
1560
lp->setFixedWidth(20);
1561
pickLay->addWidget(lp);
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)));
1567
rightLay->addStretch();
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)
1575
pWidth -= cp->size().width();
1576
topLay->addWidget(cs);
1578
rightLay->addWidget(cs);
1581
buttons = new QDialogButtonBox(q);
1582
mainLay->addWidget(buttons);
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()));
1590
retranslateStrings();
1596
q->setCurrentColor(initial);
1599
void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h)
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);
1607
void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
1609
options->setWindowTitle(q_func()->windowTitle());
1612
void QColorDialogPrivate::_q_addCustom()
1614
QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
1617
nextCust = (nextCust+1) % 16;
1620
void QColorDialogPrivate::retranslateStrings()
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"));
1628
cs->retranslateStrings();
1631
static const Qt::WindowFlags DefaultWindowFlags =
1632
Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint
1633
| Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
1637
\brief The QColorDialog class provides a dialog widget for specifying colors.
1639
\ingroup standard-dialogs
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.
1646
The static functions provide modal color dialogs.
1648
If you require a modeless dialog, use the QColorDialog constructor.
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.
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.
1661
The \l{dialogs/standarddialogs}{Standard Dialogs} example shows
1662
how to use QColorDialog as well as other built-in Qt dialogs.
1664
\image fusion-colordialog.png A color dialog in the Fusion widget style.
1666
\sa QColor, QFileDialog, QFontDialog, {Standard Dialogs Example}
1672
Constructs a color dialog with the given \a parent.
1674
QColorDialog::QColorDialog(QWidget *parent)
1675
: QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)
1684
Constructs a color dialog with the given \a parent and specified
1687
QColorDialog::QColorDialog(const QColor &initial, QWidget *parent)
1688
: QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags)
1695
\property QColorDialog::currentColor
1696
\brief the currently selected color in the dialog
1699
void QColorDialog::setCurrentColor(const QColor &color)
1702
d->setCurrentColor(color.rgb());
1703
d->selectColor(color);
1704
d->setCurrentAlpha(color.alpha());
1706
if (!testOption(QColorDialog::DontUseNativeDialog) && d->nativeDialogInUse)
1707
d->platformColorDialogHelper()->setCurrentColor(color);
1710
QColor QColorDialog::currentColor() const
1712
Q_D(const QColorDialog);
1713
return d->currentQColor();
1717
Returns the color that the user selected by clicking the \uicontrol{OK}
1718
or equivalent button.
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.
1724
QColor QColorDialog::selectedColor() const
1726
Q_D(const QColorDialog);
1727
return d->selectedQColor;
1731
Sets the given \a option to be enabled if \a on is true;
1732
otherwise, clears the given \a option.
1734
\sa options, testOption()
1736
void QColorDialog::setOption(ColorDialogOption option, bool on)
1739
d->options->setOption(static_cast<QColorDialogOptions::ColorDialogOption>(option), on);
1745
Returns true if the given \a option is enabled; otherwise, returns
1748
\sa options, setOption()
1750
bool QColorDialog::testOption(ColorDialogOption option) const
1752
Q_D(const QColorDialog);
1753
return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
1757
\property QColorDialog::options
1758
\brief the various options that affect the look and feel of the dialog
1760
By default, all options are disabled.
1762
Options should be set before showing the dialog. Setting them while the
1763
dialog is visible is not guaranteed to have an immediate effect on the
1764
dialog (depending on the option and on the platform).
1766
\sa setOption(), testOption()
1768
void QColorDialog::setOptions(ColorDialogOptions options)
1772
if (QColorDialog::options() == options)
1775
d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));
1776
d->buttons->setVisible(!(options & NoButtons));
1777
d->showAlpha(options & ShowAlphaChannel);
1780
QColorDialog::ColorDialogOptions QColorDialog::options() const
1782
Q_D(const QColorDialog);
1783
return QColorDialog::ColorDialogOptions(int(d->options->options()));
1787
\enum QColorDialog::ColorDialogOption
1791
This enum specifies various options that affect the look and feel
1794
\value ShowAlphaChannel Allow the user to select the alpha component of a color.
1795
\value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
1796
\value DontUseNativeDialog Use Qt's standard color dialog on the Mac instead of Apple's
1799
\sa options, setOption(), testOption(), windowModality()
1803
\fn void QColorDialog::currentColorChanged(const QColor &color)
1805
This signal is emitted whenever the current color changes in the dialog.
1806
The current color is specified by \a color.
1808
\sa color, colorSelected()
1812
// can only have one Cocoa color panel active
1813
bool QColorDialogPrivate::sharedColorPanelAvailable = true;
1817
\fn void QColorDialog::colorSelected(const QColor &color);
1819
This signal is emitted just after the user has clicked \uicontrol{OK} to
1820
select a color to use. The chosen color is specified by \a color.
1822
\sa color, currentColorChanged()
1826
Changes the visibility of the dialog. If \a visible is true, the dialog
1827
is shown; otherwise, it is hidden.
1829
void QColorDialog::setVisible(bool visible)
1834
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
1836
} else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
1840
d->selectedQColor = QColor();
1842
#if defined(Q_WS_MAC)
1844
if (d->delegate || (QColorDialogPrivate::sharedColorPanelAvailable &&
1845
!(testAttribute(Qt::WA_DontShowOnScreen) || (d->opts & DontUseNativeDialog)))){
1846
d->openCocoaColorPanel(currentColor(), parentWidget(), windowTitle(), options());
1847
QColorDialogPrivate::sharedColorPanelAvailable = false;
1848
setAttribute(Qt::WA_DontShowOnScreen);
1850
setWindowFlags(windowModality() == Qt::WindowModal ? Qt::Sheet : DefaultWindowFlags);
1853
d->closeCocoaColorPanel();
1854
setAttribute(Qt::WA_DontShowOnScreen, false);
1859
if (!(options() & DontUseNativeDialog))
1860
d->setNativeDialogVisible(visible);
1862
if (d->nativeDialogInUse) {
1863
// Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
1864
// updates the state correctly, but skips showing the non-native version:
1865
setAttribute(Qt::WA_DontShowOnScreen);
1867
d->nativeDialogInUse = false;
1868
setAttribute(Qt::WA_DontShowOnScreen, false);
1872
QDialog::setVisible(visible);
1879
Opens the dialog and connects its colorSelected() signal to the slot specified
1880
by \a receiver and \a member.
1882
The signal will be disconnected from the slot when the dialog is closed.
1884
void QColorDialog::open(QObject *receiver, const char *member)
1887
connect(this, SIGNAL(colorSelected(QColor)), receiver, member);
1888
d->receiverToDisconnectOnClose = receiver;
1889
d->memberToDisconnectOnClose = member;
1894
\fn QColorDialog::open()
1897
Shows the dialog as a \l{QDialog#Modal Dialogs}{window modal dialog},
1898
returning immediately.
1906
Pops up a modal color dialog with the given window \a title (or "Select Color" if none is
1907
specified), lets the user choose a color, and returns that color. The color is initially set
1908
to \a initial. The dialog is a child of \a parent. It returns an invalid (see
1909
QColor::isValid()) color if the user cancels the dialog.
1911
The \a options argument allows you to customize the dialog.
1913
QColor QColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title,
1914
ColorDialogOptions options)
1916
QColorDialog dlg(parent);
1917
if (!title.isEmpty())
1918
dlg.setWindowTitle(title);
1919
dlg.setOptions(options);
1920
dlg.setCurrentColor(initial);
1922
return dlg.selectedColor();
1928
Pops up a modal color dialog to allow the user to choose a color
1929
and an alpha channel (transparency) value. The color+alpha is
1930
initially set to \a initial. The dialog is a child of \a parent.
1932
If \a ok is non-null, \e *\a ok is set to true if the user clicked
1933
\uicontrol{OK}, and to false if the user clicked Cancel.
1935
If the user clicks Cancel, the \a initial value is returned.
1937
Use QColorDialog::getColor() instead, passing the
1938
QColorDialog::ShowAlphaChannel option.
1941
QRgb QColorDialog::getRgba(QRgb initial, bool *ok, QWidget *parent)
1943
QColor color(getColor(QColor(initial), parent, QString(), ShowAlphaChannel));
1944
QRgb result = color.isValid() ? color.rgba() : initial;
1946
*ok = color.isValid();
1951
Destroys the color dialog.
1954
QColorDialog::~QColorDialog()
1956
#if defined(Q_WS_MAC)
1959
d->releaseCocoaColorPanelDelegate();
1960
QColorDialogPrivate::sharedColorPanelAvailable = true;
1968
void QColorDialog::changeEvent(QEvent *e)
1971
if (e->type() == QEvent::LanguageChange)
1972
d->retranslateStrings();
1973
QDialog::changeEvent(e);
1977
Closes the dialog and sets its result code to \a result. If this dialog
1978
is shown with exec(), done() causes the local event loop to finish,
1979
and exec() to return \a result.
1983
void QColorDialog::done(int result)
1986
QDialog::done(result);
1987
if (result == Accepted) {
1988
d->selectedQColor = d->currentQColor();
1989
emit colorSelected(d->selectedQColor);
1991
d->selectedQColor = QColor();
1993
if (d->receiverToDisconnectOnClose) {
1994
disconnect(this, SIGNAL(colorSelected(QColor)),
1995
d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
1996
d->receiverToDisconnectOnClose = 0;
1998
d->memberToDisconnectOnClose.clear();
2003
#include "qcolordialog.moc"
2004
#include "moc_qcolordialog.cpp"
2006
#endif // QT_NO_COLORDIALOG