21#include "layermanager.h"
22#include "selectionmanager.h"
24#include "layersound.h"
25#include "layerbitmap.h"
26#include "layervector.h"
30#include "undoredocommand.h"
34 qDebug() <<
"backupElement created";
38KeyFrameRemoveCommand::KeyFrameRemoveCommand(
const KeyFrame* undoKeyFrame,
44 this->undoKeyFrame = undoKeyFrame->clone();
45 this->undoLayerId = undoLayerId;
47 this->redoLayerId = editor->layers()->currentLayer()->id();
48 this->redoPosition = editor->currentFrame();
53KeyFrameRemoveCommand::~KeyFrameRemoveCommand()
58void KeyFrameRemoveCommand::undo()
60 Layer* layer = editor()->layers()->findLayerById(undoLayerId);
61 if (layer ==
nullptr) {
69 layer->
addKeyFrame(undoKeyFrame->pos(), undoKeyFrame->clone());
73 editor()->scrubTo(undoKeyFrame->pos());
76void KeyFrameRemoveCommand::redo()
78 Layer* layer = editor()->layers()->findLayerById(redoLayerId);
79 if (layer ==
nullptr) {
87 if (isFirstRedo()) { setFirstRedo(
false);
return; }
89 layer->removeKeyFrame(redoPosition);
93 editor()->scrubTo(redoPosition);
96KeyFrameAddCommand::KeyFrameAddCommand(
int undoPosition,
103 this->undoPosition = undoPosition;
104 this->undoLayerId = undoLayerId;
106 this->redoLayerId = editor->layers()->currentLayer()->id();
107 this->redoPosition = editor->currentFrame();
109 setText(description);
112void KeyFrameAddCommand::undo()
114 Layer* layer = editor()->layers()->findLayerById(undoLayerId);
121 layer->removeKeyFrame(undoPosition);
125 editor()->layers()->setCurrentLayer(layer);
126 editor()->scrubTo(undoPosition);
129void KeyFrameAddCommand::redo()
131 Layer* layer = editor()->layers()->findLayerById(redoLayerId);
139 if (isFirstRedo()) { setFirstRedo(
false);
return; }
145 editor()->layers()->setCurrentLayer(layer);
146 editor()->scrubTo(redoPosition);
149MoveKeyFramesCommand::MoveKeyFramesCommand(
int offset,
157 this->frameOffset = offset;
158 this->positions = listOfPositions;
160 this->undoLayerId = undoLayerId;
161 this->redoLayerId = editor->layers()->currentLayer()->id();
163 setText(description);
166void MoveKeyFramesCommand::undo()
168 Layer* undoLayer = editor()->layers()->findLayerById(undoLayerId);
176 for (
int position : qAsConst(positions)) {
177 undoLayer->setFrameSelected(position,
true);
179 undoLayer->moveSelectedFrames(-frameOffset);
184void MoveKeyFramesCommand::redo()
186 Layer* redoLayer = editor()->layers()->findLayerById(redoLayerId);
195 if (isFirstRedo()) { setFirstRedo(
false);
return; }
200 for (
int position : qAsConst(newPositions)) {
201 redoLayer->setFrameSelected(position,
true);
204 redoLayer->moveSelectedFrames(frameOffset);
208BitmapReplaceCommand::BitmapReplaceCommand(
const BitmapImage* undoBitmap,
209 const int undoLayerId,
215 this->undoBitmap = *undoBitmap;
216 this->undoLayerId = undoLayerId;
218 Layer* layer = editor->layers()->currentLayer();
219 redoLayerId = layer->id();
221 getLastBitmapImageAtFrame(editor->currentFrame());
223 setText(description);
226void BitmapReplaceCommand::undo()
228 Layer* layer = editor()->layers()->findLayerById(undoLayerId);
235 static_cast<LayerBitmap*
>(layer)->replaceKeyFrame(&undoBitmap);
237 editor()->scrubTo(undoBitmap.pos());
240void BitmapReplaceCommand::redo()
242 Layer* layer = editor()->layers()->findLayerById(redoLayerId);
250 if (isFirstRedo()) { setFirstRedo(
false);
return; }
252 static_cast<LayerBitmap*
>(layer)->replaceKeyFrame(&redoBitmap);
254 editor()->scrubTo(redoBitmap.pos());
257VectorReplaceCommand::VectorReplaceCommand(
const VectorImage* undoVector,
258 const int undoLayerId,
264 this->undoVector = *undoVector;
265 this->undoLayerId = undoLayerId;
266 Layer* layer = editor->layers()->currentLayer();
267 redoLayerId = layer->id();
269 getLastVectorImageAtFrame(editor->currentFrame());
271 setText(description);
274void VectorReplaceCommand::undo()
276 Layer* layer = editor()->layers()->findLayerById(undoLayerId);
283 static_cast<LayerVector*
>(layer)->replaceKeyFrame(&undoVector);
285 editor()->scrubTo(undoVector.pos());
288void VectorReplaceCommand::redo()
290 Layer* layer = editor()->layers()->findLayerById(redoLayerId);
298 if (isFirstRedo()) { setFirstRedo(
false);
return; }
300 static_cast<LayerVector*
>(layer)->replaceKeyFrame(&redoVector);
302 editor()->scrubTo(redoVector.pos());
305TransformCommand::TransformCommand(
const QRectF& undoSelectionRect,
306 const QPointF& undoTranslation,
307 const qreal undoRotationAngle,
308 const qreal undoScaleX,
309 const qreal undoScaleY,
310 const QPointF& undoTransformAnchor,
311 const bool roundPixels,
316 this->roundPixels = roundPixels;
318 this->undoSelectionRect = undoSelectionRect;
319 this->undoAnchor = undoTransformAnchor;
320 this->undoTranslation = undoTranslation;
321 this->undoRotationAngle = undoRotationAngle;
322 this->undoScaleX = undoScaleX;
323 this->undoScaleY = undoScaleY;
325 auto selectMan = editor->select();
326 redoSelectionRect = selectMan->mySelectionRect();
327 redoAnchor = selectMan->currentTransformAnchor();
328 redoTranslation = selectMan->myTranslation();
329 redoRotationAngle = selectMan->myRotation();
330 redoScaleX = selectMan->myScaleX();
331 redoScaleY = selectMan->myScaleY();
333 setText(description);
336void TransformCommand::undo()
339 apply(undoSelectionRect,
348void TransformCommand::redo()
353 if (isFirstRedo()) { setFirstRedo(
false);
return; }
355 apply(redoSelectionRect,
364void TransformCommand::apply(
const QRectF& selectionRect,
366 const qreal rotationAngle,
369 const QPointF& selectionAnchor,
370 const bool roundPixels)
372 auto selectMan = editor()->select();
374 selectMan->setTransformAnchor(selectionAnchor);
375 selectMan->setTranslation(translation);
376 selectMan->setRotation(rotationAngle);
377 selectMan->setScale(scaleX, scaleY);
379 selectMan->calculateSelectionTransformation();
void framesModified()
This should be emitted after modifying multiple frames.
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
bool addNewKeyFrameAt(int position)
Creates a new keyframe at the given position, unless one already exists.
virtual bool addKeyFrame(int position, KeyFrame *pKeyFrame)
Adds a keyframe at the given position, unless one already exists.
void notifyAnimationLengthChanged()
This should be emitted whenever the animation length frames, eg.
void setSelection(QRectF rect, bool roundPixels=false)
Defines the selection area.
void setObsolete(bool obsolete)