timebasedwidget: rewrote scroll catchup code

Code is much better. Less hacky queuing, implements cooldowns to improve navigation, and introduces a framework so that subclasses can make use of catchup/cooldown code too with any scrollbar they want
This commit is contained in:
itsmattkc
2022-07-15 10:59:51 -07:00
parent 4b8febd10d
commit e4fd2d5d2c
11 changed files with 103 additions and 20 deletions
+43
View File
@@ -52,6 +52,10 @@ TimeBasedWidget::TimeBasedWidget(bool ruler_text_visible, bool ruler_cache_statu
connect(scrollbar_, &ResizableScrollBar::ResizeMoved, this, &TimeBasedWidget::ScrollBarResizeMoved);
PassWheelEventsToScrollBar(ruler_);
catchup_scroll_timer_ = new QTimer(this);
catchup_scroll_timer_->setInterval(250); // Hardcoded 1/4 scroll limit value
connect(catchup_scroll_timer_, &QTimer::timeout, this, &TimeBasedWidget::CatchUpTimerTimeout);
}
void TimeBasedWidget::SetScaleAndCenterOnPlayhead(const double &scale)
@@ -217,6 +221,15 @@ void TimeBasedWidget::CatchUpScrollToPoint(int point)
PageScrollInternal(point, false);
}
void TimeBasedWidget::CatchUpTimerTimeout()
{
for (auto it=catchup_scroll_values_.cbegin(); it!=catchup_scroll_values_.cend(); it++) {
QScrollBar *sb = it.key();
const CatchUpScrollData &d = it.value();
PageScrollInternal(sb, d.maximum, sb->value() + d.value, false);
}
}
void TimeBasedWidget::AutoUpdateTimebase()
{
rational video_tb = viewer_node_->GetVideoParams().frame_rate_as_time_base();
@@ -301,6 +314,36 @@ void TimeBasedWidget::PassWheelEventsToScrollBar(QObject *object)
object->installEventFilter(this);
}
void TimeBasedWidget::SetCatchUpScrollValue(QScrollBar *b, int v, int maximum)
{
CatchUpScrollData &cudata = catchup_scroll_values_[b];
cudata.value = v;
cudata.maximum = maximum;
static const qint64 min_cooldown = 100; // Hardcoded 1/10 sec cooldown
if (QDateTime::currentMSecsSinceEpoch() - cudata.last_forced >= min_cooldown) {
QMetaObject::invokeMethod(this, &TimeBasedWidget::CatchUpTimerTimeout, Qt::QueuedConnection);
cudata.last_forced = QDateTime::currentMSecsSinceEpoch();
}
if (!catchup_scroll_timer_->isActive()) {
catchup_scroll_timer_->start();
}
}
void TimeBasedWidget::SetCatchUpScrollValue(int v)
{
SetCatchUpScrollValue(scrollbar_, v, ruler()->width());
}
void TimeBasedWidget::StopCatchUpScrollTimer(QScrollBar *b)
{
catchup_scroll_values_.remove(b);
if (catchup_scroll_values_.empty()) {
catchup_scroll_timer_->stop();
}
}
void TimeBasedWidget::SetTime(const rational &time)
{
if (UserIsDraggingPlayhead()) {
+18
View File
@@ -150,6 +150,14 @@ protected:
void PassWheelEventsToScrollBar(QObject* object);
void SetCatchUpScrollValue(QScrollBar *b, int v, int maximum);
void SetCatchUpScrollValue(int v);
void StopCatchUpScrollTimer(QScrollBar *b);
void StopCatchUpScrollTimer()
{
StopCatchUpScrollTimer(scrollbar_);
}
virtual const QVector<Block*> *GetSnapBlocks() const { return nullptr; }
virtual const QVector<KeyframeViewInputConnection*> *GetSnapKeyframes() const { return nullptr; }
virtual const std::vector<NodeKeyframe*> *GetSnapIgnoreKeyframes() const { return nullptr; }
@@ -228,6 +236,14 @@ private:
TimelineWorkArea *workarea_;
TimelineMarkerList *markers_;
QTimer *catchup_scroll_timer_;
struct CatchUpScrollData {
qint64 last_forced = 0;
int maximum;
int value;
};
QMap<QScrollBar*, CatchUpScrollData> catchup_scroll_values_;
private slots:
void UpdateMaximumScroll();
@@ -247,6 +263,8 @@ private slots:
void CatchUpScrollToPoint(int point);
void CatchUpTimerTimeout();
void AutoUpdateTimebase();
void ConnectedNodeRemovedFromGraph();