From 55f7a91eaf0203f6f96a18ec455a5fa5f4d360d3 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:33:32 +0100 Subject: [PATCH] Add a button to open the novel tree root selector --- novelwriter/gui/components.py | 5 +++-- novelwriter/gui/noveltree.py | 26 +++++++++++++++++--------- novelwriter/gui/outline.py | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/novelwriter/gui/components.py b/novelwriter/gui/components.py index 35234d40..57489cf6 100644 --- a/novelwriter/gui/components.py +++ b/novelwriter/gui/components.py @@ -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) diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index d7b38a21..740a7819 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -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. diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index 9cfd3d86..16e8c0fe 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -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)