From 712f9f160f4792df6ca3174861d7c3d3b0b2b23c Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 10 Oct 2018 23:30:40 +1100 Subject: [PATCH] fixed #125 --- project/undo.cpp | 17 +++++++++++++++++ project/undo.h | 13 +++++++++++++ ui/timelinewidget.cpp | 42 ++++++++++++++++++++++++++++-------------- ui/timelinewidget.h | 3 +++ 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/project/undo.cpp b/project/undo.cpp index d1d770aae..d89b2419a 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -1488,3 +1488,20 @@ void SetBool::undo() { void SetBool::redo() { *boolean = new_setting; } + +SetSelectionsCommand::SetSelectionsCommand(Sequence* s) : + seq(s), + done(true) +{} + +void SetSelectionsCommand::undo() { + sequence->selections = old_data; + done = false; +} + +void SetSelectionsCommand::redo() { + if (!done) { + sequence->selections = new_data; + done = true; + } +} diff --git a/project/undo.h b/project/undo.h index 77f1050b9..bcdcc68d5 100644 --- a/project/undo.h +++ b/project/undo.h @@ -14,6 +14,7 @@ struct Sequence; struct Media; #include "project/marker.h" +#include "project/selection.h" #include #include @@ -524,4 +525,16 @@ private: bool new_setting; }; +class SetSelectionsCommand : public QUndoCommand { +public: + SetSelectionsCommand(Sequence *s); + void undo(); + void redo(); + QVector old_data; + QVector new_data; +private: + Sequence* seq; + bool done; +}; + #endif // UNDO_H diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index f762f4cf6..7705a61a7 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -35,6 +35,8 @@ #define MAX_TEXT_WIDTH 20 TimelineWidget::TimelineWidget(QWidget *parent) : QWidget(parent) { + selection_command = NULL; + bottom_align = false; track_resizing = false; setMouseTracking(true); @@ -690,13 +692,14 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { bool repaint = false; bool redraw = false; + ComboAction* ca = new ComboAction(); + bool push_undo = false; + if (panel_timeline->creating) { if (panel_timeline->ghosts.size() > 0) { const Ghost& g = panel_timeline->ghosts.at(0); - if (g.in != g.out) { - ComboAction* ca = new ComboAction(); - + if (g.in != g.out) { Clip* c = new Clip(sequence); c->media = NULL; c->timeline_in = qMin(g.in, g.out); @@ -759,8 +762,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { areas.append(s); panel_timeline->delete_areas_and_relink(ca, areas); - undo_stack.push(ca); - + push_undo = true; redraw = true; if (!shift) { @@ -771,9 +773,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { } else if (panel_timeline->moving_proc) { repaint = true; if (panel_timeline->ghosts.size() > 0) { - const Ghost& first_ghost = panel_timeline->ghosts.at(0); - - ComboAction* ca = new ComboAction(); + const Ghost& first_ghost = panel_timeline->ghosts.at(0); // if we were RIPPLING, move all the clips if (panel_timeline->tool == TIMELINE_TOOL_RIPPLE) { @@ -934,14 +934,13 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { } } } - } - undo_stack.push(ca); + } + push_undo = true; redraw = true; } } else if (panel_timeline->selecting || panel_timeline->rect_select_proc) { repaint = true; } else if (panel_timeline->splitting) { - ComboAction* ca = new ComboAction(); bool split = false; for (int i=0;isplit_tracks.size();i++) { int split_index = getClipIndexFromCoords(panel_timeline->drag_frame_start, panel_timeline->split_tracks.at(i)); @@ -950,10 +949,8 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { } } if (split) { - undo_stack.push(ca); + push_undo = true; redraw = true; - } else { - delete ca; } panel_timeline->split_cache.clear(); } @@ -961,6 +958,19 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { // remove duplicate selections panel_timeline->clean_up_selections(sequence->selections); + if (selection_command != NULL) { + selection_command->new_data = sequence->selections; + ca->append(selection_command); + selection_command = NULL; + push_undo = true; + } + + if (push_undo) { + undo_stack.push(ca); + } else { + delete ca; + } + // destroy all ghosts panel_timeline->ghosts.clear(); @@ -1502,6 +1512,10 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } } + // store selections + selection_command = new SetSelectionsCommand(sequence); + selection_command->old_data = sequence->selections; + panel_timeline->moving_proc = true; } panel_timeline->repaint_timeline(false); diff --git a/ui/timelinewidget.h b/ui/timelinewidget.h index 05de529f3..4a7cdb361 100644 --- a/ui/timelinewidget.h +++ b/ui/timelinewidget.h @@ -16,6 +16,7 @@ struct Clip; class Timeline; class TimelineAction; class QScrollArea; +class SetSelectionsCommand; bool same_sign(int a, int b); @@ -68,6 +69,8 @@ private: QTimer tooltip_timer; int tooltip_clip; + + SetSelectionsCommand* selection_command; signals: public slots: