From e692460c6c9d0d8aea09ed914ce06a8fc8fe5524 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 29 May 2012 23:53:58 +0530 Subject: [PATCH] ... --- src/calibre/gui2/viewer/main.py | 10 ++++++++-- src/calibre/gui2/viewer/toc.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 48927f0e4a..0ce6c3d48b 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -671,7 +671,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer): def goto_next_section(self): if hasattr(self, 'current_index'): - entry = self.toc_model.next_entry(self.current_index) + entry = self.toc_model.next_entry(self.current_index, + self.view.document.read_anchor_positions(), + self.view.scroll_pos) if entry is not None: self.pending_goto_next_section = ( self.toc_model.currently_viewed_entry, entry, False) @@ -679,7 +681,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer): def goto_previous_section(self): if hasattr(self, 'current_index'): - entry = self.toc_model.next_entry(self.current_index, backwards=True) + entry = self.toc_model.next_entry(self.current_index, + self.view.document.read_anchor_positions(), + self.view.scroll_pos, backwards=True) if entry is not None: self.pending_goto_next_section = ( self.toc_model.currently_viewed_entry, entry, True) @@ -699,6 +703,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer): # Check that we actually progressed if pgns[0] is self.toc_model.currently_viewed_entry: entry = self.toc_model.next_entry(self.current_index, + self.view.document.read_anchor_positions(), + self.view.scroll_pos, backwards=pgns[2], current_entry=pgns[1]) if entry is not None: self.pending_goto_next_section = ( diff --git a/src/calibre/gui2/viewer/toc.py b/src/calibre/gui2/viewer/toc.py index bb0510471e..0cb4e5b22e 100644 --- a/src/calibre/gui2/viewer/toc.py +++ b/src/calibre/gui2/viewer/toc.py @@ -33,7 +33,7 @@ class TOCItem(QStandardItem): self.normal_font = self.font() for t in toc: self.appendRow(TOCItem(spine, t, depth+1, all_items, parent=self)) - self.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) + self.setFlags(Qt.ItemIsEnabled) spos = 0 for i, si in enumerate(spine): if si == self.abspath: @@ -131,14 +131,21 @@ class TOC(QStandardItemModel): self.currently_viewed_entry = t return items_being_viewed - def next_entry(self, spine_pos, backwards=False, current_entry=None): + def next_entry(self, spine_pos, anchor_map, scroll_pos, backwards=False, + current_entry=None): current_entry = (self.currently_viewed_entry if current_entry is None else current_entry) if current_entry is None: return items = reversed(self.all_items) if backwards else self.all_items found = False + top = scroll_pos[0] for item in items: if found: + start_pos = anchor_map.get(item.start_anchor, 0) + if backwards and item.is_being_viewed and start_pos >= top: + # Going to this item will either not move the scroll + # position or cause to to *increase* instead of descresing + continue if item.starts_at != spine_pos or item.start_anchor: return item if item is current_entry: