mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer full scrren mode: Allow clicking in the left and right page margins to turn pages. Fixes #1024819 ([Enhancement] Clic to advance page in viewer)
This commit is contained in:
parent
091164b307
commit
3c0be00709
Binary file not shown.
65
src/calibre/ebooks/oeb/display/full_screen.coffee
Normal file
65
src/calibre/ebooks/oeb/display/full_screen.coffee
Normal file
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env coffee
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
###
|
||||
Copyright 2012, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
Released under the GPLv3 License
|
||||
###
|
||||
|
||||
|
||||
log = window.calibre_utils.log
|
||||
|
||||
class FullScreen
|
||||
# This class is a namespace to expose functions via the
|
||||
# window.full_screen object. The most important functions are:
|
||||
|
||||
constructor: () ->
|
||||
if not this instanceof arguments.callee
|
||||
throw new Error('FullScreen constructor called as function')
|
||||
this.in_full_screen = false
|
||||
this.initial_left_margin = null
|
||||
this.initial_right_margin = null
|
||||
|
||||
save_margins: () ->
|
||||
bs = document.body.style
|
||||
this.initial_left_margin = bs.marginLeft
|
||||
this.initial_right_margin = bs.marginRight
|
||||
|
||||
on: (max_text_width, in_paged_mode) ->
|
||||
if in_paged_mode
|
||||
window.paged_display.max_col_width = max_text_width
|
||||
else
|
||||
s = document.body.style
|
||||
s.maxWidth = max_text_width + 'px'
|
||||
s.marginLeft = 'auto'
|
||||
s.marginRight = 'auto'
|
||||
window.addEventListener('click', this.handle_click, false)
|
||||
|
||||
off: (in_paged_mode) ->
|
||||
window.removeEventListener('click', this.handle_click, false)
|
||||
if in_paged_mode
|
||||
window.paged_display.max_col_width = -1
|
||||
else
|
||||
s = document.body.style
|
||||
s.maxWidth = 'none'
|
||||
if this.initial_left_margin != null
|
||||
s.marginLeft = this.initial_left_margin
|
||||
if this.initial_right_margin != null
|
||||
s.marginRight = this.initial_right_margin
|
||||
|
||||
handle_click: (event) ->
|
||||
if event.target != document.documentElement or event.button != 0
|
||||
return
|
||||
res = null
|
||||
if window.paged_display.in_paged_mode
|
||||
res = window.paged_display.click_for_page_turn(event)
|
||||
else
|
||||
br = document.body.getBoundingClientRect()
|
||||
if not (br.left <= event.clientX <= br.right)
|
||||
res = event.clientX < br.left
|
||||
if res != null
|
||||
window.py_bridge.page_turn_requested(res)
|
||||
|
||||
if window?
|
||||
window.full_screen = new FullScreen()
|
||||
|
@ -395,6 +395,18 @@ class PagedDisplay
|
||||
log('Viewport cfi:', ans)
|
||||
return ans
|
||||
|
||||
click_for_page_turn: (event) ->
|
||||
# Check if the click event event should generate a apge turn. Returns
|
||||
# null if it should not, true if it is a backwards page turn, false if
|
||||
# it is a forward apge turn.
|
||||
left_boundary = this.current_margin_side
|
||||
right_bondary = this.screen_width - this.current_margin_side
|
||||
if left_boundary > event.clientX
|
||||
return true
|
||||
if right_bondary < event.clientX
|
||||
return false
|
||||
return null
|
||||
|
||||
if window?
|
||||
window.paged_display = new PagedDisplay()
|
||||
|
||||
|
@ -11,7 +11,7 @@ from functools import partial
|
||||
from PyQt4.Qt import (QSize, QSizePolicy, QUrl, SIGNAL, Qt, pyqtProperty,
|
||||
QPainter, QPalette, QBrush, QFontDatabase, QDialog, QColor, QPoint,
|
||||
QImage, QRegion, QIcon, pyqtSignature, QAction, QMenu, QString,
|
||||
pyqtSignal, QSwipeGesture, QApplication)
|
||||
pyqtSignal, QSwipeGesture, QApplication, pyqtSlot)
|
||||
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||
|
||||
from calibre.gui2.viewer.flip import SlideFlip
|
||||
@ -34,6 +34,8 @@ def load_builtin_fonts():
|
||||
|
||||
class Document(QWebPage): # {{{
|
||||
|
||||
page_turn = pyqtSignal(object)
|
||||
|
||||
def set_font_settings(self):
|
||||
opts = config().parse()
|
||||
settings = self.settings()
|
||||
@ -171,6 +173,10 @@ class Document(QWebPage): # {{{
|
||||
if not isxp and self.hyphenate and getattr(self, 'loaded_lang', ''):
|
||||
self.javascript('do_hyphenation("%s")'%self.loaded_lang)
|
||||
|
||||
@pyqtSlot(int)
|
||||
def page_turn_requested(self, backwards):
|
||||
self.page_turn.emit(bool(backwards))
|
||||
|
||||
def _pass_json_value_getter(self):
|
||||
val = json.dumps(self.bridge_value)
|
||||
return QString(val)
|
||||
@ -187,10 +193,10 @@ class Document(QWebPage): # {{{
|
||||
self.fit_images()
|
||||
self.init_hyphenate()
|
||||
self.javascript('full_screen.save_margins()')
|
||||
if self.in_paged_mode:
|
||||
self.switch_to_paged_mode()
|
||||
if self.in_fullscreen_mode:
|
||||
self.switch_to_fullscreen_mode()
|
||||
if self.in_paged_mode:
|
||||
self.switch_to_paged_mode()
|
||||
self.read_anchor_positions(use_cache=False)
|
||||
self.first_load = False
|
||||
|
||||
@ -445,6 +451,7 @@ class DocumentView(QWebView): # {{{
|
||||
self.connect(self.document, SIGNAL('selectionChanged()'), self.selection_changed)
|
||||
self.connect(self.document, SIGNAL('animated_scroll_done()'),
|
||||
self.animated_scroll_done, Qt.QueuedConnection)
|
||||
self.document.page_turn.connect(self.page_turn_requested)
|
||||
copy_action = self.pageAction(self.document.Copy)
|
||||
copy_action.setIcon(QIcon(I('convert.png')))
|
||||
d = self.document
|
||||
@ -878,6 +885,12 @@ class DocumentView(QWebView): # {{{
|
||||
self.manager.scrolled(self.scroll_fraction)
|
||||
#print 'After all:', self.document.ypos
|
||||
|
||||
def page_turn_requested(self, backwards):
|
||||
if backwards:
|
||||
self.previous_page()
|
||||
else:
|
||||
self.next_page()
|
||||
|
||||
def scroll_by(self, x=0, y=0, notify=True):
|
||||
old_pos = (self.document.xpos if self.document.in_paged_mode else
|
||||
self.document.ypos)
|
||||
|
@ -272,9 +272,11 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
<h1>%s</h1>
|
||||
<h3>%s</h3>
|
||||
<h3>%s</h3>
|
||||
<h3>%s</h3>
|
||||
</center>
|
||||
'''%(_('Full screen mode'),
|
||||
_('Right click to show controls'),
|
||||
_('Tap in the left or right page margin to turn pages'),
|
||||
_('Press Esc to quit')),
|
||||
self)
|
||||
self.full_screen_label.setVisible(False)
|
||||
@ -496,7 +498,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
a.setStartValue(QSize(width, 0))
|
||||
a.setEndValue(QSize(width, height))
|
||||
a.start()
|
||||
QTimer.singleShot(2750, self.full_screen_label.hide)
|
||||
QTimer.singleShot(3500, self.full_screen_label.hide)
|
||||
self.view.document.switch_to_fullscreen_mode()
|
||||
if self.view.document.fullscreen_clock:
|
||||
self.show_clock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user