From 2a1838467a0511bde339c8a86613ed43317e4207 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 15 Feb 2019 04:09:03 -0800 Subject: [PATCH] scrolling update --- panels/timeline.cpp | 4 ++-- panels/timeline.h | 5 ++-- ui/focusfilter.cpp | 4 ++-- ui/scrollarea.cpp | 7 +++++- ui/timelinewidget.cpp | 53 +++++++++++++++++++++++++++++++------------ 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 3289a6866..7ba0a335c 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -752,11 +752,11 @@ QVector Timeline::get_tracks_of_linked_clips(int i) { } void Timeline::zoom_in() { - multiply_zoom(true); + multiply_zoom(2.0); } void Timeline::zoom_out() { - multiply_zoom(false); + multiply_zoom(0.5); } bool is_clip_selected(Clip* clip, bool containing) { diff --git a/panels/timeline.h b/panels/timeline.h index 34aa9fea7..1270afbd9 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -232,9 +232,10 @@ public slots: void nest(); + void zoom_in(); + void zoom_out(); + private slots: - void zoom_in(); - void zoom_out(); void snapping_clicked(bool checked); void add_btn_click(); void add_menu_item(QAction*); diff --git a/ui/focusfilter.cpp b/ui/focusfilter.cpp index 6e5ffabca..7548ed82a 100644 --- a/ui/focusfilter.cpp +++ b/ui/focusfilter.cpp @@ -213,7 +213,7 @@ void FocusFilter::zoom_in() { } else if (focused_panel == panel_sequence_viewer) { panel_sequence_viewer->set_zoom(true); } else { - panel_timeline->multiply_zoom(true); + panel_timeline->zoom_in(); } } @@ -226,7 +226,7 @@ void FocusFilter::zoom_out() { } else if (focused_panel == panel_sequence_viewer) { panel_sequence_viewer->set_zoom(false); } else { - panel_timeline->multiply_zoom(false); + panel_timeline->zoom_out(); } } diff --git a/ui/scrollarea.cpp b/ui/scrollarea.cpp index 7c9d6e90c..04b45407b 100644 --- a/ui/scrollarea.cpp +++ b/ui/scrollarea.cpp @@ -12,7 +12,12 @@ ScrollArea::ScrollArea(QWidget* parent) : QScrollArea(parent) {} void ScrollArea::wheelEvent(QWheelEvent *e) { if (config.scroll_zooms) { e->ignore(); - if (e->angleDelta().y() != 0) panel_timeline->multiply_zoom(e->angleDelta().y() > 0); + + if (e->angleDelta().y() > 0) { + panel_timeline->zoom_in(); + } else if (e->angleDelta().y() < 0) { + panel_timeline->zoom_out(); + } } else { QScrollArea::wheelEvent(e); } diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 5beff5f23..cbbd6d9a7 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -341,21 +341,46 @@ void TimelineWidget::dragMoveEvent(QDragMoveEvent *event) { } void TimelineWidget::wheelEvent(QWheelEvent *event) { - bool alt = (event->modifiers() & Qt::AltModifier); - int scroll_amount = alt ? (event->angleDelta().x()) : (event->angleDelta().y()); - if (scroll_amount != 0) { - bool shift = (event->modifiers() & Qt::ShiftModifier); - bool in = (scroll_amount > 0); - if (config.scroll_zooms != shift) { - panel_timeline->multiply_zoom(in); - } else { - QScrollBar* bar = alt ? scrollBar : panel_timeline->horizontalScrollBar; + // shift used to toggle zooming instead of scrolling + bool shift = (event->modifiers() & Qt::ShiftModifier); - int step = bar->singleStep(); - if (in) step = -step; - bar->setValue(bar->value() + step); - } - } + if (!event->pixelDelta().isNull()) { + // if we got pixel scrolling data, prefer it over the angleDelta data + + QScrollBar* horiz_bar = panel_timeline->horizontalScrollBar; + QScrollBar* vert_bar = scrollBar; + + horiz_bar->setValue(horiz_bar->value() + event->pixelDelta().x()); + vert_bar->setValue(vert_bar->value() + event->pixelDelta().y()); + + } else if (!event->angleDelta().isNull()) { + + // alt is used to swap horizontal and vertical scrolling + bool alt = (event->modifiers() & Qt::AltModifier); + + int scroll_amount = alt ? (event->angleDelta().x()) : (event->angleDelta().y()); + + bool in = (scroll_amount > 0); + if (config.scroll_zooms != shift) { + + // if config.scroll_zooms is enabled or shift is held, zoom instead of scrolling + if (in) { + panel_timeline->multiply_zoom(1.5); + } else { + panel_timeline->multiply_zoom(0.75); + } + + } else { + // pass the scrolling to the Timeline's main scrollbar for horizontal scrolling, or this widget's + // scrollbar for vertical scrolling + + QScrollBar* bar = alt ? scrollBar : panel_timeline->horizontalScrollBar; + + int step = bar->singleStep(); + if (in) step = -step; + bar->setValue(bar->value() + step); + } + } } void TimelineWidget::dragLeaveEvent(QDragLeaveEvent* event) {