Merge build settings page layout options

This commit is contained in:
Veronica Berglyd Olsen
2024-10-17 21:56:35 +02:00
parent c82f7fd9ca
commit bffab79ba7
4 changed files with 62 additions and 25 deletions
+1 -6
View File
@@ -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"),
+19 -6
View File
@@ -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
+13 -1
View File
@@ -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:
+29 -12
View File
@@ -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
# =============