Add Opera-like mouse rocker gestures.

This commit is contained in:
Gregor Pohl 2015-03-03 12:56:40 +01:00 committed by Florian Bruhin
parent f19eba3b40
commit c8c095d499
4 changed files with 33 additions and 5 deletions

View File

@ -150,6 +150,7 @@ Contributors, sorted by the number of commits in descending order:
* Matthias Lisin
* Helen Sherwood-Taylor
* HalosGhost
* Gregor Pohl
* Eivind Uggedal
* Andreas Fischer
// QUTE_AUTHORS_END

View File

@ -78,6 +78,7 @@
|<<input-forward-unbound-keys,forward-unbound-keys>>|Whether to forward unbound keys to the webview in normal mode.
|<<input-spatial-navigation,spatial-navigation>>|Enables or disables the Spatial Navigation feature
|<<input-links-included-in-focus-chain,links-included-in-focus-chain>>|Whether hyperlinks should be included in the keyboard focus chain.
|<<input-rocker-gestures,rocker-gestures>>|Whether to enable Opera-like mouse rocker gestures. This disables the context menu.
|==============
.Quick reference for section ``tabs''
@ -731,6 +732,17 @@ Valid values:
Default: +pass:[true]+
[[input-rocker-gestures]]
=== rocker-gestures
Whether to enable Opera-like mouse rocker gestures. This disables the context menu.
Valid values:
* +true+
* +false+
Default: +pass:[false]+
== tabs
Configuration of the tab bar.

View File

@ -143,6 +143,8 @@ class WebView(QWebView):
self.setZoomFactor(float(config.get('ui', 'default-zoom')) / 100)
self._default_zoom_changed = False
objreg.get('config').changed.connect(self.on_config_changed)
if config.get('input', 'rocker-gestures'):
self.setContextMenuPolicy(Qt.PreventContextMenu)
def __repr__(self):
url = utils.elide(self.url().toDisplayString(), 50)
@ -178,6 +180,11 @@ class WebView(QWebView):
100)
self._default_zoom_changed = False
self.init_neighborlist()
elif section == 'input' and option == 'rocker-gestures':
if config.get('input', 'rocker-gestures'):
self.setContextMenuPolicy(Qt.PreventContextMenu)
else:
self.setContextMenuPolicy(Qt.DefaultContextMenu)
def init_neighborlist(self):
"""Initialize the _zoom neighborlist."""
@ -192,15 +199,15 @@ class WebView(QWebView):
Args:
e: The QMouseEvent.
"""
if e.button() == Qt.XButton1:
# Back button on mice which have it.
if e.button() in (Qt.XButton1, Qt.LeftButton):
# Back button on mice which have it, or rocker gesture
if self.page().history().canGoBack():
self.back()
else:
message.error(self._win_id, "At beginning of history.",
immediately=True)
elif e.button() == Qt.XButton2:
# Forward button on mice which have it.
elif e.button() in (Qt.XButton2, Qt.RightButton):
# Forward button on mice which have it, or rocker gesture
if self.page().history().canGoForward():
self.forward()
else:
@ -497,7 +504,10 @@ class WebView(QWebView):
Return:
The superclass return value.
"""
if e.button() in (Qt.XButton1, Qt.XButton2):
is_rocker_gesture = (config.get('input', 'rocker-gestures') and
e.buttons() == Qt.LeftButton | Qt.RightButton)
if e.button() in (Qt.XButton1, Qt.XButton2) or is_rocker_gesture:
self._mousepress_backforward(e)
super().mousePressEvent(e)
return

View File

@ -370,6 +370,11 @@ DATA = collections.OrderedDict([
('links-included-in-focus-chain',
SettingValue(typ.Bool(), 'true'),
"Whether hyperlinks should be included in the keyboard focus chain."),
('rocker-gestures',
SettingValue(typ.Bool(), 'false'),
"Whether to enable Opera-like mouse rocker gestures. This disables "
"the context menu."),
)),
('tabs', sect.KeyValue(