Also update colours on headers and footers

This commit is contained in:
Veronica K. B. Olsen
2020-10-25 11:14:04 +01:00
parent dbab60d064
commit 5edee1be0b
2 changed files with 90 additions and 41 deletions
+49 -24
View File
@@ -65,7 +65,6 @@ class GuiDocViewer(QTextBrowser):
self.setAutoFillBackground(True)
self.setOpenExternalLinks(False)
self.setFocusPolicy(Qt.StrongFocus)
self.initViewer()
# Document Header and Footer
self.docHeader = GuiDocViewHeader(self)
@@ -73,11 +72,6 @@ class GuiDocViewer(QTextBrowser):
self.docHistory = GuiDocViewHistory(self)
self.stickyRef = False
theOpt = QTextOption()
if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify)
self.qDocument.setDefaultTextOption(theOpt)
# Signals
self.anchorClicked.connect(self._linkClicked)
@@ -85,6 +79,8 @@ class GuiDocViewer(QTextBrowser):
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self._openContextMenu)
self.initViewer()
logger.debug("GuiDocViewer initialisation complete")
return
@@ -112,6 +108,7 @@ class GuiDocViewer(QTextBrowser):
theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont)
# Set the widget colours to match syntax theme
mainPalette = self.palette()
mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
mainPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack))
@@ -123,6 +120,10 @@ class GuiDocViewer(QTextBrowser):
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.viewport().setPalette(docPalette)
self.docHeader.matchColours()
self.docFooter.matchColours()
# Set default text margins
self.qDocument.setDocumentMargin(0)
theOpt = QTextOption()
if self.mainConf.doJustify:
@@ -705,17 +706,11 @@ class GuiDocViewHeader(QWidget):
self.theTheme = docViewer.theTheme
self.theHandle = None
# Make a QPalette that matches the Syntax Theme
self.thePalette = QPalette()
self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
fPx = int(0.9*self.theTheme.fontPixelSize)
hSp = self.mainConf.pxInt(6)
# Main Widget Settings
self.setAutoFillBackground(True)
self.setPalette(self.thePalette)
# Title Label
self.theTitle = QLabel()
@@ -726,7 +721,6 @@ class GuiDocViewHeader(QWidget):
self.theTitle.setAutoFillBackground(True)
self.theTitle.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
self.theTitle.setFixedHeight(fPx)
self.theTitle.setPalette(self.thePalette)
lblFont = self.theTitle.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -792,14 +786,31 @@ class GuiDocViewHeader(QWidget):
self.outerBox.addWidget(self.closeButton, 0)
self.setLayout(self.outerBox)
# Fix the Colours
self.matchColours()
logger.debug("GuiDocViewHeader initialisation complete")
return
##
# Setters
# Methods
##
def matchColours(self):
"""Update the colours of the widget to match those of the syntax
theme rather than the main GUI.
"""
self.thePalette = QPalette()
self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
self.thePalette.setColor(QPalette.WindowText, QColor(*self.theTheme.colText))
self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.setPalette(self.thePalette)
self.theTitle.setPalette(self.thePalette)
return
def setTitleFromHandle(self, tHandle):
"""Sets the document title from the handle, or alternatively,
set the whole document path.
@@ -892,11 +903,6 @@ class GuiDocViewFooter(QWidget):
self.viewMeta = docViewer.theParent.viewMeta
self.theHandle = None
# Make a QPalette that matches the Syntax Theme
self.thePalette = QPalette()
self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
fPx = int(0.9*self.theTheme.fontPixelSize)
bSp = self.mainConf.pxInt(2)
hSp = self.mainConf.pxInt(8)
@@ -917,7 +923,6 @@ class GuiDocViewFooter(QWidget):
# Main Widget Settings
self.setContentsMargins(0, 0, 0, 0)
self.setAutoFillBackground(True)
self.setPalette(self.thePalette)
buttonStyle = (
"QToolButton {{border: none; background: transparent;}} "
@@ -980,7 +985,6 @@ class GuiDocViewFooter(QWidget):
self.lblRefs.setAutoFillBackground(True)
self.lblRefs.setFixedHeight(fPx)
self.lblRefs.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblRefs.setPalette(self.thePalette)
self.lblSticky = QLabel("Sticky")
self.lblSticky.setBuddy(self.stickyRefs)
@@ -990,7 +994,6 @@ class GuiDocViewFooter(QWidget):
self.lblSticky.setAutoFillBackground(True)
self.lblSticky.setFixedHeight(fPx)
self.lblSticky.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblSticky.setPalette(self.thePalette)
self.lblComments = QLabel("Comments")
self.lblComments.setBuddy(self.showComments)
@@ -1000,7 +1003,6 @@ class GuiDocViewFooter(QWidget):
self.lblComments.setAutoFillBackground(True)
self.lblComments.setFixedHeight(fPx)
self.lblComments.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblComments.setPalette(self.thePalette)
self.lblSynopsis = QLabel("Synopsis")
self.lblSynopsis.setBuddy(self.showSynopsis)
@@ -1010,7 +1012,6 @@ class GuiDocViewFooter(QWidget):
self.lblSynopsis.setAutoFillBackground(True)
self.lblSynopsis.setFixedHeight(fPx)
self.lblSynopsis.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblSynopsis.setPalette(self.thePalette)
lblFont = self.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -1035,10 +1036,34 @@ class GuiDocViewFooter(QWidget):
self.outerBox.addWidget(self.lblSynopsis, 0)
self.setLayout(self.outerBox)
# Fix the Colours
self.matchColours()
logger.debug("GuiDocViewFooter initialisation complete")
return
##
# Methods
##
def matchColours(self):
"""Update the colours of the widget to match those of the syntax
theme rather than the main GUI.
"""
self.thePalette = QPalette()
self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
self.thePalette.setColor(QPalette.WindowText, QColor(*self.theTheme.colText))
self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.setPalette(self.thePalette)
self.lblRefs.setPalette(self.thePalette)
self.lblSticky.setPalette(self.thePalette)
self.lblComments.setPalette(self.thePalette)
self.lblSynopsis.setPalette(self.thePalette)
return
##
# Slots
##