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;
37class KoSnapData;
38class KoClipPath;
39class KoClipMask;
40class KoShapeAnchor;
41struct KoInsets;
44class KoShapeManager;
45
88class KRITAFLAKE_EXPORT KoShape
89{
90public:
114
118 Markers
119 };
120
124 KoShape();
125
129 virtual ~KoShape();
130
135 virtual KoShape* cloneShape() const;
136
149 KoShape* cloneShapeAndBakeAbsoluteTransform() const;
150
158 virtual void paint(QPainter &painter) const = 0;
159
165 virtual void paintStroke(QPainter &painter) const;
166
172 virtual void paintMarkers(QPainter &painter) const;
173
181 void scale(qreal sx, qreal sy);
182
190 void rotate(qreal angle);
191
196 qreal rotation() const;
197
206 void shear(qreal sx, qreal sy);
207
217 virtual void setSize(const QSizeF &size);
218
226 virtual QSizeF size() const;
227
233 virtual void setPosition(const QPointF &position);
234
240 QPointF position() const;
241
247 virtual bool hitTest(const QPointF &position) const;
248
256 virtual QRectF boundingRect() const;
257
262 static QRectF boundingRect(const QList<KoShape*> &shapes);
263
270 QRectF absoluteOutlineRect() const;
271
276 static QRectF absoluteOutlineRect(const QList<KoShape*> &shapes);
277
282
287
293 void setMinimumHeight(qreal height);
294
299 qreal minimumHeight() const;
300
301
314 virtual void setBackground(QSharedPointer<KoShapeBackground> background);
315
323 virtual QSharedPointer<KoShapeBackground> background() const;
324
330 void setInheritBackground(bool value);
331
336 bool inheritBackground() const;
337
344 virtual bool hasTransparency() const;
345
350 void setTransparency(qreal transparency);
351
356 qreal transparency(bool recursive=false) const;
357
365 qint16 zIndex() const;
366
378 void setZIndex(qint16 zIndex);
379
383 static const qint16 maxZIndex;
384
388 static const qint16 minZIndex;
389
397 void setVisible(bool on);
406 bool isVisible(bool recursive = true) const;
407
415 void setPrintable(bool on);
416
425 bool isPrintable() const;
426
433 void setSelectable(bool selectable);
434
440 bool isSelectable() const;
441
449 void setGeometryProtected(bool on);
450
458 bool isGeometryProtected() const;
459
466 void setContentProtected(bool protect);
467
474 bool isContentProtected() const;
475
480 KoShapeContainer *parent() const;
481
486 void setParent(KoShapeContainer *parent);
487
488
495 bool inheritsTransformFromAny(const QList<KoShape*> ancestorsInQuestion) const;
496
500 bool hasCommonParent(const KoShape *shape) const;
501
509 virtual void update() const;
510
520 virtual void updateAbsolute(const QRectF &rect) const;
521
525 ChildZParentChild = ChildZDefault,
526 ChildZPassThrough
527 };
528
539 virtual ChildZOrderPolicy childZOrderPolicy();
540
546 static bool compareShapeZIndex(KoShape *s1, KoShape *s2);
547
555 virtual QPainterPath outline() const;
556
564 virtual QRectF outlineRect() const;
565
570 virtual KoShapeStrokeModelSP stroke() const;
571
576 virtual void setStroke(KoShapeStrokeModelSP stroke);
577
583 void setInheritStroke(bool value);
584
589 bool inheritStroke() const;
590
595 KoInsets strokeInsets() const;
596
605 virtual void setPaintOrder(PaintOrder first, PaintOrder second);
606
611 virtual QVector<PaintOrder> paintOrder() const;
612
617 static QVector<PaintOrder> defaultPaintOrder();
618
624 void setInheritPaintOrder(bool value);
625
630 bool inheritPaintOrder() const;
631
633 void setClipPath(KoClipPath *clipPath);
634
636 KoClipPath * clipPath() const;
637
639 void setClipMask(KoClipMask *clipMask);
640
642 KoClipMask* clipMask() const;
643
650 void setKeepAspectRatio(bool keepAspect);
651
658 bool keepAspectRatio() const;
659
666 QPointF absolutePosition(KoFlake::AnchorPosition anchor = KoFlake::Center) const;
667
682 void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor = KoFlake::Center);
683
690 void setUserData(KoShapeUserData *userData);
694 KoShapeUserData *userData() const;
695
701 QString shapeId() const;
702
709 void setShapeId(const QString &id);
710
717 QTransform absoluteTransformation() const;
718
728 void applyAbsoluteTransformation(const QTransform &matrix);
729
734 void setTransformation(const QTransform &matrix);
735
737 QTransform transformation() const;
738
746 void applyTransformation(const QTransform &matrix);
747
754 void copySettings(const KoShape *shape);
755
761 static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius = 0.0, int decorationThickness = 1);
762 static KisHandlePainterHelper createHandlePainterHelperDocument(QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness);
763
769 QPointF shapeToDocument(const QPointF &point) const;
770
776 QRectF shapeToDocument(const QRectF &rect) const;
777
783 QPointF documentToShape(const QPointF &point) const;
784
790 QRectF documentToShape(const QRectF &rect) const;
791
796 QString name() const;
797
802 void setName(const QString &name);
803
807 void notifyChanged();
808
821 virtual void waitUntilReady(bool asynchronous = true) const;
822
824 virtual bool isShapeEditable(bool recursive = true) const;
825
838 bool addDependee(KoShape *shape);
839
844 void removeDependee(KoShape *shape);
845
847 bool hasDependee(KoShape *shape) const;
848
850 QList<KoShape*> dependees() const;
851
853 virtual KoSnapData snapData() const;
854
864 void setAdditionalAttribute(const QString &name, const QString &value);
865
871 void removeAdditionalAttribute(const QString &name);
872
880 bool hasAdditionalAttribute(const QString &name) const;
881
889 QString additionalAttribute(const QString &name) const;
890
891 void setAdditionalStyleAttribute(const char *name, const QString &value);
892
893 void removeAdditionalStyleAttribute(const char *name);
894
904 QSet<KoShape*> toolDelegates() const;
905
911 void setToolDelegates(const QSet<KoShape*> &delegates);
912
916 QString hyperLink () const;
917
922 void setHyperLink(const QString &hyperLink);
923
931 virtual void setResolution(qreal xRes, qreal yRes);
932
933public:
934
935 struct KRITAFLAKE_EXPORT ShapeChangeListener {
936 virtual ~ShapeChangeListener();
937 virtual void notifyShapeChanged(ChangeType type, KoShape *shape) = 0;
938
939 private:
940 friend class KoShape;
941 void registerShape(KoShape *shape);
942 void unregisterShape(KoShape *shape);
943 void notifyShapeChangedImpl(ChangeType type, KoShape *shape);
944
946 };
947
948 void addShapeChangeListener(ShapeChangeListener *listener);
949 void removeShapeChangeListener(ShapeChangeListener *listener);
950
951protected:
952 QList<ShapeChangeListener *> listeners() const;
953 void setSizeImpl(const QSizeF &size) const;
954
955public:
956 static QList<KoShape*> linearizeSubtree(const QList<KoShape*> &shapes);
957 static QList<KoShape *> linearizeSubtreeSorted(const QList<KoShape *> &shapes);
958protected:
959 KoShape(const KoShape &rhs);
960
967 virtual void shapeChanged(ChangeType type, KoShape *shape = 0);
968
970 QTransform transform() const;
971
972private:
973 class Private;
974 QScopedPointer<Private> d;
975
976 class SharedData;
977 QSharedDataPointer<SharedData> s;
978
979
980protected:
985 void shapeChangedPriv(KoShape::ChangeType type);
986
987private:
988 void addShapeManager(KoShapeManager *manager);
989 void removeShapeManager(KoShapeManager *manager);
990 friend class KoShapeManager;
991};
992
995
996#endif
float value(const T *src, size_t ch)
QPointF s1
QPointF s2
The KisHandlePainterHelper class is a special helper for painting handles around objects....
Clip path used to clip shapes.
QScopedPointer< Private > d
Definition KoShape.h:974
static const qint16 minZIndex
Definition KoShape.h:388
KoShapeAnchor * anchor() const
qreal minimumHeight() const
void setMinimumHeight(qreal height)
ChildZOrderPolicy
Used by compareShapeZIndex() to order shapes.
Definition KoShape.h:523
@ ChildZDefault
Definition KoShape.h:524
virtual void paint(QPainter &painter) const =0
Paint the shape fill The class extending this one is responsible for painting itself....
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:92
@ RotationChanged
used after a setRotation()
Definition KoShape.h:94
@ StrokeChanged
the shapes stroke has changed
Definition KoShape.h:102
@ PositionChanged
used after a setPosition()
Definition KoShape.h:93
@ Deleted
the shape was deleted
Definition KoShape.h:101
@ ClipPathChanged
the shapes clip path has changed
Definition KoShape.h:110
@ ConnectionPointChanged
a connection point has changed
Definition KoShape.h:109
@ ShearChanged
used after a shear()
Definition KoShape.h:96
@ ParentChanged
used after a setParent()
Definition KoShape.h:100
@ ContentChanged
the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
Definition KoShape.h:106
@ ClipMaskChanged
the shapes clip path has changed
Definition KoShape.h:111
@ ParameterChanged
the shapes parameter has changed (KoParameterShape only)
Definition KoShape.h:105
@ BackgroundChanged
the shapes background has changed
Definition KoShape.h:103
@ ChildChanged
a child of a container was changed/removed. This is propagated to all parents
Definition KoShape.h:108
@ TextContourMarginChanged
used after text properties changed and modified the contour margin in the text shape
Definition KoShape.h:107
@ ScaleChanged
used after a scale()
Definition KoShape.h:95
@ KeepAspectRatioChange
used after setKeepAspectRatio()
Definition KoShape.h:99
@ BorderChanged
the shapes border has changed
Definition KoShape.h:104
@ SizeChanged
used after a setSize()
Definition KoShape.h:97
@ GenericMatrixChange
used after the matrix was changed without knowing which property explicitly changed
Definition KoShape.h:98
@ Stroke
Definition KoShape.h:117
QSharedDataPointer< SharedData > s
Definition KoShape.h:977
void setAnchor(KoShapeAnchor *anchor)
static const qint16 maxZIndex
Definition KoShape.h:383
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90
QList< KoShape * > m_registeredShapes
Definition KoShape.h:945
virtual void notifyShapeChanged(ChangeType type, KoShape *shape)=0