Qt 4.8
qcolordialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 "qlabel.h"
52 #include "qlayout.h"
53 #include "qlineedit.h"
54 #include "qmenu.h"
55 #include "qpainter.h"
56 #include "qpixmap.h"
57 #include "qpushbutton.h"
58 #include "qsettings.h"
59 #include "qstyle.h"
60 #include "qstyleoption.h"
61 #include "qvalidator.h"
62 #include "qmime.h"
63 #include "qspinbox.h"
64 #include "qdialogbuttonbox.h"
65 #include "private/qguiplatformplugin_p.h"
66 
67 #ifdef Q_WS_S60
68 #include "private/qt_s60_p.h"
69 #endif
70 
71 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
72 # define QT_SMALL_COLORDIALOG
73 #endif
74 
76 
78 
79 struct QWellArrayData;
80 
81 class QWellArray : public QWidget
82 {
83  Q_OBJECT
86 
87 public:
88  QWellArray(int rows, int cols, QWidget* parent=0);
90  QString cellContent(int row, int col) const;
91 
92  int selectedColumn() const { return selCol; }
93  int selectedRow() const { return selRow; }
94 
95  virtual void setCurrent(int row, int col);
96  virtual void setSelected(int row, int col);
97 
98  QSize sizeHint() const;
99 
100  virtual void setCellBrush(int row, int col, const QBrush &);
101  QBrush cellBrush(int row, int col);
102 
103  inline int cellWidth() const
104  { return cellw; }
105 
106  inline int cellHeight() const
107  { return cellh; }
108 
109  inline int rowAt(int y) const
110  { return y / cellh; }
111 
112  inline int columnAt(int x) const
113  { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
114 
115  inline int rowY(int row) const
116  { return cellh * row; }
117 
118  inline int columnX(int column) const
119  { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
120 
121  inline int numRows() const
122  { return nrows; }
123 
124  inline int numCols() const
125  {return ncols; }
126 
127  inline QRect cellRect() const
128  { return QRect(0, 0, cellw, cellh); }
129 
130  inline QSize gridSize() const
131  { return QSize(ncols * cellw, nrows * cellh); }
132 
133  QRect cellGeometry(int row, int column)
134  {
135  QRect r;
136  if (row >= 0 && row < nrows && column >= 0 && column < ncols)
137  r.setRect(columnX(column), rowY(row), cellw, cellh);
138  return r;
139  }
140 
141  inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
142 
143 signals:
144  void selected(int row, int col);
145 
146 protected:
147  virtual void paintCell(QPainter *, int row, int col, const QRect&);
148  virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
149 
152  void keyPressEvent(QKeyEvent*);
153  void focusInEvent(QFocusEvent*);
154  void focusOutEvent(QFocusEvent*);
155  void paintEvent(QPaintEvent *);
156 
157 private:
159 
160  int nrows;
161  int ncols;
162  int cellw;
163  int cellh;
164  int curRow;
165  int curCol;
166  int selRow;
167  int selCol;
169 };
170 
171 void QWellArray::paintEvent(QPaintEvent *e)
172 {
173  QRect r = e->rect();
174  int cx = r.x();
175  int cy = r.y();
176  int ch = r.height();
177  int cw = r.width();
178  int colfirst = columnAt(cx);
179  int collast = columnAt(cx + cw);
180  int rowfirst = rowAt(cy);
181  int rowlast = rowAt(cy + ch);
182 
183  if (isRightToLeft()) {
184  int t = colfirst;
185  colfirst = collast;
186  collast = t;
187  }
188 
189  QPainter painter(this);
190  QPainter *p = &painter;
191  QRect rect(0, 0, cellWidth(), cellHeight());
192 
193 
194  if (collast < 0 || collast >= ncols)
195  collast = ncols-1;
196  if (rowlast < 0 || rowlast >= nrows)
197  rowlast = nrows-1;
198 
199  // Go through the rows
200  for (int r = rowfirst; r <= rowlast; ++r) {
201  // get row position and height
202  int rowp = rowY(r);
203 
204  // Go through the columns in the row r
205  // if we know from where to where, go through [colfirst, collast],
206  // else go through all of them
207  for (int c = colfirst; c <= collast; ++c) {
208  // get position and width of column c
209  int colp = columnX(c);
210  // Translate painter and draw the cell
211  rect.translate(colp, rowp);
212  paintCell(p, r, c, rect);
213  rect.translate(-colp, -rowp);
214  }
215  }
216 }
217 
220 };
221 
222 QWellArray::QWellArray(int rows, int cols, QWidget *parent)
223  : QWidget(parent)
224  ,nrows(rows), ncols(cols)
225 {
226  d = 0;
228  cellw = 28;
229  cellh = 24;
230  curCol = 0;
231  curRow = 0;
232  selCol = -1;
233  selRow = -1;
234 }
235 
237 {
238  ensurePolished();
239  return gridSize().boundedTo(QSize(640, 480));
240 }
241 
242 
243 void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect)
244 {
245  int b = 3; //margin
246 
247  const QPalette & g = palette();
248  QStyleOptionFrame opt;
250  opt.lineWidth = dfw;
251  opt.midLineWidth = 1;
252  opt.rect = rect.adjusted(b, b, -b, -b);
253  opt.palette = g;
255  style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this);
256  b += dfw;
257 
258  if ((row == curRow) && (col == curCol)) {
259  if (hasFocus()) {
261  opt.palette = g;
262  opt.rect = rect;
264  style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this);
265  }
266  }
267  paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));
268 }
269 
273 void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r)
274 {
275  if (d) {
276  p->fillRect(r, d->brush[row*numCols()+col]);
277  } else {
278  p->fillRect(r, Qt::white);
279  p->setPen(Qt::black);
280  p->drawLine(r.topLeft(), r.bottomRight());
281  p->drawLine(r.topRight(), r.bottomLeft());
282  }
283 }
284 
286 {
287  // The current cell marker is set to the cell the mouse is pressed in
288  QPoint pos = e->pos();
289  setCurrent(rowAt(pos.y()), columnAt(pos.x()));
290 }
291 
293 {
294  // The current cell marker is set to the cell the mouse is clicked in
296 }
297 
298 
299 /*
300  Sets the cell currently having the focus. This is not necessarily
301  the same as the currently selected cell.
302 */
303 
304 void QWellArray::setCurrent(int row, int col)
305 {
306  if ((curRow == row) && (curCol == col))
307  return;
308 
309  if (row < 0 || col < 0)
310  row = col = -1;
311 
312  int oldRow = curRow;
313  int oldCol = curCol;
314 
315  curRow = row;
316  curCol = col;
317 
318  updateCell(oldRow, oldCol);
320 }
321 
322 /*
323  Sets the currently selected cell to \a row, \a column. If \a row or
324  \a column are less than zero, the current cell is unselected.
325 
326  Does not set the position of the focus indicator.
327 */
328 void QWellArray::setSelected(int row, int col)
329 {
330  int oldRow = selRow;
331  int oldCol = selCol;
332 
333  if (row < 0 || col < 0)
334  row = col = -1;
335 
336  selCol = col;
337  selRow = row;
338 
339  updateCell(oldRow, oldCol);
341  if (row >= 0)
342  emit selected(row, col);
343 
344 #ifndef QT_NO_MENU
345  if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
346  parentWidget()->close();
347 #endif
348 }
349 
351 {
353 }
354 
355 void QWellArray::setCellBrush(int row, int col, const QBrush &b)
356 {
357  if (!d) {
358  d = new QWellArrayData;
359  int i = numRows()*numCols();
360  d->brush = new QBrush[i];
361  }
362  if (row >= 0 && row < numRows() && col >= 0 && col < numCols())
363  d->brush[row*numCols()+col] = b;
364 }
365 
366 /*
367  Returns the brush set for the cell at \a row, \a column. If no brush is
368  set, Qt::NoBrush is returned.
369 */
370 
371 QBrush QWellArray::cellBrush(int row, int col)
372 {
373  if (d && row >= 0 && row < numRows() && col >= 0 && col < numCols())
374  return d->brush[row*numCols()+col];
375  return Qt::NoBrush;
376 }
377 
378 
379 
384 {
386 }
387 
388 /*\reimp
389 */
391 {
392  switch(e->key()) { // Look at the key code
393  case Qt::Key_Left: // If 'left arrow'-key,
394  if(curCol > 0) // and cr't not in leftmost col
395  setCurrent(curRow, curCol - 1); // set cr't to next left column
396  break;
397  case Qt::Key_Right: // Correspondingly...
398  if(curCol < numCols()-1)
399  setCurrent(curRow, curCol + 1);
400  break;
401  case Qt::Key_Up:
402  if(curRow > 0)
403  setCurrent(curRow - 1, curCol);
404  break;
405  case Qt::Key_Down:
406  if(curRow < numRows()-1)
407  setCurrent(curRow + 1, curCol);
408  break;
409 #if 0
410  // bad idea that shouldn't have been implemented; very counterintuitive
411  case Qt::Key_Return:
412  case Qt::Key_Enter:
413  /*
414  ignore the key, so that the dialog get it, but still select
415  the current row/col
416  */
417  e->ignore();
418  // fallthrough intended
419 #endif
420  case Qt::Key_Space:
422  break;
423  default: // If not an interesting key,
424  e->ignore(); // we don't accept the event
425  return;
426  }
427 
428 }
429 
431 
432 static bool initrgb = false;
433 static QRgb stdrgb[6*8];
434 static QRgb cusrgb[2*8];
435 static bool customSet = false;
436 
437 
438 static void initRGB()
439 {
440  if (initrgb)
441  return;
442  initrgb = true;
443  int i = 0;
444  for (int g = 0; g < 4; g++)
445  for (int r = 0; r < 4; r++)
446  for (int b = 0; b < 3; b++)
447  stdrgb[i++] = qRgb(r * 255 / 3, g * 255 / 3, b * 255 / 2);
448 
449  for (i = 0; i < 2*8; i++)
450  cusrgb[i] = 0xffffffff;
451 }
452 
458 {
459  return 2 * 8;
460 }
461 
471 {
472  if (uint(index) >= uint(customCount()))
473  return qRgb(255, 255, 255);
474  initRGB();
475  return cusrgb[index];
476 }
477 
486 {
487  if (uint(index) >= uint(customCount()))
488  return;
489  initRGB();
490  customSet = true;
491  cusrgb[index] = color;
492 }
493 
503 {
504  if (uint(index) >= uint(6 * 8))
505  return;
506  initRGB();
507  stdrgb[index] = color;
508 }
509 
510 static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
511 {
512  QColor c;
513  c.setRgb(rgb);
514  c.getHsv(&h, &s, &v);
515 }
516 
517 class QColorWell : public QWellArray
518 {
519 public:
520  QColorWell(QWidget *parent, int r, int c, QRgb *vals)
521  :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1)
523 
524 protected:
525  void paintCellContents(QPainter *, int row, int col, const QRect&);
526  void mousePressEvent(QMouseEvent *e);
527  void mouseMoveEvent(QMouseEvent *e);
529 #ifndef QT_NO_DRAGANDDROP
532  void dragMoveEvent(QDragMoveEvent *e);
533  void dropEvent(QDropEvent *e);
534 #endif
535 
536 private:
541 
542 };
543 
544 void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r)
545 {
546  int i = row + col*numRows();
547  p->fillRect(r, QColor(values[i]));
548 }
549 
551 {
552  oldCurrent = QPoint(selectedRow(), selectedColumn());
554  mousePressed = true;
555  pressPos = e->pos();
556 }
557 
559 {
561 #ifndef QT_NO_DRAGANDDROP
562  if (!mousePressed)
563  return;
564  if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
565  setCurrent(oldCurrent.x(), oldCurrent.y());
566  int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows();
567  QColor col(values[i]);
568  QMimeData *mime = new QMimeData;
569  mime->setColorData(col);
570  QPixmap pix(cellWidth(), cellHeight());
571  pix.fill(col);
572  QPainter p(&pix);
573  p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
574  p.end();
575  QDrag *drg = new QDrag(this);
576  drg->setMimeData(mime);
577  drg->setPixmap(pix);
578  mousePressed = false;
579  drg->start();
580  }
581 #endif
582 }
583 
584 #ifndef QT_NO_DRAGANDDROP
586 {
587  if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
588  e->accept();
589  else
590  e->ignore();
591 }
592 
594 {
595  if (hasFocus())
596  parentWidget()->setFocus();
597 }
598 
600 {
601  if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) {
602  setCurrent(rowAt(e->pos().y()), columnAt(e->pos().x()));
603  e->accept();
604  } else {
605  e->ignore();
606  }
607 }
608 
610 {
611  QColor col = qvariant_cast<QColor>(e->mimeData()->colorData());
612  if (col.isValid()) {
613  int i = rowAt(e->pos().y()) + columnAt(e->pos().x()) * numRows();
614  values[i] = col.rgb();
615  update();
616  e->accept();
617  } else {
618  e->ignore();
619  }
620 }
621 
622 #endif // QT_NO_DRAGANDDROP
623 
625 {
626  if (!mousePressed)
627  return;
629  mousePressed = false;
630 }
631 
632 class QColorPicker : public QFrame
633 {
634  Q_OBJECT
635 public:
637  ~QColorPicker();
638 
639 public slots:
640  void setCol(int h, int s);
641 
642 signals:
643  void newCol(int h, int s);
644 
645 protected:
646  QSize sizeHint() const;
647  void paintEvent(QPaintEvent*);
648  void mouseMoveEvent(QMouseEvent *);
650  void resizeEvent(QResizeEvent *);
651 
652 private:
653  int hue;
654  int sat;
655 
656  QPoint colPt();
657  int huePt(const QPoint &pt);
658  int satPt(const QPoint &pt);
659  void setCol(const QPoint &pt);
660 
662 };
663 
664 static int pWidth = 220;
665 static int pHeight = 200;
666 
668 {
669  Q_OBJECT
670 public:
673 
674 public slots:
675  void setCol(int h, int s, int v);
676  void setCol(int h, int s);
677 
678 signals:
679  void newHsv(int h, int s, int v);
680 
681 protected:
682  void paintEvent(QPaintEvent*);
683  void mouseMoveEvent(QMouseEvent *);
685 
686 private:
687  enum { foff = 3, coff = 4 }; //frame and contents offset
688  int val;
689  int hue;
690  int sat;
691 
692  int y2val(int y);
693  int val2y(int val);
694  void setVal(int v);
695 
697 };
698 
699 
701 {
702  int d = height() - 2*coff - 1;
703  return 255 - (y - coff)*255/d;
704 }
705 
707 {
708  int d = height() - 2*coff - 1;
709  return coff + (255-v)*d/255;
710 }
711 
713  :QWidget(parent)
714 {
715  hue = 100; val = 100; sat = 100;
716  pix = 0;
717  // setAttribute(WA_NoErase, true);
718 }
719 
721 {
722  delete pix;
723 }
724 
726 {
727  setVal(y2val(m->y()));
728 }
730 {
731  setVal(y2val(m->y()));
732 }
733 
735 {
736  if (val == v)
737  return;
738  val = qMax(0, qMin(v,255));
739  delete pix; pix=0;
740  repaint();
741  emit newHsv(hue, sat, val);
742 }
743 
744 //receives from a hue,sat chooser and relays.
746 {
747  setCol(h, s, val);
748  emit newHsv(h, s, val);
749 }
750 
752 {
753  int w = width() - 5;
754 
755  QRect r(0, foff, w, height() - 2*foff);
756  int wi = r.width() - 2;
757  int hi = r.height() - 2;
758  if (!pix || pix->height() != hi || pix->width() != wi) {
759  delete pix;
760  QImage img(wi, hi, QImage::Format_RGB32);
761  int y;
762  uint *pixel = (uint *) img.scanLine(0);
763  for (y = 0; y < hi; y++) {
764  const uint *end = pixel + wi;
765  while (pixel < end) {
766  QColor c;
767  c.setHsv(hue, sat, y2val(y+coff));
768  *pixel = c.rgb();
769  ++pixel;
770  }
771  }
772  pix = new QPixmap(QPixmap::fromImage(img));
773  }
774  QPainter p(this);
775  p.drawPixmap(1, coff, *pix);
776  const QPalette &g = palette();
777  qDrawShadePanel(&p, r, g, true);
778  p.setPen(g.foreground().color());
779  p.setBrush(g.foreground());
780  QPolygon a;
781  int y = val2y(val);
782  a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
783  p.eraseRect(w, 0, 5, height());
784  p.drawPolygon(a);
785 }
786 
787 void QColorLuminancePicker::setCol(int h, int s , int v)
788 {
789  val = v;
790  hue = h;
791  sat = s;
792  delete pix; pix=0;
793  repaint();
794 }
795 
797 {
798  QRect r = contentsRect();
799  return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
800 }
801 
803 {
804  QRect r = contentsRect();
805  return 360 - pt.x() * 360 / (r.width() - 1);
806 }
807 
809 {
810  QRect r = contentsRect();
811  return 255 - pt.y() * 255 / (r.height() - 1);
812 }
813 
815 {
816  setCol(huePt(pt), satPt(pt));
817 }
818 
820  : QFrame(parent)
821 {
822  hue = 0; sat = 0;
823  setCol(150, 255);
824 
827 }
828 
830 {
831 }
832 
834 {
835  return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
836 }
837 
838 void QColorPicker::setCol(int h, int s)
839 {
840  int nhue = qMin(qMax(0,h), 359);
841  int nsat = qMin(qMax(0,s), 255);
842  if (nhue == hue && nsat == sat)
843  return;
844 
845  QRect r(colPt(), QSize(20,20));
846  hue = nhue; sat = nsat;
847  r = r.united(QRect(colPt(), QSize(20,20)));
848  r.translate(contentsRect().x()-9, contentsRect().y()-9);
849  // update(r);
850  repaint(r);
851 }
852 
854 {
855  QPoint p = m->pos() - contentsRect().topLeft();
856  setCol(p);
857  emit newCol(hue, sat);
858 }
859 
861 {
862  QPoint p = m->pos() - contentsRect().topLeft();
863  setCol(p);
864  emit newCol(hue, sat);
865 }
866 
868 {
869  QPainter p(this);
870  drawFrame(&p);
871  QRect r = contentsRect();
872 
873  p.drawPixmap(r.topLeft(), pix);
874  QPoint pt = colPt() + r.topLeft();
875  p.setPen(Qt::black);
876 
877  p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
878  p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
879 
880 }
881 
883 {
885 
886  int w = width() - frameWidth() * 2;
887  int h = height() - frameWidth() * 2;
888  QImage img(w, h, QImage::Format_RGB32);
889  int x, y;
890  uint *pixel = (uint *) img.scanLine(0);
891  for (y = 0; y < h; y++) {
892  const uint *end = pixel + w;
893  x = 0;
894  while (pixel < end) {
895  QPoint p(x, y);
896  QColor c;
897  c.setHsv(huePt(p), satPt(p), 200);
898  *pixel = c.rgb();
899  ++pixel;
900  ++x;
901  }
902  }
903  pix = QPixmap::fromImage(img);
904 }
905 
906 
907 class QColSpinBox : public QSpinBox
908 {
909 public:
911  : QSpinBox(parent) { setRange(0, 255); }
912  void setValue(int i) {
913  bool block = signalsBlocked();
914  blockSignals(true);
916  blockSignals(block);
917  }
918 };
919 
920 class QColorShowLabel;
921 
922 class QColorShower : public QWidget
923 {
924  Q_OBJECT
925 public:
927 
928  //things that don't emit signals
929  void setHsv(int h, int s, int v);
930 
931  int currentAlpha() const
932  { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }
933  void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); }
934  void showAlpha(bool b);
935  bool isAlphaVisible() const;
936 
937  QRgb currentColor() const { return curCol; }
938  QColor currentQColor() const { return curQColor; }
939  void retranslateStrings();
940  void updateQColor();
941 
942 public slots:
943  void setRgb(QRgb rgb);
944 
945 signals:
946  void newCol(QRgb rgb);
947  void currentColorChanged(const QColor &color);
948 
949 private slots:
950  void rgbEd();
951  void hsvEd();
952 private:
953  void showCurrentColor();
954  int hue, sat, val;
974 
975  friend class QColorDialog;
976  friend class QColorDialogPrivate;
977 };
978 
979 class QColorShowLabel : public QFrame
980 {
981  Q_OBJECT
982 
983 public:
986  setAcceptDrops(true);
987  mousePressed = false;
988  }
989  void setColor(QColor c) { col = c; }
990 
991 signals:
992  void colorDropped(QRgb);
993 
994 protected:
995  void paintEvent(QPaintEvent *);
996  void mousePressEvent(QMouseEvent *e);
997  void mouseMoveEvent(QMouseEvent *e);
999 #ifndef QT_NO_DRAGANDDROP
1002  void dropEvent(QDropEvent *e);
1003 #endif
1004 
1005 private:
1009 };
1010 
1012 {
1013  QPainter p(this);
1014  drawFrame(&p);
1015  p.fillRect(contentsRect()&e->rect(), col);
1016 }
1017 
1019 {
1020  alphaLab->setVisible(b);
1021  alphaEd->setVisible(b);
1022 }
1023 
1024 inline bool QColorShower::isAlphaVisible() const
1025 {
1026  return alphaLab->isVisible();
1027 }
1028 
1030 {
1031  mousePressed = true;
1032  pressPos = e->pos();
1033 }
1034 
1036 {
1037 #ifdef QT_NO_DRAGANDDROP
1038  Q_UNUSED(e);
1039 #else
1040  if (!mousePressed)
1041  return;
1042  if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
1043  QMimeData *mime = new QMimeData;
1044  mime->setColorData(col);
1045  QPixmap pix(30, 20);
1046  pix.fill(col);
1047  QPainter p(&pix);
1048  p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
1049  p.end();
1050  QDrag *drg = new QDrag(this);
1051  drg->setMimeData(mime);
1052  drg->setPixmap(pix);
1053  mousePressed = false;
1054  drg->start();
1055  }
1056 #endif
1057 }
1058 
1059 #ifndef QT_NO_DRAGANDDROP
1061 {
1062  if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid())
1063  e->accept();
1064  else
1065  e->ignore();
1066 }
1067 
1069 {
1070 }
1071 
1073 {
1074  QColor color = qvariant_cast<QColor>(e->mimeData()->colorData());
1075  if (color.isValid()) {
1076  col = color;
1077  repaint();
1078  emit colorDropped(col.rgb());
1079  e->accept();
1080  } else {
1081  e->ignore();
1082  }
1083 }
1084 #endif // QT_NO_DRAGANDDROP
1085 
1087 {
1088  if (!mousePressed)
1089  return;
1090  mousePressed = false;
1091 }
1092 
1094  : QWidget(parent)
1095 {
1096  colorDialog = parent;
1097 
1098  curCol = qRgb(255, 255, 255);
1099  curQColor = Qt::white;
1100 
1101  QGridLayout *gl = new QGridLayout(this);
1102  gl->setMargin(gl->spacing());
1103  lab = new QColorShowLabel(this);
1104 
1105 #ifdef QT_SMALL_COLORDIALOG
1106 # ifdef Q_WS_S60
1107  const bool nonTouchUI = !S60->hasTouchscreen;
1108 # elif defined Q_WS_MAEMO_5
1109  const bool nonTouchUI = false;
1110 # endif
1111 #endif
1112 
1113 #ifndef Q_WS_WINCE
1114 #ifdef QT_SMALL_COLORDIALOG
1115  lab->setMinimumHeight(60);
1116 #endif
1117  lab->setMinimumWidth(60);
1118 #else
1119  lab->setMinimumWidth(20);
1120 #endif
1121 
1122 // In S60, due to small screen and different screen layouts need to re-arrange the widgets.
1123 // For QVGA screens only the comboboxes and color label are visible.
1124 // For nHD screens only color and luminence pickers and color label are visible.
1125 #if !defined(QT_SMALL_COLORDIALOG)
1126  gl->addWidget(lab, 0, 0, -1, 1);
1127 #else
1128  if (nonTouchUI)
1129  gl->addWidget(lab, 0, 0, 1, -1);
1130  else
1131  gl->addWidget(lab, 0, 0, -1, 1);
1132 #endif
1133  connect(lab, SIGNAL(colorDropped(QRgb)), this, SIGNAL(newCol(QRgb)));
1134  connect(lab, SIGNAL(colorDropped(QRgb)), this, SLOT(setRgb(QRgb)));
1135 
1136  hEd = new QColSpinBox(this);
1137  hEd->setRange(0, 359);
1138  lblHue = new QLabel(this);
1139 #ifndef QT_NO_SHORTCUT
1140  lblHue->setBuddy(hEd);
1141 #endif
1143 #if !defined(QT_SMALL_COLORDIALOG)
1144  gl->addWidget(lblHue, 0, 1);
1145  gl->addWidget(hEd, 0, 2);
1146 #else
1147  if (nonTouchUI) {
1148  gl->addWidget(lblHue, 1, 0);
1149  gl->addWidget(hEd, 2, 0);
1150  } else {
1151  lblHue->hide();
1152  hEd->hide();
1153  }
1154 #endif
1155 
1156  sEd = new QColSpinBox(this);
1157  lblSat = new QLabel(this);
1158 #ifndef QT_NO_SHORTCUT
1159  lblSat->setBuddy(sEd);
1160 #endif
1162 #if !defined(QT_SMALL_COLORDIALOG)
1163  gl->addWidget(lblSat, 1, 1);
1164  gl->addWidget(sEd, 1, 2);
1165 #else
1166  if (nonTouchUI) {
1167  gl->addWidget(lblSat, 1, 1);
1168  gl->addWidget(sEd, 2, 1);
1169  } else {
1170  lblSat->hide();
1171  sEd->hide();
1172  }
1173 #endif
1174 
1175  vEd = new QColSpinBox(this);
1176  lblVal = new QLabel(this);
1177 #ifndef QT_NO_SHORTCUT
1178  lblVal->setBuddy(vEd);
1179 #endif
1181 #if !defined(QT_SMALL_COLORDIALOG)
1182  gl->addWidget(lblVal, 2, 1);
1183  gl->addWidget(vEd, 2, 2);
1184 #else
1185  if (nonTouchUI) {
1186  gl->addWidget(lblVal, 1, 2);
1187  gl->addWidget(vEd, 2, 2);
1188  } else {
1189  lblVal->hide();
1190  vEd->hide();
1191  }
1192 #endif
1193 
1194  rEd = new QColSpinBox(this);
1195  lblRed = new QLabel(this);
1196 #ifndef QT_NO_SHORTCUT
1197  lblRed->setBuddy(rEd);
1198 #endif
1200 #if !defined(QT_SMALL_COLORDIALOG)
1201  gl->addWidget(lblRed, 0, 3);
1202  gl->addWidget(rEd, 0, 4);
1203 #else
1204  if (nonTouchUI) {
1205  gl->addWidget(lblRed, 3, 0);
1206  gl->addWidget(rEd, 4, 0);
1207  } else {
1208  lblRed->hide();
1209  rEd->hide();
1210  }
1211 #endif
1212 
1213  gEd = new QColSpinBox(this);
1214  lblGreen = new QLabel(this);
1215 #ifndef QT_NO_SHORTCUT
1216  lblGreen->setBuddy(gEd);
1217 #endif
1219 #if !defined(QT_SMALL_COLORDIALOG)
1220  gl->addWidget(lblGreen, 1, 3);
1221  gl->addWidget(gEd, 1, 4);
1222 #else
1223  if (nonTouchUI) {
1224  gl->addWidget(lblGreen, 3, 1);
1225  gl->addWidget(gEd, 4, 1);
1226  } else {
1227  lblGreen->hide();
1228  gEd->hide();
1229  }
1230 #endif
1231 
1232  bEd = new QColSpinBox(this);
1233  lblBlue = new QLabel(this);
1234 #ifndef QT_NO_SHORTCUT
1235  lblBlue->setBuddy(bEd);
1236 #endif
1238 #if !defined(QT_SMALL_COLORDIALOG)
1239  gl->addWidget(lblBlue, 2, 3);
1240  gl->addWidget(bEd, 2, 4);
1241 #else
1242  if (nonTouchUI) {
1243  gl->addWidget(lblBlue, 3, 2);
1244  gl->addWidget(bEd, 4, 2);
1245  } else {
1246  lblBlue->hide();
1247  bEd->hide();
1248  }
1249 #endif
1250 
1251  alphaEd = new QColSpinBox(this);
1252  alphaLab = new QLabel(this);
1253 #ifndef QT_NO_SHORTCUT
1255 #endif
1257 #if !defined(QT_SMALL_COLORDIALOG)
1258  gl->addWidget(alphaLab, 3, 1, 1, 3);
1259  gl->addWidget(alphaEd, 3, 4);
1260 #else
1261  if (nonTouchUI) {
1262  gl->addWidget(alphaLab, 1, 3, 3, 1);
1263  gl->addWidget(alphaEd, 4, 3);
1264  } else {
1265  alphaLab->hide();
1266  alphaEd->hide();
1267  }
1268 #endif
1269  alphaEd->hide();
1270  alphaLab->hide();
1271 
1272  connect(hEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
1273  connect(sEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
1274  connect(vEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
1275 
1276  connect(rEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
1277  connect(gEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
1278  connect(bEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
1279  connect(alphaEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
1280 
1282 }
1283 
1284 inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); }
1285 inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); }
1286 inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); }
1287 inline void QColorDialogPrivate::showAlpha(bool b) { cs->showAlpha(b); }
1288 inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisible(); }
1289 
1291 {
1292  return cs->currentQColor();
1293 }
1294 
1296 {
1298  lab->repaint();
1299 }
1300 
1302 {
1303  rgbOriginal = true;
1304  curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1305 
1306  rgb2hsv(currentColor(), hue, sat, val);
1307 
1308  hEd->setValue(hue);
1309  sEd->setValue(sat);
1310  vEd->setValue(val);
1311 
1312  showCurrentColor();
1314  updateQColor();
1315 }
1316 
1318 {
1319  rgbOriginal = false;
1320  hue = hEd->value();
1321  sat = sEd->value();
1322  val = vEd->value();
1323 
1324  QColor c;
1325  c.setHsv(hue, sat, val);
1326  curCol = c.rgb();
1327 
1331 
1332  showCurrentColor();
1334  updateQColor();
1335 }
1336 
1338 {
1339  rgbOriginal = true;
1340  curCol = rgb;
1341 
1342  rgb2hsv(currentColor(), hue, sat, val);
1343 
1344  hEd->setValue(hue);
1345  sEd->setValue(sat);
1346  vEd->setValue(val);
1347 
1351 
1352  showCurrentColor();
1353  updateQColor();
1354 }
1355 
1356 void QColorShower::setHsv(int h, int s, int v)
1357 {
1358  if (h < -1 || (uint)s > 255 || (uint)v > 255)
1359  return;
1360 
1361  rgbOriginal = false;
1362  hue = h; val = v; sat = s;
1363  QColor c;
1364  c.setHsv(hue, sat, val);
1365  curCol = c.rgb();
1366 
1367  hEd->setValue(hue);
1368  sEd->setValue(sat);
1369  vEd->setValue(val);
1370 
1374 
1375  showCurrentColor();
1376  updateQColor();
1377 }
1378 
1380 {
1381  lblHue->setText(QColorDialog::tr("Hu&e:"));
1382  lblSat->setText(QColorDialog::tr("&Sat:"));
1383  lblVal->setText(QColorDialog::tr("&Val:"));
1384  lblRed->setText(QColorDialog::tr("&Red:"));
1385  lblGreen->setText(QColorDialog::tr("&Green:"));
1386  lblBlue->setText(QColorDialog::tr("Bl&ue:"));
1387  alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
1388 }
1389 
1391 {
1392  QColor oldQColor(curQColor);
1394  if (curQColor != oldQColor)
1396 }
1397 
1398 //sets all widgets to display h,s,v
1399 void QColorDialogPrivate::_q_newHsv(int h, int s, int v)
1400 {
1401  cs->setHsv(h, s, v);
1402  cp->setCol(h, s);
1403  lp->setCol(h, s, v);
1404 }
1405 
1406 //sets all widgets to display rgb
1408 {
1409  cs->setRgb(rgb);
1410  _q_newColorTypedIn(rgb);
1411 }
1412 
1413 // hack; doesn't keep curCol in sync, so use with care
1415 {
1416  Q_Q(QColorDialog);
1417  if (cs->curQColor != color) {
1418  cs->curQColor = color;
1419  emit q->currentColorChanged(color);
1420  }
1421 }
1422 
1424 {
1425  QRgb color = col.rgb();
1426  int i = 0, j = 0;
1427  // Check standard colors
1428  if (standard) {
1429  for (i = 0; i < 6; i++) {
1430  for (j = 0; j < 8; j++) {
1431  if (color == stdrgb[i + j*6]) {
1432  _q_newStandard(i, j);
1433  standard->setCurrent(i, j);
1434  standard->setSelected(i, j);
1435  standard->setFocus();
1436  return true;
1437  }
1438  }
1439  }
1440  }
1441  // Check custom colors
1442  if (custom) {
1443  for (i = 0; i < 2; i++) {
1444  for (j = 0; j < 8; j++) {
1445  if (color == cusrgb[i + j*2]) {
1446  _q_newCustom(i, j);
1447  custom->setCurrent(i, j);
1448  custom->setSelected(i, j);
1449  custom->setFocus();
1450  return true;
1451  }
1452  }
1453  }
1454  }
1455  return false;
1456 }
1457 
1458 //sets all widgets except cs to display rgb
1460 {
1461  int h, s, v;
1462  rgb2hsv(rgb, h, s, v);
1463  cp->setCol(h, s);
1464  lp->setCol(h, s, v);
1465 }
1466 
1468 {
1469  int i = r+2*c;
1470  setCurrentColor(cusrgb[i]);
1471  nextCust = i;
1472  if (standard)
1473  standard->setSelected(-1,-1);
1474 }
1475 
1477 {
1478  setCurrentColor(stdrgb[r+c*6]);
1479  if (custom)
1480  custom->setSelected(-1,-1);
1481 }
1482 
1483 void QColorDialogPrivate::init(const QColor &initial)
1484 {
1485  Q_Q(QColorDialog);
1486 
1487  q->setSizeGripEnabled(false);
1488  q->setWindowTitle(QColorDialog::tr("Select Color"));
1489 
1490  nativeDialogInUse = false;
1491 
1492  nextCust = 0;
1493  QVBoxLayout *mainLay = new QVBoxLayout(q);
1494  // there's nothing in this dialog that benefits from sizing up
1496 
1497  QHBoxLayout *topLay = new QHBoxLayout();
1498  mainLay->addLayout(topLay);
1499 
1500  leftLay = 0;
1501 
1502 #if defined(Q_WS_WINCE) || defined(QT_SMALL_COLORDIALOG)
1503  smallDisplay = true;
1504  const int lumSpace = 20;
1505 #else
1506  // small displays (e.g. PDAs) cannot fit the full color dialog,
1507  // so just use the color picker.
1508  smallDisplay = (QApplication::desktop()->width() < 480 || QApplication::desktop()->height() < 350);
1509  const int lumSpace = topLay->spacing() / 2;
1510 #endif
1511 
1512  if (!smallDisplay) {
1513  leftLay = new QVBoxLayout;
1514  topLay->addLayout(leftLay);
1515  }
1516 
1517  initRGB();
1518 
1519 #ifndef QT_NO_SETTINGS
1520  if (!customSet) {
1521  QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
1522  for (int i = 0; i < 2*8; ++i) {
1523  QVariant v = settings.value(QLatin1String("Qt/customColors/") + QString::number(i));
1524  if (v.isValid()) {
1525  QRgb rgb = v.toUInt();
1526  cusrgb[i] = rgb;
1527  }
1528  }
1529  }
1530 #endif
1531 
1532 #if defined(QT_SMALL_COLORDIALOG)
1533 # if defined(Q_WS_S60)
1534  const bool nonTouchUI = !S60->hasTouchscreen;
1535 # elif defined(Q_WS_MAEMO_5)
1536  const bool nonTouchUI = false;
1537 # endif
1538 #endif
1539 
1540  if (!smallDisplay) {
1541  standard = new QColorWell(q, 6, 8, stdrgb);
1542  lblBasicColors = new QLabel(q);
1543 #ifndef QT_NO_SHORTCUT
1544  lblBasicColors->setBuddy(standard);
1545 #endif
1546  q->connect(standard, SIGNAL(selected(int,int)), SLOT(_q_newStandard(int,int)));
1547  leftLay->addWidget(lblBasicColors);
1548  leftLay->addWidget(standard);
1549 
1550 #if !defined(Q_WS_WINCE)
1551  leftLay->addStretch();
1552 #endif
1553 
1554  custom = new QColorWell(q, 2, 8, cusrgb);
1555  custom->setAcceptDrops(true);
1556 
1557  q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int)));
1558  lblCustomColors = new QLabel(q);
1559 #ifndef QT_NO_SHORTCUT
1560  lblCustomColors->setBuddy(custom);
1561 #endif
1562  leftLay->addWidget(lblCustomColors);
1563  leftLay->addWidget(custom);
1564 
1565  addCusBt = new QPushButton(q);
1566  QObject::connect(addCusBt, SIGNAL(clicked()), q, SLOT(_q_addCustom()));
1567  leftLay->addWidget(addCusBt);
1568  } else {
1569  // better color picker size for small displays
1570 #if defined(QT_SMALL_COLORDIALOG)
1572  pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
1573  pHeight -= 20;
1574  if(screenSize.height() > screenSize.width())
1575  pWidth -= 20;
1576 #else
1577  pWidth = 150;
1578  pHeight = 100;
1579 #endif
1580  custom = 0;
1581  standard = 0;
1582  }
1583 
1584  QVBoxLayout *rightLay = new QVBoxLayout;
1585  topLay->addLayout(rightLay);
1586 
1587  QHBoxLayout *pickLay = new QHBoxLayout;
1588  rightLay->addLayout(pickLay);
1589 
1590  QVBoxLayout *cLay = new QVBoxLayout;
1591  pickLay->addLayout(cLay);
1592  cp = new QColorPicker(q);
1593 
1594  cp->setFrameStyle(QFrame::Panel + QFrame::Sunken);
1595 
1596 #if defined(QT_SMALL_COLORDIALOG)
1597  if (!nonTouchUI) {
1598  pickLay->addWidget(cp);
1599  cLay->addSpacing(lumSpace);
1600  } else {
1601  cp->hide();
1602  }
1603 #else
1604  cLay->addSpacing(lumSpace);
1605  cLay->addWidget(cp);
1606 #endif
1607  cLay->addSpacing(lumSpace);
1608 
1609  lp = new QColorLuminancePicker(q);
1610 #if defined(QT_SMALL_COLORDIALOG)
1612  const int minDimension = qMin(screenSize.height(), screenSize.width());
1613  //set picker to be finger-usable
1614  int pickerWidth = !nonTouchUI ? minDimension/9 : minDimension/12;
1615  lp->setFixedWidth(pickerWidth);
1616  if (!nonTouchUI)
1617  pickLay->addWidget(lp);
1618  else
1619  lp->hide();
1620 #else
1621  lp->setFixedWidth(20);
1622  pickLay->addWidget(lp);
1623 #endif
1624 
1625  QObject::connect(cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)));
1626  QObject::connect(lp, SIGNAL(newHsv(int,int,int)), q, SLOT(_q_newHsv(int,int,int)));
1627 
1628  rightLay->addStretch();
1629 
1630  cs = new QColorShower(q);
1631  QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb)));
1634 #if defined(QT_SMALL_COLORDIALOG)
1635  if (!nonTouchUI)
1636  pWidth -= cp->size().width();
1637  topLay->addWidget(cs);
1638 #else
1639  rightLay->addWidget(cs);
1640 #endif
1641 
1642  buttons = new QDialogButtonBox(q);
1643  mainLay->addWidget(buttons);
1644 
1645  ok = buttons->addButton(QDialogButtonBox::Ok);
1646  QObject::connect(ok, SIGNAL(clicked()), q, SLOT(accept()));
1647  ok->setDefault(true);
1648  cancel = buttons->addButton(QDialogButtonBox::Cancel);
1649  QObject::connect(cancel, SIGNAL(clicked()), q, SLOT(reject()));
1650 
1652 
1653 #ifdef Q_WS_MAC
1654  delegate = 0;
1655 #endif
1656 
1657  q->setCurrentColor(initial);
1658 }
1659 
1661 {
1662  cusrgb[nextCust] = cs->currentColor();
1663  if (custom)
1664  custom->update();
1665  nextCust = (nextCust+1) % 16;
1666 }
1667 
1669 {
1670  if (!smallDisplay) {
1671  lblBasicColors->setText(QColorDialog::tr("&Basic colors"));
1672  lblCustomColors->setText(QColorDialog::tr("&Custom colors"));
1673  addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));
1674  }
1675 
1676  cs->retranslateStrings();
1677 }
1678 
1679 static const Qt::WindowFlags DefaultWindowFlags =
1682 
1729 {
1730  Q_D(QColorDialog);
1731  d->init(Qt::white);
1732 }
1733 
1745 {
1746  Q_D(QColorDialog);
1747  d->init(initial);
1748 }
1749 
1759 {
1760  Q_D(QColorDialog);
1761  d->setCurrentColor(color.rgb());
1762  d->selectColor(color);
1763  d->setCurrentAlpha(color.alpha());
1764 
1765 #ifdef Q_WS_MAC
1766  d->setCurrentQColor(color);
1767  d->setCocoaPanelColor(color);
1768 #endif
1769  if (d->nativeDialogInUse)
1771 }
1772 
1774 {
1775  Q_D(const QColorDialog);
1776  return d->currentQColor();
1777 }
1778 
1779 
1789 {
1790  Q_D(const QColorDialog);
1791  return d->selectedQColor;
1792 }
1793 
1801 {
1802  Q_D(QColorDialog);
1803  if (!(d->opts & option) != !on)
1804  setOptions(d->opts ^ option);
1805 }
1806 
1819 {
1820  Q_D(const QColorDialog);
1821  return (d->opts & option) != 0;
1822 }
1823 
1839 void QColorDialog::setOptions(ColorDialogOptions options)
1840 {
1841  Q_D(QColorDialog);
1842 
1843  ColorDialogOptions changed = (options ^ d->opts);
1844  if (!changed)
1845  return;
1846 
1847  d->opts = options;
1848  d->buttons->setVisible(!(options & NoButtons));
1849  d->showAlpha(options & ShowAlphaChannel);
1850 }
1851 
1852 QColorDialog::ColorDialogOptions QColorDialog::options() const
1853 {
1854  Q_D(const QColorDialog);
1855  return d->opts;
1856 }
1857 
1889 #ifdef Q_WS_MAC
1890 // can only have one Cocoa color panel active
1892 #endif
1893 
1911 {
1912  Q_D(QColorDialog);
1913 
1914  if (visible){
1916  return;
1918  return;
1919 
1920  if (visible)
1921  d->selectedQColor = QColor();
1922 
1923 #if defined(Q_WS_MAC)
1924  if (visible) {
1927  d->openCocoaColorPanel(currentColor(), parentWidget(), windowTitle(), options());
1930  }
1932  } else {
1933  if (d->delegate) {
1934  d->closeCocoaColorPanel();
1937  }
1938  }
1939 #else
1940 
1941  if (!(d->opts & DontUseNativeDialog) && qt_guiPlatformPlugin()->colorDialogSetVisible(this, visible)) {
1942  d->nativeDialogInUse = true;
1943  // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below
1944  // updates the state correctly, but skips showing the non-native version:
1946  } else {
1947  d->nativeDialogInUse = false;
1949  }
1950 #endif
1951 
1952  QDialog::setVisible(visible);
1953 }
1954 
1967 void QColorDialog::open(QObject *receiver, const char *member)
1968 {
1969  Q_D(QColorDialog);
1970  connect(this, SIGNAL(colorSelected(QColor)), receiver, member);
1971  d->receiverToDisconnectOnClose = receiver;
1972  d->memberToDisconnectOnClose = member;
1973  QDialog::open();
1974 }
1975 
1989 /*
1990  For Symbian color dialogs
1991 */
1992 #ifdef Q_WS_S60
1993 extern QColor qtSymbianGetColor(const QColor &initial);
1994 #endif
1995 
2014  ColorDialogOptions options)
2015 {
2016 #ifdef Q_WS_S60
2017  if (!(options & DontUseNativeDialog))
2018  return qtSymbianGetColor(initial);
2019 #endif
2020  QColorDialog dlg(parent);
2021  if (!title.isEmpty())
2022  dlg.setWindowTitle(title);
2023  dlg.setOptions(options);
2024  dlg.setCurrentColor(initial);
2025  dlg.exec();
2026  return dlg.selectedColor();
2027 }
2028 
2040 {
2041 #ifdef Q_WS_S60
2042  return qtSymbianGetColor(initial);
2043 #endif
2044  return getColor(initial, parent, QString(), ColorDialogOptions(0));
2045 }
2046 
2047 
2065 {
2066  QColor color(getColor(QColor(initial), parent, QString(), ShowAlphaChannel));
2067  QRgb result = color.isValid() ? color.rgba() : initial;
2068  if (ok)
2069  *ok = color.isValid();
2070  return result;
2071 }
2072 
2078 {
2079  Q_D(QColorDialog);
2080 #if defined(Q_WS_MAC)
2081  if (d->delegate) {
2082  d->releaseCocoaColorPanelDelegate();
2084  }
2085 #endif
2086 
2087 #ifndef QT_NO_SETTINGS
2088  if (!customSet) {
2089  QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
2090  for (int i = 0; i < 2*8; ++i)
2091  settings.setValue(QLatin1String("Qt/customColors/") + QString::number(i), cusrgb[i]);
2092  }
2093 #endif
2094  if (d->nativeDialogInUse)
2096 
2097 }
2098 
2099 
2104 {
2105  Q_D(QColorDialog);
2106  if (e->type() == QEvent::LanguageChange)
2107  d->retranslateStrings();
2109 }
2110 
2119 {
2120  Q_D(QColorDialog);
2121  QDialog::done(result);
2122  if (result == Accepted) {
2123  d->selectedQColor = d->currentQColor();
2124  emit colorSelected(d->selectedQColor);
2125  } else {
2126  d->selectedQColor = QColor();
2127  }
2128  if (d->receiverToDisconnectOnClose) {
2130  d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2131  d->receiverToDisconnectOnClose = 0;
2132  }
2133  d->memberToDisconnectOnClose.clear();
2134 }
2135 
2137 
2138 #include "qcolordialog.moc"
2139 #include "moc_qcolordialog.cpp"
2140 
2141 #endif // QT_NO_COLORDIALOG
2142 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static int pHeight
QPoint pos() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
static int pWidth
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
void newCol(QRgb rgb)
virtual void colorDialogSetCurrentColor(QColorDialog *, const QColor &)
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
virtual void setCellBrush(int row, int col, const QBrush &)
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
void setValue(const QString &key, const QVariant &value)
Sets the value of setting key to value.
Definition: qsettings.cpp:3328
ColorDialogOption
This enum specifies various options that affect the look and feel of a color dialog.
Definition: qcolordialog.h:66
int columnX(int column) const
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
void selected(int row, int col)
unsigned int QRgb
Definition: qrgb.h:53
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
int cellHeight() const
int y() const
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setPixmap(const QPixmap &)
Sets pixmap as the pixmap used to represent the data in a drag and drop operation.
Definition: qdrag.cpp:166
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:61
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
Definition: qdrag.cpp:142
QColSpinBox * bEd
void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void setCurrentColor(QRgb rgb)
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
void _q_newHsv(int h, int s, int v)
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
void setText(const QString &)
Definition: qlabel.cpp:366
virtual void setSelected(int row, int col)
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
QColor currentQColor() const
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
bool isVisible() const
Definition: qwidget.h:1005
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
ColorDialogOptions options() const
QVariant colorData() const
Returns a color if the data stored in the object represents a color (MIME type application/x-color); ...
Definition: qmimedata.cpp:489
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
void _q_newStandard(int, int)
void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
virtual void dragEnterEvent(QDragEnterEvent *)
This event handler is called when a drag is in progress and the mouse enters this widget...
Definition: qwidget.cpp:9768
QLabel * lblRed
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
QRect united(const QRect &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: qrect.h:491
void setColorData(const QVariant &color)
Sets the color data in the object to the given color.
Definition: qmimedata.cpp:502
QColorWell(QWidget *parent, int r, int c, QRgb *vals)
void addLayout(QLayout *layout, int stretch=0)
Adds layout to the end of the box, with serial stretch factor stretch.
QColor selectedColor() const
Returns the color that the user selected by clicking the OK or equivalent button. ...
QColSpinBox * gEd
#define SLOT(a)
Definition: qobjectdefs.h:226
static Qt::MouseButtons buttons
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QLabel * lblBlue
QColor currentQColor() const
QPoint colPt()
void mousePressEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
const char * mime
void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
void accept()
Calls QDropEvent::accept().
Definition: qevent.h:539
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QColSpinBox(QWidget *parent)
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
static int customCount()
Returns the number of custom colors supported by QColorDialog.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
const QBrush & foreground() const
Use windowText() instead.
Definition: qpalette.h:123
void setValue(int val)
Definition: qspinbox.cpp:268
long ASN1_INTEGER_get ASN1_INTEGER * a
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
int columnAt(int x) const
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
int frameWidth() const
virtual void colorDialogDelete(QColorDialog *)
void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
QColorDialog(QWidget *parent=0)
Constructs a color dialog with the given parent.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
static void setStandardColor(int index, QRgb color)
Sets the standard color at index to the QRgb color value.
void setRgb(QRgb rgb)
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool hasFocus() const
Definition: qwidget.cpp:6583
QBrush cellBrush(int row, int col)
em>Reimplemented Function
void _q_newCustom(int, int)
void updateCell(int row, int column)
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
void setCol(int h, int s, int v)
static const Qt::WindowFlags DefaultWindowFlags
QLabel * lblHue
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
int height() const
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
void setMinimumHeight(int minh)
Definition: qwidget.cpp:4334
QSize gridSize() const
void setRange(int min, int max)
Convenience function to set the minimum, and maximum values with a single function call...
Definition: qspinbox.cpp:474
QColorShowLabel * lab
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void getHsv(int *h, int *s, int *v, int *a=0) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
Definition: qcolor.cpp:679
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
void newHsv(int h, int s, int v)
void setHsv(int h, int s, int v, int a=255)
Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha componen...
Definition: qcolor.cpp:734
QStyle * style() const
Definition: qwidget.cpp:2742
void showCurrentColor()
bool testOption(ColorDialogOption option) const
Returns true if the given option is enabled; otherwise, returns false.
#define Q_Q(Class)
Definition: qglobal.h:2483
int value() const
QColorDialog * colorDialog
int numRows() const
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
void setCurrentColor(const QColor &color)
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void mouseMoveEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void dragLeaveEvent(QDragLeaveEvent *e)
This event handler is called when a drag is in progress and the mouse leaves this widget...
void addStretch(int stretch=0)
Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end...
void retranslateStrings()
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
int width() const
Returns the width.
Definition: qsize.h:126
QColorPicker(QWidget *parent)
void setOptions(ColorDialogOptions options)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool customSet
The QColorDialog class provides a dialog widget for specifying colors.
Definition: qcolordialog.h:57
QLabel * lblSat
void setCol(int h, int s)
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
Definition: qrgb.h:72
QRect cellGeometry(int row, int column)
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
bool visible
whether the widget is visible
Definition: qwidget.h:191
Qt::WindowModality windowModality() const
friend class QPixmap
Definition: qwidget.h:748
void done(int result)
Closes the dialog and sets its result code to result.
int rowAt(int y) const
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QRgb getRgba(QRgb rgba=0xffffffff, bool *ok=0, QWidget *parent=0)
int width() const
static QRgb cusrgb[2 *8]
void init(const QColor &initial)
QLabel * lblGreen
QLabel * alphaLab
QRgb currentColor() const
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
void setValue(int i)
void setWindowFlags(Qt::WindowFlags type)
Definition: qwidget.cpp:10399
const QPalette & palette() const
QSize sizeHint() const
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QStyleOptionFocusRect class is used to describe the parameters for drawing a focus rectangle with...
Definition: qstyleoption.h:103
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
QColSpinBox * alphaEd
QWellArray(int rows, int cols, QWidget *parent=0)
unsigned int uint
Definition: qglobal.h:996
int spacing() const
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QRgb stdrgb[6 *8]
void setCurrentAlpha(int a)
QString windowTitle() const
static void initRGB()
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
Definition: qpainter.cpp:5205
void drawFrame(QPainter *)
em>Reimplemented Function
Definition: qframe.cpp:538
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
Definition: qdrawutil.cpp:303
static void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
bool isAlphaVisible() const
void dropEvent(QDropEvent *e)
This event handler is called when the drag is dropped on this widget.
QColor currentColor() const
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
void _q_newColorTypedIn(QRgb rgb)
QWellArrayData * d
QColorShower(QColorDialog *parent)
static int startDragDistance()
quint16 values[128]
int numCols() const
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
void dragMoveEvent(QDragMoveEvent *e)
This event handler is called if a drag is in progress, and when any of the following conditions occur...
int cellWidth() const
QRect rect() const
void dropEvent(QDropEvent *e)
This event handler is called when the drag is dropped on this widget.
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool selectColor(const QColor &color)
void hide()
Hides the widget.
Definition: qwidget.h:501
void setRgba(QRgb rgba)
Use setRgb() instead.
Definition: qcolor.cpp:1031
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
static QColor getColor(const QColor &initial, QWidget *parent, const QString &title, ColorDialogOptions options=0)
Pops up a modal color dialog with the given window title (or "Select Color" if none is specified)...
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
Definition: qwidget.cpp:10761
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
QPoint oldCurrent
QColSpinBox * hEd
QPoint topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:294
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
virtual void dragMoveEvent(QDragMoveEvent *)
This event handler is called if a drag is in progress, and when any of the following conditions occur...
Definition: qwidget.cpp:9786
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
bool isAlphaVisible() const
void setHsv(int h, int s, int v)
void setBuddy(QWidget *)
Sets this label&#39;s buddy to buddy.
Definition: qlabel.cpp:1297
void setCurrentAlpha(int a)
QPoint bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:297
int x() const
static bool sharedColorPanelAvailable
QString cellContent(int row, int col) const
void dragLeaveEvent(QDragLeaveEvent *e)
This event handler is called when a drag is in progress and the mouse leaves this widget...
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
virtual void setCurrent(int row, int col)
void mouseMoveEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
virtual void dropEvent(QDropEvent *)
This event handler is called when the drag is dropped on this widget.
Definition: qwidget.cpp:9817
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
void addSpacing(int size)
Adds a non-stretchable space (a QSpacerItem) with size size to the end of this box layout...
void mousePressEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void eraseRect(const QRectF &)
Erases the area inside the given rectangle.
Definition: qpainter.cpp:7332
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
~QColorDialog()
Destroys the color dialog.
int selectedColumn
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
void setFrameStyle(int)
Sets the frame style to style.
Definition: qframe.cpp:329
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
virtual void paintCell(QPainter *, int row, int col, const QRect &)
void dragEnterEvent(QDragEnterEvent *e)
This event handler is called when a drag is in progress and the mouse enters this widget...
Qt::DropAction start(Qt::DropActions supportedActions=Qt::CopyAction)
Starts the drag and drop operation and returns a value indicating the requested drop action when it i...
Definition: qdrag.cpp:317
QColSpinBox * sEd
int satPt(const QPoint &pt)
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setMinimumWidth(int minw)
Definition: qwidget.cpp:4325
The QSpinBox class provides a spin box widget.
Definition: qspinbox.h:56
void mouseReleaseEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
int rowY(int row) const
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
int selectedRow() const
int currentAlpha() const
The QHBoxLayout class lines up widgets horizontally.
Definition: qboxlayout.h:129
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int spacing() const
Reimplements QLayout::spacing().
Definition: qboxlayout.cpp:649
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
static QRgb customColor(int index)
Returns the custom color at the given index as a QRgb value.
QRgb currentColor() const
void mouseReleaseEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void currentColorChanged(const QColor &color)
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
QColorShowLabel(QWidget *parent)
const QMimeData * mimeData() const
Returns the data that was dropped on the widget and its associated MIME type information.
Definition: qevent.h:498
void setSizeConstraint(SizeConstraint)
Definition: qlayout.cpp:1435
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QColSpinBox * rEd
void setPoints(int nPoints, const int *points)
Resizes the polygon to nPoints and populates it with the given points.
Definition: qpolygon.cpp:350
void setColor(QColor c)
bool isRightToLeft() const
Definition: qwidget.h:428
void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
QPoint pressPos
QColorLuminancePicker(QWidget *parent=0)
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QRect availableGeometry(int screen=-1) const
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
static bool initrgb
void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void changeEvent(QEvent *event)
Reimplemented Function
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qgridlayout.h:116
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
QLabel * lblVal
void paintCellContents(QPainter *, int row, int col, const QRect &)
Reimplement this function to change the contents of the well array.
bool signalsBlocked() const
Returns true if signals are blocked; otherwise returns false.
Definition: qobject.h:148
QColSpinBox * vEd
#define slots
Definition: qobjectdefs.h:68
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition: qevent.h:305
int currentAlpha() const
void setVisible(bool visible)
Changes the visibility of the dialog.
virtual void dragLeaveEvent(QDragLeaveEvent *)
This event handler is called when a drag is in progress and the mouse leaves this widget...
Definition: qwidget.cpp:9802
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
#define signals
Definition: qobjectdefs.h:69
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
virtual void paintCellContents(QPainter *, int row, int col, const QRect &)
Reimplement this function to change the contents of the well array.
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
static const KeyPair *const end
void setMargin(int)
Definition: qlayout.cpp:464
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
void setOption(ColorDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int selectedColumn() const
void setAlignment(Qt::Alignment)
Without this function, a call to e.
Definition: qlabel.cpp:532
void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void showAlpha(bool b)
void setCurrentQColor(const QColor &color)
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
void ignore()
Calls QDropEvent::ignore().
Definition: qevent.h:540
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
void newCol(int h, int s)
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
bool end()
Ends painting.
Definition: qpainter.cpp:1929
QRect cellRect() const
QSize sizeHint() const
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
void colorSelected(const QColor &color)
This signal is emitted just after the user has clicked OK to select a color to use.
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
void dragEnterEvent(QDragEnterEvent *e)
This event handler is called when a drag is in progress and the mouse enters this widget...
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
static void setCustomColor(int index, QRgb color)
Sets the custom color at index to the QRgb color value.
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
void showAlpha(bool b)
int huePt(const QPoint &pt)