diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index bb2ea7cfd9..ed0bce537b 100644 Binary files a/resources/compiled_coffeescript.zip and b/resources/compiled_coffeescript.zip differ diff --git a/src/calibre/ebooks/oeb/display/full_screen.coffee b/src/calibre/ebooks/oeb/display/full_screen.coffee new file mode 100644 index 0000000000..f4dece210a --- /dev/null +++ b/src/calibre/ebooks/oeb/display/full_screen.coffee @@ -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 + 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() + diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index 3bb3461927..c2a09b5587 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -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() diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 1afb284e8f..dac9a05113 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -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) diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 65be08343d..c6eb76c735 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -272,9 +272,11 @@ class EbookViewer(MainWindow, Ui_EbookViewer):

%s

%s

%s

+

%s

'''%(_('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()