Make various fixes and tweaks, and update tests
This commit is contained in:
@@ -156,14 +156,15 @@ class Tokenizer(ABC):
|
||||
self._keepBreaks = True # Keep line breaks in paragraphs
|
||||
|
||||
# Margins
|
||||
self._marginTitle = (1.000, 0.500)
|
||||
self._marginHead1 = (1.000, 0.500)
|
||||
self._marginHead2 = (0.834, 0.500)
|
||||
self._marginHead3 = (0.584, 0.500)
|
||||
self._marginHead4 = (0.584, 0.500)
|
||||
self._marginTitle = (1.417, 0.500)
|
||||
self._marginHead1 = (1.417, 0.500)
|
||||
self._marginHead2 = (1.668, 0.500)
|
||||
self._marginHead3 = (1.168, 0.500)
|
||||
self._marginHead4 = (1.168, 0.500)
|
||||
self._marginText = (0.000, 0.584)
|
||||
self._marginMeta = (0.000, 0.584)
|
||||
self._marginFoot = (1.417, 0.467)
|
||||
self._marginSep = (1.168, 1.168)
|
||||
|
||||
# Title Formats
|
||||
self._fmtTitle = nwHeadFmt.TITLE # Formatting for titles
|
||||
@@ -379,6 +380,11 @@ class Tokenizer(ABC):
|
||||
self._marginMeta = (float(upper), float(lower))
|
||||
return
|
||||
|
||||
def setSeparatorMargins(self, upper: float, lower: float) -> None:
|
||||
"""Set the upper and lower meta text margin."""
|
||||
self._marginSep = (float(upper), float(lower))
|
||||
return
|
||||
|
||||
def setLinkHeadings(self, state: bool) -> None:
|
||||
"""Enable or disable adding an anchor before headings."""
|
||||
self._linkHeadings = state
|
||||
|
||||
@@ -192,6 +192,7 @@ class ToOdt(Tokenizer):
|
||||
self._mTopHead = "0.423cm"
|
||||
self._mTopText = "0.000cm"
|
||||
self._mTopMeta = "0.000cm"
|
||||
self._mTopSep = "0.247cm"
|
||||
|
||||
self._mBotTitle = "0.212cm"
|
||||
self._mBotHead1 = "0.212cm"
|
||||
@@ -201,6 +202,7 @@ class ToOdt(Tokenizer):
|
||||
self._mBotHead = "0.212cm"
|
||||
self._mBotText = "0.247cm"
|
||||
self._mBotMeta = "0.106cm"
|
||||
self._mBotSep = "0.247cm"
|
||||
|
||||
self._mBotFoot = "0.106cm"
|
||||
self._mLeftFoot = "0.600cm"
|
||||
@@ -299,6 +301,7 @@ class ToOdt(Tokenizer):
|
||||
self._mTopHead = self._emToCm(mScale * self._marginHead4[0])
|
||||
self._mTopText = self._emToCm(mScale * self._marginText[0])
|
||||
self._mTopMeta = self._emToCm(mScale * self._marginMeta[0])
|
||||
self._mTopSep = self._emToCm(mScale * self._marginSep[0])
|
||||
|
||||
self._mBotTitle = self._emToCm(mScale * self._marginTitle[1])
|
||||
self._mBotHead1 = self._emToCm(mScale * self._marginHead1[1])
|
||||
@@ -308,6 +311,7 @@ class ToOdt(Tokenizer):
|
||||
self._mBotHead = self._emToCm(mScale * self._marginHead4[1])
|
||||
self._mBotText = self._emToCm(mScale * self._marginText[1])
|
||||
self._mBotMeta = self._emToCm(mScale * self._marginMeta[1])
|
||||
self._mBotSep = self._emToCm(mScale * self._marginSep[1])
|
||||
|
||||
self._mLeftFoot = self._emToCm(self._marginFoot[0])
|
||||
self._mBotFoot = self._emToCm(self._marginFoot[1])
|
||||
@@ -501,7 +505,7 @@ class ToOdt(Tokenizer):
|
||||
self._addTextPar(xText, S_SEP, oStyle, tText)
|
||||
|
||||
elif tType == self.T_SKIP:
|
||||
self._addTextPar(xText, S_SEP, oStyle, "")
|
||||
self._addTextPar(xText, S_TEXT, oStyle, "")
|
||||
|
||||
elif tType == self.T_SYNOPSIS and self._doSynopsis:
|
||||
tTemp, tFmt = self._formatSynopsis(tText, tFormat, True)
|
||||
@@ -944,8 +948,8 @@ class ToOdt(Tokenizer):
|
||||
style.setParentStyleName("Standard")
|
||||
style.setNextStyleName(S_TEXT)
|
||||
style.setClass("text")
|
||||
style.setMarginTop(self._mTopText)
|
||||
style.setMarginBottom(self._mBotText)
|
||||
style.setMarginTop(self._mTopSep)
|
||||
style.setMarginBottom(self._mBotSep)
|
||||
style.setLineHeight(self._fLineHeight)
|
||||
style.setTextAlign("center")
|
||||
style.setFontName(self._fontFamily)
|
||||
|
||||
@@ -122,6 +122,7 @@ class ToQTextDocument(Tokenizer):
|
||||
|
||||
self._mText = (mScale * self._marginText[0], mScale * self._marginText[1])
|
||||
self._mMeta = (mScale * self._marginMeta[0], mScale * self._marginMeta[1])
|
||||
self._mSep = (mScale * self._marginSep[0], mScale * self._marginSep[1])
|
||||
|
||||
self._mIndent = mScale * 2.0
|
||||
|
||||
@@ -233,7 +234,10 @@ class ToQTextDocument(Tokenizer):
|
||||
cursor.insertText(tText.replace(nwHeadFmt.BR, "\n"), cFmt)
|
||||
|
||||
elif tType == self.T_SEP:
|
||||
newBlock(cursor, bFmt)
|
||||
sFmt = QTextBlockFormat(bFmt)
|
||||
sFmt.setTopMargin(self._mSep[0])
|
||||
sFmt.setBottomMargin(self._mSep[1])
|
||||
newBlock(cursor, sFmt)
|
||||
cursor.insertText(tText, self._cText)
|
||||
|
||||
elif tType == self.T_SKIP:
|
||||
@@ -270,7 +274,7 @@ class ToQTextDocument(Tokenizer):
|
||||
cursor = QTextCursor(self._document)
|
||||
cursor.movePosition(QTextCursor.MoveOperation.End)
|
||||
|
||||
bFmt, cFmt = self._genHeadStyle(self.T_HEAD3, -1, self._blockFmt)
|
||||
bFmt, cFmt = self._genHeadStyle(self.T_HEAD4, -1, self._blockFmt)
|
||||
newBlock(cursor, bFmt)
|
||||
cursor.insertText(self._localLookup("Footnotes"), cFmt)
|
||||
|
||||
@@ -362,7 +366,10 @@ class ToQTextDocument(Tokenizer):
|
||||
if (num := len(bits)) > 1:
|
||||
if bits[0] == nwKeyWords.TAG_KEY:
|
||||
one, two = self._project.index.parseValue(bits[1])
|
||||
cursor.insertText(one, self._cTag)
|
||||
cFmt = QTextCharFormat(self._cTag)
|
||||
cFmt.setAnchor(True)
|
||||
cFmt.setAnchorNames([f"tag_{one}".lower()])
|
||||
cursor.insertText(one, cFmt)
|
||||
if two:
|
||||
cursor.insertText(" | ", self._cText)
|
||||
cursor.insertText(two, self._cOptional)
|
||||
@@ -371,7 +378,7 @@ class ToQTextDocument(Tokenizer):
|
||||
cFmt = QTextCharFormat(self._cTag)
|
||||
cFmt.setFontUnderline(True)
|
||||
cFmt.setAnchor(True)
|
||||
cFmt.setAnchorHref(f"#{bits[0][1:]}={bit}")
|
||||
cFmt.setAnchorHref(f"#tag_{bit}".lower())
|
||||
cursor.insertText(bit, cFmt)
|
||||
if n < num:
|
||||
cursor.insertText(", ", self._cText)
|
||||
|
||||
@@ -151,6 +151,8 @@ class GuiDocViewer(QTextBrowser):
|
||||
docPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
|
||||
docPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
|
||||
self.viewport().setPalette(docPalette)
|
||||
self.docHeader.matchColours()
|
||||
self.docFooter.matchColours()
|
||||
|
||||
# Update theme colours
|
||||
self._docTheme.text = SHARED.theme.colText
|
||||
@@ -164,9 +166,6 @@ class GuiDocViewer(QTextBrowser):
|
||||
self._docTheme.tag = SHARED.theme.colTag
|
||||
self._docTheme.optional = SHARED.theme.colOpt
|
||||
|
||||
self.docHeader.matchColours()
|
||||
self.docFooter.matchColours()
|
||||
|
||||
# Set default text margins
|
||||
self.document().setDocumentMargin(0)
|
||||
|
||||
@@ -369,12 +368,10 @@ class GuiDocViewer(QTextBrowser):
|
||||
@pyqtSlot("QUrl")
|
||||
def _linkClicked(self, url: QUrl) -> None:
|
||||
"""Process a clicked link in the document."""
|
||||
link = url.url()
|
||||
logger.debug("Clicked link: '%s'", link)
|
||||
if len(link) > 0:
|
||||
bits = link.split("=")
|
||||
if len(bits) == 2:
|
||||
self.loadDocumentTagRequest.emit(bits[1], nwDocMode.VIEW)
|
||||
if link := url.url():
|
||||
logger.debug("Clicked link: '%s'", link)
|
||||
if (bits := link.partition("_")) and bits[2]:
|
||||
self.loadDocumentTagRequest.emit(bits[2], nwDocMode.VIEW)
|
||||
return
|
||||
|
||||
@pyqtSlot("QPoint")
|
||||
|
||||
Reference in New Issue
Block a user