Convert the doc title bar to a widget with a layout

This commit is contained in:
Veronica K. B. Olsen
2020-06-07 23:37:59 +02:00
parent df0a80ed96
commit 8abfb5f983
+33 -22
View File
@@ -33,7 +33,7 @@ import nw
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QColor from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
qApp, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, qApp, QWidget, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton,
QHBoxLayout QHBoxLayout
) )
@@ -41,10 +41,10 @@ from nw.constants import nwDocAction, nwUnicode
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class GuiSearchBar(QFrame): class GuiSearchBar(QWidget):
def __init__(self, theParent): def __init__(self, theParent):
QFrame.__init__(self, theParent) QWidget.__init__(self, theParent)
logger.debug("Initialising GuiSearchBar ...") logger.debug("Initialising GuiSearchBar ...")
@@ -222,10 +222,10 @@ class GuiNoticeBar(QFrame):
# END Class GuiNoticeBar # END Class GuiNoticeBar
class GuiDocTitleBar(QLabel): class GuiDocTitleBar(QWidget):
def __init__(self, theParent, theProject): def __init__(self, theParent, theProject):
QLabel.__init__(self, theParent) QWidget.__init__(self, theParent)
logger.debug("Initialising GuiDocTitleBar ...") logger.debug("Initialising GuiDocTitleBar ...")
@@ -235,24 +235,36 @@ class GuiDocTitleBar(QLabel):
self.theTheme = theParent.theTheme self.theTheme = theParent.theTheme
self.theHandle = None self.theHandle = None
self.setText("") # Make a QPalette that matches the Syntax Theme
self.setIndent(0) self.thePalette = QPalette()
self.setMargin(0) self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
# Main Widget Settings
self.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0)
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setAlignment(Qt.AlignCenter) self.setPalette(self.thePalette)
self.setWordWrap(True)
self.setFrameShape(QFrame.NoFrame)
self.setLineWidth(0)
lblPalette = self.palette() self.theTitle = QLabel()
lblPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) self.theTitle.setText("")
lblPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) self.theTitle.setIndent(0)
self.setPalette(lblPalette) self.theTitle.setMargin(0)
self.theTitle.setContentsMargins(10, 0, 0, 0)
self.theTitle.setAutoFillBackground(True)
self.theTitle.setAlignment(Qt.AlignCenter)
self.theTitle.setWordWrap(True)
self.theTitle.setFrameShape(QFrame.NoFrame)
self.theTitle.setLineWidth(0)
self.theTitle.setPalette(self.thePalette)
lblFont = self.font() lblFont = self.theTitle.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
self.setFont(lblFont) self.theTitle.setFont(lblFont)
# Assemble Layout
self.outerBox = QHBoxLayout()
self.outerBox.addWidget(self.theTitle)
self.setLayout(self.outerBox)
logger.debug("GuiDocTitleBar initialisation complete") logger.debug("GuiDocTitleBar initialisation complete")
@@ -266,7 +278,7 @@ class GuiDocTitleBar(QLabel):
"""Sets the document title from the handle, or alternatively, """Sets the document title from the handle, or alternatively,
set the whole document path. set the whole document path.
""" """
self.setText("") self.theTitle.setText("")
self.theHandle = tHandle self.theHandle = tHandle
if tHandle is None: if tHandle is None:
return False return False
@@ -279,13 +291,12 @@ class GuiDocTitleBar(QLabel):
if nwItem is not None: if nwItem is not None:
tTitle.append(nwItem.itemName) tTitle.append(nwItem.itemName)
sSep = " %s " % nwUnicode.U_RSAQUO sSep = " %s " % nwUnicode.U_RSAQUO
self.setText(sSep.join(tTitle)) self.theTitle.setText(sSep.join(tTitle))
else: else:
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
if nwItem is None: if nwItem is None:
return False return False
self.theTitle.setText(nwItem.itemName)
self.setText(nwItem.itemName)
return True return True