From bffab79ba794aafedb2fae2b3309551262a1da76 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:56:35 +0200 Subject: [PATCH] Merge build settings page layout options --- novelwriter/core/buildsettings.py | 7 +---- novelwriter/extensions/configlayout.py | 25 ++++++++++++---- novelwriter/extensions/modified.py | 14 ++++++++- novelwriter/tools/manussettings.py | 41 ++++++++++++++++++-------- 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/novelwriter/core/buildsettings.py b/novelwriter/core/buildsettings.py index 71662db4..4664e34e 100644 --- a/novelwriter/core/buildsettings.py +++ b/novelwriter/core/buildsettings.py @@ -147,12 +147,7 @@ SETTINGS_LABELS = { "format.grpPage": QT_TRANSLATE_NOOP("Builds", "Page Layout"), "format.pageUnit": QT_TRANSLATE_NOOP("Builds", "Unit"), "format.pageSize": QT_TRANSLATE_NOOP("Builds", "Page Size"), - "format.pageWidth": QT_TRANSLATE_NOOP("Builds", "Page Width"), - "format.pageHeight": QT_TRANSLATE_NOOP("Builds", "Page Height"), - "format.topMargin": QT_TRANSLATE_NOOP("Builds", "Top Margin"), - "format.bottomMargin": QT_TRANSLATE_NOOP("Builds", "Bottom Margin"), - "format.leftMargin": QT_TRANSLATE_NOOP("Builds", "Left Margin"), - "format.rightMargin": QT_TRANSLATE_NOOP("Builds", "Right Margin"), + "format.pageMargins": QT_TRANSLATE_NOOP("Builds", "Page Margins"), "odt": QT_TRANSLATE_NOOP("Builds", "Document Options"), "odt.pageHeader": QT_TRANSLATE_NOOP("Builds", "Page Header"), diff --git a/novelwriter/extensions/configlayout.py b/novelwriter/extensions/configlayout.py index 637d90c1..a34b7cde 100644 --- a/novelwriter/extensions/configlayout.py +++ b/novelwriter/extensions/configlayout.py @@ -180,9 +180,16 @@ class NScrollableForm(QScrollArea): self._sections[identifier] = qLabel return - def addRow(self, label: str, widget: QWidget | list[QWidget], helpText: str = "", - unit: str | None = None, button: QWidget | None = None, editable: str | None = None, - stretch: tuple[int, int] = (1, 0)) -> None: + def addRow( + self, + label: str | None, + widget: QWidget | list[QWidget | str | int], + helpText: str = "", + unit: str | None = None, + button: QWidget | None = None, + editable: str | None = 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)) @@ -191,13 +198,18 @@ class NScrollableForm(QScrollArea): wBox = QHBoxLayout() wBox.setContentsMargins(0, 0, 0, 0) for item in widget: - wBox.addWidget(item) + if isinstance(item, QWidget): + wBox.addWidget(item) + elif isinstance(item, str): + wBox.addWidget(QLabel(item, self)) + elif isinstance(item, int): + wBox.addSpacing(CONFIG.pxInt(item)) qWidget = QWidget(self) qWidget.setLayout(wBox) else: qWidget = widget - qLabel = QLabel(label, self) + qLabel = QLabel(label or "", self) qLabel.setIndent(self._indent) qLabel.setBuddy(qWidget) @@ -230,7 +242,8 @@ class NScrollableForm(QScrollArea): row.addWidget(qWidget, stretch[1]) self._layout.addLayout(row) - self._index[label.strip()] = qWidget + if label: + self._index[label.strip()] = qWidget self._first = False return diff --git a/novelwriter/extensions/modified.py b/novelwriter/extensions/modified.py index f07e2553..f9062b39 100644 --- a/novelwriter/extensions/modified.py +++ b/novelwriter/extensions/modified.py @@ -136,9 +136,21 @@ class NSpinBox(QSpinBox): class NDoubleSpinBox(QDoubleSpinBox): - def __init__(self, parent: QWidget | None = None) -> None: + def __init__( + self, + parent: QWidget | None = None, + *, + min: float = 0.0, + max: float = 15.0, + step: float = 0.1, + prec: int = 2, + ) -> None: super().__init__(parent=parent) self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) + self.setMinimum(min) + self.setMaximum(max) + self.setSingleStep(step) + self.setDecimals(prec) return def wheelEvent(self, event: QWheelEvent) -> None: diff --git a/novelwriter/tools/manussettings.py b/novelwriter/tools/manussettings.py index c0168301..ca20cd06 100644 --- a/novelwriter/tools/manussettings.py +++ b/novelwriter/tools/manussettings.py @@ -964,6 +964,15 @@ class _FormattingTab(NScrollableForm): spW = 6*SHARED.theme.textNWidth dbW = 8*SHARED.theme.textNWidth + # Common Translations + + trW = self.tr("W:") # Width + trH = self.tr("H:") # Height + trT = self.tr("T:") # Top + trB = self.tr("B:") # Bottom + trL = self.tr("L:") # Left + trR = self.tr("R:") # Right + # Text Content # ============ @@ -1075,24 +1084,32 @@ class _FormattingTab(NScrollableForm): self._sidebar.addButton(title, section) self.addGroupLabel(title, section) + # Unit self.pageUnit = NComboBox(self) for key, name in nwLabels.UNIT_NAME.items(): self.pageUnit.addItem(trConst(name), key) + self.addRow(self._build.getLabel("format.pageUnit"), self.pageUnit) + + # Page Size self.pageSize = NComboBox(self) for key, name in nwLabels.PAPER_NAME.items(): self.pageSize.addItem(trConst(name), key) - self.pageWidth = NDoubleSpinBox(self) + self.pageWidth = NDoubleSpinBox(self, max=500.0) self.pageWidth.setFixedWidth(dbW) - self.pageWidth.setMaximum(500.0) self.pageWidth.valueChanged.connect(self._pageSizeValueChanged) - self.pageHeight = NDoubleSpinBox(self) + self.pageHeight = NDoubleSpinBox(self, max=500.0) self.pageHeight.setFixedWidth(dbW) - self.pageHeight.setMaximum(500.0) self.pageHeight.valueChanged.connect(self._pageSizeValueChanged) + self.addRow( + self._build.getLabel("format.pageSize"), + [self.pageSize, 8, trW, self.pageWidth, trH, self.pageHeight], + ) + + # Page Margins self.topMargin = NDoubleSpinBox(self) self.topMargin.setFixedWidth(dbW) @@ -1105,14 +1122,14 @@ class _FormattingTab(NScrollableForm): self.rightMargin = NDoubleSpinBox(self) self.rightMargin.setFixedWidth(dbW) - 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) + self.addRow( + self._build.getLabel("format.pageMargins"), + [trT, self.topMargin, trB, self.bottomMargin], + ) + self.addRow( + "", + [trL, self.leftMargin, trR, self.rightMargin], + ) # Open Document # =============