This commit is contained in:
Kovid Goyal 2010-12-16 10:05:42 -07:00
parent a6bebd5d75
commit 6a6b2a6f58
2 changed files with 29 additions and 24 deletions

View File

@ -468,7 +468,6 @@ class DocumentView(QWebView):
QWebView.__init__(self, *args) QWebView.__init__(self, *args)
self.flipper = SlideFlip(self) self.flipper = SlideFlip(self)
self.is_auto_repeat_event = False self.is_auto_repeat_event = False
self.load_flip_direction = None
self.debug_javascript = False self.debug_javascript = False
self.shortcuts = Shortcuts(SHORTCUTS, 'shortcuts/viewer') self.shortcuts = Shortcuts(SHORTCUTS, 'shortcuts/viewer')
self.self_closing_pat = re.compile(r'<([a-z1-6]+)\s+([^>]+)/>', self.self_closing_pat = re.compile(r'<([a-z1-6]+)\s+([^>]+)/>',
@ -647,10 +646,6 @@ class DocumentView(QWebView):
return '<%s %s></%s>'%(match.group(1), match.group(2), match.group(1)) return '<%s %s></%s>'%(match.group(1), match.group(2), match.group(1))
def load_path(self, path, pos=0.0): def load_path(self, path, pos=0.0):
if self.load_flip_direction is not None:
self.flipper.initialize(self.current_page_image(),
self.load_flip_direction=='next')
self.load_flip_direction = None
self.initial_pos = pos self.initial_pos = pos
mt = getattr(path, 'mime_type', None) mt = getattr(path, 'mime_type', None)
if mt is None: if mt is None:
@ -763,11 +758,9 @@ class DocumentView(QWebView):
if self.document.at_top: if self.document.at_top:
if self.manager is not None: if self.manager is not None:
self.to_bottom = True self.to_bottom = True
self.load_flip_direction = 'previous' if epf else None if epf:
try: self.flipper.initialize(self.current_page_image(), False)
self.manager.previous_document() self.manager.previous_document()
finally:
self.load_flip_direction = None
else: else:
opos = self.document.ypos opos = self.document.ypos
upper_limit = opos - delta_y upper_limit = opos - delta_y
@ -800,11 +793,9 @@ class DocumentView(QWebView):
delta_y = window_height - 25 delta_y = window_height - 25
if self.document.at_bottom or ddelta <= 0: if self.document.at_bottom or ddelta <= 0:
if self.manager is not None: if self.manager is not None:
self.load_flip_direction = 'next' if epf else None if epf:
try: self.flipper.initialize(self.current_page_image())
self.manager.next_document() self.manager.next_document()
finally:
self.load_flip_direction = None
elif ddelta < 25: elif ddelta < 25:
self.scroll_by(y=ddelta) self.scroll_by(y=ddelta)
return return
@ -816,11 +807,9 @@ class DocumentView(QWebView):
#print 'After set padding=0:', self.document.ypos #print 'After set padding=0:', self.document.ypos
if opos < oopos: if opos < oopos:
if self.manager is not None: if self.manager is not None:
self.load_flip_direction = 'next' if epf else None if epf:
try: self.flipper.initialize(self.current_page_image())
self.manager.next_document() self.manager.next_document()
finally:
self.load_flip_direction = None
return return
lower_limit = opos + delta_y # Max value of top y co-ord after scrolling 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 max_y = self.document.height - window_height # The maximum possible top y co-ord
@ -828,11 +817,9 @@ class DocumentView(QWebView):
padding = lower_limit - max_y padding = lower_limit - max_y
if padding == window_height: if padding == window_height:
if self.manager is not None: if self.manager is not None:
self.load_flip_direction = 'next' if epf else None if epf:
try: self.flipper.initialize(self.current_page_image())
self.manager.next_document() self.manager.next_document()
finally:
self.load_flip_direction = 'next'
return return
#print 'Setting padding to:', lower_limit - max_y #print 'Setting padding to:', lower_limit - max_y
self.document.set_bottom_padding(lower_limit - max_y) self.document.set_bottom_padding(lower_limit - max_y)

View File

@ -12,6 +12,8 @@ class SlideFlip(QWidget):
# API {{{ # API {{{
# In addition the isVisible() and setVisible() methods must be present
def __init__(self, parent): def __init__(self, parent):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
@ -27,9 +29,19 @@ class SlideFlip(QWidget):
@property @property
def running(self): def running(self):
'True iff animation is currently running'
return self.animation.state() == self.animation.Running return self.animation.state() == self.animation.Running
def initialize(self, image, forwards=True): def initialize(self, image, forwards=True):
'''
Initialize the flipper, causes the flipper to show itself displaying
the full `image`.
:param image: The image to display as background
:param forwards: If True flipper will flip forwards, otherwise
backwards
'''
self.flip_forwards = forwards self.flip_forwards = forwards
self.before_image = QPixmap.fromImage(image) self.before_image = QPixmap.fromImage(image)
self.after_image = None self.after_image = None
@ -37,6 +49,12 @@ class SlideFlip(QWidget):
self.setVisible(True) self.setVisible(True)
def __call__(self, image, duration=0.5): def __call__(self, image, duration=0.5):
'''
Start the animation. You must have called :meth:`initialize` first.
:param duration: Animation duration in seconds.
'''
if self.running: if self.running:
return return
self.after_image = QPixmap.fromImage(image) self.after_image = QPixmap.fromImage(image)