moved autoscroll code to TimeBasedWidget rather than TimelineViewBase
Better place for it. Fixes #1406
This commit is contained in:
@@ -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_);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <QInputDialog>
|
||||
#include <QUndoCommand>
|
||||
|
||||
#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<AutoScroll::Method>(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
|
||||
#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<AutoScroll::Method>(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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user