From 3b0086e75e1d7e85ac3f8430ef38c319e4ec1336 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:56:31 +0100 Subject: [PATCH] Use a frame for page break marker in manuscript preview --- novelwriter/formats/toqdoc.py | 26 +++++++++++++++-------- tests/test_tools/test_tools_manuscript.py | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/novelwriter/formats/toqdoc.py b/novelwriter/formats/toqdoc.py index f0f495e2..0c11168f 100644 --- a/novelwriter/formats/toqdoc.py +++ b/novelwriter/formats/toqdoc.py @@ -30,7 +30,7 @@ from pathlib import Path from PyQt5.QtCore import QMarginsF, QSizeF from PyQt5.QtGui import ( QColor, QFont, QFontDatabase, QPageSize, QTextBlockFormat, QTextCharFormat, - QTextCursor, QTextDocument + QTextCursor, QTextDocument, QTextFrameFormat ) from PyQt5.QtPrintSupport import QPrinter @@ -432,17 +432,22 @@ class ToQTextDocument(Tokenizer): def _insertNewPageMarker(self, cursor: QTextCursor) -> None: """Insert a new page marker.""" if self._newPage: - cursor.insertHtml("
") + bgCol = QColor(self._theme.text) + bgCol.setAlphaF(0.1) + fgCol = QColor(self._theme.text) + fgCol.setAlphaF(0.8) - hFmt = cursor.blockFormat() - hFmt.setBottomMargin(0.0) - hFmt.setLineHeight(75.0, QtPropLineHeight) - cursor.setBlockFormat(hFmt) + fFmt = QTextFrameFormat() + fFmt.setBorderStyle(QTextFrameFormat.BorderStyle.BorderStyle_None) + fFmt.setBackground(bgCol) + fFmt.setTopMargin(self._mSep[0]) + fFmt.setBottomMargin(self._mSep[1]) bFmt = QTextBlockFormat(self._blockFmt) bFmt.setAlignment(QtAlignCenter) bFmt.setTopMargin(0.0) - bFmt.setLineHeight(75.0, QtPropLineHeight) + bFmt.setBottomMargin(0.0) + bFmt.setLineHeight(100.0, QtPropLineHeight) cFmt = QTextCharFormat(self._charFmt) cFmt.setFontItalic(False) @@ -450,10 +455,13 @@ class ToQTextDocument(Tokenizer): cFmt.setFontStrikeOut(False) cFmt.setFontWeight(QFont.Weight.Normal) cFmt.setFontPointSize(0.75*self._textFont.pointSizeF()) - cFmt.setForeground(self._theme.comment) + cFmt.setForeground(fgCol) - newBlock(cursor, bFmt) + cursor.insertFrame(fFmt) + cursor.setBlockFormat(bFmt) cursor.insertText(self._project.localLookup("New Page"), cFmt) + cursor.swap(self._document.rootFrame().lastCursorPosition()) + return def _genHeadStyle(self, hType: BlockTyp, hKey: str, rFmt: QTextBlockFormat) -> T_TextStyle: diff --git a/tests/test_tools/test_tools_manuscript.py b/tests/test_tools/test_tools_manuscript.py index 6d94477a..7aa744c2 100644 --- a/tests/test_tools/test_tools_manuscript.py +++ b/tests/test_tools/test_tools_manuscript.py @@ -48,7 +48,7 @@ def testToolManuscript_Init(monkeypatch, qtbot, nwGUI, projPath, mockRnd): buildTestProject(nwGUI, projPath) nwGUI.openProject(projPath) SHARED.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi") - allText = "New Novel\nBy Jane Doe\n\nNew Page\nA Chapter\n\t\tHi" + allText = "New Novel\nBy Jane Doe\nNew Page\n\nA Chapter\n\t\tHi" nwGUI.mainMenu.aBuildManuscript.activate(QAction.ActionEvent.Trigger) qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiManuscript) is not None, timeout=1000)