From 5a40143ed622cbd84d5c06afe6cb12017499f69b Mon Sep 17 00:00:00 2001 From: Serge Lysenko Date: Thu, 6 Apr 2017 12:00:04 +0300 Subject: Fix persistence of custom colors palette in QColorDialog QColorDialog does not save custom colors after application relaunching, if those colors were changed with drag'n'drop Task-number: QTBUG-64500 Change-Id: I8ba6e1ef4e078f7b93463e7b20c9e21659d4777e Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qcolordialog.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/widgets/dialogs') diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index cd422297f1..896baed6c5 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -119,6 +119,7 @@ public: void retranslateStrings(); void _q_addCustom(); + void _q_setCustom(int index, QRgb color); void _q_newHsv(int h, int s, int v); void _q_newColorTypedIn(QRgb rgb); @@ -237,6 +238,7 @@ public: signals: void selected(int row, int col); void currentChanged(int row, int col); + void colorChanged(int index, QRgb color); protected: virtual void paintCell(QPainter *, int row, int col, const QRect&); @@ -581,7 +583,7 @@ namespace { class QColorWell : public QWellArray { public: - QColorWell(QWidget *parent, int r, int c, QRgb *vals) + QColorWell(QWidget *parent, int r, int c, const QRgb *vals) :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1) { setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); } @@ -598,7 +600,7 @@ protected: #endif private: - QRgb *values; + const QRgb *values; bool mousePressed; QPoint pressPos; QPoint oldCurrent; @@ -675,8 +677,7 @@ void QColorWell::dropEvent(QDropEvent *e) QColor col = qvariant_cast(e->mimeData()->colorData()); if (col.isValid()) { int i = rowAt(e->pos().y()) + columnAt(e->pos().x()) * numRows(); - values[i] = col.rgb(); - update(); + emit colorChanged(i, col.rgb()); e->accept(); } else { e->ignore(); @@ -1733,6 +1734,13 @@ void QColorDialogPrivate::initWidgets() q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int))); q->connect(custom, SIGNAL(currentChanged(int,int)), SLOT(_q_nextCustom(int,int))); + + q->connect(custom, &QWellArray::colorChanged, [=] (int index, QRgb color) { + QColorDialogOptions::setCustomColor(index, color); + if (custom) + custom->update(); + }); + lblCustomColors = new QLabel(q); #ifndef QT_NO_SHORTCUT lblCustomColors->setBuddy(custom); -- cgit v1.2.3