Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShape.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2006-2008 Thorsten Zachmann <zachmann@kde.org>
3 SPDX-FileCopyrightText: 2006, 2008 C. Boemann <cbo@boemann.dk>
4 SPDX-FileCopyrightText: 2006-2010 Thomas Zander <zander@kde.org>
5 SPDX-FileCopyrightText: 2007-2009, 2011 Jan Hambrecht <jaham@gmx.net>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KOSHAPE_H
11#define KOSHAPE_H
12
13#include "KoFlake.h"
14#include "KoFlakeTypes.h"
15
16#include <QSharedPointer>
17#include <QSet>
18#include <QMap>
19#include <QMetaType>
20#include <QSharedDataPointer>
21
22#include <QDomDocument>
23
24#include "kritaflake_export.h"
25
26class QPainter;
27class QRectF;
28class QPainterPath;
29class QTransform;
30
33class KoShapeUserData;
34class KoViewConverter;
38class KoShapeShadow;
40class KoSnapData;
41class KoClipPath;
42class KoClipMask;
43class KoShapeAnchor;
44struct KoInsets;
47class KoShapeManager;
48
91class KRITAFLAKE_EXPORT KoShape
92{
93public:
118
129
136
142 Foreground
143 };
144
148 Markers
149 };
150
154 KoShape();
155
159 virtual ~KoShape();
160
165 virtual KoShape* cloneShape() const;
166
179 KoShape* cloneShapeAndBakeAbsoluteTransform() const;
180
188 virtual void paint(QPainter &painter) const = 0;
189
195 virtual void paintStroke(QPainter &painter) const;
196
202 virtual void paintMarkers(QPainter &painter) const;
203
211 void scale(qreal sx, qreal sy);
212
220 void rotate(qreal angle);
221
226 qreal rotation() const;
227
236 void shear(qreal sx, qreal sy);
237
247 virtual void setSize(const QSizeF &size);
248
256 virtual QSizeF size() const;
257
263 virtual void setPosition(const QPointF &position);
264
270 QPointF position() const;
271
277 virtual bool hitTest(const QPointF &position) const;
278
286 virtual QRectF boundingRect() const;
287
292 static QRectF boundingRect(const QList<KoShape*> &shapes);
293
300 QRectF absoluteOutlineRect() const;
301
306 static QRectF absoluteOutlineRect(const QList<KoShape*> &shapes);
307
312 TextRunAroundSide textRunAroundSide() const;
313
319 void setTextRunAroundSide(TextRunAroundSide side, RunThroughLevel runThrough = Background);
320
325 qreal textRunAroundDistanceLeft() const;
326
331 void setTextRunAroundDistanceLeft(qreal distance);
332
337 qreal textRunAroundDistanceTop() const;
338
343 void setTextRunAroundDistanceTop(qreal distance);
344
349 qreal textRunAroundDistanceRight() const;
350
355 void setTextRunAroundDistanceRight(qreal distance);
356
361 qreal textRunAroundDistanceBottom() const;
362
367 void setTextRunAroundDistanceBottom(qreal distance);
368
375 qreal textRunAroundThreshold() const;
376
383 void setTextRunAroundThreshold(qreal threshold);
384
389 TextRunAroundContour textRunAroundContour() const;
390
395 void setTextRunAroundContour(TextRunAroundContour contour);
396
401
406
412 void setMinimumHeight(qreal height);
413
418 qreal minimumHeight() const;
419
420
433 virtual void setBackground(QSharedPointer<KoShapeBackground> background);
434
442 virtual QSharedPointer<KoShapeBackground> background() const;
443
449 void setInheritBackground(bool value);
450
455 bool inheritBackground() const;
456
463 virtual bool hasTransparency() const;
464
469 void setTransparency(qreal transparency);
470
475 qreal transparency(bool recursive=false) const;
476
484 qint16 zIndex() const;
485
497 void setZIndex(qint16 zIndex);
498
502 static const qint16 maxZIndex;
503
507 static const qint16 minZIndex;
508
514 int runThrough() const;
515
521 virtual void setRunThrough(short int runThrough);
522
530 void setVisible(bool on);
539 bool isVisible(bool recursive = true) const;
540
548 void setPrintable(bool on);
549
558 bool isPrintable() const;
559
566 void setSelectable(bool selectable);
567
573 bool isSelectable() const;
574
582 void setGeometryProtected(bool on);
583
591 bool isGeometryProtected() const;
592
599 void setContentProtected(bool protect);
600
607 bool isContentProtected() const;
608
613 KoShapeContainer *parent() const;
614
619 void setParent(KoShapeContainer *parent);
620
621
628 bool inheritsTransformFromAny(const QList<KoShape*> ancestorsInQuestion) const;
629
633 bool hasCommonParent(const KoShape *shape) const;
634
642 virtual void update() const;
643
653 virtual void updateAbsolute(const QRectF &rect) const;
654
658 ChildZParentChild = ChildZDefault,
659 ChildZPassThrough
660 };
661
672 virtual ChildZOrderPolicy childZOrderPolicy();
673
679 static bool compareShapeZIndex(KoShape *s1, KoShape *s2);
680
688 virtual QPainterPath outline() const;
689
697 virtual QRectF outlineRect() const;
698
709 virtual QPainterPath shadowOutline() const;
710
715 virtual KoShapeStrokeModelSP stroke() const;
716
721 virtual void setStroke(KoShapeStrokeModelSP stroke);
722
728 void setInheritStroke(bool value);
729
734 bool inheritStroke() const;
735
740 KoInsets strokeInsets() const;
741
750 virtual void setPaintOrder(PaintOrder first, PaintOrder second);
751
756 virtual QVector<PaintOrder> paintOrder() const;
757
762 static QVector<PaintOrder> defaultPaintOrder();
763
769 void setInheritPaintOrder(bool value);
770
775 bool inheritPaintOrder() const;
776
778 void setShadow(KoShapeShadow *shadow);
779
781 KoShapeShadow *shadow() const;
782
784 void setClipPath(KoClipPath *clipPath);
785
787 KoClipPath * clipPath() const;
788
790 void setClipMask(KoClipMask *clipMask);
791
793 KoClipMask* clipMask() const;
794
801 void setKeepAspectRatio(bool keepAspect);
802
809 bool keepAspectRatio() const;
810
817 QPointF absolutePosition(KoFlake::AnchorPosition anchor = KoFlake::Center) const;
818
833 void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor = KoFlake::Center);
834
841 void setUserData(KoShapeUserData *userData);
845 KoShapeUserData *userData() const;
846
852 QString shapeId() const;
853
860 void setShapeId(const QString &id);
861
868 QTransform absoluteTransformation() const;
869
879 void applyAbsoluteTransformation(const QTransform &matrix);
880
885 void setTransformation(const QTransform &matrix);
886
888 QTransform transformation() const;
889
897 void applyTransformation(const QTransform &matrix);
898
905 void copySettings(const KoShape *shape);
906
912 static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius = 0.0, int decorationThickness = 1);
913 static KisHandlePainterHelper createHandlePainterHelperDocument(QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness);
914
920 QPointF shapeToDocument(const QPointF &point) const;
921
927 QRectF shapeToDocument(const QRectF &rect) const;
928
934 QPointF documentToShape(const QPointF &point) const;
935
941 QRectF documentToShape(const QRectF &rect) const;
942
947 QString name() const;
948
953 void setName(const QString &name);
954
958 void notifyChanged();
959
972 virtual void waitUntilReady(bool asynchronous = true) const;
973
975 virtual bool isShapeEditable(bool recursive = true) const;
976
989 bool addDependee(KoShape *shape);
990
995 void removeDependee(KoShape *shape);
996
998 bool hasDependee(KoShape *shape) const;
999
1001 QList<KoShape*> dependees() const;
1002
1004 virtual KoSnapData snapData() const;
1005
1015 void setAdditionalAttribute(const QString &name, const QString &value);
1016
1022 void removeAdditionalAttribute(const QString &name);
1023
1031 bool hasAdditionalAttribute(const QString &name) const;
1032
1040 QString additionalAttribute(const QString &name) const;
1041
1042 void setAdditionalStyleAttribute(const char *name, const QString &value);
1043
1044 void removeAdditionalStyleAttribute(const char *name);
1045
1051 KoFilterEffectStack *filterEffectStack() const;
1052
1054 void setFilterEffectStack(KoFilterEffectStack *filterEffectStack);
1055
1065 QSet<KoShape*> toolDelegates() const;
1066
1072 void setToolDelegates(const QSet<KoShape*> &delegates);
1073
1077 QString hyperLink () const;
1078
1083 void setHyperLink(const QString &hyperLink);
1084
1092 virtual void setResolution(qreal xRes, qreal yRes);
1093
1094public:
1095
1096 struct KRITAFLAKE_EXPORT ShapeChangeListener {
1097 virtual ~ShapeChangeListener();
1098 virtual void notifyShapeChanged(ChangeType type, KoShape *shape) = 0;
1099
1100 private:
1101 friend class KoShape;
1102 void registerShape(KoShape *shape);
1103 void unregisterShape(KoShape *shape);
1104 void notifyShapeChangedImpl(ChangeType type, KoShape *shape);
1105
1107 };
1108
1109 void addShapeChangeListener(ShapeChangeListener *listener);
1110 void removeShapeChangeListener(ShapeChangeListener *listener);
1111
1112protected:
1113 QList<ShapeChangeListener *> listeners() const;
1114 void setSizeImpl(const QSizeF &size) const;
1115
1116public:
1117 static QList<KoShape*> linearizeSubtree(const QList<KoShape*> &shapes);
1118 static QList<KoShape *> linearizeSubtreeSorted(const QList<KoShape *> &shapes);
1119protected:
1120 KoShape(const KoShape &rhs);
1121
1128 virtual void shapeChanged(ChangeType type, KoShape *shape = 0);
1129
1131 QTransform transform() const;
1132
1133private:
1134 class Private;
1135 QScopedPointer<Private> d;
1136
1137 class SharedData;
1138 QSharedDataPointer<SharedData> s;
1139
1140
1141protected:
1146 void shapeChangedPriv(KoShape::ChangeType type);
1147
1148private:
1149 void addShapeManager(KoShapeManager *manager);
1150 void removeShapeManager(KoShapeManager *manager);
1151 friend class KoShapeManager;
1152};
1153
1156
1157#endif
float value(const T *src, size_t ch)
QPointF s1
QPointF s2
qreal distance(const QPointF &p1, const QPointF &p2)
The KisHandlePainterHelper class is a special helper for painting handles around objects....
Clip path used to clip shapes.
This class manages a stack of filter effects.
QScopedPointer< Private > d
Definition KoShape.h:1135
static const qint16 minZIndex
Definition KoShape.h:507
KoShapeAnchor * anchor() const
qreal minimumHeight() const
void setMinimumHeight(qreal height)
ChildZOrderPolicy
Used by compareShapeZIndex() to order shapes.
Definition KoShape.h:656
@ ChildZDefault
Definition KoShape.h:657
TextRunAroundContour
The behavior text should do when intersecting this shape.
Definition KoShape.h:131
@ ContourBox
Definition KoShape.h:132
@ ContourFull
Run other text around a bounding rect of the outline.
Definition KoShape.h:133
virtual void paint(QPainter &painter) const =0
Paint the shape fill The class extending this one is responsible for painting itself....
RunThroughLevel
Definition KoShape.h:140
@ Background
Definition KoShape.h:141
TextRunAroundSide
The behavior text should do when intersecting this shape.
Definition KoShape.h:120
@ 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
@ 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
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:95
@ 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
@ 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
@ Stroke
Definition KoShape.h:147
QSharedDataPointer< SharedData > s
Definition KoShape.h:1138
void setAnchor(KoShapeAnchor *anchor)
static const qint16 maxZIndex
Definition KoShape.h:502
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90
QList< KoShape * > m_registeredShapes
Definition KoShape.h:1106
virtual void notifyShapeChanged(ChangeType type, KoShape *shape)=0