CuteLogger
Fast and simple logging solution for Qt based applications
timelinecommands.h
1 /*
2  * Copyright (c) 2013-2018 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef COMMANDS_H
19 #define COMMANDS_H
20 
21 #include "models/multitrackmodel.h"
22 #include "docks/timelinedock.h"
23 #include "undohelper.h"
24 #include <QUndoCommand>
25 #include <QString>
26 #include <QObject>
27 #include <MltTransition.h>
28 
29 namespace Timeline
30 {
31 
32 enum {
33  UndoIdTrimClipIn,
34  UndoIdTrimClipOut,
35  UndoIdFadeIn,
36  UndoIdFadeOut,
37  UndoIdTrimTransitionIn,
38  UndoIdTrimTransitionOut,
39  UndoIdAddTransitionByTrimIn,
40  UndoIdAddTransitionByTrimOut,
41  UndoIdUpdate
42 };
43 
44 class AppendCommand : public QUndoCommand
45 {
46 public:
47  AppendCommand(MultitrackModel& model, int trackIndex, const QString& xml, QUndoCommand * parent = 0);
48  void redo();
49  void undo();
50 private:
51  MultitrackModel& m_model;
52  int m_trackIndex;
53  QString m_xml;
54  UndoHelper m_undoHelper;
55 };
56 
57 class InsertCommand : public QUndoCommand
58 {
59 public:
60  InsertCommand(MultitrackModel& model, int trackIndex, int position, const QString &xml, bool seek = true, QUndoCommand * parent = 0);
61  void redo();
62  void undo();
63 private:
64  MultitrackModel& m_model;
65  int m_trackIndex;
66  int m_position;
67  QString m_xml;
68  QStringList m_oldTracks;
69  UndoHelper m_undoHelper;
70  bool m_seek;
71 };
72 
73 class OverwriteCommand : public QUndoCommand
74 {
75 public:
76  OverwriteCommand(MultitrackModel& model, int trackIndex, int position, const QString &xml, bool seek = true, QUndoCommand * parent = 0);
77  void redo();
78  void undo();
79 private:
80  MultitrackModel& m_model;
81  int m_trackIndex;
82  int m_position;
83  QString m_xml;
84  UndoHelper m_undoHelper;
85  bool m_seek;
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, bool ripple, 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  bool m_ripple;
206  UndoHelper m_undoHelper;
207 };
208 
209 class TrimCommand : public QUndoCommand
210 {
211 public:
212  explicit TrimCommand(QUndoCommand *parent = 0) : QUndoCommand(parent) {}
213  void setUndoHelper(UndoHelper* helper) { m_undoHelper.reset(helper); }
214 
215 protected:
216  QScopedPointer<UndoHelper> m_undoHelper;
217 };
218 
219 class TrimClipInCommand : public TrimCommand
220 {
221 public:
222  TrimClipInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
223  void redo();
224  void undo();
225 protected:
226  int id() const { return UndoIdTrimClipIn; }
227  bool mergeWith(const QUndoCommand *other);
228 private:
229  MultitrackModel& m_model;
230  int m_trackIndex;
231  int m_clipIndex;
232  int m_delta;
233  bool m_ripple;
234  bool m_redo;
235 };
236 
237 class TrimClipOutCommand : public TrimCommand
238 {
239 public:
240  TrimClipOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
241  void redo();
242  void undo();
243 protected:
244  int id() const { return UndoIdTrimClipOut; }
245  bool mergeWith(const QUndoCommand *other);
246 private:
247  MultitrackModel& m_model;
248  int m_trackIndex;
249  int m_clipIndex;
250  int m_delta;
251  bool m_ripple;
252  bool m_redo;
253 };
254 
255 class SplitCommand : public QUndoCommand
256 {
257 public:
258  SplitCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, QUndoCommand * parent = 0);
259  void redo();
260  void undo();
261 private:
262  MultitrackModel& m_model;
263  int m_trackIndex;
264  int m_clipIndex;
265  int m_position;
266 };
267 
268 class FadeInCommand : public QUndoCommand
269 {
270 public:
271  FadeInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
272  void redo();
273  void undo();
274 protected:
275  int id() const { return UndoIdFadeIn; }
276  bool mergeWith(const QUndoCommand *other);
277 private:
278  MultitrackModel& m_model;
279  int m_trackIndex;
280  int m_clipIndex;
281  int m_duration;
282  int m_previous;
283 };
284 
285 class FadeOutCommand : public QUndoCommand
286 {
287 public:
288  FadeOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
289  void redo();
290  void undo();
291 protected:
292  int id() const { return UndoIdFadeOut; }
293  bool mergeWith(const QUndoCommand *other);
294 private:
295  MultitrackModel& m_model;
296  int m_trackIndex;
297  int m_clipIndex;
298  int m_duration;
299  int m_previous;
300 };
301 
302 class AddTransitionCommand : public QUndoCommand
303 {
304 public:
305  AddTransitionCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, bool ripple, QUndoCommand * parent = 0);
306  void redo();
307  void undo();
308  int getTransitionIndex() const { return m_transitionIndex; }
309 private:
310  MultitrackModel& m_model;
311  int m_trackIndex;
312  int m_clipIndex;
313  int m_position;
314  int m_transitionIndex;
315  bool m_ripple;
316  UndoHelper m_undoHelper;
317 };
318 
319 class TrimTransitionInCommand : public TrimCommand
320 {
321 public:
322  TrimTransitionInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
323  void redo();
324  void undo();
325 protected:
326  int id() const { return UndoIdTrimTransitionIn; }
327  bool mergeWith(const QUndoCommand *other);
328 private:
329  MultitrackModel& m_model;
330  int m_trackIndex;
331  int m_clipIndex;
332  int m_delta;
333  bool m_notify;
334  bool m_redo;
335 };
336 
337 class TrimTransitionOutCommand : public TrimCommand
338 {
339 public:
340  TrimTransitionOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
341  void redo();
342  void undo();
343 protected:
344  int id() const { return UndoIdTrimTransitionOut; }
345  bool mergeWith(const QUndoCommand *other);
346 private:
347  MultitrackModel& m_model;
348  int m_trackIndex;
349  int m_clipIndex;
350  int m_delta;
351  bool m_notify;
352  bool m_redo;
353 };
354 
355 class AddTransitionByTrimInCommand : public TrimCommand
356 {
357 public:
358  AddTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, int trimDelta, bool redo = true, QUndoCommand * parent = 0);
359  void redo();
360  void undo();
361 protected:
362  int id() const { return UndoIdAddTransitionByTrimIn; }
363  bool mergeWith(const QUndoCommand *other);
364 private:
365  MultitrackModel& m_model;
366  int m_trackIndex;
367  int m_clipIndex;
368  int m_duration;
369  int m_trimDelta;
370  bool m_notify;
371  bool m_redo;
372 };
373 
374 class RemoveTransitionByTrimInCommand : public TrimCommand
375 {
376 public:
377  RemoveTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
378  void redo();
379  void undo();
380 private:
381  MultitrackModel& m_model;
382  int m_trackIndex;
383  int m_clipIndex;
384  int m_delta;
385  bool m_redo;
386 };
387 
388 class RemoveTransitionByTrimOutCommand : public TrimCommand
389 {
390 public:
391  RemoveTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
392  void redo();
393  void undo();
394 private:
395  MultitrackModel& m_model;
396  int m_trackIndex;
397  int m_clipIndex;
398  int m_delta;
399  bool m_redo;
400 };
401 
402 class AddTransitionByTrimOutCommand : public TrimCommand
403 {
404 public:
405  AddTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, int trimDelta, bool redo = true, QUndoCommand * parent = 0);
406  void redo();
407  void undo();
408 protected:
409  int id() const { return UndoIdAddTransitionByTrimOut; }
410  bool mergeWith(const QUndoCommand *other);
411 private:
412  MultitrackModel& m_model;
413  int m_trackIndex;
414  int m_clipIndex;
415  int m_duration;
416  int m_trimDelta;
417  bool m_notify;
418  bool m_redo;
419 };
420 
421 class AddTrackCommand: public QUndoCommand
422 {
423 public:
424  AddTrackCommand(MultitrackModel& model, bool isVideo, QUndoCommand* parent = 0);
425  void redo();
426  void undo();
427 private:
428  MultitrackModel& m_model;
429  int m_trackIndex;
430  bool m_isVideo;
431 };
432 
433 class InsertTrackCommand : public QUndoCommand
434 {
435 public:
436  InsertTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
437  void redo();
438  void undo();
439 private:
440  MultitrackModel& m_model;
441  int m_trackIndex;
442  TrackType m_trackType;
443 };
444 
445 class RemoveTrackCommand : public QUndoCommand
446 {
447 public:
448  RemoveTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
449  void redo();
450  void undo();
451 private:
452  MultitrackModel& m_model;
453  int m_trackIndex;
454  TrackType m_trackType;
455  QString m_trackName;
456  UndoHelper m_undoHelper;
457 };
458 
459 class ChangeBlendModeCommand : public QObject, public QUndoCommand
460 {
461  Q_OBJECT
462 public:
463  ChangeBlendModeCommand(Mlt::Transition& transition, const QString& propertyName, const QString& mode, QUndoCommand* parent = 0);
464  void redo();
465  void undo();
466 signals:
467  void modeChanged(QString& mode);
468 private:
469  Mlt::Transition m_transition;
470  QString m_propertyName;
471  QString m_newMode;
472  QString m_oldMode;
473 };
474 
475 class UpdateCommand : public QUndoCommand
476 {
477 public:
478  UpdateCommand(TimelineDock& timeline, int trackIndex, int clipIndex, int position,
479  QUndoCommand * parent = 0);
480  void setXmlAfter(const QString& xml) { m_xmlAfter = xml; }
481  void setPosition(int trackIndex, int clipIndex, int position);
482  int trackIndex() const {return m_trackIndex;}
483  int clipIndex() const {return m_clipIndex;}
484  int position() const {return m_position;}
485  void redo();
486  void undo();
487 private:
488  TimelineDock& m_timeline;
489  int m_trackIndex;
490  int m_clipIndex;
491  int m_position;
492  QString m_xmlAfter;
493  bool m_isFirstRedo;
494  UndoHelper m_undoHelper;
495 };
496 
497 class DetachAudioCommand: public QUndoCommand
498 {
499 public:
500  DetachAudioCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, const QString& xml, QUndoCommand* parent = 0);
501  void redo();
502  void undo();
503 private:
504  MultitrackModel& m_model;
505  int m_trackIndex;
506  int m_clipIndex;
507  int m_position;
508  int m_targetTrackIndex;
509  QString m_audioIndex;
510  QString m_xml;
511  UndoHelper m_undoHelper;
512 };
513 
514 } // namespace Timeline
515 
516 #endif