From 1c9ae095d60cff1b190dfd3cb161f71169d8e893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Sat, 19 Aug 2023 18:31:02 +0200 Subject: [PATCH] Better timeline UX Scrolling on the timeline now supports modifiers CTRL and SHIFT. * CTRL + wheel will now scale in/out the frame range as if you used the scrollbar * SHIFT + wheel will now pan the frame range as if you used the scrollbar * Without a modifier it works as before, scroll up/down See https://github.com/orgs/friction2d/discussions/58#discussioncomment-6769336 --- .../OptimalScrollArea/scrollarea.cpp | 6 +++-- src/app/GUI/animationwidgetscrollbar.cpp | 25 +++++++++++++++++++ src/app/GUI/animationwidgetscrollbar.h | 2 ++ src/app/GUI/timelinewidget.cpp | 2 ++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/app/GUI/BoxesList/OptimalScrollArea/scrollarea.cpp b/src/app/GUI/BoxesList/OptimalScrollArea/scrollarea.cpp index c55a3af37..2c328379b 100755 --- a/src/app/GUI/BoxesList/OptimalScrollArea/scrollarea.cpp +++ b/src/app/GUI/BoxesList/OptimalScrollArea/scrollarea.cpp @@ -58,8 +58,10 @@ void ScrollArea::resizeEvent(QResizeEvent *e) { QScrollArea::resizeEvent(e); } #include "GUI/global.h" -void ScrollArea::callWheelEvent(QWheelEvent *event) { - if(event->angleDelta().y() > 0) { +void ScrollArea::callWheelEvent(QWheelEvent *event) +{ + if (event->modifiers() & Qt::CTRL || event->modifiers() & Qt::SHIFT) { return; } + if (event->angleDelta().y() > 0) { scrollBy(0, -eSizesUI::widget); } else { scrollBy(0, eSizesUI::widget); diff --git a/src/app/GUI/animationwidgetscrollbar.cpp b/src/app/GUI/animationwidgetscrollbar.cpp index d3bfbb720..a57c0255a 100755 --- a/src/app/GUI/animationwidgetscrollbar.cpp +++ b/src/app/GUI/animationwidgetscrollbar.cpp @@ -304,6 +304,31 @@ void FrameScrollBar::setCanvasFrameRange(const FrameRange &range) { update(); } +void FrameScrollBar::callWheelEvent(QWheelEvent *event) +{ + if (!mRange) { return; } + bool triggered = false; + if (event->modifiers() & Qt::CTRL) { + int newFramesSpan = mViewedFramesSpan; + if (event->angleDelta().y() > 0) { newFramesSpan *= 0.85; } + else { newFramesSpan *= 1.15; } + setFramesSpan(newFramesSpan); + triggered = true; + } else if (event->modifiers() & Qt::SHIFT) { + if (event->angleDelta().y() > 0) { + setFirstViewedFrame(mFirstViewedFrame - mViewedFramesSpan/20); + triggered = true; + } else { + setFirstViewedFrame(mFirstViewedFrame + mViewedFramesSpan/20); + triggered = true; + } + } + if (!triggered) { return; } + + emitTriggeredChange(); + update(); +} + void FrameScrollBar::emitChange() { emit frameRangeChange(getViewedRange()); } diff --git a/src/app/GUI/animationwidgetscrollbar.h b/src/app/GUI/animationwidgetscrollbar.h index 7c161ac1d..283e1a6bb 100755 --- a/src/app/GUI/animationwidgetscrollbar.h +++ b/src/app/GUI/animationwidgetscrollbar.h @@ -59,6 +59,8 @@ class FrameScrollBar : public QWidget { void setDisplayedFrameRange(const FrameRange& range); void setViewedFrameRange(const FrameRange& range); void setCanvasFrameRange(const FrameRange& range); + void callWheelEvent(QWheelEvent *event); + protected: qreal posToFrame(int xPos); void paintEvent(QPaintEvent *); diff --git a/src/app/GUI/timelinewidget.cpp b/src/app/GUI/timelinewidget.cpp index 0e0def452..5842bf7b5 100755 --- a/src/app/GUI/timelinewidget.cpp +++ b/src/app/GUI/timelinewidget.cpp @@ -284,6 +284,8 @@ TimelineWidget::TimelineWidget(Document &document, connect(mFrameRangeScrollBar, &FrameScrollBar::triggeredFrameRangeChange, this, &TimelineWidget::setViewedFrameRange); + connect(mKeysView, &KeysView::wheelEventSignal, + mFrameRangeScrollBar, &FrameScrollBar::callWheelEvent); mKeysViewLayout->addWidget(mFrameRangeScrollBar); //mSceneChooser->setCurrentScene(mDocument.fActiveScene); // why?