Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeFillWrapper Class Reference

#include <KoShapeFillWrapper.h>

Classes

struct  Private
 

Public Member Functions

KUndo2CommandapplyGradient (const QGradient *gradient)
 
KUndo2CommandapplyGradientStopsOnly (const QGradient *gradient)
 
QColor color () const
 
const QGradient * gradient () const
 
QTransform gradientTransform () const
 
bool hasZeroLineWidth () const
 
bool isMixedFill () const
 
 KoShapeFillWrapper (KoShape *shape, KoFlake::FillVariant fillVariant)
 
 KoShapeFillWrapper (QList< KoShape * > shapes, KoFlake::FillVariant fillVariant)
 
const SvgMeshGradientmeshgradient () const
 
KUndo2CommandsetColor (const QColor &color)
 
KUndo2CommandsetGradient (const QGradient *gradient, const QTransform &transform)
 
KUndo2CommandsetLineWidth (const float &lineWidth)
 
KUndo2CommandsetMeshGradient (const SvgMeshGradient *gradient, const QTransform &transform)
 
KoFlake::FillType type () const
 
 ~KoShapeFillWrapper ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 22 of file KoShapeFillWrapper.h.

Constructor & Destructor Documentation

◆ KoShapeFillWrapper() [1/2]

KoShapeFillWrapper::KoShapeFillWrapper ( KoShape * shape,
KoFlake::FillVariant fillVariant )

Definition at line 229 of file KoShapeFillWrapper.cpp.

230 : m_d(new Private())
231{
233 m_d->shapes << shape;
234 m_d->fillVariant= fillVariant;
235}
const QScopedPointer< Private > m_d
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KIS_SAFE_ASSERT_RECOVER_RETURN, and m_d.

◆ KoShapeFillWrapper() [2/2]

KoShapeFillWrapper::KoShapeFillWrapper ( QList< KoShape * > shapes,
KoFlake::FillVariant fillVariant )

Definition at line 238 of file KoShapeFillWrapper.cpp.

239 : m_d(new Private())
240{
241 KIS_SAFE_ASSERT_RECOVER_RETURN(!shapes.isEmpty());
242 m_d->shapes = shapes;
243 m_d->fillVariant= fillVariant;
244}

References KIS_SAFE_ASSERT_RECOVER_RETURN, and m_d.

◆ ~KoShapeFillWrapper()

KoShapeFillWrapper::~KoShapeFillWrapper ( )

Definition at line 246 of file KoShapeFillWrapper.cpp.

247{
248}

Member Function Documentation

◆ applyGradient()

KUndo2Command * KoShapeFillWrapper::applyGradient ( const QGradient * gradient)

Definition at line 420 of file KoShapeFillWrapper.cpp.

421{
423}
QTransform gradientTransform() const
const QGradient * gradient() const
KUndo2Command * setGradient(const QGradient *gradient, const QTransform &transform)

References gradient(), gradientTransform(), and setGradient().

◆ applyGradientStopsOnly()

KUndo2Command * KoShapeFillWrapper::applyGradientStopsOnly ( const QGradient * gradient)

Definition at line 425 of file KoShapeFillWrapper.cpp.

426{
427 KUndo2Command *command = 0;
428
429 if (m_d->fillVariant == KoFlake::Fill) {
431
432 foreach (KoShape *shape, m_d->shapes) {
433 newBackgrounds << m_d->applyFillGradientStops(shape, gradient);
434 }
435
436 command = new KoShapeBackgroundCommand(m_d->shapes, newBackgrounds);
437
438 } else {
439 command = KoFlake::modifyShapesStrokes(m_d->shapes,
440 [this, gradient] (KoShapeStrokeSP stroke) {
441 m_d->applyFillGradientStops(stroke, gradient);
442 });
443 }
444
445 return command;
446}
The undo / redo command for setting the shape background.
auto modifyShapesStrokes(QList< KoShape * > shapes, ModifyFunction modifyFunction) -> decltype(modifyFunction(KoShapeStrokeSP()),(KUndo2Command *)(0))
@ Fill
Definition KoFlake.h:29

References KoFlake::Fill, gradient(), m_d, and KoFlake::modifyShapesStrokes().

◆ color()

QColor KoShapeFillWrapper::color ( ) const

Definition at line 278 of file KoShapeFillWrapper.cpp.

279{
280 // this check guarantees that the shapes list is not empty and
281 // the fill is not mixed!
282 if (type() != KoFlake::Solid) return QColor();
283
284 KoShape *shape = m_d->shapes.first();
286
287 return m_d->fillVariant == KoFlake::Fill ?
290}
KoFlake::FillType type() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
@ Solid
Definition KoFlake.h:35
static QColor color(KoShape *shape)

References ShapeBackgroundFetchPolicy::color(), ShapeStrokeFillFetchPolicy::color(), KoFlake::Fill, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, KoFlake::Solid, and type().

◆ gradient()

const QGradient * KoShapeFillWrapper::gradient ( ) const

Definition at line 292 of file KoShapeFillWrapper.cpp.

293{
294 // this check guarantees that the shapes list is not empty and
295 // the fill is not mixed!
296 if (type() != KoFlake::Gradient) return 0;
297
298 KoShape *shape = m_d->shapes.first();
300
301 return m_d->fillVariant == KoFlake::Fill ?
304}
@ Gradient
Definition KoFlake.h:36
static const QGradient * gradient(KoShape *shape)

References KoFlake::Fill, KoFlake::Gradient, ShapeBackgroundFetchPolicy::gradient(), ShapeStrokeFillFetchPolicy::gradient(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, and type().

◆ gradientTransform()

QTransform KoShapeFillWrapper::gradientTransform ( ) const

Definition at line 306 of file KoShapeFillWrapper.cpp.

307{
308 // this check guarantees that the shapes list is not empty and
309 // the fill is not mixed!
310 if (type() != KoFlake::Gradient) return QTransform();
311
312 KoShape *shape = m_d->shapes.first();
313 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(shape, QTransform());
314
315 return m_d->fillVariant == KoFlake::Fill ?
318}
static QTransform gradientTransform(KoShape *shape)

References KoFlake::Fill, KoFlake::Gradient, ShapeBackgroundFetchPolicy::gradientTransform(), ShapeStrokeFillFetchPolicy::gradientTransform(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, and type().

◆ hasZeroLineWidth()

bool KoShapeFillWrapper::hasZeroLineWidth ( ) const

Definition at line 371 of file KoShapeFillWrapper.cpp.

372{
373 KoShape *shape = m_d->shapes.first();
374 if (!shape) return false;
375 if (m_d->fillVariant == KoFlake::Fill) return false;
376
377 // this check is useful to determine if
378 KoShapeStrokeSP stroke = qSharedPointerDynamicCast<KoShapeStroke>(shape->stroke());
379 if (!stroke) return false;
380
381 if ( stroke->lineWidth() == 0.0) {
382 return true;
383 }
384
385 return false;
386}
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067

References KoFlake::Fill, m_d, and KoShape::stroke().

◆ isMixedFill()

bool KoShapeFillWrapper::isMixedFill ( ) const

Definition at line 250 of file KoShapeFillWrapper.cpp.

251{
252 if (m_d->shapes.isEmpty()) return false;
253
254 return m_d->fillVariant == KoFlake::Fill ?
255 !compareBackgrounds<ShapeBackgroundFetchPolicy>(m_d->shapes) :
257}
bool compareBackgrounds(const QList< KoShape * > shapes)

References KoFlake::Fill, and m_d.

◆ meshgradient()

const SvgMeshGradient * KoShapeFillWrapper::meshgradient ( ) const

Definition at line 320 of file KoShapeFillWrapper.cpp.

321{
322 if (type() != KoFlake::MeshGradient) return nullptr;
323
324 KoShape *shape = m_d->shapes.first();
326
327 return m_d->fillVariant == KoFlake::Fill ?
329 nullptr;
330}
@ MeshGradient
Definition KoFlake.h:38
static const SvgMeshGradient * meshgradient(KoShape *shape)

References KoFlake::Fill, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, KoFlake::MeshGradient, ShapeBackgroundFetchPolicy::meshgradient(), and type().

◆ setColor()

KUndo2Command * KoShapeFillWrapper::setColor ( const QColor & color)

Definition at line 332 of file KoShapeFillWrapper.cpp.

333{
334 KUndo2Command *command = 0;
335
336 if (m_d->fillVariant == KoFlake::Fill) {
338
339 if (color.isValid()) {
341 }
342
344 command = new KoShapeBackgroundCommand(m_d->shapes, fill);
345 } else {
346 command = KoFlake::modifyShapesStrokes(m_d->shapes,
347 [color] (KoShapeStrokeSP stroke) {
348 stroke->setLineBrush(Qt::NoBrush);
349 stroke->setColor(color);
350
351 });
352 }
353
354 return command;
355}
A simple solid color shape background.
QSharedPointer< T > toQShared(T *ptr)

References color(), KoFlake::Fill, m_d, KoFlake::modifyShapesStrokes(), and toQShared().

◆ setGradient()

KUndo2Command * KoShapeFillWrapper::setGradient ( const QGradient * gradient,
const QTransform & transform )

Definition at line 389 of file KoShapeFillWrapper.cpp.

390{
391 KUndo2Command *command = 0;
392
393 if (m_d->fillVariant == KoFlake::Fill) {
395
396 foreach (KoShape *shape, m_d->shapes) {
397 Q_UNUSED(shape);
398
400 newGradient->setTransform(transform);
401 newBackgrounds << toQShared(newGradient);
402 }
403
404 command = new KoShapeBackgroundCommand(m_d->shapes, newBackgrounds);
405
406 } else {
407 command = KoFlake::modifyShapesStrokes(m_d->shapes,
408 [gradient, transform] (KoShapeStrokeSP stroke) {
409 QBrush newBrush = *gradient;
410 newBrush.setTransform(transform);
411
412 stroke->setLineBrush(newBrush);
413 stroke->setColor(Qt::transparent);
414 });
415 }
416
417 return command;
418}
A gradient shape background.
void setTransform(const QTransform &matrix)
Sets the transform matrix.
KRITAFLAKE_EXPORT QGradient * cloneGradient(const QGradient *gradient)
clones the given gradient
Definition KoFlake.cpp:17

References KoFlake::cloneGradient(), KoFlake::Fill, gradient(), m_d, KoFlake::modifyShapesStrokes(), KoGradientBackground::setTransform(), and toQShared().

◆ setLineWidth()

KUndo2Command * KoShapeFillWrapper::setLineWidth ( const float & lineWidth)

Definition at line 357 of file KoShapeFillWrapper.cpp.

358{
359 KUndo2Command *command = 0;
360
361 command = KoFlake::modifyShapesStrokes(m_d->shapes, [lineWidth](KoShapeStrokeSP stroke) {
362 stroke->setColor(Qt::transparent);
363 stroke->setLineWidth(lineWidth);
364
365 });
366
367 return command;
368}

References m_d, and KoFlake::modifyShapesStrokes().

◆ setMeshGradient()

KUndo2Command * KoShapeFillWrapper::setMeshGradient ( const SvgMeshGradient * gradient,
const QTransform & transform )

Definition at line 448 of file KoShapeFillWrapper.cpp.

450{
451 KUndo2Command *command = nullptr;
452 if (m_d->fillVariant == KoFlake::Fill) {
454
455 for (const auto &shape: m_d->shapes) {
456 Q_UNUSED(shape);
457 KoMeshGradientBackground *newBackground =
458 new KoMeshGradientBackground(gradient, transform);
459
460 newBackgrounds << toQShared(newBackground);
461 }
462 command = new KoShapeBackgroundCommand(m_d->shapes, newBackgrounds);
463 }
464 // TODO: for strokes!!
465 return command;
466}

References KoFlake::Fill, gradient(), m_d, and toQShared().

◆ type()

KoFlake::FillType KoShapeFillWrapper::type ( ) const

Definition at line 259 of file KoShapeFillWrapper.cpp.

260{
261 if (m_d->shapes.isEmpty() || isMixedFill()) return KoFlake::None;
262
263 KoShape *shape = m_d->shapes.first();
265
266 KoFlake::FillType fillType;
267 if (m_d->fillVariant == KoFlake::Fill) {
268 // fill property of vector object
269 fillType = ShapeBackgroundFetchPolicy::type(shape);
270 } else {
271 // stroke property of vector object
272 fillType = ShapeStrokeFillFetchPolicy::type(shape);
273 }
274
275 return fillType;
276}
@ None
Definition KoFlake.h:34
static Type type(KoShape *shape)
static Type type(KoShape *shape)

References KoFlake::Fill, isMixedFill(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, KoFlake::None, ShapeBackgroundFetchPolicy::type(), and ShapeStrokeFillFetchPolicy::type().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KoShapeFillWrapper::m_d
private

Definition at line 50 of file KoShapeFillWrapper.h.


The documentation for this class was generated from the following files: