Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal scroll of the timeline using SHIFT+scroll wheel #3857

Merged
merged 6 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/timeline/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ App.controller("TimelineCtrl", function ($scope) {
scrolling_tracks.scrollLeft(new_cursor_x);
};

// Scroll the timeline horizontally of a certain amount (scrol_value)
$scope.scrollLeft = function (scroll_value) {
var scrolling_tracks = $("#scrolling_tracks");
var horz_scroll_offset = scrolling_tracks.scrollLeft();
scrolling_tracks.scrollLeft(horz_scroll_offset + scroll_value);
};

// Center the timeline on a given time position
$scope.centerOnTime = function (centerTime) {
// Get the width of the timeline
Expand Down
11 changes: 7 additions & 4 deletions src/windows/views/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2783,14 +2783,17 @@ def update_zoom(self, newValue):

# Capture wheel event to alter zoom slider control
def wheelEvent(self, event):
if int(QCoreApplication.instance().keyboardModifiers() & Qt.ControlModifier) > 0:
if event.modifiers() & Qt.ControlModifier:
event.accept()
zoom = self.window.sliderZoom
# For each 120 (standard scroll unit) adjust the zoom slider
tick_scale = 120
steps = int(event.angleDelta().y() / tick_scale)
self.window.sliderZoom.setValue(self.window.sliderZoom.value() - self.window.sliderZoom.pageStep() * steps)
delta = zoom.pageStep() * steps
log.debug("Zooming by %d steps", -steps)
zoom.setValue(zoom.value() - delta)
else:
# Otherwise pass on to implement default functionality (scroll in QWebEngineView)
super(type(self), self).wheelEvent(event)
super().wheelEvent(event)

# An item is being dragged onto the timeline (mouse is entering the timeline now)
def dragEnterEvent(self, event):
Expand Down
17 changes: 17 additions & 0 deletions src/windows/views/webview_backend/webkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,20 @@ def keyPressEvent(self, event):
else:
# Ignore most keypresses
event.ignore()

def wheelEvent(self, event):
""" Mousewheel scrolling """
if event.modifiers() & Qt.ShiftModifier:
event.accept()
frame = self.page().mainFrame()
# Compute scroll offset from wheel motion
tick_scale = 120
steps = int(event.angleDelta().y() / tick_scale)
delta = -(steps * 100)
log.debug("Scrolling horizontally by %d pixels", delta)
# Update the scroll position using AngularJS
js = f"$('body').scope().scrollLeft({delta});"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the build failure is my fault. I used an f-string, forgetting that we're still testing on Xenial which is running Python 3.5 (despite it being EOL since last spring). *sigh* Until we can get rid of Xenial when it reaches EOL in April, I guess this will have to be...

Suggested change
js = f"$('body').scope().scrollLeft({delta});"
js = "$('body').scope().scrollLeft({});".format(delta)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just going to apply that change directly, to kick off a new build and hopefully wrap this up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that was it. Now I'm really frustrated that the error message there wasn't clearer. I guess we should log the exception from the failed WebKit backend load, before raising the RuntimeError from the WebEngine exception. Otherwise the reason for the WebKit import failure gets lost.

Well, I'll fix that in another PR. For this change, merging! Many thanks @MatthieuMeert!

frame.evaluateJavaScript(js)
else:
super().wheelEvent(event)