10#if QT_CONFIG(draganddrop)
22#if QT_CONFIG(regularexpression)
23#include <qregularexpression.h>
25#if QT_CONFIG(settings)
40#include "private/qdialog_p.h"
42#include <qpa/qplatformintegration.h>
43#include <qpa/qplatformservices.h>
44#include <private/qguiapplication_p.h>
46#include <QtCore/qpointer.h>
52using namespace Qt::StringLiterals;
72 Q_DECLARE_PUBLIC(QColorDialog)
88 {
return static_cast<QPlatformColorDialogHelper *>(platformHelper()); }
90 void init(
const QColor &initial);
133 QColorLuminancePicker *
lp;
169 Q_PROPERTY(
int selectedColumn READ selectedColumn)
192 {
return y / cellh; }
195 {
if (isRightToLeft())
return ncols - (x / cellw) - 1;
return x / cellw; }
198 {
return cellh * row; }
201 {
if (isRightToLeft())
return cellw * (ncols - column - 1);
return cellw * column; }
210 {
return QRect(0, 0, cellw, cellh); }
213 {
return QSize(ncols * cellw, nrows * cellh); }
218 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
223 inline void updateCell(
int row,
int column) { update(cellGeometry(row, column)); }
266 if (isRightToLeft()) {
274 QRect rect(0, 0, cellWidth(), cellHeight());
277 if (collast < 0 || collast >= ncols)
279 if (rowlast < 0 || rowlast >= nrows)
283 for (
int r = rowfirst; r <= rowlast; ++r) {
290 for (
int c = colfirst; c <= collast; ++c) {
294 rect.translate(colp, rowp);
296 rect.translate(-colp, -rowp);
303 ,nrows(rows), ncols(cols)
305 setFocusPolicy(Qt::StrongFocus);
317 return gridSize().boundedTo(QSize(640, 480));
325 const QPalette & g = palette();
328 int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt,
this);
330 opt.midLineWidth = 1;
331 opt.rect = rect.adjusted(b, b, -b, -b);
333 opt.state = QStyle::State_Enabled | QStyle::State_Sunken;
334 style()->drawPrimitive(QStyle::PE_Frame, &opt, p,
this);
337 if ((row == curRow) && (col == curCol)) {
342 opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange;
343 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p,
this);
346 paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw));
350
351
356 p->fillRect(r, Qt::white);
357 p->setPen(Qt::black);
358 p->drawLine(r.topLeft(), r.bottomRight());
359 p->drawLine(r.topRight(), r.bottomLeft());
365 QPoint pos = e->position().toPoint();
377
378
379
383 if ((curRow == row) && (curCol == col))
386 if (row < 0 || col < 0)
398 emit currentChanged(curRow, curCol);
402
403
404
405
406
412 if (row < 0 || col < 0)
421 emit selected(row, col);
424 if (isVisible() && qobject_cast<QMenu*>(parentWidget()))
425 parentWidget()->close();
432 emit currentChanged(curRow, curCol);
490 switch (event->type()) {
491 case QEvent::MouseMove:
493 case QEvent::MouseButtonRelease:
495 case QEvent::KeyPress:
510
511
512
513int QColorDialog::customCount()
515 return QColorDialogOptions::customColorCount();
519
520
521QColor QColorDialog::customColor(
int index)
523 return QColor(QColorDialogOptions::customColor(index));
527
528
529
530
531
532
533void QColorDialog::setCustomColor(
int index, QColor color)
535 QColorDialogOptions::setCustomColor(index, color.rgba());
539
540
541
542
543QColor QColorDialog::standardColor(
int index)
545 return QColor(QColorDialogOptions::standardColor(index));
549
550
551
552
553
554
555void QColorDialog::setStandardColor(
int index, QColor color)
557 QColorDialogOptions::setStandardColor(index, color.rgba());
560static inline void rgb2hsv(QRgb rgb,
int &h,
int &s,
int &v)
564 c.getHsv(&h, &s, &v);
574 { setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); }
581#if QT_CONFIG(draganddrop)
599 p->fillRect(r, QColor(values[i]));
604 oldCurrent = QPoint(selectedRow(), selectedColumn());
607 pressPos = e->position().toPoint();
612 QWellArray::mouseMoveEvent(e);
613#if QT_CONFIG(draganddrop)
616 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
617 setCurrent(oldCurrent.x(), oldCurrent.y());
618 int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows();
619 QColor col(values[i]);
620 QMimeData *mime =
new QMimeData;
621 mime->setColorData(col);
622 QPixmap pix(cellWidth(), cellHeight());
625 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
627 QDrag *drg =
new QDrag(
this);
628 drg->setMimeData(mime);
630 mousePressed =
false;
631 drg->exec(Qt::CopyAction);
636#if QT_CONFIG(draganddrop)
680 mousePressed =
false;
709 int huePt(
const QPoint &pt);
710 int satPt(
const QPoint &pt);
711 void setCol(
const QPoint &pt);
744 enum { foff = 3, coff = 4 };
759 int d = height() - 2*coff - 1;
760 return 255 - (y - coff)*255/d;
765 int d = height() - 2*coff - 1;
766 return coff + (255-v)*d/255;
772 hue = 100; val = 100; sat = 100;
784 if (m->buttons() == Qt::NoButton) {
788 setVal(y2val(m->position().toPoint().y()));
792 setVal(y2val(m->position().toPoint().y()));
799 val = qMax(0, qMin(v,255));
800 delete pix; pix=
nullptr;
802 emit newHsv(hue, sat, val);
809 emit newHsv(h, s, val);
816 QRect r(0, foff, w, height() - 2*foff);
817 int wi = r.width() - 2;
818 int hi = r.height() - 2;
819 if (!pix || pix->height() != hi || pix->width() != wi) {
821 QImage img(wi, hi, QImage::Format_RGB32);
823 uint *pixel = (uint *) img.scanLine(0);
824 for (y = 0; y < hi; y++) {
825 uint *end = pixel + wi;
826 std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb());
829 pix =
new QPixmap(QPixmap::fromImage(img));
832 p.drawPixmap(1, coff, *pix);
833 const QPalette &g = palette();
834 qDrawShadePanel(&p, r, g,
true);
835 p.setPen(g.windowText().color());
836 p.setBrush(g.windowText());
837 p.eraseRect(w, 0, 5, height());
838 const int y = val2y(val);
839 const std::array<QPoint, 3> points = {QPoint(w, y), QPoint(w + 5, y + 5), QPoint(w + 5, y - 5)};
840 p.drawPolygon(points.data(),
static_cast<
int>(points.size()));
848 delete pix; pix=
nullptr;
854 QRect r = contentsRect();
855 return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255);
860 QRect r = contentsRect();
861 return 360 - pt.x() * 360 / (r.width() - 1);
866 QRect r = contentsRect();
867 return 255 - pt.y() * 255 / (r.height() - 1);
872 setCol(huePt(pt), satPt(pt));
882 setAttribute(Qt::WA_NoSystemBackground);
883 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
892 if (crossVisible != visible) {
893 crossVisible = visible;
900 return QSize(
pWidth + 2*frameWidth(),
pHeight + 2*frameWidth());
905 int nhue = qMin(qMax(0,h), 359);
906 int nsat = qMin(qMax(0,s), 255);
907 if (nhue == hue && nsat == sat)
910 QRect r(colPt(), QSize(20,20));
911 hue = nhue; sat = nsat;
912 r = r.united(QRect(colPt(), QSize(20,20)));
913 r.translate(contentsRect().x()-9, contentsRect().y()-9);
920 QPoint p = m->position().toPoint() - contentsRect().topLeft();
921 if (m->buttons() == Qt::NoButton) {
926 emit newCol(hue, sat);
931 QPoint p = m->position().toPoint() - contentsRect().topLeft();
933 emit newCol(hue, sat);
940 QRect r = contentsRect();
942 p.drawPixmap(r.topLeft(), pix);
945 QPoint pt = colPt() + r.topLeft();
947 p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black);
948 p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black);
954 QFrame::resizeEvent(ev);
956 int w = width() - frameWidth() * 2;
957 int h = height() - frameWidth() * 2;
958 QImage img(w, h, QImage::Format_RGB32);
960 uint *pixel = (uint *) img.scanLine(0);
961 for (y = 0; y < h; y++) {
962 const uint *end = pixel + w;
964 while (pixel < end) {
967 c.setHsv(huePt(p), satPt(p), 200);
973 pix = QPixmap::fromImage(img);
983 const QSignalBlocker blocker(
this);
984 QSpinBox::setValue(i);
1000 {
return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; }
1023 void showCurrentColor();
1045 QColorDialog *colorDialog;
1072#if QT_CONFIG(draganddrop)
1088 p.fillRect(contentsRect()&e->rect(), col);
1093 alphaLab->setVisible(b);
1094 alphaEd->setVisible(b);
1099 return alphaLab->isVisible();
1104 mousePressed =
true;
1105 pressPos = e->position().toPoint();
1110#if !QT_CONFIG(draganddrop)
1115 if ((pressPos - e->position().toPoint()).manhattanLength() > QApplication::startDragDistance()) {
1116 QMimeData *mime =
new QMimeData;
1117 mime->setColorData(col);
1118 QPixmap pix(30, 20);
1121 p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
1123 QDrag *drg =
new QDrag(
this);
1124 drg->setMimeData(mime);
1125 drg->setPixmap(pix);
1126 mousePressed =
false;
1127 drg->exec(Qt::CopyAction);
1132#if QT_CONFIG(draganddrop)
1163 mousePressed =
false;
1169 colorDialog = parent;
1171 curCol = qRgb(255, 255, 255);
1172 curQColor = Qt::white;
1174 gl =
new QGridLayout(
this);
1175 const int s = gl->spacing();
1176 gl->setContentsMargins(s, s, s, s);
1177 lab =
new QColorShowLabel(
this);
1179#ifdef QT_SMALL_COLORDIALOG
1180 lab->setMinimumHeight(60);
1182 lab->setMinimumWidth(60);
1186#if !defined(QT_SMALL_COLORDIALOG)
1187 gl->addWidget(lab, 0, 0, -1, 1);
1189 gl->addWidget(lab, 0, 0, 1, -1);
1191 connect(lab, &QColorShowLabel::colorDropped,
this, &QColorShower::newCol);
1192 connect(lab, &QColorShowLabel::colorDropped,
this, &QColorShower::setRgb);
1194 hEd =
new QColSpinBox(
this);
1195 hEd->setRange(0, 359);
1196 lblHue =
new QLabel(
this);
1197#ifndef QT_NO_SHORTCUT
1198 lblHue->setBuddy(hEd);
1200 lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1201#if !defined(QT_SMALL_COLORDIALOG)
1202 gl->addWidget(lblHue, 0, 1);
1203 gl->addWidget(hEd, 0, 2);
1205 gl->addWidget(lblHue, 1, 0);
1206 gl->addWidget(hEd, 2, 0);
1209 sEd =
new QColSpinBox(
this);
1210 lblSat =
new QLabel(
this);
1211#ifndef QT_NO_SHORTCUT
1212 lblSat->setBuddy(sEd);
1214 lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1215#if !defined(QT_SMALL_COLORDIALOG)
1216 gl->addWidget(lblSat, 1, 1);
1217 gl->addWidget(sEd, 1, 2);
1219 gl->addWidget(lblSat, 1, 1);
1220 gl->addWidget(sEd, 2, 1);
1223 vEd =
new QColSpinBox(
this);
1224 lblVal =
new QLabel(
this);
1225#ifndef QT_NO_SHORTCUT
1226 lblVal->setBuddy(vEd);
1228 lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1229#if !defined(QT_SMALL_COLORDIALOG)
1230 gl->addWidget(lblVal, 2, 1);
1231 gl->addWidget(vEd, 2, 2);
1233 gl->addWidget(lblVal, 1, 2);
1234 gl->addWidget(vEd, 2, 2);
1237 rEd =
new QColSpinBox(
this);
1238 lblRed =
new QLabel(
this);
1239#ifndef QT_NO_SHORTCUT
1240 lblRed->setBuddy(rEd);
1242 lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1243#if !defined(QT_SMALL_COLORDIALOG)
1244 gl->addWidget(lblRed, 0, 3);
1245 gl->addWidget(rEd, 0, 4);
1247 gl->addWidget(lblRed, 3, 0);
1248 gl->addWidget(rEd, 4, 0);
1251 gEd =
new QColSpinBox(
this);
1252 lblGreen =
new QLabel(
this);
1253#ifndef QT_NO_SHORTCUT
1254 lblGreen->setBuddy(gEd);
1256 lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1257#if !defined(QT_SMALL_COLORDIALOG)
1258 gl->addWidget(lblGreen, 1, 3);
1259 gl->addWidget(gEd, 1, 4);
1261 gl->addWidget(lblGreen, 3, 1);
1262 gl->addWidget(gEd, 4, 1);
1265 bEd =
new QColSpinBox(
this);
1266 lblBlue =
new QLabel(
this);
1267#ifndef QT_NO_SHORTCUT
1268 lblBlue->setBuddy(bEd);
1270 lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1271#if !defined(QT_SMALL_COLORDIALOG)
1272 gl->addWidget(lblBlue, 2, 3);
1273 gl->addWidget(bEd, 2, 4);
1275 gl->addWidget(lblBlue, 3, 2);
1276 gl->addWidget(bEd, 4, 2);
1279 alphaEd =
new QColSpinBox(
this);
1280 alphaLab =
new QLabel(
this);
1281#ifndef QT_NO_SHORTCUT
1282 alphaLab->setBuddy(alphaEd);
1284 alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1285#if !defined(QT_SMALL_COLORDIALOG)
1286 gl->addWidget(alphaLab, 3, 1, 1, 3);
1287 gl->addWidget(alphaEd, 3, 4);
1289 gl->addWidget(alphaLab, 1, 3, 3, 1);
1290 gl->addWidget(alphaEd, 4, 3);
1294 lblHtml =
new QLabel(
this);
1295 htEd =
new QLineEdit(
this);
1296 htEd->setObjectName(
"qt_colorname_lineedit");
1297#ifndef QT_NO_SHORTCUT
1298 lblHtml->setBuddy(htEd);
1301#if QT_CONFIG(regularexpression)
1302 QRegularExpression regExp(QStringLiteral(
"#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));
1303 QRegularExpressionValidator *validator =
new QRegularExpressionValidator(regExp,
this);
1304 htEd->setValidator(validator);
1306 htEd->setReadOnly(
true);
1308 htEd->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
1310 lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
1311#if defined(QT_SMALL_COLORDIALOG)
1312 gl->addWidget(lblHtml, 5, 0);
1313 gl->addWidget(htEd, 5, 1, 1, 2);
1315 gl->addWidget(lblHtml, 5, 1);
1316 gl->addWidget(htEd, 5, 2, 1, 3);
1319 connect(hEd, &QSpinBox::valueChanged,
this, &QColorShower::hsvEd);
1320 connect(sEd, &QSpinBox::valueChanged,
this, &QColorShower::hsvEd);
1321 connect(vEd, &QSpinBox::valueChanged,
this, &QColorShower::hsvEd);
1323 connect(rEd, &QSpinBox::valueChanged,
this, &QColorShower::rgbEd);
1324 connect(gEd, &QSpinBox::valueChanged,
this, &QColorShower::rgbEd);
1325 connect(bEd, &QSpinBox::valueChanged,
this, &QColorShower::rgbEd);
1326 connect(alphaEd, &QSpinBox::valueChanged,
this, &QColorShower::rgbEd);
1327 connect(htEd, &QLineEdit::textEdited,
this, &QColorShower::htmlEd);
1342 if (nativeDialogInUse)
1343 return platformColorDialogHelper()->currentColor();
1344 return cs->currentQColor();
1347void QColorShower::showCurrentColor()
1349 lab->setColor(currentColor());
1353void QColorShower::rgbEd()
1356 curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha());
1358 rgb2hsv(currentColor(), hue, sat, val);
1364 htEd->setText(QColor(curCol).name());
1367 emit newCol(currentColor());
1371void QColorShower::hsvEd()
1373 rgbOriginal =
false;
1379 c.setHsv(hue, sat, val);
1382 rEd->setValue(qRed(currentColor()));
1383 gEd->setValue(qGreen(currentColor()));
1384 bEd->setValue(qBlue(currentColor()));
1386 htEd->setText(c.name());
1389 emit newCol(currentColor());
1393void QColorShower::htmlEd()
1395 QString t = htEd->text();
1399 if (!t.startsWith(u"#")) {
1401 QSignalBlocker blocker(htEd);
1405 QColor c = QColor::fromString(t);
1409 curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());
1410 rgb2hsv(curCol, hue, sat, val);
1416 rEd->setValue(qRed(currentColor()));
1417 gEd->setValue(qGreen(currentColor()));
1418 bEd->setValue(qBlue(currentColor()));
1421 emit newCol(currentColor());
1425void QColorShower::setRgb(QRgb rgb)
1430 rgb2hsv(currentColor(), hue, sat, val);
1436 rEd->setValue(qRed(currentColor()));
1437 gEd->setValue(qGreen(currentColor()));
1438 bEd->setValue(qBlue(currentColor()));
1440 htEd->setText(QColor(rgb).name());
1446void QColorShower::
setHsv(
int h,
int s,
int v)
1448 if (h < -1 || (uint)s > 255 || (uint)v > 255)
1451 rgbOriginal =
false;
1452 hue = h; val = v; sat = s;
1454 c.setHsv(hue, sat, val);
1461 rEd->setValue(qRed(currentColor()));
1462 gEd->setValue(qGreen(currentColor()));
1463 bEd->setValue(qBlue(currentColor()));
1465 htEd->setText(c.name());
1473 lblHue->setText(QColorDialog::tr(
"Hu&e:"));
1474 lblSat->setText(QColorDialog::tr(
"&Sat:"));
1475 lblVal->setText(QColorDialog::tr(
"&Val:"));
1476 lblRed->setText(QColorDialog::tr(
"&Red:"));
1477 lblGreen->setText(QColorDialog::tr(
"&Green:"));
1478 lblBlue->setText(QColorDialog::tr(
"Bl&ue:"));
1479 alphaLab->setText(QColorDialog::tr(
"A&lpha channel:"));
1480 lblHtml->setText(QColorDialog::tr(
"&HTML:"));
1485 QColor oldQColor(curQColor);
1486 curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1487 if (curQColor != oldQColor)
1488 emit currentColorChanged(curQColor);
1494 if (!nativeDialogInUse) {
1504 if (!nativeDialogInUse) {
1506 newColorTypedIn(rgb);
1514 if (
cs->curQColor != color) {
1515 cs->curQColor = color;
1516 emit q->currentColorChanged(color);
1529 QRgb color = col.rgb();
1532 const QRgb *standardColors = QColorDialogOptions::standardColors();
1534 const QRgb *match =
std::find(standardColors, standardColorsEnd, color);
1535 if (match != standardColorsEnd) {
1536 const int index =
int(match - standardColors);
1548 const QRgb *customColors = QColorDialogOptions::customColors();
1550 const QRgb *match =
std::find(customColors, customColorsEnd, color);
1551 if (match != customColorsEnd) {
1552 const int index =
int(match - customColors);
1567 QScreen *screen = QGuiApplication::screenAt(p);
1569 screen = QGuiApplication::primaryScreen();
1570 const QRect screenRect = screen->geometry();
1571 const QPixmap pixmap =
1572 screen->grabWindow(0, p.x() - screenRect.x(), p.y() - screenRect.y(), 1, 1);
1573 const QImage i = pixmap.toImage();
1574 return i.pixel(0, 0);
1580 if (!nativeDialogInUse) {
1582 rgb2hsv(rgb, h, s, v);
1596 setCurrentRgbColor(QColorDialogOptions::customColor(i));
1603 setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6));
1612 auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
1613 if (platformServices && platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) {
1614 if (
auto *colorPicker = platformServices->colorPicker(q->windowHandle())) {
1615 q->connect(colorPicker, &QPlatformServiceColorPicker::colorPicked, q,
1616 [q, colorPicker](
const QColor &color) {
1617 colorPicker->deleteLater();
1618 q->setCurrentColor(color);
1620 colorPicker->pickColor();
1625 if (!colorPickingEventFilter)
1626 colorPickingEventFilter =
new QColorPickingEventFilter(
this, q);
1627 q->installEventFilter(colorPickingEventFilter);
1629 beforeScreenColorPicking = cs->currentColor();
1631 q->grabMouse(Qt::CrossCursor);
1638 updateTimer->start(30);
1643 dummyTransparentWindow.show();
1647
1648
1649 q->setMouseTracking(
true);
1652 buttons->setDisabled(
true);
1655 const QPoint globalPos = QCursor::pos();
1656 q->setCurrentColor(grabScreenColor(globalPos));
1663 if (lblScreenColorInfo)
1664 lblScreenColorInfo->setText(QColorDialog::tr(
"Cursor at %1, %2\nPress ESC to cancel")
1666 .arg(globalPos.y()));
1673 q->removeEventFilter(colorPickingEventFilter);
1676 updateTimer->stop();
1677 dummyTransparentWindow.setVisible(
false);
1679 q->releaseKeyboard();
1680 q->setMouseTracking(
false);
1681 lblScreenColorInfo->setText(
"\n"_L1);
1683 buttons->setDisabled(
false);
1691 q->setSizeGripEnabled(
false);
1692 q->setWindowTitle(QColorDialog::tr(
"Select Color"));
1695 nativeDialogInUse = (platformColorDialogHelper() !=
nullptr);
1699 if (!nativeDialogInUse)
1703 dummyTransparentWindow.resize(1, 1);
1704 dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);
1707 q->setCurrentColor(initial);
1713 QVBoxLayout *mainLay =
new QVBoxLayout(q);
1715 mainLay->setSizeConstraint(QLayout::SetFixedSize);
1717 QHBoxLayout *topLay =
new QHBoxLayout();
1718 mainLay->addLayout(topLay);
1722#if defined(QT_SMALL_COLORDIALOG)
1723 smallDisplay =
true;
1724 const int lumSpace = 20;
1728 smallDisplay = (QGuiApplication::primaryScreen()->virtualGeometry().width() < 480 || QGuiApplication::primaryScreen()->virtualGeometry().height() < 350);
1729 const int lumSpace = topLay->spacing() / 2;
1733 leftLay =
new QVBoxLayout;
1734 topLay->addLayout(leftLay);
1736 standard =
new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());
1737 lblBasicColors =
new QLabel(q);
1738#ifndef QT_NO_SHORTCUT
1739 lblBasicColors->setBuddy(standard);
1741 QObjectPrivate::connect(standard, &QColorWell::selected,
1742 this, &QColorDialogPrivate::newStandard);
1743 leftLay->addWidget(lblBasicColors);
1744 leftLay->addWidget(standard);
1746#if !defined(QT_SMALL_COLORDIALOG)
1748 eyeDropperButton =
new QPushButton();
1749 leftLay->addWidget(eyeDropperButton);
1750 lblScreenColorInfo =
new QLabel(
"\n"_L1);
1751 leftLay->addWidget(lblScreenColorInfo);
1752 QObjectPrivate::connect(eyeDropperButton, &QPushButton::clicked,
1753 this, &QColorDialogPrivate::pickScreenColor);
1756 lblScreenColorInfo =
nullptr;
1760 leftLay->addStretch();
1762 custom =
new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors());
1763 custom->setAcceptDrops(
true);
1765 QObjectPrivate::connect(custom, &QColorWell::selected,
this, &QColorDialogPrivate::newCustom);
1766 QObjectPrivate::connect(custom, &QColorWell::currentChanged,
this, &QColorDialogPrivate::nextCustom);
1768 QObject::connect(custom, &QWellArray::colorChanged, q, [
this] (
int index, QRgb color) {
1769 QColorDialogOptions::setCustomColor(index, color);
1774 lblCustomColors =
new QLabel(q);
1775#ifndef QT_NO_SHORTCUT
1776 lblCustomColors->setBuddy(custom);
1778 leftLay->addWidget(lblCustomColors);
1779 leftLay->addWidget(custom);
1781 addCusBt =
new QPushButton(q);
1782 QObjectPrivate::connect(addCusBt, &QPushButton::clicked,
this, &QColorDialogPrivate::addCustom);
1783 leftLay->addWidget(addCusBt);
1786#if defined(QT_SMALL_COLORDIALOG)
1787 QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size();
1788 pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
1790 if (screenSize.height() > screenSize.width())
1800 QVBoxLayout *rightLay =
new QVBoxLayout;
1801 topLay->addLayout(rightLay);
1803 QHBoxLayout *pickLay =
new QHBoxLayout;
1804 rightLay->addLayout(pickLay);
1806 QVBoxLayout *cLay =
new QVBoxLayout;
1807 pickLay->addLayout(cLay);
1808 cp =
new QColorPicker(q);
1810 cp->setFrameStyle(QFrame::Panel | QFrame::Sunken);
1812#if defined(QT_SMALL_COLORDIALOG)
1815 cLay->addSpacing(lumSpace);
1816 cLay->addWidget(
cp);
1818 cLay->addSpacing(lumSpace);
1820 lp =
new QColorLuminancePicker(q);
1821#if defined(QT_SMALL_COLORDIALOG)
1824 lp->setFixedWidth(20);
1825 pickLay->addSpacing(10);
1826 pickLay->addWidget(
lp);
1827 pickLay->addStretch();
1830 QObject::connect(cp, &QColorPicker::newCol, lp, qOverload<
int,
int>(&QColorLuminancePicker::setCol));
1831 QObjectPrivate::connect(lp, &QColorLuminancePicker::newHsv,
this, &QColorDialogPrivate::newHsv);
1833 rightLay->addStretch();
1835 cs =
new QColorShower(q);
1836 pickLay->setContentsMargins(
cs->gl->contentsMargins());
1837 QObjectPrivate::connect(cs, &QColorShower::newCol,
1838 this, &QColorDialogPrivate::newColorTypedIn);
1839 QObject::connect(cs, &QColorShower::currentColorChanged,
1840 q, &QColorDialog::currentColorChanged);
1841#if defined(QT_SMALL_COLORDIALOG)
1842 topLay->addWidget(cs);
1844 rightLay->addWidget(
cs);
1846 leftLay->addSpacing(cs->gl->contentsMargins().right());
1849 buttons =
new QDialogButtonBox(q);
1850 mainLay->addWidget(buttons);
1852 ok = buttons->addButton(QDialogButtonBox::Ok);
1853 QObject::connect(ok, &QPushButton::clicked, q, &QColorDialog::accept);
1854 ok->setDefault(
true);
1855 cancel = buttons->addButton(QDialogButtonBox::Cancel);
1856 QObject::connect(cancel, &QPushButton::clicked, q, &QColorDialog::reject);
1859 updateTimer =
new QTimer(q);
1860 QObjectPrivate::connect(updateTimer, &QTimer::timeout,
1861 this, qOverload<>(&QColorDialogPrivate::updateColorPicking));
1868 QColorDialog *d = q_func();
1869 auto *colorDialogHelper =
static_cast<QPlatformColorDialogHelper*>(h);
1870 QObject::connect(colorDialogHelper, &QPlatformColorDialogHelper::currentColorChanged,
1871 d, &QColorDialog::currentColorChanged);
1872 QObject::connect(colorDialogHelper, &QPlatformColorDialogHelper::colorSelected,
1873 d, &QColorDialog::colorSelected);
1874 colorDialogHelper->setOptions(options);
1879 options->setWindowTitle(q_func()->windowTitle());
1884 QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
1887 nextCust = (nextCust+1) % QColorDialogOptions::customColorCount();
1892 if (nativeDialogInUse)
1896 lblBasicColors->setText(QColorDialog::tr(
"&Basic colors"));
1897 lblCustomColors->setText(QColorDialog::tr(
"&Custom colors"));
1898 addCusBt->setText(QColorDialog::tr(
"&Add to Custom Colors"));
1899#if !defined(QT_SMALL_COLORDIALOG)
1900 if (eyeDropperButton)
1901 eyeDropperButton->setText(QColorDialog::tr(
"&Pick Screen Color"));
1910 const auto integration = QGuiApplicationPrivate::platformIntegration();
1911 return integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
1912 || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking);
1919 const QDialog *
const q =
static_cast<
const QDialog*>(q_ptr);
1920 if (nativeDialogInUse)
1922 if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs)
1923 || q->testAttribute(Qt::WA_DontShowOnScreen)
1924 || (options->options() & QColorDialog::DontUseNativeDialog)) {
1928 return strcmp(QColorDialog::staticMetaObject.className(), q->metaObject()->className()) == 0;
1932 Qt::Dialog | Qt::WindowTitleHint
1933 | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1975
1976
1977QColorDialog::QColorDialog(QWidget *parent)
1978 : QColorDialog(QColor(Qt::white), parent)
1983
1984
1985
1986QColorDialog::QColorDialog(
const QColor &initial, QWidget *parent)
1987 : QDialog(*
new QColorDialogPrivate, parent, qcd_DefaultWindowFlags)
1995 if (nativeDialogInUse) {
1996 platformColorDialogHelper()->setCurrentColor(color);
2000 if (setColorMode & ShowColor) {
2001 setCurrentRgbColor(color.rgb());
2004 if (setColorMode & SelectColor)
2009
2010
2011
2013void QColorDialog::setCurrentColor(
const QColor &color)
2016 d->setCurrentColor(color);
2019QColor QColorDialog::currentColor()
const
2021 Q_D(
const QColorDialog);
2022 return d->currentQColor();
2026
2027
2028
2029
2030
2031
2032
2033QColor QColorDialog::selectedColor()
const
2035 Q_D(
const QColorDialog);
2036 return d->selectedQColor;
2040
2041
2042
2043
2044
2045void QColorDialog::setOption(ColorDialogOption option,
bool on)
2047 const QColorDialog::ColorDialogOptions previousOptions = options();
2048 if (!(previousOptions & option) != !on)
2049 setOptions(previousOptions ^ option);
2053
2054
2055
2056
2057
2058bool QColorDialog::testOption(ColorDialogOption option)
const
2060 Q_D(
const QColorDialog);
2061 return d->options->testOption(
static_cast<QColorDialogOptions::ColorDialogOption>(option));
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076void QColorDialog::setOptions(ColorDialogOptions options)
2080 if (QColorDialog::options() == options)
2083 d->options->setOptions(QColorDialogOptions::ColorDialogOptions(
int(options)));
2084 if ((options & DontUseNativeDialog) && d->nativeDialogInUse) {
2085 d->nativeDialogInUse =
false;
2088 if (!d->nativeDialogInUse) {
2089 d->buttons->setVisible(!(options & NoButtons));
2090 d->showAlpha(options & ShowAlphaChannel);
2091 if (d->eyeDropperButton)
2092 d->eyeDropperButton->setVisible(!(options & NoEyeDropperButton));
2096QColorDialog::ColorDialogOptions QColorDialog::options()
const
2098 Q_D(
const QColorDialog);
2099 return QColorDialog::ColorDialogOptions(
int(d->options->options()));
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2118
2119
2120
2121
2122
2123
2124
2127
2128
2129
2130
2131
2132
2133
2136
2137
2138
2139void QColorDialog::setVisible(
bool visible)
2142 QDialog::setVisible(visible);
2146
2147
2148
2149
2150
2151
2157 selectedQColor = QColor();
2159 if (nativeDialogInUse) {
2160 if (setNativeDialogVisible(visible)) {
2163 q->setAttribute(Qt::WA_DontShowOnScreen);
2168 q->setAttribute(Qt::WA_DontShowOnScreen,
false);
2171 QDialogPrivate::setVisible(visible);
2175
2176
2177
2178
2179
2180void QColorDialog::open(QObject *receiver,
const char *member)
2183 connect(
this, SIGNAL(colorSelected(QColor)), receiver, member);
2184 d->receiverToDisconnectOnClose = receiver;
2185 d->memberToDisconnectOnClose = member;
2190
2191
2192
2193
2194
2195
2196
2197QColor QColorDialog::getColor(
const QColor &initial, QWidget *parent,
const QString &title,
2198 ColorDialogOptions options)
2200 QAutoPointer<QColorDialog> dlg(
new QColorDialog(parent));
2201 if (!title.isEmpty())
2202 dlg->setWindowTitle(title);
2203 dlg->setOptions(options);
2204 dlg->setCurrentColor(initial);
2210 return dlg->selectedColor();
2216
2217
2219QColorDialog::~QColorDialog()
2224
2225
2226void QColorDialog::changeEvent(QEvent *e)
2229 if (e->type() == QEvent::LanguageChange)
2230 d->retranslateStrings();
2231 QDialog::changeEvent(e);
2238 static QPoint lastGlobalPos;
2239 QPoint newGlobalPos = QCursor::pos();
2240 if (lastGlobalPos == newGlobalPos)
2242 lastGlobalPos = newGlobalPos;
2244 if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) {
2245 updateColorPicking(newGlobalPos);
2247 dummyTransparentWindow.setPosition(newGlobalPos);
2255 const QColor color = grabScreenColor(globalPos);
2258 setCurrentColor(color, ShowColor);
2267 updateColorPicking(e->globalPosition().toPoint());
2273 setCurrentColor(grabScreenColor(e->globalPosition().toPoint()), SetColorAll);
2281#if QT_CONFIG(shortcut)
2282 if (e->matches(QKeySequence::Cancel)) {
2283 releaseColorPicking();
2284 q->setCurrentColor(beforeScreenColorPicking);
2287 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
2288 q->setCurrentColor(grabScreenColor(QCursor::pos()));
2296
2297
2298
2299
2300
2301
2302void QColorDialog::done(
int result)
2305 if (result == Accepted) {
2306 d->selectedQColor = d->currentQColor();
2307 emit colorSelected(d->selectedQColor);
2309 d->selectedQColor = QColor();
2311 QDialog::done(result);
2312 if (d->receiverToDisconnectOnClose) {
2313 disconnect(
this, SIGNAL(colorSelected(QColor)),
2314 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
2315 d->receiverToDisconnectOnClose =
nullptr;
2317 d->memberToDisconnectOnClose.clear();
2322#include "qcolordialog.moc"
2323#include "moc_qcolordialog.cpp"
void releaseColorPicking()
QColor grabScreenColor(const QPoint &p)
bool selectColor(const QColor &color)
void init(const QColor &initial)
void setCurrentAlpha(int a)
QColorPickingEventFilter * colorPickingEventFilter
bool handleColorPickingMouseButtonRelease(QMouseEvent *e)
QColor currentQColor() const
void updateColorPicking()
bool handleColorPickingMouseMove(QMouseEvent *e)
QLabel * lblScreenColorInfo
void _q_setCustom(int index, QRgb color)
QPushButton * eyeDropperButton
void updateColorLabelText(const QPoint &)
void setCurrentColor(const QColor &color, SetColorMode setColorMode=SetColorAll)
bool isAlphaVisible() const
void setCurrentQColor(const QColor &color)
bool canBeNativeDialog() const override
void setCurrentRgbColor(QRgb rgb)
void retranslateStrings()
QRgb currentColor() const
void newColorTypedIn(QRgb rgb)
bool handleColorPickingKeyPress(QKeyEvent *e)
void updateColorPicking(const QPoint &pos)
QSharedPointer< QColorDialogOptions > options
void newStandard(int, int)
void setVisible(bool visible) override
QDialogButtonBox * buttons
bool supportsColorPicking() const
QPointer< QObject > receiverToDisconnectOnClose
QRgb beforeScreenColorPicking
virtual void initHelper(QPlatformDialogHelper *h) override
QByteArray memberToDisconnectOnClose
void newHsv(int h, int s, int v)
virtual void helperPrepareShow(QPlatformDialogHelper *h) override
QColorLuminancePicker * lp
QPlatformColorDialogHelper * platformColorDialogHelper() const
void nextCustom(int, int)
\inmodule QtCore\reentrant
\variable QStyleOption::palette
\variable QStyleOptionFocusRect::backgroundColor
QColSpinBox(QWidget *parent)
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void mouseMoveEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void setCol(int h, int s)
void mousePressEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void mouseMoveEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
QSize sizeHint() const override
void setCrossVisible(bool visible)
void resizeEvent(QResizeEvent *) override
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
void mousePressEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
bool eventFilter(QObject *, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent)
void mouseReleaseEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseMoveEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
QColor currentQColor() const
void setCurrentAlpha(int a)
bool isAlphaVisible() const
void setHsv(int h, int s, int v)
void retranslateStrings()
QRgb currentColor() const
void currentColorChanged(const QColor &color)
QColorWell(QWidget *parent, int r, int c, const QRgb *vals)
void paintCellContents(QPainter *, int row, int col, const QRect &) override
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseMoveEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void mouseReleaseEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
friend class QT_PREPEND_NAMESPACE(QUntypedBindable)
void mouseReleaseEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void focusOutEvent(QFocusEvent *) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
void currentChanged(int row, int col)
int columnAt(int x) const
void updateCell(int row, int column)
void colorChanged(int index, QRgb color)
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void mousePressEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void focusInEvent(QFocusEvent *) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
virtual void setCurrent(int row, int col)
virtual void setSelected(int row, int col)
QRect cellGeometry(int row, int column)
virtual void paintCell(QPainter *, int row, int col, const QRect &)
int columnX(int column) const
QSize sizeHint() const override
virtual void paintCellContents(QPainter *, int row, int col, const QRect &)
int selectedColumn() const
void keyPressEvent(QKeyEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
QString cellContent(int row, int col) const
static void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
static const Qt::WindowFlags qcd_DefaultWindowFlags