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
+41 -17
View File
@@ -206,6 +206,7 @@ class GuiDocEditor(QTextEdit):
theFont.setPointSize(self.mainConf.textSize) theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont) self.setFont(theFont)
# Set the widget colours to match syntax theme
mainPalette = self.palette() mainPalette = self.palette()
mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
mainPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack)) mainPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack))
@@ -217,6 +218,9 @@ class GuiDocEditor(QTextEdit):
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.viewport().setPalette(docPalette) self.viewport().setPalette(docPalette)
self.docHeader.matchColours()
self.docFooter.matchColours()
# Set default text margins # Set default text margins
cM = self.mainConf.getTextMargin() cM = self.mainConf.getTextMargin()
self.qDocument.setDocumentMargin(0) self.qDocument.setDocumentMargin(0)
@@ -2058,18 +2062,12 @@ class GuiDocEditHeader(QWidget):
self.theTheme = docEditor.theTheme self.theTheme = docEditor.theTheme
self.theHandle = None 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) fPx = int(0.9*self.theTheme.fontPixelSize)
hSp = self.mainConf.pxInt(6) hSp = self.mainConf.pxInt(6)
self.buttonSize = fPx + hSp self.buttonSize = fPx + hSp
# Main Widget Settings # Main Widget Settings
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setPalette(self.thePalette)
# Title Label # Title Label
self.theTitle = QLabel() self.theTitle = QLabel()
@@ -2080,7 +2078,6 @@ class GuiDocEditHeader(QWidget):
self.theTitle.setAutoFillBackground(True) self.theTitle.setAutoFillBackground(True)
self.theTitle.setAlignment(Qt.AlignHCenter | Qt.AlignTop) self.theTitle.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
self.theTitle.setFixedHeight(fPx) self.theTitle.setFixedHeight(fPx)
self.theTitle.setPalette(self.thePalette)
lblFont = self.theTitle.font() lblFont = self.theTitle.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -2146,14 +2143,31 @@ class GuiDocEditHeader(QWidget):
self.outerBox.addWidget(self.closeButton, 0) self.outerBox.addWidget(self.closeButton, 0)
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
# Fix the Colours
self.matchColours()
logger.debug("GuiDocEditHeader initialisation complete") logger.debug("GuiDocEditHeader initialisation complete")
return 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): def setTitleFromHandle(self, tHandle):
"""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.
@@ -2267,11 +2281,6 @@ class GuiDocEditFooter(QWidget):
self.theHandle = None self.theHandle = None
self.theItem = None self.theItem = 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))
self.sPx = int(round(0.9*self.theTheme.baseIconSize)) self.sPx = int(round(0.9*self.theTheme.baseIconSize))
fPx = int(0.9*self.theTheme.fontPixelSize) fPx = int(0.9*self.theTheme.fontPixelSize)
bSp = self.mainConf.pxInt(4) bSp = self.mainConf.pxInt(4)
@@ -2283,7 +2292,6 @@ class GuiDocEditFooter(QWidget):
# Main Widget Settings # Main Widget Settings
self.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0)
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setPalette(self.thePalette)
# Status # Status
self.statusIcon = QLabel("") self.statusIcon = QLabel("")
@@ -2298,7 +2306,6 @@ class GuiDocEditFooter(QWidget):
self.statusText.setAutoFillBackground(True) self.statusText.setAutoFillBackground(True)
self.statusText.setFixedHeight(fPx) self.statusText.setFixedHeight(fPx)
self.statusText.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.statusText.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.statusText.setPalette(self.thePalette)
self.statusText.setFont(lblFont) self.statusText.setFont(lblFont)
# Lines # Lines
@@ -2315,7 +2322,6 @@ class GuiDocEditFooter(QWidget):
self.linesText.setAutoFillBackground(True) self.linesText.setAutoFillBackground(True)
self.linesText.setFixedHeight(fPx) self.linesText.setFixedHeight(fPx)
self.linesText.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.linesText.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.linesText.setPalette(self.thePalette)
self.linesText.setFont(lblFont) self.linesText.setFont(lblFont)
# Words # Words
@@ -2332,7 +2338,6 @@ class GuiDocEditFooter(QWidget):
self.wordsText.setAutoFillBackground(True) self.wordsText.setAutoFillBackground(True)
self.wordsText.setFixedHeight(fPx) self.wordsText.setFixedHeight(fPx)
self.wordsText.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.wordsText.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.wordsText.setPalette(self.thePalette)
self.wordsText.setFont(lblFont) self.wordsText.setFont(lblFont)
# Assemble Layout # Assemble Layout
@@ -2348,6 +2353,9 @@ class GuiDocEditFooter(QWidget):
self.outerBox.addWidget(self.wordsText) self.outerBox.addWidget(self.wordsText)
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
# Fix the Colours
self.matchColours()
logger.debug("GuiDocEditFooter initialisation complete") logger.debug("GuiDocEditFooter initialisation complete")
return return
@@ -2356,6 +2364,22 @@ class GuiDocEditFooter(QWidget):
# Methods # 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.statusText.setPalette(self.thePalette)
self.linesText.setPalette(self.thePalette)
self.wordsText.setPalette(self.thePalette)
return
def setHandle(self, tHandle): def setHandle(self, tHandle):
"""Set the handle that will populate the footer's data. """Set the handle that will populate the footer's data.
""" """
+49 -24
View File
@@ -65,7 +65,6 @@ class GuiDocViewer(QTextBrowser):
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setOpenExternalLinks(False) self.setOpenExternalLinks(False)
self.setFocusPolicy(Qt.StrongFocus) self.setFocusPolicy(Qt.StrongFocus)
self.initViewer()
# Document Header and Footer # Document Header and Footer
self.docHeader = GuiDocViewHeader(self) self.docHeader = GuiDocViewHeader(self)
@@ -73,11 +72,6 @@ class GuiDocViewer(QTextBrowser):
self.docHistory = GuiDocViewHistory(self) self.docHistory = GuiDocViewHistory(self)
self.stickyRef = False self.stickyRef = False
theOpt = QTextOption()
if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify)
self.qDocument.setDefaultTextOption(theOpt)
# Signals # Signals
self.anchorClicked.connect(self._linkClicked) self.anchorClicked.connect(self._linkClicked)
@@ -85,6 +79,8 @@ class GuiDocViewer(QTextBrowser):
self.setContextMenuPolicy(Qt.CustomContextMenu) self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self._openContextMenu) self.customContextMenuRequested.connect(self._openContextMenu)
self.initViewer()
logger.debug("GuiDocViewer initialisation complete") logger.debug("GuiDocViewer initialisation complete")
return return
@@ -112,6 +108,7 @@ class GuiDocViewer(QTextBrowser):
theFont.setPointSize(self.mainConf.textSize) theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont) self.setFont(theFont)
# Set the widget colours to match syntax theme
mainPalette = self.palette() mainPalette = self.palette()
mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack))
mainPalette.setColor(QPalette.Base, 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)) docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.viewport().setPalette(docPalette) self.viewport().setPalette(docPalette)
self.docHeader.matchColours()
self.docFooter.matchColours()
# Set default text margins
self.qDocument.setDocumentMargin(0) self.qDocument.setDocumentMargin(0)
theOpt = QTextOption() theOpt = QTextOption()
if self.mainConf.doJustify: if self.mainConf.doJustify:
@@ -705,17 +706,11 @@ class GuiDocViewHeader(QWidget):
self.theTheme = docViewer.theTheme self.theTheme = docViewer.theTheme
self.theHandle = None 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) fPx = int(0.9*self.theTheme.fontPixelSize)
hSp = self.mainConf.pxInt(6) hSp = self.mainConf.pxInt(6)
# Main Widget Settings # Main Widget Settings
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setPalette(self.thePalette)
# Title Label # Title Label
self.theTitle = QLabel() self.theTitle = QLabel()
@@ -726,7 +721,6 @@ class GuiDocViewHeader(QWidget):
self.theTitle.setAutoFillBackground(True) self.theTitle.setAutoFillBackground(True)
self.theTitle.setAlignment(Qt.AlignHCenter | Qt.AlignTop) self.theTitle.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
self.theTitle.setFixedHeight(fPx) self.theTitle.setFixedHeight(fPx)
self.theTitle.setPalette(self.thePalette)
lblFont = self.theTitle.font() lblFont = self.theTitle.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -792,14 +786,31 @@ class GuiDocViewHeader(QWidget):
self.outerBox.addWidget(self.closeButton, 0) self.outerBox.addWidget(self.closeButton, 0)
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
# Fix the Colours
self.matchColours()
logger.debug("GuiDocViewHeader initialisation complete") logger.debug("GuiDocViewHeader initialisation complete")
return 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): def setTitleFromHandle(self, tHandle):
"""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.
@@ -892,11 +903,6 @@ class GuiDocViewFooter(QWidget):
self.viewMeta = docViewer.theParent.viewMeta self.viewMeta = docViewer.theParent.viewMeta
self.theHandle = None 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) fPx = int(0.9*self.theTheme.fontPixelSize)
bSp = self.mainConf.pxInt(2) bSp = self.mainConf.pxInt(2)
hSp = self.mainConf.pxInt(8) hSp = self.mainConf.pxInt(8)
@@ -917,7 +923,6 @@ class GuiDocViewFooter(QWidget):
# Main Widget Settings # Main Widget Settings
self.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0)
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setPalette(self.thePalette)
buttonStyle = ( buttonStyle = (
"QToolButton {{border: none; background: transparent;}} " "QToolButton {{border: none; background: transparent;}} "
@@ -980,7 +985,6 @@ class GuiDocViewFooter(QWidget):
self.lblRefs.setAutoFillBackground(True) self.lblRefs.setAutoFillBackground(True)
self.lblRefs.setFixedHeight(fPx) self.lblRefs.setFixedHeight(fPx)
self.lblRefs.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.lblRefs.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblRefs.setPalette(self.thePalette)
self.lblSticky = QLabel("Sticky") self.lblSticky = QLabel("Sticky")
self.lblSticky.setBuddy(self.stickyRefs) self.lblSticky.setBuddy(self.stickyRefs)
@@ -990,7 +994,6 @@ class GuiDocViewFooter(QWidget):
self.lblSticky.setAutoFillBackground(True) self.lblSticky.setAutoFillBackground(True)
self.lblSticky.setFixedHeight(fPx) self.lblSticky.setFixedHeight(fPx)
self.lblSticky.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.lblSticky.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblSticky.setPalette(self.thePalette)
self.lblComments = QLabel("Comments") self.lblComments = QLabel("Comments")
self.lblComments.setBuddy(self.showComments) self.lblComments.setBuddy(self.showComments)
@@ -1000,7 +1003,6 @@ class GuiDocViewFooter(QWidget):
self.lblComments.setAutoFillBackground(True) self.lblComments.setAutoFillBackground(True)
self.lblComments.setFixedHeight(fPx) self.lblComments.setFixedHeight(fPx)
self.lblComments.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.lblComments.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblComments.setPalette(self.thePalette)
self.lblSynopsis = QLabel("Synopsis") self.lblSynopsis = QLabel("Synopsis")
self.lblSynopsis.setBuddy(self.showSynopsis) self.lblSynopsis.setBuddy(self.showSynopsis)
@@ -1010,7 +1012,6 @@ class GuiDocViewFooter(QWidget):
self.lblSynopsis.setAutoFillBackground(True) self.lblSynopsis.setAutoFillBackground(True)
self.lblSynopsis.setFixedHeight(fPx) self.lblSynopsis.setFixedHeight(fPx)
self.lblSynopsis.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.lblSynopsis.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.lblSynopsis.setPalette(self.thePalette)
lblFont = self.font() lblFont = self.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -1035,10 +1036,34 @@ class GuiDocViewFooter(QWidget):
self.outerBox.addWidget(self.lblSynopsis, 0) self.outerBox.addWidget(self.lblSynopsis, 0)
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
# Fix the Colours
self.matchColours()
logger.debug("GuiDocViewFooter initialisation complete") logger.debug("GuiDocViewFooter initialisation complete")
return 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 # Slots
## ##