From e4f2e088bb3ed5e964510e19dc2119e44a54d6bd Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 27 May 2020 01:18:37 +0200 Subject: [PATCH] Need more calls to update document margins due to the document title bar. --- nw/gui/elements/doceditor.py | 3 ++- nw/gui/elements/docviewer.py | 41 ++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index f0976786..45058360 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -228,7 +228,6 @@ class GuiDocEditor(QTextEdit): tHandle = self.theHandle self.clearEditor() self.loadText(tHandle, showStatus=False) - self.updateDocMargins() return def loadText(self, tHandle, tLine=None, showStatus=True): @@ -289,6 +288,7 @@ class GuiDocEditor(QTextEdit): """ self.setPlainText(theText) self.setDocumentChanged(True) + self.updateDocMargins() return def saveText(self): @@ -370,6 +370,7 @@ class GuiDocEditor(QTextEdit): """ if tHandle == self.theHandle: self.docTitle.setTitleFromHandle(self.theHandle) + self.updateDocMargins() return ## diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py index 3ad0df6f..3eefed49 100644 --- a/nw/gui/elements/docviewer.py +++ b/nw/gui/elements/docviewer.py @@ -145,6 +145,7 @@ class GuiDocViewer(QTextBrowser): self.theHandle = tHandle self.theProject.setLastViewed(tHandle) self.docTitle.setTitleFromHandle(self.theHandle) + self.updateDocMargins() # Make sure the main GUI knows we changed the content self.theParent.viewMeta.refreshReferences(tHandle) @@ -199,23 +200,11 @@ class GuiDocViewer(QTextBrowser): return False return True - def updateDocTitle(self, tHandle): - """Called when an item label is changed to check if the document - title bar needs updating, + def updateDocMargins(self): + """Automatically adjust the margins so the text is centred if + Config.textFixedW is enabled or we're in Zen mode. Otherwise, + just ensure the margins are set correctly. """ - if tHandle == self.theHandle: - self.docTitle.setTitleFromHandle(self.theHandle) - return - - ## - # Events - ## - - def resizeEvent(self, theEvent): - """Make sure the document title is the same width as the window. - """ - QTextBrowser.resizeEvent(self, theEvent) - tB = self.lineWidth() tW = self.width() - 2*tB tH = self.docTitle.height() @@ -235,6 +224,26 @@ class GuiDocViewer(QTextBrowser): return + def updateDocTitle(self, tHandle): + """Called when an item label is changed to check if the document + title bar needs updating, + """ + if tHandle == self.theHandle: + self.docTitle.setTitleFromHandle(self.theHandle) + self.updateDocMargins() + return + + ## + # Events + ## + + def resizeEvent(self, theEvent): + """Make sure the document title is the same width as the window. + """ + QTextBrowser.resizeEvent(self, theEvent) + self.updateDocMargins() + return + ## # Internal Functions ##