mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add an entry to show help to the context menu when triggered by tap and hold
This commit is contained in:
parent
7040010cdc
commit
6c5e9e9769
@ -640,6 +640,7 @@ class DocumentView(QWebView): # {{{
|
||||
self.document.font_magnification_step)
|
||||
|
||||
def contextMenuEvent(self, ev):
|
||||
from_touch = ev.reason() == ev.Other
|
||||
mf = self.document.mainFrame()
|
||||
r = mf.hitTestContent(ev.pos())
|
||||
img = r.pixmap()
|
||||
@ -705,13 +706,16 @@ class DocumentView(QWebView): # {{{
|
||||
|
||||
for plugin in self.document.all_viewer_plugins:
|
||||
plugin.customize_context_menu(menu, ev, r)
|
||||
if ev.reason() == ev.Other:
|
||||
# Triggered by a touch event
|
||||
|
||||
if from_touch:
|
||||
from calibre.constants import plugins
|
||||
pi = plugins['progress_indicator'][0]
|
||||
for x in (menu, self.goto_location_menu):
|
||||
if hasattr(pi, 'set_touch_menu_style'):
|
||||
pi.set_touch_menu_style(x)
|
||||
helpt = QAction(QIcon(I('help.png')), _('Show supported touch screen gestures'), menu)
|
||||
helpt.triggered.connect(self.gesture_handler.show_help)
|
||||
menu.insertAction(menu.actions()[0], helpt)
|
||||
else:
|
||||
self.goto_location_menu.setStyle(self.style())
|
||||
self.context_menu = menu
|
||||
|
@ -10,7 +10,7 @@ import time, ctypes, sys
|
||||
from functools import partial
|
||||
from PyQt4.Qt import (
|
||||
QObject, QPointF, pyqtSignal, QEvent, QApplication, QMouseEvent, Qt,
|
||||
QContextMenuEvent)
|
||||
QContextMenuEvent, QDialog, QDialogButtonBox, QLabel, QVBoxLayout)
|
||||
|
||||
from calibre.constants import iswindows
|
||||
|
||||
@ -36,6 +36,56 @@ Tap, TapAndHold, Pinch, Swipe, SwipeAndHold = 'Tap', 'TapAndHold', 'Pinch', 'Swi
|
||||
Left, Right, Up, Down = 'Left', 'Right', 'Up', 'Down'
|
||||
In, Out = 'In', 'Out'
|
||||
|
||||
class Help(QDialog): # {{{
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QDialog.__init__(self, parent=parent)
|
||||
self.l = l = QVBoxLayout(self)
|
||||
self.setLayout(l)
|
||||
|
||||
self.la = la = QLabel(
|
||||
'''
|
||||
<style>
|
||||
h2 { text-align: center }
|
||||
dt { font-weight: bold }
|
||||
dd { margin-bottom: 1.5em }
|
||||
</style>
|
||||
|
||||
''' + _(
|
||||
'''
|
||||
<h2>The list of available gestures</h2>
|
||||
<dl>
|
||||
<dt>Single tap</dt>
|
||||
<dd>A single tap on the right two thirds of the page will turn to the next page
|
||||
and on the left one-third of the page will turn to the previous page. Single tapping
|
||||
on a link will activate the link.</dd>
|
||||
|
||||
<dt>Swipe</dt>
|
||||
<dd>Swipe to the left to go to the next page and to the right to go to the previous page.
|
||||
This mimics turning pages in a paper book.</dd>
|
||||
|
||||
<dt>Pinch</dt>
|
||||
<dd>Pinch in or out to decrease or increase the font size</dd>
|
||||
|
||||
<dt>Swipe and hold</dt>
|
||||
<dd>If you swipe and the hold your finger down instead of lifting it, pages will be turned
|
||||
rapidly allowing for quickly scanning through large numbers of pages.</dd>
|
||||
|
||||
<dt>Tap and hold</dt>
|
||||
<dd>Bring up the context (right-click) menu</dd>
|
||||
</dl>
|
||||
'''
|
||||
))
|
||||
la.setAlignment(Qt.AlignTop | Qt.AlignLeft)
|
||||
la.setWordWrap(True)
|
||||
l.addWidget(la, Qt.AlignTop|Qt.AlignLeft)
|
||||
self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close)
|
||||
bb.accepted.connect(self.accept)
|
||||
bb.rejected.connect(self.reject)
|
||||
l.addWidget(bb)
|
||||
self.resize(600, 500)
|
||||
# }}}
|
||||
|
||||
class TouchPoint(object):
|
||||
|
||||
def __init__(self, tp):
|
||||
@ -316,3 +366,9 @@ class GestureHandler(QObject):
|
||||
attr = 'magnify' if direction is Out else 'shrink'
|
||||
getattr(self.parent(), '%s_fonts' % attr)()
|
||||
|
||||
def show_help(self):
|
||||
Help(self.parent()).exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication([])
|
||||
Help().exec_()
|
||||
|
Loading…
x
Reference in New Issue
Block a user