2
* Copyright (C) 2010 Celarek Adam <kdedev at xibo dot at>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "kis_color_selector_settings.h"
20
#include "ui_wdg_color_selector_settings.h"
22
#include <QVBoxLayout>
23
#include <QDialogButtonBox>
24
#include <QPushButton>
26
#include <KConfigGroup>
29
#include "KoColorSpace.h"
30
#include "KoColorSpaceRegistry.h"
31
#include "KoColorProfile.h"
33
#include "kis_color_selector_combo_box.h"
34
#include "kis_color_selector.h"
39
KisColorSelectorSettings::KisColorSelectorSettings(QWidget *parent) :
40
KisPreferenceSet(parent),
41
ui(new Ui::KisColorSelectorSettings)
44
ui->lbl_lastUsedNumRows->hide();
45
ui->lastUsedColorsNumRows->hide();
47
ui->lbl_commonColorsNumCols->hide();
48
ui->commonColorsNumCols->hide();
49
resize(minimumSize());
51
ui->colorSelectorConfiguration->setColorSpace(ui->colorSpace->currentColorSpace());
53
connect(ui->colorSpace, SIGNAL(colorSpaceChanged(const KoColorSpace*)),
54
ui->colorSelectorConfiguration, SLOT(setColorSpace(const KoColorSpace*)));
56
connect(ui->minimalShadeSelectorLineCount, SIGNAL(valueChanged(int)),
57
ui->minimalShadeSelectorLineSettings, SLOT(setLineCount(int)));
59
connect(ui->minimalShadeSelectorLineSettings, SIGNAL(lineCountChanged(int)),
60
ui->minimalShadeSelectorLineCount, SLOT(setValue(int)));
62
connect(ui->minimalShadeSelectorAsGradient, SIGNAL(toggled(bool)),
63
ui->minimalShadeSelectorLineSettings, SIGNAL(setGradient(bool)));
65
connect(ui->minimalShadeSelectorAsColorPatches, SIGNAL(toggled(bool)),
66
ui->minimalShadeSelectorLineSettings, SIGNAL(setPatches(bool)));
68
connect(ui->minimalShadeSelectorLineHeight, SIGNAL(valueChanged(int)),
69
ui->minimalShadeSelectorLineSettings, SIGNAL(setLineHeight(int)));
71
connect(ui->minimalShadeSelectorPatchesPerLine, SIGNAL(valueChanged(int)),
72
ui->minimalShadeSelectorLineSettings, SIGNAL(setPatchCount(int)));
75
//load and save preferences
76
//if something in kritarc is missing, then the default from this load function will be used and saved back to kconfig.
77
//this way, cfg.readEntry() in any part won't be able to set its own default
82
KisColorSelectorSettings::~KisColorSelectorSettings()
87
QString KisColorSelectorSettings::id()
89
return QString("advancedColorSelector");
92
QString KisColorSelectorSettings::name()
97
QString KisColorSelectorSettings::header()
99
return QString("Color Selector Settings");
103
KIcon KisColorSelectorSettings::icon()
105
return KIcon("extended_color_selector");
109
void KisColorSelectorSettings::savePreferences() const
112
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
115
cfg.writeEntry("shadeSelectorHideable", ui->shadeSelectorHideable->isChecked());
116
cfg.writeEntry("allowHorizontalLayout", ui->allowHorizontalLayout->isChecked());
117
cfg.writeEntry("popupOnMouseOver", ui->popupOnMouseOver->isChecked());
118
cfg.writeEntry("popupOnMouseClick", ui->popupOnMouseClick->isChecked());
119
cfg.writeEntry("zoomSize", ui->popupSize->value());
121
cfg.writeEntry("useCustomColorSpace", ui->useCustomColorSpace->isChecked());
122
const KoColorSpace* colorSpace = ui->colorSpace->currentColorSpace();
124
cfg.writeEntry("customColorSpaceModel", colorSpace->colorModelId().id());
125
cfg.writeEntry("customColorSpaceDepthID", colorSpace->colorDepthId().id());
126
cfg.writeEntry("customColorSpaceProfile", colorSpace->profile()->name());
130
cfg.writeEntry("lastUsedColorsShow", ui->lastUsedColorsShow->isChecked());
131
cfg.writeEntry("lastUsedColorsAlignment", ui->lastUsedColorsAlignVertical->isChecked());
132
cfg.writeEntry("lastUsedColorsScrolling", ui->lastUsedColorsAllowScrolling->isChecked());
133
cfg.writeEntry("lastUsedColorsNumCols", ui->lastUsedColorsNumCols->value());
134
cfg.writeEntry("lastUsedColorsNumRows", ui->lastUsedColorsNumRows->value());
135
cfg.writeEntry("lastUsedColorsCount", ui->lastUsedColorsPatchCount->value());
136
cfg.writeEntry("lastUsedColorsWidth", ui->lastUsedColorsWidth->value());
137
cfg.writeEntry("lastUsedColorsHeight", ui->lastUsedColorsHeight->value());
139
cfg.writeEntry("commonColorsShow", ui->commonColorsShow->isChecked());
140
cfg.writeEntry("commonColorsAlignment", ui->commonColorsAlignVertical->isChecked());
141
cfg.writeEntry("commonColorsScrolling", ui->commonColorsAllowScrolling->isChecked());
142
cfg.writeEntry("commonColorsNumCols", ui->commonColorsNumCols->value());
143
cfg.writeEntry("commonColorsNumRows", ui->commonColorsNumRows->value());
144
cfg.writeEntry("commonColorsCount", ui->commonColorsPatchCount->value());
145
cfg.writeEntry("commonColorsWidth", ui->commonColorsWidth->value());
146
cfg.writeEntry("commonColorsHeight", ui->commonColorsHeight->value());
147
cfg.writeEntry("commonColorsAutoUpdate", ui->commonColorsAutoUpdate->isChecked());
150
QString shadeSelectorType("MyPaint");
151
if(ui->shadeSelectorTypeMinimal->isChecked())
152
shadeSelectorType="Minimal";
153
if(ui->shadeSelectorTypeHidden->isChecked())
154
shadeSelectorType="Hidden";
156
cfg.writeEntry("shadeSelectorType", shadeSelectorType);
158
cfg.writeEntry("shadeSelectorUpdateOnRightClick", ui->shadeSelectorUpdateOnRightClick->isChecked());
159
cfg.writeEntry("shadeSelectorUpdateOnForeground", ui->shadeSelectorUpdateOnForeground->isChecked());
160
cfg.writeEntry("shadeSelectorUpdateOnLeftClick", ui->shadeSelectorUpdateOnLeftClick->isChecked());
161
cfg.writeEntry("shadeSelectorUpdateOnBackground", ui->shadeSelectorUpdateOnBackground->isChecked());
163
cfg.writeEntry("minimalShadeSelectorAsGradient", ui->minimalShadeSelectorAsGradient->isChecked());
164
cfg.writeEntry("minimalShadeSelectorPatchCount", ui->minimalShadeSelectorPatchesPerLine->value());
165
cfg.writeEntry("minimalShadeSelectorLineConfig", ui->minimalShadeSelectorLineSettings->toString());
166
cfg.writeEntry("minimalShadeSelectorLineHeight", ui->minimalShadeSelectorLineHeight->value());
169
KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
170
cfg.writeEntry("colorSelectorConfiguration", cstw->configuration().toString());
172
emit settingsChanged();
175
//void KisColorSelectorSettings::changeEvent(QEvent *e)
177
// QDialog::changeEvent(e);
178
// switch (e->type()) {
179
// case QEvent::LanguageChange:
180
// ui->retranslateUi(this);
187
void KisColorSelectorSettings::loadPreferences()
190
//don't forget to also add a new entry to the default preferences
192
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
196
//it's not possible to set a radio box to false. additionally, we need to set shrunkenDonothing to true, in case..
197
bool a = cfg.readEntry("shadeSelectorHideable", false);
198
bool b = cfg.readEntry("allowHorizontalLayout", false);
200
ui->shadeSelectorHideable->setChecked(true);
202
ui->allowHorizontalLayout->setChecked(true);
204
ui->shrunkenDoNothing->setChecked(true);
206
if(cfg.readEntry("useCustomColorSpace", false))
207
ui->useCustomColorSpace->setChecked(true);
209
ui->useImageColorSpace->setChecked(true);
211
ui->colorSpace->setCurrentColorModel(KoID(cfg.readEntry("customColorSpaceModel", "RGBA")));
212
ui->colorSpace->setCurrentColorDepth(KoID(cfg.readEntry("customColorSpaceDepthID", "U8")));
213
ui->colorSpace->setCurrentProfile(cfg.readEntry("customColorSpaceProfile", KoColorSpaceRegistry::instance()->rgb8()->profile()->name()));
215
a = cfg.readEntry("popupOnMouseOver", false);
216
b = cfg.readEntry("popupOnMouseClick", true);
218
ui->popupOnMouseOver->setChecked(true);
220
ui->popupOnMouseClick->setChecked(true);
222
ui->neverZoom->setChecked(true);
224
ui->popupSize->setValue(cfg.readEntry("zoomSize", 280));
227
ui->lastUsedColorsShow->setChecked(cfg.readEntry("lastUsedColorsShow", true));
228
a = cfg.readEntry("lastUsedColorsAlignment", true);
229
ui->lastUsedColorsAlignVertical->setChecked(a);
230
ui->lastUsedColorsAlignHorizontal->setChecked(!a);
231
ui->lastUsedColorsAllowScrolling->setChecked(cfg.readEntry("lastUsedColorsScrolling", true));
232
ui->lastUsedColorsNumCols->setValue(cfg.readEntry("lastUsedColorsNumCols", 1));
233
ui->lastUsedColorsNumRows->setValue(cfg.readEntry("lastUsedColorsNumRows", 1));
234
ui->lastUsedColorsPatchCount->setValue(cfg.readEntry("lastUsedColorsCount", 20));
235
ui->lastUsedColorsWidth->setValue(cfg.readEntry("lastUsedColorsWidth", 16));
236
ui->lastUsedColorsHeight->setValue(cfg.readEntry("lastUsedColorsHeight", 16));
238
ui->commonColorsShow->setChecked(cfg.readEntry("commonColorsShow", true));
239
a = cfg.readEntry("commonColorsAlignment", false);
240
ui->commonColorsAlignVertical->setChecked(a);
241
ui->commonColorsAlignHorizontal->setChecked(!a);
242
ui->commonColorsAllowScrolling->setChecked(cfg.readEntry("commonColorsScrolling", false));
243
ui->commonColorsNumCols->setValue(cfg.readEntry("commonColorsNumCols", 1));
244
ui->commonColorsNumRows->setValue(cfg.readEntry("commonColorsNumRows", 1));
245
ui->commonColorsPatchCount->setValue(cfg.readEntry("commonColorsCount", 12));
246
ui->commonColorsWidth->setValue(cfg.readEntry("commonColorsWidth", 16));
247
ui->commonColorsHeight->setValue(cfg.readEntry("commonColorsHeight", 16));
248
ui->commonColorsAutoUpdate->setChecked(cfg.readEntry("commonColorsAutoUpdate", false));
251
QString shadeSelectorType=cfg.readEntry("shadeSelectorType", "Minimal");
252
ui->shadeSelectorTypeMyPaint->setChecked(shadeSelectorType=="MyPaint");
253
ui->shadeSelectorTypeMinimal->setChecked(shadeSelectorType=="Minimal");
254
ui->shadeSelectorTypeHidden->setChecked(shadeSelectorType=="Hidden");
256
ui->shadeSelectorUpdateOnRightClick->setChecked(cfg.readEntry("shadeSelectorUpdateOnRightClick", false));
257
ui->shadeSelectorUpdateOnLeftClick->setChecked(cfg.readEntry("shadeSelectorUpdateOnLeftClick", false));
258
ui->shadeSelectorUpdateOnForeground->setChecked(cfg.readEntry("shadeSelectorUpdateOnForeground", true));
259
ui->shadeSelectorUpdateOnBackground->setChecked(cfg.readEntry("shadeSelectorUpdateOnBackground", true));
261
bool asGradient = cfg.readEntry("minimalShadeSelectorAsGradient", true);
262
if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true);
263
else ui->minimalShadeSelectorAsColorPatches->setChecked(true);
265
ui->minimalShadeSelectorPatchesPerLine->setValue(cfg.readEntry("minimalShadeSelectorPatchCount", 10));
266
ui->minimalShadeSelectorLineSettings->fromString(cfg.readEntry("minimalShadeSelectorLineConfig", "0|0.2|0|0|0|0|0;1|0|1|1|0|0|0;2|0|-1|1|0|0|0;"));
267
ui->minimalShadeSelectorLineHeight->setValue(cfg.readEntry("minimalShadeSelectorLineHeight", 10));
270
KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
271
cstw->setConfiguration(KisColorSelector::Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", "3|0|5|0"))); // triangle selector
274
void KisColorSelectorSettings::loadDefaultPreferences()
277
//if you change something, don't forget that loadPreferences should be kept in sync
280
ui->allowHorizontalLayout->setChecked(false);
281
ui->shadeSelectorHideable->setChecked(false);
282
ui->shrunkenDoNothing->setChecked(true);
284
ui->popupOnMouseClick->setChecked(true);
285
ui->popupOnMouseOver->setChecked(false);
286
ui->neverZoom->setChecked(false);
287
ui->popupSize->setValue(280);
289
ui->useImageColorSpace->setChecked(true);
290
ui->colorSpace->setCurrentColorModel(KoID("RGBA"));
291
ui->colorSpace->setCurrentColorDepth(KoID("U8"));
292
ui->colorSpace->setCurrentProfile(KoColorSpaceRegistry::instance()->rgb8()->profile()->name());
295
ui->lastUsedColorsShow->setChecked(true);
296
ui->lastUsedColorsAlignVertical->setChecked(true);
297
ui->lastUsedColorsAlignHorizontal->setChecked(false);
298
ui->lastUsedColorsAllowScrolling->setChecked(true);
299
ui->lastUsedColorsNumCols->setValue(1);
300
ui->lastUsedColorsNumRows->setValue(1);
301
ui->lastUsedColorsPatchCount->setValue(20);
302
ui->lastUsedColorsWidth->setValue(16);
303
ui->lastUsedColorsHeight->setValue(16);
305
ui->commonColorsShow->setChecked(true);
306
ui->commonColorsAlignVertical->setChecked(false);
307
ui->commonColorsAlignHorizontal->setChecked(true);
308
ui->commonColorsAllowScrolling->setChecked(false);
309
ui->commonColorsNumCols->setValue(1);
310
ui->commonColorsNumRows->setValue(1);
311
ui->commonColorsPatchCount->setValue(12);
312
ui->commonColorsWidth->setValue(16);
313
ui->commonColorsHeight->setValue(16);
314
ui->commonColorsAutoUpdate->setChecked(false);
317
ui->shadeSelectorTypeMyPaint->setChecked(false);
318
ui->shadeSelectorTypeMinimal->setChecked(true);
319
ui->shadeSelectorTypeHidden->setChecked(false);
321
ui->shadeSelectorUpdateOnRightClick->setChecked(false);
322
ui->shadeSelectorUpdateOnLeftClick->setChecked(false);
323
ui->shadeSelectorUpdateOnForeground->setChecked(true);
324
ui->shadeSelectorUpdateOnBackground->setChecked(true);
326
bool asGradient = true;
327
if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true);
328
else ui->minimalShadeSelectorAsColorPatches->setChecked(true);
330
ui->minimalShadeSelectorPatchesPerLine->setValue(10);
331
ui->minimalShadeSelectorLineSettings->fromString("0|0.2|0|0|0|0|0;1|0|1|1|0|0|0;2|0|-1|1|0|0|0;");
332
ui->minimalShadeSelectorLineHeight->setValue(10);
335
KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
336
cstw->setConfiguration(KisColorSelector::Configuration("3|0|5|0")); // triangle selector
339
KisColorSelectorSettingsDialog::KisColorSelectorSettingsDialog(QWidget *parent) :
341
m_widget(new KisColorSelectorSettings(this))
343
QLayout* l = new QVBoxLayout(this);
344
l->addWidget(m_widget);
346
m_widget->loadPreferences();
348
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults,
351
l->addWidget(buttonBox);
353
connect(buttonBox, SIGNAL(accepted()), m_widget, SLOT(savePreferences()));
354
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
355
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
356
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults),
357
SIGNAL(clicked()), m_widget, SLOT(loadDefaultPreferences()));