mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Page flip animation is used when transitioning between flows as well
This commit is contained in:
parent
cf19068002
commit
9b7ebac28a
@ -468,6 +468,7 @@ 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+([^>]+)/>',
|
||||||
@ -646,6 +647,8 @@ 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.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:
|
||||||
@ -708,6 +711,11 @@ 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:
|
||||||
|
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):
|
def turn_off_internal_scrollbars(self):
|
||||||
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
|
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
|
||||||
@ -743,13 +751,19 @@ class DocumentView(QWebView):
|
|||||||
def previous_page(self):
|
def previous_page(self):
|
||||||
if self.flipper.running and not self.is_auto_repeat_event:
|
if self.flipper.running and not self.is_auto_repeat_event:
|
||||||
return
|
return
|
||||||
|
if self.loading_url is not None:
|
||||||
|
return
|
||||||
epf = self.document.enable_page_flip and not self.is_auto_repeat_event
|
epf = self.document.enable_page_flip and not self.is_auto_repeat_event
|
||||||
|
|
||||||
delta_y = self.document.window_height - 25
|
delta_y = self.document.window_height - 25
|
||||||
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.manager.previous_document()
|
self.load_flip_direction = 'previous' if epf else None
|
||||||
|
try:
|
||||||
|
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
|
||||||
@ -768,6 +782,8 @@ class DocumentView(QWebView):
|
|||||||
def next_page(self):
|
def next_page(self):
|
||||||
if self.flipper.running and not self.is_auto_repeat_event:
|
if self.flipper.running and not self.is_auto_repeat_event:
|
||||||
return
|
return
|
||||||
|
if self.loading_url is not None:
|
||||||
|
return
|
||||||
epf = self.document.enable_page_flip and not self.is_auto_repeat_event
|
epf = self.document.enable_page_flip and not self.is_auto_repeat_event
|
||||||
|
|
||||||
window_height = self.document.window_height
|
window_height = self.document.window_height
|
||||||
@ -779,7 +795,11 @@ 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.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:
|
elif ddelta < 25:
|
||||||
self.scroll_by(y=ddelta)
|
self.scroll_by(y=ddelta)
|
||||||
return
|
return
|
||||||
@ -791,7 +811,11 @@ 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.manager.next_document()
|
self.load_flip_direction = 'next' if epf else None
|
||||||
|
try:
|
||||||
|
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
|
||||||
@ -799,7 +823,11 @@ 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.manager.next_document()
|
self.load_flip_direction = 'next' if epf else None
|
||||||
|
try:
|
||||||
|
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)
|
||||||
|
@ -10,6 +10,8 @@ from PyQt4.Qt import QWidget, QPainter, QPropertyAnimation, QEasingCurve, \
|
|||||||
|
|
||||||
class SlideFlip(QWidget):
|
class SlideFlip(QWidget):
|
||||||
|
|
||||||
|
# API {{{
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
|
|
||||||
@ -54,6 +56,8 @@ class SlideFlip(QWidget):
|
|||||||
self.animation.setDuration(duration * 1000)
|
self.animation.setDuration(duration * 1000)
|
||||||
self.animation.start()
|
self.animation.start()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
def finished(self):
|
def finished(self):
|
||||||
self.setVisible(False)
|
self.setVisible(False)
|
||||||
self.before_image = self.after_image = None
|
self.before_image = self.after_image = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user