Emit ClickTarget from HintManager.start_hinting.

This is much clearer than transmitting a string which must match the
ClickTarget enum.
This commit is contained in:
Florian Bruhin 2015-05-06 23:17:23 +02:00
parent f99a070735
commit 98596d439f
2 changed files with 19 additions and 19 deletions

View File

@ -117,7 +117,7 @@ class HintManager(QObject):
mouse_event: Mouse event to be posted in the web view. mouse_event: Mouse event to be posted in the web view.
arg: A QMouseEvent arg: A QMouseEvent
start_hinting: Emitted when hinting starts, before a link is clicked. start_hinting: Emitted when hinting starts, before a link is clicked.
arg: The hinting target name. arg: The ClickTarget to use.
stop_hinting: Emitted after a link was clicked. stop_hinting: Emitted after a link was clicked.
""" """
@ -137,7 +137,7 @@ class HintManager(QObject):
} }
mouse_event = pyqtSignal('QMouseEvent') mouse_event = pyqtSignal('QMouseEvent')
start_hinting = pyqtSignal(str) start_hinting = pyqtSignal(usertypes.ClickTarget)
stop_hinting = pyqtSignal() stop_hinting = pyqtSignal()
def __init__(self, win_id, tab_id, parent=None): def __init__(self, win_id, tab_id, parent=None):
@ -413,22 +413,26 @@ class HintManager(QObject):
elem: The QWebElement to click. elem: The QWebElement to click.
context: The HintContext to use. context: The HintContext to use.
""" """
if context.target == Target.rapid: target_mapping = {
target = Target.tab_bg Target.rapid: usertypes.ClickTarget.tab_bg,
elif context.target == Target.rapid_win: Target.rapid_win: usertypes.ClickTarget.window,
target = Target.window Target.normal: usertypes.ClickTarget.normal,
else: Target.tab: usertypes.ClickTarget.tab,
target = context.target Target.tab_bg: usertypes.ClickTarget.tab_bg,
Target.window: usertypes.ClickTarget.window,
Target.hover: usertypes.ClickTarget.normal,
}
# FIXME Instead of clicking the center, we could have nicer heuristics. # FIXME Instead of clicking the center, we could have nicer heuristics.
# e.g. parse (-webkit-)border-radius correctly and click text fields at # e.g. parse (-webkit-)border-radius correctly and click text fields at
# the bottom right, and everything else on the top left or so. # the bottom right, and everything else on the top left or so.
# https://github.com/The-Compiler/qutebrowser/issues/70 # https://github.com/The-Compiler/qutebrowser/issues/70
pos = elem.rect_on_view().center() pos = elem.rect_on_view().center()
action = "Hovering" if target == Target.hover else "Clicking" action = "Hovering" if context.target == Target.hover else "Clicking"
log.hints.debug("{} on '{}' at {}/{}".format( log.hints.debug("{} on '{}' at {}/{}".format(
action, elem, pos.x(), pos.y())) action, elem, pos.x(), pos.y()))
self.start_hinting.emit(target.name) self.start_hinting.emit(target_mapping[context.target])
if target in (Target.tab, Target.tab_bg, Target.window): if context.target in [Target.tab, Target.tab_bg, Target.window,
Target.rapid, Target.rapid_win]:
modifiers = Qt.ControlModifier modifiers = Qt.ControlModifier
else: else:
modifiers = Qt.NoModifier modifiers = Qt.NoModifier
@ -436,7 +440,7 @@ class HintManager(QObject):
QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton,
Qt.NoModifier), Qt.NoModifier),
] ]
if target != Target.hover: if context.target != Target.hover:
events += [ events += [
QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton,
Qt.LeftButton, modifiers), Qt.LeftButton, modifiers),

View File

@ -427,14 +427,10 @@ class BrowserPage(QWebPage):
"""Emitted before a hinting-click takes place. """Emitted before a hinting-click takes place.
Args: Args:
hint_target: A string to set self._hint_target to. hint_target: A ClickTarget member to set self._hint_target to.
""" """
t = getattr(usertypes.ClickTarget, hint_target, None) log.webview.debug("Setting force target to {}".format(hint_target))
if t is None: self._hint_target = hint_target
return
log.webview.debug("Setting force target to {}/{}".format(
hint_target, t))
self._hint_target = t
@pyqtSlot() @pyqtSlot()
def on_stop_hinting(self): def on_stop_hinting(self):