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);
32 connect(m_selectorConfigGrid, SIGNAL(sigConfigSelected(KisColorSelectorConfiguration)),
34 connect(m_selectorConfigGrid, SIGNAL(sigConfigSelected(KisColorSelectorConfiguration)),
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::colorHistoryFromDocument, m_ui->chkColorHistoryDocument->isChecked());
117 cfg.set(WGConfig::colorHistoryEnabled, m_ui->historyGroupBox->isChecked());
118 cfg.set(WGConfig::colorHistory.orientation, m_ui->rbHistoryHorizontal->isChecked() ? Qt::Horizontal : Qt::Vertical);
119 cfg.set(WGConfig::colorHistory.patchSize, { m_ui->sbHistoryPatchWidth->value(), m_ui->sbHistoryPatchHeight->value() });
120 cfg.set(WGConfig::colorHistory.maxCount, m_ui->sbHistoryMaxPatches->value());
121 cfg.set(WGConfig::colorHistory.rows, m_ui->sbHistoryRows->value());
122 cfg.set(WGConfig::colorHistory.scrolling, static_cast<WGConfig::Scrolling>(m_ui->cbScrolling->currentIndex()));
123 cfg.set(WGConfig::colorHistoryShowClearButton, m_ui->ckHistoryClearButton->isChecked());
124 // Common Colors (Colors from Image)
125 cfg.set(WGConfig::commonColorsEnabled, m_ui->commonColorsGroupBox->isChecked());
126 cfg.set(WGConfig::commonColors.orientation, m_ui->rbCommonColorsHorizontal->isChecked() ? Qt::Horizontal : Qt::Vertical);
127 cfg.set(WGConfig::commonColors.patchSize, { m_ui->sbCommonColorsPatchWidth->value(),
128 m_ui->sbCommonColorsPatchHeight->value() });
129 cfg.set(WGConfig::commonColors.maxCount, m_ui->sbCommonColorsPatches->value());
130 cfg.set(WGConfig::commonColors.rows, m_ui->sbCommonColorsRows->value());
131 cfg.set(WGConfig::commonColors.scrolling, static_cast<WGConfig::Scrolling>(m_ui->cbCommonColorsScrolling->currentIndex()));
132 cfg.set(WGConfig::commonColorsAutoUpdate, m_ui->ckCCAutoUpdate->isChecked());
133
136}
137
142
147
149{
151 m_ui->cmbSelectorRenderingMode->setCurrentIndex(cfg.get(WGConfig::selectorRenderMode, defaults));
152 m_ui->cmbColorModel->setCurrentIndex(cfg.get(WGConfig::rgbColorModel, defaults) - KisVisualColorModel::HSV);
153 KisColorSelectorConfiguration selectorCfg = defaults ? cfg.defaultColorSelectorConfiguration
154 : cfg.colorSelectorConfiguration();
155 m_selectorConfigGrid->setChecked(selectorCfg);
156 m_ui->btnSelectorShape->setIcon(m_selectorConfigGrid->generateIcon(selectorCfg, devicePixelRatioF()));
157 // General
158 m_ui->grpQuickSettingsMenu->setChecked(cfg.get(WGConfig::quickSettingsEnabled, defaults));
159 QVector<KisColorSelectorConfiguration> favoriteConfigs = cfg.favoriteConfigurations(defaults);
160 for (const KisColorSelectorConfiguration &fav : std::as_const(favoriteConfigs)) {
162 }
163 m_ui->cmbSelectionColorSpace->setCurrentIndex(cfg.get(WGConfig::colorSpaceSource, defaults));
164 m_ui->wdgColorspace->setCurrentColorSpace(cfg.customSelectionColorSpace(defaults));
165 m_ui->chkProofColors->setChecked(cfg.get(WGConfig::proofToPaintingColors, defaults));
166 // Pop-ups
167 m_ui->sbPopupSize->setValue(cfg.get(WGConfig::popupSize, defaults));
168 Qt::Orientation patchOrientation = cfg.get(WGConfig::popupPatches.orientation, defaults);
169 if (patchOrientation == Qt::Horizontal) {
170 m_ui->rbPopupHorizontal->setChecked(true);
171 } else {
172 m_ui->rbPopupVertical->setChecked(true);
173 }
174 QSize colorPatchSize = cfg.get(WGConfig::popupPatches.patchSize, defaults);
175 m_ui->sbPatchWidth->setValue(colorPatchSize.width());
176 m_ui->sbPatchHeight->setValue(colorPatchSize.height());
177 m_ui->sbPopupMaxPatches->setValue(cfg.get(WGConfig::popupPatches.maxCount, defaults));
178 m_ui->sbPopupPatchesRows->setValue(cfg.get(WGConfig::popupPatches.rows, defaults));
179 m_ui->cbPopupScrolling->setCurrentIndex(static_cast<int>(cfg.get(WGConfig::popupPatches.scrolling, defaults)));
180 // Shade Selector
181 m_ui->grpMinimalShadeSelector->setChecked(cfg.get(WGConfig::minimalShadeSelectorEnabled, defaults));
182 m_ui->chkShadeSelUpdateExternal->setChecked(cfg.get(WGConfig::shadeSelectorUpdateOnExternalChanges, defaults));
183 m_ui->chkShadeSelUpdateInteraction->setChecked(cfg.get(WGConfig::shadeSelectorUpdateOnInteractionEnd, defaults));
184 m_ui->chkShadeSelUpdateOnRightClick->setChecked(cfg.get(WGConfig::shadeSelectorUpdateOnRightClick, defaults));
185 m_shadeLineConfig = cfg.shadeSelectorLines(defaults);
186 // update shade lines we will re-use, the rest is handled by slotSetShadeLineCount()
187 for (int i = 0, end = qMin(m_shadeLineButtons.size(), m_shadeLineConfig.size()); i < end; i++) {
189 }
190 m_ui->sbShadeLineCount->setValue(m_shadeLineConfig.size());
191 m_ui->sbShadeLineHeight->setValue(cfg.get(WGConfig::shadeSelectorLineHeight, defaults));
192 // Color History
193 m_ui->chkColorHistoryDocument->setChecked(cfg.get(WGConfig::colorHistoryFromDocument, defaults));
194 m_ui->historyGroupBox->setChecked(cfg.get(WGConfig::colorHistoryEnabled, defaults));
195 patchOrientation = cfg.get(WGConfig::colorHistory.orientation, defaults);
196 if (patchOrientation == Qt::Horizontal) {
197 m_ui->rbHistoryHorizontal->setChecked(true);
198 } else {
199 m_ui->rbHistoryVertical->setChecked(true);
200 }
201 colorPatchSize = cfg.get(WGConfig::colorHistory.patchSize, defaults);
202 m_ui->sbHistoryPatchWidth->setValue(colorPatchSize.width());
203 m_ui->sbHistoryPatchHeight->setValue(colorPatchSize.height());
204 m_ui->sbHistoryMaxPatches->setValue(cfg.get(WGConfig::colorHistory.maxCount));
205 m_ui->sbHistoryRows->setValue(cfg.get(WGConfig::colorHistory.rows, defaults));
206 m_ui->cbScrolling->setCurrentIndex(static_cast<int>(cfg.get(WGConfig::colorHistory.scrolling, defaults)));
207 m_ui->ckHistoryClearButton->setChecked(cfg.get(WGConfig::colorHistoryShowClearButton, defaults));
208 // Common Colors (Colors from Image)
209 m_ui->commonColorsGroupBox->setChecked(cfg.get(WGConfig::commonColorsEnabled, defaults));
210 patchOrientation = cfg.get(WGConfig::commonColors.orientation, defaults);
211 if (patchOrientation == Qt::Horizontal) {
212 m_ui->rbCommonColorsHorizontal->setChecked(true);
213 } else {
214 m_ui->rbCommonColorsVertical->setChecked(true);
215 }
216 colorPatchSize = cfg.get(WGConfig::commonColors.patchSize, defaults);
217 m_ui->sbCommonColorsPatchWidth->setValue(colorPatchSize.width());
218 m_ui->sbCommonColorsPatchHeight->setValue(colorPatchSize.height());
219 m_ui->sbCommonColorsPatches->setValue(cfg.get(WGConfig::commonColors.maxCount, defaults));
220 m_ui->sbCommonColorsRows->setValue(cfg.get(WGConfig::commonColors.rows, defaults));
221 m_ui->cbCommonColorsScrolling->setCurrentIndex(static_cast<int>(cfg.get(WGConfig::commonColors.scrolling, defaults)));
222 m_ui->ckCCAutoUpdate->setChecked(cfg.get(WGConfig::commonColorsAutoUpdate, defaults));
223}
224
226{
227 Q_UNUSED(cfg);
228 m_ui->btnSelectorShape->setIcon(m_selectorConfigGrid->currentIcon());
229}
230
232{
234 switch (index) {
235 case 0:
236 default:
238 break;
239 case 1:
241 break;
242 case 2:
244 break;
245 case 3:
247 }
249 m_ui->btnSelectorShape->setIcon(m_selectorConfigGrid->currentIcon());
250}
251
257
259{
260 if (m_shadeLineConfig.size() < count) {
261 m_shadeLineConfig.resize(count);
262 }
263 while (m_shadeLineButtons.size() < count) {
264 QToolButton *lineButton = new QToolButton(this);
265 lineButton->setIconSize(QSize(128, 10));
266 // TODO: update icon
267 lineButton->setIcon(m_shadeLineEditor->generateIcon(m_shadeLineConfig.at(m_shadeLineButtons.size())));
268 m_shadeLineGroup->addButton(lineButton, m_shadeLineButtons.size());
269 m_shadeLineButtons.append(lineButton);
270 m_ui->shadeLineLayout->addWidget(lineButton);
271 }
272 while (m_shadeLineButtons.size() > count)
273 {
274 m_ui->shadeLineLayout->removeWidget(m_shadeLineButtons.last());
275 delete m_shadeLineButtons.last();
276 m_shadeLineButtons.removeLast();
277 }
278}
279
281{
282 KIS_SAFE_ASSERT_RECOVER_RETURN(lineNum >= 0 && lineNum < m_shadeLineConfig.size());
283
285 m_shadeLineEditor->show();
286
287 QWidget *btn = m_shadeLineButtons.at(lineNum);
288 QRect fitRect = kisGrowRect(btn->screen()->availableGeometry(), -10);
289 QRect popupRect = m_shadeLineEditor->rect();
290 popupRect.moveTo(btn->mapToGlobal(QPoint()));
291 popupRect = kisEnsureInRect(popupRect, fitRect);
292 m_shadeLineEditor->move(popupRect.topLeft());
293}
294
296{
297 KIS_SAFE_ASSERT_RECOVER_RETURN(lineNum >= 0 && lineNum < m_shadeLineConfig.size());
298
301}
302
303
305 : QDialog(parent)
306 , m_widget(new WGColorSelectorSettings(this))
307{
308 QLayout* layout = new QVBoxLayout(this);
309 layout->addWidget(m_widget);
310
312
313 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults,
314 Qt::Horizontal,
315 this);
316 layout->addWidget(buttonBox);
317
318 connect(buttonBox, SIGNAL(accepted()), m_widget, SLOT(savePreferences()));
319 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
320 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
321 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults),
322 SIGNAL(clicked()), m_widget, SLOT(loadDefaultPreferences()));
323}
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:291
const GenericSetting< bool > colorHistoryEnabled
Definition WGConfig.cpp:238
const ColorPatches commonColors
Definition WGConfig.cpp:221
const GenericSetting< bool > colorHistoryFromDocument
Definition WGConfig.cpp:239
const GenericSetting< bool > minimalShadeSelectorEnabled
Definition WGConfig.cpp:247
const GenericSetting< bool > commonColorsEnabled
Definition WGConfig.cpp:240
const NumericSetting< KisVisualColorSelector::RenderMode > selectorRenderMode
Definition WGConfig.cpp:256
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:241
const NumericSetting< KisVisualColorModel::ColorModel > rgbColorModel
Definition WGConfig.cpp:253
const NumericSetting< int > shadeSelectorLineHeight
Definition WGConfig.cpp:248
class WGConfig Accessor
const GenericSetting< bool > proofToPaintingColors
Definition WGConfig.cpp:237
const NumericSetting< int > popupSize
Definition WGConfig.cpp:245
const GenericSetting< bool > shadeSelectorUpdateOnExternalChanges
Definition WGConfig.cpp:249
const GenericSetting< bool > quickSettingsEnabled
Definition WGConfig.cpp:244
const GenericSetting< bool > commonColorsAutoUpdate
Definition WGConfig.cpp:242
const GenericSetting< bool > shadeSelectorUpdateOnInteractionEnd
Definition WGConfig.cpp:250
const ColorPatches colorHistory
Definition WGConfig.cpp:213
const GenericSetting< bool > shadeSelectorUpdateOnRightClick
Definition WGConfig.cpp:251
NumericSetting< Scrolling > scrolling
Definition WGConfig.h:200
NumericSetting< int > rows
Definition WGConfig.h:199
NumericSetting< int > maxCount
Definition WGConfig.h:198