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
35 this,
41 this,
45 this,
49 this,
53 this,
57}
58
63
71
79
81{
82 if (!m_optionsWidget) {
83 return true;
84 }
86}
87
89{
90 if (!m_optionsWidget) {
91 return 0;
92 }
94}
95
103
105{
106 if (!m_optionsWidget) {
107 return 0;
108 }
110}
111
120
128
135
137 SelectionMode mode)
138{
139 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
140 cfg.writeEntry("selectionMode", static_cast<int>(mode));
141}
142
144 SelectionAction action)
145{
146 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
147 cfg.writeEntry("selectionAction", static_cast<int>(action));
149}
150
152{
153 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
154 cfg.writeEntry("antiAliasSelection", value);
155}
156
158{
159 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
160 cfg.writeEntry("growSelection", value);
161}
162
164{
165 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
166 cfg.writeEntry("stopGrowingAtDarkestPixel", value);
167}
168
170{
171 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
172 cfg.writeEntry("featherSelection", value);
173}
174
177{
178 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
179 cfg.writeEntry(
180 "sampleLayersMode",
182 ? "sampleAllLayers"
184 ? "sampleColorLabeledLayers"
185 : "sampleCurrentLayer"));
186}
187
189{
190 const QList<int> colorLabels = m_optionsWidget->selectedColorLabels();
191 if (colorLabels.isEmpty()) {
192 return;
193 }
194 QString colorLabelsStr = QString::number(colorLabels.first());
195 for (int i = 1; i < colorLabels.size(); ++i) {
196 colorLabelsStr += "," + QString::number(colorLabels[i]);
197 }
198
199 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
200 cfg.writeEntry("colorLabels", colorLabelsStr);
201}
202
208
214
220
226
232
234{
235 if (!isActivated || !m_optionsWidget) {
236 return;
237 }
238
239 KConfigGroup cfg = KSharedConfig::openConfig()->group("KisToolSelectBase");
240
242 (SelectionMode)cfg.readEntry("selectionMode",
243 static_cast<int>(SHAPE_PROTECTION));
245 (SelectionAction)cfg.readEntry("selectionAction",
246 static_cast<int>(SELECTION_REPLACE));
247
251
253}
254
256{
257 if (m_configGroupForTool == "") {
258 return;
259 }
260
261 KConfigGroup cfgToolSpecific =
262 KSharedConfig::openConfig()->group(m_configGroupForTool);
263 const bool antiAliasSelection =
264 cfgToolSpecific.readEntry("antiAliasSelection", true);
265 const int growSelection = cfgToolSpecific.readEntry("growSelection", 0);
266 const bool stopGrowingAtDarkestPixel =
267 cfgToolSpecific.readEntry("stopGrowingAtDarkestPixel", false);
268 const int featherSelection =
269 cfgToolSpecific.readEntry("featherSelection", 0);
270 const QString referenceLayersStr =
271 cfgToolSpecific.readEntry("sampleLayersMode", "sampleCurrentLayer");
272
273 const QStringList colorLabelsStr =
274 cfgToolSpecific.readEntry<QString>("colorLabels", "")
275 .split(',', Qt::SkipEmptyParts);
276
278 referenceLayersStr == "sampleAllLayers"
280 : (referenceLayersStr == "sampleColorLabeledLayers"
283 QList<int> colorLabels;
284 for (const QString &colorLabelStr : colorLabelsStr) {
285 bool ok;
286 const int colorLabel = colorLabelStr.toInt(&ok);
287 if (ok) {
288 colorLabels << colorLabel;
289 }
290 }
291
299}
float value(const T *src, size_t ch)
SelectionMode
@ SHAPE_PROTECTION
SelectionAction
@ SELECTION_REPLACE
@ SELECTION_INTERSECT
@ SELECTION_SYMMETRICDIFFERENCE
@ SELECTION_DEFAULT
@ SELECTION_SUBTRACT
@ SELECTION_ADD
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setMode(SelectionMode newMode)
void setGrowSelection(int newGrowSelection)
void setAntiAliasSelection(bool newAntiAliasSelection)
void actionChanged(SelectionAction action)
void antiAliasSelectionChanged(bool antiAliasSelection)
void setAction(SelectionAction newAction)
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 selectionActionChanged(SelectionAction newAction)
KisSelectionOptions::ReferenceLayers referenceLayers() const
void slotReferenceLayersChanged(KisSelectionOptions::ReferenceLayers referenceLayers)