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 "KoInsets.h"
19
20#include <FlakeDebug.h>
21
22#include <QPainter>
23
25{
26public:
29
35
36 void add(KoShape *child) override
37 {
40 }
41
42 void remove(KoShape *child) override
43 {
46 }
47
48 void childChanged(KoShape *shape, KoShape::ChangeType type) override
49 {
51 //debugFlake << type;
52 switch (type) {
63 break;
64 default:
65 break;
66 }
67 }
68
69private: // members
71};
72
74{
75public:
77
78 Private(const Private &) {}
79
80 virtual ~Private() = default;
81
82 mutable QRectF savedOutlineRect;
83 mutable bool sizeCached = false;
84
85};
86
93
95 : KoShapeContainer(rhs)
96 , d(new Private(*rhs.d))
97{
98 ShapeGroupContainerModel *otherModel = dynamic_cast<ShapeGroupContainerModel*>(rhs.model());
99 KIS_ASSERT_RECOVER_RETURN(otherModel);
100 setModelInit(new ShapeGroupContainerModel(*otherModel, this));
101}
102
113
115{
116 return new KoShapeGroup(*this);
117}
118
119void KoShapeGroup::paintComponent(QPainter &painter) const
120{
121 Q_UNUSED(painter);
122}
123
124bool KoShapeGroup::hitTest(const QPointF &position) const
125{
126 Q_UNUSED(position);
127 return false;
128}
129
131{
132 if (!d->sizeCached) {
133 QRectF bound;
134 Q_FOREACH (KoShape *shape, shapes()) {
135 bound |= shape->transformation().mapRect(shape->outlineRect());
136 }
137 d->savedOutlineRect = bound;
138 KoShape::setSizeImpl(bound.size());
139 d->sizeCached = true;
140 }
141}
142
143QSizeF KoShapeGroup::size() const
144{
146 return KoShape::size();
147}
148
149void KoShapeGroup::setSize(const QSizeF &size)
150{
151 QSizeF oldSize = this->size();
152 if (!shapeCount() || oldSize.isNull()) return;
153
154 const QTransform scale =
155 QTransform::fromScale(size.width() / oldSize.width(), size.height() / oldSize.height());
156
158
160}
161
163{
165 return d->savedOutlineRect;
166}
167
169{
171}
172
174{
175 Q_UNUSED(shape);
177 switch (type) {
179 break;
180 default:
181 break;
182 }
183
185}
186
188{
189 d->sizeCached = false;
190}
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
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:740
virtual QRectF outlineRect() const
Definition KoShape.cpp:566
void setSizeImpl(const QSizeF &size) const
Definition KoShape.cpp:262
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:299
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:374
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
@ ClipPathChanged
the shapes clip path has changed
Definition KoShape.h:110
@ ShearChanged
used after a shear()
Definition KoShape.h:96
@ ClipMaskChanged
the shapes clip path has changed
Definition KoShape.h:111
@ ParameterChanged
the shapes parameter has changed (KoParameterShape only)
Definition KoShape.h:105
@ ScaleChanged
used after a scale()
Definition KoShape.h:95
@ 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
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
Definition KoShape.cpp:209
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:383
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:248
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:745
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