diff --git a/app/widget/marker/CMakeLists.txt b/app/widget/marker/CMakeLists.txt index 01ce2157d..73922308e 100644 --- a/app/widget/marker/CMakeLists.txt +++ b/app/widget/marker/CMakeLists.txt @@ -20,5 +20,7 @@ set(OLIVE_SOURCES widget/marker/marker.cpp widget/marker/markercopypaste.h widget/marker/markercopypaste.cpp + widget/marker/markerundo.h + widget/marker/markerundo.cpp PARENT_SCOPE ) diff --git a/app/widget/marker/markercopypaste.cpp b/app/widget/marker/markercopypaste.cpp index 6dd7b7eee..4a2eddbe3 100644 --- a/app/widget/marker/markercopypaste.cpp +++ b/app/widget/marker/markercopypaste.cpp @@ -16,6 +16,7 @@ #include "markercopypaste.h" #include "core.h" +#include "markerundo.h" #include "widget/timebased/timebasedwidget.h" namespace olive { @@ -108,7 +109,7 @@ void MarkerCopyPasteService::PasteMarkersFromClipboard(TimelineMarkerList* list, } } - command->add_child(new TimeBasedWidget::MarkerAddCommand(Core::instance()->GetActiveProject(), + command->add_child(new MarkerAddCommand(Core::instance()->GetActiveProject(), list, TimeRange(in + offset, out + offset), name, diff --git a/app/widget/marker/markerundo.cpp b/app/widget/marker/markerundo.cpp new file mode 100644 index 000000000..ba338b031 --- /dev/null +++ b/app/widget/marker/markerundo.cpp @@ -0,0 +1,69 @@ +/*** + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#include "markerundo.h" + +namespace olive { + +MarkerAddCommand::MarkerAddCommand(Project *project, TimelineMarkerList *marker_list, const TimeRange &range, const QString &name, int color) : + project_(project), + marker_list_(marker_list), + range_(range), + name_(name), + color_(color) +{ +} + +Project* MarkerAddCommand::GetRelevantProject() const +{ + return project_; +} + +void MarkerAddCommand::redo() +{ + added_marker_ = marker_list_->AddMarker(range_, name_, color_); +} + +void MarkerAddCommand::undo() +{ + marker_list_->RemoveMarker(added_marker_); +} + +MarkerRemoveCommand::MarkerRemoveCommand(Project *project, TimelineMarker *marker, TimelineMarkerList *marker_list) : + project_(project), + marker_(marker), + marker_list_(marker_list), + range_(marker->time()), + name_(marker->name()), + color_(marker->color()) +{ +} + +Project* MarkerRemoveCommand::GetRelevantProject() const +{ + return project_; +} + +void MarkerRemoveCommand::redo() +{ + marker_list_->RemoveMarker(marker_); +} + +void MarkerRemoveCommand::undo() +{ + marker_list_->AddMarker(range_, name_, color_); +} + +} diff --git a/app/widget/marker/markerundo.h b/app/widget/marker/markerundo.h new file mode 100644 index 000000000..5390b8ead --- /dev/null +++ b/app/widget/marker/markerundo.h @@ -0,0 +1,66 @@ +/*** + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#ifndef MARKERUNDO_H +#define MARKERUNDO_H + +#include "undo/undocommand.h" +#include "timeline/timelinemarker.h" + +namespace olive { + +class MarkerAddCommand : public UndoCommand { + public: + MarkerAddCommand(Project* project, TimelineMarkerList* marker_list, const TimeRange& range, const QString& name, + int color = -1); + + virtual Project* GetRelevantProject() const override; + + protected: + virtual void redo() override; + virtual void undo() override; + + private: + Project* project_; + TimelineMarkerList* marker_list_; + TimeRange range_; + QString name_; + int color_; + + TimelineMarker* added_marker_; +}; + +class MarkerRemoveCommand : public UndoCommand { + public: + MarkerRemoveCommand(Project* project, TimelineMarker* marker, TimelineMarkerList* marker_list); + + virtual Project* GetRelevantProject() const override; + + protected: + virtual void redo() override; + virtual void undo() override; + + private: + Project* project_; + TimelineMarker* marker_; + TimelineMarkerList* marker_list_; + TimeRange range_; + QString name_; + int color_; +}; + +} + +#endif // TIMELINEUNDOTRACK_H diff --git a/app/widget/timebased/timebasedwidget.cpp b/app/widget/timebased/timebasedwidget.cpp index 28e8a7eab..351803553 100644 --- a/app/widget/timebased/timebasedwidget.cpp +++ b/app/widget/timebased/timebasedwidget.cpp @@ -27,6 +27,7 @@ #include "config/config.h" #include "core.h" #include "node/project/sequence/sequence.h" +#include "widget/marker/markerundo.h" #include "widget/timelinewidget/undo/timelineundoworkarea.h" namespace olive { @@ -665,55 +666,6 @@ void TimeBasedWidget::DeleteSelected() } } -TimeBasedWidget::MarkerAddCommand::MarkerAddCommand(Project *project, TimelineMarkerList *marker_list, const TimeRange &range, const QString &name, int color) : - project_(project), - marker_list_(marker_list), - range_(range), - name_(name), - color_(color) -{ -} - -Project *TimeBasedWidget::MarkerAddCommand::GetRelevantProject() const -{ - return project_; -} - -void TimeBasedWidget::MarkerAddCommand::redo() -{ - added_marker_ = marker_list_->AddMarker(range_, name_, color_); -} - -void TimeBasedWidget::MarkerAddCommand::undo() -{ - marker_list_->RemoveMarker(added_marker_); -} - -TimeBasedWidget::MarkerRemoveCommand::MarkerRemoveCommand(Project* project, TimelineMarker* marker, TimelineMarkerList* marker_list) : - project_(project), - marker_(marker), - marker_list_(marker_list), - range_(marker->time()), - name_(marker->name()), - color_(marker->color()) -{ -} - -Project *TimeBasedWidget::MarkerRemoveCommand::GetRelevantProject() const -{ - return project_; -} - -void TimeBasedWidget::MarkerRemoveCommand::redo() -{ - marker_list_->RemoveMarker(marker_); -} - -void TimeBasedWidget::MarkerRemoveCommand::undo() -{ - marker_list_->AddMarker(range_, name_, color_); -} - bool TimeBasedWidget::eventFilter(QObject *object, QEvent *event) { if (wheel_passthrough_objects_.contains(object) && event->type() == QEvent::Wheel) { diff --git a/app/widget/timebased/timebasedwidget.h b/app/widget/timebased/timebasedwidget.h index 4167858aa..e8b6bee76 100644 --- a/app/widget/timebased/timebasedwidget.h +++ b/app/widget/timebased/timebasedwidget.h @@ -54,47 +54,6 @@ public: virtual bool eventFilter(QObject* object, QEvent* event) override; - // Temp file location - - class MarkerAddCommand : public UndoCommand { - public: - MarkerAddCommand(Project* project, TimelineMarkerList* marker_list, const TimeRange& range, const QString& name, int color = -1); - - virtual Project* GetRelevantProject() const override; - - protected: - virtual void redo() override; - virtual void undo() override; - - private: - Project* project_; - TimelineMarkerList* marker_list_; - TimeRange range_; - QString name_; - int color_; - - TimelineMarker* added_marker_; - }; - - class MarkerRemoveCommand : public UndoCommand { - public: - MarkerRemoveCommand(Project* project, TimelineMarker* marker, TimelineMarkerList* marker_list); - - virtual Project* GetRelevantProject() const override; - - protected: - virtual void redo() override; - virtual void undo() override; - - private: - Project* project_; - TimelineMarker* marker_; - TimelineMarkerList* marker_list_; - TimeRange range_; - QString name_; - int color_; - }; - public slots: void SetTime(const rational &time); diff --git a/app/widget/timeruler/seekablewidget.cpp b/app/widget/timeruler/seekablewidget.cpp index 3b052b842..fe803c408 100644 --- a/app/widget/timeruler/seekablewidget.cpp +++ b/app/widget/timeruler/seekablewidget.cpp @@ -27,6 +27,7 @@ #include "common/qtutils.h" #include "core.h" #include "widget/timebased/timebasedwidget.h" +#include "widget/marker/markerundo.h" namespace olive { @@ -95,7 +96,7 @@ void SeekableWidget::DeleteSelected() { MultiUndoCommand* command = new MultiUndoCommand(); foreach (TimelineMarker *marker, GetActiveTimelineMarkers()) { - command->add_child(new TimeBasedWidget::MarkerRemoveCommand(Core::instance()->GetActiveProject(), marker, timeline_points_->markers())); + command->add_child(new MarkerRemoveCommand(Core::instance()->GetActiveProject(), marker, timeline_points_->markers())); } Core::instance()->undo_stack()->pushIfHasChildren(command);