mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Viewer: Auto-expand entries in the Table of Contents when viewing the corresponding location in the book.
This commit is contained in:
parent
ccce39da50
commit
d6ee7238bb
@ -51,6 +51,14 @@ class TOCView(QTreeView):
|
||||
self.customContextMenuRequested.connect(self.context_menu)
|
||||
QApplication.instance().palette_changed.connect(self.set_style_sheet, type=Qt.QueuedConnection)
|
||||
|
||||
def setModel(self, model):
|
||||
QTreeView.setModel(self, model)
|
||||
model.auto_expand_nodes.connect(self.auto_expand_indices, type=Qt.QueuedConnection)
|
||||
|
||||
def auto_expand_indices(self, indices):
|
||||
for idx in indices:
|
||||
self.setExpanded(idx, True)
|
||||
|
||||
def set_style_sheet(self):
|
||||
self.setStyleSheet('''
|
||||
QTreeView {
|
||||
@ -195,6 +203,8 @@ class TOCItem(QStandardItem):
|
||||
|
||||
class TOC(QStandardItemModel):
|
||||
|
||||
auto_expand_nodes = pyqtSignal(object)
|
||||
|
||||
def __init__(self, toc=None):
|
||||
QStandardItemModel.__init__(self)
|
||||
self.current_query = {'text':'', 'index':-1, 'items':()}
|
||||
@ -244,6 +254,7 @@ class TOC(QStandardItemModel):
|
||||
if node is not None:
|
||||
viewed_nodes |= {x.node_id for x in node.ancestors}
|
||||
viewed_nodes.add(node.node_id)
|
||||
self.auto_expand_nodes.emit([n.index() for n in node.ancestors])
|
||||
for node in self.all_items:
|
||||
is_being_viewed = node.node_id in viewed_nodes
|
||||
if is_being_viewed != node.is_being_viewed:
|
||||
|
Loading…
x
Reference in New Issue
Block a user