Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_dlg_stroke_selection_properties.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Kapustin Alexey <akapust1n@yandex.ru>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QRadioButton>
10#include <QLayout>
11#include <QSpinBox>
12#include <QSlider>
13#include <QCheckBox>
14#include <QPlainTextEdit>
15#include <QTextEdit>
16
17#include <klocalizedstring.h>
18
19#include <KoColorSpace.h>
20#include "KoColorProfile.h"
22#include "KoColor.h"
24#include "KoColorPopupAction.h"
25#include "kis_icon_utils.h"
26#include "KoID.h"
27#include "kis_image.h"
28#include "kis_annotation.h"
29#include "kis_config.h"
32#include <KisSqueezedComboBox.h>
33#include "kis_layer_utils.h"
34#include <kis_ls_utils.h>
36#include "KoUnit.h"
38#include "KisMainWindow.h"
39
40#include <kis_signals_blocker.h>
41
43 : KoDialog(view->mainWindowAsQWidget())
44{
46 KisPropertiesConfigurationSP cfg = KisConfig(true).exportConfiguration("StrokeSelection");
47
51 setCaption(i18nc("@title:window", "Stroke Selection Properties"));
52 m_page = new WdgStrokeSelection(this);
53 m_page->m_isVectorLayer = isVectorLayer;
54 m_page->m_cfg = cfg;
55
56 m_image = image;
57
59
61 m_options.color = cfg->getColor("color");
62 m_options.colorLineSource = static_cast<ColorLineSource>(cfg->getInt("lineColorSource"));
63 m_page->lineColorBox->setCurrentIndex(static_cast<int>(m_options.colorLineSource));
64
65 m_page->colorSelector->setColor(getSelectedColor().toQColor());
66
67 m_options.brushSelected = cfg->getBool("useBrush", 0);
68 m_page->typeBox->setCurrentIndex(m_options.brushSelected? 0 : 1);
69
70 m_options.colorFillSource = static_cast<ColorFillSource>(cfg->getInt("colorFillSource", 0));
71 m_page->fillBox->setCurrentIndex(static_cast<int>(m_options.colorFillSource));
72 m_options.customColor = cfg->getColor("customColor");
73
75 m_page->colorFillSelector->setColor(m_options.customColor.toQColor());
76 }
77 else {
78 m_page->colorFillSelector->setColor(getFillSelectedColor().toQColor());
79 }
80
81 m_options.lineSize = cfg->getInt("lineSize", 1);
82 m_page->lineSize->setValue(m_options.lineSize);
83
84 m_options.lineDimension = cfg->getInt("lineDimension", 0);
85 m_page->sizeBox->setCurrentIndex(m_options.lineDimension);
86
87 connect(m_page, SIGNAL(colorSelectorChanged()), SLOT(setColorButton()));
88 connect(m_page, SIGNAL(colorFillSelectorChanged()), SLOT(setColorFillButton()));
89 connect(m_page->colorFillSelector, SIGNAL(changed(QColor)), SLOT(colorFillChanged(QColor)));
90 connect(m_page->colorSelector, SIGNAL(changed(QColor)), SLOT(colorChanged(QColor)));
91
93
94}
95
97{
99 m_options.lineSize = m_page->lineSize->value();
100
101 m_options.lineDimension = m_page->sizeBox->currentIndex();
102 m_options.colorLineSource = static_cast<ColorLineSource>(m_page->lineColorBox->currentIndex());
103
105 cfg->setProperty("lineSize", m_options.lineSize);
106 cfg->setProperty("colorFillSource", static_cast<int>(m_options.colorFillSource));
107 cfg->setProperty("useBrush", m_options.brushSelected);
108 cfg->setProperty("lineDimension", m_options.lineDimension);
109 cfg->setProperty("lineColorSource", static_cast<int>(m_options.colorLineSource));
110
111 QVariant colorVariant;
112 colorVariant.setValue(m_options.customColor);
113 cfg->setProperty("customColor", colorVariant);
114
115 colorVariant.setValue(m_options.color);
116 cfg->setProperty("color", colorVariant);
117
118 colorVariant.setValue(m_options.fillColor);
119 cfg->setProperty("fillColor", colorVariant);
120
121 KisConfig(false).setExportConfiguration("StrokeSelection", cfg);
122
123 delete m_page;
124}
125
127{
128 KoColor color;
129
130 ColorLineSource currentSource = static_cast<ColorLineSource>(m_page->lineColorBox->currentIndex());
131 switch(currentSource) {
136 default:
137 return m_page->m_options.color;
138 }
139}
140
142{
143 KoColor color;
144
145 ColorFillSource currentSource = static_cast<ColorFillSource>(m_page->fillBox->currentIndex());
146 switch (currentSource) {
152 return m_converter->approximateFromRenderedQColor(m_page->colorSelector->color());
153 default:
155 }
156
157}
158
159
161{
162 return (static_cast<DrawType>(m_page->typeBox->currentIndex()) == DrawType::CurrentBrush);
163}
164
181
183{
184 m_page->colorFillSelector->setColor(getFillSelectedColor().toQColor());
185}
186
188{
189 m_page->colorSelector->setColor(getSelectedColor().toQColor());
190}
191
193{
194 int value = m_page->lineSize->value();
195
196 if (m_page->sizeBox->currentIndex() == 0) {
197 return value;
198 }
199 else if (m_page->sizeBox->currentIndex() == 1) {
201 return pixels;
202 }
203 else {
205 return pixels;
206 }
207}
208
210{/* TODO
211 int index = m_page->linePosition->currentIndex();
212 switch(index)
213 {
214 case(0):
215 return linePosition::OUTSIDE;
216 case(1):
217 return linePosition::INSIDE;
218 case(2):
219 return linePosition::CENTER;
220 default:
221 return linePosition::CENTER;
222 }*/
224}
225
226void KisDlgStrokeSelection::colorChanged(const QColor &newColor)
227{
228 KisSignalsBlocker blocker(m_page->fillBox, m_page->lineColorBox);
229
230 if (m_page->fillBox->currentIndex() == static_cast<int>(ColorFillSource::PaintColor)) {
231 m_page->colorFillSelector->setColor(newColor);
232 }
233
237
238 if (tempColor.toQColor() == FGColor.toQColor()) {
239 m_page->lineColorBox->setCurrentIndex(static_cast<int>(ColorLineSource::FGColor));
240 }
241 else if (tempColor.toQColor() == BGColor.toQColor()) {
242 m_page->lineColorBox->setCurrentIndex(static_cast<int>(ColorLineSource::BGColor));
243 }
244 else {
245 m_page->lineColorBox->setCurrentIndex((int)ColorLineSource::CustomColor);
246 }
247 m_page->m_options.color = tempColor;
248}
249
250void KisDlgStrokeSelection::colorFillChanged(const QColor &newColor)
251{
252 KisSignalsBlocker blocker(m_page->fillBox);
253
258
259 if (tempColor.toQColor() == FGColor.toQColor()) {
260 m_page->fillBox->setCurrentIndex(static_cast<int>(ColorFillSource::FGColor));
261
262 }
263 else if (tempColor.toQColor() == BGColor.toQColor()) {
264 m_page->fillBox->setCurrentIndex(static_cast<int>(ColorFillSource::BGColor));
265 }
266 else if (PaintColor.toQColor() != tempColor.toQColor() ) {
267 m_page->fillBox->setCurrentIndex((int)ColorFillSource::CustomColor);
268 m_page->m_options.customColor = tempColor;
269 }
270
271 m_page->m_options.fillColor = tempColor;
272}
273
274
275
276WdgStrokeSelection::WdgStrokeSelection(QWidget *parent) : QWidget(parent)
277{
278 setupUi(this);
279}
280
282{
283 m_options.fillColor = m_cfg->getColor("fillColor");
285 colorFillSelector->setEnabled(false);
286 }
287 else {
288 colorFillSelector->setEnabled(true);
289 }
290
291 if (m_isVectorLayer) {
292 typeBox->setCurrentIndex(1);
293 typeBox->setEnabled(false);
294 }
295 else {
296 typeBox->setEnabled(true);
297 }
298
299 on_typeBox_currentIndexChanged(typeBox->currentIndex());
300}
301
303{
304 if (index == static_cast<int>(ColorFillSource::None)) {
305 colorFillSelector->setDisabled(true);
306 }
307 else {
308 colorFillSelector->setDisabled(false);
310 }
311 m_options.colorFillSource = static_cast<ColorFillSource>(index);
312}
313
315{
316 if (arg1 == 0) {
318 lineSize->setEnabled(false);
319 fillBox->setEnabled(false);
320 colorFillSelector->setEnabled(false);
321 sizeBox->setEnabled(false);
322 }
323 else {
324 m_options.brushSelected = false;
325 lineSize->setEnabled(true);
326 fillBox->setEnabled(true);
327 colorFillSelector->setEnabled(true);
328 sizeBox->setEnabled(true);
329 }
330}
331
336
337
338StrokeSelectionOptions ::StrokeSelectionOptions()
339{
340 color.fromQColor(Qt::black);
341 fillColor.fromQColor(Qt::black);
342 customColor.fromQColor(Qt::black);
343}
344
346{
347 using namespace KisToolShapeUtils;
348
349 ColorFillSource tempColor = static_cast<ColorFillSource>(colorFillSource);
350 FillStyle style = FillStyleNone;
351
352 switch (tempColor) {
354 style = FillStyleForegroundColor;
355 break;
357 style = FillStyleBackgroundColor;
358 break;
360 style = FillStyleBackgroundColor;
361 break;
363 style = FillStyleNone;
364 break;
366 style = FillStyleBackgroundColor;
367 break;
368 }
369 return style;
370}
371
372
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisDisplayColorConverter displayColorConverter
KisPropertiesConfigurationSP exportConfiguration(const QString &filterId, bool defaultValue=false) const
void setExportConfiguration(const QString &filterId, KisPropertiesConfigurationSP properties) const
KoColor approximateFromRenderedQColor(const QColor &c) const
KisDlgStrokeSelection(KisImageWSP image, KisViewManager *view, bool isVectorLayer)
StrokeSelectionOptions getParams() const
KoCanvasResourceProvider * m_resourceManager
void colorFillChanged(const QColor &newColor)
void colorChanged(const QColor &newColor)
KoCanvasResourceProvider * resourceManager() const
KisMainWindow * mainWindow() const
KisCanvas2 * canvasBase() const
Return the canvas base class.
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void setDefaultButton(ButtonCode id)
Definition KoDialog.cpp:302
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition KoDialog.h:127
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition KoDialog.h:130
static qreal convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor=1.0)
Definition KoUnit.cpp:295
@ Millimeter
Definition KoUnit.h:75
@ Inch
Definition KoUnit.h:77
@ Pixel
Definition KoUnit.h:82
void colorFillSelectorChanged()
void colorSelectorChanged()
KisPropertiesConfigurationSP m_cfg
This file is part of the Krita application in calligra.
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.
KisToolShapeUtils::FillStyle fillStyle() const