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:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user