Moved the document title element into the document instead of main GUI

This commit is contained in:
Veronica K. B. Olsen
2020-05-01 20:51:46 +02:00
parent cc1113ea6c
commit bf3ecfbef4
5 changed files with 63 additions and 40 deletions
+15 -3
View File
@@ -32,7 +32,7 @@ from time import time
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import (
qApp, QTextEdit, QAction, QMenu, QShortcut, QMessageBox
qApp, QTextEdit, QAction, QMenu, QShortcut, QMessageBox, QLabel
)
from PyQt5.QtGui import (
QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette,
@@ -41,6 +41,7 @@ from PyQt5.QtGui import (
from nw.project import NWDoc
from nw.gui.tools import GuiDocHighlighter, WordCounter
from nw.gui.elements.doctitlebar import GuiDocTitleBar
from nw.tools import NWSpellSimple
from nw.constants import nwUnicode, nwDocAction
@@ -82,6 +83,10 @@ class GuiDocEditor(QTextEdit):
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
self.qDocument.contentsChange.connect(self._docChange)
# Document Title
self.docTitle = GuiDocTitleBar(self, self.theProject)
self.docTitle.setGeometry(0,0,self.docTitle.width(),self.docTitle.height())
# Syntax
self.hLight = GuiDocHighlighter(self.qDocument, self.theParent)
@@ -150,7 +155,7 @@ class GuiDocEditor(QTextEdit):
self.setDocumentChanged(False)
self.theParent.noticeBar.hideNote()
self.theParent.updateEditTitle()
self.docTitle.setTitleFromHandle(self.theHandle)
return True
@@ -265,7 +270,7 @@ class GuiDocEditor(QTextEdit):
else:
self.theParent.noticeBar.showNote("This document is read only.")
self.theParent.updateEditTitle()
self.docTitle.setTitleFromHandle(self.theHandle)
self.hLight.spellCheck = spTemp
qApp.restoreOverrideCursor()
@@ -321,9 +326,16 @@ class GuiDocEditor(QTextEdit):
else:
tM = self.mainConf.textMargin
tB = self.lineWidth()
tW = self.width() - 2*tB
tH = self.docTitle.height()
self.docTitle.setGeometry(tB, tB, tW, tH)
docFormat = self.qDocument.rootFrame().frameFormat()
docFormat.setLeftMargin(tM)
docFormat.setRightMargin(tM)
if docFormat.topMargin() < tH:
docFormat.setTopMargin(tH + 2)
# Updating root frame triggers a QTextDocument->contentsChange
# signal, which we do not want as it re-runs the syntax
+15 -7
View File
@@ -30,7 +30,7 @@ import nw
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLabel, QFrame, QStyle
from nw.constants import nwUnicode
@@ -50,14 +50,22 @@ class GuiDocTitleBar(QLabel):
self.theHandle = None
self.setText("")
self.setContentsMargins(8,2,8,2)
self.setIndent(0)
self.setMargin(0)
self.setContentsMargins(0,0,0,0)
self.setAutoFillBackground(True)
self.setAlignment(Qt.AlignCenter)
self.setWordWrap(True)
docPalette = self.palette()
docPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.setPalette(docPalette)
self.setFrameShape(QFrame.NoFrame)
self.setLineWidth(0)
lblPalette = self.palette()
lblPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
lblPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.setPalette(lblPalette)
lblFont = self.font()
lblFont.setPointSizeF(0.9*self.theTheme.defFontSize)
self.setFont(lblFont)
logger.debug("DocTitleBar initialisation complete")
@@ -103,7 +111,7 @@ class GuiDocTitleBar(QLabel):
"""Capture a click on the title and ensure that the item is
selected in the project tree.
"""
self.theParent.treeView.setSelectedHandle(self.theHandle)
self.theParent.theParent.treeView.setSelectedHandle(self.theHandle)
return
# END Class GuiDocTitleBar
+27 -2
View File
@@ -34,6 +34,7 @@ from PyQt5.QtGui import QTextOption, QFont, QPalette, QColor, QTextCursor
from nw.convert import ToHtml
from nw.constants import nwAlert, nwItemType, nwDocAction
from nw.gui.elements.doctitlebar import GuiDocTitleBar
logger = logging.getLogger(__name__)
@@ -56,6 +57,10 @@ class GuiDocViewer(QTextBrowser):
self.setOpenExternalLinks(False)
self.initViewer()
# Document Title
self.docTitle = GuiDocTitleBar(self, self.theProject)
self.docTitle.setGeometry(0,0,self.docTitle.width(),self.docTitle.height())
theOpt = QTextOption()
if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify)
@@ -74,7 +79,7 @@ class GuiDocViewer(QTextBrowser):
self.clear()
self.setSearchPaths([""])
self.theHandle = None
self.theParent.updateViewTitle()
self.docTitle.setTitleFromHandle(self.theHandle)
return True
def initViewer(self):
@@ -137,10 +142,10 @@ class GuiDocViewer(QTextBrowser):
self.verticalScrollBar().setValue(sPos)
self.theHandle = tHandle
self.theProject.setLastViewed(tHandle)
self.docTitle.setTitleFromHandle(self.theHandle)
# Make sure the main GUI knows we changed the content
self.theParent.viewMeta.refreshReferences(tHandle)
self.theParent.updateViewTitle()
return True
@@ -184,6 +189,26 @@ class GuiDocViewer(QTextBrowser):
return False
return True
##
# 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()
self.docTitle.setGeometry(tB, tB, tW, tH)
docFormat = self.qDocument.rootFrame().frameFormat()
if docFormat.topMargin() < tH:
docFormat.setTopMargin(tH + 2)
return
##
# Internal Functions
##
+4
View File
@@ -110,6 +110,10 @@ class GuiTheme:
self.getPixmap = self.theIcons.getPixmap
self.loadDecoration = self.theIcons.loadDecoration
# Extract Other Info
self.defFont = qApp.font()
self.defFontSize = self.defFont.pointSizeF()
return
##