Add clicking on links
This commit is contained in:
parent
c2aa9517ea
commit
de0e96ab2d
@ -17,10 +17,12 @@
|
||||
|
||||
"""A HintManager to draw hints over links."""
|
||||
|
||||
import logging
|
||||
import math
|
||||
from collections import namedtuple
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QObject
|
||||
from PyQt5.QtCore import pyqtSignal, QObject, QEvent, Qt
|
||||
from PyQt5.QtGui import QMouseEvent
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
from qutebrowser.utils.keyparser import KeyParser
|
||||
@ -71,7 +73,14 @@ class HintManager(QObject):
|
||||
|
||||
Signals:
|
||||
hint_strings_updated: Emitted when the possible hint strings changed.
|
||||
arg: A list of hint strings.
|
||||
set_mode: Emitted when the input mode should be changed.
|
||||
arg: The new mode, as a string.
|
||||
mouse_event: Mouse event to be posted in the web view.
|
||||
arg: A QMouseEvent
|
||||
openurl: Open a new url
|
||||
arg 0: URL to open as a string.
|
||||
arg 1: true if it should be opened in a new tab, else false.
|
||||
"""
|
||||
|
||||
SELECTORS = {
|
||||
@ -100,6 +109,7 @@ class HintManager(QObject):
|
||||
|
||||
hint_strings_updated = pyqtSignal(list)
|
||||
set_mode = pyqtSignal(str)
|
||||
mouse_event = pyqtSignal('QMouseEvent')
|
||||
|
||||
def __init__(self, frame):
|
||||
"""Constructor.
|
||||
@ -247,7 +257,7 @@ class HintManager(QObject):
|
||||
|
||||
def stop(self):
|
||||
"""Stop hinting."""
|
||||
for elem in self._elems:
|
||||
for elem in self._elems.values():
|
||||
elem.label.removeFromDocument()
|
||||
self._elems = {}
|
||||
self.set_mode.emit("normal")
|
||||
@ -269,4 +279,16 @@ class HintManager(QObject):
|
||||
|
||||
def fire(self, keystr):
|
||||
"""Fire a completed hint."""
|
||||
raise NotImplementedError
|
||||
elem = self._elems[keystr].elem
|
||||
logging.debug("Clicking on: {}".format(elem.toPlainText()))
|
||||
self.stop()
|
||||
events = [
|
||||
QMouseEvent(QEvent.MouseMove, elem.geometry().center(),
|
||||
Qt.NoButton, Qt.NoButton, Qt.NoModifier),
|
||||
QMouseEvent(QEvent.MouseButtonPress, elem.geometry().center(),
|
||||
Qt.LeftButton, Qt.NoButton, Qt.NoModifier),
|
||||
QMouseEvent(QEvent.MouseButtonRelease, elem.geometry().center(),
|
||||
Qt.LeftButton, Qt.NoButton, Qt.NoModifier),
|
||||
]
|
||||
for evt in events:
|
||||
self.mouse_event.emit(evt)
|
||||
|
@ -341,6 +341,7 @@ DATA = OrderedDict([
|
||||
('r', 'reload'),
|
||||
('H', 'back'),
|
||||
('L', 'forward'),
|
||||
('f', 'hint'),
|
||||
('h', 'scroll -50 0'),
|
||||
('j', 'scroll 0 50'),
|
||||
('k', 'scroll 0 -50'),
|
||||
|
@ -21,6 +21,7 @@ import logging
|
||||
import functools
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QEvent
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||
|
||||
@ -77,6 +78,7 @@ class BrowserTab(QWebView):
|
||||
self.page_ = BrowserPage(self)
|
||||
self.setPage(self.page_)
|
||||
self.hintmanager = HintManager(self.page_.mainFrame())
|
||||
self.hintmanager.mouse_event.connect(self.on_mouse_event)
|
||||
self.signal_cache = SignalCache(uncached=['linkHovered'])
|
||||
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||
self.page_.linkHovered.connect(self.linkHovered)
|
||||
@ -185,6 +187,11 @@ class BrowserTab(QWebView):
|
||||
if section == 'general' and option in ['zoomlevels', 'defaultzoom']:
|
||||
self._init_neighborlist()
|
||||
|
||||
@pyqtSlot('QMouseEvent')
|
||||
def on_mouse_event(self, evt):
|
||||
"""Post a new mouseevent from a hintmanager."""
|
||||
QApplication.postEvent(self, evt)
|
||||
|
||||
def _on_destroyed(self, sender):
|
||||
"""Called when a subsystem has been destroyed during shutdown.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user