File indexing completed on 2025-01-26 04:04:54
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net> 0003 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "kis_command_ids.h" 0009 0010 #include "KoShapeTransformCommand.h" 0011 #include "KoShape.h" 0012 0013 #include <QList> 0014 #include <QTransform> 0015 0016 #include <FlakeDebug.h> 0017 0018 class Q_DECL_HIDDEN KoShapeTransformCommand::Private 0019 { 0020 public: 0021 Private(const QList<KoShape*> &list) : shapes(list) { } 0022 QList<KoShape*> shapes; 0023 QList<QTransform> oldState; 0024 QList<QTransform> newState; 0025 }; 0026 0027 KoShapeTransformCommand::KoShapeTransformCommand(const QList<KoShape*> &shapes, const QList<QTransform> &oldState, const QList<QTransform> &newState, KUndo2Command * parent) 0028 : KUndo2Command(parent), 0029 d(new Private(shapes)) 0030 { 0031 Q_ASSERT(shapes.count() == oldState.count()); 0032 Q_ASSERT(shapes.count() == newState.count()); 0033 d->oldState = oldState; 0034 d->newState = newState; 0035 } 0036 0037 KoShapeTransformCommand::~KoShapeTransformCommand() 0038 { 0039 delete d; 0040 } 0041 0042 void KoShapeTransformCommand::redo() 0043 { 0044 KUndo2Command::redo(); 0045 0046 const int shapeCount = d->shapes.count(); 0047 for (int i = 0; i < shapeCount; ++i) { 0048 KoShape * shape = d->shapes[i]; 0049 const QRectF oldDirtyRect = shape->boundingRect(); 0050 shape->setTransformation(d->newState[i]); 0051 shape->updateAbsolute(oldDirtyRect | shape->boundingRect()); 0052 } 0053 } 0054 0055 void KoShapeTransformCommand::undo() 0056 { 0057 KUndo2Command::undo(); 0058 0059 const int shapeCount = d->shapes.count(); 0060 for (int i = 0; i < shapeCount; ++i) { 0061 KoShape * shape = d->shapes[i]; 0062 const QRectF oldDirtyRect = shape->boundingRect(); 0063 shape->setTransformation(d->oldState[i]); 0064 shape->updateAbsolute(oldDirtyRect | shape->boundingRect()); 0065 } 0066 } 0067 0068 int KoShapeTransformCommand::id() const 0069 { 0070 return KisCommandUtils::TransformShapeId; 0071 } 0072 0073 bool KoShapeTransformCommand::mergeWith(const KUndo2Command *command) 0074 { 0075 const KoShapeTransformCommand *other = dynamic_cast<const KoShapeTransformCommand*>(command); 0076 0077 if (!other || 0078 other->d->shapes != d->shapes || 0079 other->text() != text()) { 0080 0081 return false; 0082 } 0083 0084 d->newState = other->d->newState; 0085 return true; 0086 }