diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index cc3ea2c3..c50b327d 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -390,9 +390,9 @@ class GuiDocEditor(QPlainTextEdit): self.setFont(font) # Reset sub-widget font to GUI font - self.docHeader.setFont(SHARED.theme.guiFont) - self.docFooter.setFont(SHARED.theme.guiFont) - self.docSearch.setFont(SHARED.theme.guiFont) + self.docHeader.updateFont() + self.docFooter.updateFont() + self.docSearch.updateFont() return @@ -2410,9 +2410,6 @@ class GuiDocEditSearch(QFrame): iSz = SHARED.theme.baseIconSize mPx = CONFIG.pxInt(6) - self.boxFont = SHARED.theme.guiFont - self.boxFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) - self.setContentsMargins(0, 0, 0, 0) self.setAutoFillBackground(True) self.setFrameStyle(QFrame.Shape.StyledPanel | QFrame.Shadow.Plain) @@ -2424,12 +2421,10 @@ class GuiDocEditSearch(QFrame): # ========== self.searchBox = QLineEdit(self) - self.searchBox.setFont(self.boxFont) self.searchBox.setPlaceholderText(self.tr("Search for")) self.searchBox.returnPressed.connect(self._doSearch) self.replaceBox = QLineEdit(self) - self.replaceBox.setFont(self.boxFont) self.replaceBox.setPlaceholderText(self.tr("Replace with")) self.replaceBox.returnPressed.connect(self._doReplace) @@ -2439,12 +2434,9 @@ class GuiDocEditSearch(QFrame): self.searchOpt.setContentsMargins(0, 0, 0, 0) self.searchLabel = QLabel(self.tr("Search"), self) - self.searchLabel.setFont(self.boxFont) self.searchLabel.setIndent(CONFIG.pxInt(6)) self.resultLabel = QLabel("?/?", self) - self.resultLabel.setFont(self.boxFont) - self.resultLabel.setMinimumWidth(SHARED.theme.getTextWidth("?/?", self.boxFont)) self.toggleCase = QAction(self.tr("Case Sensitive"), self) self.toggleCase.setCheckable(True) @@ -2529,6 +2521,7 @@ class GuiDocEditSearch(QFrame): self.replaceButton.setVisible(False) self.adjustSize() + self.updateFont() self.updateTheme() logger.debug("Ready: GuiDocEditSearch") @@ -2612,7 +2605,9 @@ class GuiDocEditSearch(QFrame): numCount = f"{lim:n}+" if (resCount or 0) > lim else f"{resCount:n}" sCurrRes = "?" if currRes is None else str(currRes) sResCount = "?" if resCount is None else numCount - minWidth = SHARED.theme.getTextWidth(f"{sResCount}//{sResCount}", self.boxFont) + minWidth = SHARED.theme.getTextWidth( + f"{sResCount}//{sResCount}", SHARED.theme.guiFontSmall + ) self.resultLabel.setText(f"{sCurrRes}/{sResCount}") self.resultLabel.setMinimumWidth(minWidth) self.adjustSize() @@ -2623,6 +2618,18 @@ class GuiDocEditSearch(QFrame): # Methods ## + def updateFont(self) -> None: + """Update the font settings.""" + self.setFont(SHARED.theme.guiFont) + self.searchBox.setFont(SHARED.theme.guiFontSmall) + self.replaceBox.setFont(SHARED.theme.guiFontSmall) + self.searchLabel.setFont(SHARED.theme.guiFontSmall) + self.resultLabel.setFont(SHARED.theme.guiFontSmall) + self.resultLabel.setMinimumWidth( + SHARED.theme.getTextWidth("?/?", SHARED.theme.guiFontSmall) + ) + return + def updateTheme(self) -> None: """Update theme elements.""" qPalette = QApplication.palette() @@ -2807,10 +2814,6 @@ class GuiDocEditHeader(QWidget): self.itemTitle.setAlignment(QtAlignCenterTop) self.itemTitle.setFixedHeight(iPx) - lblFont = self.itemTitle.font() - lblFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) - self.itemTitle.setFont(lblFont) - # Other Widgets self.outlineMenu = QMenu(self) @@ -2864,6 +2867,7 @@ class GuiDocEditHeader(QWidget): self.setContentsMargins(0, 0, 0, 0) self.setMinimumHeight(iPx + 2*mPx) + self.updateFont() self.updateTheme() logger.debug("Ready: GuiDocEditHeader") @@ -2902,6 +2906,12 @@ class GuiDocEditHeader(QWidget): logger.debug("Document outline updated in %.3f ms", 1000*(time() - tStart)) return + def updateFont(self) -> None: + """Update the font settings.""" + self.setFont(SHARED.theme.guiFont) + self.itemTitle.setFont(SHARED.theme.guiFontSmall) + return + def updateTheme(self) -> None: """Update theme elements.""" self.tbButton.setThemeIcon("menu") @@ -3015,9 +3025,6 @@ class GuiDocEditFooter(QWidget): bSp = CONFIG.pxInt(4) hSp = CONFIG.pxInt(6) - lblFont = self.font() - lblFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) - # Cached Translations self._trLineCount = self.tr("Line: {0} ({1})") self._trWordCount = self.tr("Words: {0} ({1})") @@ -3040,7 +3047,6 @@ class GuiDocEditFooter(QWidget): self.statusText.setAutoFillBackground(True) self.statusText.setFixedHeight(fPx) self.statusText.setAlignment(QtAlignLeftTop) - self.statusText.setFont(lblFont) # Lines self.linesIcon = QLabel("", self) @@ -3055,7 +3061,6 @@ class GuiDocEditFooter(QWidget): self.linesText.setAutoFillBackground(True) self.linesText.setFixedHeight(fPx) self.linesText.setAlignment(QtAlignLeftTop) - self.linesText.setFont(lblFont) # Words self.wordsIcon = QLabel("", self) @@ -3070,7 +3075,6 @@ class GuiDocEditFooter(QWidget): self.wordsText.setAutoFillBackground(True) self.wordsText.setFixedHeight(fPx) self.wordsText.setAlignment(QtAlignLeftTop) - self.wordsText.setFont(lblFont) # Assemble Layout self.outerBox = QHBoxLayout() @@ -3093,6 +3097,7 @@ class GuiDocEditFooter(QWidget): self.setMinimumHeight(fPx + 2*mPx) # Fix the Colours + self.updateFont() self.updateTheme() # Initialise Info @@ -3106,6 +3111,14 @@ class GuiDocEditFooter(QWidget): # Methods ## + def updateFont(self) -> None: + """Update the font settings.""" + self.setFont(SHARED.theme.guiFont) + self.statusText.setFont(SHARED.theme.guiFontSmall) + self.linesText.setFont(SHARED.theme.guiFontSmall) + self.wordsText.setFont(SHARED.theme.guiFontSmall) + return + def updateTheme(self) -> None: """Update theme elements.""" iPx = round(0.9*SHARED.theme.baseIconHeight) diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index d5e0fcdd..afaeb366 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -192,8 +192,8 @@ class GuiDocViewer(QTextBrowser): self.setFont(font) # Reset sub-widget font to GUI font - self.docHeader.setFont(SHARED.theme.guiFont) - self.docFooter.setFont(SHARED.theme.guiFont) + self.docHeader.updateFont() + self.docFooter.updateFont() return @@ -654,10 +654,6 @@ class GuiDocViewHeader(QWidget): self.itemTitle.setAlignment(QtAlignCenterTop) self.itemTitle.setFixedHeight(iPx) - lblFont = self.itemTitle.font() - lblFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) - self.itemTitle.setFont(lblFont) - # Other Widgets self.outlineMenu = QMenu(self) @@ -708,7 +704,7 @@ class GuiDocViewHeader(QWidget): self.outerBox.setContentsMargins(mPx, mPx, mPx, mPx) self.setMinimumHeight(iPx + 2*mPx) - # Fix the Colours + self.updateFont() self.updateTheme() logger.debug("Ready: GuiDocViewHeader") @@ -753,6 +749,12 @@ class GuiDocViewHeader(QWidget): self._docOutline = data return + def updateFont(self) -> None: + """Update the font settings.""" + self.setFont(SHARED.theme.guiFont) + self.itemTitle.setFont(SHARED.theme.guiFontSmall) + return + def updateTheme(self) -> None: """Update theme elements.""" self.outlineButton.setThemeIcon("list") @@ -894,11 +896,6 @@ class GuiDocViewFooter(QWidget): self.showSynopsis.toggled.connect(self._doToggleSynopsis) self.showSynopsis.setToolTip(self.tr("Show Synopsis Comments")) - lblFont = self.font() - lblFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) - self.showComments.setFont(lblFont) - self.showSynopsis.setFont(lblFont) - # Assemble Layout self.outerBox = QHBoxLayout() self.outerBox.addWidget(self.showHide, 0) @@ -914,7 +911,7 @@ class GuiDocViewFooter(QWidget): self.outerBox.setContentsMargins(mPx, mPx, mPx, mPx) self.setMinimumHeight(iPx + 2*mPx) - # Fix the Colours + self.updateFont() self.updateTheme() logger.debug("Ready: GuiDocViewFooter") @@ -925,6 +922,13 @@ class GuiDocViewFooter(QWidget): # Methods ## + def updateFont(self) -> None: + """Update the font settings.""" + self.setFont(SHARED.theme.guiFont) + self.showComments.setFont(SHARED.theme.guiFontSmall) + self.showSynopsis.setFont(SHARED.theme.guiFontSmall) + return + def updateTheme(self) -> None: """Update theme elements.""" # Icons diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index c13283f4..6af30b8d 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -30,9 +30,7 @@ from math import ceil from pathlib import Path from PyQt5.QtCore import QSize, Qt -from PyQt5.QtGui import ( - QPalette, QColor, QIcon, QFont, QFontMetrics, QFontDatabase, QPixmap -) +from PyQt5.QtGui import QColor, QFont, QFontDatabase, QFontMetrics, QIcon, QPalette, QPixmap from PyQt5.QtWidgets import QApplication from novelwriter import CONFIG @@ -154,6 +152,8 @@ class GuiTheme: self.guiFont = QApplication.font() self.guiFontB = QApplication.font() self.guiFontB.setBold(True) + self.guiFontSmall = QApplication.font() + self.guiFontSmall.setPointSizeF(0.9*self.guiFont.pointSizeF()) qMetric = QFontMetrics(self.guiFont) fHeight = qMetric.height() diff --git a/novelwriter/tools/manuscript.py b/novelwriter/tools/manuscript.py index 376d8a6a..12ca8212 100644 --- a/novelwriter/tools/manuscript.py +++ b/novelwriter/tools/manuscript.py @@ -761,7 +761,6 @@ class _PreviewWidget(QTextBrowser): self.setPalette(dPalette) self.setMinimumWidth(40*SHARED.theme.textNWidth) - self.setTextFont(CONFIG.textFont, CONFIG.textSize) self.setTabStopDistance(CONFIG.getTabWidth()) self.setOpenExternalLinks(False) @@ -802,6 +801,8 @@ class _PreviewWidget(QTextBrowser): self._updateDocMargins() self._updateBuildAge() + self.setTextFont(CONFIG.textFont, CONFIG.textSize) + # Age Timer self.ageTimer = QTimer(self) self.ageTimer.setInterval(10000) @@ -840,8 +841,8 @@ class _PreviewWidget(QTextBrowser): font.setFamily(family) font.setPointSize(size) self.setFont(font) - self.ageLabel.setFont(SHARED.theme.guiFont) self.buildProgress.setFont(SHARED.theme.guiFont) + self.ageLabel.setFont(SHARED.theme.guiFontSmall) return ##