Handle taps on the viewer

This commit is contained in:
Kovid Goyal 2014-02-10 16:07:06 +05:30
parent 72ae72418c
commit e6c62225cb

View File

@ -165,6 +165,7 @@ class GestureHandler(QObject):
QObject.__init__(self, view) QObject.__init__(self, view)
self.state = State() self.state = State()
self.state.swiped.connect(self.handle_swipe) self.state.swiped.connect(self.handle_swipe)
self.state.tapped.connect(self.handle_tap)
self.evmap = {QEvent.TouchBegin: 'start', QEvent.TouchUpdate: 'update', QEvent.TouchEnd: 'end'} self.evmap = {QEvent.TouchBegin: 'start', QEvent.TouchUpdate: 'update', QEvent.TouchEnd: 'end'}
# Ignore fake mouse events generated by the window system from touch # Ignore fake mouse events generated by the window system from touch
@ -220,3 +221,8 @@ class GestureHandler(QObject):
func = {Left:'next_page', Right: 'previous_page', Up:'goto_previous_section', Down:'goto_next_section'}[direction] func = {Left:'next_page', Right: 'previous_page', Up:'goto_previous_section', Down:'goto_next_section'}[direction]
getattr(view, func)() getattr(view, func)()
def handle_tap(self, tp):
view = self.parent()
threshold = view.width() / 3.0
attr = 'previous' if tp.start_position.x() <= threshold else 'next'
getattr(view, '%s_page'%attr)()