From 3978a8501a0e3db041f2fcbedaaa2ad23bc5282d Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sun, 23 Oct 2022 22:28:35 -0700 Subject: [PATCH] timeline: implement select to seek and seek to select --- app/config/config.cpp | 2 +- .../tabs/preferencesbehaviortab.cpp | 2 +- app/widget/timelinewidget/timelinewidget.cpp | 41 +++++++++++++++++++ app/widget/timelinewidget/timelinewidget.h | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/config/config.cpp b/app/config/config.cpp index c9e814a16..56ea47a74 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -82,7 +82,7 @@ void Config::SetDefaults() SetEntryInternal(QStringLiteral("InvertTimelineScrollAxes"), NodeValue::kBoolean, true); SetEntryInternal(QStringLiteral("SelectAlsoSeeks"), NodeValue::kBoolean, false); SetEntryInternal(QStringLiteral("PasteSeeks"), NodeValue::kBoolean, true); - SetEntryInternal(QStringLiteral("SelectAlsoSeeks"), NodeValue::kBoolean, false); + SetEntryInternal(QStringLiteral("SeekAlsoSelects"), NodeValue::kBoolean, false); SetEntryInternal(QStringLiteral("SetNameWithMarker"), NodeValue::kBoolean, false); SetEntryInternal(QStringLiteral("AutoSeekToBeginning"), NodeValue::kBoolean, true); SetEntryInternal(QStringLiteral("DropFileOnMediaToReplace"), NodeValue::kBoolean, false); diff --git a/app/dialog/preferences/tabs/preferencesbehaviortab.cpp b/app/dialog/preferences/tabs/preferencesbehaviortab.cpp index df9917a84..6db150edc 100644 --- a/app/dialog/preferences/tabs/preferencesbehaviortab.cpp +++ b/app/dialog/preferences/tabs/preferencesbehaviortab.cpp @@ -73,7 +73,7 @@ PreferencesBehaviorTab::PreferencesBehaviorTab() tr("Hold ALT on any UI element to switch scrolling axes"), timeline_group); AddItem(tr("Seek Also Selects"), - QStringLiteral("SelectAlsoSeeks"), + QStringLiteral("SeekAlsoSelects"), timeline_group); AddItem(tr("Seek to the End of Pastes"), QStringLiteral("PasteSeeks"), diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index ed8dd84d8..507f417c6 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -198,6 +198,17 @@ TimelineWidget::TimelineWidget(QWidget *parent) : signal_block_change_timer_->setSingleShot(true); connect(signal_block_change_timer_, &QTimer::timeout, this, [this]{ signal_block_change_timer_->stop(); + + if (OLIVE_CONFIG("SelectAlsoSeeks").toBool()) { + rational start = RATIONAL_MAX; + for (Block *b : selected_blocks_) { + start = std::min(start, b->in()); + } + if (start != RATIONAL_MAX) { + GetConnectedNode()->SetPlayhead(start); + } + } + emit BlockSelectionChanged(selected_blocks_); }); } @@ -242,6 +253,36 @@ void TimelineWidget::resizeEvent(QResizeEvent *event) UpdateTimecodeWidthFromSplitters(views_.first()->splitter()); } +void TimelineWidget::TimeChangedEvent(const rational &t) +{ + if (OLIVE_CONFIG("SeekAlsoSelects").toBool()) { + TimelineWidgetSelections sels; + + QVector new_blocks; + + for (auto it=sequence()->GetTracks().cbegin(); it!=sequence()->GetTracks().cend(); it++) { + Track *track = *it; + if (track->IsLocked()) { + continue; + } + + Block *b = track->VisibleBlockAtTime(sequence()->GetPlayhead()); + if (!b || dynamic_cast(b)) { + continue; + } + + new_blocks.push_back(b); + sels[track->ToReference()].insert(b->range()); + } + + if (selected_blocks_ != new_blocks) { + selected_blocks_ = new_blocks; + SetSelections(sels, false); + SignalBlockSelectionChange(); + } + } +} + void TimelineWidget::ScaleChangedEvent(const double &scale) { super::ScaleChangedEvent(scale); diff --git a/app/widget/timelinewidget/timelinewidget.h b/app/widget/timelinewidget/timelinewidget.h index 74cf4d896..4a49bcfb7 100644 --- a/app/widget/timelinewidget/timelinewidget.h +++ b/app/widget/timelinewidget/timelinewidget.h @@ -290,6 +290,7 @@ signals: protected: virtual void resizeEvent(QResizeEvent *event) override; + virtual void TimeChangedEvent(const rational &) override; virtual void TimebaseChangedEvent(const rational &) override; virtual void ScaleChangedEvent(const double &) override;