Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • interface
undoredocommand.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2008-2009 Mj Mendoza IV
6Copyright (C) 2012-2020 Matthew Chiawen Chang
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; version 2 of the License.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17*/
18
19#ifndef UNDOREDOCOMMAND_H
20#define UNDOREDOCOMMAND_H
21
22#include <QUndoCommand>
23#include <QRectF>
24
25#include "bitmapimage.h"
26#include "vectorimage.h"
27#include "soundclip.h"
28#include "camera.h"
29#include "layer.h"
30
31class Editor;
32class UndoRedoManager;
33class PreferenceManager;
34class SoundClip;
35class Camera;
36class KeyFrame;
37class TransformCommand;
38
39class UndoRedoCommand : public QUndoCommand
40{
41public:
42 explicit UndoRedoCommand(Editor* editor, QUndoCommand* parent = nullptr);
43 ~UndoRedoCommand() = default;
44
45protected:
46 Editor* editor() const { return mEditor; }
47
48 bool isFirstRedo() const { return mIsFirstRedo; }
49 void setFirstRedo(const bool state) { mIsFirstRedo = state; }
50
51private:
52 Editor* mEditor = nullptr;
53 bool mIsFirstRedo = true;
54};
55
56class KeyFrameRemoveCommand : public UndoRedoCommand
57{
58public:
59 KeyFrameRemoveCommand(const KeyFrame* undoKeyFrame,
60 int undoLayerId,
61 const QString& description,
62 Editor* editor,
63 QUndoCommand* parent = nullptr
64 );
65 ~KeyFrameRemoveCommand() override;
66
67 void undo() override;
68 void redo() override;
69
70private:
71
72 int undoLayerId = 0;
73 int redoLayerId = 0;
74
75 KeyFrame* undoKeyFrame = nullptr;
76 int redoPosition = 0;
77};
78
79class KeyFrameAddCommand : public UndoRedoCommand
80{
81public:
82 KeyFrameAddCommand(int undoPosition,
83 int undoLayerId,
84 const QString& description,
85 Editor* editor,
86 QUndoCommand* parent = nullptr);
87 ~KeyFrameAddCommand() = default;
88
89 void undo() override;
90 void redo() override;
91
92private:
93
94 int undoLayerId = 0;
95 int redoLayerId = 0;
96
97 int undoPosition = 0;
98 int redoPosition = 0;
99};
100
101class MoveKeyFramesCommand : public UndoRedoCommand
102{
103public:
104 MoveKeyFramesCommand(int offset,
105 QList<int> listOfPositions,
106 int undoLayerId,
107 const QString& description,
108 Editor* editor,
109 QUndoCommand* parent = nullptr);
110
111 void undo() override;
112 void redo() override;
113
114private:
115 int undoLayerId = 0;
116 int redoLayerId = 0;
117
118 int frameOffset = 0;
119 QList<int> positions;
120};
121
122class BitmapReplaceCommand : public UndoRedoCommand
123{
124
125public:
126 BitmapReplaceCommand(const BitmapImage* backupBitmap,
127 const int undoLayerId,
128 const QString& description,
129 Editor* editor,
130 QUndoCommand* parent = nullptr);
131
132 void undo() override;
133 void redo() override;
134
135private:
136 int undoLayerId = 0;
137 int redoLayerId = 0;
138
139 BitmapImage undoBitmap;
140 BitmapImage redoBitmap;
141};
142
143class VectorReplaceCommand : public UndoRedoCommand
144{
145public:
146 VectorReplaceCommand(const VectorImage* undoVector,
147 const int undoLayerId,
148 const QString& description,
149 Editor* editor,
150 QUndoCommand* parent = nullptr);
151
152 void undo() override;
153 void redo() override;
154
155private:
156 int undoLayerId = 0;
157 int redoLayerId = 0;
158
159 VectorImage undoVector;
160 VectorImage redoVector;
161};
162
163class TransformCommand : public UndoRedoCommand
164
165{
166public:
167 TransformCommand(const QRectF& undoSelectionRect,
168 const QPointF& undoTranslation,
169 const qreal undoRotationAngle,
170 const qreal undoScaleX,
171 const qreal undoScaleY,
172 const QPointF& undoTransformAnchor,
173 const bool roundPixels,
174 const QString& description,
175 Editor* editor,
176 QUndoCommand* parent = nullptr);
177
178 void undo() override;
179 void redo() override;
180
181private:
182 void apply(const QRectF& selectionRect,
183 const QPointF& translation,
184 const qreal rotationAngle,
185 const qreal scaleX,
186 const qreal scaleY,
187 const QPointF& selectionAnchor,
188 const bool roundPixels);
189
190 QRectF undoSelectionRect;
191 QRectF redoSelectionRect;
192
193 QPointF undoAnchor;
194 QPointF redoAnchor;
195
196 QPointF undoTranslation;
197 QPointF redoTranslation;
198
199 qreal undoScaleX;
200 qreal undoScaleY;
201
202 qreal redoScaleX;
203 qreal redoScaleY;
204
205 qreal undoRotationAngle;
206 qreal redoRotationAngle;
207
208 bool roundPixels;
209};
210
211#endif // UNDOREDOCOMMAND_H
BitmapImage
Definition: bitmapimage.h:28
BitmapReplaceCommand
Definition: undoredocommand.h:123
Camera
Definition: camera.h:25
Editor
Definition: editor.h:71
KeyFrameAddCommand
Definition: undoredocommand.h:80
KeyFrame
Definition: keyframe.h:30
KeyFrameRemoveCommand
Definition: undoredocommand.h:57
MoveKeyFramesCommand
Definition: undoredocommand.h:102
PreferenceManager
Definition: preferencemanager.h:28
SoundClip
Definition: soundclip.h:27
TransformCommand
Definition: undoredocommand.h:165
UndoRedoCommand
Definition: undoredocommand.h:40
UndoRedoManager
Definition: undoredomanager.h:119
VectorImage
Definition: vectorimage.h:32
VectorReplaceCommand
Definition: undoredocommand.h:144
QList
QPointF
QRectF
QString
QUndoCommand
Generated on Wed Apr 29 2026 06:05:08 for Pencil2D by doxygen 1.9.6 based on revision 5841f625b8680b86111af64be6a1235440cd8ff2