Krita Source Code Documentation
Loading...
Searching...
No Matches
WGColorSelectorSettings.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Mathias Wein <lynx.mw+kde@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
8#include "ui_WdgWGSelectorSettings.h"
9
12#include "WGColorSelectorDock.h"
13#include "WGShadeLineEditor.h"
14
15#include <QApplication>
16#include <QButtonGroup>
17#include <QVBoxLayout>
18#include <QScreen>
19#include <QDialogButtonBox>
20#include <QPushButton>
21#include <QToolButton>
22
24 : KisPreferenceSet(parent)
25 , m_ui(new Ui::WGConfigWidget)
26 , m_shadeLineGroup(new QButtonGroup(this))
27{
28 m_ui->setupUi(this);
31 m_ui->btnSelectorShape->setPopupWidget(m_selectorConfigGrid);
35 m_ui->btnSelectorShape, SLOT(hidePopupWidget()));
36 connect(m_ui->cmbColorModel, SIGNAL(currentIndexChanged(int)), SLOT(slotSetColorModel(int)));
37 connect(m_ui->sbShadeLineCount, SIGNAL(valueChanged(int)), SLOT(slotSetShadeLineCount(int)));
40 m_ui->btnFavoriteSelectors->setPopupWidget(m_favoriteConfigGrid);
41
43 m_shadeLineEditor->hide();
44 connect(m_shadeLineEditor, SIGNAL(sigEditorClosed(int)), SLOT(slotLineEdited(int)));
45
46 slotColorSpaceSourceChanged(m_ui->cmbSelectionColorSpace->currentIndex());
47 connect(m_ui->cmbSelectionColorSpace, SIGNAL(currentIndexChanged(int)), SLOT(slotColorSpaceSourceChanged(int)));
48
49 m_shadeLineGroup->setExclusive(false);
50 slotSetShadeLineCount(m_ui->sbShadeLineCount->value());
51 connect(m_shadeLineGroup, SIGNAL(idClicked(int)), SLOT(slotShowLineEditor(int)));
52}
53
57
59{
60 return stringID();
61}
62
64{
65 return QString(i18n("Wide Gamut Selector"));
66}
67
69{
70 return QString(i18n("Wide Gamut Color Selector Settings"));
71}
72
74{
75 return QIcon();
76}
77
79{
80 return QString("WideGamutColorSelector");
81}
82
84{
85 WGConfig::Accessor cfg(false);
87 static_cast<KisVisualColorSelector::RenderMode>(m_ui->cmbSelectorRenderingMode->currentIndex()));
89 m_ui->cmbColorModel->currentIndex() + KisVisualColorModel::HSV));
90 cfg.setColorSelectorConfiguration(m_selectorConfigGrid->currentConfiguration());
91 // General
92 cfg.set(WGConfig::quickSettingsEnabled, m_ui->grpQuickSettingsMenu->isChecked());
93 cfg.setFavoriteConfigurations(m_favoriteConfigGrid->selectedConfigurations());
95 static_cast<WGColorSelectorDock::ColorSpaceSource>(m_ui->cmbSelectionColorSpace->currentIndex()));
96 cfg.setCustomSelectionColorSpace(m_ui->wdgColorspace->currentColorSpace());
97 cfg.set(WGConfig::proofToPaintingColors, m_ui->chkProofColors->isChecked());
98 // Pop-ups
99 cfg.set(WGConfig::popupSize, m_ui->sbPopupSize->value());
100 cfg.set(WGConfig::popupPatches.orientation, m_ui->rbPopupHorizontal->isChecked() ? Qt::Horizontal : Qt::Vertical);
101 cfg.set(WGConfig::popupPatches.patchSize, QSize(m_ui->sbPatchWidth->value(), m_ui->sbPatchHeight->value()));
102 cfg.set(WGConfig::popupPatches.maxCount, m_ui->sbPopupMaxPatches->value());
103 cfg.set(WGConfig::popupPatches.rows, m_ui->sbPopupPatchesRows->value());
104 cfg.set(WGConfig::popupPatches.scrolling, static_cast<WGConfig::Scrolling>(m_ui->cbPopupScrolling->currentIndex()));
105 // Shade Selector
106 cfg.set(WGConfig::minimalShadeSelectorEnabled, m_ui->grpMinimalShadeSelector->isChecked());
107 cfg.set(WGConfig::shadeSelectorUpdateOnExternalChanges, m_ui->chkShadeSelUpdateExternal->isChecked());
108 cfg.set(WGConfig::shadeSelectorUpdateOnInteractionEnd, m_ui->chkShadeSelUpdateInteraction->isChecked());
109 cfg.set(WGConfig::shadeSelectorUpdateOnRightClick, m_ui->chkShadeSelUpdateOnRightClick->isChecked());
110 // we don't discard shade line configurations right away so we need to trim here
112 lineConfig.resize(m_ui->sbShadeLineCount->value());
113 cfg.setShadeSelectorLines(lineConfig);
114 cfg.set(WGConfig::shadeSelectorLineHeight, m_ui->sbShadeLineHeight->value());
115 // Color History
116 cfg.set(WGConfig::colorHistoryEnabled, m_ui->historyGroupBox->isChecked());
117 cfg.set(WGConfig::colorHistory.orientation, m_ui->rbHistoryHorizontal->isChecked() ? Qt::Horizontal : Qt::Vertical);
118 cfg.set(WGConfig::colorHistory.patchSize, { m_ui->sbHistoryPatchWidth->value(), m_ui->sbHistoryPatchHeight->value() });
119 cfg.set(WGConfig::colorHistory.maxCount, m_ui->sbHistoryMaxPatches->value());
120 cfg.set(WGConfig::colorHistory.rows, m_ui->sbHistoryRows->value());
121 cfg.set(WGConfig::colorHistory.scrolling, static_cast<WGConfig::Scrolling>(m_ui->cbScrolling->currentIndex()));
122 cfg.set(WGConfig::colorHistoryShowClearButton, m_ui->ckHistoryClearButton->isChecked());
123 // Common Colors (Colors from Image)
124 cfg.set(WGConfig::commonColorsEnabled, m_ui->commonColorsGroupBox->isChecked());
125 cfg.set(WGConfig::commonColors.orientation, m_ui->rbCommonColorsHorizontal->isChecked() ? Qt::Horizontal : Qt::Vertical);
126 cfg.set(WGConfig::commonColors.patchSize, { m_ui->sbCommonColorsPatchWidth->value(),
127 m_ui->sbCommonColorsPatchHeight->value() });
128 cfg.set(WGConfig::commonColors.maxCount, m_ui->sbCommonColorsPatches->value());
129 cfg.set(WGConfig::commonColors.rows, m_ui->sbCommonColorsRows->value());
130 cfg.set(WGConfig::commonColors.scrolling, static_cast<WGConfig::Scrolling>(m_ui->cbCommonColorsScrolling->currentIndex()));
131 cfg.set(WGConfig::commonColorsAutoUpdate, m_ui->ckCCAutoUpdate->isChecked());
132
135}
136
141
146
148{
150 m_ui->cmbSelectorRenderingMode->setCurrentIndex(cfg.get(WGConfig::selectorRenderMode, defaults));
151 m_ui->cmbColorModel->setCurrentIndex(cfg.get(WGConfig::rgbColorModel, defaults) - KisVisualColorModel::HSV);
152 KisColorSelectorConfiguration selectorCfg = defaults ? cfg.defaultColorSelectorConfiguration
153 : cfg.colorSelectorConfiguration();
154 m_selectorConfigGrid->setChecked(selectorCfg);
155 m_ui->btnSelectorShape->setIcon(m_selectorConfigGrid->generateIcon(selectorCfg, devicePixelRatioF()));
156 // General
157 m_ui->grpQuickSettingsMenu->setChecked(cfg.get(WGConfig::quickSettingsEnabled, defaults));
158 QVector<KisColorSelectorConfiguration> favoriteConfigs = cfg.favoriteConfigurations(defaults);
159 for (const KisColorSelectorConfiguration &fav : std::as_const(favoriteConfigs)) {
161 }
162 m_ui->cmbSelectionColorSpace->setCurrentIndex(cfg.get(WGConfig::colorSpaceSource, defaults));
163 m_ui->wdgColorspace->setCurrentColorSpace(cfg.customSelectionColorSpace(defaults));
164 m_ui->chkProofColors->setChecked(cfg.get(WGConfig::proofToPaintingColors, defaults));
165 // Pop-ups
166 m_ui->sbPopupSize->setValue(cfg.get(WGConfig::popupSize, defaults));
167 Qt::Orientation patchOrientation = cfg.get(WGConfig::popupPatches.orientation, defaults);
168 if (patchOrientation == Qt::Horizontal) {
169 m_ui->rbPopupHorizontal->setChecked(true);
170 } else {
171 m_ui->rbPopupVertical->setChecked(true);
172 }
173 QSize colorPatchSize = cfg.get(WGConfig::popupPatches.patchSize, defaults);
174 m_ui->sbPatchWidth->setValue(colorPatchSize.width());
175 m_ui->sbPatchHeight->setValue(colorPatchSize.height());
176 m_ui->sbPopupMaxPatches->setValue(cfg.get(WGConfig::popupPatches.maxCount, defaults));
177 m_ui->sbPopupPatchesRows->setValue(cfg.get(WGConfig::popupPatches.rows, defaults));
178 m_ui->cbPopupScrolling->setCurrentIndex(static_cast<int>(cfg.get(WGConfig::popupPatches.scrolling, defaults)));
179 // Shade Selector
180 m_ui->grpMinimalShadeSelector->setChecked(cfg.get(WGConfig::minimalShadeSelectorEnabled, defaults));
181 m_ui->chkShadeSelUpdateExternal->setChecked(cfg.get(WGConfig::shadeSelectorUpdateOnExternalChanges, defaults));
182 m_ui->chkShadeSelUpdateInteraction->setChecked(cfg.get(WGConfig::shadeSelectorUpdateOnInteractionEnd, defaults));
183 m_ui->chkShadeSelUpdateOnRightClick->setChecked(cfg.get(WGConfig::shadeSelectorUpdateOnRightClick, defaults));
184 m_shadeLineConfig = cfg.shadeSelectorLines(defaults);
185 // update shade lines we will re-use, the rest is handled by slotSetShadeLineCount()
186 for (int i = 0, end = qMin(m_shadeLineButtons.size(), m_shadeLineConfig.size()); i < end; i++) {
188 }
189 m_ui->sbShadeLineCount->setValue(m_shadeLineConfig.size());
190 m_ui->sbShadeLineHeight->setValue(cfg.get(WGConfig::shadeSelectorLineHeight, defaults));
191 // Color History
192 m_ui->historyGroupBox->setChecked(cfg.get(WGConfig::colorHistoryEnabled, defaults));
193 patchOrientation = cfg.get(WGConfig::colorHistory.orientation, defaults);
194 if (patchOrientation == Qt::Horizontal) {
195 m_ui->rbHistoryHorizontal->setChecked(true);
196 } else {
197 m_ui->rbHistoryVertical->setChecked(true);
198 }
199 colorPatchSize = cfg.get(WGConfig::colorHistory.patchSize, defaults);
200 m_ui->sbHistoryPatchWidth->setValue(colorPatchSize.width());
201 m_ui->sbHistoryPatchHeight->setValue(colorPatchSize.height());
202 m_ui->sbHistoryMaxPatches->setValue(cfg.get(WGConfig::colorHistory.maxCount));
203 m_ui->sbHistoryRows->setValue(cfg.get(WGConfig::colorHistory.rows, defaults));
204 m_ui->cbScrolling->setCurrentIndex(static_cast<int>(cfg.get(WGConfig::colorHistory.scrolling, defaults)));
205 m_ui->ckHistoryClearButton->setChecked(cfg.get(WGConfig::colorHistoryShowClearButton, defaults));
206 // Common Colors (Colors from Image)
207 m_ui->commonColorsGroupBox->setChecked(cfg.get(WGConfig::commonColorsEnabled, defaults));
208 patchOrientation = cfg.get(WGConfig::commonColors.orientation, defaults);
209 if (patchOrientation == Qt::Horizontal) {
210 m_ui->rbCommonColorsHorizontal->setChecked(true);
211 } else {
212 m_ui->rbCommonColorsVertical->setChecked(true);
213 }
214 colorPatchSize = cfg.get(WGConfig::commonColors.patchSize, defaults);
215 m_ui->sbCommonColorsPatchWidth->setValue(colorPatchSize.width());
216 m_ui->sbCommonColorsPatchHeight->setValue(colorPatchSize.height());
217 m_ui->sbCommonColorsPatches->setValue(cfg.get(WGConfig::commonColors.maxCount, defaults));
218 m_ui->sbCommonColorsRows->setValue(cfg.get(WGConfig::commonColors.rows, defaults));
219 m_ui->cbCommonColorsScrolling->setCurrentIndex(static_cast<int>(cfg.get(WGConfig::commonColors.scrolling, defaults)));
220 m_ui->ckCCAutoUpdate->setChecked(cfg.get(WGConfig::commonColorsAutoUpdate, defaults));
221}
222
224{
225 Q_UNUSED(cfg);
226 m_ui->btnSelectorShape->setIcon(m_selectorConfigGrid->currentIcon());
227}
228
230{
232 switch (index) {
233 case 0:
234 default:
236 break;
237 case 1:
239 break;
240 case 2:
242 break;
243 case 3:
245 }
247 m_ui->btnSelectorShape->setIcon(m_selectorConfigGrid->currentIcon());
248}
249
255
257{
258 if (m_shadeLineConfig.size() < count) {
259 m_shadeLineConfig.resize(count);
260 }
261 while (m_shadeLineButtons.size() < count) {
262 QToolButton *lineButton = new QToolButton(this);
263 lineButton->setIconSize(QSize(128, 10));
264 // TODO: update icon
265 lineButton->setIcon(m_shadeLineEditor->generateIcon(m_shadeLineConfig.at(m_shadeLineButtons.size())));
266 m_shadeLineGroup->addButton(lineButton, m_shadeLineButtons.size());
267 m_shadeLineButtons.append(lineButton);
268 m_ui->shadeLineLayout->addWidget(lineButton);
269 }
270 while (m_shadeLineButtons.size() > count)
271 {
272 m_ui->shadeLineLayout->removeWidget(m_shadeLineButtons.last());
273 delete m_shadeLineButtons.last();
274 m_shadeLineButtons.removeLast();
275 }
276}
277
279{
280 KIS_SAFE_ASSERT_RECOVER_RETURN(lineNum >= 0 && lineNum < m_shadeLineConfig.size());
281
283 m_shadeLineEditor->show();
284
285 QWidget *btn = m_shadeLineButtons.at(lineNum);
286 QRect fitRect = kisGrowRect(btn->screen()->availableGeometry(), -10);
287 QRect popupRect = m_shadeLineEditor->rect();
288 popupRect.moveTo(btn->mapToGlobal(QPoint()));
289 popupRect = kisEnsureInRect(popupRect, fitRect);
290 m_shadeLineEditor->move(popupRect.topLeft());
291}
292
294{
295 KIS_SAFE_ASSERT_RECOVER_RETURN(lineNum >= 0 && lineNum < m_shadeLineConfig.size());
296
299}
300
301
303 : QDialog(parent)
304 , m_widget(new WGColorSelectorSettings(this))
305{
306 QLayout* layout = new QVBoxLayout(this);
307 layout->addWidget(m_widget);
308
310
311 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults,
312 Qt::Horizontal,
313 this);
314 layout->addWidget(buttonBox);
315
316 connect(buttonBox, SIGNAL(accepted()), m_widget, SLOT(savePreferences()));
317 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
318 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
319 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults),
320 SIGNAL(clicked()), m_widget, SLOT(loadDefaultPreferences()));
321}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
WGColorSelectorSettings * m_widget
WGShadeLineEditor * m_shadeLineEditor
WGColorSelectorSettings(QWidget *parent=0)
void savePreferences() const override
WGSelectorConfigGrid * m_selectorConfigGrid
void loadPreferencesImpl(bool loadDefaults)
QVector< WGConfig::ShadeLine > m_shadeLineConfig
QScopedPointer< Ui::WGConfigWidget > m_ui
QVector< QToolButton * > m_shadeLineButtons
void slotSetSelectorConfiguration(const KisColorSelectorConfiguration &cfg)
WGSelectorConfigGrid * m_favoriteConfigGrid
QVector< KisColorSelectorConfiguration > selectedConfigurations() const
KisColorSelectorConfiguration currentConfiguration() const
void setConfigurations(const QVector< KisColorSelectorConfiguration > &configurations)
QIcon generateIcon(const KisColorSelectorConfiguration &configuration, qreal pixelRatio=1.0, bool dualState=false) const
void setColorModel(KisVisualColorModel::ColorModel model)
static QVector< KisColorSelectorConfiguration > hueBasedConfigurations()
void setChecked(const KisColorSelectorConfiguration &configuration)
QIcon generateIcon(const WGConfig::ShadeLine &cfg)
void setConfiguration(const WGConfig::ShadeLine &cfg, int lineIndex)
WGConfig::ShadeLine configuration() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
Definition kis_global.h:267
const GenericSetting< bool > colorHistoryEnabled
Definition WGConfig.cpp:238
const ColorPatches commonColors
Definition WGConfig.cpp:221
const GenericSetting< bool > minimalShadeSelectorEnabled
Definition WGConfig.cpp:246
const GenericSetting< bool > commonColorsEnabled
Definition WGConfig.cpp:239
const NumericSetting< KisVisualColorSelector::RenderMode > selectorRenderMode
Definition WGConfig.cpp:255
const ColorPatches popupPatches
Definition WGConfig.cpp:229
const NumericSetting< WGColorSelectorDock::ColorSpaceSource > colorSpaceSource
WGConfigNotifier * notifier()
Definition WGConfig.cpp:190
const GenericSetting< bool > colorHistoryShowClearButton
Definition WGConfig.cpp:240
const NumericSetting< KisVisualColorModel::ColorModel > rgbColorModel
Definition WGConfig.cpp:252
const NumericSetting< int > shadeSelectorLineHeight
Definition WGConfig.cpp:247
class WGConfig Accessor
const GenericSetting< bool > proofToPaintingColors
Definition WGConfig.cpp:237
const NumericSetting< int > popupSize
Definition WGConfig.cpp:244
const GenericSetting< bool > shadeSelectorUpdateOnExternalChanges
Definition WGConfig.cpp:248
const GenericSetting< bool > quickSettingsEnabled
Definition WGConfig.cpp:243
const GenericSetting< bool > commonColorsAutoUpdate
Definition WGConfig.cpp:241
const GenericSetting< bool > shadeSelectorUpdateOnInteractionEnd
Definition WGConfig.cpp:249
const ColorPatches colorHistory
Definition WGConfig.cpp:213
const GenericSetting< bool > shadeSelectorUpdateOnRightClick
Definition WGConfig.cpp:250
NumericSetting< Scrolling > scrolling
Definition WGConfig.h:200
NumericSetting< int > rows
Definition WGConfig.h:199
NumericSetting< int > maxCount
Definition WGConfig.h:198