From ca807b7b665738c76b6bbb1ad71a62f64e80a79c Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sun, 15 Aug 2021 13:45:08 +0100 Subject: [PATCH] Marker color is saved to .ove file --- app/timeline/timelinemarker.cpp | 12 ++++++++++-- app/timeline/timelinemarker.h | 2 +- app/widget/timeruler/seekablewidget.cpp | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/timeline/timelinemarker.cpp b/app/timeline/timelinemarker.cpp index 7d5d44884..11e5303dc 100644 --- a/app/timeline/timelinemarker.cpp +++ b/app/timeline/timelinemarker.cpp @@ -73,6 +73,8 @@ void TimelineMarkerList::Save(QXmlStreamWriter *writer) const writer->writeAttribute(QStringLiteral("name"), marker->name()); + writer->writeAttribute(QStringLiteral("color"), QString::number(marker->color())); + writer->writeAttribute(QStringLiteral("in"), marker->time().in().toString()); writer->writeAttribute(QStringLiteral("out"), marker->time().out().toString()); @@ -85,9 +87,12 @@ TimelineMarkerList::~TimelineMarkerList() qDeleteAll(markers_); } -TimelineMarker* TimelineMarkerList::AddMarker(const TimeRange &time, const QString &name) +TimelineMarker* TimelineMarkerList::AddMarker(const TimeRange &time, const QString &name, int color) { TimelineMarker* m = new TimelineMarker(time, name); + if (color >= 0) { + m->set_color(color); + } markers_.append(m); emit MarkerAdded(m); return m; @@ -117,11 +122,14 @@ void TimelineMarkerList::Load(QXmlStreamReader *reader) while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("marker")) { QString name; + int color = -1; rational in, out; XMLAttributeLoop(reader, attr) { if (attr.name() == QStringLiteral("name")) { name = attr.value().toString(); + }else if(attr.name() == QStringLiteral("color")){ + color = attr.value().toInt(); } else if (attr.name() == QStringLiteral("in")) { in = rational::fromString(attr.value().toString()); } else if (attr.name() == QStringLiteral("out")) { @@ -129,7 +137,7 @@ void TimelineMarkerList::Load(QXmlStreamReader *reader) } } - AddMarker(TimeRange(in, out), name); + AddMarker(TimeRange(in, out), name, color); } reader->skipCurrentElement(); diff --git a/app/timeline/timelinemarker.h b/app/timeline/timelinemarker.h index be037367f..be1c62b77 100644 --- a/app/timeline/timelinemarker.h +++ b/app/timeline/timelinemarker.h @@ -68,7 +68,7 @@ public: virtual ~TimelineMarkerList() override; - TimelineMarker *AddMarker(const TimeRange& time = TimeRange(), const QString& name = QString()); + TimelineMarker *AddMarker(const TimeRange& time = TimeRange(), const QString& name = QString(), int color = -1); void RemoveMarker(TimelineMarker* marker); diff --git a/app/widget/timeruler/seekablewidget.cpp b/app/widget/timeruler/seekablewidget.cpp index 0d62eed00..297bf6558 100644 --- a/app/widget/timeruler/seekablewidget.cpp +++ b/app/widget/timeruler/seekablewidget.cpp @@ -44,6 +44,7 @@ SeekableWidget::SeekableWidget(QWidget* parent) : playhead_width_ = QtUtils::QFontMetricsWidth(fm, "H"); setContextMenuPolicy(Qt::CustomContextMenu); + } void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points) @@ -53,6 +54,10 @@ void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points) disconnect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast(&SeekableWidget::update)); disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast(&SeekableWidget::update)); disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast(&SeekableWidget::update)); + + foreach(Marker* marker_widget, marker_map_.values()) { + marker_widget->deleteLater(); + } } timeline_points_ = points; @@ -66,6 +71,14 @@ void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points) connect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, &SeekableWidget::addMarker); } + if (timeline_points() && !timeline_points()->markers()->list().isEmpty()) { + foreach (TimelineMarker *marker, timeline_points()->markers()->list()) { + if (!marker_map_.keys().contains(marker)) { + addMarker(marker); + } + } + } + updateMarkerPositions(); update(); @@ -147,6 +160,7 @@ void SeekableWidget::addMarker(TimelineMarker* marker) connect(marker, &TimelineMarker::ColorChanged, marker_widget, &Marker::SetColor); marker_widget->move(TimeToScreen(marker->time().in()), 20); + marker_widget->SetColor(marker->color()); marker_widget->show(); } }