Add a button to open the novel tree root selector

This commit is contained in:
Veronica Berglyd Olsen
2022-11-22 12:33:32 +01:00
parent b7373688e7
commit 55f7a91eaf
3 changed files with 21 additions and 12 deletions
+3 -2
View File
@@ -40,11 +40,12 @@ class NovelSelector(QComboBox):
novelSelectionChanged = pyqtSignal(str)
def __init__(self, parent, project, theme):
def __init__(self, parent, project, mainGui):
super().__init__(parent=parent)
self._mainGui = mainGui
self._project = project
self._theme = theme
self._theme = mainGui.mainTheme
self._blockSignal = False
self.currentIndexChanged.connect(self._indexChanged)
+17 -9
View File
@@ -191,6 +191,7 @@ class GuiNovelToolBar(QWidget):
self.mainConf = novelwriter.CONFIG
self.novelView = novelView
self.mainGui = novelView.mainGui
self.theProject = novelView.mainGui.theProject
self.mainTheme = novelView.mainGui.mainTheme
@@ -204,12 +205,17 @@ class GuiNovelToolBar(QWidget):
selFont = self.font()
selFont.setWeight(QFont.Bold)
self.novelPrefix = self.tr("Outline of {0}")
self.novelValue = NovelSelector(self, self.theProject, self.mainTheme)
self.novelValue = NovelSelector(self, self.theProject, self.mainGui)
self.novelValue.setFont(selFont)
self.novelValue.setMinimumWidth(self.mainConf.pxInt(150))
self.novelValue.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.novelValue.novelSelectionChanged.connect(self.setCurrentRoot)
self.tbNovel = QToolButton(self)
self.tbNovel.setToolTip(self.tr("Novel Root"))
self.tbNovel.setIconSize(QSize(iPx, iPx))
self.tbNovel.clicked.connect(self._openNovelSelector)
# Refresh Button
self.tbRefresh = QToolButton(self)
self.tbRefresh.setToolTip(self.tr("Refresh"))
@@ -236,6 +242,7 @@ class GuiNovelToolBar(QWidget):
# Assemble
self.outerBox = QHBoxLayout()
self.outerBox.addWidget(self.novelValue)
self.outerBox.addWidget(self.tbNovel)
self.outerBox.addWidget(self.tbRefresh)
self.outerBox.addWidget(self.tbMore)
self.outerBox.setContentsMargins(mPx, mPx, 0, mPx)
@@ -257,6 +264,7 @@ class GuiNovelToolBar(QWidget):
"""Update theme elements.
"""
# Icons
self.tbNovel.setIcon(self.mainTheme.getIcon("cls_novel"))
self.tbRefresh.setIcon(self.mainTheme.getIcon("refresh"))
self.tbMore.setIcon(self.mainTheme.getIcon("menu"))
@@ -271,6 +279,7 @@ class GuiNovelToolBar(QWidget):
"QToolButton:hover {{border: none; background: rgba({1},{2},{3},0.2);}}"
).format(self.mainConf.pxInt(2), fadeCol.red(), fadeCol.green(), fadeCol.blue())
self.tbNovel.setStyleSheet(buttonStyle)
self.tbRefresh.setStyleSheet(buttonStyle)
self.tbMore.setStyleSheet(buttonStyle)
@@ -279,10 +288,7 @@ class GuiNovelToolBar(QWidget):
"QComboBox::drop-down {border-style: none}"
)
self.novelValue.updateList(prefix=self.novelPrefix)
if self.novelValue.count() > 1:
self.novelValue.setToolTip(self.tr("Click to change root folder"))
else:
self.novelValue.setToolTip("")
self.tbNovel.setVisible(self.novelValue.count() > 1)
return
@@ -297,10 +303,7 @@ class GuiNovelToolBar(QWidget):
"""Build the novel root menu.
"""
self.novelValue.updateList(prefix=self.novelPrefix)
if self.novelValue.count() > 1:
self.novelValue.setToolTip(self.tr("Click to change root folder"))
else:
self.novelValue.setToolTip("")
self.tbNovel.setVisible(self.novelValue.count() > 1)
return
def setCurrentRoot(self, rootHandle):
@@ -321,6 +324,11 @@ class GuiNovelToolBar(QWidget):
# Private Slots
##
@pyqtSlot()
def _openNovelSelector(self):
self.novelValue.showPopup()
return
@pyqtSlot()
def _refreshNovelTree(self):
"""Rebuild the current tree.
+1 -1
View File
@@ -234,7 +234,7 @@ class GuiOutlineToolBar(QToolBar):
self.novelLabel = QLabel(self.tr("Outline of"))
self.novelLabel.setContentsMargins(0, 0, mPx, 0)
self.novelValue = NovelSelector(self, self.theProject, self.mainTheme)
self.novelValue = NovelSelector(self, self.theProject, self.mainGui)
self.novelValue.setMinimumWidth(self.mainConf.pxInt(200))
self.novelValue.novelSelectionChanged.connect(self._novelValueChanged)