diff --git a/mainwindow.cpp b/mainwindow.cpp index 1dcc99353..657b965cb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -161,3 +161,17 @@ void MainWindow::on_actionRipple_Delete_triggered() { panel_timeline->delete_selection(true); } + +void MainWindow::on_action_Undo_triggered() +{ + if (panel_timeline->focused()) { + panel_timeline->undo(); + } +} + +void MainWindow::on_action_Redo_triggered() +{ + if (panel_timeline->focused()) { + panel_timeline->redo(); + } +} diff --git a/mainwindow.h b/mainwindow.h index 5556aae3a..56294253e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,6 +51,10 @@ private slots: void on_actionRipple_Delete_triggered(); + void on_action_Undo_triggered(); + + void on_action_Redo_triggered(); + private: Ui::MainWindow *ui; void setup_layout(); diff --git a/olive.pro.user b/olive.pro.user index d9d7e31d6..e15a33f3d 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -292,7 +292,7 @@ olive.pro false - C:/Users/Matt/Documents/temp + 3768 false true diff --git a/panels/timeline.cpp b/panels/timeline.cpp index a9b3e15bc..3582fbde3 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -137,6 +137,22 @@ bool Timeline::focused() { return (ui->video_area->hasFocus() || ui->audio_area->hasFocus()); } +void Timeline::undo() { + if (sequence != NULL) { + sequence->undo(); + ui->video_area->redraw_clips(); + ui->audio_area->redraw_clips(); + } +} + +void Timeline::redo() { + if (sequence != NULL) { + sequence->redo(); + ui->video_area->redraw_clips(); + ui->audio_area->redraw_clips(); + } +} + void Timeline::repaint_timeline() { if (playing) { // playhead = playhead_start + (playback_timer.elapsed() * 0.001 * sequence->frame_rate); @@ -151,6 +167,9 @@ void Timeline::repaint_timeline() { } void Timeline::redraw_all_clips() { + // add current sequence to the undo stack + sequence->undo_add_current(); + ui->video_area->redraw_clips(); ui->audio_area->redraw_clips(); } diff --git a/panels/timeline.h b/panels/timeline.h index 66939775f..abd650e79 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -61,6 +61,8 @@ public: bool focused(); void zoom_in(); void zoom_out(); + void undo(); + void redo(); void set_sequence(Sequence* s); Sequence* sequence; diff --git a/project/sequence.cpp b/project/sequence.cpp index 7140bec67..843c72b86 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -5,6 +5,7 @@ #include Sequence::Sequence() { + undo_pointer = -1; } Sequence::~Sequence() { @@ -120,3 +121,29 @@ void Sequence::split_at_playhead(long frame) { } } } + +void Sequence::undo_add_current() { + undo_pointer++; + undo_stack.resize(undo_pointer); + undo_stack.append(clips); + qDebug() << "a pointer:" << undo_pointer << undo_stack.size(); +} + +void Sequence::undo() { + if (undo_pointer > 0) { + undo_pointer--; + clips = undo_stack[undo_pointer]; + } else { + qDebug() << "[INFO] No more undos"; + } + qDebug() << "u pointer:" << undo_pointer << undo_stack.size(); +} +void Sequence::redo() { + if (undo_pointer == undo_stack.size() - 1) { + qDebug() << "[INFO] No more redos"; + } else { + undo_pointer++; + clips = undo_stack[undo_pointer]; + } + qDebug() << "r pointer:" << undo_pointer << undo_stack.size(); +} diff --git a/project/sequence.h b/project/sequence.h index d63abe68f..3297a0df4 100644 --- a/project/sequence.h +++ b/project/sequence.h @@ -1,6 +1,8 @@ #ifndef SEQUENCE_H #define SEQUENCE_H +#define UNDO_LIMIT 100 + #include #include "project/clip.h" @@ -25,8 +27,16 @@ public: float frame_rate; int audio_frequency; int audio_layout; + + void undo_add_current(); + void undo(); + void redo(); private: QList clips; + + QVector> undo_stack; + int undo_pointer; + int undo_stack_start; }; #endif // SEQUENCE_H diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 743aae638..66a29c831 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -772,8 +772,8 @@ void TimelineWidget::paintEvent(QPaintEvent*) { if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) { QPoint mouse_pos = mapFromGlobal(QCursor::pos()); int track = getTrackFromScreenPoint(mouse_pos.y()); - if (is_track_visible(track)) { - int cursor_x = getScreenPointFromFrame(getFrameFromScreenPoint(mouse_pos.x(), false)); + if (is_track_visible(track)) { + int cursor_x = getScreenPointFromFrame(getFrameFromScreenPoint(mouse_pos.x(), false)); int cursor_y = getScreenPointFromTrack(track); p.setPen(Qt::gray);