Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_selection_tool_config_widget_helper.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
10#include <kis_signals_blocker.h>
11
12#include <KConfigGroup>
13#include <KSharedConfig>
14
16 const QString &windowTitle)
17 : m_optionsWidget(0)
18 , m_windowTitle(windowTitle)
19{
20}
21
23 const QString &toolId)
24{
26 Q_CHECK_PTR(m_optionsWidget);
27
28 m_optionsWidget->setObjectName(toolId + "option widget");
30
33 connect(m_optionsWidget,
35 this,
37 connect(m_optionsWidget,
39 this,
43 connect(m_optionsWidget,
45 this,
47 connect(m_optionsWidget,
49 this,
51 connect(m_optionsWidget,
53 this,
55 connect(m_optionsWidget,
57 this,
61}
62
67
75
83
91
93{
94 if (!m_optionsWidget) {
95 return true;
96 }
98}
99
101{
102 if (!m_optionsWidget) {
103 return 0;
104 }
106}
107
115
117{
118 if (!m_optionsWidget) {
119 return 0;
120 }
122}
123
132
140
147
149 SelectionMode mode)
150{
151 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
152 cfg.writeEntry("selectionMode", static_cast<int>(mode));
153}
154
156 SelectionAction action)
157{
158 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
159 cfg.writeEntry("selectionAction", static_cast<int>(action));
161}
162
164{
165 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
166 cfg.writeEntry("moveSelectedContent", value);
167}
168
170{
171 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
172 cfg.writeEntry("antiAliasSelection", value);
173}
174
176{
177 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
178 cfg.writeEntry("growSelection", value);
179}
180
182{
183 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
184 cfg.writeEntry("stopGrowingAtDarkestPixel", value);
185}
186
188{
189 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
190 cfg.writeEntry("featherSelection", value);
191}
192
195{
196 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
197
198 QString sampleModeString = "sampleCurrentLayer";
199
200 switch (referenceLayers) {
202 sampleModeString = "sampleAllLayers";
203 break;
205 sampleModeString = "sampleCurrentGroup";
206 break;
208 sampleModeString = "sampleColorLabeledLayers";
209 break;
211 // noop, initialized above
212 break;
213 }
214
215 cfg.writeEntry("sampleLayersMode", sampleModeString);
216}
217
219{
220 const QList<int> colorLabels = m_optionsWidget->selectedColorLabels();
221 if (colorLabels.isEmpty()) {
222 return;
223 }
224 QString colorLabelsStr = QString::number(colorLabels.first());
225 for (int i = 1; i < colorLabels.size(); ++i) {
226 colorLabelsStr += "," + QString::number(colorLabels[i]);
227 }
228
229 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
230 cfg.writeEntry("colorLabels", colorLabelsStr);
231}
232
238
244
250
256
262
264{
265 if (!isActivated || !m_optionsWidget) {
266 return;
267 }
268
269 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
270
272 (SelectionMode)cfg.readEntry("selectionMode",
273 static_cast<int>(SHAPE_PROTECTION));
275 (SelectionAction)cfg.readEntry("selectionAction",
276 static_cast<int>(SELECTION_REPLACE));
277
281
283}
284
286{
287 if (m_configGroupForTool == "") {
288 return;
289 }
290
291 KConfigGroup cfgToolSpecific =
292 KSharedConfig::openConfig()->group(m_configGroupForTool);
293 const bool moveSelectedContent =
294 cfgToolSpecific.readEntry("moveSelectedContent", false);
295 const bool antiAliasSelection =
296 cfgToolSpecific.readEntry("antiAliasSelection", true);
297 const int growSelection = cfgToolSpecific.readEntry("growSelection", 0);
298 const bool stopGrowingAtDarkestPixel =
299 cfgToolSpecific.readEntry("stopGrowingAtDarkestPixel", false);
300 const int featherSelection =
301 cfgToolSpecific.readEntry("featherSelection", 0);
302 const QString referenceLayersStr =
303 cfgToolSpecific.readEntry("sampleLayersMode", "sampleCurrentLayer");
304
305 const QStringList colorLabelsStr =
306 cfgToolSpecific.readEntry<QString>("colorLabels", "")
307 .split(',', Qt::SkipEmptyParts);
308
310
311 if (referenceLayersStr == "sampleAllLayers") {
313 } else if (referenceLayersStr == "sampleCurrentGroup") {
315 } else if (referenceLayersStr == "sampleCurrentLayer") {
317 } else if (referenceLayersStr == "sampleColorLabeledLayers") {
319 } else {
320 qWarning() << "KisSelectionToolConfigWidgetHelper::reloadExactToolConfig(): unknown reference layer mode string" << referenceLayersStr;
322 }
323
324 QList<int> colorLabels;
325 for (const QString &colorLabelStr : colorLabelsStr) {
326 bool ok;
327 const int colorLabel = colorLabelStr.toInt(&ok);
328 if (ok) {
329 colorLabels << colorLabel;
330 }
331 }
332
341}
float value(const T *src, size_t ch)
SelectionMode
@ SHAPE_PROTECTION
SelectionAction
@ SELECTION_REPLACE
@ SELECTION_INTERSECT
@ SELECTION_SYMMETRICDIFFERENCE
@ SELECTION_DEFAULT
@ SELECTION_SUBTRACT
@ SELECTION_ADD
void setMode(SelectionMode newMode)
void setGrowSelection(int newGrowSelection)
void setAntiAliasSelection(bool newAntiAliasSelection)
void actionChanged(SelectionAction action)
void antiAliasSelectionChanged(bool antiAliasSelection)
void setAction(SelectionAction newAction)
void setMoveSelectedContent(bool newMoveSelectedContent)
SelectionMode mode() const
void setSelectedColorLabels(const QList< int > &newSelectedColorLabels)
void featherSelectionChanged(int featherSelection)
void setReferenceLayers(ReferenceLayers newReferenceLayers)
void selectedColorLabelsChanged()
void setFeatherSelection(int newFeatherSelection)
QList< int > selectedColorLabels() const
ReferenceLayers referenceLayers() const
void referenceLayersChanged(ReferenceLayers referenceLayers)
void stopGrowingAtDarkestPixelChanged(bool stopGrowingAtDarkestPixel)
void growSelectionChanged(int growSelection)
void setStopGrowingAtDarkestPixel(bool newStopGrowingAtDarkestPixel)
SelectionAction action() const
void modeChanged(SelectionMode mode)
void moveSelectedContentChanged(bool moveSelectedContent)
void selectionActionChanged(SelectionAction newAction)
KisSelectionOptions::ReferenceLayers referenceLayers() const
void slotReferenceLayersChanged(KisSelectionOptions::ReferenceLayers referenceLayers)