Merge from trunk

This commit is contained in:
Charles Haley 2012-07-24 19:20:24 +02:00
commit 32c4f0d6cf
6 changed files with 104 additions and 28 deletions

Binary file not shown.

View 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()

View File

@ -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()

View File

@ -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()
@ -73,7 +75,6 @@ class Document(QWebPage): # {{{
self.loaded_javascript = False
self.js_loader = JavaScriptLoader(
dynamic_coffeescript=self.debug_javascript)
self.initial_left_margin = self.initial_right_margin = u''
self.in_fullscreen_mode = False
self.setLinkDelegationPolicy(self.DelegateAllLinks)
@ -172,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,14 +192,11 @@ class Document(QWebPage): # {{{
self.set_bottom_padding(0)
self.fit_images()
self.init_hyphenate()
self.initial_left_margin = unicode(self.javascript(
'document.body.style.marginLeft').toString())
self.initial_right_margin = unicode(self.javascript(
'document.body.style.marginRight').toString())
if self.in_paged_mode:
self.switch_to_paged_mode()
self.javascript('full_screen.save_margins()')
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
@ -257,27 +259,13 @@ class Document(QWebPage): # {{{
def switch_to_fullscreen_mode(self):
self.in_fullscreen_mode = True
if self.in_paged_mode:
self.javascript('paged_display.max_col_width = %d'%self.max_fs_width)
else:
self.javascript('''
var s = document.body.style;
s.maxWidth = "%dpx";
s.marginLeft = "auto";
s.marginRight = "auto";
'''%self.max_fs_width)
self.javascript('full_screen.on(%d, %s)'%(self.max_fs_width,
'true' if self.in_paged_mode else 'false'))
def switch_to_window_mode(self):
self.in_fullscreen_mode = False
if self.in_paged_mode:
self.javascript('paged_display.max_col_width = %d'%-1)
else:
self.javascript('''
var s = document.body.style;
s.maxWidth = "none";
s.marginLeft = "%s";
s.marginRight = "%s";
'''%(self.initial_left_margin, self.initial_right_margin))
self.javascript('full_screen.off(%s)'%('true' if self.in_paged_mode
else 'false'))
@pyqtSignature("QString")
def debug(self, msg):
@ -463,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
@ -896,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)

View File

@ -32,10 +32,12 @@ class JavaScriptLoader(object):
'indexing':'ebooks.oeb.display.indexing',
'paged':'ebooks.oeb.display.paged',
'utils':'ebooks.oeb.display.utils',
'fs':'ebooks.oeb.display.full_screen',
}
ORDER = ('jquery', 'jquery_scrollTo', 'bookmarks', 'referencing', 'images',
'hyphenation', 'hyphenator', 'utils', 'cfi', 'indexing', 'paged')
'hyphenation', 'hyphenator', 'utils', 'cfi', 'indexing', 'paged',
'fs')
def __init__(self, dynamic_coffeescript=False):

View File

@ -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()