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:
115
119 Markers
120 };
121
125 KoShape();
126
130 virtual ~KoShape();
131
136 virtual KoShape* cloneShape() const;
137
150 KoShape* cloneShapeAndBakeAbsoluteTransform() const;
151
159 virtual void paint(QPainter &painter) const = 0;
160
166 virtual void paintStroke(QPainter &painter) const;
167
173 virtual void paintMarkers(QPainter &painter) const;
174
182 void scale(qreal sx, qreal sy);
183
191 void rotate(qreal angle);
192
197 qreal rotation() const;
198
207 void shear(qreal sx, qreal sy);
208
218 virtual void setSize(const QSizeF &size);
219
227 virtual QSizeF size() const;
228
234 virtual void setPosition(const QPointF &position);
235
241 QPointF position() const;
242
248 virtual bool hitTest(const QPointF &position) const;
249
257 virtual QRectF boundingRect() const;
258
263 static QRectF boundingRect(const QList<KoShape*> &shapes);
264
271 QRectF absoluteOutlineRect() const;
272
277 static QRectF absoluteOutlineRect(const QList<KoShape*> &shapes);
278
283
288
294 void setMinimumHeight(qreal height);
295
300 qreal minimumHeight() const;
301
302
315 virtual void setBackground(QSharedPointer<KoShapeBackground> background);
316
324 virtual QSharedPointer<KoShapeBackground> background() const;
325
331 void setInheritBackground(bool value);
332
337 bool inheritBackground() const;
338
345 virtual bool hasTransparency() const;
346
351 void setTransparency(qreal transparency);
352
357 qreal transparency(bool recursive=false) const;
358
366 qint16 zIndex() const;
367
379 void setZIndex(qint16 zIndex);
380
384 static const qint16 maxZIndex;
385
389 static const qint16 minZIndex;
390
398 void setVisible(bool on);
407 bool isVisible(bool recursive = true) const;
408
416 void setPrintable(bool on);
417
426 bool isPrintable() const;
427
434 void setSelectable(bool selectable);
435
441 bool isSelectable() const;
442
450 void setGeometryProtected(bool on);
451
459 bool isGeometryProtected() const;
460
467 void setContentProtected(bool protect);
468
475 bool isContentProtected() const;
476
481 KoShapeContainer *parent() const;
482
487 void setParent(KoShapeContainer *parent);
488
489
496 bool inheritsTransformFromAny(const QList<KoShape*> ancestorsInQuestion) const;
497
501 bool hasCommonParent(const KoShape *shape) const;
502
510 virtual void update() const;
511
521 virtual void updateAbsolute(const QRectF &rect) const;
522
526 ChildZParentChild = ChildZDefault,
527 ChildZPassThrough
528 };
529
540 virtual ChildZOrderPolicy childZOrderPolicy();
541
547 static bool compareShapeZIndex(KoShape *s1, KoShape *s2);
548
556 virtual QPainterPath outline() const;
557
565 virtual QRectF outlineRect() const;
566
571 virtual KoShapeStrokeModelSP stroke() const;
572
577 virtual void setStroke(KoShapeStrokeModelSP stroke);
578
584 void setInheritStroke(bool value);
585
590 bool inheritStroke() const;
591
596 KoInsets strokeInsets() const;
597
606 virtual void setPaintOrder(PaintOrder first, PaintOrder second);
607
612 virtual QVector<PaintOrder> paintOrder() const;
613
618 static QVector<PaintOrder> defaultPaintOrder();
619
625 void setInheritPaintOrder(bool value);
626
631 bool inheritPaintOrder() const;
632
634 void setClipPath(KoClipPath *clipPath);
635
637 KoClipPath * clipPath() const;
638
640 void setClipMask(KoClipMask *clipMask);
641
643 KoClipMask* clipMask() const;
644
651 void setKeepAspectRatio(bool keepAspect);
652
659 bool keepAspectRatio() const;
660
667 QPointF absolutePosition(KoFlake::AnchorPosition anchor = KoFlake::Center) const;
668
683 void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor = KoFlake::Center);
684
691 void setUserData(KoShapeUserData *userData);
695 KoShapeUserData *userData() const;
696
702 QString shapeId() const;
703
710 void setShapeId(const QString &id);
711
718 QTransform absoluteTransformation() const;
719
729 void applyAbsoluteTransformation(const QTransform &matrix);
730
735 void setTransformation(const QTransform &matrix);
736
738 QTransform transformation() const;
739
747 void applyTransformation(const QTransform &matrix);
748
755 void copySettings(const KoShape *shape);
756
762 static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius = 0.0, int decorationThickness = 1);
763 static KisHandlePainterHelper createHandlePainterHelperDocument(QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness);
764
770 QPointF shapeToDocument(const QPointF &point) const;
771
777 QRectF shapeToDocument(const QRectF &rect) const;
778
784 QPointF documentToShape(const QPointF &point) const;
785
791 QRectF documentToShape(const QRectF &rect) const;
792
797 QString name() const;
798
803 void setName(const QString &name);
804
808 void notifyChanged();
809
822 virtual void waitUntilReady(bool asynchronous = true) const;
823
825 virtual bool isShapeEditable(bool recursive = true) const;
826
839 bool addDependee(KoShape *shape);
840
845 void removeDependee(KoShape *shape);
846
848 bool hasDependee(KoShape *shape) const;
849
851 QList<KoShape*> dependees() const;
852
854 virtual KoSnapData snapData() const;
855
865 void setAdditionalAttribute(const QString &name, const QString &value);
866
872 void removeAdditionalAttribute(const QString &name);
873
881 bool hasAdditionalAttribute(const QString &name) const;
882
890 QString additionalAttribute(const QString &name) const;
891
892 void setAdditionalStyleAttribute(const char *name, const QString &value);
893
894 void removeAdditionalStyleAttribute(const char *name);
895
905 QSet<KoShape*> toolDelegates() const;
906
912 void setToolDelegates(const QSet<KoShape*> &delegates);
913
917 QString hyperLink () const;
918
923 void setHyperLink(const QString &hyperLink);
924
932 virtual void setResolution(qreal xRes, qreal yRes);
933
934public:
935
936 struct KRITAFLAKE_EXPORT ShapeChangeListener {
937 virtual ~ShapeChangeListener();
938 virtual void notifyShapeChanged(ChangeType type, KoShape *shape) = 0;
939
940 private:
941 friend class KoShape;
942 void registerShape(KoShape *shape);
943 void unregisterShape(KoShape *shape);
944 void notifyShapeChangedImpl(ChangeType type, KoShape *shape);
945
947 };
948
949 void addShapeChangeListener(ShapeChangeListener *listener);
950 void removeShapeChangeListener(ShapeChangeListener *listener);
951
952protected:
953 QList<ShapeChangeListener *> listeners() const;
954 void setSizeImpl(const QSizeF &size) const;
955
956public:
957 static QList<KoShape*> linearizeSubtree(const QList<KoShape*> &shapes);
958 static QList<KoShape *> linearizeSubtreeSorted(const QList<KoShape *> &shapes);
959protected:
960 KoShape(const KoShape &rhs);
961
968 virtual void shapeChanged(ChangeType type, KoShape *shape = 0);
969
971 QTransform transform() const;
972
973private:
974 class Private;
975 QScopedPointer<Private> d;
976
977 class SharedData;
978 QSharedDataPointer<SharedData> s;
979
980
981protected:
986 void shapeChangedPriv(KoShape::ChangeType type);
987
988private:
989 void addShapeManager(KoShapeManager *manager);
990 void removeShapeManager(KoShapeManager *manager);
991 friend class KoShapeManager;
992};
993
996
997#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:975
static const qint16 minZIndex
Definition KoShape.h:389
KoShapeAnchor * anchor() const
qreal minimumHeight() const
void setMinimumHeight(qreal height)
ChildZOrderPolicy
Used by compareShapeZIndex() to order shapes.
Definition KoShape.h:524
@ ChildZDefault
Definition KoShape.h:525
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
@ GeometryProtectedChanged
used after a setPosition()
Definition KoShape.h:113
@ StrokeChanged
the shapes stroke has changed
Definition KoShape.h:102
@ PositionChanged
used after a setPosition()
Definition KoShape.h:93
@ TransparencyChanged
the shapetransparency value has changed
Definition KoShape.h:112
@ 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:118
QSharedDataPointer< SharedData > s
Definition KoShape.h:978
void setAnchor(KoShapeAnchor *anchor)
static const qint16 maxZIndex
Definition KoShape.h:384
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90
QList< KoShape * > m_registeredShapes
Definition KoShape.h:946
virtual void notifyShapeChanged(ChangeType type, KoShape *shape)=0