From aad35e2d7b3fda3dd18dfb0ffe9dfa991dd8900b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 15 Jun 2020 16:35:24 +0200 Subject: [PATCH] First some cleanup of the document widgets --- nw/gui/doceditor.py | 24 +++++++++++++++--------- nw/gui/docviewer.py | 23 ++++++++++++----------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 4c5d5ce7..bd491a4f 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -7,7 +7,7 @@ File History: Created: 2018-09-29 [0.0.1] GuiDocEditor - Created: 2019-04-22 [0.0.1] WordCounter + Created: 2019-04-22 [0.0.1] BackgroundWordCounter Created: 2020-04-25 [0.4.5] GuiDocEditHeader This file is a part of novelWriter @@ -126,7 +126,7 @@ class GuiDocEditor(QTextEdit): self.wcTimer.setInterval(int(self.wcInterval*1000)) self.wcTimer.timeout.connect(self._runCounter) - self.wCounter = WordCounter(self) + self.wCounter = BackgroundWordCounter(self) self.wCounter.finished.connect(self._updateCounts) self.initEditor() @@ -338,11 +338,7 @@ class GuiDocEditor(QTextEdit): docFormat = self.qDocument.rootFrame().frameFormat() docFormat.setLeftMargin(tM) - docFormat.setRightMargin(tM) - if tT > 0: - docFormat.setTopMargin(tT) - else: - docFormat.setTopMargin(0) + docFormat.setTopMargin(max(0, tT)) # Updating root frame triggers a QTextDocument->contentsChange # signal, which we do not want as it re-runs the syntax @@ -1205,7 +1201,12 @@ class GuiDocEditor(QTextEdit): # END Class GuiDocEditor -class WordCounter(QThread): +# =============================================================================================== # +# The Off GUI Thread Word Counter +# Runs the word counter in the background for the doCEditor +# =============================================================================================== # + +class BackgroundWordCounter(QThread): def __init__(self, theParent): QThread.__init__(self, theParent) @@ -1228,7 +1229,12 @@ class WordCounter(QThread): return -## END Class WordCounter +## END Class BackgroundWordCounter + +# =============================================================================================== # +# The Embedded Document Header +# Only used by DocEditor, and is at a fixed position in the QTextEdit's viewport +# =============================================================================================== # class GuiDocEditHeader(QWidget): diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 1059c277..8c2ea236 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -236,13 +236,14 @@ class GuiDocViewer(QTextBrowser): else: sW = 0 + cM = self.mainConf.getTextMargin() tB = self.frameWidth() tW = self.width() - 2*tB - sW tH = self.docHeader.height() fH = self.docFooter.height() fY = self.height() - fH - tB - tT = self.mainConf.getTextMargin() - tH - bT = self.mainConf.getTextMargin() - fH + tT = cM - tH + bT = cM - fH self.docHeader.setGeometry(tB, tB, tW, tH) self.docFooter.setGeometry(tB, fY, tW, fH) self.setViewportMargins(0, tH, 0, fH) @@ -558,16 +559,16 @@ class GuiDocViewHeader(QWidget): class GuiDocViewFooter(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, docViewer): + QWidget.__init__(self, docViewer) logger.debug("Initialising GuiDocViewFooter ...") self.mainConf = nw.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.optState = theParent.theProject.optState - self.viewMeta = theParent.theParent.viewMeta + self.docViewer = docViewer + self.theParent = docViewer.theParent + self.theTheme = docViewer.theTheme + self.viewMeta = docViewer.theParent.viewMeta self.theHandle = None # Make a QPalette that matches the Syntax Theme @@ -669,9 +670,9 @@ class GuiDocViewFooter(QWidget): """Toggle the sticky flag for the reference panel. """ logger.verbose("Reference sticky is %s" % str(theState)) - self.theParent.stickyRef = theState - if not theState and self.theParent.theHandle is not None: - self.viewMeta.refreshReferences(self.theParent.theHandle) + self.docViewer.stickyRef = theState + if not theState and self.docViewer.theHandle is not None: + self.viewMeta.refreshReferences(self.docViewer.theHandle) return # END Class GuiDocViewFooter