mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
227f696597
commit
e692460c6c
@ -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 = (
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user