Add a button to open the novel tree root selector
This commit is contained in:
@@ -40,11 +40,12 @@ class NovelSelector(QComboBox):
|
|||||||
|
|
||||||
novelSelectionChanged = pyqtSignal(str)
|
novelSelectionChanged = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, parent, project, theme):
|
def __init__(self, parent, project, mainGui):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
|
self._mainGui = mainGui
|
||||||
self._project = project
|
self._project = project
|
||||||
self._theme = theme
|
self._theme = mainGui.mainTheme
|
||||||
self._blockSignal = False
|
self._blockSignal = False
|
||||||
self.currentIndexChanged.connect(self._indexChanged)
|
self.currentIndexChanged.connect(self._indexChanged)
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ class GuiNovelToolBar(QWidget):
|
|||||||
|
|
||||||
self.mainConf = novelwriter.CONFIG
|
self.mainConf = novelwriter.CONFIG
|
||||||
self.novelView = novelView
|
self.novelView = novelView
|
||||||
|
self.mainGui = novelView.mainGui
|
||||||
self.theProject = novelView.mainGui.theProject
|
self.theProject = novelView.mainGui.theProject
|
||||||
self.mainTheme = novelView.mainGui.mainTheme
|
self.mainTheme = novelView.mainGui.mainTheme
|
||||||
|
|
||||||
@@ -204,12 +205,17 @@ class GuiNovelToolBar(QWidget):
|
|||||||
selFont = self.font()
|
selFont = self.font()
|
||||||
selFont.setWeight(QFont.Bold)
|
selFont.setWeight(QFont.Bold)
|
||||||
self.novelPrefix = self.tr("Outline of {0}")
|
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.setFont(selFont)
|
||||||
self.novelValue.setMinimumWidth(self.mainConf.pxInt(150))
|
self.novelValue.setMinimumWidth(self.mainConf.pxInt(150))
|
||||||
self.novelValue.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
self.novelValue.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||||
self.novelValue.novelSelectionChanged.connect(self.setCurrentRoot)
|
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
|
# Refresh Button
|
||||||
self.tbRefresh = QToolButton(self)
|
self.tbRefresh = QToolButton(self)
|
||||||
self.tbRefresh.setToolTip(self.tr("Refresh"))
|
self.tbRefresh.setToolTip(self.tr("Refresh"))
|
||||||
@@ -236,6 +242,7 @@ class GuiNovelToolBar(QWidget):
|
|||||||
# Assemble
|
# Assemble
|
||||||
self.outerBox = QHBoxLayout()
|
self.outerBox = QHBoxLayout()
|
||||||
self.outerBox.addWidget(self.novelValue)
|
self.outerBox.addWidget(self.novelValue)
|
||||||
|
self.outerBox.addWidget(self.tbNovel)
|
||||||
self.outerBox.addWidget(self.tbRefresh)
|
self.outerBox.addWidget(self.tbRefresh)
|
||||||
self.outerBox.addWidget(self.tbMore)
|
self.outerBox.addWidget(self.tbMore)
|
||||||
self.outerBox.setContentsMargins(mPx, mPx, 0, mPx)
|
self.outerBox.setContentsMargins(mPx, mPx, 0, mPx)
|
||||||
@@ -257,6 +264,7 @@ class GuiNovelToolBar(QWidget):
|
|||||||
"""Update theme elements.
|
"""Update theme elements.
|
||||||
"""
|
"""
|
||||||
# Icons
|
# Icons
|
||||||
|
self.tbNovel.setIcon(self.mainTheme.getIcon("cls_novel"))
|
||||||
self.tbRefresh.setIcon(self.mainTheme.getIcon("refresh"))
|
self.tbRefresh.setIcon(self.mainTheme.getIcon("refresh"))
|
||||||
self.tbMore.setIcon(self.mainTheme.getIcon("menu"))
|
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);}}"
|
"QToolButton:hover {{border: none; background: rgba({1},{2},{3},0.2);}}"
|
||||||
).format(self.mainConf.pxInt(2), fadeCol.red(), fadeCol.green(), fadeCol.blue())
|
).format(self.mainConf.pxInt(2), fadeCol.red(), fadeCol.green(), fadeCol.blue())
|
||||||
|
|
||||||
|
self.tbNovel.setStyleSheet(buttonStyle)
|
||||||
self.tbRefresh.setStyleSheet(buttonStyle)
|
self.tbRefresh.setStyleSheet(buttonStyle)
|
||||||
self.tbMore.setStyleSheet(buttonStyle)
|
self.tbMore.setStyleSheet(buttonStyle)
|
||||||
|
|
||||||
@@ -279,10 +288,7 @@ class GuiNovelToolBar(QWidget):
|
|||||||
"QComboBox::drop-down {border-style: none}"
|
"QComboBox::drop-down {border-style: none}"
|
||||||
)
|
)
|
||||||
self.novelValue.updateList(prefix=self.novelPrefix)
|
self.novelValue.updateList(prefix=self.novelPrefix)
|
||||||
if self.novelValue.count() > 1:
|
self.tbNovel.setVisible(self.novelValue.count() > 1)
|
||||||
self.novelValue.setToolTip(self.tr("Click to change root folder"))
|
|
||||||
else:
|
|
||||||
self.novelValue.setToolTip("")
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -297,10 +303,7 @@ class GuiNovelToolBar(QWidget):
|
|||||||
"""Build the novel root menu.
|
"""Build the novel root menu.
|
||||||
"""
|
"""
|
||||||
self.novelValue.updateList(prefix=self.novelPrefix)
|
self.novelValue.updateList(prefix=self.novelPrefix)
|
||||||
if self.novelValue.count() > 1:
|
self.tbNovel.setVisible(self.novelValue.count() > 1)
|
||||||
self.novelValue.setToolTip(self.tr("Click to change root folder"))
|
|
||||||
else:
|
|
||||||
self.novelValue.setToolTip("")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def setCurrentRoot(self, rootHandle):
|
def setCurrentRoot(self, rootHandle):
|
||||||
@@ -321,6 +324,11 @@ class GuiNovelToolBar(QWidget):
|
|||||||
# Private Slots
|
# Private Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def _openNovelSelector(self):
|
||||||
|
self.novelValue.showPopup()
|
||||||
|
return
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _refreshNovelTree(self):
|
def _refreshNovelTree(self):
|
||||||
"""Rebuild the current tree.
|
"""Rebuild the current tree.
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
self.novelLabel = QLabel(self.tr("Outline of"))
|
self.novelLabel = QLabel(self.tr("Outline of"))
|
||||||
self.novelLabel.setContentsMargins(0, 0, mPx, 0)
|
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.setMinimumWidth(self.mainConf.pxInt(200))
|
||||||
self.novelValue.novelSelectionChanged.connect(self._novelValueChanged)
|
self.novelValue.novelSelectionChanged.connect(self._novelValueChanged)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user