diff --git a/nw/gui/noveltree.py b/nw/gui/noveltree.py index 9c9e562b..bbb3948f 100644 --- a/nw/gui/noveltree.py +++ b/nw/gui/noveltree.py @@ -77,6 +77,10 @@ class GuiNovelTree(QTreeWidget): treeHeadItem.setToolTip(self.C_WORDS, "Word count") treeHeadItem.setToolTip(self.C_POV, "Point-of-view character") + treeHeader = self.header() + treeHeader.setStretchLastSection(True) + treeHeader.setMinimumSectionSize(iPx + 6) + # Get user's column width preferences for NAME and COUNT treeColWidth = self.mainConf.getNovelColWidths() if len(treeColWidth) <= 3: @@ -161,6 +165,35 @@ class GuiNovelTree(QTreeWidget): return None + ## + # Events + ## + + def mousePressEvent(self, theEvent): + """Overload mousePressEvent to clear selection if clicking the + mouse in a blank area of the tree view, and to load a document + for viewing if the user middle-clicked. + """ + QTreeWidget.mousePressEvent(self, theEvent) + + if theEvent.button() == Qt.LeftButton: + selItem = self.indexAt(theEvent.pos()) + if not selItem.isValid(): + self.clearSelection() + + elif theEvent.button() == Qt.MiddleButton: + selItem = self.itemAt(theEvent.pos()) + if not isinstance(selItem, QTreeWidgetItem): + return + + tHandle = self.getSelectedHandle() + if tHandle is None: + return + + self.theParent.viewDocument(tHandle) + + return + ## # Slots ## diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 290c4391..79e6dcd9 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -699,7 +699,7 @@ class GuiProjectTree(QTreeWidget): def mousePressEvent(self, theEvent): """Overload mousePressEvent to clear selection if clicking the mouse in a blank area of the tree view, and to load a document - for viewing if the suer middle clicked. + for viewing if the user middle-clicked. """ QTreeWidget.mousePressEvent(self, theEvent) diff --git a/nw/guimain.py b/nw/guimain.py index 4efba144..fb1808c9 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -269,6 +269,7 @@ class GuiMain(QMainWindow): """Wrapper function to clear all sub-elements of the main GUI. """ self.treeView.clearTree() + self.novelView.clearTree() self.docEditor.clearEditor() self.closeDocViewer() self.statusBar.clearStatus() @@ -878,6 +879,7 @@ class GuiMain(QMainWindow): self.docEditor.initEditor() self.docViewer.initViewer() self.treeView.initTree() + self.novelView.initTree() self.projView.initOutline() self.projMeta.initDetails() @@ -1381,19 +1383,19 @@ class GuiMain(QMainWindow): def _projTabsChanged(self, tabIndex): """Activated when the project view tab is changed. """ - tHandle = None + sHandle = None if tabIndex == self.idxTreeView: logger.verbose("Project tree tab activated") - tHandle = self.treeView.getSelectedHandle() + sHandle = self.treeView.getSelectedHandle() elif tabIndex == self.idxNovelView: logger.verbose("Novel tree tab activated") if self.hasProject: self.novelView.refreshTree() - tHandle = self.novelView.getSelectedHandle() + sHandle = self.novelView.getSelectedHandle() - self.treeMeta.updateViewBox(tHandle) + self.treeMeta.updateViewBox(sHandle) return