scroll only in increments when dragging the playhead
This commit is contained in:
@@ -52,6 +52,11 @@ public:
|
|||||||
|
|
||||||
static bool WheelEventIsAZoomEvent(QWheelEvent* event);
|
static bool WheelEventIsAZoomEvent(QWheelEvent* event);
|
||||||
|
|
||||||
|
bool IsDraggingPlayhead() const
|
||||||
|
{
|
||||||
|
return dragging_playhead_;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void SetTime(const int64_t time);
|
void SetTime(const int64_t time);
|
||||||
|
|
||||||
|
|||||||
@@ -183,18 +183,12 @@ void TimeBasedWidget::ScrollBarResizeMoved(int movement)
|
|||||||
|
|
||||||
void TimeBasedWidget::PageScrollToPlayhead()
|
void TimeBasedWidget::PageScrollToPlayhead()
|
||||||
{
|
{
|
||||||
int playhead_pos = qRound(TimeToScene(GetTime()));
|
PageScrollInternal(true);
|
||||||
|
}
|
||||||
|
|
||||||
int viewport_width = ruler()->width();
|
void TimeBasedWidget::CatchUpScrollToPlayhead()
|
||||||
int viewport_padding = viewport_width / 16;
|
{
|
||||||
|
PageScrollInternal(false);
|
||||||
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
|
TimeRuler *TimeBasedWidget::ruler() const
|
||||||
@@ -259,8 +253,13 @@ TimelinePoints *TimeBasedWidget::GetConnectedTimelinePoints() const
|
|||||||
return points_;
|
return points_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeBasedWidget::ConnectTimelineView(TimeBasedView *base)
|
void TimeBasedWidget::ConnectTimelineView(TimeBasedView *base, bool connect_time_change_event)
|
||||||
{
|
{
|
||||||
|
if (connect_time_change_event) {
|
||||||
|
connect(base, &TimeBasedView::TimeChanged, this, &TimeBasedWidget::SetTimestamp);
|
||||||
|
connect(base, &TimeBasedView::TimeChanged, this, &TimeBasedWidget::TimeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
timeline_views_.append(base);
|
timeline_views_.append(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,21 +271,29 @@ void TimeBasedWidget::PassWheelEventsToScrollBar(QObject *object)
|
|||||||
|
|
||||||
void TimeBasedWidget::SetTimestamp(int64_t timestamp)
|
void TimeBasedWidget::SetTimestamp(int64_t timestamp)
|
||||||
{
|
{
|
||||||
ruler_->SetTime(timestamp);
|
if (GetTime() != timestamp) {
|
||||||
|
if (UserIsDraggingPlayhead()) {
|
||||||
|
// If the user is dragging the playhead, we will simply nudge over and not use autoscroll rules.
|
||||||
|
QMetaObject::invokeMethod(this, "CatchUpScrollToPlayhead", Qt::QueuedConnection);
|
||||||
|
} else {
|
||||||
|
// Otherwise, assume we jumped to this out of nowhere and must now autoscroll
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (static_cast<AutoScroll::Method>(Config::Current()["Autoscroll"].toInt())) {
|
ruler_->SetTime(timestamp);
|
||||||
case AutoScroll::kNone:
|
|
||||||
// Do nothing
|
TimeChangedEvent(timestamp);
|
||||||
break;
|
|
||||||
case AutoScroll::kPage:
|
|
||||||
QMetaObject::invokeMethod(this, "PageScrollToPlayhead", Qt::QueuedConnection);
|
|
||||||
break;
|
|
||||||
case AutoScroll::kSmooth:
|
|
||||||
QMetaObject::invokeMethod(this, "CenterScrollOnPlayhead", Qt::QueuedConnection);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeChangedEvent(timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeBasedWidget::SetTimebase(const rational &timebase)
|
void TimeBasedWidget::SetTimebase(const rational &timebase)
|
||||||
@@ -474,6 +481,46 @@ void TimeBasedWidget::ResetPoint(Timeline::MovementMode m)
|
|||||||
Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(GetTimelinePointsProject(), points_, r));
|
Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(GetTimelinePointsProject(), points_, r));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimeBasedWidget::PageScrollInternal(bool whole_page_scroll)
|
||||||
|
{
|
||||||
|
int playhead_pos = qRound(TimeToScene(GetTime()));
|
||||||
|
|
||||||
|
int viewport_width = ruler()->width();
|
||||||
|
int viewport_padding = viewport_width / 16;
|
||||||
|
|
||||||
|
if (whole_page_scroll) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Just jump in increments
|
||||||
|
if (playhead_pos < scrollbar()->value() + viewport_padding) {
|
||||||
|
scrollbar()->setValue(scrollbar()->value() - viewport_padding);
|
||||||
|
} else if (playhead_pos > scrollbar()->value() + viewport_width - viewport_padding) {
|
||||||
|
scrollbar()->setValue(scrollbar()->value() + viewport_padding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TimeBasedWidget::UserIsDraggingPlayhead() const
|
||||||
|
{
|
||||||
|
if (ruler_->IsDraggingPlayhead()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (TimeBasedView* view, timeline_views_) {
|
||||||
|
if (view->IsDraggingPlayhead()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void TimeBasedWidget::SetInAtPlayhead()
|
void TimeBasedWidget::SetInAtPlayhead()
|
||||||
{
|
{
|
||||||
SetPoint(Timeline::kTrimIn, GetTime());
|
SetPoint(Timeline::kTrimIn, GetTime());
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ protected:
|
|||||||
|
|
||||||
TimelinePoints* GetConnectedTimelinePoints() const;
|
TimelinePoints* GetConnectedTimelinePoints() const;
|
||||||
|
|
||||||
void ConnectTimelineView(TimeBasedView* base);
|
void ConnectTimelineView(TimeBasedView* base, bool connect_time_change_event = true);
|
||||||
|
|
||||||
void PassWheelEventsToScrollBar(QObject* object);
|
void PassWheelEventsToScrollBar(QObject* object);
|
||||||
|
|
||||||
@@ -184,6 +184,10 @@ private:
|
|||||||
*/
|
*/
|
||||||
void ResetPoint(Timeline::MovementMode m);
|
void ResetPoint(Timeline::MovementMode m);
|
||||||
|
|
||||||
|
void PageScrollInternal(bool whole_page_scroll);
|
||||||
|
|
||||||
|
bool UserIsDraggingPlayhead() const;
|
||||||
|
|
||||||
ViewerOutput* viewer_node_;
|
ViewerOutput* viewer_node_;
|
||||||
|
|
||||||
TimeRuler* ruler_;
|
TimeRuler* ruler_;
|
||||||
@@ -225,6 +229,8 @@ private slots:
|
|||||||
*/
|
*/
|
||||||
void PageScrollToPlayhead();
|
void PageScrollToPlayhead();
|
||||||
|
|
||||||
|
void CatchUpScrollToPlayhead();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
|
|||||||
|
|
||||||
view_splitter_->addWidget(tview);
|
view_splitter_->addWidget(tview);
|
||||||
|
|
||||||
ConnectTimelineView(view);
|
ConnectTimelineView(view, false);
|
||||||
|
|
||||||
connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, ruler(), &TimeRuler::SetScroll);
|
connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, ruler(), &TimeRuler::SetScroll);
|
||||||
connect(view, &TimelineView::ScaleChanged, this, &TimelineWidget::SetScale);
|
connect(view, &TimelineView::ScaleChanged, this, &TimelineWidget::SetScale);
|
||||||
@@ -1012,9 +1012,7 @@ void TimelineWidget::ViewTimestampChanged(int64_t ts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update all other views
|
// Update all other views
|
||||||
SetViewTimestamp(ts);
|
SetTimestamp(ts);
|
||||||
|
|
||||||
ruler()->SetTime(ts);
|
|
||||||
emit TimeChanged(ts);
|
emit TimeChanged(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ SeekableWidget::SeekableWidget(QWidget* parent) :
|
|||||||
time_(0),
|
time_(0),
|
||||||
timeline_points_(nullptr),
|
timeline_points_(nullptr),
|
||||||
scroll_(0),
|
scroll_(0),
|
||||||
snap_service_(nullptr)
|
snap_service_(nullptr),
|
||||||
|
dragging_(false)
|
||||||
{
|
{
|
||||||
QFontMetrics fm = fontMetrics();
|
QFontMetrics fm = fontMetrics();
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ void SeekableWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
SeekToScreenPoint(event->pos().x());
|
SeekToScreenPoint(event->pos().x());
|
||||||
|
dragging_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +105,8 @@ void SeekableWidget::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
if (snap_service_) {
|
if (snap_service_) {
|
||||||
snap_service_->HideSnaps();
|
snap_service_->HideSnaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dragging_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeekableWidget::ScaleChangedEvent(const double &)
|
void SeekableWidget::ScaleChangedEvent(const double &)
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ public:
|
|||||||
|
|
||||||
void SetSnapService(SnapService* service);
|
void SetSnapService(SnapService* service);
|
||||||
|
|
||||||
|
bool IsDraggingPlayhead() const
|
||||||
|
{
|
||||||
|
return dragging_;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void SetTime(const int64_t &r);
|
void SetTime(const int64_t &r);
|
||||||
|
|
||||||
@@ -98,6 +103,8 @@ private:
|
|||||||
|
|
||||||
SnapService* snap_service_;
|
SnapService* snap_service_;
|
||||||
|
|
||||||
|
bool dragging_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user