From 1204a69baa21003bc9754d6c77f6e26161b1fda9 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 30 Dec 2018 22:54:26 +1100 Subject: [PATCH] fixed transition glitches --- mainwindow.cpp | 8 ++++++++ mainwindow.h | 2 ++ project/sequence.cpp | 20 ++++++++++++++------ project/undo.cpp | 31 ++++++++++++++++++++++++++++++- project/undo.h | 3 +++ 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 78cf658c5..56880c2f9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -767,6 +767,10 @@ void MainWindow::setup_menus() { tools_menu->addAction("Preferences", this, SLOT(preferences()), QKeySequence("Ctrl+.")); +#ifdef QT_DEBUG + tools_menu->addAction("Clear Undo", this, SLOT(clear_undo_stack()), QKeySequence("Ctrl+.")); +#endif + // INITIALIZE HELP MENU QMenu* help_menu = menuBar->addMenu("&Help"); @@ -815,6 +819,10 @@ void MainWindow::paintEvent(QPaintEvent *event) { #endif } +void MainWindow::clear_undo_stack() { + undo_stack.clear(); +} + void MainWindow::open_project() { QString fn = QFileDialog::getOpenFileName(this, "Open Project...", "", OLIVE_FILE_FILTER); if (!fn.isEmpty() && can_close_project()) { diff --git a/mainwindow.h b/mainwindow.h index 0e22f70e3..043b083b3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,8 @@ protected: void paintEvent(QPaintEvent *event); private slots: + void clear_undo_stack(); + void show_about(); void delete_slot(); void select_all(); diff --git a/project/sequence.cpp b/project/sequence.cpp index c65c2e1c5..4450df41f 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -61,13 +61,21 @@ void Sequence::hard_delete_transition(Clip *c, int type) { Transition* t = transitions.at(transition_index); if (t->secondary_clip != NULL) { - if (type == TA_OPENING_TRANSITION) { - // convert to closing transition - t->parent_clip = t->secondary_clip; - } + for (int i=0;iopening_transition == transition_index + || c->closing_transition == transition_index)) { + if (type == TA_OPENING_TRANSITION) { + // convert to closing transition + t->parent_clip = t->secondary_clip; + } - del = false; - t->secondary_clip = NULL; + del = false; + t->secondary_clip = NULL; + } + } } if (del) { diff --git a/project/undo.cpp b/project/undo.cpp index 27914fa47..c8b50917a 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -95,6 +95,8 @@ void MoveClipAction::redo() { DeleteClipAction::DeleteClipAction(Sequence* s, int clip) : seq(s), index(clip), + opening_transition(-1), + closing_transition(-1), old_project_changed(mainWindow->isWindowModified()) {} @@ -105,13 +107,27 @@ DeleteClipAction::~DeleteClipAction() { void DeleteClipAction::undo() { // restore ref to clip seq->clips[index] = ref; - ref = NULL; + + // restore shared transitions + if (opening_transition > -1) { + seq->transitions.at(opening_transition)->secondary_clip = seq->transitions.at(opening_transition)->parent_clip; + seq->transitions.at(opening_transition)->parent_clip = ref; + ref->opening_transition = opening_transition; + opening_transition = -1; + } + if (closing_transition > -1) { + seq->transitions.at(closing_transition)->secondary_clip = ref; + ref->closing_transition = closing_transition; + closing_transition = -1; + } // restore links to this clip for (int i=linkClipIndex.size()-1;i>=0;i--) { seq->clips.at(linkClipIndex.at(i))->linked.insert(linkLinkIndex.at(i), index); } + ref = NULL; + mainWindow->setWindowModified(old_project_changed); } @@ -123,6 +139,19 @@ void DeleteClipAction::redo() { } seq->clips[index] = NULL; + // save shared transitions + if (ref->opening_transition > -1 && ref->get_opening_transition()->secondary_clip != NULL) { + opening_transition = ref->opening_transition; + ref->get_opening_transition()->parent_clip = ref->get_opening_transition()->secondary_clip; + ref->get_opening_transition()->secondary_clip = NULL; + ref->opening_transition = -1; + } + if (ref->closing_transition > -1 && ref->get_closing_transition()->secondary_clip != NULL) { + closing_transition = ref->closing_transition; + ref->get_closing_transition()->secondary_clip = NULL; + ref->closing_transition = -1; + } + // delete link to this clip linkClipIndex.clear(); linkLinkIndex.clear(); diff --git a/project/undo.h b/project/undo.h index a52da2a1f..759d5acb7 100644 --- a/project/undo.h +++ b/project/undo.h @@ -71,6 +71,9 @@ private: Clip* ref; int index; + int opening_transition; + int closing_transition; + QVector linkClipIndex; QVector linkLinkIndex;