CuteLogger
Fast and simple logging solution for Qt based applications
timelinecommands.h
1 /*
2  * Copyright (c) 2013-2017 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef COMMANDS_H
20 #define COMMANDS_H
21 
22 #include "models/multitrackmodel.h"
23 #include "docks/timelinedock.h"
24 #include "undohelper.h"
25 #include <QUndoCommand>
26 #include <QString>
27 #include <QObject>
28 #include <MltTransition.h>
29 
30 namespace Timeline
31 {
32 
33 enum {
34  UndoIdTrimClipIn,
35  UndoIdTrimClipOut,
36  UndoIdFadeIn,
37  UndoIdFadeOut,
38  UndoIdTrimTransitionIn,
39  UndoIdTrimTransitionOut,
40  UndoIdAddTransitionByTrimIn,
41  UndoIdAddTransitionByTrimOut,
42  UndoIdUpdate
43 };
44 
45 class AppendCommand : public QUndoCommand
46 {
47 public:
48  AppendCommand(MultitrackModel& model, int trackIndex, const QString& xml, QUndoCommand * parent = 0);
49  void redo();
50  void undo();
51 private:
52  MultitrackModel& m_model;
53  int m_trackIndex;
54  QString m_xml;
55  UndoHelper m_undoHelper;
56 };
57 
58 class InsertCommand : public QUndoCommand
59 {
60 public:
61  InsertCommand(MultitrackModel& model, int trackIndex, int position, const QString &xml, QUndoCommand * parent = 0);
62  void redo();
63  void undo();
64 private:
65  MultitrackModel& m_model;
66  int m_trackIndex;
67  int m_position;
68  QString m_xml;
69  QStringList m_oldTracks;
70  UndoHelper m_undoHelper;
71 };
72 
73 class OverwriteCommand : public QUndoCommand
74 {
75 public:
76  OverwriteCommand(MultitrackModel& model, int trackIndex, int position, const QString &xml, QUndoCommand * parent = 0);
77  void redo();
78  void undo();
79 private:
80  MultitrackModel& m_model;
81  int m_trackIndex;
82  QString m_playlistXml;
83  int m_position;
84  QString m_xml;
85  UndoHelper m_undoHelper;
86 };
87 
88 class LiftCommand : public QUndoCommand
89 {
90 public:
91  LiftCommand(MultitrackModel& model, int trackIndex, int clipIndex, const QString &xml, QUndoCommand * parent = 0);
92  void redo();
93  void undo();
94 private:
95  MultitrackModel& m_model;
96  int m_trackIndex;
97  int m_clipIndex;
98  QString m_xml;
99  UndoHelper m_undoHelper;
100 };
101 
102 class RemoveCommand : public QUndoCommand
103 {
104 public:
105  RemoveCommand(MultitrackModel& model, int trackIndex, int clipIndex, const QString &xml, QUndoCommand * parent = 0);
106  void redo();
107  void undo();
108 private:
109  MultitrackModel& m_model;
110  int m_trackIndex;
111  int m_clipIndex;
112  QString m_xml;
113  UndoHelper m_undoHelper;
114 };
115 
116 class NameTrackCommand : public QUndoCommand
117 {
118 public:
119  NameTrackCommand(MultitrackModel& model, int trackIndex, const QString& name, QUndoCommand * parent = 0);
120  void redo();
121  void undo();
122 private:
123  MultitrackModel& m_model;
124  int m_trackIndex;
125  QString m_name;
126  QString m_oldName;
127 };
128 
129 class MergeCommand : public QUndoCommand
130 {
131 public:
132  MergeCommand(MultitrackModel& model, int trackIndex, int clipIndex, QUndoCommand * parent = 0);
133  void redo();
134  void undo();
135 private:
136  MultitrackModel& m_model;
137  int m_trackIndex;
138  int m_clipIndex;
139  UndoHelper m_undoHelper;
140 };
141 
142 class MuteTrackCommand : public QUndoCommand
143 {
144 public:
145  MuteTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand * parent = 0);
146  void redo();
147  void undo();
148 private:
149  MultitrackModel& m_model;
150  int m_trackIndex;
151  bool m_oldValue;
152 };
153 
154 class HideTrackCommand : public QUndoCommand
155 {
156 public:
157  HideTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand * parent = 0);
158  void redo();
159  void undo();
160 private:
161  MultitrackModel& m_model;
162  int m_trackIndex;
163  bool m_oldValue;
164 };
165 
166 class CompositeTrackCommand : public QUndoCommand
167 {
168 public:
169  CompositeTrackCommand(MultitrackModel& model, int trackIndex, bool value, QUndoCommand * parent = 0);
170  void redo();
171  void undo();
172 private:
173  MultitrackModel& m_model;
174  int m_trackIndex;
175  bool m_value;
176  bool m_oldValue;
177 };
178 
179 class LockTrackCommand : public QUndoCommand
180 {
181 public:
182  LockTrackCommand(MultitrackModel& model, int trackIndex, bool value, QUndoCommand * parent = 0);
183  void redo();
184  void undo();
185 private:
186  MultitrackModel& m_model;
187  int m_trackIndex;
188  bool m_value;
189  bool m_oldValue;
190 };
191 
192 class MoveClipCommand : public QUndoCommand
193 {
194 public:
195  MoveClipCommand(MultitrackModel& model, int fromTrackIndex, int toTrackIndex, int clipIndex, int position, QUndoCommand * parent = 0);
196  void redo();
197  void undo();
198 private:
199  MultitrackModel& m_model;
200  int m_fromTrackIndex;
201  int m_toTrackIndex;
202  int m_fromClipIndex;
203  int m_fromStart;
204  int m_toStart;
205  UndoHelper m_undoHelper;
206 };
207 
208 class TrimCommand : public QUndoCommand
209 {
210 public:
211  explicit TrimCommand(QUndoCommand *parent = 0) : QUndoCommand(parent) {}
212  void setUndoHelper(UndoHelper* helper) { m_undoHelper.reset(helper); }
213 
214 protected:
215  QScopedPointer<UndoHelper> m_undoHelper;
216 };
217 
218 class TrimClipInCommand : public TrimCommand
219 {
220 public:
221  TrimClipInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
222  void redo();
223  void undo();
224 protected:
225  int id() const { return UndoIdTrimClipIn; }
226  bool mergeWith(const QUndoCommand *other);
227 private:
228  MultitrackModel& m_model;
229  int m_trackIndex;
230  int m_clipIndex;
231  int m_delta;
232  bool m_ripple;
233  bool m_redo;
234 };
235 
236 class TrimClipOutCommand : public TrimCommand
237 {
238 public:
239  TrimClipOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
240  void redo();
241  void undo();
242 protected:
243  int id() const { return UndoIdTrimClipOut; }
244  bool mergeWith(const QUndoCommand *other);
245 private:
246  MultitrackModel& m_model;
247  int m_trackIndex;
248  int m_clipIndex;
249  int m_delta;
250  bool m_ripple;
251  bool m_redo;
252 };
253 
254 class SplitCommand : public QUndoCommand
255 {
256 public:
257  SplitCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, QUndoCommand * parent = 0);
258  void redo();
259  void undo();
260 private:
261  MultitrackModel& m_model;
262  int m_trackIndex;
263  int m_clipIndex;
264  int m_position;
265 };
266 
267 class FadeInCommand : public QUndoCommand
268 {
269 public:
270  FadeInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
271  void redo();
272  void undo();
273 protected:
274  int id() const { return UndoIdFadeIn; }
275  bool mergeWith(const QUndoCommand *other);
276 private:
277  MultitrackModel& m_model;
278  int m_trackIndex;
279  int m_clipIndex;
280  int m_duration;
281  int m_previous;
282 };
283 
284 class FadeOutCommand : public QUndoCommand
285 {
286 public:
287  FadeOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
288  void redo();
289  void undo();
290 protected:
291  int id() const { return UndoIdFadeOut; }
292  bool mergeWith(const QUndoCommand *other);
293 private:
294  MultitrackModel& m_model;
295  int m_trackIndex;
296  int m_clipIndex;
297  int m_duration;
298  int m_previous;
299 };
300 
301 class AddTransitionCommand : public QUndoCommand
302 {
303 public:
304  AddTransitionCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, QUndoCommand * parent = 0);
305  void redo();
306  void undo();
307  int getTransitionIndex() const { return m_transitionIndex; }
308 private:
309  MultitrackModel& m_model;
310  int m_trackIndex;
311  int m_clipIndex;
312  int m_position;
313  int m_transitionIndex;
314  UndoHelper m_undoHelper;
315 };
316 
317 class TrimTransitionInCommand : public TrimCommand
318 {
319 public:
320  TrimTransitionInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
321  void redo();
322  void undo();
323 protected:
324  int id() const { return UndoIdTrimTransitionIn; }
325  bool mergeWith(const QUndoCommand *other);
326 private:
327  MultitrackModel& m_model;
328  int m_trackIndex;
329  int m_clipIndex;
330  int m_delta;
331  bool m_notify;
332  bool m_redo;
333 };
334 
335 class TrimTransitionOutCommand : public TrimCommand
336 {
337 public:
338  TrimTransitionOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
339  void redo();
340  void undo();
341 protected:
342  int id() const { return UndoIdTrimTransitionOut; }
343  bool mergeWith(const QUndoCommand *other);
344 private:
345  MultitrackModel& m_model;
346  int m_trackIndex;
347  int m_clipIndex;
348  int m_delta;
349  bool m_notify;
350  bool m_redo;
351 };
352 
353 class AddTransitionByTrimInCommand : public TrimCommand
354 {
355 public:
356  AddTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
357  void redo();
358  void undo();
359 protected:
360  int id() const { return UndoIdAddTransitionByTrimIn; }
361  bool mergeWith(const QUndoCommand *other);
362 private:
363  MultitrackModel& m_model;
364  int m_trackIndex;
365  int m_clipIndex;
366  int m_delta;
367  bool m_notify;
368  bool m_redo;
369 };
370 
371 class RemoveTransitionByTrimInCommand : public TrimCommand
372 {
373 public:
374  RemoveTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
375  void redo();
376  void undo();
377 private:
378  MultitrackModel& m_model;
379  int m_trackIndex;
380  int m_clipIndex;
381  int m_delta;
382  bool m_redo;
383 };
384 
385 class RemoveTransitionByTrimOutCommand : public TrimCommand
386 {
387 public:
388  RemoveTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
389  void redo();
390  void undo();
391 private:
392  MultitrackModel& m_model;
393  int m_trackIndex;
394  int m_clipIndex;
395  int m_delta;
396  bool m_redo;
397 };
398 
399 class AddTransitionByTrimOutCommand : public TrimCommand
400 {
401 public:
402  AddTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
403  void redo();
404  void undo();
405 protected:
406  int id() const { return UndoIdAddTransitionByTrimOut; }
407  bool mergeWith(const QUndoCommand *other);
408 private:
409  MultitrackModel& m_model;
410  int m_trackIndex;
411  int m_clipIndex;
412  int m_delta;
413  bool m_notify;
414  bool m_redo;
415 };
416 
417 class AddTrackCommand: public QUndoCommand
418 {
419 public:
420  AddTrackCommand(MultitrackModel& model, bool isVideo, QUndoCommand* parent = 0);
421  void redo();
422  void undo();
423 private:
424  MultitrackModel& m_model;
425  int m_trackIndex;
426  bool m_isVideo;
427 };
428 
429 class InsertTrackCommand : public QUndoCommand
430 {
431 public:
432  InsertTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
433  void redo();
434  void undo();
435 private:
436  MultitrackModel& m_model;
437  int m_trackIndex;
438  TrackType m_trackType;
439 };
440 
441 class RemoveTrackCommand : public QUndoCommand
442 {
443 public:
444  RemoveTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
445  void redo();
446  void undo();
447 private:
448  MultitrackModel& m_model;
449  int m_trackIndex;
450  QString m_xml;
451  TrackType m_trackType;
452  QString m_trackName;
453 };
454 
455 class ChangeBlendModeCommand : public QObject, public QUndoCommand
456 {
457  Q_OBJECT
458 public:
459  ChangeBlendModeCommand(Mlt::Transition& transition, const QString& propertyName, const QString& mode, QUndoCommand* parent = 0);
460  void redo();
461  void undo();
462 signals:
463  void modeChanged(QString& mode);
464 private:
465  Mlt::Transition m_transition;
466  QString m_propertyName;
467  QString m_newMode;
468  QString m_oldMode;
469 };
470 
471 class UpdateCommand : public QUndoCommand
472 {
473 public:
474  UpdateCommand(TimelineDock& timeline, int trackIndex, int clipIndex, int position,
475  QUndoCommand * parent = 0);
476  void setXmlAfter(const QString& xml) { m_xmlAfter = xml; }
477  void redo();
478  void undo();
479 private:
480  TimelineDock& m_timeline;
481  int m_trackIndex;
482  int m_clipIndex;
483  int m_position;
484  QString m_xmlAfter;
485  bool m_isFirstRedo;
486  UndoHelper m_undoHelper;
487 };
488 
489 } // namespace Timeline
490 
491 #endif
Definition: timelinecommands.cpp:25