Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShape Class Referenceabstract

#include <KoShape.h>

+ Inheritance diagram for KoShape:

Classes

class  Private
 
struct  ShapeChangeListener
 
class  SharedData
 

Public Types

enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , ShadowChanged ,
  BorderChanged , ParameterChanged , ContentChanged , TextRunAroundChanged ,
  ChildChanged , ConnectionPointChanged , ClipPathChanged , ClipMaskChanged ,
  TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
enum  RunThroughLevel { Background , Foreground }
 
enum  TextRunAroundContour { ContourBox , ContourFull , ContourOutside }
 The behavior text should do when intersecting this shape. More...
 
enum  TextRunAroundSide {
  BiggestRunAroundSide , LeftRunAroundSide , RightRunAroundSide , EnoughRunAroundSide ,
  BothRunAroundSide , NoRunAround , RunThrough
}
 The behavior text should do when intersecting this shape. More...
 

Public Member Functions

QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual QRectF boundingRect () const
 Get the bounding box of the shape.
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
virtual KoShapecloneShape () const
 creates a deep copy of the shape or shape's subtree
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
KoFilterEffectStackfilterEffectStack () const
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
virtual bool hitTest (const QPointF &position) const
 Check if the shape is hit on position.
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual QPainterPath outline () const
 
virtual QRectF outlineRect () const
 
virtual void paint (QPainter &painter) const =0
 Paint the shape fill The class extending this one is responsible for painting itself. painter is expected to be preconfigured to work in "document" pixels.
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
int runThrough () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setFilterEffectStack (KoFilterEffectStack *filterEffectStack)
 Sets the new filter effect stack, removing the old one.
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
virtual void setRunThrough (short int runThrough)
 
void setSelectable (bool selectable)
 
void setShadow (KoShapeShadow *shadow)
 Sets the new shadow, removing the old one.
 
void setShapeId (const QString &id)
 
virtual void setSize (const QSizeF &size)
 Resize the shape.
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setTextRunAroundContour (TextRunAroundContour contour)
 
void setTextRunAroundDistanceBottom (qreal distance)
 
void setTextRunAroundDistanceLeft (qreal distance)
 
void setTextRunAroundDistanceRight (qreal distance)
 
void setTextRunAroundDistanceTop (qreal distance)
 
void setTextRunAroundSide (TextRunAroundSide side, RunThroughLevel runThrough=Background)
 
void setTextRunAroundThreshold (qreal threshold)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
KoShapeShadowshadow () const
 Returns the currently set shadow or 0 if there is no shadow set.
 
virtual QPainterPath shadowOutline () const
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual QSizeF size () const
 Get the size of the shape in pt.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
TextRunAroundContour textRunAroundContour () const
 
qreal textRunAroundDistanceBottom () const
 
qreal textRunAroundDistanceLeft () const
 
qreal textRunAroundDistanceRight () const
 
qreal textRunAroundDistanceTop () const
 
TextRunAroundSide textRunAroundSide () const
 
qreal textRunAroundThreshold () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void update () const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 

Static Public Member Functions

static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 

Static Public Attributes

static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 

Protected Member Functions

 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
virtual void shapeChanged (ChangeType type, KoShape *shape=0)
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Private Member Functions

void addShapeManager (KoShapeManager *manager)
 
void removeShapeManager (KoShapeManager *manager)
 

Private Attributes

QScopedPointer< Privated
 
QSharedDataPointer< SharedDatas
 

Friends

class KoShapeManager
 

Detailed Description

Base class for all flake shapes. Shapes extend this class to allow themselves to be manipulated. This class just represents a graphical shape in the document and can be manipulated by some default tools in this library.

Due to the limited responsibility of this class, the extending object can have any data backend and is responsible for painting itself.

We strongly suggest that any extending class will use a Model View Controller (MVC) design where the View part is all in this class, as well as the one that inherits from this one. This allows the data that rests in the model to be reused in different parts of the document. For example by having two flake objects that show that same data. Or each showing a section of it.

The KoShape data is completely in postscript-points (pt) (see KoUnit for conversion methods to and from points). This image will explain the real-world use of the shape and its options.
The Rotation center can be returned with absolutePosition()

Flake objects can be created in three ways:

  • a simple new KoDerivedFlake(),
  • through an associated tool,
  • through a factory

Shape interaction notifications

We had several notification methods that allow your shape to be notified of changes in other shapes positions or rotation etc.

  1. The most general is KoShape::shapeChanged().
    a virtual method that you can use to check various changed to your shape made by tools or otherwise.
  2. for shape hierarchies the parent may receive a notification when a child was modified. This is done though KoShapeContainerModel::childChanged()
  3. any shape that is at a similar position as another shape there is collision detection. You can register your shape to be sensitive to any changes like moving or whatever to other shapes that intersect yours. Such changes will then be notified to your shape using the method from (1) You should call KoShape::setCollisionDetection(bool) to enable this.

Definition at line 91 of file KoShape.h.

Member Enumeration Documentation

◆ ChangeType

Used by shapeChanged() to select which change was made.

Enumerator
PositionChanged 

used after a setPosition()

RotationChanged 

used after a setRotation()

ScaleChanged 

used after a scale()

ShearChanged 

used after a shear()

SizeChanged 

used after a setSize()

GenericMatrixChange 

used after the matrix was changed without knowing which property explicitly changed

KeepAspectRatioChange 

used after setKeepAspectRatio()

ParentChanged 

used after a setParent()

Deleted 

the shape was deleted

StrokeChanged 

the shapes stroke has changed

BackgroundChanged 

the shapes background has changed

ShadowChanged 

the shapes shadow has changed

BorderChanged 

the shapes border has changed

ParameterChanged 

the shapes parameter has changed (KoParameterShape only)

ContentChanged 

the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape

TextRunAroundChanged 

used after a setTextRunAroundSide()

ChildChanged 

a child of a container was changed/removed. This is propagated to all parents

ConnectionPointChanged 

a connection point has changed

ClipPathChanged 

the shapes clip path has changed

ClipMaskChanged 

the shapes clip path has changed

TransparencyChanged 

the shapetransparency value has changed

Definition at line 95 of file KoShape.h.

95 {
104 Deleted,
117 };
@ RotationChanged
used after a setRotation()
Definition KoShape.h:97
@ StrokeChanged
the shapes stroke has changed
Definition KoShape.h:105
@ PositionChanged
used after a setPosition()
Definition KoShape.h:96
@ TransparencyChanged
the shapetransparency value has changed
Definition KoShape.h:116
@ Deleted
the shape was deleted
Definition KoShape.h:104
@ ClipPathChanged
the shapes clip path has changed
Definition KoShape.h:114
@ ConnectionPointChanged
a connection point has changed
Definition KoShape.h:113
@ TextRunAroundChanged
used after a setTextRunAroundSide()
Definition KoShape.h:111
@ ShearChanged
used after a shear()
Definition KoShape.h:99
@ ParentChanged
used after a setParent()
Definition KoShape.h:103
@ ContentChanged
the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
Definition KoShape.h:110
@ ClipMaskChanged
the shapes clip path has changed
Definition KoShape.h:115
@ ShadowChanged
the shapes shadow has changed
Definition KoShape.h:107
@ ParameterChanged
the shapes parameter has changed (KoParameterShape only)
Definition KoShape.h:109
@ BackgroundChanged
the shapes background has changed
Definition KoShape.h:106
@ ChildChanged
a child of a container was changed/removed. This is propagated to all parents
Definition KoShape.h:112
@ ScaleChanged
used after a scale()
Definition KoShape.h:98
@ KeepAspectRatioChange
used after setKeepAspectRatio()
Definition KoShape.h:102
@ BorderChanged
the shapes border has changed
Definition KoShape.h:108
@ SizeChanged
used after a setSize()
Definition KoShape.h:100
@ GenericMatrixChange
used after the matrix was changed without knowing which property explicitly changed
Definition KoShape.h:101

◆ ChildZOrderPolicy

Used by compareShapeZIndex() to order shapes.

Enumerator
ChildZDefault 
ChildZParentChild 

normal parent/child ordering

ChildZPassThrough 

children are considered equal to this shape

Definition at line 656 of file KoShape.h.

656 {
660 };
@ ChildZDefault
Definition KoShape.h:657
@ ChildZParentChild
normal parent/child ordering
Definition KoShape.h:658
@ ChildZPassThrough
children are considered equal to this shape
Definition KoShape.h:659

◆ PaintOrder

Enumerator
Fill 
Stroke 
Markers 

Definition at line 145 of file KoShape.h.

145 {
146 Fill,
147 Stroke,
148 Markers
149 };
@ Stroke
Definition KoShape.h:147
@ Markers
Definition KoShape.h:148

◆ RunThroughLevel

TODO

Enumerator
Background 
Foreground 

Definition at line 140 of file KoShape.h.

140 {
143 };
@ Background
Definition KoShape.h:141
@ Foreground
Definition KoShape.h:142

◆ TextRunAroundContour

The behavior text should do when intersecting this shape.

Enumerator
ContourBox 
ContourFull 

Run other text around a bounding rect of the outline.

Run other text around also on the inside

ContourOutside 

Run other text around only on the outside.

Definition at line 131 of file KoShape.h.

131 {
132 ContourBox,
135 };
@ ContourOutside
Run other text around only on the outside.
Definition KoShape.h:134
@ ContourBox
Definition KoShape.h:132
@ ContourFull
Run other text around a bounding rect of the outline.
Definition KoShape.h:133

◆ TextRunAroundSide

The behavior text should do when intersecting this shape.

Enumerator
BiggestRunAroundSide 

Run other text around the side that has the most space.

LeftRunAroundSide 

Run other text around the left side of the frame.

RightRunAroundSide 

Run other text around the right side of the frame.

EnoughRunAroundSide 

Run other text dynamically around both sides of the shape, provided there is sufficient space left.

BothRunAroundSide 

Run other text around both sides of the shape.

NoRunAround 

The text will be completely avoiding the frame by keeping the horizontal space that this frame occupies blank.

RunThrough 

The text will completely ignore the frame and layout as if it was not there.

Definition at line 120 of file KoShape.h.

120 {
128 };
@ RightRunAroundSide
Run other text around the right side of the frame.
Definition KoShape.h:123
@ BiggestRunAroundSide
Run other text around the side that has the most space.
Definition KoShape.h:121
@ BothRunAroundSide
Run other text around both sides of the shape.
Definition KoShape.h:125
@ RunThrough
The text will completely ignore the frame and layout as if it was not there.
Definition KoShape.h:127
@ NoRunAround
The text will be completely avoiding the frame by keeping the horizontal space that this frame occupi...
Definition KoShape.h:126
@ LeftRunAroundSide
Run other text around the left side of the frame.
Definition KoShape.h:122
@ EnoughRunAroundSide
Run other text dynamically around both sides of the shape, provided there is sufficient space left.
Definition KoShape.h:124

Constructor & Destructor Documentation

◆ KoShape() [1/2]

KoShape::KoShape ( )

Constructor.

Definition at line 163 of file KoShape.cpp.

164 : d(new Private()),
165 s(new SharedData)
166{
168}
QScopedPointer< Private > d
Definition KoShape.h:1135
QSharedDataPointer< SharedData > s
Definition KoShape.h:1138
void notifyChanged()
Definition KoShape.cpp:698

References notifyChanged().

◆ ~KoShape()

KoShape::~KoShape ( )
virtual

Destructor.

The shape must have already been detached from all the parents and shape managers. Otherwise we might accidentally request some RTTI information, which is not available anymore (we are in d-tor).

TL;DR: fix the code that caused this destruction without unparenting instead of trying to remove these assert!

Definition at line 176 of file KoShape.cpp.

177{
179 d->listeners.clear();
188 KIS_SAFE_ASSERT_RECOVER (!d->parent) {
189 d->parent->removeShape(this);
190 }
191
192 KIS_SAFE_ASSERT_RECOVER (d->shapeManagers.isEmpty()) {
193 Q_FOREACH (KoShapeManager *manager, d->shapeManagers) {
194 manager->shapeInterface()->notifyShapeDestructed(this);
195 }
196 d->shapeManagers.clear();
197 }
198}
KoShapeManager::ShapeInterface shapeInterface
void shapeChangedPriv(KoShape::ChangeType type)
Definition KoShape.cpp:132
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
void notifyShapeDestructed(KoShape *shape)

References d, Deleted, KIS_SAFE_ASSERT_RECOVER, KoShapeManager::ShapeInterface::notifyShapeDestructed(), shapeChangedPriv(), and KoShapeManager::shapeInterface.

◆ KoShape() [2/2]

KoShape::KoShape ( const KoShape & rhs)
protected

Definition at line 170 of file KoShape.cpp.

171 : d(new Private()),
172 s(rhs.s)
173{
174}

Member Function Documentation

◆ absoluteOutlineRect() [1/2]

QRectF KoShape::absoluteOutlineRect ( ) const
Returns
the bounding rect of the outline of the shape measured in absolute coordinate system. Please note that in contrast to boundingRect() this rect doesn't include the stroke and other insets.

Definition at line 368 of file KoShape.cpp.

369{
370 return absoluteTransformation().map(outline()).boundingRect();
371}
virtual QPainterPath outline() const
Definition KoShape.cpp:630
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References absoluteTransformation(), and outline().

◆ absoluteOutlineRect() [2/2]

QRectF KoShape::absoluteOutlineRect ( const QList< KoShape * > & shapes)
static

Same as a member function, but applies to a list of shapes and returns a united rect.

Definition at line 373 of file KoShape.cpp.

374{
375 QRectF absoluteOutlineRect;
376 Q_FOREACH (KoShape *shape, shapes) {
378 }
379 return absoluteOutlineRect;
380}
QRectF absoluteOutlineRect() const
Definition KoShape.cpp:368

References absoluteOutlineRect().

◆ absolutePosition()

QPointF KoShape::absolutePosition ( KoFlake::AnchorPosition anchor = KoFlake::Center) const

Return the position of this shape regardless of rotation/skew/scaling and regardless of this shape having a parent (being in a group) or not.

Parameters
anchorThe place on the (unaltered) shape that you want the position of.
Returns
the point that is the absolute, centered position of this shape.

Definition at line 653 of file KoShape.cpp.

654{
655 const QRectF rc = outlineRect();
656
657 QPointF point = rc.topLeft();
658
659 bool valid = false;
660 QPointF anchoredPoint = KoFlake::anchorToPoint(anchor, rc, &valid);
661 if (valid) {
662 point = anchoredPoint;
663 }
664
665 return absoluteTransformation().map(point);
666}
virtual QRectF outlineRect() const
Definition KoShape.cpp:637
KoShapeAnchor * anchor() const
KRITAFLAKE_EXPORT QPointF anchorToPoint(AnchorPosition anchor, const QRectF rect, bool *valid=0)
Definition KoFlake.cpp:329

References absoluteTransformation(), anchor(), KoFlake::anchorToPoint(), and outlineRect().

◆ absoluteTransformation()

QTransform KoShape::absoluteTransformation ( ) const

Create a matrix that describes all the transformations done on this shape.

The absolute transformation is the combined transformation of this shape and all its parents and grandparents.

Definition at line 382 of file KoShape.cpp.

383{
384 QTransform matrix;
385 // apply parents matrix to inherit any transformations done there.
386 KoShapeContainer * container = d->parent;
387 if (container) {
388 if (container->inheritsTransform(this)) {
389 matrix = container->absoluteTransformation();
390 } else {
391 QSizeF containerSize = container->size();
392 QPointF containerPos = container->absolutePosition() - QPointF(0.5 * containerSize.width(), 0.5 * containerSize.height());
393 matrix.translate(containerPos.x(), containerPos.y());
394 }
395 }
396
397 return s->localMatrix * matrix;
398}
bool inheritsTransform(const KoShape *shape) const
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:820
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
KoShapeContainer * parent() const
Definition KoShape.cpp:1039

References absolutePosition(), absoluteTransformation(), d, KoShapeContainer::inheritsTransform(), parent(), s, and size().

◆ addDependee()

bool KoShape::addDependee ( KoShape * shape)

Adds a shape which depends on this shape. Making a shape dependent on this one means it will get shapeChanged() called on each update of this shape.

If this shape already depends on the given shape, establishing the dependency is refused to prevent circular dependencies.

Parameters
shapethe shape which depends on this shape
Returns
true if dependency could be established, otherwise false
See also
removeDependee(), hasDependee()

Definition at line 1221 of file KoShape.cpp.

1222{
1223 if (! shape)
1224 return false;
1225
1226 // refuse to establish a circular dependency
1227 if (shape->hasDependee(this))
1228 return false;
1229
1230 if (! d->dependees.contains(shape))
1231 d->dependees.append(shape);
1232
1233 return true;
1234}
bool hasDependee(KoShape *shape) const
Returns if the given shape is dependent on this shape.
Definition KoShape.cpp:1243

References d, and hasDependee().

◆ additionalAttribute()

QString KoShape::additionalAttribute ( const QString & name) const

Get additional attribute

Parameters
nameThe name of the attribute in the following form prefix:tag e.g. presentation:placeholder
Returns
The value of the attribute if it exists or a null string if not found.

Definition at line 1279 of file KoShape.cpp.

1280{
1281 return s->additionalAttributes.value(name);
1282}
QString name() const
Definition KoShape.cpp:1150

References name(), and s.

◆ addShapeChangeListener()

void KoShape::addShapeChangeListener ( KoShape::ShapeChangeListener * listener)

Definition at line 1360 of file KoShape.cpp.

1361{
1362
1363 KIS_SAFE_ASSERT_RECOVER_RETURN(!d->listeners.contains(listener));
1364 listener->registerShape(this);
1365 d->listeners.append(listener);
1366}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
void registerShape(KoShape *shape)
Definition KoShape.cpp:1337

References d, KIS_SAFE_ASSERT_RECOVER_RETURN, and KoShape::ShapeChangeListener::registerShape().

◆ addShapeManager()

void KoShape::addShapeManager ( KoShapeManager * manager)
private

Definition at line 148 of file KoShape.cpp.

149{
150 d->shapeManagers.insert(manager);
151}

References d.

◆ anchor()

KoShapeAnchor * KoShape::anchor ( ) const

Return the KoShapeAnchor, or 0

◆ applyAbsoluteTransformation()

void KoShape::applyAbsoluteTransformation ( const QTransform & matrix)

Applies a transformation to this shape.

The transformation given is relative to the global coordinate system, i.e. the document. This is a convenience function to apply a global transformation to this shape.

See also
applyTransformation
Parameters
matrixthe transformation matrix to apply

Definition at line 400 of file KoShape.cpp.

401{
402 QTransform globalMatrix = absoluteTransformation();
403 // the transformation is relative to the global coordinate system
404 // but we want to change the local matrix, so convert the matrix
405 // to be relative to the local coordinate system
406 QTransform transformMatrix = globalMatrix * matrix * globalMatrix.inverted();
407 applyTransformation(transformMatrix);
408}
void applyTransformation(const QTransform &matrix)
Definition KoShape.cpp:410

References absoluteTransformation(), and applyTransformation().

◆ applyTransformation()

void KoShape::applyTransformation ( const QTransform & matrix)

Applies a transformation to this shape.

The transformation given is relative to the shape coordinate system.

Parameters
matrixthe transformation matrix to apply

Definition at line 410 of file KoShape.cpp.

411{
412 s->localMatrix = matrix * s->localMatrix;
415}

References GenericMatrixChange, notifyChanged(), s, and shapeChangedPriv().

◆ background()

QSharedPointer< KoShapeBackground > KoShape::background ( ) const
virtual

Return the brush used to paint the background of this shape with. A QBrush can have a plain color, be fully transparent or have a complex fill. setting such a brush will allow the shape to fill itself using that brush and will be able to tell if its transparent or not.

Returns
the background-brush

Reimplemented in KoSvgTextShape.

Definition at line 926 of file KoShape.cpp.

927{
928
930
931 if (!s->inheritBackground) {
932 bg = s->fill;
933 } else if (parent()) {
934 bg = parent()->background();
935 }
936
937 return bg;
938}
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:926

References background(), parent(), and s.

◆ boundingRect() [1/2]

QRectF KoShape::boundingRect ( ) const
virtual

Get the bounding box of the shape.

This includes the line width and the shadow of the shape

Returns
the bounding box of the shape

Reimplemented in KoPathShape, KoSelection, KoShapeGroup, KoShapeLayer, KoSvgTextShape, and KisNodeShape.

Definition at line 335 of file KoShape.cpp.

336{
337
338 QTransform transform = absoluteTransformation();
339 QRectF bb = outlineRect();
340 if (s->stroke) {
341 KoInsets insets;
342 s->stroke->strokeInsets(this, insets);
343 bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
344 }
345 bb = transform.mapRect(bb);
346 if (s->shadow) {
347 KoInsets insets;
348 s->shadow->insets(insets);
349 bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
350 }
351 if (s->filterEffectStack) {
352 QRectF clipRect = s->filterEffectStack->clipRectForBoundingRect(outlineRect());
353 bb |= transform.mapRect(clipRect);
354 }
355
356 return bb;
357}
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
Definition KoShape.cpp:1145
qreal bottom
Bottom inset.
Definition KoInsets.h:50
qreal right
Right inset.
Definition KoInsets.h:52
qreal top
Top inset.
Definition KoInsets.h:49
qreal left
Left inset.
Definition KoInsets.h:51

References absoluteTransformation(), KoInsets::bottom, KoInsets::left, outlineRect(), KoInsets::right, s, KoInsets::top, and transform().

◆ boundingRect() [2/2]

QRectF KoShape::boundingRect ( const QList< KoShape * > & shapes)
static

Get the united bounding box of a group of shapes. This is a utility function used in many places in Krita.

Definition at line 359 of file KoShape.cpp.

360{
361 QRectF boundingRect;
362 Q_FOREACH (KoShape *shape, shapes) {
363 boundingRect |= shape->boundingRect();
364 }
365 return boundingRect;
366}
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335

References boundingRect().

◆ childZOrderPolicy()

KoShape::ChildZOrderPolicy KoShape::childZOrderPolicy ( )
virtual

Returns if during compareShapeZIndex() how this shape portrays the values of its children. The default behaviour is to let this shape's z values take the place of its children's values, so you get a parent/child relationship. The children are naturally still ordered relatively to their z values

But for special cases (like Calligra's TextShape) it can be overloaded to return ChildZPassThrough which means the children keep their own z values

Returns
the z order policy of this shape

Definition at line 429 of file KoShape.cpp.

430{
431 return ChildZDefault;
432}

References ChildZDefault.

◆ clipMask()

KoClipMask * KoShape::clipMask ( ) const

Returns the currently set clip mask or 0 if there is no clip mask set.

Definition at line 1140 of file KoShape.cpp.

1141{
1142 return s->clipMask.data();
1143}

References s.

◆ clipPath()

KoClipPath * KoShape::clipPath ( ) const

Returns the currently set clip path or 0 if there is no clip path set.

Definition at line 1128 of file KoShape.cpp.

1129{
1130 return s->clipPath.data();
1131}

References KoClipPath::clipPath, and s.

◆ cloneShape()

KoShape * KoShape::cloneShape ( ) const
virtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented in KoPathShape, KoShapeGroup, KoSvgTextShape, KisReferenceImage, ImageShape, EllipseShape, EnhancedPathShape, RectangleShape, SpiralShape, StarShape, and KarbonCalligraphicShape.

Definition at line 200 of file KoShape.cpp.

201{
202 KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "not implemented!");
203 qWarning() << shapeId() << "cannot be cloned";
204 return 0;
205}
QString shapeId() const
Definition KoShape.cpp:1057
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP, and shapeId().

◆ cloneShapeAndBakeAbsoluteTransform()

KoShape * KoShape::cloneShapeAndBakeAbsoluteTransform ( ) const

creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.

After cloning clonedShape->transformation() is equal to this->absoluteTransformation(), even though the new shape has no parents.

This is just a convenience wrapper for cloneShape()

Returns
cloned shape

The shape is cloned without its parent's transformation, so we should adjust it manually.

Definition at line 207 of file KoShape.cpp.

208{
209 KoShape *clonedShape = this->cloneShape();
210
215 KoShape *oldParentShape = this->parent();
216 if (oldParentShape && !oldParentShape->absoluteTransformation().isIdentity()) {
217 clonedShape->applyAbsoluteTransformation(oldParentShape->absoluteTransformation());
218 }
219
220 return clonedShape;
221}
void applyAbsoluteTransformation(const QTransform &matrix)
Definition KoShape.cpp:400
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200

References absoluteTransformation(), applyAbsoluteTransformation(), cloneShape(), and parent().

◆ compareShapeZIndex()

bool KoShape::compareShapeZIndex ( KoShape * s1,
KoShape * s2 )
static

This is a method used to sort a list using the STL sorting methods.

Parameters
s1the first shape
s2the second shape

WARNING: Our definition of zIndex is not yet compatible with SVG2's definition. In SVG stacking context of groups with the same zIndex are merged, while in Krita the contents of groups is never merged. One group will always below than the other. Therefore, when zIndex of two groups inside the same parent coincide, the resulting painting order in Krita is UNDEFINED.

To avoid this trouble we use KoShapeReorderCommand::mergeInShape() inside KoShapeCreateCommand.

The algorithm below doesn't correctly handle the case when the two pointers actually point to the same shape. So just check it in advance to guarantee strict weak ordering relation requirement

Definition at line 434 of file KoShape.cpp.

435{
454 if (s1 == s2) return false;
455
456
457 // First sort according to runThrough which is sort of a master level
458 KoShape *parentShapeS1 = s1->parent();
459 KoShape *parentShapeS2 = s2->parent();
460 int runThrough1 = s1->runThrough();
461 int runThrough2 = s2->runThrough();
462 while (parentShapeS1) {
463 if (parentShapeS1->childZOrderPolicy() == KoShape::ChildZParentChild) {
464 runThrough1 = parentShapeS1->runThrough();
465 } else {
466 runThrough1 = runThrough1 + parentShapeS1->runThrough();
467 }
468 parentShapeS1 = parentShapeS1->parent();
469 }
470
471 while (parentShapeS2) {
472 if (parentShapeS2->childZOrderPolicy() == KoShape::ChildZParentChild) {
473 runThrough2 = parentShapeS2->runThrough();
474 } else {
475 runThrough2 = runThrough2 + parentShapeS2->runThrough();
476 }
477 parentShapeS2 = parentShapeS2->parent();
478 }
479
480 if (runThrough1 > runThrough2) {
481 return false;
482 }
483 if (runThrough1 < runThrough2) {
484 return true;
485 }
486
487 // If on the same runThrough level then the zIndex is all that matters.
488 //
489 // We basically walk up through the parents until we find a common base parent
490 // To do that we need two loops where the inner loop walks up through the parents
491 // of s2 every time we step up one parent level on s1
492 //
493 // We don't update the index value until after we have seen that it's not a common base
494 // That way we ensure that two children of a common base are sorted according to their respective
495 // z value
496 bool foundCommonParent = false;
497 int index1 = s1->zIndex();
498 int index2 = s2->zIndex();
499 parentShapeS1 = s1;
500 parentShapeS2 = s2;
501 while (parentShapeS1 && !foundCommonParent) {
502 parentShapeS2 = s2;
503 index2 = parentShapeS2->zIndex();
504 while (parentShapeS2) {
505 if (parentShapeS2 == parentShapeS1) {
506 foundCommonParent = true;
507 break;
508 }
509 if (parentShapeS2->childZOrderPolicy() == KoShape::ChildZParentChild) {
510 index2 = parentShapeS2->zIndex();
511 }
512 parentShapeS2 = parentShapeS2->parent();
513 }
514
515 if (!foundCommonParent) {
516 if (parentShapeS1->childZOrderPolicy() == KoShape::ChildZParentChild) {
517 index1 = parentShapeS1->zIndex();
518 }
519 parentShapeS1 = parentShapeS1->parent();
520 }
521 }
522
523 // If the one shape is a parent/child of the other then sort so.
524 if (s1 == parentShapeS2) {
525 return true;
526 }
527 if (s2 == parentShapeS1) {
528 return false;
529 }
530
531 // If we went that far then the z-Index is used for sorting.
532 return index1 < index2;
533}
QPointF s1
QPointF s2
int runThrough() const
Definition KoShape.cpp:962
virtual ChildZOrderPolicy childZOrderPolicy()
Definition KoShape.cpp:429
qint16 zIndex() const
Definition KoShape.cpp:600

References childZOrderPolicy(), ChildZParentChild, parent(), runThrough(), s1, s2, and zIndex().

◆ copySettings()

void KoShape::copySettings ( const KoShape * shape)

Copy all the settings from the parameter shape and apply them to this shape. Settings like the position and rotation to visible and locked. The parent is a notable exclusion.

Parameters
shapethe shape to use as original

Definition at line 679 of file KoShape.cpp.

680{
681 s->size = shape->size();
682 s->zIndex = shape->zIndex();
683 s->visible = shape->isVisible(false);
684
685 // Ensure printable is true by default
686 if (!s->visible)
687 s->printable = true;
688 else
689 s->printable = shape->isPrintable();
690
691 s->geometryProtected = shape->isGeometryProtected();
692 s->protectContent = shape->isContentProtected();
693 s->selectable = shape->isSelectable();
694 s->keepAspect = shape->keepAspectRatio();
695 s->localMatrix = shape->s->localMatrix;
696}
bool isContentProtected() const
Definition KoShape.cpp:1034
bool isSelectable() const
Definition KoShape.cpp:1014
bool isGeometryProtected() const
Definition KoShape.cpp:1024
bool isPrintable() const
Definition KoShape.cpp:1001
bool keepAspectRatio() const
Definition KoShape.cpp:1052
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979

References isContentProtected(), isGeometryProtected(), isPrintable(), isSelectable(), isVisible(), keepAspectRatio(), s, size(), and zIndex().

◆ createHandlePainterHelperDocument()

KisHandlePainterHelper KoShape::createHandlePainterHelperDocument ( QPainter * painter,
KoShape * shape,
qreal handleRadius,
int decorationThickness )
static

Definition at line 1189 of file KoShape.cpp.

1190{
1191 const QTransform originalPainterTransform = painter->transform();
1192
1193 painter->setTransform(shape->absoluteTransformation() *
1194 painter->transform());
1195
1196 // move c-tor
1197 return KisHandlePainterHelper(painter, originalPainterTransform, handleRadius, decorationThickness);
1198}
The KisHandlePainterHelper class is a special helper for painting handles around objects....

References absoluteTransformation().

◆ createHandlePainterHelperView()

KisHandlePainterHelper KoShape::createHandlePainterHelperView ( QPainter * painter,
KoShape * shape,
const KoViewConverter & converter,
qreal handleRadius = 0.0,
int decorationThickness = 1 )
static

A convenience method that creates a handles helper with applying transformations at the same time. Please note that you shouldn't save/restore additionally. All the work on restoring original painter's transformations is done by the helper.

Definition at line 1177 of file KoShape.cpp.

1178{
1179 const QTransform originalPainterTransform = painter->transform();
1180
1181 painter->setTransform(shape->absoluteTransformation() *
1182 converter.documentToView() *
1183 painter->transform());
1184
1185 // move c-tor
1186 return KisHandlePainterHelper(painter, originalPainterTransform, handleRadius, decorationThickness);
1187}
virtual QPointF documentToView(const QPointF &documentPoint) const

References absoluteTransformation(), and KoViewConverter::documentToView().

◆ defaultPaintOrder()

QVector< KoShape::PaintOrder > KoShape::defaultPaintOrder ( )
static

default paint order as per SVG specification

Returns
constant value of {Fill, Stroke, Markers}

Definition at line 784 of file KoShape.cpp.

785{
786 static QVector<PaintOrder> order = {Fill, Stroke, Markers};
787 return order;
788}

References Fill, Markers, and Stroke.

◆ dependees()

QList< KoShape * > KoShape::dependees ( ) const

Returns list of shapes depending on this shape.

Definition at line 1248 of file KoShape.cpp.

1249{
1250 return d->dependees;
1251}

References d.

◆ documentToShape() [1/2]

QPointF KoShape::documentToShape ( const QPointF & point) const

Transforms point from document coordinates to shape coordinates.

Parameters
pointin document coordinates
Returns
point in shape coordinates

Definition at line 1211 of file KoShape.cpp.

1212{
1213 return absoluteTransformation().inverted().map(point);
1214}

References absoluteTransformation().

◆ documentToShape() [2/2]

QRectF KoShape::documentToShape ( const QRectF & rect) const

Transform rect from document coordinates to shape coordinates.

Parameters
rectin document coordinates
Returns
rect in shape coordinates

Definition at line 1216 of file KoShape.cpp.

1217{
1218 return absoluteTransformation().inverted().mapRect(rect);
1219}

References absoluteTransformation().

◆ filterEffectStack()

KoFilterEffectStack * KoShape::filterEffectStack ( ) const

Returns the filter effect stack of the shape

Returns
the list of filter effects applied on the shape when rendering.

Definition at line 1294 of file KoShape.cpp.

1295{
1296 return s->filterEffectStack;
1297}

References s.

◆ hasAdditionalAttribute()

bool KoShape::hasAdditionalAttribute ( const QString & name) const

Check if additional attribute is set

Parameters
nameThe name of the attribute in the following form prefix:tag e.g. presentation:placeholder
Returns
true if there is a attribute with prefix:tag set, false otherwise

Definition at line 1274 of file KoShape.cpp.

1275{
1276 return s->additionalAttributes.contains(name);
1277}

References name(), and s.

◆ hasCommonParent()

bool KoShape::hasCommonParent ( const KoShape * shape) const
Returns
true if this shape has a common parent with shape

Definition at line 581 of file KoShape.cpp.

582{
583 const KoShape *thisShape = this;
584 while (thisShape) {
585
586 const KoShape *otherShape = shape;
587 while (otherShape) {
588 if (thisShape == otherShape) {
589 return true;
590 }
591 otherShape = otherShape->parent();
592 }
593
594 thisShape = thisShape->parent();
595 }
596
597 return false;
598}

References parent().

◆ hasDependee()

bool KoShape::hasDependee ( KoShape * shape) const

Returns if the given shape is dependent on this shape.

Definition at line 1243 of file KoShape.cpp.

1244{
1245 return d->dependees.contains(shape);
1246}

References d.

◆ hasTransparency()

bool KoShape::hasTransparency ( ) const
virtual

Returns true if there is some transparency, false if the shape is fully opaque. The default implementation will just return if the background has some transparency, you should override it and always return true if your shape is not square.

Returns
if the shape is (partly) transparent.

Definition at line 715 of file KoShape.cpp.

716{
718
719 return !bg || bg->hasTransparency() || s->transparency > 0.0;
720}

References background(), and s.

◆ hitTest()

bool KoShape::hitTest ( const QPointF & position) const
virtual

Check if the shape is hit on position.

Parameters
positionthe position where the user clicked.
Returns
true when it hits.

Reimplemented in KoPathShape, KoSelection, KoShapeGroup, and KoShapeLayer.

Definition at line 308 of file KoShape.cpp.

309{
310 if (d->parent && d->parent->isClipped(this) && !d->parent->hitTest(position))
311 return false;
312
313 QPointF point = absoluteTransformation().inverted().map(position);
314 QRectF bb = outlineRect();
315
316 if (s->stroke) {
317 KoInsets insets;
318 s->stroke->strokeInsets(this, insets);
319 bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
320 }
321 if (bb.contains(point))
322 return true;
323
324 // if there is no shadow we can as well just leave
325 if (! s->shadow)
326 return false;
327
328 // the shadow has an offset to the shape, so we simply
329 // check if the position minus the shadow offset hits the shape
330 point = absoluteTransformation().inverted().map(position - s->shadow->offset());
331
332 return bb.contains(point);
333}
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825

References absoluteTransformation(), KoInsets::bottom, d, KoInsets::left, outlineRect(), position(), KoInsets::right, s, and KoInsets::top.

◆ hyperLink()

QString KoShape::hyperLink ( ) const

Return the hyperlink for this shape.

Definition at line 1320 of file KoShape.cpp.

1321{
1322 return s->hyperLink;
1323}

References s.

◆ inheritBackground()

bool KoShape::inheritBackground ( ) const

inheritBackground shows if the shape inherits background from its parent

Returns
true if the shape inherits the fill

Definition at line 949 of file KoShape.cpp.

950{
951 return s->inheritBackground;
952}

References s.

◆ inheritPaintOrder()

bool KoShape::inheritPaintOrder ( ) const

inheritPaintOrder

Returns
whether the paint order is inherited. By default it is.

Definition at line 795 of file KoShape.cpp.

796{
797 return s->inheritPaintOrder;
798}

References s.

◆ inheritsTransformFromAny()

bool KoShape::inheritsTransformFromAny ( const QList< KoShape * > ancestorsInQuestion) const

inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.

Returns
true if there is a (transitive) transformation-wise parent found in ancestorsInQuestion

Definition at line 559 of file KoShape.cpp.

560{
561 bool result = false;
562
563 KoShape *shape = const_cast<KoShape*>(this);
564 while (shape) {
565 KoShapeContainer *parent = shape->parent();
566 if (parent && !parent->inheritsTransform(shape)) {
567 break;
568 }
569
570 if (ancestorsInQuestion.contains(shape)) {
571 result = true;
572 break;
573 }
574
575 shape = parent;
576 }
577
578 return result;
579}

References KoShapeContainer::inheritsTransform(), and parent().

◆ inheritStroke()

bool KoShape::inheritStroke ( ) const

inheritStroke shows if the shape inherits the stroke from its parent

Returns
true if the shape inherits the stroke style

Definition at line 1098 of file KoShape.cpp.

1099{
1100 return s->inheritStroke;
1101}

References s.

◆ isContentProtected()

bool KoShape::isContentProtected ( ) const

Returns current content protection state of this shape. Content protection is a hint for tools to disallow the user editing the content.

Returns
current content protection state of this shape.
See also
isGeometryProtected(), isSelectable(), isVisible()

Definition at line 1034 of file KoShape.cpp.

1035{
1036 return s->protectContent;
1037}

References s.

◆ isGeometryProtected()

bool KoShape::isGeometryProtected ( ) const

Returns current geometry protection state of this shape. The geometry being protected means the user can not change shape or position of the shape. This includes any matrix operation such as rotation.

Returns
current geometry protection state of this shape.
See also
isContentProtected(), isSelectable(), isVisible()

Definition at line 1024 of file KoShape.cpp.

1025{
1026 return s->geometryProtected;
1027}

References s.

◆ isPrintable()

bool KoShape::isPrintable ( ) const

Returns the current printable state of this shape.

A shape can be visible but not printable, not printable and not visible or visible and printable, but not invisible and still printable.

Returns
current printable state of this shape.

Definition at line 1001 of file KoShape.cpp.

1002{
1003 if (s->visible)
1004 return s->printable;
1005 else
1006 return false;
1007}

References s.

◆ isSelectable()

bool KoShape::isSelectable ( ) const

Returns if this shape can be selected by the user.

Returns
true only when the object is selectable.
See also
isGeometryProtected(), isContentProtected(), isVisible()

Definition at line 1014 of file KoShape.cpp.

1015{
1016 return s->selectable;
1017}

References s.

◆ isShapeEditable()

bool KoShape::isShapeEditable ( bool recursive = true) const
virtual

checks recursively if the shape or one of its parents is not visible or locked

Reimplemented in KisShapeLayer.

Definition at line 1165 of file KoShape.cpp.

1166{
1167 if (!s->visible || s->geometryProtected)
1168 return false;
1169
1170 if (recursive && d->parent) {
1171 return d->parent->isShapeEditable(true);
1172 }
1173
1174 return true;
1175}

References d, and s.

◆ isVisible()

bool KoShape::isVisible ( bool recursive = true) const

Returns current visibility state of this shape. Being visible means being painted, as well as being used for things like guidelines or searches.

Parameters
recursivewhen true, checks visibility recursively
Returns
current visibility state of this shape.
See also
isGeometryProtected(), isContentProtected(), isSelectable()

Definition at line 979 of file KoShape.cpp.

980{
981 if (!recursive)
982 return s->visible;
983
984 if (!s->visible)
985 return false;
986
987 KoShapeContainer * parentShape = parent();
988
989 if (parentShape) {
990 return parentShape->isVisible(true);
991 }
992
993 return true;
994}

References isVisible(), parent(), and s.

◆ keepAspectRatio()

bool KoShape::keepAspectRatio ( ) const

Setting the shape to keep its aspect-ratio has the effect that user-scaling will keep the width/height ratio intact so as not to distort shapes that rely on that ratio.

Returns
whether to keep aspect ratio of this shape

Definition at line 1052 of file KoShape.cpp.

1053{
1054 return s->keepAspect;
1055}

References s.

◆ linearizeSubtree()

QList< KoShape * > KoShape::linearizeSubtree ( const QList< KoShape * > & shapes)
static

Definition at line 1381 of file KoShape.cpp.

1382{
1383 QList<KoShape *> result;
1384
1385 Q_FOREACH (KoShape *shape, shapes) {
1386 result << shape;
1387
1388 KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
1389 if (container) {
1390 result << linearizeSubtree(container->shapes());
1391 }
1392 }
1393
1394 return result;
1395}
QList< KoShape * > shapes() const
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1381

References linearizeSubtree(), and KoShapeContainer::shapes().

◆ linearizeSubtreeSorted()

QList< KoShape * > KoShape::linearizeSubtreeSorted ( const QList< KoShape * > & shapes)
static

Definition at line 1397 of file KoShape.cpp.

1398{
1399 QList<KoShape*> sortedShapes = shapes;
1400 std::sort(sortedShapes.begin(), sortedShapes.end(), KoShape::compareShapeZIndex);
1401
1402 QList<KoShape *> result;
1403
1404 Q_FOREACH (KoShape *shape, sortedShapes) {
1405 result << shape;
1406
1407 KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
1408 if (container) {
1409 result << linearizeSubtreeSorted(container->shapes());
1410 }
1411 }
1412
1413 return result;
1414}
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:434
static QList< KoShape * > linearizeSubtreeSorted(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1397

References compareShapeZIndex(), linearizeSubtreeSorted(), and KoShapeContainer::shapes().

◆ listeners()

QList< KoShape::ShapeChangeListener * > KoShape::listeners ( ) const
protected

Definition at line 1376 of file KoShape.cpp.

1377{
1378 return d->listeners;
1379}

References d.

◆ minimumHeight()

qreal KoShape::minimumHeight ( ) const

Return the minimum height of the shape.

Returns
the minimum height of the shape. Default is 0.0.

◆ name()

QString KoShape::name ( ) const

Returns the name of the shape.

Returns
the shapes name

Definition at line 1150 of file KoShape.cpp.

1151{
1152 return s->name;
1153}

References s.

◆ notifyChanged()

void KoShape::notifyChanged ( )

Update the position of the shape in the tree of the KoShapeManager.

Definition at line 698 of file KoShape.cpp.

699{
700 Q_FOREACH (KoShapeManager * manager, d->shapeManagers) {
701 manager->notifyShapeChanged(this);
702 }
703}
void notifyShapeChanged(KoShape *shape)

References d, and KoShapeManager::notifyShapeChanged().

◆ outline()

QPainterPath KoShape::outline ( ) const
virtual

returns the outline of the shape in the form of a path. The outline returned will always be relative to the position() of the shape, so moving the shape will not alter the result. The outline is used to draw the stroke on, for example.

Returns
the outline of the shape in the form of a path.

Reimplemented in KoPathShape, and KoSvgTextShape.

Definition at line 630 of file KoShape.cpp.

631{
632 QPainterPath path;
633 path.addRect(outlineRect());
634 return path;
635}

References outlineRect().

◆ outlineRect()

QRectF KoShape::outlineRect ( ) const
virtual

returns the outline of the shape in the form of a rect. The outlineRect returned will always be relative to the position() of the shape, so moving the shape will not alter the result. The outline is used to calculate the boundingRect.

Returns
the outline of the shape in the form of a rect.

Reimplemented in KoPathShape, KoSelection, KoShapeGroup, and KoSvgTextShape.

Definition at line 637 of file KoShape.cpp.

638{
639 const QSizeF s = size();
640 return QRectF(QPointF(0, 0), QSizeF(qMax(s.width(), qreal(0.0001)),
641 qMax(s.height(), qreal(0.0001))));
642}

References s, and size().

◆ paint()

virtual void KoShape::paint ( QPainter & painter) const
pure virtual

Paint the shape fill The class extending this one is responsible for painting itself. painter is expected to be preconfigured to work in "document" pixels.

Parameters
painterused for painting the shape

Implemented in KisReferenceImage, KoPathShape, KoSelection, KoShapeContainer, KoSvgTextShape, KisNodeShape, and ImageShape.

◆ paintMarkers()

void KoShape::paintMarkers ( QPainter & painter) const
virtual

paintStroke paints the shape's markers

Parameters
painterused for painting the shape
See also
applyConversion()

Definition at line 230 of file KoShape.cpp.

231{
232 if (stroke()) {
233 stroke()->paintMarkers(this, painter);
234 }
235}
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067

References stroke().

◆ paintOrder()

QVector< KoShape::PaintOrder > KoShape::paintOrder ( ) const
virtual

paintOrder

Returns
vector of paint orders, will always be 3 big and contain a fill, stroke and marker entry.

Reimplemented in KoSvgTextShape.

Definition at line 773 of file KoShape.cpp.

774{
776 if (!s->inheritPaintOrder) {
777 order = s->paintOrder;
778 } else if (parent()) {
779 order = parent()->paintOrder();
780 }
781 return order;
782}
virtual QVector< PaintOrder > paintOrder() const
paintOrder
Definition KoShape.cpp:773
static QVector< PaintOrder > defaultPaintOrder()
default paint order as per SVG specification
Definition KoShape.cpp:784

References defaultPaintOrder(), paintOrder(), parent(), and s.

◆ paintStroke()

void KoShape::paintStroke ( QPainter & painter) const
virtual

paintStroke paints the shape's stroked outline

Parameters
painterused for painting the shape
See also
applyConversion()

Reimplemented in KoSvgTextShape.

Definition at line 223 of file KoShape.cpp.

224{
225 if (stroke()) {
226 stroke()->paint(this, painter);
227 }
228}

References stroke().

◆ parent()

KoShapeContainer * KoShape::parent ( ) const

Returns the parent, or 0 if there is no parent.

Returns
the parent, or 0 if there is no parent.

Definition at line 1039 of file KoShape.cpp.

1040{
1041 return d->parent;
1042}

References d, and parent().

◆ position()

QPointF KoShape::position ( ) const

Get the position of the shape in pt.

Returns
the position of the shape

Definition at line 825 of file KoShape.cpp.

826{
827 QPointF center = outlineRect().center();
828 return s->localMatrix.map(center) - center;
829}

References outlineRect(), and s.

◆ removeAdditionalAttribute()

void KoShape::removeAdditionalAttribute ( const QString & name)

Remove additional attribute

Parameters
nameThe name of the attribute in the following form prefix:tag e.g. presentation:placeholder

Definition at line 1269 of file KoShape.cpp.

1270{
1271 s->additionalAttributes.remove(name);
1272}

References name(), and s.

◆ removeAdditionalStyleAttribute()

void KoShape::removeAdditionalStyleAttribute ( const char * name)

Definition at line 1289 of file KoShape.cpp.

1290{
1291 s->additionalStyleAttributes.remove(name);
1292}

References name(), and s.

◆ removeDependee()

void KoShape::removeDependee ( KoShape * shape)

Removes as shape depending on this shape.

See also
addDependee(), hasDependee()

Definition at line 1236 of file KoShape.cpp.

1237{
1238 int index = d->dependees.indexOf(shape);
1239 if (index >= 0)
1240 d->dependees.removeAt(index);
1241}

References d.

◆ removeShapeChangeListener()

void KoShape::removeShapeChangeListener ( KoShape::ShapeChangeListener * listener)

Definition at line 1368 of file KoShape.cpp.

1369{
1370
1371 KIS_SAFE_ASSERT_RECOVER_RETURN(d->listeners.contains(listener));
1372 d->listeners.removeAll(listener);
1373 listener->unregisterShape(this);
1374}
void unregisterShape(KoShape *shape)
Definition KoShape.cpp:1343

References d, KIS_SAFE_ASSERT_RECOVER_RETURN, and KoShape::ShapeChangeListener::unregisterShape().

◆ removeShapeManager()

void KoShape::removeShapeManager ( KoShapeManager * manager)
private

Definition at line 153 of file KoShape.cpp.

154{
155 d->shapeManagers.remove(manager);
156}

References d.

◆ rotate()

void KoShape::rotate ( qreal angle)

Rotate the shape (relative)

The shape will be rotated from the current rotation using the center of the shape using the size()

Parameters
anglechange the angle of rotation increasing it with 'angle' degrees

Definition at line 250 of file KoShape.cpp.

251{
252 QPointF center = s->localMatrix.map(QPointF(0.5 * size().width(), 0.5 * size().height()));
253 QTransform rotateMatrix;
254 rotateMatrix.translate(center.x(), center.y());
255 rotateMatrix.rotate(angle);
256 rotateMatrix.translate(-center.x(), -center.y());
257 s->localMatrix = s->localMatrix * rotateMatrix;
258
261}

References notifyChanged(), RotationChanged, s, shapeChangedPriv(), and size().

◆ rotation()

qreal KoShape::rotation ( ) const

Return the current rotation in degrees. It returns NaN if the shape has a shearing or scaling transformation applied.

Definition at line 800 of file KoShape.cpp.

801{
802 // try to extract the rotation angle out of the local matrix
803 // if it is a pure rotation matrix
804
805 // check if the matrix has shearing mixed in
806 if (fabs(fabs(s->localMatrix.m12()) - fabs(s->localMatrix.m21())) > 1e-10)
807 return std::numeric_limits<qreal>::quiet_NaN();
808 // check if the matrix has scaling mixed in
809 if (fabs(s->localMatrix.m11() - s->localMatrix.m22()) > 1e-10)
810 return std::numeric_limits<qreal>::quiet_NaN();
811
812 // calculate the angle from the matrix elements
813 qreal angle = atan2(-s->localMatrix.m21(), s->localMatrix.m11()) * 180.0 / M_PI;
814 if (angle < 0.0)
815 angle += 360.0;
816
817 return angle;
818}
#define M_PI
Definition kis_global.h:111
KRITAIMAGE_EXPORT qreal atan2(qreal y, qreal x)
atan2 replacement

References M_PI, and s.

◆ runThrough()

int KoShape::runThrough ( ) const

Retrieve the run through property of this shape. The run through property is used to determine if the shape is behind, inside or before text.

Returns
the run through of this shape.

Definition at line 962 of file KoShape.cpp.

963{
964 return s->runThrough;
965}

References s.

◆ scale()

void KoShape::scale ( qreal sx,
qreal sy )

Scale the shape using the zero-point which is the top-left corner.

See also
position()
Parameters
sxscale in x direction
syscale in y direction

Definition at line 237 of file KoShape.cpp.

238{
239 QPointF pos = position();
240 QTransform scaleMatrix;
241 scaleMatrix.translate(pos.x(), pos.y());
242 scaleMatrix.scale(sx, sy);
243 scaleMatrix.translate(-pos.x(), -pos.y());
244 s->localMatrix = s->localMatrix * scaleMatrix;
245
248}

References notifyChanged(), position(), s, ScaleChanged, and shapeChangedPriv().

◆ setAbsolutePosition()

void KoShape::setAbsolutePosition ( const QPointF & newPosition,
KoFlake::AnchorPosition anchor = KoFlake::Center )

Move this shape to an absolute position where the end location will be the same regardless of the shape's rotation/skew/scaling and regardless of this shape having a parent (being in a group) or not.
The newPosition is going to be the center of the shape. This has the convenient effect that:

shape->setAbsolutePosition(QPointF(0,0));
shape->rotate(45);

Will result in the same visual position of the shape as the opposite:

shape->rotate(45);
shape->setAbsolutePosition(QPointF(0,0));
Parameters
newPositionthe new absolute center of the shape.
anchorThe place on the (unaltered) shape that you set the position of.

Definition at line 668 of file KoShape.cpp.

669{
670 QPointF currentAbsPosition = absolutePosition(anchor);
671 QPointF translate = newPosition - currentAbsPosition;
672 QTransform translateMatrix;
673 translateMatrix.translate(translate.x(), translate.y());
674 applyAbsoluteTransformation(translateMatrix);
677}

References absolutePosition(), anchor(), applyAbsoluteTransformation(), notifyChanged(), PositionChanged, and shapeChangedPriv().

◆ setAdditionalAttribute()

void KoShape::setAdditionalAttribute ( const QString & name,
const QString & value )

Set additional attribute

This can be used to attach additional attributes to a shape for attributes that are application specific like presentation:placeholder

Parameters
nameThe name of the attribute in the following form prefix:tag e.g. presentation:placeholder
valueThe value of the attribute

Definition at line 1264 of file KoShape.cpp.

1265{
1266 s->additionalAttributes.insert(name, value);
1267}
float value(const T *src, size_t ch)

References name(), s, and value().

◆ setAdditionalStyleAttribute()

void KoShape::setAdditionalStyleAttribute ( const char * name,
const QString & value )

Definition at line 1284 of file KoShape.cpp.

1285{
1286 s->additionalStyleAttributes.insert(name, value);
1287}

References name(), s, and value().

◆ setAnchor()

void KoShape::setAnchor ( KoShapeAnchor * anchor)

Set the KoShapeAnchor

◆ setBackground()

void KoShape::setBackground ( QSharedPointer< KoShapeBackground > background)
virtual

Set the background of the shape. A shape background can be a plain color, a gradient, a pattern, be fully transparent or have a complex fill. Setting such a background will allow the shape to be filled and will be able to tell if it is transparent or not.

If the shape inherited the background from its parent, its stops inheriting it, that is inheritBackground property resets to false.

Parameters
backgroundthe new shape background.

Reimplemented in KoSvgTextShape.

Definition at line 918 of file KoShape.cpp.

919{
920 s->inheritBackground = false;
921 s->fill = fill;
924}

References BackgroundChanged, notifyChanged(), s, and shapeChangedPriv().

◆ setClipMask()

void KoShape::setClipMask ( KoClipMask * clipMask)

Sets a new clip mask, removing the old one. The mask is owned by the shape.

Definition at line 1133 of file KoShape.cpp.

1134{
1135 s->clipMask.reset(clipMask);
1137 notifyChanged();
1138}
KoClipMask * clipMask() const
Returns the currently set clip mask or 0 if there is no clip mask set.
Definition KoShape.cpp:1140

References clipMask(), ClipMaskChanged, notifyChanged(), s, and shapeChangedPriv().

◆ setClipPath()

void KoShape::setClipPath ( KoClipPath * clipPath)

Sets a new clip path, removing the old one.

Definition at line 1121 of file KoShape.cpp.

1122{
1123 s->clipPath.reset(clipPath);
1125 notifyChanged();
1126}
KoClipPath * clipPath() const
Returns the currently set clip path or 0 if there is no clip path set.
Definition KoShape.cpp:1128

References clipPath(), ClipPathChanged, notifyChanged(), s, and shapeChangedPriv().

◆ setContentProtected()

void KoShape::setContentProtected ( bool protect)

Marks the shape to have its content protected against editing. Content protection is a hint for tools to disallow the user editing the content.

Parameters
protectwhen true set the shapes content to be protected from user modification.
See also
setGeometryProtected(), setSelectable(), setVisible()

Definition at line 1029 of file KoShape.cpp.

1030{
1031 s->protectContent = protect;
1032}

References s.

◆ setFilterEffectStack()

void KoShape::setFilterEffectStack ( KoFilterEffectStack * filterEffectStack)

Sets the new filter effect stack, removing the old one.

Definition at line 1299 of file KoShape.cpp.

1300{
1301 if (s->filterEffectStack)
1302 s->filterEffectStack->deref();
1303 s->filterEffectStack = filterEffectStack;
1304 if (s->filterEffectStack) {
1305 s->filterEffectStack->ref();
1306 }
1307 notifyChanged();
1308}
KoFilterEffectStack * filterEffectStack() const
Definition KoShape.cpp:1294

References KoFilterEffectStack::deref(), filterEffectStack(), notifyChanged(), KoFilterEffectStack::ref(), and s.

◆ setGeometryProtected()

void KoShape::setGeometryProtected ( bool on)

Tells the shape to have its position/rotation and size protected from user-changes. The geometry being protected means the user can not change shape or position of the shape. This includes any matrix operation such as rotation.

Parameters
onwhen true; set the shape to have its geometry protected.
See also
setContentProtected(), setSelectable(), setVisible()

Definition at line 1019 of file KoShape.cpp.

1020{
1021 s->geometryProtected = on;
1022}

References s.

◆ setHyperLink()

void KoShape::setHyperLink ( const QString & hyperLink)

Set hyperlink for this shape.

Parameters
hyperLinkname.

Definition at line 1325 of file KoShape.cpp.

1326{
1327 s->hyperLink = hyperLink;
1328}
QString hyperLink() const
Definition KoShape.cpp:1320

References hyperLink(), and s.

◆ setInheritBackground()

void KoShape::setInheritBackground ( bool value)

setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.

Parameters
valuetrue if the shape should inherit the filling background

Definition at line 940 of file KoShape.cpp.

941{
942
943 s->inheritBackground = value;
944 if (s->inheritBackground) {
945 s->fill.clear();
946 }
947}

References s, and value().

◆ setInheritPaintOrder()

void KoShape::setInheritPaintOrder ( bool value)

setInheritPaintOrder set inherit paint order.

Parameters
value

Definition at line 790 of file KoShape.cpp.

791{
792 s->inheritPaintOrder = value;
793}

References s, and value().

◆ setInheritStroke()

void KoShape::setInheritStroke ( bool value)

setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.

Parameters
valuetrue if the shape should inherit the stroke style

Definition at line 1090 of file KoShape.cpp.

1091{
1092 s->inheritStroke = value;
1093 if (s->inheritStroke) {
1094 s->stroke.clear();
1095 }
1096}

References s, and value().

◆ setKeepAspectRatio()

void KoShape::setKeepAspectRatio ( bool keepAspect)

Setting the shape to keep its aspect-ratio has the effect that user-scaling will keep the width/height ratio intact so as not to distort shapes that rely on that ratio.

Parameters
keepAspectthe new value

Definition at line 1044 of file KoShape.cpp.

1045{
1046 s->keepAspect = keepAspect;
1047
1049 notifyChanged();
1050}

References KeepAspectRatioChange, notifyChanged(), s, and shapeChangedPriv().

◆ setMinimumHeight()

void KoShape::setMinimumHeight ( qreal height)

Set the minimum height of the shape. Currently it's not respected but only for informational purpose

Parameters
heightthe minimum height of the frame.

◆ setName()

void KoShape::setName ( const QString & name)

Sets the name of the shape.

Parameters
namethe new shape name

Definition at line 1155 of file KoShape.cpp.

1156{
1157 s->name = name;
1158}

References name(), and s.

◆ setPaintOrder()

void KoShape::setPaintOrder ( KoShape::PaintOrder first,
KoShape::PaintOrder second )
virtual

setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.

Parameters
firstfirst thing to paint
secondsecond thing to paint.

Reimplemented in KoSvgTextShape.

Definition at line 749 of file KoShape.cpp.

750{
751 KIS_SAFE_ASSERT_RECOVER_RETURN(first != second);
753
754 if (first != Fill) {
755 if (order.at(1) == first) {
756 order[1] = order[0];
757 order[0] = first;
758 } else if (order.at(2) == first) {
759 order[2] = order[0];
760 order[0] = first;
761 }
762 }
763 if (second != first && second != Stroke) {
764 if (order.at(2) == second) {
765 order[2] = order[1];
766 order[1] = second;
767 }
768 }
769 s->inheritPaintOrder = false;
770 s->paintOrder = order;
771}

References defaultPaintOrder(), Fill, KIS_SAFE_ASSERT_RECOVER_RETURN, and s.

◆ setParent()

void KoShape::setParent ( KoShapeContainer * parent)

Set the parent of this shape.

Parameters
parentthe new parent of this shape. Can be 0 if the shape has no parent anymore.

Definition at line 535 of file KoShape.cpp.

536{
537
538 if (d->parent == parent) {
539 return;
540 }
541
542 if (d->parent) {
543 d->parent->shapeInterface()->removeShape(this);
544 d->parent = 0;
545 }
546
547
549
550 if (parent && parent != this) {
551 d->parent = parent;
553 }
554
557}
KoShapeContainer::ShapeInterface shapeInterface

References d, and parent().

◆ setPosition()

void KoShape::setPosition ( const QPointF & position)
virtual

Set the position of the shape in pt.

Parameters
positionthe new position of the shape

Reimplemented in KisNodeShape.

Definition at line 295 of file KoShape.cpp.

296{
297 QPointF currentPos = position();
298 if (newPosition == currentPos)
299 return;
300 QTransform translateMatrix;
301 translateMatrix.translate(newPosition.x() - currentPos.x(), newPosition.y() - currentPos.y());
302 s->localMatrix = s->localMatrix * translateMatrix;
303
306}

References notifyChanged(), position(), PositionChanged, s, and shapeChangedPriv().

◆ setPrintable()

void KoShape::setPrintable ( bool on)

Changes the shape to be printable or not. The default is true.

If a Shape's print flag is true, the shape will be printed. If false, the shape will not be printed. If a shape is not visible (

See also
isVisible), it isPrinted will return false, too.

Definition at line 996 of file KoShape.cpp.

997{
998 s->printable = on;
999}

References s.

◆ setResolution()

void KoShape::setResolution ( qreal xRes,
qreal yRes )
virtual

Update the image resolution in pixels per inch. Shapes should override this if they need to know the image resolution.

Parameters
xRes
yRes

Reimplemented in KoSvgTextShape.

Definition at line 1416 of file KoShape.cpp.

1417{
1418}

◆ setRunThrough()

void KoShape::setRunThrough ( short int runThrough)
virtual

Set the run through property of this shape. The run through property is used to determine if the shape is behind, inside or before text.

Parameters
runThroughthe new run through;

Reimplemented in KoTosContainer.

Definition at line 967 of file KoShape.cpp.

968{
969 s->runThrough = runThrough;
970}

References runThrough(), and s.

◆ setSelectable()

void KoShape::setSelectable ( bool selectable)

Makes it possible for the user to select this shape. This parameter defaults to true.

Parameters
selectablewhen true; set the shape to be selectable by the user.
See also
setGeometryProtected(), setContentProtected(), setVisible()

Definition at line 1009 of file KoShape.cpp.

1010{
1011 s->selectable = selectable;
1012}

References s.

◆ setShadow()

void KoShape::setShadow ( KoShapeShadow * shadow)

Sets the new shadow, removing the old one.

Definition at line 1103 of file KoShape.cpp.

1104{
1105 if (s->shadow)
1106 s->shadow->deref();
1107 s->shadow = shadow;
1108 if (s->shadow) {
1109 s->shadow->ref();
1110 // TODO update changed area
1111 }
1113 notifyChanged();
1114}
KoShapeShadow * shadow() const
Returns the currently set shadow or 0 if there is no shadow set.
Definition KoShape.cpp:1116

References notifyChanged(), KoShapeShadow::ref(), s, shadow(), ShadowChanged, and shapeChangedPriv().

◆ setShapeId()

void KoShape::setShapeId ( const QString & id)

Set the Id of this shape. A shapeFactory is expected to set the Id at creation so applications can find out what kind of shape this is.

See also
KoShapeFactoryBase::shapeId()
Parameters
idthe ID from the factory that created this shape

Definition at line 1062 of file KoShape.cpp.

1063{
1064 s->shapeId = id;
1065}

References s.

◆ setSize()

void KoShape::setSize ( const QSizeF & size)
virtual

Resize the shape.

Parameters
sizethe new size of the shape. This is different from scaling as scaling is a so called secondary operation which is comparable to zooming in instead of changing the size of the basic shape. Easiest example of this difference is that using this method will not distort the size of pattern-fills and strokes.

Reimplemented in EllipseShape, EnhancedPathShape, SpiralShape, StarShape, KarbonCalligraphicShape, KoParameterShape, KoPathShape, KoSelection, KoShapeGroup, and ImageShape.

Definition at line 276 of file KoShape.cpp.

277{
278 QSizeF oldSize(size());
279
280 // always set size, as d->size and size() may vary
281 setSizeImpl(newSize);
282
283 if (oldSize == newSize)
284 return;
285
288}
void setSizeImpl(const QSizeF &size) const
Definition KoShape.cpp:290

References notifyChanged(), setSizeImpl(), shapeChangedPriv(), size(), and SizeChanged.

◆ setSizeImpl()

void KoShape::setSizeImpl ( const QSizeF & size) const
protected

Definition at line 290 of file KoShape.cpp.

291{
292 s->size = size;
293}

References s, and size().

◆ setStroke()

void KoShape::setStroke ( KoShapeStrokeModelSP stroke)
virtual

Set a new stroke, removing the old one. The stroke inheritance becomes disabled.

Parameters
strokethe new stroke, or 0 if there should be no stroke.

Reimplemented in KoSvgTextShape.

Definition at line 1081 of file KoShape.cpp.

1082{
1083
1084 s->inheritStroke = false;
1085 s->stroke = stroke;
1087 notifyChanged();
1088}

References notifyChanged(), s, shapeChangedPriv(), stroke(), and StrokeChanged.

◆ setTextRunAroundContour()

void KoShape::setTextRunAroundContour ( KoShape::TextRunAroundContour contour)

Set how tight text run around is done around this shape.

Parameters
contourthe new contour

Definition at line 913 of file KoShape.cpp.

914{
915 s->textRunAroundContour = contour;
916}

References s.

◆ setTextRunAroundDistanceBottom()

void KoShape::setTextRunAroundDistanceBottom ( qreal distance)

Set the space between this shape's bottom edge and the text that run around this shape.

Parameters
distancethe space around this shape to keep free from text

Definition at line 893 of file KoShape.cpp.

894{
895 s->textRunAroundDistanceBottom = distance;
896}
qreal distance(const QPointF &p1, const QPointF &p2)

References distance(), and s.

◆ setTextRunAroundDistanceLeft()

void KoShape::setTextRunAroundDistanceLeft ( qreal distance)

Set the space between this shape's left edge and the text that run around this shape.

Parameters
distancethe space around this shape to keep free from text

Definition at line 873 of file KoShape.cpp.

874{
875 s->textRunAroundDistanceLeft = distance;
876}

References distance(), and s.

◆ setTextRunAroundDistanceRight()

void KoShape::setTextRunAroundDistanceRight ( qreal distance)

Set the space between this shape's right edge and the text that run around this shape.

Parameters
distancethe space around this shape to keep free from text

Definition at line 883 of file KoShape.cpp.

884{
885 s->textRunAroundDistanceRight = distance;
886}

References distance(), and s.

◆ setTextRunAroundDistanceTop()

void KoShape::setTextRunAroundDistanceTop ( qreal distance)

Set the space between this shape's top edge and the text that run around this shape.

Parameters
distancethe space around this shape to keep free from text

Definition at line 863 of file KoShape.cpp.

864{
865 s->textRunAroundDistanceTop = distance;
866}

References distance(), and s.

◆ setTextRunAroundSide()

void KoShape::setTextRunAroundSide ( TextRunAroundSide side,
RunThroughLevel runThrough = Background )

Set the side text should flow around this shape.

Parameters
sidethe requested side
runThroughrun through the foreground or background or...

Definition at line 836 of file KoShape.cpp.

837{
838
839 if (side == RunThrough) {
840 if (runThrough == Background) {
841 setRunThrough(-1);
842 } else {
843 setRunThrough(1);
844 }
845 } else {
846 setRunThrough(0);
847 }
848
849 if ( s->textRunAroundSide == side) {
850 return;
851 }
852
853 s->textRunAroundSide = side;
856}
virtual void setRunThrough(short int runThrough)
Definition KoShape.cpp:967

References Background, notifyChanged(), RunThrough, runThrough(), s, setRunThrough(), shapeChangedPriv(), and TextRunAroundChanged.

◆ setTextRunAroundThreshold()

void KoShape::setTextRunAroundThreshold ( qreal threshold)

Set the threshold above which text should flow around this shape. The text will not flow around the shape on a side unless the space available on that side is above this threshold. Only used when the text run around side is EnoughRunAroundSide.

Parameters
thresholdthe new threshold

Definition at line 903 of file KoShape.cpp.

904{
905 s->textRunAroundThreshold = threshold;
906}

References s.

◆ setToolDelegates()

void KoShape::setToolDelegates ( const QSet< KoShape * > & delegates)

Set the tool delegates.

Parameters
delegatesthe new delegates.
See also
toolDelegates()

Definition at line 1315 of file KoShape.cpp.

1316{
1317 d->toolDelegates = delegates;
1318}

References d.

◆ setTransformation()

void KoShape::setTransformation ( const QTransform & matrix)

Sets a new transformation matrix describing the local transformations on this shape.

Parameters
matrixthe new transformation matrix

Definition at line 417 of file KoShape.cpp.

418{
419 s->localMatrix = matrix;
422}

References GenericMatrixChange, notifyChanged(), s, and shapeChangedPriv().

◆ setTransparency()

void KoShape::setTransparency ( qreal transparency)

Sets shape level transparency.

Parameters
transparencythe new shape level transparency

Definition at line 722 of file KoShape.cpp.

723{
724 s->transparency = qBound<qreal>(0.0, transparency, 1.0);
725
728}
qreal transparency(bool recursive=false) const
Definition KoShape.cpp:730

References notifyChanged(), s, shapeChangedPriv(), transparency(), and TransparencyChanged.

◆ setUserData()

void KoShape::setUserData ( KoShapeUserData * userData)

Set a data object on the shape to be used by an application. This is specifically useful when a shape is created in a plugin and that data from that shape should be accessible outside the plugin.

Parameters
userDatathe new user data, or 0 to delete the current one.

Definition at line 705 of file KoShape.cpp.

706{
707 s->userData.reset(userData);
708}
KoShapeUserData * userData() const
Definition KoShape.cpp:710

References s, and userData().

◆ setVisible()

void KoShape::setVisible ( bool on)

Changes the Shape to be visible or invisible. Being visible means being painted, as well as being used for things like guidelines or searches.

Parameters
onwhen true; set the shape to be visible.
See also
setGeometryProtected(), setContentProtected(), setSelectable()

Definition at line 972 of file KoShape.cpp.

973{
974 int _on = (on ? 1 : 0);
975 if (s->visible == _on) return;
976 s->visible = _on;
977}

References s.

◆ setZIndex()

void KoShape::setZIndex ( qint16 zIndex)

Set the z-coordinate of this shape. The zIndex property is used to determine which shape lies on top of other objects. An shape with a higher z-order is on top, and can obscure, another shape.

Just like two objects having the same x or y coordinate will make them 'touch', so will two objects with the same z-index touch on the z plane. In layering the shape this, however, can cause a little confusion as one always has to be on top. The layering if two overlapping objects have the same index is implementation dependent and probably depends on the order in which they are added to the shape manager.

Parameters
zIndexthe new z-index;

Definition at line 954 of file KoShape.cpp.

955{
956 if (s->zIndex == zIndex)
957 return;
958 s->zIndex = zIndex;
960}

References notifyChanged(), s, and zIndex().

◆ shadow()

KoShapeShadow * KoShape::shadow ( ) const

Returns the currently set shadow or 0 if there is no shadow set.

Definition at line 1116 of file KoShape.cpp.

1117{
1118 return s->shadow;
1119}

References s.

◆ shadowOutline()

QPainterPath KoShape::shadowOutline ( ) const
virtual

returns the outline of the shape in the form of a path for the use of painting a shadow.

Normally this would be the same as outline() if there is a fill (background) set on the shape and empty if not. However, a shape could reimplement this to return an outline even if no fill is defined. A typical example of this would be the picture shape which has a picture but almost never a background.

Returns
the outline of the shape in the form of a path.

Definition at line 644 of file KoShape.cpp.

645{
646 if (background()) {
647 return outline();
648 }
649
650 return QPainterPath();
651}

References background(), and outline().

◆ shapeChanged()

void KoShape::shapeChanged ( ChangeType type,
KoShape * shape = 0 )
protectedvirtual

A hook that allows inheriting classes to do something after a KoShape property changed This is called whenever the shape, position rotation or scale properties were altered.

Parameters
typean indicator which type was changed.
shapethe shape.

Reimplemented in KoSvgTextShape, KoShapeContainer, KoShapeGroup, KoTosContainer, and EnhancedPathShape.

Definition at line 1253 of file KoShape.cpp.

1254{
1255 Q_UNUSED(type);
1256 Q_UNUSED(shape);
1257}

◆ shapeChangedPriv()

void KoShape::shapeChangedPriv ( KoShape::ChangeType type)
protected

Notify the shape that a change was done. To be used by inheriting shapes.

Parameters
typethe change type

Definition at line 132 of file KoShape.cpp.

133{
134 if (d->parent)
135 d->parent->model()->childChanged(this, type);
136
137 this->shapeChanged(type);
138
139 Q_FOREACH (KoShape * shape, d->dependees) {
140 shape->shapeChanged(type, this);
141 }
142
143 Q_FOREACH (KoShape::ShapeChangeListener *listener, d->listeners) {
144 listener->notifyShapeChangedImpl(type, this);
145 }
146}
QList< KoShape * > dependees() const
Returns list of shapes depending on this shape.
Definition KoShape.cpp:1248
virtual void shapeChanged(ChangeType type, KoShape *shape=0)
Definition KoShape.cpp:1253
void notifyShapeChangedImpl(ChangeType type, KoShape *shape)
Definition KoShape.cpp:1349

References d, dependees(), KoShape::ShapeChangeListener::notifyShapeChangedImpl(), and shapeChanged().

◆ shapeId()

QString KoShape::shapeId ( ) const

Return the Id of this shape, identifying the type of shape by the id of the factory.

See also
KoShapeFactoryBase::shapeId()
Returns
the id of the shape-type

Definition at line 1057 of file KoShape.cpp.

1058{
1059 return s->shapeId;
1060}

References s.

◆ shapeToDocument() [1/2]

QPointF KoShape::shapeToDocument ( const QPointF & point) const

Transforms point from shape coordinates to document coordinates.

Parameters
pointin shape coordinates
Returns
point in document coordinates

Definition at line 1201 of file KoShape.cpp.

1202{
1203 return absoluteTransformation().map(point);
1204}

References absoluteTransformation().

◆ shapeToDocument() [2/2]

QRectF KoShape::shapeToDocument ( const QRectF & rect) const

Transforms rect from shape coordinates to document coordinates.

Parameters
rectin shape coordinates
Returns
rect in document coordinates

Definition at line 1206 of file KoShape.cpp.

1207{
1208 return absoluteTransformation().mapRect(rect);
1209}

References absoluteTransformation().

◆ shear()

void KoShape::shear ( qreal sx,
qreal sy )

Shear the shape The shape will be sheared using the zero-point which is the top-left corner.

See also
position()
Parameters
sxshear in x direction
syshear in y direction

Definition at line 263 of file KoShape.cpp.

264{
265 QPointF pos = position();
266 QTransform shearMatrix;
267 shearMatrix.translate(pos.x(), pos.y());
268 shearMatrix.shear(sx, sy);
269 shearMatrix.translate(-pos.x(), -pos.y());
270 s->localMatrix = s->localMatrix * shearMatrix;
271
274}

References notifyChanged(), position(), s, shapeChangedPriv(), and ShearChanged.

◆ size()

QSizeF KoShape::size ( ) const
virtual

Get the size of the shape in pt.

The size is in shape coordinates.

Returns
the size of the shape as set by setSize()

Reimplemented in KoPathShape, KoSelection, KoShapeGroup, and KisNodeShape.

Definition at line 820 of file KoShape.cpp.

821{
822 return s->size;
823}

References s.

◆ snapData()

KoSnapData KoShape::snapData ( ) const
virtual

Returns additional snap data the shape wants to have snapping to.

Definition at line 1259 of file KoShape.cpp.

1260{
1261 return KoSnapData();
1262}

◆ stroke()

KoShapeStrokeModelSP KoShape::stroke ( ) const
virtual

Returns the currently set stroke, or 0 if there is no stroke.

Returns
the currently set stroke, or 0 if there is no stroke.

Reimplemented in KoSvgTextShape.

Definition at line 1067 of file KoShape.cpp.

1068{
1069
1071
1072 if (!s->inheritStroke) {
1073 stroke = s->stroke;
1074 } else if (parent()) {
1075 stroke = parent()->stroke();
1076 }
1077
1078 return stroke;
1079}

References parent(), s, and stroke().

◆ strokeInsets()

KoInsets KoShape::strokeInsets ( ) const

Return the insets of the stroke. Convenience method for KoShapeStrokeModel::strokeInsets()

Definition at line 741 of file KoShape.cpp.

742{
743 KoInsets answer;
744 if (s->stroke)
745 s->stroke->strokeInsets(this, answer);
746 return answer;
747}

References s.

◆ textRunAroundContour()

KoShape::TextRunAroundContour KoShape::textRunAroundContour ( ) const

Return the how tight text run around is done around this shape.

Returns
the contour

Definition at line 908 of file KoShape.cpp.

909{
910 return s->textRunAroundContour;
911}

References s.

◆ textRunAroundDistanceBottom()

qreal KoShape::textRunAroundDistanceBottom ( ) const

The space between this shape's bottom edge and text that runs around this shape.

Returns
the space around this shape to keep free from text

Definition at line 888 of file KoShape.cpp.

889{
890 return s->textRunAroundDistanceBottom;
891}

References s.

◆ textRunAroundDistanceLeft()

qreal KoShape::textRunAroundDistanceLeft ( ) const

The space between this shape's left edge and text that runs around this shape.

Returns
the space around this shape to keep free from text

Definition at line 868 of file KoShape.cpp.

869{
870 return s->textRunAroundDistanceLeft;
871}

References s.

◆ textRunAroundDistanceRight()

qreal KoShape::textRunAroundDistanceRight ( ) const

The space between this shape's right edge and text that runs around this shape.

Returns
the space around this shape to keep free from text

Definition at line 878 of file KoShape.cpp.

879{
880 return s->textRunAroundDistanceRight;
881}

References s.

◆ textRunAroundDistanceTop()

qreal KoShape::textRunAroundDistanceTop ( ) const

The space between this shape's top edge and text that runs around this shape.

Returns
the space around this shape to keep free from text

Definition at line 858 of file KoShape.cpp.

859{
860 return s->textRunAroundDistanceTop;
861}

References s.

◆ textRunAroundSide()

KoShape::TextRunAroundSide KoShape::textRunAroundSide ( ) const

Return the side text should flow around this shape. This implements the ODF style:wrap attribute that specifies how text is displayed around a frame or graphic object.

Definition at line 831 of file KoShape.cpp.

832{
833 return s->textRunAroundSide;
834}

References s.

◆ textRunAroundThreshold()

qreal KoShape::textRunAroundThreshold ( ) const

Return the threshold above which text should flow around this shape. The text will not flow around the shape on a side unless the space available on that side is above this threshold. Only used when the text run around side is EnoughRunAroundSide.

Returns
threshold the threshold

Definition at line 898 of file KoShape.cpp.

899{
900 return s->textRunAroundThreshold;
901}

References s.

◆ toolDelegates()

QSet< KoShape * > KoShape::toolDelegates ( ) const

Return the tool delegates for this shape. In Flake a shape being selected will cause the tool manager to make available all tools that can edit the selected shapes. In some cases selecting one shape should allow the tool to edit a related shape be available too. The tool delegates allows this to happen by taking all the shapes in the set into account on tool selection. Notice that if the set is non-empty 'this' shape is no longer looked at. You can choose to add itself to the set too.

Definition at line 1310 of file KoShape.cpp.

1311{
1312 return d->toolDelegates;
1313}

References d.

◆ transform()

QTransform KoShape::transform ( ) const
protected

return the current matrix that contains the rotation/scale/position of this shape

Definition at line 1145 of file KoShape.cpp.

1146{
1147 return s->localMatrix;
1148}

References s.

◆ transformation()

QTransform KoShape::transformation ( ) const

Returns the shapes local transformation matrix.

Definition at line 424 of file KoShape.cpp.

425{
426 return s->localMatrix;
427}

References s.

◆ transparency()

qreal KoShape::transparency ( bool recursive = false) const

Returns the shape level transparency.

Parameters
recursivewhen true takes the parents transparency into account

Definition at line 730 of file KoShape.cpp.

731{
732 if (!recursive || !parent()) {
733 return s->transparency;
734 } else {
735 const qreal parentOpacity = 1.0-parent()->transparency(recursive);
736 const qreal childOpacity = 1.0-s->transparency;
737 return 1.0-(parentOpacity*childOpacity);
738 }
739}

References parent(), s, and transparency().

◆ update()

void KoShape::update ( ) const
virtual

Request a repaint to be queued. The repaint will be of the entire Shape, including its selection handles should this shape be selected.

This method will return immediately and only request a repaint. Successive calls will be merged into an appropriate repaint action.

Reimplemented in KoShapeContainer, and KoShapeContainer.

Definition at line 605 of file KoShape.cpp.

606{
607
608 if (!d->shapeManagers.empty()) {
609 const QRectF rect(boundingRect());
610 Q_FOREACH (KoShapeManager * manager, d->shapeManagers) {
611 manager->update(rect, this, true);
612 }
613 }
614}
void update(const QRectF &rect, const KoShape *shape=0, bool selectionHandles=false)

References boundingRect(), d, and KoShapeManager::update().

◆ updateAbsolute()

void KoShape::updateAbsolute ( const QRectF & rect) const
virtual

Request a repaint to be queued. The repaint will be restricted to the parameters rectangle, which is expected to be in absolute coordinates of the canvas and it is expected to be normalized.

This method will return immediately and only request a repaint. Successive calls will be merged into an appropriate repaint action.

Parameters
rectthe rectangle (in pt) to queue for repaint.

Definition at line 616 of file KoShape.cpp.

617{
618 if (rect.isEmpty() && !rect.isNull()) {
619 return;
620 }
621
622
623 if (!d->shapeManagers.empty() && isVisible()) {
624 Q_FOREACH (KoShapeManager *manager, d->shapeManagers) {
625 manager->update(rect);
626 }
627 }
628}

References d, isVisible(), and KoShapeManager::update().

◆ userData()

KoShapeUserData * KoShape::userData ( ) const

Return the current userData.

Definition at line 710 of file KoShape.cpp.

711{
712 return s->userData.data();
713}

References s.

◆ waitUntilReady()

void KoShape::waitUntilReady ( bool asynchronous = true) const
virtual

A shape can be in a state that it is doing processing data like loading or text layout. In this case it can be shown on screen probably partially but it should really not be printed until it is fully done processing. Warning! This method can be blocking for a long time

Parameters
asynchronousIf set to true the processing will can take place in a different thread and the function will not block until the shape is finished. In case of printing Flake will call this method from a non-main thread and only start printing it when the in case of printing method returned. If set to false the processing needs to be done synchronously and will block until the result is finished.

Definition at line 1160 of file KoShape.cpp.

1161{
1162 Q_UNUSED(asynchronous);
1163}

◆ zIndex()

qint16 KoShape::zIndex ( ) const

Retrieve the z-coordinate of this shape. The zIndex property is used to determine which shape lies on top of other objects. An shape with a higher z-order is on top, and can obscure another shape.

Returns
the z-index of this shape.
See also
setZIndex()

Definition at line 600 of file KoShape.cpp.

601{
602 return s->zIndex;
603}

References s, and zIndex().

Friends And Related Symbol Documentation

◆ KoShapeManager

friend class KoShapeManager
friend

Definition at line 1151 of file KoShape.h.

Member Data Documentation

◆ d

QScopedPointer<Private> KoShape::d
private

Definition at line 1135 of file KoShape.h.

◆ maxZIndex

const qint16 KoShape::maxZIndex = std::numeric_limits<qint16>::max()
static

Maximum value of z-index

Definition at line 502 of file KoShape.h.

◆ minZIndex

const qint16 KoShape::minZIndex = std::numeric_limits<qint16>::min()
static

Minimum value of z-index

Definition at line 507 of file KoShape.h.

◆ s

QSharedDataPointer<SharedData> KoShape::s
private

Definition at line 1138 of file KoShape.h.


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