This commit is contained in:
Kovid Goyal 2012-05-29 23:53:58 +05:30
parent 227f696597
commit e692460c6c
2 changed files with 17 additions and 4 deletions

View File

@ -671,7 +671,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
def goto_next_section(self): def goto_next_section(self):
if hasattr(self, 'current_index'): 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: if entry is not None:
self.pending_goto_next_section = ( self.pending_goto_next_section = (
self.toc_model.currently_viewed_entry, entry, False) self.toc_model.currently_viewed_entry, entry, False)
@ -679,7 +681,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
def goto_previous_section(self): def goto_previous_section(self):
if hasattr(self, 'current_index'): 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: if entry is not None:
self.pending_goto_next_section = ( self.pending_goto_next_section = (
self.toc_model.currently_viewed_entry, entry, True) self.toc_model.currently_viewed_entry, entry, True)
@ -699,6 +703,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
# Check that we actually progressed # Check that we actually progressed
if pgns[0] is self.toc_model.currently_viewed_entry: if pgns[0] is self.toc_model.currently_viewed_entry:
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,
backwards=pgns[2], current_entry=pgns[1]) backwards=pgns[2], current_entry=pgns[1])
if entry is not None: if entry is not None:
self.pending_goto_next_section = ( self.pending_goto_next_section = (

View File

@ -33,7 +33,7 @@ class TOCItem(QStandardItem):
self.normal_font = self.font() self.normal_font = self.font()
for t in toc: for t in toc:
self.appendRow(TOCItem(spine, t, depth+1, all_items, parent=self)) self.appendRow(TOCItem(spine, t, depth+1, all_items, parent=self))
self.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) self.setFlags(Qt.ItemIsEnabled)
spos = 0 spos = 0
for i, si in enumerate(spine): for i, si in enumerate(spine):
if si == self.abspath: if si == self.abspath:
@ -131,14 +131,21 @@ class TOC(QStandardItemModel):
self.currently_viewed_entry = t self.currently_viewed_entry = t
return items_being_viewed 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 current_entry = (self.currently_viewed_entry if current_entry is None
else current_entry) else current_entry)
if current_entry is None: return if current_entry is None: return
items = reversed(self.all_items) if backwards else self.all_items items = reversed(self.all_items) if backwards else self.all_items
found = False found = False
top = scroll_pos[0]
for item in items: for item in items:
if found: 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: if item.starts_at != spine_pos or item.start_anchor:
return item return item
if item is current_entry: if item is current_entry: