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

Clip path used to clip shapes. More...

#include <KoClipPath.h>

+ Inheritance diagram for KoClipPath:

Public Member Functions

QTransform clipDataTransformation (KoShape *clippedShape) const
 
QList< KoPathShape * > clipPathShapes () const
 Returns the clip path shapes.
 
Qt::FillRule clipRule () const
 Returns the current clip rule.
 
QList< KoShape * > clipShapes () const
 
KoClipPathclone () const
 
void collectShapePath (QPainterPath *result, const KoShape *shape)
 
void compileClipPath ()
 
KoFlake::CoordinateSystem coordinates () const
 
 KoClipPath (const KoClipPath &)
 
 KoClipPath (QList< KoShape * > clipShapes, KoFlake::CoordinateSystem coordinates)
 
KoClipPathoperator= (const KoClipPath &)
 
QPainterPath path () const
 Returns the current clip path with coordinates in percent of the clipped shape size.
 
QPainterPath pathForSize (const QSizeF &size) const
 Returns the current clip path scaled to match the specified shape size.
 
 Private ()
 
 Private (const Private &rhs)
 
void setClipRule (Qt::FillRule clipRule)
 Sets the clip rule to be used for the clip path.
 
 ~KoClipPath ()
 
 ~Private ()
 

Static Public Member Functions

static void applyClipping (KoShape *clippedShape, QPainter &painter)
 Applies the clipping to the given painter.
 

Public Attributes

QPainterPath clipPath
 the compiled clip path in shape coordinates of the clipped shape
 
Qt::FillRule clipRule = Qt::WindingFill
 
KoFlake::CoordinateSystem coordinates = KoFlake::ObjectBoundingBox
 
QSizeF initialShapeSize
 initial size of clipped shape
 
QTransform initialTransformToShape
 initial transformation to shape coordinates of the clipped shape
 
QList< KoShape * > shapes
 

Private Attributes

QSharedDataPointer< Privated
 

Detailed Description

Clip path used to clip shapes.

Definition at line 34 of file KoClipPath.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KoClipPath::~Private ( )
inline

Definition at line 57 of file KoClipPath.cpp.

58 {
59 qDeleteAll(shapes);
60 shapes.clear();
61 }
QList< KoShape * > shapes

◆ KoClipPath() [1/2]

KoClipPath::KoClipPath ( QList< KoShape * > clipShapes,
KoFlake::CoordinateSystem coordinates )

Create a new shape clipping using the given clip data

Parameters
clipShapesdefine the clipping shapes, owned by KoClipPath!
coordinatesshows if ObjectBoundingBox or UserSpaceOnUse coordinate system is used.

Definition at line 105 of file KoClipPath.cpp.

106 : d(new Private())
107{
108 d->shapes = clipShapes;
109 d->coordinates = coordinates;
110 d->compileClipPath();
111}
KoFlake::CoordinateSystem coordinates
QList< KoShape * > clipShapes() const
QSharedDataPointer< Private > d
Definition KoClipPath.h:77

References clipShapes(), coordinates, and d.

◆ ~KoClipPath()

KoClipPath::~KoClipPath ( )

Definition at line 113 of file KoClipPath.cpp.

114{
115}

◆ KoClipPath() [2/2]

KoClipPath::KoClipPath ( const KoClipPath & rhs)

Definition at line 117 of file KoClipPath.cpp.

118 : d(new Private(*rhs.d))
119{
120}

Member Function Documentation

◆ applyClipping()

void KoClipPath::applyClipping ( KoShape * clippedShape,
QPainter & painter )
static

Applies the clipping to the given painter.

Definition at line 148 of file KoClipPath.cpp.

149{
150 if (shape->clipPath()) {
151 QPainterPath path = shape->clipPath()->path();
152
153 if (shape->clipPath()->coordinates() == KoFlake::ObjectBoundingBox) {
154 const QRectF shapeLocalBoundingRect = shape->outline().boundingRect();
155 path = KisAlgebra2D::mapToRect(shapeLocalBoundingRect).map(path);
156 }
157
158 if (!path.isEmpty()) {
159 painter.setClipPath(path, Qt::IntersectClip);
160 }
161 }
162}
QTransform mapToRect(const QRectF &rect)

References KoShape::clipPath(), coordinates, KisAlgebra2D::mapToRect(), KoFlake::ObjectBoundingBox, KoShape::outline(), and path().

◆ clipDataTransformation()

QTransform KoClipPath::clipDataTransformation ( KoShape * clippedShape) const

Returns the transformation from the clip data path shapes to the current document coordinates of the specified clipped shape. If the specified clipped shape is null, the transformation from clip data path shapes to shape coordinates of the clipped shape at the time of creating this clip path is being returned.

Definition at line 195 of file KoClipPath.cpp.

196{
197 if (!clippedShape)
198 return d->initialTransformToShape;
199
200 // the current transformation of the clipped shape
201 QTransform currentShapeTransform = clippedShape->absoluteTransformation();
202
203 // calculate the transformation which represents any resizing of the clipped shape
204 const QSizeF currentShapeSize = clippedShape->outline().boundingRect().size();
205 const qreal sx = currentShapeSize.width() / d->initialShapeSize.width();
206 const qreal sy = currentShapeSize.height() / d->initialShapeSize.height();
207 QTransform scaleTransform = QTransform().scale(sx, sy);
208
209 // 1. transform to initial clipped shape coordinates
210 // 2. apply resizing transformation
211 // 3. convert to current clipped shape document coordinates
212 return d->initialTransformToShape * scaleTransform * currentShapeTransform;
213}
virtual QPainterPath outline() const
Definition KoShape.cpp:630
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References KoShape::absoluteTransformation(), d, and KoShape::outline().

◆ clipPathShapes()

QList< KoPathShape * > KoClipPath::clipPathShapes ( ) const

Returns the clip path shapes.

Definition at line 174 of file KoClipPath.cpp.

175{
176 // TODO: deprecate this method!
177
179
180 Q_FOREACH (KoShape *shape, d->shapes) {
181 KoPathShape *pathShape = dynamic_cast<KoPathShape*>(shape);
182 if (pathShape) {
183 shapes << pathShape;
184 }
185 }
186
187 return shapes;
188}
The position of a path point within a path shape.
Definition KoPathShape.h:63

References d, and shapes.

◆ clipRule()

Qt::FillRule KoClipPath::clipRule ( ) const

Returns the current clip rule.

◆ clipShapes()

QList< KoShape * > KoClipPath::clipShapes ( ) const

Definition at line 190 of file KoClipPath.cpp.

191{
192 return d->shapes;
193}

References d.

◆ clone()

KoClipPath * KoClipPath::clone ( ) const

Definition at line 128 of file KoClipPath.cpp.

129{
130 return new KoClipPath(*this);
131}
KoClipPath(QList< KoShape * > clipShapes, KoFlake::CoordinateSystem coordinates)

References KoClipPath().

◆ collectShapePath()

void KoClipPath::collectShapePath ( QPainterPath * result,
const KoShape * shape )
inline

Definition at line 63 of file KoClipPath.cpp.

63 {
64 if (const KoPathShape *pathShape = dynamic_cast<const KoPathShape*>(shape)) {
65 // different shapes add up to the final path using Windind Fill rule (acc. to SVG 1.1)
66 QTransform t = pathShape->absoluteTransformation();
67 result->addPath(t.map(pathShape->outline()));
68 } else if (const KoShapeGroup *groupShape = dynamic_cast<const KoShapeGroup*>(shape)) {
69 QList<KoShape*> shapes = groupShape->shapes();
70 std::sort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
71
72 Q_FOREACH (const KoShape *child, shapes) {
73 collectShapePath(result, child);
74 }
75 }
76 }
void collectShapePath(QPainterPath *result, const KoShape *shape)
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:434

References KoShape::compareShapeZIndex().

◆ compileClipPath()

void KoClipPath::compileClipPath ( )
inline

Definition at line 79 of file KoClipPath.cpp.

80 {
82 if (clipShapes.isEmpty())
83 return;
84
85 clipPath = QPainterPath();
86 clipPath.setFillRule(Qt::WindingFill);
87
88 std::sort(clipShapes.begin(), clipShapes.end(), KoShape::compareShapeZIndex);
89
90 Q_FOREACH (KoShape *path, clipShapes) {
91 if (!path) continue;
92
94 }
95 }
QPainterPath clipPath
the compiled clip path in shape coordinates of the clipped shape

References KoShape::compareShapeZIndex().

◆ coordinates()

KoFlake::CoordinateSystem KoClipPath::coordinates ( ) const

◆ operator=()

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

Definition at line 122 of file KoClipPath.cpp.

123{
124 d = rhs.d;
125 return *this;
126}

References d.

◆ path()

QPainterPath KoClipPath::path ( ) const

Returns the current clip path with coordinates in percent of the clipped shape size.

Definition at line 164 of file KoClipPath.cpp.

165{
166 return d->clipPath;
167}

References d.

◆ pathForSize()

QPainterPath KoClipPath::pathForSize ( const QSizeF & size) const

Returns the current clip path scaled to match the specified shape size.

Definition at line 169 of file KoClipPath.cpp.

170{
171 return scaleFromPercent(size).map(d->clipPath);
172}
QTransform scaleFromPercent(const QSizeF &size)

References d, and scaleFromPercent().

◆ Private() [1/2]

KoClipPath::Private ( )
inline

Definition at line 37 of file KoClipPath.cpp.

38 : QSharedData()
39 {}

◆ Private() [2/2]

KoClipPath::Private ( const Private & rhs)
inline

Definition at line 41 of file KoClipPath.cpp.

42 : QSharedData()
43 , clipPath(rhs.clipPath)
44 , clipRule(rhs.clipRule)
45 , coordinates(rhs.coordinates)
46 , initialTransformToShape(rhs.initialTransformToShape)
47 , initialShapeSize(rhs.initialShapeSize)
48 {
49 Q_FOREACH (KoShape *shape, rhs.shapes) {
50 KoShape *clonedShape = shape->cloneShape();
51 KIS_ASSERT_RECOVER(clonedShape) { continue; }
52
53 shapes.append(clonedShape);
54 }
55 }
QTransform initialTransformToShape
initial transformation to shape coordinates of the clipped shape
QSizeF initialShapeSize
initial size of clipped shape
Qt::FillRule clipRule
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55

References KoShape::cloneShape(), and KIS_ASSERT_RECOVER.

◆ setClipRule()

void KoClipPath::setClipRule ( Qt::FillRule clipRule)

Sets the clip rule to be used for the clip path.

Definition at line 133 of file KoClipPath.cpp.

134{
135 d->clipRule = clipRule;
136}

References clipRule, and d.

Member Data Documentation

◆ clipPath

QPainterPath KoClipPath::clipPath

the compiled clip path in shape coordinates of the clipped shape

Definition at line 98 of file KoClipPath.cpp.

◆ clipRule

Qt::FillRule KoClipPath::clipRule = Qt::WindingFill

Definition at line 99 of file KoClipPath.cpp.

◆ coordinates

Definition at line 100 of file KoClipPath.cpp.

◆ d

QSharedDataPointer<Private> KoClipPath::d
private

Definition at line 77 of file KoClipPath.h.

◆ initialShapeSize

QSizeF KoClipPath::initialShapeSize

initial size of clipped shape

Definition at line 102 of file KoClipPath.cpp.

◆ initialTransformToShape

QTransform KoClipPath::initialTransformToShape

initial transformation to shape coordinates of the clipped shape

Definition at line 101 of file KoClipPath.cpp.

◆ shapes

QList<KoShape*> KoClipPath::shapes

Definition at line 97 of file KoClipPath.cpp.


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