Scroll novel view when looping through documents (#1555)

This commit is contained in:
Veronica Berglyd Olsen
2023-11-29 20:55:05 +01:00
parent ef93b41240
commit ce666d9d7a
2 changed files with 7 additions and 9 deletions
+6 -8
View File
@@ -567,27 +567,25 @@ class GuiNovelTree(QTreeWidget):
self._lastColSize = minmax(colSize, 15, 75)/100.0 self._lastColSize = minmax(colSize, 15, 75)/100.0
return return
def setActiveHandle(self, tHandle: str | None) -> None: def setActiveHandle(self, tHandle: str | None, doScroll: bool = False) -> None:
"""Highlight the rows associated with a given handle.""" """Highlight the rows associated with a given handle."""
tStart = time() didScroll = False
self._actHandle = tHandle self._actHandle = tHandle
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
tItem = self.topLevelItem(i) if tItem := self.topLevelItem(i):
if tItem is not None:
if tItem.data(self.C_DATA, self.D_HANDLE) == tHandle: if tItem.data(self.C_DATA, self.D_HANDLE) == tHandle:
tItem.setBackground(self.C_TITLE, self.palette().alternateBase()) tItem.setBackground(self.C_TITLE, self.palette().alternateBase())
tItem.setBackground(self.C_WORDS, self.palette().alternateBase()) tItem.setBackground(self.C_WORDS, self.palette().alternateBase())
tItem.setBackground(self.C_EXTRA, self.palette().alternateBase()) tItem.setBackground(self.C_EXTRA, self.palette().alternateBase())
tItem.setBackground(self.C_MORE, self.palette().alternateBase()) tItem.setBackground(self.C_MORE, self.palette().alternateBase())
if doScroll and not didScroll:
self.scrollToItem(tItem, QAbstractItemView.ScrollHint.PositionAtCenter)
didScroll = True
else: else:
tItem.setBackground(self.C_TITLE, self.palette().base()) tItem.setBackground(self.C_TITLE, self.palette().base())
tItem.setBackground(self.C_WORDS, self.palette().base()) tItem.setBackground(self.C_WORDS, self.palette().base())
tItem.setBackground(self.C_EXTRA, self.palette().base()) tItem.setBackground(self.C_EXTRA, self.palette().base())
tItem.setBackground(self.C_MORE, self.palette().base()) tItem.setBackground(self.C_MORE, self.palette().base())
logger.debug("Highlighted Novel Tree in %.3f ms", (time() - tStart)*1000)
return return
## ##
+1 -1
View File
@@ -606,7 +606,7 @@ class GuiMain(QMainWindow):
if self.docEditor.loadText(tHandle, tLine): if self.docEditor.loadText(tHandle, tLine):
SHARED.project.data.setLastHandle(tHandle, "editor") SHARED.project.data.setLastHandle(tHandle, "editor")
self.projView.setSelectedHandle(tHandle, doScroll=doScroll) self.projView.setSelectedHandle(tHandle, doScroll=doScroll)
self.novelView.setActiveHandle(tHandle) self.novelView.setActiveHandle(tHandle, doScroll=doScroll)
if changeFocus: if changeFocus:
self.docEditor.setFocus() self.docEditor.setFocus()
else: else: