Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeGroup.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
3 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#include "KoShapeGroup.h"
10#include "KoShapeContainer_p.h"
11#include "KoShapeLayer.h"
15#include "KoXmlWriter.h"
16#include "KoShapeRegistry.h"
17#include "KoShapeStrokeModel.h"
18#include "KoShapeShadow.h"
19#include "KoInsets.h"
20
21#include <FlakeDebug.h>
22
23#include <QPainter>
24
26{
27public:
30
36
37 void add(KoShape *child) override
38 {
41 }
42
43 void remove(KoShape *child) override
44 {
47 }
48
49 void childChanged(KoShape *shape, KoShape::ChangeType type) override
50 {
52 //debugFlake << type;
53 switch (type) {
64 break;
65 default:
66 break;
67 }
68 }
69
70private: // members
72};
73
75{
76public:
78
79 Private(const Private &) {}
80
81 virtual ~Private() = default;
82
83 mutable QRectF savedOutlineRect;
84 mutable bool sizeCached = false;
85
86};
87
94
96 : KoShapeContainer(rhs)
97 , d(new Private(*rhs.d))
98{
99 ShapeGroupContainerModel *otherModel = dynamic_cast<ShapeGroupContainerModel*>(rhs.model());
100 KIS_ASSERT_RECOVER_RETURN(otherModel);
101 setModelInit(new ShapeGroupContainerModel(*otherModel, this));
102}
103
114
116{
117 return new KoShapeGroup(*this);
118}
119
120void KoShapeGroup::paintComponent(QPainter &painter) const
121{
122 Q_UNUSED(painter);
123}
124
125bool KoShapeGroup::hitTest(const QPointF &position) const
126{
127 Q_UNUSED(position);
128 return false;
129}
130
132{
133 if (!d->sizeCached) {
134 QRectF bound;
135 Q_FOREACH (KoShape *shape, shapes()) {
136 bound |= shape->transformation().mapRect(shape->outlineRect());
137 }
138 d->savedOutlineRect = bound;
139 KoShape::setSizeImpl(bound.size());
140 d->sizeCached = true;
141 }
142}
143
144QSizeF KoShapeGroup::size() const
145{
147 return KoShape::size();
148}
149
150void KoShapeGroup::setSize(const QSizeF &size)
151{
152 QSizeF oldSize = this->size();
153 if (!shapeCount() || oldSize.isNull()) return;
154
155 const QTransform scale =
156 QTransform::fromScale(size.width() / oldSize.width(), size.height() / oldSize.height());
157
159
161}
162
164{
166 return d->savedOutlineRect;
167}
168
170{
171 QRectF groupBound = KoShape::boundingRect(shapes());
172
173 if (shadow()) {
174 KoInsets insets;
175 shadow()->insets(insets);
176 groupBound.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
177 }
178 return groupBound;
179}
180
182{
183 Q_UNUSED(shape);
185 switch (type) {
187 break;
188 default:
189 break;
190 }
191
193}
194
196{
197 d->sizeCached = false;
198}
virtual void childChanged(KoShape *shape, KoShape::ChangeType type)
void setModelInit(KoShapeContainerModel *model)
QList< KoShape * > shapes() const
KoShapeContainerModel * model
void shapeChanged(ChangeType type, KoShape *shape=0) override
Private(const Private &)
virtual ~Private()=default
void shapeChanged(ChangeType type, KoShape *shape=0) override
void tryUpdateCachedSize() const
QSizeF size() const override
Get the size of the shape in pt.
QRectF outlineRect() const override
KoShapeGroup()
Constructor.
void setSize(const QSizeF &size) override
Resize the shape.
~KoShapeGroup() override
destructor
QScopedPointer< Private > d
void paintComponent(QPainter &painter) const override
This implementation is empty since a group is itself not visible.
QRectF boundingRect() const override
a group's boundingRect
bool hitTest(const QPointF &position) const override
always returns false since the group itself can't be selected or hit
void invalidateSizeCache()
Invalidate the size cache of the group.
KoShape * cloneShape() const override
creates a deep copy of the shape or shape's subtree
friend class ShapeGroupContainerModel
void insets(KoInsets &insets) const
Fills the insets object with the space the shadow takes around a shape.
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:820
virtual QRectF outlineRect() const
Definition KoShape.cpp:637
void setSizeImpl(const QSizeF &size) const
Definition KoShape.cpp:290
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:417
KoShapeShadow * shadow() const
Returns the currently set shadow or 0 if there is no shadow set.
Definition KoShape.cpp:1116
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
@ ClipPathChanged
the shapes clip path has changed
Definition KoShape.h:114
@ ShearChanged
used after a shear()
Definition KoShape.h:99
@ ClipMaskChanged
the shapes clip path has changed
Definition KoShape.h:115
@ ParameterChanged
the shapes parameter has changed (KoParameterShape only)
Definition KoShape.h:109
@ ScaleChanged
used after a scale()
Definition KoShape.h:98
@ 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
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
Definition KoShape.cpp:237
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:276
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825
ShapeGroupContainerModel(KoShapeGroup *group)
void add(KoShape *child) override
void childChanged(KoShape *shape, KoShape::ChangeType type) override
ShapeGroupContainerModel(const ShapeGroupContainerModel &rhs, KoShapeGroup *group)
~ShapeGroupContainerModel() override
void remove(KoShape *child) override
void add(KoShape *child) override
void remove(KoShape *shape) override
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
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