From 869cdd2fb0ab5465406c98cd10817bda14ffbd25 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 18 Jun 2024 22:41:29 +0200 Subject: [PATCH] Extend colour label widget to accept two colour states --- novelwriter/dialogs/about.py | 2 +- novelwriter/dialogs/docmerge.py | 2 +- novelwriter/dialogs/docsplit.py | 2 +- novelwriter/dialogs/preferences.py | 4 ++-- novelwriter/dialogs/projectsettings.py | 10 ++++----- novelwriter/dialogs/wordlist.py | 2 +- novelwriter/extensions/configlayout.py | 28 ++++++++++++++++++++++---- novelwriter/gui/outline.py | 2 +- novelwriter/tools/manussettings.py | 4 ++-- novelwriter/tools/noveldetails.py | 16 +++++++-------- 10 files changed, 46 insertions(+), 26 deletions(-) diff --git a/novelwriter/dialogs/about.py b/novelwriter/dialogs/about.py index 628c4e4e..25e0d2ef 100644 --- a/novelwriter/dialogs/about.py +++ b/novelwriter/dialogs/about.py @@ -75,7 +75,7 @@ class GuiAbout(NDialog): # Credits self.lblCredits = NColourLabel( - self.tr("Credits"), scale=1.6, parent=self, bold=True + self.tr("Credits"), self, scale=1.6, bold=True ) self.txtCredits = QTextBrowser(self) diff --git a/novelwriter/dialogs/docmerge.py b/novelwriter/dialogs/docmerge.py index 32b52a8d..d745dadb 100644 --- a/novelwriter/dialogs/docmerge.py +++ b/novelwriter/dialogs/docmerge.py @@ -58,7 +58,7 @@ class GuiDocMerge(NDialog): self.headLabel.setFont(SHARED.theme.guiFontB) self.helpLabel = NColourLabel( self.tr("Drag and drop items to change the order, or uncheck to exclude."), - SHARED.theme.helpText, parent=self, wrap=True + self, color=SHARED.theme.helpText, wrap=True ) iPx = SHARED.theme.baseIconHeight diff --git a/novelwriter/dialogs/docsplit.py b/novelwriter/dialogs/docsplit.py index 5c4e586b..5dae422a 100644 --- a/novelwriter/dialogs/docsplit.py +++ b/novelwriter/dialogs/docsplit.py @@ -62,7 +62,7 @@ class GuiDocSplit(NDialog): self.headLabel.setFont(SHARED.theme.guiFontB) self.helpLabel = NColourLabel( self.tr("Select the maximum level to split into files."), - SHARED.theme.helpText, parent=self, wrap=True + self, color=SHARED.theme.helpText, wrap=True ) # Values diff --git a/novelwriter/dialogs/preferences.py b/novelwriter/dialogs/preferences.py index d08498b2..2904476e 100644 --- a/novelwriter/dialogs/preferences.py +++ b/novelwriter/dialogs/preferences.py @@ -66,8 +66,8 @@ class GuiPreferences(NDialog): # Title self.titleLabel = NColourLabel( - self.tr("Preferences"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) + self.tr("Preferences"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) ) # Search Box diff --git a/novelwriter/dialogs/projectsettings.py b/novelwriter/dialogs/projectsettings.py index c8d72d88..e718634f 100644 --- a/novelwriter/dialogs/projectsettings.py +++ b/novelwriter/dialogs/projectsettings.py @@ -76,8 +76,8 @@ class GuiProjectSettings(NDialog): # Title self.titleLabel = NColourLabel( - self.tr("Project Settings"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) + self.tr("Project Settings"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) ) # SideBar @@ -345,7 +345,7 @@ class _StatusPage(NFixedPage): # Title self.pageTitle = NColourLabel( - pageLabel, SHARED.theme.helpText, parent=self, + pageLabel, self, color=SHARED.theme.helpText, scale=NColourLabel.HEADER_SCALE ) @@ -637,8 +637,8 @@ class _ReplacePage(NFixedPage): # Title self.pageTitle = NColourLabel( - self.tr("Text Auto-Replace for Preview and Build"), - SHARED.theme.helpText, parent=self, scale=NColourLabel.HEADER_SCALE + self.tr("Text Auto-Replace for Preview and Build"), self, + color=SHARED.theme.helpText, scale=NColourLabel.HEADER_SCALE ) # List Box diff --git a/novelwriter/dialogs/wordlist.py b/novelwriter/dialogs/wordlist.py index 8f3f53f5..8009d157 100644 --- a/novelwriter/dialogs/wordlist.py +++ b/novelwriter/dialogs/wordlist.py @@ -69,7 +69,7 @@ class GuiWordList(NDialog): # Header self.headLabel = NColourLabel( - self.tr("Project Word List"), SHARED.theme.helpText, parent=self, + self.tr("Project Word List"), self, color=SHARED.theme.helpText, scale=NColourLabel.HEADER_SCALE ) diff --git a/novelwriter/extensions/configlayout.py b/novelwriter/extensions/configlayout.py index e9f8194d..ca9d582e 100644 --- a/novelwriter/extensions/configlayout.py +++ b/novelwriter/extensions/configlayout.py @@ -203,7 +203,7 @@ class NScrollableForm(QScrollArea): if helpText: qHelp = NColourLabel( - str(helpText), color=self._helpCol, parent=self, + str(helpText), self, color=self._helpCol, scale=self._fontScale, wrap=True, indent=self._indent ) labelBox = QVBoxLayout() @@ -252,11 +252,20 @@ class NColourLabel(QLabel): HELP_SCALE = DEFAULT_SCALE HEADER_SCALE = 1.25 - def __init__(self, text: str, color: QColor | None = None, parent: QWidget | None = None, - scale: float = HELP_SCALE, wrap: bool = False, indent: int = 0, - bold: bool = False) -> None: + _state = None + + def __init__( + self, text: str, parent: QWidget, *, + color: QColor | None = None, faded: QColor | None = None, + scale: float = HELP_SCALE, wrap: bool = False, indent: int = 0, + bold: bool = False + ) -> None: super().__init__(text, parent=parent) + default = self.palette().windowText().color() + self._color = color or default + self._faded = faded or default + font = self.font() font.setPointSizeF(scale*font.pointSizeF()) font.setWeight(QFont.Weight.Bold if bold else QFont.Weight.Normal) @@ -268,9 +277,20 @@ class NColourLabel(QLabel): self.setFont(font) self.setIndent(indent) self.setWordWrap(wrap) + self.setColorState(True) return + def setColorState(self, state: bool) -> None: + """Change the colour state.""" + if self._state is not state: + self._state = state + print("State:", state, type(self.parent()).__name__) + colour = self.palette() + colour.setColor(QPalette.ColorRole.WindowText, self._color if state else self._faded) + self.setPalette(colour) + return + class NWrappedWidgetBox(QHBoxLayout): """Extension: A Text-Wrapped Widget Box diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index aa3d756d..3a411f35 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -215,7 +215,7 @@ class GuiOutlineToolBar(QToolBar): # Novel Selector self.novelLabel = NColourLabel( - self.tr("Outline of"), parent=self, scale=NColourLabel.HEADER_SCALE, bold=True + self.tr("Outline of"), self, scale=NColourLabel.HEADER_SCALE, bold=True ) self.novelLabel.setContentsMargins(0, 0, CONFIG.pxInt(12), 0) diff --git a/novelwriter/tools/manussettings.py b/novelwriter/tools/manussettings.py index f060a7b0..8964dcf4 100644 --- a/novelwriter/tools/manussettings.py +++ b/novelwriter/tools/manussettings.py @@ -98,8 +98,8 @@ class GuiBuildSettings(NToolDialog): # Title self.titleLabel = NColourLabel( - self.tr("Manuscript Build Settings"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) + self.tr("Manuscript Build Settings"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) ) # Settings Name diff --git a/novelwriter/tools/noveldetails.py b/novelwriter/tools/noveldetails.py index cd7f5f38..a7cb80c4 100644 --- a/novelwriter/tools/noveldetails.py +++ b/novelwriter/tools/noveldetails.py @@ -68,8 +68,8 @@ class GuiNovelDetails(NNonBlockingDialog): # Title self.titleLabel = NColourLabel( - self.tr("Novel Details"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) + self.tr("Novel Details"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE, indent=CONFIG.pxInt(4) ) # Novel Selector @@ -199,8 +199,8 @@ class _OverviewPage(NScrollablePage): # Project Info self.projLabel = NColourLabel( - self.tr("Project"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE + self.tr("Project"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE ) self.projName = QLabel("", self) @@ -223,8 +223,8 @@ class _OverviewPage(NScrollablePage): # Novel Info self.novelLabel = NColourLabel( - self.tr("Selected Novel"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE + self.tr("Selected Novel"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE ) self.novelName = QLabel("", self) @@ -315,8 +315,8 @@ class _ContentsPage(NFixedPage): # Title self.contentLabel = NColourLabel( - self.tr("Table of Contents"), SHARED.theme.helpText, - parent=self, scale=NColourLabel.HEADER_SCALE + self.tr("Table of Contents"), self, color=SHARED.theme.helpText, + scale=NColourLabel.HEADER_SCALE ) # Contents Tree