From fbded93e39006b1140db4a8b117a49f00a4a7704 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 2 Dec 2018 19:38:38 +1100 Subject: [PATCH] made pasting effects undoable --- panels/effectcontrols.cpp | 2 +- panels/panels.cpp | 7 +++---- panels/timeline.cpp | 11 ++++++++++- project/undo.cpp | 37 ++++++++++++------------------------- project/undo.h | 15 +++------------ 5 files changed, 29 insertions(+), 43 deletions(-) diff --git a/panels/effectcontrols.cpp b/panels/effectcontrols.cpp index 18e0baffc..c31f46e13 100644 --- a/panels/effectcontrols.cpp +++ b/panels/effectcontrols.cpp @@ -76,7 +76,7 @@ void EffectControls::menu_select(QAction* q) { ca->append(new AddTransitionCommand(c, NULL, NULL, meta, TA_CLOSING_TRANSITION, 30)); } } else { - ca->append(new AddEffectCommand(c, meta)); + ca->append(new AddEffectCommand(c, NULL, meta)); } } } diff --git a/panels/panels.cpp b/panels/panels.cpp index e2ed4599b..94f568470 100644 --- a/panels/panels.cpp +++ b/panels/panels.cpp @@ -80,7 +80,7 @@ void update_effect_controls() { } } - bool same = (selected_clips.size() == panel_effect_controls->selected_clips.size()); + bool same = (selected_clips.size() == panel_effect_controls->selected_clips.size()); if (same) { for (int i=0;iselected_clips.at(i)) { @@ -97,9 +97,8 @@ void update_effect_controls() { } void update_ui(bool modified) { - if (modified) { -// panel_sequence_viewer->reset_all_audio(); - update_effect_controls(); + if (modified) { + update_effect_controls(); } panel_effect_controls->update_keyframes(); panel_timeline->repaint_timeline(); diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 1caa80d2a..de7a56011 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -973,17 +973,26 @@ void Timeline::paste(bool insert) { panel_sequence_viewer->seek(paste_end); } } else if (clipboard_type == CLIPBOARD_TYPE_EFFECT) { + ComboAction* ca = new ComboAction(); + bool push = false; for (int i=0;iclips.size();i++) { Clip* c = sequence->clips.at(i); if (c != NULL && is_clip_selected(c, true)) { for (int j=0;j(clipboard.at(j)); if ((c->track < 0) == (e->meta->subtype == EFFECT_TYPE_VIDEO)) { - c->effects.append(e->copy(c)); + ca->append(new AddEffectCommand(c, e->copy(c), NULL)); + push = true; } } } } + if (push) { + ca->appendPost(new ReloadEffectsCommand()); + undo_stack.push(ca); + } else { + delete ca; + } update_ui(true); } } diff --git a/project/undo.cpp b/project/undo.cpp index 636b872ee..70f3ebad8 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -198,10 +198,10 @@ void SetTimelineInOutCommand::redo() { mainWindow->setWindowModified(true); } -AddEffectCommand::AddEffectCommand(Clip* c, const EffectMeta *e) : +AddEffectCommand::AddEffectCommand(Clip* c, Effect* e, const EffectMeta *m) : clip(c), - meta(e), - ref(NULL), + meta(m), + ref(e), done(false), old_project_changed(mainWindow->isWindowModified()) {} @@ -211,6 +211,7 @@ AddEffectCommand::~AddEffectCommand() { } void AddEffectCommand::undo() { + clip->effects.last()->close(); clip->effects.removeLast(); done = false; mainWindow->setWindowModified(old_project_changed); @@ -703,7 +704,9 @@ void EffectDeleteCommand::redo() { for (int i=0;ieffects.at(fx_id)); + Effect* e = c->effects.at(fx_id); + e->close(); + deleted_objects.append(e); c->effects.removeAt(fx_id); } panel_effect_controls->reload_clips(); @@ -1300,26 +1303,10 @@ void SetPointer::redo() { mainWindow->setWindowModified(true); } -/*MoveGizmo::MoveGizmo(Effect *e, EffectGizmo *g, int x_movement, int y_movement, double tc) : - effect(e), - gizmo(g), - x(x_movement), - y(y_movement), - timecode(tc), - done(true), - old_changed(mainWindow->isWindowModified()) -{} - -void MoveGizmo::undo() { - effect->gizmo_move(gizmo, -x, -y, timecode); - mainWindow->setWindowModified(old_changed); - done = false; +void ReloadEffectsCommand::undo() { + redo(); } -void MoveGizmo::redo() { - if (!done) { - effect->gizmo_move(gizmo, x, y, timecode); - mainWindow->setWindowModified(true); - done = true; - } -}*/ +void ReloadEffectsCommand::redo() { + panel_effect_controls->reload_clips(); +} diff --git a/project/undo.h b/project/undo.h index 3535c5195..afd4c3f0a 100644 --- a/project/undo.h +++ b/project/undo.h @@ -88,7 +88,7 @@ private: class AddEffectCommand : public QUndoCommand { public: - AddEffectCommand(Clip* c, const EffectMeta* e); + AddEffectCommand(Clip* c, Effect *e, const EffectMeta* m); ~AddEffectCommand(); void undo(); void redo(); @@ -598,19 +598,10 @@ private: void* old_data; }; -/*class MoveGizmo : public QUndoCommand { +class ReloadEffectsCommand : public QUndoCommand { public: - MoveGizmo(Effect* e, EffectGizmo* g, int x_movement, int y_movement, double tc); void undo(); void redo(); -private: - Effect* effect; - EffectGizmo* gizmo; - int x; - int y; - double timecode; - bool done; - bool old_changed; -};*/ +}; #endif // UNDO_H