From 469275eea5a6f938a3793a60a01d48ed85621d4c Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 15 Jun 2022 19:39:07 +0200 Subject: [PATCH] Add novel tree highlight of rows of current document --- novelwriter/assets/themes/default_dark.conf | 2 +- novelwriter/assets/themes/solarized_dark.conf | 2 +- novelwriter/gui/noveltree.py | 29 +++++++++++++++++-- novelwriter/guimain.py | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/novelwriter/assets/themes/default_dark.conf b/novelwriter/assets/themes/default_dark.conf index 14d0ad51..44317ac1 100644 --- a/novelwriter/assets/themes/default_dark.conf +++ b/novelwriter/assets/themes/default_dark.conf @@ -10,7 +10,7 @@ licenseurl = https://creativecommons.org/licenses/by-sa/4.0/ window = 54, 54, 54 windowtext = 174, 174, 174 base = 62, 62, 62 -alternatebase = 67, 67, 67 +alternatebase = 78, 78, 78 text = 174, 174, 174 tooltipbase = 255, 255, 192 tooltiptext = 21, 21, 13 diff --git a/novelwriter/assets/themes/solarized_dark.conf b/novelwriter/assets/themes/solarized_dark.conf index 81a85a16..812d968d 100644 --- a/novelwriter/assets/themes/solarized_dark.conf +++ b/novelwriter/assets/themes/solarized_dark.conf @@ -10,7 +10,7 @@ licenseurl = https://github.com/altercation/solarized/blob/master/LICENSE window = 0, 43, 54 windowtext = 253, 246, 227 base = 7, 54, 66 -alternatebase = 67, 67, 67 +alternatebase = 0, 43, 54 text = 253, 246, 227 tooltipbase = 133, 153, 0 tooltiptext = 0, 43, 54 diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index 711a71e3..9dd0f78c 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -84,6 +84,7 @@ class GuiNovelView(QWidget): # Function Mappings self.updateWordCounts = self.novelTree.updateWordCounts self.getSelectedHandle = self.novelTree.getSelectedHandle + self.setActiveHandle = self.novelTree.setActiveHandle return @@ -505,6 +506,23 @@ class GuiNovelTree(QTreeWidget): self.refreshTree(rootHandle=self.theProject.lastNovel, overRide=True) return + def setActiveHandle(self, tHandle): + """Highlight the rows associated with a given handle. + """ + for i in range(self.topLevelItemCount()): + tItem = self.topLevelItem(i) + if tItem.data(self.C_TITLE, self.D_HANDLE) == tHandle: + tItem.setBackground(self.C_TITLE, self.palette().alternateBase()) + tItem.setBackground(self.C_WORDS, self.palette().alternateBase()) + tItem.setBackground(self.C_EXTRA, self.palette().alternateBase()) + tItem.setBackground(self.C_MORE, self.palette().alternateBase()) + else: + tItem.setBackground(self.C_TITLE, self.palette().base()) + tItem.setBackground(self.C_WORDS, self.palette().base()) + tItem.setBackground(self.C_EXTRA, self.palette().base()) + tItem.setBackground(self.C_MORE, self.palette().base()) + return + ## # Events ## @@ -534,6 +552,13 @@ class GuiNovelTree(QTreeWidget): return + def focusOutEvent(self, theEvent): + """Clear the selection when the tree no longer has focus. + """ + QTreeWidget.focusOutEvent(self, theEvent) + self.clearSelection() + return + ## # Private Slots ## @@ -596,14 +621,14 @@ class GuiNovelTree(QTreeWidget): newItem.setFont(self.C_TITLE, self._hFonts[iLevel]) newItem.setText(self.C_WORDS, f"{novIdx.wordCount:n}") newItem.setTextAlignment(self.C_WORDS, Qt.AlignRight) + newItem.setData(self.C_MORE, Qt.DecorationRole, self._pMore) + # Custom column lastText, toolTip = self._getLastColumnText(tHandle, sTitle) newItem.setText(self.C_EXTRA, lastText) if lastText: newItem.setToolTip(self.C_EXTRA, toolTip) - newItem.setData(self.C_MORE, Qt.DecorationRole, self._pMore) - self._treeMap[tKey] = newItem self.addTopLevelItem(newItem) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index e9535747..5cbecf7a 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -573,6 +573,7 @@ class GuiMain(QMainWindow): if self.docEditor.docChanged(): self.saveDocument() self.docEditor.clearEditor() + self.novelView.setActiveHandle(None) return True @@ -594,6 +595,7 @@ class GuiMain(QMainWindow): self.docEditor.setFocus() self.theProject.setLastEdited(tHandle) self.projView.setSelectedHandle(tHandle, doScroll=doScroll) + self.novelView.setActiveHandle(tHandle) else: return False