Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_brush_based_paintop_settings.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Sven Langkamp <sven.langkamp@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
11#include <kis_boundary.h>
13#include <QLineF>
14#include "kis_signals_blocker.h"
15#include "kis_brush_option.h"
17#include <kis_paintop_preset.h>
19#include "kis_texture_option.h"
22
25 : m_parent(parent)
26 {
27 m_option.readOptionSetting(m_parent, parent->resourcesInterface(), parent->canvasResourcesInterface());
28 }
29
31 return m_option.brush();
32 }
33
36};
37
40 : m_parent(parent)
41 {
42 m_option.readOptionSetting(m_parent, parent->resourcesInterface(), parent->canvasResourcesInterface());
43 }
44
48
50 return m_option.brush();
51 }
52
55};
56
57
67
74
76{
78 KisBrushBasedPaintOpSettingsSP settings = dynamic_cast<KisBrushBasedPaintOpSettings*>(_settings.data());
79
87 settings->setResourceCacheInterface(resourceCacheInterface());
88
89 return settings;
90}
91
93{
95
96 if (!brush) {
97 BrushReader w(this);
98 brush = w.brush();
100 }
101
102 return brush;
103}
104
106 const OutlineMode &mode,
107 qreal alignForZoom,
108 qreal additionalScale)
109{
111
112 if (mode.isVisible) {
113 KisBrushSP brush = this->brush();
114 if (!brush) return path;
115 qreal finalScale = brush->scale() * additionalScale;
116
117 KisOptimizedBrushOutline realOutline = brush->outline(alignForZoom > 2.0 || qFuzzyCompare(alignForZoom, 2.0));
118
119 if (mode.forceCircle) {
120
121 QPainterPath ellipse;
122 ellipse.addEllipse(realOutline.boundingRect());
123 realOutline = ellipse;
124 }
125
126 path = outlineFetcher()->fetchOutline(info, this, realOutline, mode, alignForZoom, finalScale, brush->angle());
127
128 if (mode.showTiltDecoration) {
129 const QPainterPath tiltLine = makeTiltIndicator(info,
130 realOutline.boundingRect().center(),
131 realOutline.boundingRect().width() * 0.5,
132 3.0);
133 path.addPath(outlineFetcher()->fetchOutline(info, this, tiltLine, mode, alignForZoom, finalScale, 0.0, true, realOutline.boundingRect().center().x(), realOutline.boundingRect().center().y()));
134 }
135 }
136
137 return path;
138}
139
141{
142 return brushOutlineImpl(info, mode, alignForZoom, 1.0);
143}
144
146{
147 BrushWriter w(this);
148 if (!w.brush()) return;
149 w.brush()->setSpacing(value);
150}
151
153{
155 return this->brush()->spacing();
156}
157
159{
160 BrushWriter w(this);
161 if (!w.brush()) return;
162 w.brush()->setAutoSpacing(active, coeff);
163}
164
165
167{
169 return this->brush()->autoSpacingActive();
170}
171
173{
175 return this->brush()->autoSpacingCoeff();
176}
177
179{
180 BrushWriter w(this);
181 if (!w.brush()) return;
182
183 w.brush()->setUserEffectiveSize(value);
184}
185
187{
189 return this->brush()->userEffectiveSize();
190}
191
193{
194 BrushWriter w(this);
195 if (!w.brush()) return;
196
199 w.brush()->setAngle(value);
200}
201
203{
205 const qreal value = kisRadiansToDegrees(this->brush()->angle());
206 return value;
207}
208
209
211#include "kis_paintop_preset.h"
213
215{
218
219 if (props.isEmpty()) {
220 {
222 new KisIntSliderBasedPaintOpPropertyCallback(KisIntSliderBasedPaintOpPropertyCallback::Int,
223 KisIntSliderBasedPaintOpPropertyCallback::SubType_Angle,
224 KoID("angle", i18n("Angle")),
225 settings,
226 0);
227
228 prop->setRange(0, 360);
229
230 prop->setReadCallback(
231 [](KisUniformPaintOpProperty *prop) {
233 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
234
235 prop->setValue(s->paintOpAngle());
236 });
237 prop->setWriteCallback(
238 [](KisUniformPaintOpProperty *prop) {
240 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
241
242 s->setPaintOpAngle(prop->value().toReal());
243 });
244
245 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
246 prop->requestReadValue();
247 props << toQShared(prop);
248 }
249 {
251 new KisUniformPaintOpPropertyCallback(KisUniformPaintOpPropertyCallback::Bool, KoID("auto_spacing", i18n("Auto Spacing")), settings, 0);
252
253 prop->setReadCallback(
254 [](KisUniformPaintOpProperty *prop) {
256 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
257
258 prop->setValue(s->autoSpacingActive());
259 });
260 prop->setWriteCallback(
261 [](KisUniformPaintOpProperty *prop) {
263 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
264
265 s->setAutoSpacing(prop->value().toBool(), s->autoSpacingCoeff());
266 });
267
268 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
269 prop->requestReadValue();
270 props << toQShared(prop);
271 }
272
273 {
275 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
276 KoID("spacing", i18n("Spacing")),
277 settings,
278 0);
279
280 prop->setRange(0.01, 10);
281 prop->setSingleStep(0.01);
282 prop->setExponentRatio(3.0);
283
284
285 prop->setReadCallback(
286 [](KisUniformPaintOpProperty *prop) {
288 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
289 if (s) {
290 const qreal value = s->autoSpacingActive() ?
291 s->autoSpacingCoeff() : s->spacing();
292 prop->setValue(value);
293 }
294 });
295 prop->setWriteCallback(
296 [](KisUniformPaintOpProperty *prop) {
298 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
299 if (s) {
300 if (s->autoSpacingActive()) {
301 s->setAutoSpacing(true, prop->value().toReal());
302 } else {
303 s->setSpacing(prop->value().toReal());
304 }
305 }
306 });
307
308 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
309 prop->requestReadValue();
310 props << toQShared(prop);
311 }
312 }
313
314 return KisPaintOpSettings::uniformProperties(settings, updateProxy) + props;
315}
316
322
324{
325 return true;
326}
327
345
347{
348 m_savedBrush.clear();
349
350 QVariant brush = cacheInterface ? cacheInterface->fetch("settings/brush") : QVariant();
351
352 if (brush.isValid()) {
353 KisBrushSP brushPointer = brush.value<KisBrushSP>();
354 KIS_SAFE_ASSERT_RECOVER_NOOP(brushPointer);
355
356 if (brushPointer) {
357 m_savedBrush = brushPointer->clone().dynamicCast<KisBrush>();
358 }
359 }
360
362}
363
365{
367
368 KisBrushSP brush = this->brush();
370
371 brush->coldInitBrush();
372
373 cacheInterface->put("settings/brush", QVariant::fromValue(brush->clone().dynamicCast<KisBrush>()));
374}
float value(const T *src, size_t ch)
KisBrushBasedPaintOpSettings(KisResourcesInterfaceSP resourcesInterface)
KisPaintOpSettingsSP clone() const override
virtual bool hasPatternSettings() const override
bool paintIncremental() override
Reimplemented.
QList< int > requiredCanvasResources() const override
void setResourceCacheInterface(KoResourceCacheInterfaceSP cacheInterface) override
QList< KisUniformPaintOpPropertyWSP > m_uniformProperties
void setAutoSpacing(bool active, qreal coeff)
void regenerateResourceCache(KoResourceCacheInterfaceSP cacheInterface) override
KisOptimizedBrushOutline brushOutline(const KisPaintInformation &info, const OutlineMode &mode, qreal alignForZoom) override
KisOptimizedBrushOutline brushOutlineImpl(const KisPaintInformation &info, const OutlineMode &mode, qreal alignForZoom, qreal additionalScale)
KisOptimizedBrushOutline fetchOutline(const KisPaintInformation &info, const KisPaintOpSettingsSP settings, const KisOptimizedBrushOutline &originalOutline, const KisPaintOpSettings::OutlineMode &mode, qreal alignForZoom, qreal additionalScale=1.0, qreal additionalRotation=0.0, bool tilt=false, qreal tiltcenterx=1.0, qreal tiltcentery=1.0) const
const KisCurrentOutlineFetcher * outlineFetcher() const
void readOptionSetting(KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface, KoCanvasResourcesInterfaceSP canvasResourcesInterface)
void writeOptionSetting(KisPropertiesConfigurationPointer settings) const
static bool requiresEffectiveCompositeOp(const KisPropertiesConfiguration *settings)
bool applyingGradient() const
Definition KoID.h:30
static bool qFuzzyCompare(half p1, half p2)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
T kisRadiansToDegrees(T radians)
Definition kis_global.h:181
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngleDegrees(T a)
Definition kis_global.h:132
T kisDegreesToRadians(T degrees)
Definition kis_global.h:176
QSharedPointer< T > toQShared(T *ptr)
Container< QSharedPointer< T > > listWeakToStrong(const Container< QWeakPointer< T > > &container, bool allOrNothing=true)
KisCallbackBasedPaintopProperty< KisSliderBasedPaintOpProperty< int > > KisIntSliderBasedPaintOpPropertyCallback
KisCallbackBasedPaintopProperty< KisSliderBasedPaintOpProperty< qreal > > KisDoubleSliderBasedPaintOpPropertyCallback
KisCallbackBasedPaintopProperty< KisUniformPaintOpProperty > KisUniformPaintOpPropertyCallback
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.
const KisBrushBasedPaintOpSettings * m_parent
BrushReader(const KisBrushBasedPaintOpSettings *parent)
KisBrushOptionProperties m_option
KisBrushBasedPaintOpSettings * m_parent
BrushWriter(KisBrushBasedPaintOpSettings *parent)
KisBrushOptionProperties m_option
static QPainterPath makeTiltIndicator(KisPaintInformation const &info, QPointF const &start, qreal lengthScale, qreal angle)
QList< KisUniformPaintOpPropertyWSP > uniformProperties
KoResourceCacheInterfaceSP resourceCacheInterface
bool read(const KisPropertiesConfiguration *setting)