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"
23
26 : m_parent(parent)
27 {
28 m_option.readOptionSetting(m_parent, parent->resourcesInterface(), parent->canvasResourcesInterface());
29 }
30
32 return m_option.brush();
33 }
34
37};
38
41 : m_parent(parent)
42 {
43 m_option.readOptionSetting(m_parent, parent->resourcesInterface(), parent->canvasResourcesInterface());
44 }
45
49
51 return m_option.brush();
52 }
53
56};
57
58
68
75
86
88{
90 KisBrushBasedPaintOpSettingsSP settings = dynamic_cast<KisBrushBasedPaintOpSettings*>(_settings.data());
91
99 settings->setResourceCacheInterface(resourceCacheInterface());
100
101 return settings;
102}
103
105{
107
108 if (!brush) {
109 BrushReader w(this);
110 brush = w.brush();
112 }
113
114 return brush;
115}
116
118 const OutlineMode &mode,
119 qreal alignForZoom,
120 qreal additionalScale)
121{
123
124 if (mode.isVisible) {
125 KisBrushSP brush = this->brush();
126 if (!brush) return path;
127 qreal finalScale = brush->scale() * additionalScale;
128
129 KisOptimizedBrushOutline realOutline = brush->outline(alignForZoom > 2.0 || qFuzzyCompare(alignForZoom, 2.0));
130
131 if (mode.forceCircle) {
132
133 QPainterPath ellipse;
134 ellipse.addEllipse(realOutline.boundingRect());
135 realOutline = ellipse;
136 }
137
138 path = outlineFetcher()->fetchOutline(info, this, realOutline, mode, alignForZoom, finalScale, brush->angle());
139
140 if (mode.showTiltDecoration) {
141 const QPainterPath tiltLine = makeTiltIndicator(info,
142 realOutline.boundingRect().center(),
143 realOutline.boundingRect().width() * 0.5,
144 3.0);
145 path.addPath(outlineFetcher()->fetchOutline(info, this, tiltLine, mode, alignForZoom, finalScale, 0.0, true, realOutline.boundingRect().center().x(), realOutline.boundingRect().center().y()));
146 }
147 }
148
149 return path;
150}
151
153{
154 return brushOutlineImpl(info, mode, alignForZoom, 1.0);
155}
156
158{
159 BrushWriter w(this);
160 if (!w.brush()) return;
161 w.brush()->setSpacing(value);
162}
163
165{
167 return this->brush()->spacing();
168}
169
171{
172 BrushWriter w(this);
173 if (!w.brush()) return;
174 w.brush()->setAutoSpacing(active, coeff);
175}
176
177
179{
181 return this->brush()->autoSpacingActive();
182}
183
185{
187 return this->brush()->autoSpacingCoeff();
188}
189
191{
192 BrushWriter w(this);
193 if (!w.brush()) return;
194
195 w.brush()->setUserEffectiveSize(value);
196}
197
199{
201 return this->brush()->userEffectiveSize();
202}
203
205{
206 BrushWriter w(this);
207 if (!w.brush()) return;
208
211 w.brush()->setAngle(value);
212}
213
215{
217 const qreal value = kisRadiansToDegrees(this->brush()->angle());
218 return value;
219}
220
221
223#include "kis_paintop_preset.h"
225
227{
230
231 if (props.isEmpty()) {
232 {
234 new KisIntSliderBasedPaintOpPropertyCallback(KisIntSliderBasedPaintOpPropertyCallback::Int,
235 KisIntSliderBasedPaintOpPropertyCallback::SubType_Angle,
236 KoID("angle", i18n("Angle")),
237 settings,
238 0);
239
240 prop->setRange(0, 360);
241
242 prop->setReadCallback(
243 [](KisUniformPaintOpProperty *prop) {
245 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
246
247 prop->setValue(s->paintOpAngle());
248 });
249 prop->setWriteCallback(
250 [](KisUniformPaintOpProperty *prop) {
252 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
253
254 s->setPaintOpAngle(prop->value().toReal());
255 });
256
257 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
258 prop->requestReadValue();
259 props << toQShared(prop);
260 }
261 {
263 new KisUniformPaintOpPropertyCallback(KisUniformPaintOpPropertyCallback::Bool, KoID("auto_spacing", i18n("Auto Spacing")), settings, 0);
264
265 prop->setReadCallback(
266 [](KisUniformPaintOpProperty *prop) {
268 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
269
270 prop->setValue(s->autoSpacingActive());
271 });
272 prop->setWriteCallback(
273 [](KisUniformPaintOpProperty *prop) {
275 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
276
277 s->setAutoSpacing(prop->value().toBool(), s->autoSpacingCoeff());
278 });
279
280 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
281 prop->requestReadValue();
282 props << toQShared(prop);
283 }
284
285 {
287 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
288 KoID("spacing", i18n("Spacing")),
289 settings,
290 0);
291
292 prop->setRange(0.01, 10);
293 prop->setSingleStep(0.01);
294 prop->setExponentRatio(3.0);
295
296
297 prop->setReadCallback(
298 [](KisUniformPaintOpProperty *prop) {
300 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
301 if (s) {
302 const qreal value = s->autoSpacingActive() ?
303 s->autoSpacingCoeff() : s->spacing();
304 prop->setValue(value);
305 }
306 });
307 prop->setWriteCallback(
308 [](KisUniformPaintOpProperty *prop) {
310 dynamic_cast<KisBrushBasedPaintOpSettings*>(prop->settings().data());
311 if (s) {
312 if (s->autoSpacingActive()) {
313 s->setAutoSpacing(true, prop->value().toReal());
314 } else {
315 s->setSpacing(prop->value().toReal());
316 }
317 }
318 });
319
320 QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
321 prop->requestReadValue();
322 props << toQShared(prop);
323 }
324 }
325
326 return KisPaintOpSettings::uniformProperties(settings, updateProxy) + props;
327}
328
334
336{
337 return true;
338}
339
357
359{
360 m_savedBrush.clear();
361
362 QVariant brush = cacheInterface ? cacheInterface->fetch("settings/brush") : QVariant();
363
364 if (brush.isValid()) {
365 KisBrushSP brushPointer = brush.value<KisBrushSP>();
366 KIS_SAFE_ASSERT_RECOVER_NOOP(brushPointer);
367
368 if (brushPointer) {
369 m_savedBrush = brushPointer->clone().dynamicCast<KisBrush>();
370 }
371 }
372
374}
375
377{
379
380 KisBrushSP brush = this->brush();
382
383 brush->coldInitBrush();
384
385 cacheInterface->put("settings/brush", QVariant::fromValue(brush->clone().dynamicCast<KisBrush>()));
386}
float value(const T *src, size_t ch)
const QString COMPOSITE_ALPHA_DARKEN_CLAMP
const QString COMPOSITE_ALPHA_DARKEN
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)