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 <richard.gustavsen@qt.io>
bb10
Serge Lysenko 2017-04-06 12:00:04 +03:00 committed by Serge Lysenko
parent 4d88d79aa5
commit 5a40143ed6
2 changed files with 13 additions and 4 deletions

View File

@ -297,6 +297,7 @@ void QColorDialogStaticData::writeSettings() const
{
#ifndef QT_NO_SETTINGS
if (customSet) {
const_cast<QColorDialogStaticData*>(this)->customSet = false;
QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));
for (int i = 0; i < int(CustomColorCount); ++i)
settings.setValue(QLatin1String("Qt/customColors/") + QString::number(i), customRgb[i]);

View File

@ -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<QColor>(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);