15#include <klocalizedstring.h>
21 if (!orderedShapes.isEmpty()) {
22 KoShape * top = orderedShapes.last();
46 shouldNormalize(_shouldNormalize),
62 Q_FOREACH (
KoShape* shape,
d->shapes) {
63 d->oldParents.append(shape->
parent());
66 if (
d->container->shapes().isEmpty()) {
81 if (
d->shouldNormalize &&
dynamic_cast<KoShapeGroup*
>(
d->container)) {
82 QRectF bound =
d->containerBoundingRect();
85 d->container->setSize(bound.size());
87 if (
d->container->shapeCount() > 0) {
90 QPointF positionOffset = oldGroupPosition - bound.topLeft();
92 child->setAbsolutePosition(
child->absolutePosition() + positionOffset);
96 QTransform groupTransform =
d->container->absoluteTransformation().inverted();
102 Q_FOREACH (
KoShape *shape, containerShapes) {
108 Q_FOREACH (
KoShape *shape,
d->shapes) {
120 indexedShapes = prependIndexedShapes + indexedShapes;
123 if (!indexedShapes.isEmpty()) {
125 d->shapesReorderCommand->redo();
128 uint shapeCount =
d->shapes.count();
129 for (
uint i = 0; i < shapeCount; ++i) {
133 d->container->addShape(shape);
143 QTransform ungroupTransform =
d->container->absoluteTransformation();
144 for (
int i = 0; i <
d->shapes.count(); i++) {
146 d->container->removeShape(shape);
147 if (
d->oldParents.at(i)) {
148 d->oldParents.at(i)->addShape(shape);
153 if (
d->shapesReorderCommand) {
154 d->shapesReorderCommand->undo();
155 d->shapesReorderCommand.reset();
158 if (
d->shouldNormalize &&
dynamic_cast<KoShapeGroup*
>(
d->container)) {
160 if (
d->container->shapeCount() > 0) {
161 bool boundingRectInitialized =
false;
163 Q_FOREACH (
KoShape * shape,
d->container->shapes()) {
164 if (! boundingRectInitialized) {
166 boundingRectInitialized =
true;
172 QPointF positionOffset = oldGroupPosition - bound.topLeft();
174 child->setAbsolutePosition(
child->absolutePosition() + positionOffset);
177 d->container->setSize(bound.size());
void setText(const KUndo2MagicString &text)
const KUndo2Command * child(int index) const
KoShapeContainer * container
the container where the grouping should be for.
bool shouldNormalize
Adjust the coordinate system of the group to its origin into the topleft of the group.
QList< KoShapeContainer * > oldParents
the old parents of the shapes
QScopedPointer< KUndo2Command > shapesReorderCommand
QList< KoShape * > shapes
list of shapes to be grouped
KoShapeGroupCommandPrivate(KoShapeContainer *container, const QList< KoShape * > &shapes, bool _shouldNormalize)
QRectF containerBoundingRect()
The undo / redo command for grouping shapes.
~KoShapeGroupCommand() override
const QScopedPointer< KoShapeGroupCommandPrivate > d
KoShapeGroupCommand(KoShapeContainer *container, const QList< KoShape * > &shapes, bool shouldNormalize, KUndo2Command *parent=0)
void redo() override
redo the command
void undo() override
revert the actions done in redo
static KoShapeGroupCommand * createCommand(KoShapeContainer *container, const QList< KoShape * > &shapes, bool shouldNormalize=false)
This command allows you to change the zIndex of a number of shapes.
static QList< KoShapeReorderCommand::IndexedShape > homogenizeZIndexesLazy(QList< IndexedShape > shapes)
virtual QRectF outlineRect() const
bool hasCommonParent(const KoShape *shape) const
void setZIndex(qint16 zIndex)
void applyAbsoluteTransformation(const QTransform &matrix)
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
virtual QRectF boundingRect() const
Get the bounding box of the shape.
KoShapeContainer * parent() const
QTransform absoluteTransformation() const
void setParent(KoShapeContainer *parent)
KUndo2MagicString kundo2_i18n(const char *text)