timeline: made markers undoable

This commit is contained in:
itsmattkc
2020-11-16 08:58:51 +11:00
parent 39149d28c7
commit 81c98e1026
5 changed files with 53 additions and 3 deletions
+2 -1
View File
@@ -72,11 +72,12 @@ TimelineMarkerList::~TimelineMarkerList()
qDeleteAll(markers_);
}
void TimelineMarkerList::AddMarker(const TimeRange &time, const QString &name)
TimelineMarker* TimelineMarkerList::AddMarker(const TimeRange &time, const QString &name)
{
TimelineMarker* m = new TimelineMarker(time, name);
markers_.append(m);
emit MarkerAdded(m);
return m;
}
void TimelineMarkerList::RemoveMarker(TimelineMarker *marker)
+1 -1
View File
@@ -61,7 +61,7 @@ public:
virtual ~TimelineMarkerList() override;
void AddMarker(const TimeRange& time = TimeRange(), const QString& name = QString());
TimelineMarker *AddMarker(const TimeRange& time = TimeRange(), const QString& name = QString());
void RemoveMarker(TimelineMarker* marker);
+25 -1
View File
@@ -458,7 +458,8 @@ void TimeBasedWidget::SetMarker()
}
if (ok) {
points_->markers()->AddMarker(TimeRange(GetTime(), GetTime()), marker_name);
Core::instance()->undo_stack()->push(new MarkerAddCommand(static_cast<Sequence*>(GetConnectedNode()->parent())->project(),
points_->markers(), TimeRange(GetTime(), GetTime()), marker_name));
}
}
@@ -517,4 +518,27 @@ void TimeBasedWidget::GoToOut()
}
}
TimeBasedWidget::MarkerAddCommand::MarkerAddCommand(Project *project, TimelineMarkerList *marker_list, const TimeRange &range, const QString &name) :
project_(project),
marker_list_(marker_list),
range_(range),
name_(name)
{
}
Project *TimeBasedWidget::MarkerAddCommand::GetRelevantProject() const
{
return project_;
}
void TimeBasedWidget::MarkerAddCommand::redo_internal()
{
added_marker_ = marker_list_->AddMarker(range_, name_);
}
void TimeBasedWidget::MarkerAddCommand::undo_internal()
{
marker_list_->RemoveMarker(added_marker_);
}
OLIVE_NAMESPACE_EXIT
+21
View File
@@ -139,6 +139,27 @@ signals:
void TimebaseChanged(const rational&);
private:
class MarkerAddCommand : public UndoCommand
{
public:
MarkerAddCommand(Project* project, TimelineMarkerList* marker_list, const TimeRange& range, const QString& name);
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
Project* project_;
TimelineMarkerList* marker_list_;
TimeRange range_;
QString name_;
TimelineMarker* added_marker_;
};
/**
* @brief Set either in or out point to the current playhead
*
+4
View File
@@ -51,6 +51,8 @@ void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points)
if (timeline_points_) {
disconnect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
disconnect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
}
timeline_points_ = points;
@@ -58,6 +60,8 @@ void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points)
if (timeline_points_) {
connect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
connect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
connect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
connect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
}
update();