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

A gradient shape background. More...

#include <KoGradientBackground.h>

+ Inheritance diagram for KoGradientBackground:

Classes

class  Private
 

Public Member Functions

bool compareTo (const KoShapeBackground *other) const override
 
const QGradient * gradient () const
 Returns the gradient.
 
 KoGradientBackground (const KoGradientBackground &)
 
 KoGradientBackground (const QGradient &gradient, const QTransform &matrix=QTransform())
 
 KoGradientBackground (QGradient *gradient, const QTransform &matrix=QTransform())
 
KoGradientBackgroundoperator= (const KoGradientBackground &)
 
void paint (QPainter &painter, const QPainterPath &fillPath) const override
 reimplemented from KoShapeBackground
 
void setGradient (const QGradient &gradient)
 
void setTransform (const QTransform &matrix)
 Sets the transform matrix.
 
QTransform transform () const
 Returns the transform matrix.
 
 ~KoGradientBackground () override
 Destroys the background.
 
- Public Member Functions inherited from KoShapeBackground
virtual bool hasTransparency () const
 Returns if the background has some transparency.
 
 KoShapeBackground ()
 
virtual operator bool () const
 
virtual ~KoShapeBackground ()
 

Private Attributes

QSharedDataPointer< Privated
 

Detailed Description

A gradient shape background.

Definition at line 19 of file KoGradientBackground.h.

Constructor & Destructor Documentation

◆ KoGradientBackground() [1/3]

KoGradientBackground::KoGradientBackground ( QGradient * gradient,
const QTransform & matrix = QTransform() )
explicit

Creates new gradient background from given gradient. The background takes ownership of the given gradient.

Definition at line 31 of file KoGradientBackground.cpp.

33 , d(new Private)
34{
35 d->gradient = gradient;
36 d->matrix = matrix;
37 Q_ASSERT(d->gradient);
38}
const QGradient * gradient() const
Returns the gradient.
QSharedDataPointer< Private > d

References d, and gradient().

◆ KoGradientBackground() [2/3]

KoGradientBackground::KoGradientBackground ( const QGradient & gradient,
const QTransform & matrix = QTransform() )
explicit

Create new gradient background from the given gradient. A clone of the given gradient is used.

Definition at line 40 of file KoGradientBackground.cpp.

42 , d(new Private)
43{
44 d->gradient = KoFlake::cloneGradient(&gradient);
45 d->matrix = matrix;
46 Q_ASSERT(d->gradient);
47}
KRITAFLAKE_EXPORT QGradient * cloneGradient(const QGradient *gradient)
clones the given gradient
Definition KoFlake.cpp:17

References KoFlake::cloneGradient(), d, and gradient().

◆ ~KoGradientBackground()

KoGradientBackground::~KoGradientBackground ( )
override

Destroys the background.

Definition at line 49 of file KoGradientBackground.cpp.

50{
51 delete d->gradient;
52}

References d.

◆ KoGradientBackground() [3/3]

KoGradientBackground::KoGradientBackground ( const KoGradientBackground & rhs)

Definition at line 54 of file KoGradientBackground.cpp.

55 : d(new Private(*rhs.d))
56{
57}

Member Function Documentation

◆ compareTo()

bool KoGradientBackground::compareTo ( const KoShapeBackground * other) const
overridevirtual

Implements KoShapeBackground.

Definition at line 65 of file KoGradientBackground.cpp.

66{
67 const KoGradientBackground *otherGradient = dynamic_cast<const KoGradientBackground*>(other);
68
69 return otherGradient &&
70 d->matrix == otherGradient->d->matrix &&
71 *d->gradient == *otherGradient->d->gradient;
72}
A gradient shape background.

References d.

◆ gradient()

const QGradient * KoGradientBackground::gradient ( ) const

Returns the gradient.

Definition at line 92 of file KoGradientBackground.cpp.

93{
94 return d->gradient;
95}

References d.

◆ operator=()

KoGradientBackground & KoGradientBackground::operator= ( const KoGradientBackground & rhs)

Definition at line 59 of file KoGradientBackground.cpp.

60{
61 d = rhs.d;
62 return *this;
63}

References d.

◆ paint()

void KoGradientBackground::paint ( QPainter & painter,
const QPainterPath & fillPath ) const
overridevirtual

reimplemented from KoShapeBackground

NOTE: important hack!

Qt has different notation of QBrush::setTransform() in comparison to what SVG defines. SVG defines gradientToUser matrix to be postmultiplied by QBrush::transform(), but Qt does exactly reverse!

That most probably has been caused by the fact that Qt uses transposed matrices and someone just mistyped the stuff long ago :(

So here we basically emulate this feature by converting the gradient into QGradient::LogicalMode and doing transformations manually.

Implements KoShapeBackground.

Definition at line 97 of file KoGradientBackground.cpp.

98{
99 if (!d->gradient) return;
100
101 if (d->gradient->coordinateMode() == QGradient::ObjectBoundingMode) {
102
117 const QRectF boundingRect = fillPath.boundingRect();
118 QTransform gradientToUser(boundingRect.width(), 0, 0, boundingRect.height(),
119 boundingRect.x(), boundingRect.y());
120
121 // TODO: how about slicing the object?
122 QGradient g = *d->gradient;
123 g.setCoordinateMode(QGradient::LogicalMode);
124
125 QBrush b(g);
126 b.setTransform(d->matrix * gradientToUser);
127 painter.setBrush(b);
128 } else {
129 QBrush b(*d->gradient);
130 b.setTransform(d->matrix);
131 painter.setBrush(b);
132 }
133
134 painter.drawPath(fillPath);
135}

References d.

◆ setGradient()

void KoGradientBackground::setGradient ( const QGradient & gradient)

Sets a new gradient. A clone of the given gradient is used.

Definition at line 84 of file KoGradientBackground.cpp.

85{
86 delete d->gradient;
87
88 d->gradient = KoFlake::cloneGradient(&gradient);
89 Q_ASSERT(d->gradient);
90}

References KoFlake::cloneGradient(), d, and gradient().

◆ setTransform()

void KoGradientBackground::setTransform ( const QTransform & matrix)

Sets the transform matrix.

Definition at line 74 of file KoGradientBackground.cpp.

75{
76 d->matrix = matrix;
77}

References d.

◆ transform()

QTransform KoGradientBackground::transform ( ) const

Returns the transform matrix.

Definition at line 79 of file KoGradientBackground.cpp.

80{
81 return d->matrix;
82}

References d.

Member Data Documentation

◆ d

QSharedDataPointer<Private> KoGradientBackground::d
private

Definition at line 62 of file KoGradientBackground.h.


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