Add support for page layout settings in builds

This commit is contained in:
Veronica Berglyd Olsen
2023-07-19 23:55:00 +02:00
parent bebf487776
commit ac92e5b126
5 changed files with 283 additions and 51 deletions
+14 -4
View File
@@ -22,16 +22,16 @@ General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
from __future__ import annotations
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP
from novelwriter.enum import nwBuildFmt, nwItemClass, nwItemLayout, nwOutline from novelwriter.enum import nwBuildFmt, nwItemClass, nwItemLayout, nwOutline
def trConst(tString): def trConst(text: str) -> str:
"""Wrapper function for locally translating constants. """Wrapper function for locally translating constants."""
""" return QCoreApplication.translate("Constant", text)
return QCoreApplication.translate("Constant", tString)
class nwConst: class nwConst:
@@ -225,6 +225,16 @@ class nwLabels:
nwBuildFmt.J_HTML: ".json", nwBuildFmt.J_HTML: ".json",
nwBuildFmt.J_NWD: ".json", nwBuildFmt.J_NWD: ".json",
} }
UNIT_NAME = {
"mm": QT_TRANSLATE_NOOP("Constant", "Millimetres"),
"cm": QT_TRANSLATE_NOOP("Constant", "Centimetres"),
"in": QT_TRANSLATE_NOOP("Constant", "Inches"),
}
UNIT_SCALE = {
"mm": 1.0,
"cm": 10.0,
"in": 25.4,
}
# END Class nwLabels # END Class nwLabels
+32 -6
View File
@@ -71,6 +71,14 @@ SETTINGS_TEMPLATE = {
"format.justifyText": (bool, False), "format.justifyText": (bool, False),
"format.stripUnicode": (bool, False), "format.stripUnicode": (bool, False),
"format.replaceTabs": (bool, False), "format.replaceTabs": (bool, False),
"format.pageUnit": (str, "cm"),
"format.pageSize": (str, "A4"),
"format.pageWidth": (float, 21.0),
"format.pageHeight": (float, 29.7),
"format.topMargin": (float, 2.0),
"format.bottomMargin": (float, 2.0),
"format.leftMargin": (float, 2.0),
"format.rightMargin": (float, 2.0),
"odt.addColours": (bool, True), "odt.addColours": (bool, True),
"html.addStyles": (bool, True), "html.addStyles": (bool, True),
} }
@@ -99,7 +107,7 @@ SETTINGS_LABELS = {
"text.addNoteHeadings": QT_TRANSLATE_NOOP("Builds", "Add Titles for Notes"), "text.addNoteHeadings": QT_TRANSLATE_NOOP("Builds", "Add Titles for Notes"),
"format.grpFormat": QT_TRANSLATE_NOOP("Builds", "Text Format"), "format.grpFormat": QT_TRANSLATE_NOOP("Builds", "Text Format"),
"format.buildLang": QT_TRANSLATE_NOOP("Builds", "Document Language"), "format.buildLang": QT_TRANSLATE_NOOP("Builds", "Language"),
"format.textFont": QT_TRANSLATE_NOOP("Builds", "Font Family"), "format.textFont": QT_TRANSLATE_NOOP("Builds", "Font Family"),
"format.textSize": QT_TRANSLATE_NOOP("Builds", "Font Size"), "format.textSize": QT_TRANSLATE_NOOP("Builds", "Font Size"),
"format.lineHeight": QT_TRANSLATE_NOOP("Builds", "Line Height"), "format.lineHeight": QT_TRANSLATE_NOOP("Builds", "Line Height"),
@@ -107,6 +115,15 @@ SETTINGS_LABELS = {
"format.justifyText": QT_TRANSLATE_NOOP("Builds", "Justify Text Margins"), "format.justifyText": QT_TRANSLATE_NOOP("Builds", "Justify Text Margins"),
"format.stripUnicode": QT_TRANSLATE_NOOP("Builds", "Replace Unicode Characters"), "format.stripUnicode": QT_TRANSLATE_NOOP("Builds", "Replace Unicode Characters"),
"format.replaceTabs": QT_TRANSLATE_NOOP("Builds", "Replace Tabs with Spaces"), "format.replaceTabs": QT_TRANSLATE_NOOP("Builds", "Replace Tabs with Spaces"),
"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"),
"odt": QT_TRANSLATE_NOOP("Builds", "Open Document"), "odt": QT_TRANSLATE_NOOP("Builds", "Open Document"),
"odt.addColours": QT_TRANSLATE_NOOP("Builds", "Add Highlight Colours"), "odt.addColours": QT_TRANSLATE_NOOP("Builds", "Add Highlight Colours"),
@@ -115,6 +132,15 @@ SETTINGS_LABELS = {
"html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"), "html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"),
} }
PAGE_SIZES = {
"A4": (210.0, 297.0),
"A5": (148.0, 210.0),
"A6": (105.0, 148.0),
"Legal": (215.9, 355.6),
"Letter": (215.9, 279.4),
"Custom": (-1.0, -1.0),
}
class FilterMode(Enum): class FilterMode(Enum):
"""The decision reason for an item in a filtered project.""" """The decision reason for an item in a filtered project."""
@@ -160,7 +186,7 @@ class BuildSettings:
@property @property
def buildID(self) -> str: def buildID(self) -> str:
"""The build ID as an UUID.""" """The build ID as a UUID."""
return self._uuid return self._uuid
@property @property
@@ -196,24 +222,24 @@ class BuildSettings:
def getStr(self, key: str) -> str: def getStr(self, key: str) -> str:
"""Type safe value access for strings.""" """Type safe value access for strings."""
value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None)[1])) value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None))[1])
return str(value) return str(value)
def getBool(self, key: str) -> bool: def getBool(self, key: str) -> bool:
"""Type safe value access for bools.""" """Type safe value access for bools."""
value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None)[1])) value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None))[1])
return bool(value) return bool(value)
def getInt(self, key: str) -> int: def getInt(self, key: str) -> int:
"""Type safe value access for integers.""" """Type safe value access for integers."""
value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None)[1])) value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None))[1])
if isinstance(value, (int, float)): if isinstance(value, (int, float)):
return int(value) return int(value)
return 0 return 0
def getFloat(self, key: str) -> float: def getFloat(self, key: str) -> float:
"""Type safe value access for floats.""" """Type safe value access for floats."""
value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None)[1])) value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None))[1])
if isinstance(value, (int, float)): if isinstance(value, (int, float)):
return float(value) return float(value)
return 0.0 return 0.0
+13 -1
View File
@@ -33,13 +33,14 @@ from PyQt5.QtGui import QFont, QFontInfo
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.enum import nwBuildFmt from novelwriter.enum import nwBuildFmt
from novelwriter.error import formatException, logException from novelwriter.error import formatException, logException
from novelwriter.constants import nwLabels
from novelwriter.core.item import NWItem from novelwriter.core.item import NWItem
from novelwriter.core.tomd import ToMarkdown from novelwriter.core.tomd import ToMarkdown
from novelwriter.core.toodt import ToOdt from novelwriter.core.toodt import ToOdt
from novelwriter.core.tohtml import ToHtml from novelwriter.core.tohtml import ToHtml
from novelwriter.core.project import NWProject from novelwriter.core.project import NWProject
from novelwriter.core.tokenizer import Tokenizer from novelwriter.core.tokenizer import Tokenizer
from novelwriter.core.buildsettings import BuildSettings from novelwriter.core.buildsettings import PAGE_SIZES, BuildSettings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -290,6 +291,17 @@ class NWBuildDocument:
bldObj.setColourHeaders(self._build.getBool("odt.addColours")) bldObj.setColourHeaders(self._build.getBool("odt.addColours"))
bldObj.setLanguage(buildLang) bldObj.setLanguage(buildLang)
scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0)
width, height = PAGE_SIZES.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
bldObj.setPageLayout(
width if width > 0.0 else scale*self._build.getFloat("format.pageWidth"),
height if height > 0.0 else scale*self._build.getFloat("format.pageHeight"),
scale*self._build.getFloat("format.topMargin"),
scale*self._build.getFloat("format.bottomMargin"),
scale*self._build.getFloat("format.leftMargin"),
scale*self._build.getFloat("format.rightMargin"),
)
filtered = self._build.buildItemFilter( filtered = self._build.buildItemFilter(
self._project, withRoots=self._build.getBool("text.addNoteHeadings") self._project, withRoots=self._build.getBool("text.addNoteHeadings")
) )
+24 -6
View File
@@ -147,7 +147,7 @@ class ToOdt(Tokenizer):
self._dLanguage = "en" self._dLanguage = "en"
self._dCountry = "GB" self._dCountry = "GB"
# Text Margings in Units of em # Text Margings
self._mTopTitle = "0.423cm" self._mTopTitle = "0.423cm"
self._mTopHead1 = "0.423cm" self._mTopHead1 = "0.423cm"
self._mTopHead2 = "0.353cm" self._mTopHead2 = "0.353cm"
@@ -166,11 +166,13 @@ class ToOdt(Tokenizer):
self._mBotText = "0.247cm" self._mBotText = "0.247cm"
self._mBotMeta = "0.106cm" self._mBotMeta = "0.106cm"
# Document Margins # Document Size and Margins
self._mDocTop = "2.000cm" self._mDocWidth = "21.0cm"
self._mDocBtm = "2.000cm" self._mDocHeight = "29.7cm"
self._mDocLeft = "2.000cm" self._mDocTop = "2.000cm"
self._mDocRight = "2.000cm" self._mDocBtm = "2.000cm"
self._mDocLeft = "2.000cm"
self._mDocRight = "2.000cm"
# Colour # Colour
self._colHead12 = None self._colHead12 = None
@@ -200,6 +202,19 @@ class ToOdt(Tokenizer):
self._colourHead = state self._colourHead = state
return return
def setPageLayout(
self, width: int | float, height: int | float,
top: int | float, bottom: int | float, left: int | float, right: int | float
):
"""Set the document page size and margins in millimetres."""
self._mDocWidth = f"{width/10.0:.3f}cm"
self._mDocHeight = f"{height/10.0:.3f}cm"
self._mDocTop = f"{top/10.0:.3f}cm"
self._mDocBtm = f"{bottom/10.0:.3f}cm"
self._mDocLeft = f"{left/10.0:.3f}cm"
self._mDocRight = f"{right/10.0:.3f}cm"
return
## ##
# Class Methods # Class Methods
## ##
@@ -721,10 +736,13 @@ class ToOdt(Tokenizer):
xPage = ET.SubElement(self._xAut2, _mkTag("style", "page-layout"), attrib=tAttr) xPage = ET.SubElement(self._xAut2, _mkTag("style", "page-layout"), attrib=tAttr)
tAttr = {} tAttr = {}
tAttr[_mkTag("fo", "page-width")] = self._mDocWidth
tAttr[_mkTag("fo", "page-height")] = self._mDocHeight
tAttr[_mkTag("fo", "margin-top")] = self._mDocTop tAttr[_mkTag("fo", "margin-top")] = self._mDocTop
tAttr[_mkTag("fo", "margin-bottom")] = self._mDocBtm tAttr[_mkTag("fo", "margin-bottom")] = self._mDocBtm
tAttr[_mkTag("fo", "margin-left")] = self._mDocLeft tAttr[_mkTag("fo", "margin-left")] = self._mDocLeft
tAttr[_mkTag("fo", "margin-right")] = self._mDocRight tAttr[_mkTag("fo", "margin-right")] = self._mDocRight
tAttr[_mkTag("fo", "print-orientation")] = "portrait"
ET.SubElement(xPage, _mkTag("style", "page-layout-properties"), attrib=tAttr) ET.SubElement(xPage, _mkTag("style", "page-layout-properties"), attrib=tAttr)
xHead = ET.SubElement(xPage, _mkTag("style", "header-style")) xHead = ET.SubElement(xPage, _mkTag("style", "header-style"))
+200 -34
View File
@@ -40,8 +40,8 @@ from PyQt5.QtWidgets import (
) )
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.constants import nwHeadFmt from novelwriter.constants import nwHeadFmt, nwLabels, trConst
from novelwriter.core.buildsettings import BuildSettings, FilterMode from novelwriter.core.buildsettings import PAGE_SIZES, 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 NConfigLayout, NSimpleLayout from novelwriter.extensions.configlayout import NConfigLayout, NSimpleLayout
@@ -644,7 +644,7 @@ class _HeadingsTab(QWidget):
self.btnScene.clicked.connect(lambda: self._editHeading(self.EDIT_SCENE)) self.btnScene.clicked.connect(lambda: self._editHeading(self.EDIT_SCENE))
self.hdeScene = QLabel(self.tr("Hide")) self.hdeScene = QLabel(self.tr("Hide"))
self.hdeScene.setToolTip(sceneHideTip) self.hdeScene.setToolTip(sceneHideTip)
self.swtScene = NSwitch(width=2*iPx, height=iPx) self.swtScene = NSwitch(self, width=2*iPx, height=iPx)
self.swtScene.setToolTip(sceneHideTip) self.swtScene.setToolTip(sceneHideTip)
wrapScene = QHBoxLayout() wrapScene = QHBoxLayout()
@@ -671,7 +671,7 @@ class _HeadingsTab(QWidget):
self.btnSection.clicked.connect(lambda: self._editHeading(self.EDIT_SECTION)) self.btnSection.clicked.connect(lambda: self._editHeading(self.EDIT_SECTION))
self.hdeSection = QLabel(self.tr("Hide")) self.hdeSection = QLabel(self.tr("Hide"))
self.hdeSection.setToolTip(sectionHideTip) self.hdeSection.setToolTip(sectionHideTip)
self.swtSection = NSwitch(width=2*iPx, height=iPx) self.swtSection = NSwitch(self, width=2*iPx, height=iPx)
self.swtSection.setToolTip(sectionHideTip) self.swtSection.setToolTip(sectionHideTip)
wrapSection = QHBoxLayout() wrapSection = QHBoxLayout()
@@ -882,10 +882,10 @@ class _ContentTab(QWidget):
self.formLeft = NSimpleLayout() self.formLeft = NSimpleLayout()
self.formLeft.addGroupLabel(self._build.getLabel("text.grpContent")) self.formLeft.addGroupLabel(self._build.getLabel("text.grpContent"))
self.incSynopsis = NSwitch(width=2*iPx, height=iPx) self.incSynopsis = NSwitch(self, width=2*iPx, height=iPx)
self.incComments = NSwitch(width=2*iPx, height=iPx) self.incComments = NSwitch(self, width=2*iPx, height=iPx)
self.incKeywords = NSwitch(width=2*iPx, height=iPx) self.incKeywords = NSwitch(self, width=2*iPx, height=iPx)
self.incBodyText = NSwitch(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.includeSynopsis"), self.incSynopsis)
self.formLeft.addRow(self._build.getLabel("text.includeComments"), self.incComments) self.formLeft.addRow(self._build.getLabel("text.includeComments"), self.incComments)
@@ -898,7 +898,7 @@ class _ContentTab(QWidget):
self.formRight = NSimpleLayout() self.formRight = NSimpleLayout()
self.formRight.addGroupLabel(self._build.getLabel("text.grpInsert")) self.formRight.addGroupLabel(self._build.getLabel("text.grpInsert"))
self.addNoteHead = NSwitch(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.formRight.addRow(self._build.getLabel("text.addNoteHeadings"), self.addNoteHead)
@@ -945,33 +945,34 @@ class _FormatTab(QWidget):
self.mainTheme = buildMain.mainGui.mainTheme self.mainTheme = buildMain.mainGui.mainTheme
self._build = build self._build = build
self._unitScale = 1.0
iPx = self.mainTheme.baseIconSize iPx = self.mainTheme.baseIconSize
spW = 6*self.mainTheme.textNWidth
dbW = 8*self.mainTheme.textNWidth
# Form # Text Format Form
# ==== # ================
self.mainForm = NConfigLayout() self.formFormat = NConfigLayout()
self.mainForm.addGroupLabel(self._build.getLabel("format.grpFormat")) self.formFormat.addGroupLabel(self._build.getLabel("format.grpFormat"))
# Build Language # Build Language
self.buildLang = QComboBox() self.buildLang = QComboBox()
self.buildLang.setMinimumWidth(CONFIG.pxInt(250))
langauges = CONFIG.listLanguages(CONFIG.LANG_PROJ) langauges = CONFIG.listLanguages(CONFIG.LANG_PROJ)
self.buildLang.addItem("[%s]" % self.tr("Not Set"), "None") self.buildLang.addItem("[%s]" % self.tr("Not Set"), "None")
for langID, langName in langauges: for langID, langName in langauges:
self.buildLang.addItem(langName, langID) self.buildLang.addItem(langName, langID)
self.mainForm.addRow(self._build.getLabel("format.buildLang"), self.buildLang) self.formFormat.addRow(self._build.getLabel("format.buildLang"), self.buildLang)
# Font Family # Font Family
self.textFont = QLineEdit() self.textFont = QLineEdit()
self.textFont.setReadOnly(True) self.textFont.setReadOnly(True)
self.textFont.setMinimumWidth(CONFIG.pxInt(200))
self.btnTextFont = QPushButton("...") self.btnTextFont = QPushButton("...")
self.btnTextFont.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("..."))) self.btnTextFont.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("...")))
self.btnTextFont.clicked.connect(self._selectFont) self.btnTextFont.clicked.connect(self._selectFont)
self.mainForm.addRow( self.formFormat.addRow(
self._build.getLabel("format.textFont"), self.textFont, button=self.btnTextFont self._build.getLabel("format.textFont"), self.textFont, button=self.btnTextFont
) )
@@ -980,39 +981,104 @@ class _FormatTab(QWidget):
self.textSize.setMinimum(8) self.textSize.setMinimum(8)
self.textSize.setMaximum(60) self.textSize.setMaximum(60)
self.textSize.setSingleStep(1) self.textSize.setSingleStep(1)
self.textSize.setMinimumWidth(CONFIG.pxInt(60)) self.textSize.setMinimumWidth(spW)
self.mainForm.addRow( self.formFormat.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)
self.lineHeight.setFixedWidth(6*self.mainTheme.textNWidth) self.lineHeight.setFixedWidth(spW)
self.lineHeight.setMinimum(0.75) self.lineHeight.setMinimum(0.75)
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.lineHeight.setMinimumWidth(CONFIG.pxInt(60)) self.formFormat.addRow(
self.mainForm.addRow(
self._build.getLabel("format.lineHeight"), self.lineHeight, unit="em" self._build.getLabel("format.lineHeight"), self.lineHeight, unit="em"
) )
# Switches # Text Options Form
self.mainForm.addGroupLabel(self._build.getLabel("format.grpOptions")) # =================
self.mainForm.setContentsMargins(0, 0, 0, 0)
self.justifyText = NSwitch(width=2*iPx, height=iPx) self.formOptions = NSimpleLayout()
self.stripUnicode = NSwitch(width=2*iPx, height=iPx) self.formOptions.addGroupLabel(self._build.getLabel("format.grpOptions"))
self.replaceTabs = NSwitch(width=2*iPx, height=iPx) self.formOptions.setContentsMargins(0, 0, 0, 0)
self.mainForm.addRow(self._build.getLabel("format.justifyText"), self.justifyText) self.justifyText = NSwitch(self, width=2*iPx, height=iPx)
self.mainForm.addRow(self._build.getLabel("format.stripUnicode"), self.stripUnicode) self.stripUnicode = NSwitch(self, width=2*iPx, height=iPx)
self.mainForm.addRow(self._build.getLabel("format.replaceTabs"), self.replaceTabs) 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)
# Page Layout Form
# ================
self.formLayout = NSimpleLayout()
self.formLayout.addGroupLabel(self._build.getLabel("format.grpPage"))
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.pageUnit = QComboBox(self)
for key, name in nwLabels.UNIT_NAME.items():
self.pageUnit.addItem(trConst(name), key)
self.pageSize = QComboBox(self)
for key, size in PAGE_SIZES.items():
self.pageSize.addItem(key, size)
self.pageWidth = QDoubleSpinBox(self)
self.pageWidth.setFixedWidth(dbW)
self.pageWidth.setMaximum(500.0)
self.pageHeight = QDoubleSpinBox(self)
self.pageHeight.setFixedWidth(dbW)
self.pageHeight.setMaximum(500.0)
self.topMargin = QDoubleSpinBox(self)
self.topMargin.setFixedWidth(dbW)
self.bottomMargin = QDoubleSpinBox(self)
self.bottomMargin.setFixedWidth(dbW)
self.leftMargin = QDoubleSpinBox(self)
self.leftMargin.setFixedWidth(dbW)
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)
# Assemble GUI # Assemble GUI
# ============ # ============
self.setLayout(self.mainForm) 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
@@ -1034,6 +1100,29 @@ class _FormatTab(QWidget):
self.stripUnicode.setChecked(self._build.getBool("format.stripUnicode")) self.stripUnicode.setChecked(self._build.getBool("format.stripUnicode"))
self.replaceTabs.setChecked(self._build.getBool("format.replaceTabs")) self.replaceTabs.setChecked(self._build.getBool("format.replaceTabs"))
pageUnit = self._build.getStr("format.pageUnit")
index = self.pageUnit.findData(pageUnit)
if index >= 0:
self.pageUnit.setCurrentIndex(index)
self._unitScale = nwLabels.UNIT_SCALE.get(pageUnit, 1.0)
self._changeUnit(index)
self.pageWidth.setValue(self._build.getFloat("format.pageWidth"))
self.pageHeight.setValue(self._build.getFloat("format.pageHeight"))
self.topMargin.setValue(self._build.getFloat("format.topMargin"))
self.bottomMargin.setValue(self._build.getFloat("format.bottomMargin"))
self.leftMargin.setValue(self._build.getFloat("format.leftMargin"))
self.rightMargin.setValue(self._build.getFloat("format.rightMargin"))
pageSize = self._build.getStr("format.pageSize")
index = self.pageSize.findText(pageSize)
if index >= 0:
self.pageSize.setCurrentIndex(index)
self._changePageSize(index)
self.pageUnit.currentIndexChanged.connect(self._changeUnit)
self.pageSize.currentIndexChanged.connect(self._changePageSize)
return return
def saveContent(self): def saveContent(self):
@@ -1045,6 +1134,14 @@ class _FormatTab(QWidget):
self._build.setValue("format.justifyText", self.justifyText.isChecked()) self._build.setValue("format.justifyText", self.justifyText.isChecked())
self._build.setValue("format.stripUnicode", self.stripUnicode.isChecked()) self._build.setValue("format.stripUnicode", self.stripUnicode.isChecked())
self._build.setValue("format.replaceTabs", self.replaceTabs.isChecked()) self._build.setValue("format.replaceTabs", self.replaceTabs.isChecked())
self._build.setValue("format.pageUnit", str(self.pageUnit.currentData()))
self._build.setValue("format.pageSize", str(self.pageSize.currentText()))
self._build.setValue("format.pageWidth", self.pageWidth.value())
self._build.setValue("format.pageHeight", self.pageHeight.value())
self._build.setValue("format.topMargin", self.topMargin.value())
self._build.setValue("format.bottomMargin", self.bottomMargin.value())
self._build.setValue("format.leftMargin", self.leftMargin.value())
self._build.setValue("format.rightMargin", self.rightMargin.value())
return return
## ##
@@ -1063,6 +1160,75 @@ class _FormatTab(QWidget):
self.textSize.setValue(theFont.pointSize()) self.textSize.setValue(theFont.pointSize())
return return
@pyqtSlot(int)
def _changeUnit(self, index: int):
"""The current unit change, so recalculate sizes."""
newUnit = self.pageUnit.itemData(index)
newScale = nwLabels.UNIT_SCALE.get(newUnit, 1.0)
reScale = self._unitScale/newScale
pageWidth = self.pageWidth.value() * reScale
pageHeight = self.pageHeight.value() * reScale
topMargin = self.topMargin.value() * reScale
bottomMargin = self.bottomMargin.value() * reScale
leftMargin = self.leftMargin.value() * reScale
rightMargin = self.rightMargin.value() * reScale
isMM = newUnit == "mm"
nDec = 1 if isMM else 2
nStep = 1.0 if isMM else 0.1
pMax = 500.0 if isMM else 50.0
mMax = 150.0 if isMM else 15.0
self.pageWidth.setDecimals(nDec)
self.pageWidth.setSingleStep(nStep)
self.pageWidth.setMaximum(pMax)
self.pageWidth.setValue(pageWidth)
self.pageHeight.setDecimals(nDec)
self.pageHeight.setSingleStep(nStep)
self.pageHeight.setMaximum(pMax)
self.pageHeight.setValue(pageHeight)
self.topMargin.setDecimals(nDec)
self.topMargin.setSingleStep(nStep)
self.topMargin.setMaximum(mMax)
self.topMargin.setValue(topMargin)
self.bottomMargin.setDecimals(nDec)
self.bottomMargin.setSingleStep(nStep)
self.bottomMargin.setMaximum(mMax)
self.bottomMargin.setValue(bottomMargin)
self.leftMargin.setDecimals(nDec)
self.leftMargin.setSingleStep(nStep)
self.leftMargin.setMaximum(mMax)
self.leftMargin.setValue(leftMargin)
self.rightMargin.setDecimals(nDec)
self.rightMargin.setSingleStep(nStep)
self.rightMargin.setMaximum(mMax)
self.rightMargin.setValue(rightMargin)
self._unitScale = newScale
return
@pyqtSlot(int)
def _changePageSize(self, index: int):
"""The page size has changed."""
self.pageWidth.setEnabled(True)
self.pageHeight.setEnabled(True)
width, height = self.pageSize.itemData(index) if index >= 0 else (-1.0, -1.0)
if width > 0.0 and height > 0.0:
self.pageWidth.setEnabled(False)
self.pageHeight.setEnabled(False)
self.pageWidth.setValue(width/self._unitScale)
self.pageHeight.setValue(height/self._unitScale)
return
# END Class _FormatTab # END Class _FormatTab
@@ -1084,7 +1250,7 @@ class _OutputTab(QWidget):
self.formLeft = NSimpleLayout() self.formLeft = NSimpleLayout()
self.formLeft.addGroupLabel(self._build.getLabel("odt")) self.formLeft.addGroupLabel(self._build.getLabel("odt"))
self.odtAddColours = NSwitch(width=2*iPx, height=iPx) self.odtAddColours = NSwitch(self, width=2*iPx, height=iPx)
self.formLeft.addRow(self._build.getLabel("odt.addColours"), self.odtAddColours) self.formLeft.addRow(self._build.getLabel("odt.addColours"), self.odtAddColours)
@@ -1094,7 +1260,7 @@ class _OutputTab(QWidget):
self.formRight = NSimpleLayout() self.formRight = NSimpleLayout()
self.formRight.addGroupLabel(self._build.getLabel("html")) self.formRight.addGroupLabel(self._build.getLabel("html"))
self.htmlAddStyles = NSwitch(width=2*iPx, height=iPx) self.htmlAddStyles = NSwitch(self, width=2*iPx, height=iPx)
self.formRight.addRow(self._build.getLabel("html.addStyles"), self.htmlAddStyles) self.formRight.addRow(self._build.getLabel("html.addStyles"), self.htmlAddStyles)