mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Cleanup ebook viewer code a little and make PgUp work with Qt 4.5 again
This commit is contained in:
parent
37827a5a2f
commit
a3db47ac48
@ -187,11 +187,11 @@ class Document(QWebPage):
|
|||||||
return unicode(ans.toString())
|
return unicode(ans.toString())
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def scroll_by(self, x=0, y=0):
|
def scroll_by(self, dx=0, dy=0):
|
||||||
self.javascript('window.scrollBy(%d, %d)'%(x, y))
|
self.mainFrame().scroll(dx, dy)
|
||||||
|
|
||||||
def scroll_to(self, x=0, y=0):
|
def scroll_to(self, x=0, y=0):
|
||||||
self.javascript('window.scrollTo(%d, %d)'%(x, y))
|
self.mainFrame().setScrollPosition(QPoint(x, y))
|
||||||
|
|
||||||
def jump_to_anchor(self, anchor):
|
def jump_to_anchor(self, anchor):
|
||||||
self.javascript('document.location.hash = "%s"'%anchor)
|
self.javascript('document.location.hash = "%s"'%anchor)
|
||||||
@ -205,72 +205,54 @@ class Document(QWebPage):
|
|||||||
def bookmark(self):
|
def bookmark(self):
|
||||||
return self.javascript('calculate_bookmark(%d)'%(self.ypos+25), 'string')
|
return self.javascript('calculate_bookmark(%d)'%(self.ypos+25), 'string')
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def at_bottom(self):
|
def at_bottom(self):
|
||||||
def fget(self):
|
return self.height - self.ypos <= self.window_height
|
||||||
return self.height - self.ypos <= self.window_height
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def at_top(self):
|
def at_top(self):
|
||||||
def fget(self):
|
return self.ypos <=0
|
||||||
return self.ypos <= 0
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def ypos(self):
|
def ypos(self):
|
||||||
def fget(self):
|
return self.mainFrame().scrollPosition().y()
|
||||||
return self.javascript('window.pageYOffset', 'int')
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def window_height(self):
|
def window_height(self):
|
||||||
def fget(self):
|
return self.javascript('window.innerHeight', 'int')
|
||||||
return self.javascript('window.innerHeight', 'int')
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def window_width(self):
|
def window_width(self):
|
||||||
def fget(self):
|
return self.javascript('window.innerWidth', 'int')
|
||||||
return self.javascript('window.innerWidth', 'int')
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def xpos(self):
|
def xpos(self):
|
||||||
def fget(self):
|
return self.mainFrame().scrollPosition().x()
|
||||||
return self.javascript('window.pageXOffset', 'int')
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def scroll_fraction(self):
|
def scroll_fraction(self):
|
||||||
def fget(self):
|
try:
|
||||||
try:
|
return float(self.ypos)/(self.height-self.window_height)
|
||||||
return float(self.ypos)/(self.height-self.window_height)
|
except ZeroDivisionError:
|
||||||
except ZeroDivisionError:
|
return 0.
|
||||||
return 0.
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def hscroll_fraction(self):
|
def hscroll_fraction(self):
|
||||||
def fget(self):
|
try:
|
||||||
return float(self.xpos)/self.width
|
return float(self.xpos)/self.width
|
||||||
return property(fget=fget)
|
except ZeroDivisionError:
|
||||||
|
return 0.
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def height(self):
|
def height(self):
|
||||||
def fget(self):
|
return self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results
|
||||||
return self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def width(self):
|
def width(self):
|
||||||
def fget(self):
|
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
||||||
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
class EntityDeclarationProcessor(object):
|
class EntityDeclarationProcessor(object):
|
||||||
|
|
||||||
@ -346,23 +328,17 @@ class DocumentView(QWebView):
|
|||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
return self._size_hint
|
return self._size_hint
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def scroll_fraction(self):
|
def scroll_fraction(self):
|
||||||
def fget(self):
|
return self.document.scroll_fraction
|
||||||
return self.document.scroll_fraction
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def hscroll_fraction(self):
|
def hscroll_fraction(self):
|
||||||
def fget(self):
|
return self.document.hscroll_fraction
|
||||||
return self.document.hscroll_fraction
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
@dynamic_property
|
@property
|
||||||
def content_size(self):
|
def content_size(self):
|
||||||
def fget(self):
|
return self.document.width, self.document.height
|
||||||
return self.document.width, self.document.height
|
|
||||||
return property(fget=fget)
|
|
||||||
|
|
||||||
def search(self, text):
|
def search(self, text):
|
||||||
return self.findText(text)
|
return self.findText(text)
|
||||||
@ -393,8 +369,6 @@ class DocumentView(QWebView):
|
|||||||
self.scrollbar.setVisible(delta > 0)
|
self.scrollbar.setVisible(delta > 0)
|
||||||
|
|
||||||
def load_finished(self, ok):
|
def load_finished(self, ok):
|
||||||
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
|
|
||||||
self.document.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
|
|
||||||
self._size_hint = self.document.mainFrame().contentsSize()
|
self._size_hint = self.document.mainFrame().contentsSize()
|
||||||
scrolled = False
|
scrolled = False
|
||||||
if self.to_bottom:
|
if self.to_bottom:
|
||||||
@ -413,6 +387,8 @@ class DocumentView(QWebView):
|
|||||||
self.document.set_reference_prefix('%d.'%(spine_index+1))
|
self.document.set_reference_prefix('%d.'%(spine_index+1))
|
||||||
if scrolled:
|
if scrolled:
|
||||||
self.manager.scrolled(self.document.scroll_fraction)
|
self.manager.scrolled(self.document.scroll_fraction)
|
||||||
|
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
|
||||||
|
self.document.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -435,21 +411,18 @@ class DocumentView(QWebView):
|
|||||||
self.scroll_by(y=overlap)
|
self.scroll_by(y=overlap)
|
||||||
|
|
||||||
def previous_page(self):
|
def previous_page(self):
|
||||||
|
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.manager.previous_document()
|
self.manager.previous_document()
|
||||||
self.to_bottom = True
|
self.to_bottom = True
|
||||||
else:
|
else:
|
||||||
opos = self.document.ypos
|
opos = self.document.ypos
|
||||||
while True:
|
upper_limit = opos - delta_y
|
||||||
delta = abs(opos-self.document.ypos)
|
if upper_limit < 0:
|
||||||
if delta > self.size().height():
|
upper_limit = 0
|
||||||
self.wheel_event(down=True)
|
if upper_limit < opos:
|
||||||
break
|
self.document.scroll_to(self.document.xpos, upper_limit)
|
||||||
pre = self.document.ypos
|
|
||||||
self.wheel_event(down=False)
|
|
||||||
if pre == self.document.ypos:
|
|
||||||
break
|
|
||||||
if self.manager is not None:
|
if self.manager is not None:
|
||||||
self.manager.scrolled(self.scroll_fraction)
|
self.manager.scrolled(self.scroll_fraction)
|
||||||
|
|
||||||
@ -477,7 +450,6 @@ class DocumentView(QWebView):
|
|||||||
if self.manager is not None:
|
if self.manager is not None:
|
||||||
self.manager.scrolled(self.scroll_fraction)
|
self.manager.scrolled(self.scroll_fraction)
|
||||||
|
|
||||||
|
|
||||||
def scroll_by(self, x=0, y=0, notify=True):
|
def scroll_by(self, x=0, y=0, notify=True):
|
||||||
old_pos = self.document.ypos
|
old_pos = self.document.ypos
|
||||||
self.document.scroll_by(x, y)
|
self.document.scroll_by(x, y)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user