Update remaining build settings pages and delete old config layouts

This commit is contained in:
Veronica Berglyd Olsen
2024-01-27 18:06:08 +01:00
parent 6b106599dd
commit 51314804bf
2 changed files with 65 additions and 250 deletions
+14 -136
View File
@@ -3,8 +3,7 @@ novelWriter Custom Widget: Config Layout
========================================== ==========================================
File History: File History:
Created: 2020-05-03 [0.4.5] NConfigLayout, NColourLabel Created: 2020-05-03 [0.4.5] NColourLabel
Created: 2023-05-23 [2.1b1] NSimpleLayout
Created: 2024-01-08 [2.3b1] NScrollableForm Created: 2024-01-08 [2.3b1] NScrollableForm
Created: 2024-01-26 [2.3b1] NScrollablePage Created: 2024-01-26 [2.3b1] NScrollablePage
Created: 2024-01-26 [2.3b1] NFixedPage Created: 2024-01-26 [2.3b1] NFixedPage
@@ -30,8 +29,8 @@ from __future__ import annotations
from PyQt5.QtGui import QColor, QPalette from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractButton, QFrame, QGridLayout, QHBoxLayout, QLabel, QLayout, QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea,
QScrollArea, QSizePolicy, QVBoxLayout, QWidget QVBoxLayout, QWidget
) )
from novelwriter import CONFIG from novelwriter import CONFIG
@@ -173,7 +172,7 @@ class NScrollableForm(QScrollArea):
self.verticalScrollBar().setValue(yPos) self.verticalScrollBar().setValue(yPos)
return return
def addGroupLabel(self, label: str, identifier: int) -> None: def addGroupLabel(self, label: str, identifier: int | None = None) -> None:
"""Add a text label to separate groups of settings.""" """Add a text label to separate groups of settings."""
hM = CONFIG.pxInt(4) hM = CONFIG.pxInt(4)
qLabel = QLabel(f"<b>{label}</b>", self) qLabel = QLabel(f"<b>{label}</b>", self)
@@ -181,13 +180,14 @@ class NScrollableForm(QScrollArea):
if not self._first: if not self._first:
self._layout.addSpacing(5*hM) self._layout.addSpacing(5*hM)
self._layout.addWidget(qLabel) self._layout.addWidget(qLabel)
self._sections[identifier] = qLabel
self._first = False self._first = False
if identifier is not None:
self._sections[identifier] = qLabel
return return
def addRow(self, label: str, widget: QWidget, helpText: str = "", unit: str | None = None, def addRow(self, label: str, widget: QWidget, helpText: str = "", unit: str | None = None,
button: QWidget | None = None, editable: str | None = None, button: QWidget | None = None, editable: str | None = None,
stretch: tuple[int, int] = (0, 0)) -> None: stretch: tuple[int, int] = (1, 0)) -> None:
"""Add a label and a widget as a new row of the form.""" """Add a label and a widget as a new row of the form."""
row = QHBoxLayout() row = QHBoxLayout()
row.setSpacing(CONFIG.pxInt(12)) row.setSpacing(CONFIG.pxInt(12))
@@ -202,8 +202,8 @@ class NScrollableForm(QScrollArea):
scale=self._fontScale, wrap=True, indent=self._indent scale=self._fontScale, wrap=True, indent=self._indent
) )
labelBox = QVBoxLayout() labelBox = QVBoxLayout()
labelBox.addWidget(qLabel) labelBox.addWidget(qLabel, 0)
labelBox.addWidget(qHelp) labelBox.addWidget(qHelp, 1)
labelBox.setSpacing(0) labelBox.setSpacing(0)
row.addLayout(labelBox, stretch[0]) row.addLayout(labelBox, stretch[0])
if editable: if editable:
@@ -213,13 +213,13 @@ class NScrollableForm(QScrollArea):
if isinstance(unit, str): if isinstance(unit, str):
box = QHBoxLayout() box = QHBoxLayout()
box.addWidget(widget) box.addWidget(widget, 1)
box.addWidget(QLabel(unit, self)) box.addWidget(QLabel(unit, self), 0)
row.addLayout(box, stretch[1]) row.addLayout(box, stretch[1])
elif isinstance(button, QAbstractButton): elif isinstance(button, QAbstractButton):
box = QHBoxLayout() box = QHBoxLayout()
box.addWidget(widget) box.addWidget(widget, 1)
box.addWidget(button) box.addWidget(button, 0)
row.addLayout(box, stretch[1]) row.addLayout(box, stretch[1])
else: else:
row.addWidget(widget, stretch[1]) row.addWidget(widget, stretch[1])
@@ -239,125 +239,6 @@ class NScrollableForm(QScrollArea):
# END Class NScrollableForm # END Class NScrollableForm
class NConfigLayout(QGridLayout):
def __init__(self) -> None:
super().__init__()
self._nextRow = 0
self._helpCol = QColor(0, 0, 0)
self._fontScale = DEFAULT_SCALE
self._itemMap = {}
wSp = CONFIG.pxInt(8)
self.setHorizontalSpacing(wSp)
self.setVerticalSpacing(wSp)
self.setColumnStretch(0, 1)
return
##
# Class Methods
##
def addGroupLabel(self, label: str) -> None:
"""Add a text label to separate groups of settings."""
hM = CONFIG.pxInt(4)
qLabel = QLabel("<b>%s</b>" % label)
qLabel.setContentsMargins(0, hM, 0, hM)
self.addWidget(qLabel, self._nextRow, 0, 1, 2, Qt.AlignLeft)
self.setRowStretch(self._nextRow, 0)
self.setRowStretch(self._nextRow + 1, 1)
self._nextRow += 1
return
def addRow(self, label: str, widget: QWidget, unit: str | None = None,
button: QWidget | None = None) -> int:
"""Add a label and a widget as a new row of the grid."""
wSp = CONFIG.pxInt(8)
qLabel = QLabel(label)
qLabel.setIndent(wSp)
qLabel.setBuddy(widget)
qHelp = None
self.addWidget(qLabel, self._nextRow, 0, 1, 1, LEFT_TOP)
if isinstance(unit, str):
controlBox = QHBoxLayout()
controlBox.addWidget(widget, 0, Qt.AlignVCenter)
controlBox.addWidget(QLabel(unit), 0, Qt.AlignVCenter)
controlBox.setSpacing(wSp)
self.addLayout(controlBox, self._nextRow, 1, 1, 1, RIGHT_TOP)
elif isinstance(button, QAbstractButton):
controlBox = QHBoxLayout()
controlBox.addWidget(widget, 0, Qt.AlignVCenter)
controlBox.addWidget(button, 0, Qt.AlignVCenter)
controlBox.setSpacing(wSp)
self.addLayout(controlBox, self._nextRow, 1, 1, 1, RIGHT_TOP)
else:
self.addWidget(widget, self._nextRow, 1, 1, 1, RIGHT_TOP)
self.setRowStretch(self._nextRow, 0)
self.setRowStretch(self._nextRow+1, 1)
self._itemMap[self._nextRow] = (qLabel, qHelp, widget)
self._nextRow += 1
return self._nextRow - 1
# END Class NConfigLayout
class NSimpleLayout(QGridLayout):
"""Similar to NConfigLayout, but only has a label + widget two
column layout.
"""
def __init__(self, stretcColumn: int = 0) -> None:
super().__init__()
self._nextRow = 0
wSp = CONFIG.pxInt(8)
self.setHorizontalSpacing(wSp)
self.setVerticalSpacing(wSp)
self.setColumnStretch(stretcColumn, 1)
return
##
# Methods
##
def addGroupLabel(self, label: str) -> None:
"""Add a text label to separate groups of settings."""
hM = CONFIG.pxInt(4)
qLabel = QLabel("<b>%s</b>" % label)
qLabel.setContentsMargins(0, hM, 0, hM)
self.addWidget(qLabel, self._nextRow, 0, 1, 2, Qt.AlignLeft)
self.setRowStretch(self._nextRow, 0)
self.setRowStretch(self._nextRow + 1, 1)
self._nextRow += 1
return
def addRow(self, label: str, widget: QWidget) -> None:
"""Add a label and a widget as a new row of the grid."""
wSp = CONFIG.pxInt(8)
qLabel = QLabel(label)
qLabel.setIndent(wSp)
qLabel.setBuddy(widget)
self.addWidget(qLabel, self._nextRow, 0, 1, 1, LEFT_TOP)
self.addWidget(widget, self._nextRow, 1, 1, 1, RIGHT_TOP)
self.setRowStretch(self._nextRow, 0)
self.setRowStretch(self._nextRow+1, 1)
self._nextRow += 1
return
# END Class NSimpleLayout
class NColourLabel(QLabel): class NColourLabel(QLabel):
"""Extension: A Coloured Label """Extension: A Coloured Label
@@ -380,10 +261,7 @@ class NColourLabel(QLabel):
self.setPalette(colour) self.setPalette(colour)
self.setFont(font) self.setFont(font)
self.setIndent(indent) self.setIndent(indent)
self.setWordWrap(wrap)
if wrap:
self.setWordWrap(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
return return
+51 -114
View File
@@ -43,7 +43,7 @@ from novelwriter.core.buildsettings import BuildSettings, FilterMode
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.switchbox import NSwitchBox from novelwriter.extensions.switchbox import NSwitchBox
from novelwriter.extensions.configlayout import ( from novelwriter.extensions.configlayout import (
NColourLabel, NConfigLayout, NFixedPage, NScrollablePage, NSimpleLayout NColourLabel, NFixedPage, NScrollableForm, NScrollablePage
) )
from novelwriter.extensions.pagedsidebar import NPagedSideBar from novelwriter.extensions.pagedsidebar import NPagedSideBar
@@ -881,7 +881,7 @@ class _HeadingSyntaxHighlighter(QSyntaxHighlighter):
# END Class _HeadingSyntaxHighlighter # END Class _HeadingSyntaxHighlighter
class _ContentTab(QWidget): class _ContentTab(NScrollableForm):
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None: def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None:
super().__init__(parent=buildMain) super().__init__(parent=buildMain)
@@ -890,42 +890,26 @@ class _ContentTab(QWidget):
iPx = SHARED.theme.baseIconSize iPx = SHARED.theme.baseIconSize
# Left Form # Text Content
# =========
self.formLeft = NSimpleLayout()
self.formLeft.addGroupLabel(self._build.getLabel("text.grpContent"))
self.incSynopsis = NSwitch(self, width=2*iPx, height=iPx) self.incSynopsis = NSwitch(self, width=2*iPx, height=iPx)
self.incComments = NSwitch(self, width=2*iPx, height=iPx) self.incComments = NSwitch(self, width=2*iPx, height=iPx)
self.incKeywords = NSwitch(self, width=2*iPx, height=iPx) self.incKeywords = NSwitch(self, width=2*iPx, height=iPx)
self.incBodyText = NSwitch(self, width=2*iPx, height=iPx) self.incBodyText = NSwitch(self, width=2*iPx, height=iPx)
self.formLeft.addRow(self._build.getLabel("text.includeSynopsis"), self.incSynopsis) self.addGroupLabel(self._build.getLabel("text.grpContent"))
self.formLeft.addRow(self._build.getLabel("text.includeComments"), self.incComments) self.addRow(self._build.getLabel("text.includeSynopsis"), self.incSynopsis)
self.formLeft.addRow(self._build.getLabel("text.includeKeywords"), self.incKeywords) self.addRow(self._build.getLabel("text.includeComments"), self.incComments)
self.formLeft.addRow(self._build.getLabel("text.includeBodyText"), self.incBodyText) self.addRow(self._build.getLabel("text.includeKeywords"), self.incKeywords)
self.addRow(self._build.getLabel("text.includeBodyText"), self.incBodyText)
# Right Form
# ==========
self.formRight = NSimpleLayout()
self.formRight.addGroupLabel(self._build.getLabel("text.grpInsert"))
# Insert Content
self.addNoteHead = NSwitch(self, width=2*iPx, height=iPx) self.addNoteHead = NSwitch(self, width=2*iPx, height=iPx)
self.formRight.addRow(self._build.getLabel("text.addNoteHeadings"), self.addNoteHead) self.addGroupLabel(self._build.getLabel("text.grpInsert"))
self.addRow(self._build.getLabel("text.addNoteHeadings"), self.addNoteHead)
# Assemble GUI # Finalise
# ============ self.finalise()
self.outerBox = QHBoxLayout()
self.outerBox.addLayout(self.formLeft, 1)
self.outerBox.addLayout(self.formRight, 1)
self.outerBox.setContentsMargins(0, 0, 0, 0)
self.outerBox.setSpacing(CONFIG.pxInt(16))
self.setLayout(self.outerBox)
return return
@@ -950,7 +934,7 @@ class _ContentTab(QWidget):
# END Class _ContentTab # END Class _ContentTab
class _FormatTab(QWidget): class _FormatTab(NScrollableForm):
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None: def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None:
super().__init__(parent=buildMain) super().__init__(parent=buildMain)
@@ -964,20 +948,20 @@ class _FormatTab(QWidget):
spW = 6*SHARED.theme.textNWidth spW = 6*SHARED.theme.textNWidth
dbW = 8*SHARED.theme.textNWidth dbW = 8*SHARED.theme.textNWidth
# Text Format Form # Text Format
# ================ # ===========
self.formFormat = NConfigLayout() self.addGroupLabel(self._build.getLabel("format.grpFormat"))
self.formFormat.addGroupLabel(self._build.getLabel("format.grpFormat"))
# Font Family # Font Family
self.textFont = QLineEdit() self.textFont = QLineEdit(self)
self.textFont.setReadOnly(True) self.textFont.setReadOnly(True)
self.btnTextFont = QPushButton("...") self.btnTextFont = QPushButton("...")
self.btnTextFont.setMaximumWidth(int(2.5*SHARED.theme.getTextWidth("..."))) self.btnTextFont.setMaximumWidth(int(2.5*SHARED.theme.getTextWidth("...")))
self.btnTextFont.clicked.connect(self._selectFont) self.btnTextFont.clicked.connect(self._selectFont)
self.formFormat.addRow( self.addRow(
self._build.getLabel("format.textFont"), self.textFont, button=self.btnTextFont self._build.getLabel("format.textFont"), self.textFont,
button=self.btnTextFont, stretch=(3, 2)
) )
# Font Size # Font Size
@@ -986,9 +970,7 @@ class _FormatTab(QWidget):
self.textSize.setMaximum(60) self.textSize.setMaximum(60)
self.textSize.setSingleStep(1) self.textSize.setSingleStep(1)
self.textSize.setMinimumWidth(spW) self.textSize.setMinimumWidth(spW)
self.formFormat.addRow( self.addRow(self._build.getLabel("format.textSize"), self.textSize, unit="pt")
self._build.getLabel("format.textSize"), self.textSize, unit="pt"
)
# Line Height # Line Height
self.lineHeight = QDoubleSpinBox(self) self.lineHeight = QDoubleSpinBox(self)
@@ -997,31 +979,25 @@ class _FormatTab(QWidget):
self.lineHeight.setMaximum(3.0) self.lineHeight.setMaximum(3.0)
self.lineHeight.setSingleStep(0.05) self.lineHeight.setSingleStep(0.05)
self.lineHeight.setDecimals(2) self.lineHeight.setDecimals(2)
self.formFormat.addRow( self.addRow(self._build.getLabel("format.lineHeight"), self.lineHeight, unit="em")
self._build.getLabel("format.lineHeight"), self.lineHeight, unit="em"
)
# Text Options Form # Text Options
# ================= # ============
self.formOptions = NSimpleLayout() self.addGroupLabel(self._build.getLabel("format.grpOptions"))
self.formOptions.addGroupLabel(self._build.getLabel("format.grpOptions"))
self.formOptions.setContentsMargins(0, 0, 0, 0)
self.justifyText = NSwitch(self, width=2*iPx, height=iPx) self.justifyText = NSwitch(self, width=2*iPx, height=iPx)
self.stripUnicode = NSwitch(self, width=2*iPx, height=iPx) self.stripUnicode = NSwitch(self, width=2*iPx, height=iPx)
self.replaceTabs = NSwitch(self, width=2*iPx, height=iPx) self.replaceTabs = NSwitch(self, width=2*iPx, height=iPx)
self.formOptions.addRow(self._build.getLabel("format.justifyText"), self.justifyText) self.addRow(self._build.getLabel("format.justifyText"), self.justifyText)
self.formOptions.addRow(self._build.getLabel("format.stripUnicode"), self.stripUnicode) self.addRow(self._build.getLabel("format.stripUnicode"), self.stripUnicode)
self.formOptions.addRow(self._build.getLabel("format.replaceTabs"), self.replaceTabs) self.addRow(self._build.getLabel("format.replaceTabs"), self.replaceTabs)
# Page Layout Form # Page Layout
# ================ # ===========
self.formLayout = NSimpleLayout() self.addGroupLabel(self._build.getLabel("format.grpPage"))
self.formLayout.addGroupLabel(self._build.getLabel("format.grpPage"))
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.pageUnit = QComboBox(self) self.pageUnit = QComboBox(self)
for key, name in nwLabels.UNIT_NAME.items(): for key, name in nwLabels.UNIT_NAME.items():
@@ -1053,38 +1029,17 @@ class _FormatTab(QWidget):
self.rightMargin = QDoubleSpinBox(self) self.rightMargin = QDoubleSpinBox(self)
self.rightMargin.setFixedWidth(dbW) self.rightMargin.setFixedWidth(dbW)
self.formLayout.addRow(self._build.getLabel("format.pageUnit"), self.pageUnit) self.addRow(self._build.getLabel("format.pageUnit"), self.pageUnit)
self.formLayout.addRow(self._build.getLabel("format.pageSize"), self.pageSize) self.addRow(self._build.getLabel("format.pageSize"), self.pageSize)
self.formLayout.addRow(self._build.getLabel("format.pageWidth"), self.pageWidth) self.addRow(self._build.getLabel("format.pageWidth"), self.pageWidth)
self.formLayout.addRow(self._build.getLabel("format.pageHeight"), self.pageHeight) self.addRow(self._build.getLabel("format.pageHeight"), self.pageHeight)
self.formLayout.addRow(self._build.getLabel("format.topMargin"), self.topMargin) self.addRow(self._build.getLabel("format.topMargin"), self.topMargin)
self.formLayout.addRow(self._build.getLabel("format.bottomMargin"), self.bottomMargin) self.addRow(self._build.getLabel("format.bottomMargin"), self.bottomMargin)
self.formLayout.addRow(self._build.getLabel("format.leftMargin"), self.leftMargin) self.addRow(self._build.getLabel("format.leftMargin"), self.leftMargin)
self.formLayout.addRow(self._build.getLabel("format.rightMargin"), self.rightMargin) self.addRow(self._build.getLabel("format.rightMargin"), self.rightMargin)
# Assemble GUI # Finalise
# ============ self.finalise()
self.formLeft = QVBoxLayout()
self.formLeft.addLayout(self.formFormat)
self.formLeft.addLayout(self.formOptions)
self.formLeft.addStretch(1)
self.formLeft.setContentsMargins(0, 0, 0, 0)
self.formLeft.setSpacing(CONFIG.pxInt(8))
self.formRight = QVBoxLayout()
self.formRight.addLayout(self.formLayout)
self.formRight.addStretch(1)
self.formRight.setContentsMargins(0, 0, 0, 0)
self.formRight.setSpacing(CONFIG.pxInt(8))
self.outerBox = QHBoxLayout()
self.outerBox.addLayout(self.formLeft, 1)
self.outerBox.addLayout(self.formRight, 1)
self.outerBox.setContentsMargins(0, 0, 0, 0)
self.outerBox.setSpacing(CONFIG.pxInt(16))
self.setLayout(self.outerBox)
return return
@@ -1248,7 +1203,7 @@ class _FormatTab(QWidget):
# END Class _FormatTab # END Class _FormatTab
class _OutputTab(QWidget): class _OutputTab(NScrollableForm):
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None: def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None:
super().__init__(parent=buildMain) super().__init__(parent=buildMain)
@@ -1257,36 +1212,18 @@ class _OutputTab(QWidget):
iPx = SHARED.theme.baseIconSize iPx = SHARED.theme.baseIconSize
# Left Form # Open Document
# ========= self.addGroupLabel(self._build.getLabel("odt"))
self.formLeft = NSimpleLayout()
self.formLeft.addGroupLabel(self._build.getLabel("odt"))
self.odtAddColours = NSwitch(self, width=2*iPx, height=iPx) self.odtAddColours = NSwitch(self, width=2*iPx, height=iPx)
self.addRow(self._build.getLabel("odt.addColours"), self.odtAddColours)
self.formLeft.addRow(self._build.getLabel("odt.addColours"), self.odtAddColours) # HTML Document
self.addGroupLabel(self._build.getLabel("html"))
# Right Form
# ==========
self.formRight = NSimpleLayout()
self.formRight.addGroupLabel(self._build.getLabel("html"))
self.htmlAddStyles = NSwitch(self, width=2*iPx, height=iPx) self.htmlAddStyles = NSwitch(self, width=2*iPx, height=iPx)
self.addRow(self._build.getLabel("html.addStyles"), self.htmlAddStyles)
self.formRight.addRow(self._build.getLabel("html.addStyles"), self.htmlAddStyles) # Finalise
self.finalise()
# Assemble GUI
# ============
self.outerBox = QHBoxLayout()
self.outerBox.addLayout(self.formLeft, 1)
self.outerBox.addLayout(self.formRight, 1)
self.outerBox.setContentsMargins(0, 0, 0, 0)
self.outerBox.setSpacing(CONFIG.pxInt(16))
self.setLayout(self.outerBox)
return return