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:
Created: 2020-05-03 [0.4.5] NConfigLayout, NColourLabel
Created: 2023-05-23 [2.1b1] NSimpleLayout
Created: 2020-05-03 [0.4.5] NColourLabel
Created: 2024-01-08 [2.3b1] NScrollableForm
Created: 2024-01-26 [2.3b1] NScrollablePage
Created: 2024-01-26 [2.3b1] NFixedPage
@@ -30,8 +29,8 @@ from __future__ import annotations
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QAbstractButton, QFrame, QGridLayout, QHBoxLayout, QLabel, QLayout,
QScrollArea, QSizePolicy, QVBoxLayout, QWidget
QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea,
QVBoxLayout, QWidget
)
from novelwriter import CONFIG
@@ -173,7 +172,7 @@ class NScrollableForm(QScrollArea):
self.verticalScrollBar().setValue(yPos)
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."""
hM = CONFIG.pxInt(4)
qLabel = QLabel(f"<b>{label}</b>", self)
@@ -181,13 +180,14 @@ class NScrollableForm(QScrollArea):
if not self._first:
self._layout.addSpacing(5*hM)
self._layout.addWidget(qLabel)
self._sections[identifier] = qLabel
self._first = False
if identifier is not None:
self._sections[identifier] = qLabel
return
def addRow(self, label: str, widget: QWidget, helpText: str = "", unit: 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."""
row = QHBoxLayout()
row.setSpacing(CONFIG.pxInt(12))
@@ -202,8 +202,8 @@ class NScrollableForm(QScrollArea):
scale=self._fontScale, wrap=True, indent=self._indent
)
labelBox = QVBoxLayout()
labelBox.addWidget(qLabel)
labelBox.addWidget(qHelp)
labelBox.addWidget(qLabel, 0)
labelBox.addWidget(qHelp, 1)
labelBox.setSpacing(0)
row.addLayout(labelBox, stretch[0])
if editable:
@@ -213,13 +213,13 @@ class NScrollableForm(QScrollArea):
if isinstance(unit, str):
box = QHBoxLayout()
box.addWidget(widget)
box.addWidget(QLabel(unit, self))
box.addWidget(widget, 1)
box.addWidget(QLabel(unit, self), 0)
row.addLayout(box, stretch[1])
elif isinstance(button, QAbstractButton):
box = QHBoxLayout()
box.addWidget(widget)
box.addWidget(button)
box.addWidget(widget, 1)
box.addWidget(button, 0)
row.addLayout(box, stretch[1])
else:
row.addWidget(widget, stretch[1])
@@ -239,125 +239,6 @@ class NScrollableForm(QScrollArea):
# 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):
"""Extension: A Coloured Label
@@ -380,10 +261,7 @@ class NColourLabel(QLabel):
self.setPalette(colour)
self.setFont(font)
self.setIndent(indent)
if wrap:
self.setWordWrap(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setWordWrap(wrap)
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.switchbox import NSwitchBox
from novelwriter.extensions.configlayout import (
NColourLabel, NConfigLayout, NFixedPage, NScrollablePage, NSimpleLayout
NColourLabel, NFixedPage, NScrollableForm, NScrollablePage
)
from novelwriter.extensions.pagedsidebar import NPagedSideBar
@@ -881,7 +881,7 @@ class _HeadingSyntaxHighlighter(QSyntaxHighlighter):
# END Class _HeadingSyntaxHighlighter
class _ContentTab(QWidget):
class _ContentTab(NScrollableForm):
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None:
super().__init__(parent=buildMain)
@@ -890,42 +890,26 @@ class _ContentTab(QWidget):
iPx = SHARED.theme.baseIconSize
# Left Form
# =========
self.formLeft = NSimpleLayout()
self.formLeft.addGroupLabel(self._build.getLabel("text.grpContent"))
# Text Content
self.incSynopsis = 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.incBodyText = NSwitch(self, width=2*iPx, height=iPx)
self.formLeft.addRow(self._build.getLabel("text.includeSynopsis"), self.incSynopsis)
self.formLeft.addRow(self._build.getLabel("text.includeComments"), self.incComments)
self.formLeft.addRow(self._build.getLabel("text.includeKeywords"), self.incKeywords)
self.formLeft.addRow(self._build.getLabel("text.includeBodyText"), self.incBodyText)
# Right Form
# ==========
self.formRight = NSimpleLayout()
self.formRight.addGroupLabel(self._build.getLabel("text.grpInsert"))
self.addGroupLabel(self._build.getLabel("text.grpContent"))
self.addRow(self._build.getLabel("text.includeSynopsis"), self.incSynopsis)
self.addRow(self._build.getLabel("text.includeComments"), self.incComments)
self.addRow(self._build.getLabel("text.includeKeywords"), self.incKeywords)
self.addRow(self._build.getLabel("text.includeBodyText"), self.incBodyText)
# Insert Content
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
# ============
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)
# Finalise
self.finalise()
return
@@ -950,7 +934,7 @@ class _ContentTab(QWidget):
# END Class _ContentTab
class _FormatTab(QWidget):
class _FormatTab(NScrollableForm):
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None:
super().__init__(parent=buildMain)
@@ -964,20 +948,20 @@ class _FormatTab(QWidget):
spW = 6*SHARED.theme.textNWidth
dbW = 8*SHARED.theme.textNWidth
# Text Format Form
# ================
# Text Format
# ===========
self.formFormat = NConfigLayout()
self.formFormat.addGroupLabel(self._build.getLabel("format.grpFormat"))
self.addGroupLabel(self._build.getLabel("format.grpFormat"))
# Font Family
self.textFont = QLineEdit()
self.textFont = QLineEdit(self)
self.textFont.setReadOnly(True)
self.btnTextFont = QPushButton("...")
self.btnTextFont.setMaximumWidth(int(2.5*SHARED.theme.getTextWidth("...")))
self.btnTextFont.clicked.connect(self._selectFont)
self.formFormat.addRow(
self._build.getLabel("format.textFont"), self.textFont, button=self.btnTextFont
self.addRow(
self._build.getLabel("format.textFont"), self.textFont,
button=self.btnTextFont, stretch=(3, 2)
)
# Font Size
@@ -986,9 +970,7 @@ class _FormatTab(QWidget):
self.textSize.setMaximum(60)
self.textSize.setSingleStep(1)
self.textSize.setMinimumWidth(spW)
self.formFormat.addRow(
self._build.getLabel("format.textSize"), self.textSize, unit="pt"
)
self.addRow(self._build.getLabel("format.textSize"), self.textSize, unit="pt")
# Line Height
self.lineHeight = QDoubleSpinBox(self)
@@ -997,31 +979,25 @@ class _FormatTab(QWidget):
self.lineHeight.setMaximum(3.0)
self.lineHeight.setSingleStep(0.05)
self.lineHeight.setDecimals(2)
self.formFormat.addRow(
self._build.getLabel("format.lineHeight"), self.lineHeight, unit="em"
)
self.addRow(self._build.getLabel("format.lineHeight"), self.lineHeight, unit="em")
# Text Options Form
# =================
# Text Options
# ============
self.formOptions = NSimpleLayout()
self.formOptions.addGroupLabel(self._build.getLabel("format.grpOptions"))
self.formOptions.setContentsMargins(0, 0, 0, 0)
self.addGroupLabel(self._build.getLabel("format.grpOptions"))
self.justifyText = 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.formOptions.addRow(self._build.getLabel("format.justifyText"), self.justifyText)
self.formOptions.addRow(self._build.getLabel("format.stripUnicode"), self.stripUnicode)
self.formOptions.addRow(self._build.getLabel("format.replaceTabs"), self.replaceTabs)
self.addRow(self._build.getLabel("format.justifyText"), self.justifyText)
self.addRow(self._build.getLabel("format.stripUnicode"), self.stripUnicode)
self.addRow(self._build.getLabel("format.replaceTabs"), self.replaceTabs)
# Page Layout Form
# ================
# Page Layout
# ===========
self.formLayout = NSimpleLayout()
self.formLayout.addGroupLabel(self._build.getLabel("format.grpPage"))
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.addGroupLabel(self._build.getLabel("format.grpPage"))
self.pageUnit = QComboBox(self)
for key, name in nwLabels.UNIT_NAME.items():
@@ -1053,38 +1029,17 @@ class _FormatTab(QWidget):
self.rightMargin = QDoubleSpinBox(self)
self.rightMargin.setFixedWidth(dbW)
self.formLayout.addRow(self._build.getLabel("format.pageUnit"), self.pageUnit)
self.formLayout.addRow(self._build.getLabel("format.pageSize"), self.pageSize)
self.formLayout.addRow(self._build.getLabel("format.pageWidth"), self.pageWidth)
self.formLayout.addRow(self._build.getLabel("format.pageHeight"), self.pageHeight)
self.formLayout.addRow(self._build.getLabel("format.topMargin"), self.topMargin)
self.formLayout.addRow(self._build.getLabel("format.bottomMargin"), self.bottomMargin)
self.formLayout.addRow(self._build.getLabel("format.leftMargin"), self.leftMargin)
self.formLayout.addRow(self._build.getLabel("format.rightMargin"), self.rightMargin)
self.addRow(self._build.getLabel("format.pageUnit"), self.pageUnit)
self.addRow(self._build.getLabel("format.pageSize"), self.pageSize)
self.addRow(self._build.getLabel("format.pageWidth"), self.pageWidth)
self.addRow(self._build.getLabel("format.pageHeight"), self.pageHeight)
self.addRow(self._build.getLabel("format.topMargin"), self.topMargin)
self.addRow(self._build.getLabel("format.bottomMargin"), self.bottomMargin)
self.addRow(self._build.getLabel("format.leftMargin"), self.leftMargin)
self.addRow(self._build.getLabel("format.rightMargin"), self.rightMargin)
# Assemble GUI
# ============
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)
# Finalise
self.finalise()
return
@@ -1248,7 +1203,7 @@ class _FormatTab(QWidget):
# END Class _FormatTab
class _OutputTab(QWidget):
class _OutputTab(NScrollableForm):
def __init__(self, buildMain: GuiBuildSettings, build: BuildSettings) -> None:
super().__init__(parent=buildMain)
@@ -1257,36 +1212,18 @@ class _OutputTab(QWidget):
iPx = SHARED.theme.baseIconSize
# Left Form
# =========
self.formLeft = NSimpleLayout()
self.formLeft.addGroupLabel(self._build.getLabel("odt"))
# Open Document
self.addGroupLabel(self._build.getLabel("odt"))
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)
# Right Form
# ==========
self.formRight = NSimpleLayout()
self.formRight.addGroupLabel(self._build.getLabel("html"))
# HTML Document
self.addGroupLabel(self._build.getLabel("html"))
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)
# 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)
# Finalise
self.finalise()
return