diff --git a/novelwriter/extensions/pagedsidebar.py b/novelwriter/extensions/pagedsidebar.py
index f095410b..27b2639a 100644
--- a/novelwriter/extensions/pagedsidebar.py
+++ b/novelwriter/extensions/pagedsidebar.py
@@ -6,6 +6,7 @@ A custom widget for making a sidebar for flipping through pages
File History:
Created: 2023-02-21 [2.1b1] NPagedSideBar
Created: 2023-02-21 [2.1b1] NPagedToolButton
+Created: 2023-02-21 [2.1b1] NPagedToolLabel
This file is a part of novelWriter
Copyright 2018–2023, Veronica Berglyd Olsen
@@ -24,8 +25,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
"""
-from PyQt5.QtCore import QRectF, Qt
from PyQt5.QtGui import QColor, QPainter
+from PyQt5.QtCore import QRectF, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import (
QButtonGroup, QLabel, QSizePolicy, QStyle, QStyleOptionToolButton, QToolBar,
QToolButton, QWidget
@@ -34,16 +35,20 @@ from PyQt5.QtWidgets import (
class NPagedSideBar(QToolBar):
+ buttonClicked = pyqtSignal(int)
+
def __init__(self, parent):
super().__init__(parent=parent)
self._buttons = []
self._actions = []
- self._group = QButtonGroup(self)
- self._group.setExclusive(True)
self._labelCol = None
self._spacerHeight = self.fontMetrics().height() // 2
+ self._group = QButtonGroup(self)
+ self._group.setExclusive(True)
+ self._group.buttonClicked.connect(self._buttonClicked)
+
self.setMovable(False)
self.setOrientation(Qt.Vertical)
@@ -79,26 +84,39 @@ class NPagedSideBar(QToolBar):
self.insertWidget(self._stretchAction, label)
return
- def addButton(self, text):
+ def addButton(self, text, buttonId=-1):
"""Add a new button to the toolbar.
"""
button = NPagedToolButton(self)
button.setText(text)
action = self.insertWidget(self._stretchAction, button)
- self._group.addButton(button)
+ self._group.addButton(button, id=buttonId)
self._buttons.append(button)
self._actions.append(action)
return action
+ ##
+ # Private Slots
+ ##
+
+ @pyqtSlot("QAbstractButton*")
+ def _buttonClicked(self, button):
+ """A button was clicked in the group, emit its id.
+ """
+ buttonId = self._group.id(button)
+ if buttonId != -1:
+ self.buttonClicked.emit(buttonId)
+ return
+
# END Class NPagedSideBar
class NPagedToolButton(QToolButton):
- __slots__ = ["_bH", "_tM", "_lM", "_cR"]
+ __slots__ = ("_bH", "_tM", "_lM", "_cR")
def __init__(self, parent):
super().__init__(parent=parent)
@@ -160,7 +178,7 @@ class NPagedToolButton(QToolButton):
class NPagedToolLabel(QLabel):
- __slots__ = ["_bH", "_tM", "_lM", "_textCol"]
+ __slots__ = ("_bH", "_tM", "_lM", "_textCol")
def __init__(self, parent, textColor=None):
super().__init__(parent=parent)
diff --git a/novelwriter/tools/mbuild.py b/novelwriter/tools/mbuild.py
index 47dcc34c..47098ce4 100644
--- a/novelwriter/tools/mbuild.py
+++ b/novelwriter/tools/mbuild.py
@@ -24,15 +24,14 @@ along with this program. If not, see .
"""
import logging
-
import novelwriter
+from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import (
- QAbstractItemView, QDialog, QHBoxLayout, QTabWidget, QTreeWidget,
+ QAbstractItemView, QDialog, QHBoxLayout, QStackedWidget, QTreeWidget,
QWidget
)
-from novelwriter.extensions.pageddialog import NVerticalTabBar
from novelwriter.extensions.pagedsidebar import NPagedSideBar
logger = logging.getLogger(__name__)
@@ -40,6 +39,14 @@ logger = logging.getLogger(__name__)
class GuiBuildManuscript(QDialog):
+ OPT_FILTERS = 1
+ OPT_HEADINGS = 2
+ OPT_FORMAT = 3
+ OPT_CONTENT = 4
+ BLD_HTML = 5
+ BLD_MARKDOWN = 6
+ BLD_ODT = 7
+
def __init__(self, mainGui):
super().__init__(parent=mainGui)
@@ -65,44 +72,54 @@ class GuiBuildManuscript(QDialog):
self.optSideBar.setLabelColor(self.mainTheme.helpText)
self.optSideBar.addLabel(self.tr("Options"))
- self.optFilters = self.optSideBar.addButton(self.tr("Filters"))
- self.optHeadings = self.optSideBar.addButton(self.tr("Headings"))
- self.optFormat = self.optSideBar.addButton(self.tr("Format"))
- self.optContent = self.optSideBar.addButton(self.tr("Content"))
+ self.optSideBar.addButton(self.tr("Filters"), self.OPT_FILTERS)
+ self.optSideBar.addButton(self.tr("Headings"), self.OPT_HEADINGS)
+ self.optSideBar.addButton(self.tr("Format"), self.OPT_FORMAT)
+ self.optSideBar.addButton(self.tr("Content"), self.OPT_CONTENT)
self.optSideBar.addSeparator()
self.optSideBar.addLabel(self.tr("Build"))
- self.bldHtml = self.optSideBar.addButton(self.tr("HTML"))
- self.bldMd = self.optSideBar.addButton(self.tr("Markdown"))
- self.bldOdt = self.optSideBar.addButton(self.tr("Open Document"))
+ self.optSideBar.addButton(self.tr("HTML"), self.BLD_HTML)
+ self.optSideBar.addButton(self.tr("Markdown"), self.BLD_MARKDOWN)
+ self.optSideBar.addButton(self.tr("Open Document"), self.BLD_ODT)
+
+ self.optSideBar.buttonClicked.connect(self._stackPageSelected)
# Options Area
# ============
- self.optTabBar = NVerticalTabBar(self)
- self.optTabBar.setExpanding(False)
-
- self.optTabBox = QTabWidget(self)
- self.optTabBox.setTabBar(self.optTabBar)
- self.optTabBox.setTabPosition(QTabWidget.West)
-
# Create Tabs
self.optTabSelect = GuiBuildSelectionTab(self)
self.optTabFormat = GuiBuildFormattingTab(self)
# Add Tabs
- self.optTabBox.addTab(self.optTabSelect, self.tr("Selection"))
- self.optTabBox.addTab(self.optTabFormat, self.tr("Formatting"))
+ self.toolStack = QStackedWidget(self)
+ self.toolStack.addWidget(self.optTabSelect)
+ self.toolStack.addWidget(self.optTabFormat)
# Assemble
self.outerBox = QHBoxLayout()
self.outerBox.addWidget(self.optSideBar)
- self.outerBox.addWidget(self.optTabBox)
+ self.outerBox.addWidget(self.toolStack)
self.setLayout(self.outerBox)
return
+ ##
+ # Private Slots
+ ##
+
+ @pyqtSlot(int)
+ def _stackPageSelected(self, pageId):
+ """Process a user request to switch page.
+ """
+ if pageId == self.OPT_FILTERS:
+ self.toolStack.setCurrentWidget(self.optTabSelect)
+ elif pageId == self.OPT_FORMAT:
+ self.toolStack.setCurrentWidget(self.optTabFormat)
+ return
+
# END Class GuiBuildManuscript