~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/plugins/extensions/dockers/colorselectorng/kis_color_selector_settings.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2010 Celarek Adam <kdedev at xibo dot at>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "kis_color_selector_settings.h"
 
20
#include "ui_wdg_color_selector_settings.h"
 
21
 
 
22
#include <QVBoxLayout>
 
23
#include <QDialogButtonBox>
 
24
#include <QPushButton>
 
25
 
 
26
#include <KConfigGroup>
 
27
#include <KIcon>
 
28
 
 
29
#include "KoColorSpace.h"
 
30
#include "KoColorSpaceRegistry.h"
 
31
#include "KoColorProfile.h"
 
32
 
 
33
#include "kis_color_selector_combo_box.h"
 
34
#include "kis_color_selector.h"
 
35
 
 
36
 
 
37
#include <KDebug>
 
38
 
 
39
KisColorSelectorSettings::KisColorSelectorSettings(QWidget *parent) :
 
40
    KisPreferenceSet(parent),
 
41
    ui(new Ui::KisColorSelectorSettings)
 
42
{
 
43
    ui->setupUi(this);
 
44
    ui->lbl_lastUsedNumRows->hide();
 
45
    ui->lastUsedColorsNumRows->hide();
 
46
 
 
47
    ui->lbl_commonColorsNumCols->hide();
 
48
    ui->commonColorsNumCols->hide();
 
49
    resize(minimumSize());
 
50
 
 
51
    ui->colorSelectorConfiguration->setColorSpace(ui->colorSpace->currentColorSpace());
 
52
 
 
53
    connect(ui->colorSpace,                 SIGNAL(colorSpaceChanged(const KoColorSpace*)),
 
54
            ui->colorSelectorConfiguration, SLOT(setColorSpace(const KoColorSpace*)));
 
55
 
 
56
    connect(ui->minimalShadeSelectorLineCount,      SIGNAL(valueChanged(int)),
 
57
            ui->minimalShadeSelectorLineSettings,   SLOT(setLineCount(int)));
 
58
 
 
59
    connect(ui->minimalShadeSelectorLineSettings,   SIGNAL(lineCountChanged(int)),
 
60
            ui->minimalShadeSelectorLineCount,      SLOT(setValue(int)));
 
61
 
 
62
    connect(ui->minimalShadeSelectorAsGradient,     SIGNAL(toggled(bool)),
 
63
            ui->minimalShadeSelectorLineSettings,   SIGNAL(setGradient(bool)));
 
64
 
 
65
    connect(ui->minimalShadeSelectorAsColorPatches, SIGNAL(toggled(bool)),
 
66
            ui->minimalShadeSelectorLineSettings,   SIGNAL(setPatches(bool)));
 
67
 
 
68
    connect(ui->minimalShadeSelectorLineHeight,     SIGNAL(valueChanged(int)),
 
69
            ui->minimalShadeSelectorLineSettings,   SIGNAL(setLineHeight(int)));
 
70
 
 
71
    connect(ui->minimalShadeSelectorPatchesPerLine, SIGNAL(valueChanged(int)),
 
72
            ui->minimalShadeSelectorLineSettings,   SIGNAL(setPatchCount(int)));
 
73
 
 
74
 
 
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
 
78
    loadPreferences();
 
79
    savePreferences();
 
80
}
 
81
 
 
82
KisColorSelectorSettings::~KisColorSelectorSettings()
 
83
{
 
84
    delete ui;
 
85
}
 
86
 
 
87
QString KisColorSelectorSettings::id()
 
88
{
 
89
    return QString("advancedColorSelector");
 
90
}
 
91
 
 
92
QString KisColorSelectorSettings::name()
 
93
{
 
94
    return header();
 
95
}
 
96
 
 
97
QString KisColorSelectorSettings::header()
 
98
{
 
99
    return QString("Color Selector Settings");
 
100
}
 
101
 
 
102
 
 
103
KIcon KisColorSelectorSettings::icon()
 
104
{
 
105
    return KIcon("extended_color_selector");
 
106
}
 
107
 
 
108
 
 
109
void KisColorSelectorSettings::savePreferences() const
 
110
{
 
111
    //write cfg
 
112
    KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
 
113
 
 
114
    //general
 
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());
 
120
 
 
121
    cfg.writeEntry("useCustomColorSpace", ui->useCustomColorSpace->isChecked());
 
122
    const KoColorSpace* colorSpace = ui->colorSpace->currentColorSpace();
 
123
    if(colorSpace) {
 
124
        cfg.writeEntry("customColorSpaceModel", colorSpace->colorModelId().id());
 
125
        cfg.writeEntry("customColorSpaceDepthID", colorSpace->colorDepthId().id());
 
126
        cfg.writeEntry("customColorSpaceProfile", colorSpace->profile()->name());
 
127
    }
 
128
 
 
129
    //color patches
 
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());
 
138
 
 
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());
 
148
 
 
149
    //shade selector
 
150
    QString shadeSelectorType("MyPaint");
 
151
    if(ui->shadeSelectorTypeMinimal->isChecked())
 
152
        shadeSelectorType="Minimal";
 
153
    if(ui->shadeSelectorTypeHidden->isChecked())
 
154
        shadeSelectorType="Hidden";
 
155
 
 
156
    cfg.writeEntry("shadeSelectorType", shadeSelectorType);
 
157
 
 
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());
 
162
 
 
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());
 
167
 
 
168
    //color selector
 
169
    KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
 
170
    cfg.writeEntry("colorSelectorConfiguration", cstw->configuration().toString());
 
171
 
 
172
    emit settingsChanged();
 
173
}
 
174
 
 
175
//void KisColorSelectorSettings::changeEvent(QEvent *e)
 
176
//{
 
177
//    QDialog::changeEvent(e);
 
178
//    switch (e->type()) {
 
179
//    case QEvent::LanguageChange:
 
180
//        ui->retranslateUi(this);
 
181
//        break;
 
182
//    default:
 
183
//        break;
 
184
//    }
 
185
//}
 
186
 
 
187
void KisColorSelectorSettings::loadPreferences()
 
188
{
 
189
    //read cfg
 
190
    //don't forget to also add a new entry to the default preferences
 
191
 
 
192
    KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
 
193
 
 
194
    //general
 
195
 
 
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);
 
199
    if(a)
 
200
        ui->shadeSelectorHideable->setChecked(true);
 
201
    else if(b)
 
202
        ui->allowHorizontalLayout->setChecked(true);
 
203
    else
 
204
        ui->shrunkenDoNothing->setChecked(true);
 
205
 
 
206
    if(cfg.readEntry("useCustomColorSpace", false))
 
207
        ui->useCustomColorSpace->setChecked(true);
 
208
    else
 
209
        ui->useImageColorSpace->setChecked(true);
 
210
 
 
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()));
 
214
 
 
215
    a = cfg.readEntry("popupOnMouseOver", false);
 
216
    b = cfg.readEntry("popupOnMouseClick", true);
 
217
    if(a)
 
218
        ui->popupOnMouseOver->setChecked(true);
 
219
    else if(b)
 
220
        ui->popupOnMouseClick->setChecked(true);
 
221
    else
 
222
        ui->neverZoom->setChecked(true);
 
223
 
 
224
    ui->popupSize->setValue(cfg.readEntry("zoomSize", 280));
 
225
 
 
226
    //color patches
 
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));
 
237
 
 
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));
 
249
 
 
250
    //shade selector
 
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");
 
255
 
 
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));
 
260
 
 
261
    bool asGradient = cfg.readEntry("minimalShadeSelectorAsGradient", true);
 
262
    if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true);
 
263
    else ui->minimalShadeSelectorAsColorPatches->setChecked(true);
 
264
 
 
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));
 
268
 
 
269
    //color selector
 
270
    KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
 
271
    cstw->setConfiguration(KisColorSelector::Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", "3|0|5|0"))); // triangle selector
 
272
}
 
273
 
 
274
void KisColorSelectorSettings::loadDefaultPreferences()
 
275
{
 
276
    //set defaults
 
277
    //if you change something, don't forget that loadPreferences should be kept in sync
 
278
 
 
279
    //general
 
280
    ui->allowHorizontalLayout->setChecked(false);
 
281
    ui->shadeSelectorHideable->setChecked(false);
 
282
    ui->shrunkenDoNothing->setChecked(true);
 
283
 
 
284
    ui->popupOnMouseClick->setChecked(true);
 
285
    ui->popupOnMouseOver->setChecked(false);
 
286
    ui->neverZoom->setChecked(false);
 
287
    ui->popupSize->setValue(280);
 
288
 
 
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());
 
293
 
 
294
    //color patches
 
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);
 
304
 
 
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);
 
315
 
 
316
    //shade selector
 
317
    ui->shadeSelectorTypeMyPaint->setChecked(false);
 
318
    ui->shadeSelectorTypeMinimal->setChecked(true);
 
319
    ui->shadeSelectorTypeHidden->setChecked(false);
 
320
 
 
321
    ui->shadeSelectorUpdateOnRightClick->setChecked(false);
 
322
    ui->shadeSelectorUpdateOnLeftClick->setChecked(false);
 
323
    ui->shadeSelectorUpdateOnForeground->setChecked(true);
 
324
    ui->shadeSelectorUpdateOnBackground->setChecked(true);
 
325
 
 
326
    bool asGradient = true;
 
327
    if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true);
 
328
    else ui->minimalShadeSelectorAsColorPatches->setChecked(true);
 
329
 
 
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);
 
333
 
 
334
    //color selector
 
335
    KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
 
336
    cstw->setConfiguration(KisColorSelector::Configuration("3|0|5|0")); // triangle selector
 
337
}
 
338
 
 
339
KisColorSelectorSettingsDialog::KisColorSelectorSettingsDialog(QWidget *parent) :
 
340
        QDialog(parent),
 
341
        m_widget(new KisColorSelectorSettings(this))
 
342
{
 
343
    QLayout* l = new QVBoxLayout(this);
 
344
    l->addWidget(m_widget);
 
345
 
 
346
    m_widget->loadPreferences();
 
347
 
 
348
    QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults,
 
349
                                                       Qt::Horizontal,
 
350
                                                       this);
 
351
    l->addWidget(buttonBox);
 
352
 
 
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()));
 
358
}
 
359