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 cfg.writeEntry(
198 "sampleLayersMode",
200 ? "sampleAllLayers"
202 ? "sampleColorLabeledLayers"
203 : "sampleCurrentLayer"));
204}
205
207{
208 const QList<int> colorLabels = m_optionsWidget->selectedColorLabels();
209 if (colorLabels.isEmpty()) {
210 return;
211 }
212 QString colorLabelsStr = QString::number(colorLabels.first());
213 for (int i = 1; i < colorLabels.size(); ++i) {
214 colorLabelsStr += "," + QString::number(colorLabels[i]);
215 }
216
217 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
218 cfg.writeEntry("colorLabels", colorLabelsStr);
219}
220
226
232
238
244
250
252{
253 if (!isActivated || !m_optionsWidget) {
254 return;
255 }
256
257 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
258
260 (SelectionMode)cfg.readEntry("selectionMode",
261 static_cast<int>(SHAPE_PROTECTION));
263 (SelectionAction)cfg.readEntry("selectionAction",
264 static_cast<int>(SELECTION_REPLACE));
265
269
271}
272
274{
275 if (m_configGroupForTool == "") {
276 return;
277 }
278
279 KConfigGroup cfgToolSpecific =
280 KSharedConfig::openConfig()->group(m_configGroupForTool);
281 const bool moveSelectedContent =
282 cfgToolSpecific.readEntry("moveSelectedContent", false);
283 const bool antiAliasSelection =
284 cfgToolSpecific.readEntry("antiAliasSelection", true);
285 const int growSelection = cfgToolSpecific.readEntry("growSelection", 0);
286 const bool stopGrowingAtDarkestPixel =
287 cfgToolSpecific.readEntry("stopGrowingAtDarkestPixel", false);
288 const int featherSelection =
289 cfgToolSpecific.readEntry("featherSelection", 0);
290 const QString referenceLayersStr =
291 cfgToolSpecific.readEntry("sampleLayersMode", "sampleCurrentLayer");
292
293 const QStringList colorLabelsStr =
294 cfgToolSpecific.readEntry<QString>("colorLabels", "")
295 .split(',', Qt::SkipEmptyParts);
296
298 referenceLayersStr == "sampleAllLayers"
300 : (referenceLayersStr == "sampleColorLabeledLayers"
303 QList<int> colorLabels;
304 for (const QString &colorLabelStr : colorLabelsStr) {
305 bool ok;
306 const int colorLabel = colorLabelStr.toInt(&ok);
307 if (ok) {
308 colorLabels << colorLabel;
309 }
310 }
311
320}
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)