More robust flip animation

This commit is contained in:
Kovid Goyal 2010-12-16 09:57:00 -07:00
parent 9b7ebac28a
commit a6bebd5d75
2 changed files with 17 additions and 14 deletions

View File

@ -648,7 +648,9 @@ class DocumentView(QWebView):
def load_path(self, path, pos=0.0): def load_path(self, path, pos=0.0):
if self.load_flip_direction is not None: if self.load_flip_direction is not None:
self.flipper.initialize(self.current_page_image()) 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:
@ -711,11 +713,13 @@ class DocumentView(QWebView):
self.manager.scrolled(self.document.scroll_fraction) self.manager.scrolled(self.document.scroll_fraction)
self.turn_off_internal_scrollbars() self.turn_off_internal_scrollbars()
if self.load_flip_direction is not None: if self.flipper.isVisible():
if self.flipper.running:
self.flipper.setVisible(False)
else:
self.flipper(self.current_page_image(), self.flipper(self.current_page_image(),
duration=self.document.page_flip_duration, duration=self.document.page_flip_duration)
forwards=self.load_flip_direction == 'next')
self.load_flip_direction = None
def turn_off_internal_scrollbars(self): def turn_off_internal_scrollbars(self):
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff) self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
@ -771,10 +775,11 @@ class DocumentView(QWebView):
upper_limit = 0 upper_limit = 0
if upper_limit < opos: if upper_limit < opos:
if epf: if epf:
self.flipper.initialize(self.current_page_image()) self.flipper.initialize(self.current_page_image(),
forwards=False)
self.document.scroll_to(self.document.xpos, upper_limit) self.document.scroll_to(self.document.xpos, upper_limit)
if epf: if epf:
self.flipper(self.current_page_image(), forwards=False, self.flipper(self.current_page_image(),
duration=self.document.page_flip_duration) duration=self.document.page_flip_duration)
if self.manager is not None: if self.manager is not None:
self.manager.scrolled(self.scroll_fraction) self.manager.scrolled(self.scroll_fraction)
@ -831,10 +836,8 @@ class DocumentView(QWebView):
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)
before_img = None
if epf: if epf:
before_img = self.current_page_image() self.flipper.initialize(self.current_page_image())
self.flipper.initialize(before_img)
#print 'Document height:', self.document.height #print 'Document height:', self.document.height
max_y = self.document.height - window_height max_y = self.document.height - window_height
lower_limit = min(max_y, lower_limit) lower_limit = min(max_y, lower_limit)

View File

@ -29,16 +29,16 @@ class SlideFlip(QWidget):
def running(self): def running(self):
return self.animation.state() == self.animation.Running return self.animation.state() == self.animation.Running
def initialize(self, image): def initialize(self, image, forwards=True):
self.flip_forwards = forwards
self.before_image = QPixmap.fromImage(image) self.before_image = QPixmap.fromImage(image)
self.after_image = None self.after_image = None
self.setGeometry(0, 0, image.width(), image.height()) self.setGeometry(0, 0, image.width(), image.height())
self.setVisible(True) self.setVisible(True)
def __call__(self, image, duration=0.5, forwards=True): def __call__(self, image, duration=0.5):
if self.running: if self.running:
return return
self.flip_forwards = forwards
self.after_image = QPixmap.fromImage(image) self.after_image = QPixmap.fromImage(image)
if self.flip_forwards: if self.flip_forwards: