diff --git a/app/widget/curvewidget/curvewidget.cpp b/app/widget/curvewidget/curvewidget.cpp index 75d481ad9..b8dcd1a1d 100644 --- a/app/widget/curvewidget/curvewidget.cpp +++ b/app/widget/curvewidget/curvewidget.cpp @@ -89,7 +89,6 @@ CurveWidget::CurveWidget(QWidget *parent) : ruler_view_layout->addWidget(ruler()); view_ = new CurveView(); - connect(view_, &CurveView::RequestCenterScrollOnPlayhead, this, &CurveWidget::CenterScrollOnPlayhead); ConnectTimelineView(view_); ruler_view_layout->addWidget(view_); diff --git a/app/widget/nodeparamview/nodeparamview.cpp b/app/widget/nodeparamview/nodeparamview.cpp index 2a734a718..597ef7d61 100644 --- a/app/widget/nodeparamview/nodeparamview.cpp +++ b/app/widget/nodeparamview/nodeparamview.cpp @@ -85,7 +85,6 @@ NodeParamView::NodeParamView(QWidget *parent) : keyframe_view_ = new KeyframeView(); keyframe_view_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ConnectTimelineView(keyframe_view_); - connect(keyframe_view_, &KeyframeView::RequestCenterScrollOnPlayhead, this, &NodeParamView::CenterScrollOnPlayhead); keyframe_area_layout->addWidget(keyframe_view_); // Connect ruler and keyframe view together diff --git a/app/widget/timebased/timebased.cpp b/app/widget/timebased/timebased.cpp index ea894768e..6d09dfe8b 100644 --- a/app/widget/timebased/timebased.cpp +++ b/app/widget/timebased/timebased.cpp @@ -23,6 +23,7 @@ #include #include +#include "common/autoscroll.h" #include "common/timecodefunctions.h" #include "config/config.h" #include "core.h" @@ -155,6 +156,22 @@ void TimeBasedWidget::ScrollBarResized(const double &multiplier) SetScale(GetScale() * corrected_scale); } +void TimeBasedWidget::PageScrollToPlayhead() +{ + int playhead_pos = qRound(TimeToScene(GetTime())); + + int viewport_width = ruler()->width(); + int viewport_padding = viewport_width / 16; + + if (playhead_pos < scrollbar()->value()) { + // Anchor the playhead to the RIGHT of where we scroll to + scrollbar()->setValue(playhead_pos - viewport_width + viewport_padding); + } else if (playhead_pos > scrollbar()->value() + viewport_width) { + // Anchor the playhead to the LEFT of where we scroll to + scrollbar()->setValue(playhead_pos - viewport_padding); + } +} + TimeRuler *TimeBasedWidget::ruler() const { return ruler_; @@ -224,6 +241,18 @@ void TimeBasedWidget::SetTimestamp(int64_t timestamp) { ruler_->SetTime(timestamp); + switch (static_cast(Config::Current()["Autoscroll"].toInt())) { + case AutoScroll::kNone: + // Do nothing + break; + case AutoScroll::kPage: + QMetaObject::invokeMethod(this, "PageScrollToPlayhead", Qt::QueuedConnection); + break; + case AutoScroll::kSmooth: + QMetaObject::invokeMethod(this, "CenterScrollOnPlayhead", Qt::QueuedConnection); + break; + } + TimeChangedEvent(timestamp); } diff --git a/app/widget/timebased/timebased.h b/app/widget/timebased/timebased.h index 6fdfad8e0..2689feba4 100644 --- a/app/widget/timebased/timebased.h +++ b/app/widget/timebased/timebased.h @@ -204,6 +204,14 @@ private slots: void ScrollBarResized(const double& multiplier); + /** + * @brief Slot to handle page scrolling of the playhead + * + * If the playhead is outside the current scroll bounds, this function will scroll to where it is. Otherwise it will + * do nothing. + */ + void PageScrollToPlayhead(); + }; } diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index 51360ce7c..86d5856d4 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -131,7 +131,6 @@ TimelineWidget::TimelineWidget(QWidget *parent) : connect(view, &TimelineView::customContextMenuRequested, this, &TimelineWidget::ShowContextMenu); connect(scrollbar(), &QScrollBar::valueChanged, view->horizontalScrollBar(), &QScrollBar::setValue); connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, scrollbar(), &QScrollBar::setValue); - connect(view, &TimelineView::RequestCenterScrollOnPlayhead, this, &TimelineWidget::CenterScrollOnPlayhead); connect(view, &TimelineView::MousePressed, this, &TimelineWidget::ViewMousePressed); connect(view, &TimelineView::MouseMoved, this, &TimelineWidget::ViewMouseMoved); diff --git a/app/widget/timelinewidget/view/timelineviewbase.cpp b/app/widget/timelinewidget/view/timelineviewbase.cpp index 45a836b64..a252a867a 100644 --- a/app/widget/timelinewidget/view/timelineviewbase.cpp +++ b/app/widget/timelinewidget/view/timelineviewbase.cpp @@ -25,7 +25,6 @@ #include #include -#include "common/autoscroll.h" #include "common/timecodefunctions.h" #include "config/config.h" @@ -115,18 +114,6 @@ void TimelineViewBase::SetTime(const int64_t time) { playhead_ = time; - switch (static_cast(Config::Current()["Autoscroll"].toInt())) { - case AutoScroll::kNone: - // Do nothing - break; - case AutoScroll::kPage: - QMetaObject::invokeMethod(this, "PageScrollToPlayhead", Qt::QueuedConnection); - break; - case AutoScroll::kSmooth: - emit RequestCenterScrollOnPlayhead(); - break; - } - // Force redraw for playhead viewport()->update(); } @@ -257,21 +244,6 @@ void TimelineViewBase::UpdateSceneRect() } } -void TimelineViewBase::PageScrollToPlayhead() -{ - int playhead_pos = qRound(GetPlayheadX()); - - int viewport_padding = viewport()->width() / 16; - - if (playhead_pos < horizontalScrollBar()->value()) { - // Anchor the playhead to the RIGHT of where we scroll to - horizontalScrollBar()->setValue(playhead_pos - viewport()->width() + viewport_padding); - } else if (playhead_pos > horizontalScrollBar()->value() + viewport()->width()) { - // Anchor the playhead to the LEFT of where we scroll to - horizontalScrollBar()->setValue(playhead_pos - viewport_padding); - } -} - void TimelineViewBase::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); diff --git a/app/widget/timelinewidget/view/timelineviewbase.h b/app/widget/timelinewidget/view/timelineviewbase.h index 1b14744e3..4ae847391 100644 --- a/app/widget/timelinewidget/view/timelineviewbase.h +++ b/app/widget/timelinewidget/view/timelineviewbase.h @@ -60,8 +60,6 @@ signals: void ScaleChanged(double scale); - void RequestCenterScrollOnPlayhead(); - protected: virtual void drawForeground(QPainter *painter, const QRectF &rect) override; @@ -124,14 +122,6 @@ private slots: */ void UpdateSceneRect(); - /** - * @brief Slot to handle page scrolling of the playhead - * - * If the playhead is outside the current scroll bounds, this function will scroll to where it is. Otherwise it will - * do nothing. - */ - void PageScrollToPlayhead(); - }; }