Permalink
Browse files

Move mouse wheel zooming to MouseEventHandler

  • Loading branch information...
The-Compiler committed Aug 11, 2016
1 parent 677bb29 commit 1a94cb551c829f9d8db37a07d9ea476e715aa94c
@@ -220,19 +220,6 @@ def set_default(self):
default_zoom = config.get('ui', 'default-zoom')
self._set_factor_internal(float(default_zoom) / 100)
- @pyqtSlot(QPoint)
- def _on_mouse_wheel_zoom(self, delta):
- """Handle zooming via mousewheel requested by the web view."""
- divider = config.get('input', 'mouse-zoom-divider')
- factor = self.factor() + delta.y() / divider
- if factor < 0:
- return
- perc = int(100 * factor)
- message.info(self._win_id, "Zoom level: {}%".format(perc))
- self._neighborlist.fuzzyval = perc
- self._set_factor_internal(factor)
- self._default_zoom_changed = True
-
class AbstractCaret(QObject):
@@ -495,7 +482,6 @@ def _set_widget(self, widget):
self.zoom._widget = widget
self.search._widget = widget
self.printing._widget = widget
- widget.mouse_wheel_zoom.connect(self.zoom._on_mouse_wheel_zoom)
self._install_event_filter()
def _install_event_filter(self):
@@ -65,14 +65,17 @@ class MouseEventFilter(QObject):
Attributes:
_tab: The browsertab object this filter is installed on.
_handlers: A dict of handler functions for the handled events.
+ _ignore_wheel_event: Whether to ignore the next wheelEvent.
"""
def __init__(self, tab, parent=None):
super().__init__(parent)
self._tab = tab
self._handlers = {
QEvent.MouseButtonPress: self._handle_mouse_press,
+ QEvent.Wheel: self._handle_wheel,
}
+ self._ignore_wheel_event = False
def _handle_mouse_press(self, _obj, e):
"""Handle pressing of a mouse button."""
@@ -82,6 +85,29 @@ def _handle_mouse_press(self, _obj, e):
if e.button() in [Qt.XButton1, Qt.XButton2] or is_rocker_gesture:
self._mousepress_backforward(e)
return True
+ self._ignore_wheel_event = True
+ return False
+
+ def _handle_wheel(self, _obj, e):
+ """Zoom on Ctrl-Mousewheel.
+
+ Args:
+ e: The QWheelEvent.
+ """
+ if self._ignore_wheel_event:
+ # See https://github.com/The-Compiler/qutebrowser/issues/395
+ self._ignore_wheel_event = False
+ return True
+
+ if e.modifiers() & Qt.ControlModifier:
+ divider = config.get('input', 'mouse-zoom-divider')
+ factor = self._tab.zoom.factor() + (e.angleDelta().y() / divider)
+ if factor < 0:
+ return False
+ perc = int(100 * factor)
+ message.info(self._tab.win_id, "Zoom level: {}%".format(perc))
+ self._tab.zoom.set_factor(factor)
+
return False
def _mousepress_backforward(self, e):
@@ -33,24 +33,10 @@ class WebEngineView(QWebEngineView):
"""Custom QWebEngineView subclass with qutebrowser-specific features."""
- mouse_wheel_zoom = pyqtSignal(QPoint)
-
def __init__(self, parent=None):
super().__init__(parent)
self.setPage(WebEnginePage(self))
- def wheelEvent(self, e):
- """Zoom on Ctrl-Mousewheel.
-
- Args:
- e: The QWheelEvent.
- """
- if e.modifiers() & Qt.ControlModifier:
- e.accept()
- self.mouse_wheel_zoom.emit(e.angleDelta())
- else:
- super().wheelEvent(e)
-
class WebEnginePage(QWebEnginePage):
@@ -47,22 +47,16 @@ class WebView(QWebView):
_old_scroll_pos: The old scroll position.
_check_insertmode: If True, in mouseReleaseEvent we should check if we
need to enter/leave insert mode.
- _ignore_wheel_event: Ignore the next wheel event.
- See https://github.com/The-Compiler/qutebrowser/issues/395
Signals:
scroll_pos_changed: Scroll percentage of current tab changed.
arg 1: x-position in %.
arg 2: y-position in %.
- mouse_wheel_zoom: Emitted when the page should be zoomed because the
- mousewheel was used with ctrl.
- arg 1: The angle delta of the wheel event (QPoint)
shutting_down: Emitted when the view is shutting down.
"""
scroll_pos_changed = pyqtSignal(int, int)
shutting_down = pyqtSignal()
- mouse_wheel_zoom = pyqtSignal(QPoint)
def __init__(self, win_id, tab_id, tab, parent=None):
super().__init__(parent)
@@ -75,7 +69,6 @@ def __init__(self, win_id, tab_id, tab, parent=None):
self._check_insertmode = False
self.scroll_pos = (-1, -1)
self._old_scroll_pos = (-1, -1)
- self._ignore_wheel_event = False
self._set_bg_color()
self._tab_id = tab_id
@@ -388,7 +381,6 @@ def mousePressEvent(self, e):
"""
self._mousepress_insertmode(e)
self._mousepress_opentarget(e)
- self._ignore_wheel_event = True
super().mousePressEvent(e)
def mouseReleaseEvent(self, e):
@@ -404,19 +396,3 @@ def contextMenuEvent(self, e):
self.shutting_down.connect(menu.close)
modeman.instance(self.win_id).entered.connect(menu.close)
menu.exec_(e.globalPos())
-
- def wheelEvent(self, e):
- """Zoom on Ctrl-Mousewheel.
-
- Args:
- e: The QWheelEvent.
- """
- if self._ignore_wheel_event:
- self._ignore_wheel_event = False
- # See https://github.com/The-Compiler/qutebrowser/issues/395
- return
- if e.modifiers() & Qt.ControlModifier:
- e.accept()
- self.mouse_wheel_zoom.emit(e.angleDelta())
- else:
- super().wheelEvent(e)
@@ -19,7 +19,7 @@
import pytest
-from PyQt5.QtCore import PYQT_VERSION, pyqtSignal, QPoint
+from PyQt5.QtCore import PYQT_VERSION, pyqtSignal
from qutebrowser.browser import browsertab
from qutebrowser.keyinput import modeman
@@ -29,22 +29,16 @@
try:
from PyQt5.QtWebKitWidgets import QWebView
-
- class WebView(QWebView):
- mouse_wheel_zoom = pyqtSignal(QPoint)
except ImportError:
- WebView = None
+ QWebView = None
try:
from PyQt5.QtWebEngineWidgets import QWebEngineView
-
- class WebEngineView(QWebEngineView):
- mouse_wheel_zoom = pyqtSignal(QPoint)
except ImportError:
- WebEngineView = None
+ QWebEngineView = None
-@pytest.fixture(params=[WebView, WebEngineView])
+@pytest.fixture(params=[QWebView, QWebEngineView])
def view(qtbot, config_stub, request):
config_stub.data = {
'input': {

0 comments on commit 1a94cb5

Please sign in to comment.