Moved the document title element into the document instead of main GUI
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
##
|
||||
|
||||
@@ -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
|
||||
|
||||
##
|
||||
|
||||
+2
-28
@@ -43,7 +43,7 @@ from nw.gui import (
|
||||
GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor, GuiExport,
|
||||
GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar, GuiDocViewDetails,
|
||||
GuiConfigEditor, GuiProjectEditor, GuiItemEditor, GuiProjectOutline,
|
||||
GuiSessionLogView, GuiDocMerge, GuiDocSplit, GuiProjectLoad, GuiDocTitleBar
|
||||
GuiSessionLogView, GuiDocMerge, GuiDocSplit, GuiProjectLoad
|
||||
)
|
||||
from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup
|
||||
from nw.tools import countWords
|
||||
@@ -65,10 +65,6 @@ class GuiMain(QMainWindow):
|
||||
self.hasProject = False
|
||||
self.isZenMode = False
|
||||
|
||||
# Init early to avoid circular dependencies
|
||||
self.docEditor = None
|
||||
self.docViewer = None
|
||||
|
||||
# Some runtime info useful for debugging
|
||||
logger.info("OS: %s" % self.mainConf.osType)
|
||||
logger.info("Kernel: %s" % self.mainConf.kernelVer)
|
||||
@@ -94,8 +90,6 @@ class GuiMain(QMainWindow):
|
||||
# Main GUI Elements
|
||||
self.statusBar = GuiMainStatus(self)
|
||||
self.noticeBar = GuiNoticeBar(self)
|
||||
self.viewTitle = GuiDocTitleBar(self, self.theProject)
|
||||
self.editTitle = GuiDocTitleBar(self, self.theProject)
|
||||
self.docEditor = GuiDocEditor(self, self.theProject)
|
||||
self.docViewer = GuiDocViewer(self, self.theProject)
|
||||
self.viewMeta = GuiDocViewDetails(self, self.theProject)
|
||||
@@ -123,7 +117,6 @@ class GuiMain(QMainWindow):
|
||||
self.docEdit.setSpacing(0)
|
||||
self.docEdit.addWidget(self.searchBar)
|
||||
self.docEdit.addWidget(self.noticeBar)
|
||||
self.docEdit.addWidget(self.editTitle)
|
||||
self.docEdit.addWidget(self.docEditor)
|
||||
self.editPane.setLayout(self.docEdit)
|
||||
|
||||
@@ -131,10 +124,9 @@ class GuiMain(QMainWindow):
|
||||
self.docView = QVBoxLayout()
|
||||
self.docView.setContentsMargins(0,0,0,0)
|
||||
self.docView.setSpacing(0)
|
||||
self.docView.addWidget(self.viewTitle)
|
||||
self.docView.addWidget(self.docViewer)
|
||||
self.docView.addWidget(self.viewMeta)
|
||||
self.docView.setStretch(1, 1)
|
||||
self.docView.setStretch(0, 1)
|
||||
self.viewPane.setLayout(self.docView)
|
||||
|
||||
self.splitView = QSplitter(Qt.Horizontal)
|
||||
@@ -614,24 +606,6 @@ class GuiMain(QMainWindow):
|
||||
logger.debug("Document action requested, but no document has focus")
|
||||
return True
|
||||
|
||||
def updateEditTitle(self):
|
||||
"""Ensure the editor title is up to date with the editor text.
|
||||
This should only be called by loadText and clearEditor in the
|
||||
editor class.
|
||||
"""
|
||||
if self.docEditor is not None:
|
||||
self.editTitle.setTitleFromHandle(self.docEditor.theHandle)
|
||||
return
|
||||
|
||||
def updateViewTitle(self):
|
||||
"""Ensure the viewer title is up to date with the viewer text.
|
||||
This should only be called by loadText and clearViewer in the
|
||||
viewer class.
|
||||
"""
|
||||
if self.docViewer is not None:
|
||||
self.viewTitle.setTitleFromHandle(self.docViewer.theHandle)
|
||||
return
|
||||
|
||||
##
|
||||
# Tree Item Actions
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user