mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
E-book viewer: Fix bug that was causing viewer to sometimes not scroll to the top of the page when clicking a link in the Table of Contents that points to the top of the page.
This commit is contained in:
parent
1ae9666d87
commit
b1f5c25405
@ -368,6 +368,7 @@ class DocumentView(QWebView):
|
|||||||
self.setPage(self.document)
|
self.setPage(self.document)
|
||||||
self.manager = None
|
self.manager = None
|
||||||
self._reference_mode = False
|
self._reference_mode = False
|
||||||
|
self._ignore_scrollbar_signals = False
|
||||||
self.connect(self.document, SIGNAL('loadStarted()'), self.load_started)
|
self.connect(self.document, SIGNAL('loadStarted()'), self.load_started)
|
||||||
self.connect(self.document, SIGNAL('loadFinished(bool)'), self.load_finished)
|
self.connect(self.document, SIGNAL('loadFinished(bool)'), self.load_finished)
|
||||||
self.connect(self.document, SIGNAL('linkClicked(QUrl)'), self.link_clicked)
|
self.connect(self.document, SIGNAL('linkClicked(QUrl)'), self.link_clicked)
|
||||||
@ -467,13 +468,16 @@ class DocumentView(QWebView):
|
|||||||
if getattr(self, 'scrollbar', None) is not None:
|
if getattr(self, 'scrollbar', None) is not None:
|
||||||
delta = self.document.width - self.size().width()
|
delta = self.document.width - self.size().width()
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
|
self._ignore_scrollbar_signals = True
|
||||||
self.scrollbar.blockSignals(True)
|
self.scrollbar.blockSignals(True)
|
||||||
self.scrollbar.setRange(0, delta)
|
self.scrollbar.setRange(0, delta)
|
||||||
self.scrollbar.setValue(0)
|
self.scrollbar.setValue(0)
|
||||||
self.scrollbar.setSingleStep(1)
|
self.scrollbar.setSingleStep(1)
|
||||||
self.scrollbar.setPageStep(int(delta/10.))
|
self.scrollbar.setPageStep(int(delta/10.))
|
||||||
self.scrollbar.blockSignals(False)
|
|
||||||
self.scrollbar.setVisible(delta > 0)
|
self.scrollbar.setVisible(delta > 0)
|
||||||
|
self.scrollbar.blockSignals(False)
|
||||||
|
self._ignore_scrollbar_signals = False
|
||||||
|
|
||||||
|
|
||||||
def load_finished(self, ok):
|
def load_finished(self, ok):
|
||||||
self._size_hint = self.document.mainFrame().contentsSize()
|
self._size_hint = self.document.mainFrame().contentsSize()
|
||||||
@ -565,6 +569,8 @@ class DocumentView(QWebView):
|
|||||||
self.manager.scrolled(self.scroll_fraction)
|
self.manager.scrolled(self.scroll_fraction)
|
||||||
|
|
||||||
def scroll_to(self, pos, notify=True):
|
def scroll_to(self, pos, notify=True):
|
||||||
|
if self._ignore_scrollbar_signals:
|
||||||
|
return
|
||||||
old_pos = self.document.ypos
|
old_pos = self.document.ypos
|
||||||
if isinstance(pos, basestring):
|
if isinstance(pos, basestring):
|
||||||
self.document.jump_to_anchor(pos)
|
self.document.jump_to_anchor(pos)
|
||||||
@ -572,8 +578,9 @@ class DocumentView(QWebView):
|
|||||||
if pos >= 1:
|
if pos >= 1:
|
||||||
self.document.scroll_to(0, self.document.height)
|
self.document.scroll_to(0, self.document.height)
|
||||||
else:
|
else:
|
||||||
self.document.scroll_to(0, int(math.ceil(
|
y = int(math.ceil(
|
||||||
pos*(self.document.height-self.document.window_height))))
|
pos*(self.document.height-self.document.window_height)))
|
||||||
|
self.document.scroll_to(0, y)
|
||||||
if notify and self.manager is not None and self.document.ypos != old_pos:
|
if notify and self.manager is not None and self.document.ypos != old_pos:
|
||||||
self.manager.scrolled(self.scroll_fraction)
|
self.manager.scrolled(self.scroll_fraction)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user