mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Fix next page scrolling when current document is just a little more than a screenfull. Also use a more robust method to insert blank space at the end of the document when the last screenfull is partially empty.
This commit is contained in:
parent
4ea4986a9d
commit
348b268c7b
@ -384,25 +384,25 @@ class Document(QWebPage):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def height(self):
|
def height(self):
|
||||||
ans = self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results
|
j = self.javascript('document.body.offsetHeight', 'int')
|
||||||
if ans == 0:
|
q = self.mainFrame().contentsSize().height()
|
||||||
ans = self.mainFrame().contentsSize().height()
|
if q == j:
|
||||||
return ans
|
return j
|
||||||
|
if min(j, q) <= 0:
|
||||||
|
return max(j, q)
|
||||||
|
window_height = self.window_height
|
||||||
|
if j == window_height:
|
||||||
|
return j if q < 1.2*j else q
|
||||||
|
return j
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def width(self):
|
def width(self):
|
||||||
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
||||||
|
|
||||||
def set_bottom_padding(self, amount):
|
def set_bottom_padding(self, amount):
|
||||||
body = self.mainFrame().documentElement().findFirst('body')
|
s = QSize(-1, -1) if amount == 0 else QSize(self.width,
|
||||||
if body.isNull():
|
self.height+amount)
|
||||||
return
|
self.setPreferredContentsSize(s)
|
||||||
old_padding = unicode(body.styleProperty('padding-bottom',
|
|
||||||
body.ComputedStyle)).strip()
|
|
||||||
padding = u'%dpx'%amount
|
|
||||||
if old_padding != padding:
|
|
||||||
body.setStyleProperty('padding-bottom', padding + ' !important')
|
|
||||||
|
|
||||||
|
|
||||||
class EntityDeclarationProcessor(object):
|
class EntityDeclarationProcessor(object):
|
||||||
|
|
||||||
@ -705,13 +705,21 @@ class DocumentView(QWebView):
|
|||||||
|
|
||||||
def next_page(self):
|
def next_page(self):
|
||||||
window_height = self.document.window_height
|
window_height = self.document.window_height
|
||||||
|
document_height = self.document.height
|
||||||
|
ddelta = document_height - window_height
|
||||||
|
#print '\nWindow height:', window_height
|
||||||
|
#print 'Document height:', self.document.height
|
||||||
|
|
||||||
delta_y = window_height - 25
|
delta_y = window_height - 25
|
||||||
if self.document.at_bottom:
|
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.manager.next_document()
|
||||||
|
elif ddelta < 25:
|
||||||
|
self.scroll_by(y=ddelta)
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
oopos = self.document.ypos
|
oopos = self.document.ypos
|
||||||
#print '\nOriginal position:', oopos
|
#print 'Original position:', oopos
|
||||||
self.document.set_bottom_padding(0)
|
self.document.set_bottom_padding(0)
|
||||||
opos = self.document.ypos
|
opos = self.document.ypos
|
||||||
#print 'After set padding=0:', self.document.ypos
|
#print 'After set padding=0:', self.document.ypos
|
||||||
@ -722,8 +730,14 @@ class DocumentView(QWebView):
|
|||||||
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
|
||||||
if max_y < lower_limit:
|
if max_y < lower_limit:
|
||||||
|
padding = lower_limit - max_y
|
||||||
|
if padding == window_height:
|
||||||
|
if self.manager is not None:
|
||||||
|
self.manager.next_document()
|
||||||
|
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)
|
||||||
|
#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)
|
||||||
#print 'Scroll to:', lower_limit
|
#print 'Scroll to:', lower_limit
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Ebook Viewer</string>
|
<string>E-book Viewer</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowIcon">
|
<property name="windowIcon">
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
<iconset resource="../../../../resources/images.qrc">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user