Add novel tree highlight of rows of current document

This commit is contained in:
Veronica Berglyd Olsen
2022-06-15 19:39:07 +02:00
parent ba0ce33cfc
commit 469275eea5
4 changed files with 31 additions and 4 deletions
+1 -1
View File
@@ -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
@@ -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
+27 -2
View File
@@ -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)
+2
View File
@@ -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