Skip to content

Commit

Permalink
Better timeline UX
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rodlie committed Aug 19, 2023
1 parent 26af22a commit 1c9ae09
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/GUI/BoxesList/OptimalScrollArea/scrollarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions src/app/GUI/animationwidgetscrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/GUI/animationwidgetscrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
2 changes: 2 additions & 0 deletions src/app/GUI/timelinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit 1c9ae09

Please sign in to comment.