diff --git a/app/dialog/export/export.cpp b/app/dialog/export/export.cpp index d805f8726..f93bb6177 100644 --- a/app/dialog/export/export.cpp +++ b/app/dialog/export/export.cpp @@ -107,7 +107,7 @@ ExportDialog::ExportDialog(ViewerOutput *viewer_node, QWidget *parent) : range_combobox_ = new QComboBox(); range_combobox_->addItem(tr("Entire Sequence")); range_combobox_->addItem(tr("In to Out")); - range_combobox_->setEnabled(viewer_node_->GetTimelinePoints()->workarea()->enabled()); + range_combobox_->setEnabled(viewer_node_->GetWorkArea()->enabled()); preferences_layout->addWidget(range_combobox_, row, 1, 1, 3); @@ -247,7 +247,6 @@ ExportDialog::ExportDialog(ViewerOutput *viewer_node, QWidget *parent) : // Set viewer to view the node preview_viewer_->ConnectViewerNode(viewer_node_); - preview_viewer_->ruler()->ConnectTimelinePoints(viewer_node_->GetTimelinePoints()); preview_viewer_->SetColorMenuEnabled(false); preview_viewer_->SetColorTransform(video_tab_->CurrentOCIOColorSpace()); } @@ -529,7 +528,7 @@ ExportParams ExportDialog::GenerateParams() const params.set_custom_range(TimeRange(export_time, export_time + GetSelectedTimebase())); } else if (range_combobox_->currentIndex() == kRangeInToOut) { // Assume if this combobox is enabled, workarea is enabled - a check that we make in this dialog's constructor - params.set_custom_range(viewer_node_->GetTimelinePoints()->workarea()->range()); + params.set_custom_range(viewer_node_->GetWorkArea()->range()); } if (video_tab_->scaling_method_combobox()->isEnabled()) { @@ -570,7 +569,7 @@ ExportParams ExportDialog::GenerateParams() const rational ExportDialog::GetExportLength() const { if (range_combobox_->currentIndex() == kRangeInToOut) { - return viewer_node_->GetTimelinePoints()->workarea()->range().length(); + return viewer_node_->GetWorkArea()->range().length(); } else { return viewer_node_->GetLength(); } diff --git a/app/node/block/clip/clip.cpp b/app/node/block/clip/clip.cpp index 241484965..080850c45 100644 --- a/app/node/block/clip/clip.cpp +++ b/app/node/block/clip/clip.cpp @@ -204,17 +204,17 @@ void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int if (new_connected_viewer != connected_viewer_) { if (connected_viewer_) { - disconnect(connected_viewer_->GetTimelinePoints()->markers(), &TimelineMarkerList::MarkerAdded, this, &ClipBlock::PreviewChanged); - disconnect(connected_viewer_->GetTimelinePoints()->markers(), &TimelineMarkerList::MarkerRemoved, this, &ClipBlock::PreviewChanged); - disconnect(connected_viewer_->GetTimelinePoints()->markers(), &TimelineMarkerList::MarkerModified, this, &ClipBlock::PreviewChanged); + disconnect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerAdded, this, &ClipBlock::PreviewChanged); + disconnect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerRemoved, this, &ClipBlock::PreviewChanged); + disconnect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerModified, this, &ClipBlock::PreviewChanged); } connected_viewer_ = new_connected_viewer; if (connected_viewer_) { - connect(connected_viewer_->GetTimelinePoints()->markers(), &TimelineMarkerList::MarkerAdded, this, &ClipBlock::PreviewChanged); - connect(connected_viewer_->GetTimelinePoints()->markers(), &TimelineMarkerList::MarkerRemoved, this, &ClipBlock::PreviewChanged); - connect(connected_viewer_->GetTimelinePoints()->markers(), &TimelineMarkerList::MarkerModified, this, &ClipBlock::PreviewChanged); + connect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerAdded, this, &ClipBlock::PreviewChanged); + connect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerRemoved, this, &ClipBlock::PreviewChanged); + connect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerModified, this, &ClipBlock::PreviewChanged); } } diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index a9476a101..b505a8354 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -58,7 +58,8 @@ ViewerOutput::ViewerOutput(bool create_buffer_inputs, bool create_default_stream SetFlags(kDontShowInParamView); - timeline_points_ = new TimelinePoints(this); + workarea_ = new TimelineWorkArea(this); + markers_ = new TimelineMarkerList(this); } QString ViewerOutput::Name() const diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index c68225df8..bc30cbc8a 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -29,7 +29,8 @@ #include "render/framehashcache.h" #include "render/subtitleparams.h" #include "render/videoparams.h" -#include "timeline/timelinepoints.h" +#include "timeline/timelinemarker.h" +#include "timeline/timelineworkarea.h" namespace olive { @@ -142,10 +143,8 @@ public: const rational &GetVideoLength() const { return video_length_; } const rational &GetAudioLength() const { return audio_length_; } - TimelinePoints* GetTimelinePoints() - { - return timeline_points_; - } + TimelineWorkArea *GetWorkArea() const { return workarea_; } + TimelineMarkerList *GetMarkers() const { return markers_; } QVector GetEnabledStreamsAsReferences() const; @@ -212,7 +211,8 @@ private: AudioParams cached_audio_params_; - TimelinePoints *timeline_points_; + TimelineWorkArea *workarea_; + TimelineMarkerList *markers_; }; diff --git a/app/node/project/footage/footage.h b/app/node/project/footage/footage.h index 4db9cdf59..43e5f80c7 100644 --- a/app/node/project/footage/footage.h +++ b/app/node/project/footage/footage.h @@ -29,7 +29,6 @@ #include "node/output/viewer/viewer.h" #include "render/audioparams.h" #include "render/videoparams.h" -#include "timeline/timelinepoints.h" namespace olive { diff --git a/app/node/project/sequence/sequence.h b/app/node/project/sequence/sequence.h index 25220a4f5..4f8b62d04 100644 --- a/app/node/project/sequence/sequence.h +++ b/app/node/project/sequence/sequence.h @@ -23,7 +23,6 @@ #include "node/output/track/tracklist.h" #include "node/output/viewer/viewer.h" -#include "timeline/timelinepoints.h" namespace olive { diff --git a/app/node/project/serializer/serializer210528.cpp b/app/node/project/serializer/serializer210528.cpp index f0ad798ad..ea30b7578 100644 --- a/app/node/project/serializer/serializer210528.cpp +++ b/app/node/project/serializer/serializer210528.cpp @@ -496,7 +496,7 @@ void ProjectSerializer210528::LoadNodeCustom(QXmlStreamReader *reader, Node *nod while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("points")) { - LoadTimelinePoints(reader, viewer->GetTimelinePoints()); + LoadTimelinePoints(reader, viewer); } else if (reader->name() == QStringLiteral("timestamp") && footage) { footage->set_timestamp(reader->readElementText().toLongLong()); } else { @@ -553,13 +553,13 @@ void ProjectSerializer210528::LoadNodeCustom(QXmlStreamReader *reader, Node *nod } } -void ProjectSerializer210528::LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const +void ProjectSerializer210528::LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *points) const { while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("markers")) { - LoadMarkerList(reader, points->markers()); + LoadMarkerList(reader, points->GetMarkers()); } else if (reader->name() == QStringLiteral("workarea")) { - LoadWorkArea(reader, points->workarea()); + LoadWorkArea(reader, points->GetWorkArea()); } else { reader->skipCurrentElement(); } diff --git a/app/node/project/serializer/serializer210528.h b/app/node/project/serializer/serializer210528.h index 2bf195064..537b89cf4 100644 --- a/app/node/project/serializer/serializer210528.h +++ b/app/node/project/serializer/serializer210528.h @@ -78,7 +78,7 @@ private: void LoadNodeCustom(QXmlStreamReader *reader, Node *node, XMLNodeData &xml_node_data) const; - void LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const; + void LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *points) const; void LoadWorkArea(QXmlStreamReader *reader, TimelineWorkArea *workarea) const; diff --git a/app/node/project/serializer/serializer210907.cpp b/app/node/project/serializer/serializer210907.cpp index edcb86ae3..dc5e127e7 100644 --- a/app/node/project/serializer/serializer210907.cpp +++ b/app/node/project/serializer/serializer210907.cpp @@ -488,7 +488,7 @@ void ProjectSerializer210907::LoadNodeCustom(QXmlStreamReader *reader, Node *nod while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("points")) { - LoadTimelinePoints(reader, viewer->GetTimelinePoints()); + LoadTimelinePoints(reader, viewer); } else if (reader->name() == QStringLiteral("timestamp") && footage) { footage->set_timestamp(reader->readElementText().toLongLong()); } else { @@ -545,13 +545,13 @@ void ProjectSerializer210907::LoadNodeCustom(QXmlStreamReader *reader, Node *nod } } -void ProjectSerializer210907::LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const +void ProjectSerializer210907::LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *points) const { while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("markers")) { - LoadMarkerList(reader, points->markers()); + LoadMarkerList(reader, points->GetMarkers()); } else if (reader->name() == QStringLiteral("workarea")) { - LoadWorkArea(reader, points->workarea()); + LoadWorkArea(reader, points->GetWorkArea()); } else { reader->skipCurrentElement(); } diff --git a/app/node/project/serializer/serializer210907.h b/app/node/project/serializer/serializer210907.h index 6a56d43b5..c3e8033de 100644 --- a/app/node/project/serializer/serializer210907.h +++ b/app/node/project/serializer/serializer210907.h @@ -77,7 +77,7 @@ private: void LoadNodeCustom(QXmlStreamReader *reader, Node *node, XMLNodeData &xml_node_data) const; - void LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const; + void LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *points) const; void LoadWorkArea(QXmlStreamReader *reader, TimelineWorkArea *workarea) const; diff --git a/app/node/project/serializer/serializer211228.cpp b/app/node/project/serializer/serializer211228.cpp index 41254b105..94a6ce1ed 100644 --- a/app/node/project/serializer/serializer211228.cpp +++ b/app/node/project/serializer/serializer211228.cpp @@ -538,7 +538,7 @@ void ProjectSerializer211228::LoadNodeCustom(QXmlStreamReader *reader, Node *nod while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("points")) { - LoadTimelinePoints(reader, viewer->GetTimelinePoints()); + LoadTimelinePoints(reader, viewer); } else if (reader->name() == QStringLiteral("timestamp") && footage) { footage->set_timestamp(reader->readElementText().toLongLong()); } else { @@ -595,13 +595,13 @@ void ProjectSerializer211228::LoadNodeCustom(QXmlStreamReader *reader, Node *nod } } -void ProjectSerializer211228::LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const +void ProjectSerializer211228::LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *points) const { while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("markers")) { - LoadMarkerList(reader, points->markers()); + LoadMarkerList(reader, points->GetMarkers()); } else if (reader->name() == QStringLiteral("workarea")) { - LoadWorkArea(reader, points->workarea()); + LoadWorkArea(reader, points->GetWorkArea()); } else { reader->skipCurrentElement(); } diff --git a/app/node/project/serializer/serializer211228.h b/app/node/project/serializer/serializer211228.h index 49733a5d7..bc424bc4c 100644 --- a/app/node/project/serializer/serializer211228.h +++ b/app/node/project/serializer/serializer211228.h @@ -78,7 +78,7 @@ private: void LoadNodeCustom(QXmlStreamReader *reader, Node *node, XMLNodeData &xml_node_data) const; - void LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const; + void LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *points) const; void LoadWorkArea(QXmlStreamReader *reader, TimelineWorkArea *workarea) const; diff --git a/app/node/project/serializer/serializer220403.cpp b/app/node/project/serializer/serializer220403.cpp index 7dd4ae5c3..a8fd3c88c 100644 --- a/app/node/project/serializer/serializer220403.cpp +++ b/app/node/project/serializer/serializer220403.cpp @@ -989,7 +989,7 @@ void ProjectSerializer220403::LoadNodeCustom(QXmlStreamReader *reader, Node *nod while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("points")) { - LoadTimelinePoints(reader, viewer->GetTimelinePoints()); + LoadTimelinePoints(reader, viewer); } else if (reader->name() == QStringLiteral("timestamp") && footage) { footage->set_timestamp(reader->readElementText().toLongLong()); } else { @@ -1084,7 +1084,7 @@ void ProjectSerializer220403::SaveNodeCustom(QXmlStreamWriter *writer, Node *nod if (ViewerOutput *viewer = dynamic_cast(node)) { // Write TimelinePoints writer->writeStartElement(QStringLiteral("points")); - SaveTimelinePoints(writer, viewer->GetTimelinePoints()); + SaveTimelinePoints(writer, viewer); writer->writeEndElement(); // points if (Footage *footage = dynamic_cast(node)) { @@ -1136,27 +1136,27 @@ void ProjectSerializer220403::SaveNodeCustom(QXmlStreamWriter *writer, Node *nod } } -void ProjectSerializer220403::LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const +void ProjectSerializer220403::LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *viewer) const { while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("markers")) { - LoadMarkerList(reader, points->markers()); + LoadMarkerList(reader, viewer->GetMarkers()); } else if (reader->name() == QStringLiteral("workarea")) { - LoadWorkArea(reader, points->workarea()); + LoadWorkArea(reader, viewer->GetWorkArea()); } else { reader->skipCurrentElement(); } } } -void ProjectSerializer220403::SaveTimelinePoints(QXmlStreamWriter *writer, TimelinePoints *points) const +void ProjectSerializer220403::SaveTimelinePoints(QXmlStreamWriter *writer, ViewerOutput *viewer) const { writer->writeStartElement(QStringLiteral("workarea")); - SaveWorkArea(writer, points->workarea()); + SaveWorkArea(writer, viewer->GetWorkArea()); writer->writeEndElement(); // workarea writer->writeStartElement(QStringLiteral("markers")); - SaveMarkerList(writer, points->markers()); + SaveMarkerList(writer, viewer->GetMarkers()); writer->writeEndElement(); // markers } diff --git a/app/node/project/serializer/serializer220403.h b/app/node/project/serializer/serializer220403.h index 4612b2fce..fbeb4bfc2 100644 --- a/app/node/project/serializer/serializer220403.h +++ b/app/node/project/serializer/serializer220403.h @@ -100,9 +100,9 @@ private: void SaveNodeCustom(QXmlStreamWriter *writer, Node *node) const; - void LoadTimelinePoints(QXmlStreamReader *reader, TimelinePoints *points) const; + void LoadTimelinePoints(QXmlStreamReader *reader, ViewerOutput *viewer) const; - void SaveTimelinePoints(QXmlStreamWriter *writer, TimelinePoints *points) const; + void SaveTimelinePoints(QXmlStreamWriter *writer, ViewerOutput *viewer) const; void LoadMarker(QXmlStreamReader *reader, TimelineMarker *marker) const; diff --git a/app/panel/timeline/timeline.cpp b/app/panel/timeline/timeline.cpp index f08f7b998..686aec085 100644 --- a/app/panel/timeline/timeline.cpp +++ b/app/panel/timeline/timeline.cpp @@ -36,6 +36,7 @@ TimelinePanel::TimelinePanel(QWidget *parent) : connect(tw, &TimelineWidget::BlockSelectionChanged, this, &TimelinePanel::BlockSelectionChanged); connect(tw, &TimelineWidget::RequestCaptureStart, this, &TimelinePanel::RequestCaptureStart); connect(tw, &TimelineWidget::RevealViewerInProject, this, &TimelinePanel::RevealViewerInProject); + connect(tw, &TimelineWidget::RevealViewerInFootageViewer, this, &TimelinePanel::RevealViewerInFootageViewer); } void TimelinePanel::SplitAtPlayhead() diff --git a/app/panel/timeline/timeline.h b/app/panel/timeline/timeline.h index 90de35332..cf596a724 100644 --- a/app/panel/timeline/timeline.h +++ b/app/panel/timeline/timeline.h @@ -109,6 +109,7 @@ signals: void RequestCaptureStart(const TimeRange &time, const Track::Reference &track); void RevealViewerInProject(ViewerOutput *r); + void RevealViewerInFootageViewer(ViewerOutput *r, const TimeRange &range); }; diff --git a/app/task/precache/precachetask.cpp b/app/task/precache/precachetask.cpp index e83de623b..b0145474c 100644 --- a/app/task/precache/precachetask.cpp +++ b/app/task/precache/precachetask.cpp @@ -65,9 +65,9 @@ bool PreCacheTask::Run() // Get list of invalidated ranges TimeRange intersection; - if (footage_->GetTimelinePoints()->workarea()->enabled()) { + if (footage_->GetWorkArea()->enabled()) { // If we're caching only in-out, limit the range to that - intersection = footage_->GetTimelinePoints()->workarea()->range(); + intersection = footage_->GetWorkArea()->range(); } else { // Otherwise use full length intersection = TimeRange(0, footage_->GetVideoLength()); diff --git a/app/timeline/CMakeLists.txt b/app/timeline/CMakeLists.txt index 3fb988e83..f43d93de3 100644 --- a/app/timeline/CMakeLists.txt +++ b/app/timeline/CMakeLists.txt @@ -21,8 +21,6 @@ set(OLIVE_SOURCES timeline/timelinecoordinate.cpp timeline/timelinemarker.h timeline/timelinemarker.cpp - timeline/timelinepoints.h - timeline/timelinepoints.cpp timeline/timelineworkarea.h timeline/timelineworkarea.cpp PARENT_SCOPE diff --git a/app/timeline/timelinepoints.cpp b/app/timeline/timelinepoints.cpp deleted file mode 100644 index b7c2034bb..000000000 --- a/app/timeline/timelinepoints.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 "timelinepoints.h" - -#include "common/xmlutils.h" - -namespace olive { - -TimelinePoints::TimelinePoints(QObject *parent) : - QObject(parent) -{ - markers_ = new TimelineMarkerList(this); - workarea_ = new TimelineWorkArea(this); -} - -TimelineMarkerList *TimelinePoints::markers() -{ - return markers_; -} - -const TimelineMarkerList *TimelinePoints::markers() const -{ - return markers_; -} - -const TimelineWorkArea *TimelinePoints::workarea() const -{ - return workarea_; -} - -TimelineWorkArea *TimelinePoints::workarea() -{ - return workarea_; -} - -} diff --git a/app/timeline/timelinepoints.h b/app/timeline/timelinepoints.h deleted file mode 100644 index 02ea804ce..000000000 --- a/app/timeline/timelinepoints.h +++ /dev/null @@ -1,53 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 TIMELINEPOINTS_H -#define TIMELINEPOINTS_H - -#include -#include - -#include "timelinemarker.h" -#include "timelineworkarea.h" - -namespace olive { - -class TimelinePoints : public QObject -{ - Q_OBJECT -public: - TimelinePoints(QObject *parent = nullptr); - - TimelineMarkerList* markers(); - const TimelineMarkerList* markers() const; - - TimelineWorkArea* workarea(); - const TimelineWorkArea* workarea() const; - -private: - TimelineMarkerList *markers_; - - TimelineWorkArea *workarea_; - -}; - -} - -#endif // TIMELINEPOINTS_H diff --git a/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp b/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp index 4672657bb..2d4f98ea2 100644 --- a/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp +++ b/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp @@ -31,36 +31,51 @@ namespace olive { ResizableTimelineScrollBar::ResizableTimelineScrollBar(QWidget* parent) : ResizableScrollBar(parent), - points_(nullptr), + markers_(nullptr), + workarea_(nullptr), scale_(1.0) { } ResizableTimelineScrollBar::ResizableTimelineScrollBar(Qt::Orientation orientation, QWidget* parent) : ResizableScrollBar(orientation, parent), - points_(nullptr), + markers_(nullptr), + workarea_(nullptr), scale_(1.0) { } -void ResizableTimelineScrollBar::ConnectTimelinePoints(TimelinePoints *points) +void ResizableTimelineScrollBar::ConnectMarkers(TimelineMarkerList *markers) { - if (points_) { - disconnect(points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast(&ResizableTimelineScrollBar::update)); - disconnect(points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast(&ResizableTimelineScrollBar::update)); - disconnect(points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast(&ResizableTimelineScrollBar::update)); - disconnect(points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast(&ResizableTimelineScrollBar::update)); - disconnect(points_->markers(), &TimelineMarkerList::MarkerModified, this, static_cast(&ResizableTimelineScrollBar::update)); + if (markers_) { + disconnect(markers_, &TimelineMarkerList::MarkerAdded, this, static_cast(&ResizableTimelineScrollBar::update)); + disconnect(markers_, &TimelineMarkerList::MarkerRemoved, this, static_cast(&ResizableTimelineScrollBar::update)); + disconnect(markers_, &TimelineMarkerList::MarkerModified, this, static_cast(&ResizableTimelineScrollBar::update)); } - points_ = points; + markers_ = markers; - if (points_) { - connect(points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast(&ResizableTimelineScrollBar::update)); - connect(points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast(&ResizableTimelineScrollBar::update)); - connect(points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast(&ResizableTimelineScrollBar::update)); - connect(points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast(&ResizableTimelineScrollBar::update)); - connect(points_->markers(), &TimelineMarkerList::MarkerModified, this, static_cast(&ResizableTimelineScrollBar::update)); + if (markers_) { + connect(markers_, &TimelineMarkerList::MarkerAdded, this, static_cast(&ResizableTimelineScrollBar::update)); + connect(markers_, &TimelineMarkerList::MarkerRemoved, this, static_cast(&ResizableTimelineScrollBar::update)); + connect(markers_, &TimelineMarkerList::MarkerModified, this, static_cast(&ResizableTimelineScrollBar::update)); + } + + update(); +} + +void ResizableTimelineScrollBar::ConnectWorkArea(TimelineWorkArea *workarea) +{ + if (workarea_) { + disconnect(workarea_, &TimelineWorkArea::RangeChanged, this, static_cast(&ResizableTimelineScrollBar::update)); + disconnect(workarea_, &TimelineWorkArea::EnabledChanged, this, static_cast(&ResizableTimelineScrollBar::update)); + } + + workarea_ = workarea; + + if (workarea_) { + connect(workarea_, &TimelineWorkArea::RangeChanged, this, static_cast(&ResizableTimelineScrollBar::update)); + connect(workarea_, &TimelineWorkArea::EnabledChanged, this, static_cast(&ResizableTimelineScrollBar::update)); } update(); @@ -77,9 +92,8 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event) { ResizableScrollBar::paintEvent(event); - if (points_ - && !timebase().isNull() - && (points_->workarea()->enabled() || !points_->markers()->empty())) { + if (!timebase().isNull() && ((workarea_ && workarea_->enabled()) || (markers_ && !markers_->empty()))) { + // Draw workarea QStyleOptionSlider opt; initStyleOption(&opt); @@ -87,20 +101,20 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event) QStyle::SC_ScrollBarGroove, this); double ratio = scale_ * double(gr.width()) / double(this->maximum() + gr.width()); - QPainter p(this); - if (points_->workarea()->enabled()) { + if (workarea_ && workarea_->enabled()) { + QColor workarea_color(this->palette().highlight().color()); workarea_color.setAlpha(128); - qint64 in = qMax(qint64(0), qRound64(ratio * TimeToScene(points_->workarea()->in()))); + qint64 in = qMax(qint64(0), qRound64(ratio * TimeToScene(workarea_->in()))); qint64 out; - if (points_->workarea()->out() == RATIONAL_MAX) { + if (workarea_->out() == RATIONAL_MAX) { out = gr.width(); } else { - out = qMin(qint64(gr.width()), qRound64(ratio * TimeToScene(points_->workarea()->out()))); + out = qMin(qint64(gr.width()), qRound64(ratio * TimeToScene(workarea_->out()))); } qint64 length = qMax(qint64(1), out-in); @@ -112,8 +126,9 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event) workarea_color); } - if (!points_->markers()->empty()) { - for (auto it=points_->markers()->cbegin(); it!=points_->markers()->cend(); it++) { + // Draw markers + if (markers_ && !markers_->empty()) { + for (auto it=markers_->cbegin(); it!=markers_->cend(); it++) { TimelineMarker* marker = *it; QColor marker_color = ColorCoding::GetColor(marker->color()).toQColor(); diff --git a/app/widget/resizablescrollbar/resizabletimelinescrollbar.h b/app/widget/resizablescrollbar/resizabletimelinescrollbar.h index dcd8b10fc..93d7ec197 100644 --- a/app/widget/resizablescrollbar/resizabletimelinescrollbar.h +++ b/app/widget/resizablescrollbar/resizabletimelinescrollbar.h @@ -22,7 +22,8 @@ #define RESIZABLETIMELINESCROLLBAR_H #include "resizablescrollbar.h" -#include "timeline/timelinepoints.h" +#include "timeline/timelinemarker.h" +#include "timeline/timelineworkarea.h" #include "widget/timebased/timescaledobject.h" namespace olive { @@ -34,7 +35,8 @@ public: ResizableTimelineScrollBar(QWidget* parent = nullptr); ResizableTimelineScrollBar(Qt::Orientation orientation, QWidget* parent = nullptr); - void ConnectTimelinePoints(TimelinePoints* points); + void ConnectMarkers(TimelineMarkerList *markers); + void ConnectWorkArea(TimelineWorkArea *workarea); void SetScale(double d); @@ -42,7 +44,9 @@ protected: virtual void paintEvent(QPaintEvent* event) override; private: - TimelinePoints* points_; + TimelineMarkerList* markers_; + + TimelineWorkArea* workarea_; double scale_; diff --git a/app/widget/timebased/timebasedwidget.cpp b/app/widget/timebased/timebasedwidget.cpp index a812e6c69..ebd95cf9e 100644 --- a/app/widget/timebased/timebasedwidget.cpp +++ b/app/widget/timebased/timebasedwidget.cpp @@ -39,7 +39,9 @@ TimeBasedWidget::TimeBasedWidget(bool ruler_text_visible, bool ruler_cache_statu viewer_node_(nullptr), auto_max_scrollbar_(false), toggle_show_all_(false), - auto_set_timebase_(true) + auto_set_timebase_(true), + workarea_(nullptr), + markers_(nullptr) { ruler_ = new TimeRuler(ruler_text_visible, ruler_cache_status_visible, this); ConnectTimelineView(ruler_, true); @@ -98,8 +100,8 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node) SetTimebase(rational()); // Disconnect ruler and scrollbar from timeline points - ruler()->ConnectTimelinePoints(nullptr); - scrollbar_->ConnectTimelinePoints(nullptr); + ConnectWorkArea(nullptr); + ConnectMarkers(nullptr); } // Call derivatives @@ -111,8 +113,8 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node) connect(viewer_node_, &ViewerOutput::RemovedFromGraph, this, &TimeBasedWidget::ConnectedNodeRemovedFromGraph); // Connect ruler and scrollbar to timeline points - ruler()->ConnectTimelinePoints(viewer_node_->GetTimelinePoints()); - scrollbar_->ConnectTimelinePoints(viewer_node_->GetTimelinePoints()); + ConnectWorkArea(viewer_node_->GetWorkArea()); + ConnectMarkers(viewer_node_->GetMarkers()); // If we're setting the timebase, set it automatically based on the video and audio parameters if (auto_set_timebase_) { @@ -130,6 +132,20 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node) emit ConnectedNodeChanged(old, node); } +void TimeBasedWidget::ConnectWorkArea(TimelineWorkArea *workarea) +{ + workarea_ = workarea; + ruler()->SetWorkArea(workarea); + scrollbar_->ConnectWorkArea(workarea); +} + +void TimeBasedWidget::ConnectMarkers(TimelineMarkerList *markers) +{ + markers_ = markers; + ruler()->SetMarkers(markers); + scrollbar_->ConnectMarkers(markers); +} + void TimeBasedWidget::UpdateMaximumScroll() { rational length = (viewer_node_) ? viewer_node_->GetLength() : 0; @@ -374,14 +390,14 @@ void TimeBasedWidget::GoToNextCut() rational closest_cut = RATIONAL_MAX; - foreach (Track* track, sequence->GetTracks()) { + for (Track* track : sequence->GetTracks()) { rational this_track_closest_cut = track->track_length(); if (this_track_closest_cut <= GetTime()) { this_track_closest_cut = RATIONAL_MAX; } - foreach (Block* block, track->Blocks()) { + for (Block* block : track->Blocks()) { if (block->in() > GetTime()) { this_track_closest_cut = block->in(); break; @@ -457,10 +473,10 @@ void TimeBasedWidget::SetPoint(Timeline::MovementMode m, const rational& time) } MultiUndoCommand* command = new MultiUndoCommand(); - TimelinePoints* points = viewer_node_->GetTimelinePoints(); + TimelineWorkArea* points = viewer_node_->GetWorkArea(); // Enable workarea if it isn't already enabled - if (!points->workarea()->enabled()) { + if (!points->enabled()) { command->add_child(new WorkareaSetEnabledCommand(viewer_node_->project(), points, true)); } @@ -470,23 +486,23 @@ void TimeBasedWidget::SetPoint(Timeline::MovementMode m, const rational& time) if (m == Timeline::kTrimIn) { in_point = time; - if (!points->workarea()->enabled() || points->workarea()->out() < in_point) { + if (!points->enabled() || points->out() < in_point) { out_point = TimelineWorkArea::kResetOut; } else { - out_point = points->workarea()->out(); + out_point = points->out(); } } else { out_point = time; - if (!points->workarea()->enabled() || points->workarea()->in() > out_point) { + if (!points->enabled() || points->in() > out_point) { in_point = TimelineWorkArea::kResetIn; } else { - in_point = points->workarea()->in(); + in_point = points->in(); } } // Set workarea - command->add_child(new WorkareaSetRangeCommand(points->workarea(), TimeRange(in_point, out_point))); + command->add_child(new WorkareaSetRangeCommand(points, TimeRange(in_point, out_point))); Core::instance()->undo_stack()->push(command); } @@ -497,13 +513,13 @@ void TimeBasedWidget::ResetPoint(Timeline::MovementMode m) return; } - TimelinePoints* points = GetConnectedNode()->GetTimelinePoints(); + TimelineWorkArea* points = GetConnectedNode()->GetWorkArea(); - if (!GetConnectedNode() || !points->workarea()->enabled()) { + if (!points->enabled()) { return; } - TimeRange r = points->workarea()->range(); + TimeRange r = points->range(); if (m == Timeline::kTrimIn) { r.set_in(TimelineWorkArea::kResetIn); @@ -511,7 +527,7 @@ void TimeBasedWidget::ResetPoint(Timeline::MovementMode m) r.set_out(TimelineWorkArea::kResetOut); } - Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(points->workarea(), r)); + Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(points, r)); } void TimeBasedWidget::PageScrollInternal(QScrollBar *bar, int maximum, int screen_position, bool whole_page_scroll) @@ -582,8 +598,7 @@ void TimeBasedWidget::ClearInOutPoints() return; } - - Core::instance()->undo_stack()->push(new WorkareaSetEnabledCommand(GetConnectedNode()->project(), GetConnectedNode()->GetTimelinePoints(), false)); + Core::instance()->undo_stack()->push(new WorkareaSetEnabledCommand(GetConnectedNode()->project(), GetConnectedNode()->GetWorkArea(), false)); } void TimeBasedWidget::SetMarker() @@ -592,7 +607,7 @@ void TimeBasedWidget::SetMarker() return; } - TimelineMarkerList *markers = GetConnectedNode()->GetTimelinePoints()->markers(); + TimelineMarkerList *markers = GetConnectedNode()->GetMarkers(); if (TimelineMarker *existing = markers->GetMarkerAtTime(GetTime())) { // We already have a marker here, so pop open the edit dialog @@ -661,8 +676,8 @@ void TimeBasedWidget::ToggleShowAll() void TimeBasedWidget::GoToIn() { if (GetConnectedNode()) { - if (GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { - SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->in()); + if (GetConnectedNode()->GetWorkArea()->enabled()) { + SetTimeAndSignal(GetConnectedNode()->GetWorkArea()->in()); } else { GoToStart(); } @@ -672,8 +687,8 @@ void TimeBasedWidget::GoToIn() void TimeBasedWidget::GoToOut() { if (GetConnectedNode()) { - if (GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { - SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->out()); + if (GetConnectedNode()->GetWorkArea()->enabled()) { + SetTimeAndSignal(GetConnectedNode()->GetWorkArea()->out()); } else { GoToEnd(); } @@ -750,7 +765,7 @@ bool TimeBasedWidget::SnapPoint(const std::vector &start_times, ration // Snap to clip markers too if (ClipBlock *clip = dynamic_cast(b)) { if (clip->connected_viewer()) { - TimelineMarkerList *markers = clip->connected_viewer()->GetTimelinePoints()->markers(); + TimelineMarkerList *markers = clip->connected_viewer()->GetMarkers(); for (auto jt=markers->cbegin(); jt!=markers->cend(); jt++) { TimelineMarker *marker = *jt; @@ -768,8 +783,8 @@ bool TimeBasedWidget::SnapPoint(const std::vector &start_times, ration } } - if ((snap_points & kSnapToMarkers) && ruler()->GetTimelinePoints()) { - for (auto it=ruler()->GetTimelinePoints()->markers()->cbegin(); it!=ruler()->GetTimelinePoints()->markers()->cend(); it++) { + if ((snap_points & kSnapToMarkers) && ruler()->GetMarkers()) { + for (auto it=ruler()->GetMarkers()->cbegin(); it!=ruler()->GetMarkers()->cend(); it++) { TimelineMarker* m = *it; // Ignore selected markers @@ -787,9 +802,9 @@ bool TimeBasedWidget::SnapPoint(const std::vector &start_times, ration } } - if ((snap_points & kSnapToWorkarea) && ruler()->GetTimelinePoints()) { - const rational &workarea_in = ruler()->GetTimelinePoints()->workarea()->in(); - const rational &workarea_out = ruler()->GetTimelinePoints()->workarea()->out(); + if ((snap_points & kSnapToWorkarea) && ruler()->GetWorkArea()) { + const rational &workarea_in = ruler()->GetWorkArea()->in(); + const rational &workarea_out = ruler()->GetWorkArea()->out(); AttemptSnap(potential_snaps, screen_pt, TimeToScene(workarea_in), start_times, workarea_in); AttemptSnap(potential_snaps, screen_pt, TimeToScene(workarea_out), start_times, workarea_out); diff --git a/app/widget/timebased/timebasedwidget.h b/app/widget/timebased/timebasedwidget.h index 82924160f..509e8f8b9 100644 --- a/app/widget/timebased/timebasedwidget.h +++ b/app/widget/timebased/timebasedwidget.h @@ -50,6 +50,11 @@ public: void ConnectViewerNode(ViewerOutput *node); + TimelineWorkArea *GetConnectedWorkArea() const { return workarea_; } + TimelineMarkerList *GetConnectedMarkers() const { return markers_; } + void ConnectWorkArea(TimelineWorkArea *workarea); + void ConnectMarkers(TimelineMarkerList *markers); + void SetScaleAndCenterOnPlayhead(const double& scale); TimeRuler* ruler() const; @@ -130,6 +135,9 @@ protected: virtual void ConnectedNodeChangeEvent(ViewerOutput*){} + virtual void ConnectedWorkAreaChangeEvent(TimelineWorkArea *){} + virtual void ConnectedMarkersChangeEvent(TimelineMarkerList *){} + virtual void ConnectNodeEvent(ViewerOutput*){} virtual void DisconnectNodeEvent(ViewerOutput*){} @@ -217,6 +225,9 @@ private: double scrollbar_start_scale_; bool scrollbar_top_handle_; + TimelineWorkArea *workarea_; + TimelineMarkerList *markers_; + private slots: void UpdateMaximumScroll(); diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index aeb1a0678..caffc39de 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -638,7 +638,7 @@ void TimelineWidget::PasteInsert() void TimelineWidget::DeleteInToOut(bool ripple) { if (!GetConnectedNode() - || !GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { + || !GetConnectedNode()->GetWorkArea()->enabled()) { return; } @@ -648,8 +648,8 @@ void TimelineWidget::DeleteInToOut(bool ripple) command->add_child(new TimelineRippleRemoveAreaCommand( sequence(), - GetConnectedNode()->GetTimelinePoints()->workarea()->in(), - GetConnectedNode()->GetTimelinePoints()->workarea()->out())); + GetConnectedNode()->GetWorkArea()->in(), + GetConnectedNode()->GetWorkArea()->out())); } else { QVector unlocked_tracks = sequence()->GetUnlockedTracks(); @@ -657,7 +657,7 @@ void TimelineWidget::DeleteInToOut(bool ripple) foreach (Track* track, unlocked_tracks) { GapBlock* gap = new GapBlock(); - gap->set_length_and_media_out(GetConnectedNode()->GetTimelinePoints()->workarea()->length()); + gap->set_length_and_media_out(GetConnectedNode()->GetWorkArea()->length()); command->add_child(new NodeAddCommand(static_cast(track->parent()), gap)); @@ -665,17 +665,17 @@ void TimelineWidget::DeleteInToOut(bool ripple) command->add_child(new TrackPlaceBlockCommand(sequence()->track_list(track->type()), track->Index(), gap, - GetConnectedNode()->GetTimelinePoints()->workarea()->in())); + GetConnectedNode()->GetWorkArea()->in())); } } // Clear workarea after this command->add_child(new WorkareaSetEnabledCommand(GetConnectedNode()->project(), - GetConnectedNode()->GetTimelinePoints(), + GetConnectedNode()->GetWorkArea(), false)); if (ripple) { - SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->in()); + SetTimeAndSignal(GetConnectedNode()->GetWorkArea()->in()); } Core::instance()->undo_stack()->push(command); diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index bc1a5590a..3914e137f 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -231,7 +231,7 @@ void ImportTool::FootageToGhosts(rational ghost_start, const DraggedFootageData rational footage_duration; rational ghost_in; - TimelineWorkArea* wk = footage->GetTimelinePoints()->workarea(); + TimelineWorkArea* wk = footage->GetWorkArea(); if (wk->enabled()) { footage_duration = wk->length(); ghost_in = wk->in(); diff --git a/app/widget/timelinewidget/undo/timelineundoworkarea.h b/app/widget/timelinewidget/undo/timelineundoworkarea.h index b953fafa7..f83601747 100644 --- a/app/widget/timelinewidget/undo/timelineundoworkarea.h +++ b/app/widget/timelinewidget/undo/timelineundoworkarea.h @@ -22,16 +22,15 @@ #define TIMELINEUNDOWORKAREA_H #include "node/project/project.h" -#include "timeline/timelinepoints.h" namespace olive { class WorkareaSetEnabledCommand : public UndoCommand { public: - WorkareaSetEnabledCommand(Project *project, TimelinePoints* points, bool enabled) : + WorkareaSetEnabledCommand(Project *project, TimelineWorkArea* points, bool enabled) : project_(project), points_(points), - old_enabled_(points_->workarea()->enabled()), + old_enabled_(points_->enabled()), new_enabled_(enabled) { } @@ -44,18 +43,18 @@ public: protected: virtual void redo() override { - points_->workarea()->set_enabled(new_enabled_); + points_->set_enabled(new_enabled_); } virtual void undo() override { - points_->workarea()->set_enabled(old_enabled_); + points_->set_enabled(old_enabled_); } private: Project* project_; - TimelinePoints* points_; + TimelineWorkArea* points_; bool old_enabled_; diff --git a/app/widget/timelinewidget/view/timelineview.cpp b/app/widget/timelinewidget/view/timelineview.cpp index d3ee50c04..7c76ba37a 100644 --- a/app/widget/timelinewidget/view/timelineview.cpp +++ b/app/widget/timelinewidget/view/timelineview.cpp @@ -547,7 +547,7 @@ void TimelineView::DrawBlock(QPainter *painter, bool foreground, Block *block, q } } - TimelineMarkerList *marker_list = clip->connected_viewer()->GetTimelinePoints()->markers(); + TimelineMarkerList *marker_list = clip->connected_viewer()->GetMarkers(); if (!marker_list->empty()) { clip_marker_rects_.clear(); diff --git a/app/widget/timeruler/seekablewidget.cpp b/app/widget/timeruler/seekablewidget.cpp index 45cfb9717..5f130485f 100644 --- a/app/widget/timeruler/seekablewidget.cpp +++ b/app/widget/timeruler/seekablewidget.cpp @@ -41,7 +41,8 @@ namespace olive { SeekableWidget::SeekableWidget(QWidget* parent) : super(parent), - timeline_points_(nullptr), + markers_(nullptr), + workarea_(nullptr), dragging_(false), ignore_next_focus_out_(false), selection_manager_(this), @@ -63,26 +64,41 @@ SeekableWidget::SeekableWidget(QWidget* parent) : selection_manager_.SetSnapMask(TimeBasedWidget::kSnapAll); } -void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points) +void SeekableWidget::SetMarkers(TimelineMarkerList *markers) { - if (timeline_points_) { + if (markers_) { selection_manager_.ClearSelection(); - disconnect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, viewport(), static_cast(&QWidget::update)); - disconnect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, viewport(), static_cast(&QWidget::update)); - disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, viewport(), static_cast(&QWidget::update)); - disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, viewport(), static_cast(&QWidget::update)); - disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerModified, viewport(), static_cast(&QWidget::update)); + disconnect(markers_, &TimelineMarkerList::MarkerAdded, viewport(), static_cast(&QWidget::update)); + disconnect(markers_, &TimelineMarkerList::MarkerRemoved, viewport(), static_cast(&QWidget::update)); + disconnect(markers_, &TimelineMarkerList::MarkerModified, viewport(), static_cast(&QWidget::update)); } - timeline_points_ = points; + markers_ = markers; - if (timeline_points_) { - connect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, viewport(), static_cast(&QWidget::update)); - connect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, viewport(), static_cast(&QWidget::update)); - connect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, viewport(), static_cast(&QWidget::update)); - connect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, viewport(), static_cast(&QWidget::update)); - connect(timeline_points_->markers(), &TimelineMarkerList::MarkerModified, viewport(), static_cast(&QWidget::update)); + if (markers_) { + connect(markers_, &TimelineMarkerList::MarkerAdded, viewport(), static_cast(&QWidget::update)); + connect(markers_, &TimelineMarkerList::MarkerRemoved, viewport(), static_cast(&QWidget::update)); + connect(markers_, &TimelineMarkerList::MarkerModified, viewport(), static_cast(&QWidget::update)); + } + + viewport()->update(); +} + +void SeekableWidget::SetWorkArea(TimelineWorkArea *workarea) +{ + if (workarea_) { + selection_manager_.ClearSelection(); + + disconnect(workarea_, &TimelineWorkArea::RangeChanged, viewport(), static_cast(&QWidget::update)); + disconnect(workarea_, &TimelineWorkArea::EnabledChanged, viewport(), static_cast(&QWidget::update)); + } + + workarea_ = workarea; + + if (workarea_) { + connect(workarea_, &TimelineWorkArea::RangeChanged, viewport(), static_cast(&QWidget::update)); + connect(workarea_, &TimelineWorkArea::EnabledChanged, viewport(), static_cast(&QWidget::update)); } viewport()->update(); @@ -139,11 +155,11 @@ bool SeekableWidget::PasteMarkers() m->set_time(m->time().in() - min); - if (TimelineMarker *existing = timeline_points_->markers()->GetMarkerAtTime(m->time().in())) { + if (TimelineMarker *existing = markers_->GetMarkerAtTime(m->time().in())) { command->add_child(new MarkerRemoveCommand(existing)); } - command->add_child(new MarkerAddCommand(timeline_points_->markers(), m)); + command->add_child(new MarkerAddCommand(markers_, m)); } Core::instance()->undo_stack()->push(command); @@ -187,7 +203,7 @@ void SeekableWidget::mouseMoveEvent(QMouseEvent *event) } else { SeekToScenePoint(scene.x()); } - } else if (timeline_points_) { + } else { // Look for resize points if (FindResizeHandle(event)) { setCursor(Qt::SizeHorCursor); @@ -238,6 +254,59 @@ void SeekableWidget::focusOutEvent(QFocusEvent *event) } } +void SeekableWidget::DrawMarkers(QPainter *p, int marker_bottom) +{ + selection_manager_.ClearDrawnObjects(); + + // Draw markers + if (markers_ && !markers_->empty() && marker_bottom > 0) { + int lim_left = GetLeftLimit(); + int lim_right = GetRightLimit(); + + for (auto it=markers_->cbegin(); it!=markers_->cend(); it++) { + TimelineMarker* marker = *it; + + int marker_right = TimeToScene(marker->time().out()); + if (marker_right < lim_left) { + continue; + } + + int marker_left = TimeToScene(marker->time().in()); + if (marker_left >= lim_right) { + break; + } + + QRect marker_rect = marker->Draw(p, QPoint(marker_left, marker_bottom), GetScale(), selection_manager_.IsSelected(marker)); + marker_top_ = marker_rect.top(); + selection_manager_.DeclareDrawnObject(marker, marker_rect); + } + } + + marker_bottom_ = marker_bottom; +} + +void SeekableWidget::DrawWorkArea(QPainter *p) +{ + // Draw in/out workarea + if (workarea_ && workarea_->enabled()) { + int lim_left = GetLeftLimit(); + int lim_right = GetRightLimit(); + + int workarea_left = qMax(qreal(lim_left), TimeToScene(workarea_->in())); + int workarea_right; + + if (workarea_->out() == TimelineWorkArea::kResetOut) { + workarea_right = lim_right; + } else { + workarea_right = qMin(qreal(lim_right), TimeToScene(workarea_->out())); + } + + QColor translucent_highlight = palette().highlight().color(); + translucent_highlight.setAlpha(96); + p->fillRect(workarea_left, 0, workarea_right - workarea_left, height(), translucent_highlight); + } +} + void SeekableWidget::DeselectAllMarkers() { selection_manager_.ClearSelection(); @@ -309,57 +378,6 @@ void SeekableWidget::SelectionManagerDeselectEvent(void *obj) viewport()->update(); } -void SeekableWidget::DrawTimelinePoints(QPainter* p, int marker_bottom) -{ - if (!GetTimelinePoints()) { - return; - } - - int lim_left = GetScroll(); - int lim_right = lim_left + width(); - - selection_manager_.ClearDrawnObjects(); - - // Draw in/out workarea - if (GetTimelinePoints()->workarea()->enabled()) { - int workarea_left = qMax(qreal(lim_left), TimeToScene(GetTimelinePoints()->workarea()->in())); - int workarea_right; - - if (GetTimelinePoints()->workarea()->out() == TimelineWorkArea::kResetOut) { - workarea_right = lim_right; - } else { - workarea_right = qMin(qreal(lim_right), TimeToScene(GetTimelinePoints()->workarea()->out())); - } - - QColor translucent_highlight = palette().highlight().color(); - translucent_highlight.setAlpha(96); - p->fillRect(workarea_left, 0, workarea_right - workarea_left, height(), translucent_highlight); - } - - // Draw markers - if (marker_bottom > 0 && !GetTimelinePoints()->markers()->empty()) { - for (auto it=GetTimelinePoints()->markers()->cbegin(); it!=GetTimelinePoints()->markers()->cend(); it++) { - TimelineMarker* marker = *it; - - int marker_right = TimeToScene(marker->time().out()); - if (marker_right < lim_left) { - continue; - } - - int marker_left = TimeToScene(marker->time().in()); - if (marker_left >= lim_right) { - break; - } - - QRect marker_rect = marker->Draw(p, QPoint(marker_left, marker_bottom), GetScale(), selection_manager_.IsSelected(marker)); - marker_top_ = marker_rect.top(); - selection_manager_.DeclareDrawnObject(marker, marker_rect); - } - } - - marker_bottom_ = marker_bottom; -} - void SeekableWidget::DrawPlayhead(QPainter *p, int x, int y) { int half_width = playhead_width_ / 2; @@ -389,6 +407,16 @@ void SeekableWidget::DrawPlayhead(QPainter *p, int x, int y) p->setRenderHint(QPainter::Antialiasing, false); } +int SeekableWidget::GetLeftLimit() const +{ + return GetScroll(); +} + +int SeekableWidget::GetRightLimit() const +{ + return GetLeftLimit() + width(); +} + bool SeekableWidget::ShowContextMenu(const QPoint &p) { if (selection_manager_.GetObjectAtPoint(p) && !selection_manager_.GetSelectedObjects().empty()) { @@ -427,32 +455,38 @@ bool SeekableWidget::FindResizeHandle(QMouseEvent *event) rational max = SceneToTimeNoGrid(scene.x() + border); // Test for workarea - if (timeline_points_->workarea()->in() >= min && timeline_points_->workarea()->in() < max) { - resize_mode_ = kResizeIn; - } else if (timeline_points_->workarea()->out() >= min && timeline_points_->workarea()->out() < max) { - resize_mode_ = kResizeOut; + if (workarea_) { + if (workarea_->in() >= min && workarea_->in() < max) { + resize_mode_ = kResizeIn; + } else if (workarea_->out() >= min && workarea_->out() < max) { + resize_mode_ = kResizeOut; + } } if (resize_mode_ != kResizeNone) { - resize_item_ = timeline_points_->workarea(); - resize_item_range_ = timeline_points_->workarea()->range(); - resize_snap_mask_ = TimeBasedWidget::kSnapAll & ~TimeBasedWidget::kSnapToWorkarea; + if (workarea_) { + resize_item_ = workarea_; + resize_item_range_ = workarea_->range(); + resize_snap_mask_ = TimeBasedWidget::kSnapAll & ~TimeBasedWidget::kSnapToWorkarea; + } } else if (event->pos().y() >= marker_top_ && event->pos().y() < marker_bottom_) { - // Check for markers - for (auto it=timeline_points_->markers()->cbegin(); it!=timeline_points_->markers()->cend(); it++) { - TimelineMarker *m = *it; - if (m->time().in() != m->time().out()) { - if (m->time().in() >= min && m->time().in() < max) { - resize_mode_ = kResizeIn; - } else if (m->time().out() >= min && m->time().out() < max) { - resize_mode_ = kResizeOut; - } + if (markers_) { + // Check for markers + for (auto it=markers_->cbegin(); it!=markers_->cend(); it++) { + TimelineMarker *m = *it; + if (m->time().in() != m->time().out()) { + if (m->time().in() >= min && m->time().in() < max) { + resize_mode_ = kResizeIn; + } else if (m->time().out() >= min && m->time().out() < max) { + resize_mode_ = kResizeOut; + } - if (resize_mode_ != kResizeNone) { - resize_item_ = m; - resize_item_range_ = m->time(); - resize_snap_mask_ = TimeBasedWidget::kSnapAll; - break; + if (resize_mode_ != kResizeNone) { + resize_item_ = m; + resize_item_range_ = m->time(); + resize_snap_mask_ = TimeBasedWidget::kSnapAll; + break; + } } } } diff --git a/app/widget/timeruler/seekablewidget.h b/app/widget/timeruler/seekablewidget.h index dc28e9dbe..d29686f8f 100644 --- a/app/widget/timeruler/seekablewidget.h +++ b/app/widget/timeruler/seekablewidget.h @@ -25,7 +25,6 @@ #include #include "common/rational.h" -#include "timeline/timelinepoints.h" #include "widget/menu/menu.h" #include "widget/timebased/timebasedviewselectionmanager.h" @@ -42,8 +41,11 @@ public: return horizontalScrollBar()->value(); } - TimelinePoints* GetTimelinePoints() const { return timeline_points_; } - void ConnectTimelinePoints(TimelinePoints* points); + TimelineMarkerList *GetMarkers() const { return markers_; } + TimelineWorkArea *GetWorkArea() const { return workarea_; } + + void SetMarkers(TimelineMarkerList *markers); + void SetWorkArea(TimelineWorkArea *workarea); bool IsDraggingPlayhead() const { @@ -84,7 +86,8 @@ protected: virtual void focusOutEvent(QFocusEvent *event) override; - void DrawTimelinePoints(QPainter *p, int marker_bottom = 0); + void DrawMarkers(QPainter *p, int marker_bottom = 0); + void DrawWorkArea(QPainter *p); void DrawPlayhead(QPainter* p, int x, int y); @@ -96,6 +99,9 @@ protected: return playhead_width_; } + int GetLeftLimit() const; + int GetRightLimit() const; + protected slots: virtual bool ShowContextMenu(const QPoint &p); @@ -112,7 +118,8 @@ private: void CommitResizeHandle(); - TimelinePoints* timeline_points_; + TimelineMarkerList* markers_; + TimelineWorkArea* workarea_; int text_height_; diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index 642e160df..39d356006 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -103,9 +103,8 @@ void TimeRuler::drawForeground(QPainter *p, const QRectF &rect) // Draw timeline points if connected int marker_height = TimelineMarker::GetMarkerHeight(p->fontMetrics()); - if (GetTimelinePoints()) { - DrawTimelinePoints(p, marker_height); - } + DrawMarkers(p, marker_height); + DrawWorkArea(p); double width_of_frame = timebase_dbl() * GetScale(); double width_of_second = 0; diff --git a/app/widget/viewer/audiowaveformview.cpp b/app/widget/viewer/audiowaveformview.cpp index 92dc7e500..073edc0d8 100644 --- a/app/widget/viewer/audiowaveformview.cpp +++ b/app/widget/viewer/audiowaveformview.cpp @@ -82,7 +82,8 @@ void AudioWaveformView::drawForeground(QPainter *p, const QRectF &rect) } // Draw in/out points - DrawTimelinePoints(p); + DrawWorkArea(p); + DrawMarkers(p); // Draw waveform p->setPen(QColor(64, 255, 160)); // FIXME: Hardcoded color diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index f9bf5a8e0..82c3a2459 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -233,7 +233,6 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n) UpdateWaveformViewFromMode(); waveform_view_->SetViewer(GetConnectedNode()->audio_playback_cache()); - waveform_view_->ConnectTimelinePoints(GetConnectedNode()->GetTimelinePoints()); UpdateRendererVideoParameters(); UpdateRendererAudioParameters(); @@ -270,7 +269,6 @@ void ViewerWidget::DisconnectNodeEvent(ViewerOutput *n) } waveform_view_->SetViewer(nullptr); - waveform_view_->ConnectTimelinePoints(nullptr); // Queue an UpdateStack so that when it runs, the viewer node will be fully disconnected QMetaObject::invokeMethod(this, &ViewerWidget::UpdateWaveformViewFromMode, Qt::QueuedConnection); @@ -284,6 +282,16 @@ void ViewerWidget::ConnectedNodeChangeEvent(ViewerOutput *n) display_widget_->SetSubtitleTracks(dynamic_cast(n)); } +void ViewerWidget::ConnectedWorkAreaChangeEvent(TimelineWorkArea *workarea) +{ + waveform_view_->SetWorkArea(workarea); +} + +void ViewerWidget::ConnectedMarkersChangeEvent(TimelineMarkerList *markers) +{ + waveform_view_->SetMarkers(markers); +} + void ViewerWidget::ScaleChangedEvent(const double &s) { super::ScaleChangedEvent(s); @@ -379,8 +387,8 @@ void ViewerWidget::CacheEntireSequence() void ViewerWidget::CacheSequenceInOut() { - if (GetConnectedNode() && GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { - auto_cacher_.ForceCacheRange(GetConnectedNode()->GetTimelinePoints()->workarea()->range()); + if (GetConnectedNode() && GetConnectedNode()->GetWorkArea()->enabled()) { + auto_cacher_.ForceCacheRange(GetConnectedNode()->GetWorkArea()->range()); } else { QMessageBox::warning(this, tr("Error"), @@ -1314,9 +1322,9 @@ void ViewerWidget::Play(bool in_to_out_only) { if (in_to_out_only) { if (GetConnectedNode() - && GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { + && GetConnectedNode()->GetWorkArea()->enabled()) { // Jump to in point - SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->in()); + SetTimeAndSignal(GetConnectedNode()->GetWorkArea()->in()); } else { in_to_out_only = false; } @@ -1444,11 +1452,11 @@ void ViewerWidget::PlaybackTimerUpdate() min_time = recording_range_.in(); max_time = recording_range_.out(); - } else if (play_in_to_out_only_ && GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { + } else if (play_in_to_out_only_ && GetConnectedNode()->GetWorkArea()->enabled()) { // If "play in to out" is enabled or we're looping AND we have a workarea, only play the workarea - min_time = GetConnectedNode()->GetTimelinePoints()->workarea()->in(); - max_time = GetConnectedNode()->GetTimelinePoints()->workarea()->out(); + min_time = GetConnectedNode()->GetWorkArea()->in(); + max_time = GetConnectedNode()->GetWorkArea()->out(); } else { diff --git a/app/widget/viewer/viewer.h b/app/widget/viewer/viewer.h index d38ef5316..f1aefcb85 100644 --- a/app/widget/viewer/viewer.h +++ b/app/widget/viewer/viewer.h @@ -163,6 +163,8 @@ protected: virtual void ConnectNodeEvent(ViewerOutput *) override; virtual void DisconnectNodeEvent(ViewerOutput *) override; virtual void ConnectedNodeChangeEvent(ViewerOutput *) override; + virtual void ConnectedWorkAreaChangeEvent(TimelineWorkArea *) override; + virtual void ConnectedMarkersChangeEvent(TimelineMarkerList *) override; virtual void ScaleChangedEvent(const double& s) override;