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, 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 };
71 
72 class OverwriteCommand : public QUndoCommand
73 {
74 public:
75  OverwriteCommand(MultitrackModel& model, int trackIndex, int position, const QString &xml, QUndoCommand * parent = 0);
76  void redo();
77  void undo();
78 private:
79  MultitrackModel& m_model;
80  int m_trackIndex;
81  int m_position;
82  QString m_xml;
83  UndoHelper m_undoHelper;
84 };
85 
86 class LiftCommand : public QUndoCommand
87 {
88 public:
89  LiftCommand(MultitrackModel& model, int trackIndex, int clipIndex, const QString &xml, QUndoCommand * parent = 0);
90  void redo();
91  void undo();
92 private:
93  MultitrackModel& m_model;
94  int m_trackIndex;
95  int m_clipIndex;
96  QString m_xml;
97  UndoHelper m_undoHelper;
98 };
99 
100 class RemoveCommand : public QUndoCommand
101 {
102 public:
103  RemoveCommand(MultitrackModel& model, int trackIndex, int clipIndex, const QString &xml, QUndoCommand * parent = 0);
104  void redo();
105  void undo();
106 private:
107  MultitrackModel& m_model;
108  int m_trackIndex;
109  int m_clipIndex;
110  QString m_xml;
111  UndoHelper m_undoHelper;
112 };
113 
114 class NameTrackCommand : public QUndoCommand
115 {
116 public:
117  NameTrackCommand(MultitrackModel& model, int trackIndex, const QString& name, QUndoCommand * parent = 0);
118  void redo();
119  void undo();
120 private:
121  MultitrackModel& m_model;
122  int m_trackIndex;
123  QString m_name;
124  QString m_oldName;
125 };
126 
127 class MergeCommand : public QUndoCommand
128 {
129 public:
130  MergeCommand(MultitrackModel& model, int trackIndex, int clipIndex, QUndoCommand * parent = 0);
131  void redo();
132  void undo();
133 private:
134  MultitrackModel& m_model;
135  int m_trackIndex;
136  int m_clipIndex;
137  UndoHelper m_undoHelper;
138 };
139 
140 class MuteTrackCommand : public QUndoCommand
141 {
142 public:
143  MuteTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand * parent = 0);
144  void redo();
145  void undo();
146 private:
147  MultitrackModel& m_model;
148  int m_trackIndex;
149  bool m_oldValue;
150 };
151 
152 class HideTrackCommand : public QUndoCommand
153 {
154 public:
155  HideTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand * parent = 0);
156  void redo();
157  void undo();
158 private:
159  MultitrackModel& m_model;
160  int m_trackIndex;
161  bool m_oldValue;
162 };
163 
164 class CompositeTrackCommand : public QUndoCommand
165 {
166 public:
167  CompositeTrackCommand(MultitrackModel& model, int trackIndex, bool value, QUndoCommand * parent = 0);
168  void redo();
169  void undo();
170 private:
171  MultitrackModel& m_model;
172  int m_trackIndex;
173  bool m_value;
174  bool m_oldValue;
175 };
176 
177 class LockTrackCommand : public QUndoCommand
178 {
179 public:
180  LockTrackCommand(MultitrackModel& model, int trackIndex, bool value, QUndoCommand * parent = 0);
181  void redo();
182  void undo();
183 private:
184  MultitrackModel& m_model;
185  int m_trackIndex;
186  bool m_value;
187  bool m_oldValue;
188 };
189 
190 class MoveClipCommand : public QUndoCommand
191 {
192 public:
193  MoveClipCommand(MultitrackModel& model, int fromTrackIndex, int toTrackIndex, int clipIndex, int position, bool ripple, QUndoCommand * parent = 0);
194  void redo();
195  void undo();
196 private:
197  MultitrackModel& m_model;
198  int m_fromTrackIndex;
199  int m_toTrackIndex;
200  int m_fromClipIndex;
201  int m_fromStart;
202  int m_toStart;
203  bool m_ripple;
204  UndoHelper m_undoHelper;
205 };
206 
207 class TrimCommand : public QUndoCommand
208 {
209 public:
210  explicit TrimCommand(QUndoCommand *parent = 0) : QUndoCommand(parent) {}
211  void setUndoHelper(UndoHelper* helper) { m_undoHelper.reset(helper); }
212 
213 protected:
214  QScopedPointer<UndoHelper> m_undoHelper;
215 };
216 
217 class TrimClipInCommand : public TrimCommand
218 {
219 public:
220  TrimClipInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
221  void redo();
222  void undo();
223 protected:
224  int id() const { return UndoIdTrimClipIn; }
225  bool mergeWith(const QUndoCommand *other);
226 private:
227  MultitrackModel& m_model;
228  int m_trackIndex;
229  int m_clipIndex;
230  int m_delta;
231  bool m_ripple;
232  bool m_redo;
233 };
234 
235 class TrimClipOutCommand : public TrimCommand
236 {
237 public:
238  TrimClipOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
239  void redo();
240  void undo();
241 protected:
242  int id() const { return UndoIdTrimClipOut; }
243  bool mergeWith(const QUndoCommand *other);
244 private:
245  MultitrackModel& m_model;
246  int m_trackIndex;
247  int m_clipIndex;
248  int m_delta;
249  bool m_ripple;
250  bool m_redo;
251 };
252 
253 class SplitCommand : public QUndoCommand
254 {
255 public:
256  SplitCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, QUndoCommand * parent = 0);
257  void redo();
258  void undo();
259 private:
260  MultitrackModel& m_model;
261  int m_trackIndex;
262  int m_clipIndex;
263  int m_position;
264 };
265 
266 class FadeInCommand : public QUndoCommand
267 {
268 public:
269  FadeInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
270  void redo();
271  void undo();
272 protected:
273  int id() const { return UndoIdFadeIn; }
274  bool mergeWith(const QUndoCommand *other);
275 private:
276  MultitrackModel& m_model;
277  int m_trackIndex;
278  int m_clipIndex;
279  int m_duration;
280  int m_previous;
281 };
282 
283 class FadeOutCommand : public QUndoCommand
284 {
285 public:
286  FadeOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
287  void redo();
288  void undo();
289 protected:
290  int id() const { return UndoIdFadeOut; }
291  bool mergeWith(const QUndoCommand *other);
292 private:
293  MultitrackModel& m_model;
294  int m_trackIndex;
295  int m_clipIndex;
296  int m_duration;
297  int m_previous;
298 };
299 
300 class AddTransitionCommand : public QUndoCommand
301 {
302 public:
303  AddTransitionCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, bool ripple, QUndoCommand * parent = 0);
304  void redo();
305  void undo();
306  int getTransitionIndex() const { return m_transitionIndex; }
307 private:
308  MultitrackModel& m_model;
309  int m_trackIndex;
310  int m_clipIndex;
311  int m_position;
312  int m_transitionIndex;
313  bool m_ripple;
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 duration, int trimDelta, 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_duration;
367  int m_trimDelta;
368  bool m_notify;
369  bool m_redo;
370 };
371 
372 class RemoveTransitionByTrimInCommand : public TrimCommand
373 {
374 public:
375  RemoveTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
376  void redo();
377  void undo();
378 private:
379  MultitrackModel& m_model;
380  int m_trackIndex;
381  int m_clipIndex;
382  int m_delta;
383  bool m_redo;
384 };
385 
386 class RemoveTransitionByTrimOutCommand : public TrimCommand
387 {
388 public:
389  RemoveTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
390  void redo();
391  void undo();
392 private:
393  MultitrackModel& m_model;
394  int m_trackIndex;
395  int m_clipIndex;
396  int m_delta;
397  bool m_redo;
398 };
399 
400 class AddTransitionByTrimOutCommand : public TrimCommand
401 {
402 public:
403  AddTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, int trimDelta, bool redo = true, QUndoCommand * parent = 0);
404  void redo();
405  void undo();
406 protected:
407  int id() const { return UndoIdAddTransitionByTrimOut; }
408  bool mergeWith(const QUndoCommand *other);
409 private:
410  MultitrackModel& m_model;
411  int m_trackIndex;
412  int m_clipIndex;
413  int m_duration;
414  int m_trimDelta;
415  bool m_notify;
416  bool m_redo;
417 };
418 
419 class AddTrackCommand: public QUndoCommand
420 {
421 public:
422  AddTrackCommand(MultitrackModel& model, bool isVideo, QUndoCommand* parent = 0);
423  void redo();
424  void undo();
425 private:
426  MultitrackModel& m_model;
427  int m_trackIndex;
428  bool m_isVideo;
429 };
430 
431 class InsertTrackCommand : public QUndoCommand
432 {
433 public:
434  InsertTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
435  void redo();
436  void undo();
437 private:
438  MultitrackModel& m_model;
439  int m_trackIndex;
440  TrackType m_trackType;
441 };
442 
443 class RemoveTrackCommand : public QUndoCommand
444 {
445 public:
446  RemoveTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
447  void redo();
448  void undo();
449 private:
450  MultitrackModel& m_model;
451  int m_trackIndex;
452  TrackType m_trackType;
453  QString m_trackName;
454  UndoHelper m_undoHelper;
455 };
456 
457 class ChangeBlendModeCommand : public QObject, public QUndoCommand
458 {
459  Q_OBJECT
460 public:
461  ChangeBlendModeCommand(Mlt::Transition& transition, const QString& propertyName, const QString& mode, QUndoCommand* parent = 0);
462  void redo();
463  void undo();
464 signals:
465  void modeChanged(QString& mode);
466 private:
467  Mlt::Transition m_transition;
468  QString m_propertyName;
469  QString m_newMode;
470  QString m_oldMode;
471 };
472 
473 class UpdateCommand : public QUndoCommand
474 {
475 public:
476  UpdateCommand(TimelineDock& timeline, int trackIndex, int clipIndex, int position,
477  QUndoCommand * parent = 0);
478  void setXmlAfter(const QString& xml) { m_xmlAfter = xml; }
479  void setPosition(int trackIndex, int clipIndex, int position);
480  int trackIndex() const {return m_trackIndex;}
481  int clipIndex() const {return m_clipIndex;}
482  int position() const {return m_position;}
483  void redo();
484  void undo();
485 private:
486  TimelineDock& m_timeline;
487  int m_trackIndex;
488  int m_clipIndex;
489  int m_position;
490  QString m_xmlAfter;
491  bool m_isFirstRedo;
492  UndoHelper m_undoHelper;
493 };
494 
495 class DetachAudioCommand: public QUndoCommand
496 {
497 public:
498  DetachAudioCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, const QString& xml, QUndoCommand* parent = 0);
499  void redo();
500  void undo();
501 private:
502  MultitrackModel& m_model;
503  int m_trackIndex;
504  int m_clipIndex;
505  int m_position;
506  int m_targetTrackIndex;
507  QString m_audioIndex;
508  QString m_xml;
509  UndoHelper m_undoHelper;
510 };
511 
512 } // namespace Timeline
513 
514 #endif
Definition: timelinecommands.cpp:24