From 9b7ebac28ae27eb5a2deb0742e9f4d4d630549ef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Dec 2010 09:31:54 -0700 Subject: [PATCH] E-book viewer: Page flip animation is used when transitioning between flows as well --- src/calibre/gui2/viewer/documentview.py | 36 ++++++++++++++++++++++--- src/calibre/gui2/viewer/flip.py | 4 +++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 4ce9b9818e..21c81bea2f 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -468,6 +468,7 @@ class DocumentView(QWebView): QWebView.__init__(self, *args) self.flipper = SlideFlip(self) self.is_auto_repeat_event = False + self.load_flip_direction = None self.debug_javascript = False self.shortcuts = Shortcuts(SHORTCUTS, 'shortcuts/viewer') self.self_closing_pat = re.compile(r'<([a-z1-6]+)\s+([^>]+)/>', @@ -646,6 +647,8 @@ class DocumentView(QWebView): return '<%s %s>'%(match.group(1), match.group(2), match.group(1)) def load_path(self, path, pos=0.0): + if self.load_flip_direction is not None: + self.flipper.initialize(self.current_page_image()) self.initial_pos = pos mt = getattr(path, 'mime_type', None) if mt is None: @@ -708,6 +711,11 @@ class DocumentView(QWebView): self.manager.scrolled(self.document.scroll_fraction) self.turn_off_internal_scrollbars() + if self.load_flip_direction is not None: + self.flipper(self.current_page_image(), + duration=self.document.page_flip_duration, + forwards=self.load_flip_direction == 'next') + self.load_flip_direction = None def turn_off_internal_scrollbars(self): self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff) @@ -743,13 +751,19 @@ class DocumentView(QWebView): def previous_page(self): if self.flipper.running and not self.is_auto_repeat_event: return + if self.loading_url is not None: + return epf = self.document.enable_page_flip and not self.is_auto_repeat_event delta_y = self.document.window_height - 25 if self.document.at_top: if self.manager is not None: self.to_bottom = True - self.manager.previous_document() + self.load_flip_direction = 'previous' if epf else None + try: + self.manager.previous_document() + finally: + self.load_flip_direction = None else: opos = self.document.ypos upper_limit = opos - delta_y @@ -768,6 +782,8 @@ class DocumentView(QWebView): def next_page(self): if self.flipper.running and not self.is_auto_repeat_event: return + if self.loading_url is not None: + return epf = self.document.enable_page_flip and not self.is_auto_repeat_event window_height = self.document.window_height @@ -779,7 +795,11 @@ class DocumentView(QWebView): delta_y = window_height - 25 if self.document.at_bottom or ddelta <= 0: if self.manager is not None: - self.manager.next_document() + self.load_flip_direction = 'next' if epf else None + try: + self.manager.next_document() + finally: + self.load_flip_direction = None elif ddelta < 25: self.scroll_by(y=ddelta) return @@ -791,7 +811,11 @@ class DocumentView(QWebView): #print 'After set padding=0:', self.document.ypos if opos < oopos: if self.manager is not None: - self.manager.next_document() + self.load_flip_direction = 'next' if epf else None + try: + self.manager.next_document() + finally: + self.load_flip_direction = None return lower_limit = opos + delta_y # Max value of top y co-ord after scrolling max_y = self.document.height - window_height # The maximum possible top y co-ord @@ -799,7 +823,11 @@ class DocumentView(QWebView): padding = lower_limit - max_y if padding == window_height: if self.manager is not None: - self.manager.next_document() + self.load_flip_direction = 'next' if epf else None + try: + self.manager.next_document() + finally: + self.load_flip_direction = 'next' return #print 'Setting padding to:', lower_limit - max_y self.document.set_bottom_padding(lower_limit - max_y) diff --git a/src/calibre/gui2/viewer/flip.py b/src/calibre/gui2/viewer/flip.py index d12d3f56fe..0907f90700 100644 --- a/src/calibre/gui2/viewer/flip.py +++ b/src/calibre/gui2/viewer/flip.py @@ -10,6 +10,8 @@ from PyQt4.Qt import QWidget, QPainter, QPropertyAnimation, QEasingCurve, \ class SlideFlip(QWidget): + # API {{{ + def __init__(self, parent): QWidget.__init__(self, parent) @@ -54,6 +56,8 @@ class SlideFlip(QWidget): self.animation.setDuration(duration * 1000) self.animation.start() + # }}} + def finished(self): self.setVisible(False) self.before_image = self.after_image = None