Add text margin settings

This commit is contained in:
Veronica Berglyd Olsen
2024-10-17 21:57:04 +02:00
parent bffab79ba7
commit 912198cc40
5 changed files with 189 additions and 9 deletions
+7
View File
@@ -98,6 +98,13 @@ class nwHeaders:
H_VALID = ("H0", "H1", "H2", "H3", "H4") H_VALID = ("H0", "H1", "H2", "H3", "H4")
H_LEVEL = {"H0": 0, "H1": 1, "H2": 2, "H3": 3, "H4": 4} H_LEVEL = {"H0": 0, "H1": 1, "H2": 2, "H3": 3, "H4": 4}
H_SIZES = {0: 2.50, 1: 2.00, 2: 1.75, 3: 1.50, 4: 1.25} H_SIZES = {0: 2.50, 1: 2.00, 2: 1.75, 3: 1.50, 4: 1.25}
H_LABEL = {
"H0": QT_TRANSLATE_NOOP("Constant", "Title"),
"H1": QT_TRANSLATE_NOOP("Constant", "Heading 1 (Partition)"),
"H2": QT_TRANSLATE_NOOP("Constant", "Heading 2 (Chapter)"),
"H3": QT_TRANSLATE_NOOP("Constant", "Heading 3 (Scene)"),
"H4": QT_TRANSLATE_NOOP("Constant", "Heading 4 (Section)"),
}
class nwFiles: class nwFiles:
+18
View File
@@ -87,6 +87,20 @@ SETTINGS_TEMPLATE: dict[str, tuple[type, str | int | float | bool]] = {
"format.firstLineIndent": (bool, False), "format.firstLineIndent": (bool, False),
"format.firstIndentWidth": (float, 1.4), "format.firstIndentWidth": (float, 1.4),
"format.indentFirstPar": (bool, False), "format.indentFirstPar": (bool, False),
"format.titleMarginT": (float, 1.42),
"format.titleMarginB": (float, 0.50),
"format.h1MarginT": (float, 1.42),
"format.h1MarginB": (float, 0.50),
"format.h2MarginT": (float, 1.67),
"format.h2MarginB": (float, 0.50),
"format.h3MarginT": (float, 1.17),
"format.h3MarginB": (float, 0.50),
"format.h4MarginT": (float, 1.17),
"format.h4MarginB": (float, 0.50),
"format.textMarginT": (float, 0.00),
"format.textMarginB": (float, 0.50),
"format.sepMarginT": (float, 1.17),
"format.sepMarginB": (float, 1.17),
"format.pageUnit": (str, "cm"), "format.pageUnit": (str, "cm"),
"format.pageSize": (str, "A4"), "format.pageSize": (str, "A4"),
"format.pageWidth": (float, 21.0), "format.pageWidth": (float, 21.0),
@@ -144,6 +158,10 @@ SETTINGS_LABELS = {
"format.firstIndentWidth": QT_TRANSLATE_NOOP("Builds", "Indent Width"), "format.firstIndentWidth": QT_TRANSLATE_NOOP("Builds", "Indent Width"),
"format.indentFirstPar": QT_TRANSLATE_NOOP("Builds", "Indent First Paragraph"), "format.indentFirstPar": QT_TRANSLATE_NOOP("Builds", "Indent First Paragraph"),
"format.grpMargins": QT_TRANSLATE_NOOP("Builds", "Text Margins"),
"format.textMargin": QT_TRANSLATE_NOOP("Builds", "Text Paragraph"),
"format.sepMargin": QT_TRANSLATE_NOOP("Builds", "Scene Separator"),
"format.grpPage": QT_TRANSLATE_NOOP("Builds", "Page Layout"), "format.grpPage": QT_TRANSLATE_NOOP("Builds", "Page Layout"),
"format.pageUnit": QT_TRANSLATE_NOOP("Builds", "Unit"), "format.pageUnit": QT_TRANSLATE_NOOP("Builds", "Unit"),
"format.pageSize": QT_TRANSLATE_NOOP("Builds", "Page Size"), "format.pageSize": QT_TRANSLATE_NOOP("Builds", "Page Size"),
+29
View File
@@ -287,6 +287,35 @@ class NWBuildDocument:
self._build.getBool("odt.boldHeadings"), self._build.getBool("odt.boldHeadings"),
) )
bldObj.setTitleMargins(
self._build.getFloat("format.titleMarginT"),
self._build.getFloat("format.titleMarginB"),
)
bldObj.setHead1Margins(
self._build.getFloat("format.h1MarginT"),
self._build.getFloat("format.h1MarginB"),
)
bldObj.setHead2Margins(
self._build.getFloat("format.h2MarginT"),
self._build.getFloat("format.h2MarginB"),
)
bldObj.setHead3Margins(
self._build.getFloat("format.h3MarginT"),
self._build.getFloat("format.h3MarginB"),
)
bldObj.setHead4Margins(
self._build.getFloat("format.h4MarginT"),
self._build.getFloat("format.h4MarginB"),
)
bldObj.setTextMargins(
self._build.getFloat("format.textMarginT"),
self._build.getFloat("format.textMarginB"),
)
bldObj.setSeparatorMargins(
self._build.getFloat("format.sepMarginT"),
self._build.getFloat("format.sepMarginB"),
)
bldObj.setBodyText(self._build.getBool("text.includeBodyText")) bldObj.setBodyText(self._build.getBool("text.includeBodyText"))
bldObj.setSynopsis(self._build.getBool("text.includeSynopsis")) bldObj.setSynopsis(self._build.getBool("text.includeSynopsis"))
bldObj.setComments(self._build.getBool("text.includeComments")) bldObj.setComments(self._build.getBool("text.includeComments"))
+5 -5
View File
@@ -34,7 +34,7 @@ from PyQt5.QtWidgets import QAction, QMenuBar
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import openExternalPath from novelwriter.common import openExternalPath
from novelwriter.constants import nwConst, nwKeyWords, nwLabels, nwUnicode, trConst from novelwriter.constants import nwConst, nwHeaders, nwKeyWords, nwLabels, nwUnicode, trConst
from novelwriter.enum import nwDocAction, nwDocInsert, nwFocus, nwView from novelwriter.enum import nwDocAction, nwDocInsert, nwFocus, nwView
from novelwriter.extensions.eventfilters import StatusTipFilter from novelwriter.extensions.eventfilters import StatusTipFilter
@@ -700,28 +700,28 @@ class GuiMainMenu(QMenuBar):
self.fmtMenu.addSeparator() self.fmtMenu.addSeparator()
# Format > Heading 1 (Partition) # Format > Heading 1 (Partition)
self.aFmtHead1 = self.fmtMenu.addAction(self.tr("Heading 1 (Partition)")) self.aFmtHead1 = self.fmtMenu.addAction(trConst(nwHeaders.H_LABEL["H1"]))
self.aFmtHead1.setShortcut("Ctrl+1") self.aFmtHead1.setShortcut("Ctrl+1")
self.aFmtHead1.triggered.connect( self.aFmtHead1.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H1) lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H1)
) )
# Format > Heading 2 (Chapter) # Format > Heading 2 (Chapter)
self.aFmtHead2 = self.fmtMenu.addAction(self.tr("Heading 2 (Chapter)")) self.aFmtHead2 = self.fmtMenu.addAction(trConst(nwHeaders.H_LABEL["H2"]))
self.aFmtHead2.setShortcut("Ctrl+2") self.aFmtHead2.setShortcut("Ctrl+2")
self.aFmtHead2.triggered.connect( self.aFmtHead2.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H2) lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H2)
) )
# Format > Heading 3 (Scene) # Format > Heading 3 (Scene)
self.aFmtHead3 = self.fmtMenu.addAction(self.tr("Heading 3 (Scene)")) self.aFmtHead3 = self.fmtMenu.addAction(trConst(nwHeaders.H_LABEL["H3"]))
self.aFmtHead3.setShortcut("Ctrl+3") self.aFmtHead3.setShortcut("Ctrl+3")
self.aFmtHead3.triggered.connect( self.aFmtHead3.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H3) lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H3)
) )
# Format > Heading 4 (Section) # Format > Heading 4 (Section)
self.aFmtHead4 = self.fmtMenu.addAction(self.tr("Heading 4 (Section)")) self.aFmtHead4 = self.fmtMenu.addAction(trConst(nwHeaders.H_LABEL["H4"]))
self.aFmtHead4.setShortcut("Ctrl+4") self.aFmtHead4.setShortcut("Ctrl+4")
self.aFmtHead4.triggered.connect( self.aFmtHead4.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H4) lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H4)
+130 -4
View File
@@ -38,7 +38,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import describeFont from novelwriter.common import describeFont
from novelwriter.constants import nwHeadFmt, nwKeyWords, nwLabels, trConst from novelwriter.constants import nwHeaders, nwHeadFmt, nwKeyWords, nwLabels, trConst
from novelwriter.core.buildsettings import BuildSettings, FilterMode from novelwriter.core.buildsettings import BuildSettings, FilterMode
from novelwriter.extensions.configlayout import ( from novelwriter.extensions.configlayout import (
NColourLabel, NFixedPage, NScrollableForm, NScrollablePage NColourLabel, NFixedPage, NScrollableForm, NScrollablePage
@@ -1076,6 +1076,98 @@ class _FormattingTab(NScrollableForm):
self.addRow(self._build.getLabel("format.firstIndentWidth"), self.indentWidth, unit="em") self.addRow(self._build.getLabel("format.firstIndentWidth"), self.indentWidth, unit="em")
self.addRow(self._build.getLabel("format.indentFirstPar"), self.indentFirstPar) self.addRow(self._build.getLabel("format.indentFirstPar"), self.indentFirstPar)
# Text Margins
# ============
title = self._build.getLabel("format.grpMargins")
section += 1
self._sidebar.addButton(title, section)
self.addGroupLabel(title, section)
# Title
self.titleMarginT = NDoubleSpinBox(self)
self.titleMarginT.setFixedWidth(dbW)
self.titleMarginB = NDoubleSpinBox(self)
self.titleMarginB.setFixedWidth(dbW)
self.addRow(
trConst(nwHeaders.H_LABEL["H0"]),
[trT, self.titleMarginT, 6, trB, self.titleMarginB],
)
# Heading 1
self.h1MarginT = NDoubleSpinBox(self)
self.h1MarginT.setFixedWidth(dbW)
self.h1MarginB = NDoubleSpinBox(self)
self.h1MarginB.setFixedWidth(dbW)
self.addRow(
trConst(nwHeaders.H_LABEL["H1"]),
[trT, self.h1MarginT, 6, trB, self.h1MarginB],
)
# Heading 2
self.h2MarginT = NDoubleSpinBox(self)
self.h2MarginT.setFixedWidth(dbW)
self.h2MarginB = NDoubleSpinBox(self)
self.h2MarginB.setFixedWidth(dbW)
self.addRow(
trConst(nwHeaders.H_LABEL["H2"]),
[trT, self.h2MarginT, 6, trB, self.h2MarginB],
)
# Heading 3
self.h3MarginT = NDoubleSpinBox(self)
self.h3MarginT.setFixedWidth(dbW)
self.h3MarginB = NDoubleSpinBox(self)
self.h3MarginB.setFixedWidth(dbW)
self.addRow(
trConst(nwHeaders.H_LABEL["H3"]),
[trT, self.h3MarginT, 6, trB, self.h3MarginB],
)
# Heading 4
self.h4MarginT = NDoubleSpinBox(self)
self.h4MarginT.setFixedWidth(dbW)
self.h4MarginB = NDoubleSpinBox(self)
self.h4MarginB.setFixedWidth(dbW)
self.addRow(
trConst(nwHeaders.H_LABEL["H4"]),
[trT, self.h4MarginT, 6, trB, self.h4MarginB],
)
# Text
self.textMarginT = NDoubleSpinBox(self)
self.textMarginT.setFixedWidth(dbW)
self.textMarginB = NDoubleSpinBox(self)
self.textMarginB.setFixedWidth(dbW)
self.addRow(
self._build.getLabel("format.textMargin"),
[trT, self.textMarginT, 6, trB, self.textMarginB],
)
# Separator
self.sepMarginT = NDoubleSpinBox(self)
self.sepMarginT.setFixedWidth(dbW)
self.sepMarginB = NDoubleSpinBox(self)
self.sepMarginB.setFixedWidth(dbW)
self.addRow(
self._build.getLabel("format.sepMargin"),
[trT, self.sepMarginT, 6, trB, self.sepMarginB],
)
# Page Layout # Page Layout
# =========== # ===========
@@ -1106,7 +1198,7 @@ class _FormattingTab(NScrollableForm):
self.addRow( self.addRow(
self._build.getLabel("format.pageSize"), self._build.getLabel("format.pageSize"),
[self.pageSize, 8, trW, self.pageWidth, trH, self.pageHeight], [self.pageSize, 6, trW, self.pageWidth, 6, trH, self.pageHeight],
) )
# Page Margins # Page Margins
@@ -1124,11 +1216,11 @@ class _FormattingTab(NScrollableForm):
self.addRow( self.addRow(
self._build.getLabel("format.pageMargins"), self._build.getLabel("format.pageMargins"),
[trT, self.topMargin, trB, self.bottomMargin], [trT, self.topMargin, 6, trB, self.bottomMargin],
) )
self.addRow( self.addRow(
"", "",
[trL, self.leftMargin, trR, self.rightMargin], [trL, self.leftMargin, 6, trR, self.rightMargin],
) )
# Open Document # Open Document
@@ -1220,6 +1312,24 @@ class _FormattingTab(NScrollableForm):
self.indentWidth.setValue(self._build.getFloat("format.firstIndentWidth")) self.indentWidth.setValue(self._build.getFloat("format.firstIndentWidth"))
self.indentFirstPar.setChecked(self._build.getBool("format.indentFirstPar")) self.indentFirstPar.setChecked(self._build.getBool("format.indentFirstPar"))
# Text Margins
# ============
self.titleMarginT.setValue(self._build.getFloat("format.titleMarginT"))
self.titleMarginB.setValue(self._build.getFloat("format.titleMarginB"))
self.h1MarginT.setValue(self._build.getFloat("format.h1MarginT"))
self.h1MarginB.setValue(self._build.getFloat("format.h1MarginB"))
self.h2MarginT.setValue(self._build.getFloat("format.h2MarginT"))
self.h2MarginB.setValue(self._build.getFloat("format.h2MarginB"))
self.h3MarginT.setValue(self._build.getFloat("format.h3MarginT"))
self.h3MarginB.setValue(self._build.getFloat("format.h3MarginB"))
self.h4MarginT.setValue(self._build.getFloat("format.h4MarginT"))
self.h4MarginB.setValue(self._build.getFloat("format.h4MarginB"))
self.textMarginT.setValue(self._build.getFloat("format.textMarginT"))
self.textMarginB.setValue(self._build.getFloat("format.textMarginB"))
self.sepMarginT.setValue(self._build.getFloat("format.sepMarginT"))
self.sepMarginB.setValue(self._build.getFloat("format.sepMarginB"))
# Page Layout # Page Layout
# =========== # ===========
@@ -1290,6 +1400,22 @@ class _FormattingTab(NScrollableForm):
self._build.setValue("format.firstIndentWidth", self.indentWidth.value()) self._build.setValue("format.firstIndentWidth", self.indentWidth.value())
self._build.setValue("format.indentFirstPar", self.indentFirstPar.isChecked()) self._build.setValue("format.indentFirstPar", self.indentFirstPar.isChecked())
# Text Margins
self._build.setValue("format.titleMarginT", self.titleMarginT.value())
self._build.setValue("format.titleMarginB", self.titleMarginB.value())
self._build.setValue("format.h1MarginT", self.h1MarginT.value())
self._build.setValue("format.h1MarginB", self.h1MarginB.value())
self._build.setValue("format.h2MarginT", self.h2MarginT.value())
self._build.setValue("format.h2MarginB", self.h2MarginB.value())
self._build.setValue("format.h3MarginT", self.h3MarginT.value())
self._build.setValue("format.h3MarginB", self.h3MarginB.value())
self._build.setValue("format.h4MarginT", self.h4MarginT.value())
self._build.setValue("format.h4MarginB", self.h4MarginB.value())
self._build.setValue("format.textMarginT", self.textMarginT.value())
self._build.setValue("format.textMarginB", self.textMarginB.value())
self._build.setValue("format.sepMarginT", self.sepMarginT.value())
self._build.setValue("format.sepMarginB", self.sepMarginB.value())
# Page Layout # Page Layout
self._build.setValue("format.pageUnit", str(self.pageUnit.currentData())) self._build.setValue("format.pageUnit", str(self.pageUnit.currentData()))
self._build.setValue("format.pageSize", str(self.pageSize.currentData())) self._build.setValue("format.pageSize", str(self.pageSize.currentData()))