Add icon colour settings to themes and enforce them on all GUI icons

This commit is contained in:
Veronica Berglyd Olsen
2025-10-26 14:02:18 +01:00
parent 2c1c46b98d
commit 6db67e909d
25 changed files with 216 additions and 187 deletions
+27 -27
View File
@@ -2489,17 +2489,17 @@ class GuiDocToolBar(QWidget):
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette)
self.tbBoldMD.setThemeIcon("fmt_bold", "orange")
self.tbItalicMD.setThemeIcon("fmt_italic", "orange")
self.tbStrikeMD.setThemeIcon("fmt_strike", "orange")
self.tbMarkMD.setThemeIcon("fmt_mark", "orange")
self.tbBold.setThemeIcon("fmt_bold")
self.tbItalic.setThemeIcon("fmt_italic")
self.tbStrike.setThemeIcon("fmt_strike")
self.tbUnderline.setThemeIcon("fmt_underline")
self.tbMark.setThemeIcon("fmt_mark")
self.tbSuperscript.setThemeIcon("fmt_superscript")
self.tbSubscript.setThemeIcon("fmt_subscript")
self.tbBoldMD.setThemeIcon("fmt_bold", "mdformat")
self.tbItalicMD.setThemeIcon("fmt_italic", "mdformat")
self.tbStrikeMD.setThemeIcon("fmt_strike", "mdformat")
self.tbMarkMD.setThemeIcon("fmt_mark", "mdformat")
self.tbBold.setThemeIcon("fmt_bold", "scformat")
self.tbItalic.setThemeIcon("fmt_italic", "scformat")
self.tbStrike.setThemeIcon("fmt_strike", "scformat")
self.tbUnderline.setThemeIcon("fmt_underline", "scformat")
self.tbMark.setThemeIcon("fmt_mark", "scformat")
self.tbSuperscript.setThemeIcon("fmt_superscript", "scformat")
self.tbSubscript.setThemeIcon("fmt_subscript", "scformat")
class GuiDocEditSearch(QFrame):
@@ -2727,16 +2727,16 @@ class GuiDocEditSearch(QFrame):
self.replaceBox.setPalette(palette)
# Set icons
self.toggleCase.setIcon(SHARED.theme.getIcon("search_case"))
self.toggleWord.setIcon(SHARED.theme.getIcon("search_word"))
self.toggleRegEx.setIcon(SHARED.theme.getIcon("search_regex"))
self.toggleLoop.setIcon(SHARED.theme.getIcon("search_loop"))
self.toggleProject.setIcon(SHARED.theme.getIcon("search_project"))
self.toggleMatchCap.setIcon(SHARED.theme.getIcon("search_preserve"))
self.cancelSearch.setIcon(SHARED.theme.getIcon("search_cancel"))
self.searchButton.setThemeIcon("search", "green")
self.replaceButton.setThemeIcon("search_replace", "green")
self.showReplace.setThemeIcon("unfold")
self.toggleCase.setIcon(SHARED.theme.getIcon("search_case", "tool"))
self.toggleWord.setIcon(SHARED.theme.getIcon("search_word", "tool"))
self.toggleRegEx.setIcon(SHARED.theme.getIcon("search_regex", "tool"))
self.toggleLoop.setIcon(SHARED.theme.getIcon("search_loop", "tool"))
self.toggleProject.setIcon(SHARED.theme.getIcon("search_project", "tool"))
self.toggleMatchCap.setIcon(SHARED.theme.getIcon("search_preserve", "tool"))
self.cancelSearch.setIcon(SHARED.theme.getIcon("search_cancel", "tool"))
self.searchButton.setThemeIcon("search", "action")
self.replaceButton.setThemeIcon("search_replace", "apply")
self.showReplace.setThemeIcon("unfold", "default")
# Set stylesheets
self.searchOpt.setStyleSheet("QToolBar {padding: 0;}")
@@ -2967,11 +2967,11 @@ class GuiDocEditHeader(QWidget):
"""Update theme elements."""
logger.debug("Theme Update: GuiDocEditHeader")
self.tbButton.setThemeIcon("fmt_toolbar", "blue")
self.outlineButton.setThemeIcon("list", "blue")
self.searchButton.setThemeIcon("search", "blue")
self.minmaxButton.setThemeIcon("maximise", "blue")
self.closeButton.setThemeIcon("close", "red")
self.tbButton.setThemeIcon("fmt_toolbar", "action")
self.outlineButton.setThemeIcon("list", "action")
self.searchButton.setThemeIcon("search", "action")
self.minmaxButton.setThemeIcon("maximise", "action")
self.closeButton.setThemeIcon("close", "reject")
buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON)
self.tbButton.setStyleSheet(buttonStyle)
@@ -3037,7 +3037,7 @@ class GuiDocEditHeader(QWidget):
@pyqtSlot(bool)
def _focusModeChanged(self, focusMode: bool) -> None:
"""Update minimise/maximise icon of the Focus Mode button."""
self.minmaxButton.setThemeIcon("minimise" if focusMode else "maximise", "blue")
self.minmaxButton.setThemeIcon("minimise" if focusMode else "maximise", "action")
##
# Events
+8 -8
View File
@@ -727,12 +727,12 @@ class GuiDocViewHeader(QWidget):
"""Update theme elements."""
logger.debug("Theme Update: GuiDocViewHeader")
self.outlineButton.setThemeIcon("list", "blue")
self.backButton.setThemeIcon("chevron_left", "blue")
self.forwardButton.setThemeIcon("chevron_right", "blue")
self.editButton.setThemeIcon("edit", "green")
self.refreshButton.setThemeIcon("refresh", "green")
self.closeButton.setThemeIcon("close", "red")
self.outlineButton.setThemeIcon("list", "action")
self.backButton.setThemeIcon("chevron_left", "action")
self.forwardButton.setThemeIcon("chevron_right", "action")
self.editButton.setThemeIcon("edit", "change")
self.refreshButton.setThemeIcon("refresh", "change")
self.closeButton.setThemeIcon("close", "reject")
buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON)
self.outlineButton.setStyleSheet(buttonStyle)
@@ -916,9 +916,9 @@ class GuiDocViewFooter(QWidget):
logger.debug("Theme Update: GuiDocViewFooter")
fPx = int(0.9*SHARED.theme.fontPixelSize)
bulletIcon = SHARED.theme.getToggleIcon("bullet", (fPx, fPx), "blue")
bulletIcon = SHARED.theme.getToggleIcon("bullet", (fPx, fPx), "action")
self.showHide.setThemeIcon("panel")
self.showHide.setThemeIcon("panel", "default")
self.showComments.setIcon(bulletIcon)
self.showSynopsis.setIcon(bulletIcon)
self.showNotes.setIcon(bulletIcon)
+7 -7
View File
@@ -108,7 +108,7 @@ class GuiDocViewerPanel(QWidget):
"""Update theme elements."""
logger.debug("Theme Update: GuiDocViewerPanel")
self.optsButton.setThemeIcon("more_vertical")
self.optsButton.setThemeIcon("more_vertical", "default")
self.optsButton.setStyleSheet(SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON))
self.mainTabs.setStyleSheet(SHARED.theme.getStyleSheet(STYLES_FLAT_TABS))
if updateTabs:
@@ -263,8 +263,8 @@ class _ViewPanelBackRefs(QTreeWidget):
header.setSectionsMovable(False)
# Cache Icons Locally
self._editIcon = SHARED.theme.getIcon("edit", "green")
self._viewIcon = SHARED.theme.getIcon("view", "blue")
self._editIcon = SHARED.theme.getIcon("edit", "change")
self._viewIcon = SHARED.theme.getIcon("view", "action")
# Signals
self.clicked.connect(self._treeItemClicked)
@@ -274,8 +274,8 @@ class _ViewPanelBackRefs(QTreeWidget):
"""Update theme elements."""
logger.debug("Theme Update: _ViewPanelBackRefs")
self._editIcon = SHARED.theme.getIcon("edit", "green")
self._viewIcon = SHARED.theme.getIcon("view", "blue")
self._editIcon = SHARED.theme.getIcon("edit", "change")
self._viewIcon = SHARED.theme.getIcon("view", "action")
for i in range(self.topLevelItemCount()):
if item := self.topLevelItem(i):
item.setIcon(self.C_EDIT, self._editIcon)
@@ -407,8 +407,8 @@ class _ViewPanelKeyWords(QTreeWidget):
logger.debug("Theme Update: _ViewPanelKeyWords")
self._classIcon = SHARED.theme.getIcon(nwLabels.CLASS_ICON[self._class], "root")
self._editIcon = SHARED.theme.getIcon("edit", "green")
self._viewIcon = SHARED.theme.getIcon("view", "blue")
self._editIcon = SHARED.theme.getIcon("edit", "change")
self._viewIcon = SHARED.theme.getIcon("view", "action")
def countEntries(self) -> int:
"""Return the number of items in the list."""
+3 -3
View File
@@ -247,9 +247,9 @@ class GuiNovelToolBar(QWidget):
"""Update theme elements."""
logger.debug("Theme Update: GuiNovelToolBar")
self.tbNovel.setThemeIcon("cls_novel", "red")
self.tbRefresh.setThemeIcon("refresh", "green")
self.tbMore.setThemeIcon("more_vertical")
self.tbNovel.setThemeIcon("cls_novel", "root")
self.tbRefresh.setThemeIcon("refresh", "change")
self.tbMore.setThemeIcon("more_vertical", "default")
buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON)
self.tbNovel.setStyleSheet(buttonStyle)
+3 -3
View File
@@ -264,9 +264,9 @@ class GuiOutlineToolBar(QToolBar):
self.setStyleSheet("QToolBar {border: 0px;}")
self.novelValue.refreshNovelList()
self.aRefresh.setIcon(SHARED.theme.getIcon("refresh", "green"))
self.aExport.setIcon(SHARED.theme.getIcon("export", "blue"))
self.tbColumns.setIcon(SHARED.theme.getIcon("more_vertical"))
self.aRefresh.setIcon(SHARED.theme.getIcon("refresh", "change"))
self.aExport.setIcon(SHARED.theme.getIcon("export", "action"))
self.tbColumns.setIcon(SHARED.theme.getIcon("more_vertical", "default"))
self.tbColumns.setStyleSheet("QToolButton::menu-indicator {image: none;}")
self.novelLabel.setTextColors(color=self.palette().windowText().color())
+7 -7
View File
@@ -356,11 +356,11 @@ class GuiProjectToolBar(QWidget):
self.tbAdd.setStyleSheet(buttonStyle)
self.tbMore.setStyleSheet(buttonStyle)
self.tbQuick.setThemeIcon("bookmarks", "blue")
self.tbMoveU.setThemeIcon("chevron_up", "blue")
self.tbMoveD.setThemeIcon("chevron_down", "blue")
self.tbAdd.setThemeIcon("add", "green")
self.tbMore.setThemeIcon("more_vertical")
self.tbQuick.setThemeIcon("bookmarks", "action")
self.tbMoveU.setThemeIcon("chevron_up", "action")
self.tbMoveD.setThemeIcon("chevron_down", "action")
self.tbAdd.setThemeIcon("add", "add")
self.tbMore.setThemeIcon("more_vertical", "default")
self.aAddScene.setIcon(SHARED.theme.getIcon("prj_scene", "scene"))
self.aAddChap.setIcon(SHARED.theme.getIcon("prj_chapter", "chapter"))
@@ -1183,10 +1183,10 @@ class _TreeContextMenu(QMenu):
if len(self._indices) > 1:
mSub = qtAddMenu(self, self.tr("Set Active to ..."))
aOne = qtAddAction(mSub, self._tree.trActive)
aOne.setIcon(SHARED.theme.getIcon("checked", "green"))
aOne.setIcon(SHARED.theme.getIcon("checked", "accept"))
aOne.triggered.connect(qtLambda(self._iterItemActive, True))
aTwo = qtAddAction(mSub, self._tree.trInactive)
aTwo.setIcon(SHARED.theme.getIcon("unchecked", "red"))
aTwo.setIcon(SHARED.theme.getIcon("unchecked", "reject"))
aTwo.triggered.connect(qtLambda(self._iterItemActive, False))
else:
action = qtAddAction(self, self.tr("Toggle Active"))
+5 -5
View File
@@ -107,7 +107,7 @@ class GuiProjectSearch(QWidget):
# Search Box
self.searchAction = QAction("", self)
self.searchAction.setIcon(SHARED.theme.getIcon("search", "blue"))
self.searchAction.setIcon(SHARED.theme.getIcon("search", "apply"))
self.searchAction.triggered.connect(self._processSearch)
self.searchText = QLineEdit(self)
@@ -170,10 +170,10 @@ class GuiProjectSearch(QWidget):
f"QLineEdit:focus {{border: 1px solid {colFocus};}} "
)
self.searchAction.setIcon(SHARED.theme.getIcon("search", "blue"))
self.toggleCase.setIcon(SHARED.theme.getIcon("search_case"))
self.toggleWord.setIcon(SHARED.theme.getIcon("search_word"))
self.toggleRegEx.setIcon(SHARED.theme.getIcon("search_regex"))
self.searchAction.setIcon(SHARED.theme.getIcon("search", "apply"))
self.toggleCase.setIcon(SHARED.theme.getIcon("search_case", "tool"))
self.toggleWord.setIcon(SHARED.theme.getIcon("search_word", "tool"))
self.toggleRegEx.setIcon(SHARED.theme.getIcon("search_regex", "tool"))
def processReturn(self) -> None:
"""Process a return keypress forwarded from the main GUI."""
+9 -9
View File
@@ -142,14 +142,14 @@ class GuiSideBar(QWidget):
self.tbTheme.setStyleSheet(buttonStyle)
self.tbSettings.setStyleSheet(buttonStyle)
self.tbProject.setThemeIcon("sb_project")
self.tbNovel.setThemeIcon("sb_novel")
self.tbSearch.setThemeIcon("sb_search")
self.tbOutline.setThemeIcon("sb_outline")
self.tbBuild.setThemeIcon("sb_build")
self.tbDetails.setThemeIcon("sb_details")
self.tbStats.setThemeIcon("sb_stats")
self.tbSettings.setThemeIcon("settings")
self.tbProject.setThemeIcon("sb_project", "default")
self.tbNovel.setThemeIcon("sb_novel", "default")
self.tbSearch.setThemeIcon("sb_search", "default")
self.tbOutline.setThemeIcon("sb_outline", "default")
self.tbBuild.setThemeIcon("sb_build", "default")
self.tbDetails.setThemeIcon("sb_details", "default")
self.tbStats.setThemeIcon("sb_stats", "default")
self.tbSettings.setThemeIcon("settings", "default")
self._setThemeModeIcon()
@@ -176,7 +176,7 @@ class GuiSideBar(QWidget):
def _setThemeModeIcon(self) -> None:
"""Set the theme button icon."""
self.tbTheme.setThemeIcon(nwLabels.THEME_MODE_ICON[CONFIG.themeMode])
self.tbTheme.setThemeIcon(nwLabels.THEME_MODE_ICON[CONFIG.themeMode], "default")
self.tbTheme.setToolTip(trConst(nwLabels.THEME_MODE_LABEL[CONFIG.themeMode]))
+42 -20
View File
@@ -57,23 +57,23 @@ STYLES_MIN_TOOLBUTTON = "minimalToolButton"
STYLES_BIG_TOOLBUTTON = "bigToolButton"
STANDARD_BUTTONS = {
nwStandardButton.OK: (QT_TRANSLATE_NOOP("Button", "OK"), "btn_ok", "blue"),
nwStandardButton.CANCEL: (QT_TRANSLATE_NOOP("Button", "Cancel"), "btn_cancel", "red"),
nwStandardButton.YES: (QT_TRANSLATE_NOOP("Button", "&Yes"), "btn_yes", "green"),
nwStandardButton.NO: (QT_TRANSLATE_NOOP("Button", "&No"), "btn_no", "red"),
nwStandardButton.OPEN: (QT_TRANSLATE_NOOP("Button", "Open"), "btn_open", "blue"),
nwStandardButton.CLOSE: (QT_TRANSLATE_NOOP("Button", "Close"), "btn_close", "faded"),
nwStandardButton.SAVE: (QT_TRANSLATE_NOOP("Button", "Save"), "btn_save", "blue"),
nwStandardButton.BROWSE: (QT_TRANSLATE_NOOP("Button", "Browse"), "btn_browse", "yellow"),
nwStandardButton.LIST: (QT_TRANSLATE_NOOP("Button", "List"), "btn_list", "blue"),
nwStandardButton.NEW: (QT_TRANSLATE_NOOP("Button", "New"), "btn_new", "green"),
nwStandardButton.CREATE: (QT_TRANSLATE_NOOP("Button", "Create"), "btn_create", "yellow"),
nwStandardButton.RESET: (QT_TRANSLATE_NOOP("Button", "Reset"), "btn_reset", "green"),
nwStandardButton.INSERT: (QT_TRANSLATE_NOOP("Button", "Insert"), "btn_insert", "blue"),
nwStandardButton.APPLY: (QT_TRANSLATE_NOOP("Button", "Apply"), "btn_apply", "blue"),
nwStandardButton.BUILD: (QT_TRANSLATE_NOOP("Button", "Build"), "btn_build", "blue"),
nwStandardButton.PRINT: (QT_TRANSLATE_NOOP("Button", "Print"), "btn_print", "blue"),
nwStandardButton.PREVIEW: (QT_TRANSLATE_NOOP("Button", "Preview"), "btn_preview", "blue"),
nwStandardButton.OK: (QT_TRANSLATE_NOOP("Button", "OK"), "btn_ok", "action"),
nwStandardButton.CANCEL: (QT_TRANSLATE_NOOP("Button", "Cancel"), "btn_cancel", "reject"),
nwStandardButton.YES: (QT_TRANSLATE_NOOP("Button", "&Yes"), "btn_yes", "accept"),
nwStandardButton.NO: (QT_TRANSLATE_NOOP("Button", "&No"), "btn_no", "reject"),
nwStandardButton.OPEN: (QT_TRANSLATE_NOOP("Button", "Open"), "btn_open", "action"),
nwStandardButton.CLOSE: (QT_TRANSLATE_NOOP("Button", "Close"), "btn_close", "destroy"),
nwStandardButton.SAVE: (QT_TRANSLATE_NOOP("Button", "Save"), "btn_save", "action"),
nwStandardButton.BROWSE: (QT_TRANSLATE_NOOP("Button", "Browse"), "btn_browse", "systemio"),
nwStandardButton.LIST: (QT_TRANSLATE_NOOP("Button", "List"), "btn_list", "action"),
nwStandardButton.NEW: (QT_TRANSLATE_NOOP("Button", "New"), "btn_new", "apply"),
nwStandardButton.CREATE: (QT_TRANSLATE_NOOP("Button", "Create"), "btn_create", "create"),
nwStandardButton.RESET: (QT_TRANSLATE_NOOP("Button", "Reset"), "btn_reset", "reset"),
nwStandardButton.INSERT: (QT_TRANSLATE_NOOP("Button", "Insert"), "btn_insert", "action"),
nwStandardButton.APPLY: (QT_TRANSLATE_NOOP("Button", "Apply"), "btn_apply", "apply"),
nwStandardButton.BUILD: (QT_TRANSLATE_NOOP("Button", "Build"), "btn_build", "action"),
nwStandardButton.PRINT: (QT_TRANSLATE_NOOP("Button", "Print"), "btn_print", "action"),
nwStandardButton.PREVIEW: (QT_TRANSLATE_NOOP("Button", "Preview"), "btn_preview", "action"),
}
@@ -357,6 +357,28 @@ class GuiTheme:
self._setBaseColor("inactive", self._readColor(parser, sec, "inactive"))
self._setBaseColor("disabled", self._readColor(parser, sec, "disabled"))
# Icon
sec = "Icon"
if parser.has_section(sec):
self._setBaseColor("tool", self._readColor(parser, sec, "tool"))
self._setBaseColor("accept", self._readColor(parser, sec, "accept"))
self._setBaseColor("reject", self._readColor(parser, sec, "reject"))
self._setBaseColor("action", self._readColor(parser, sec, "action"))
self._setBaseColor("altaction", self._readColor(parser, sec, "altaction"))
self._setBaseColor("apply", self._readColor(parser, sec, "apply"))
self._setBaseColor("create", self._readColor(parser, sec, "create"))
self._setBaseColor("destroy", self._readColor(parser, sec, "destroy"))
self._setBaseColor("reset", self._readColor(parser, sec, "reset"))
self._setBaseColor("add", self._readColor(parser, sec, "add"))
self._setBaseColor("change", self._readColor(parser, sec, "change"))
self._setBaseColor("remove", self._readColor(parser, sec, "remove"))
self._setBaseColor("scformat", self._readColor(parser, sec, "scformat"))
self._setBaseColor("mdformat", self._readColor(parser, sec, "mdformat"))
self._setBaseColor("systemio", self._readColor(parser, sec, "systemio"))
self._setBaseColor("info", self._readColor(parser, sec, "info"))
self._setBaseColor("warning", self._readColor(parser, sec, "warning"))
self._setBaseColor("error", self._readColor(parser, sec, "error"))
# Palette
sec = "Palette"
if parser.has_section(sec):
@@ -767,7 +789,7 @@ class GuiIcons:
# Access Functions
##
def getIcon(self, name: str, color: str | None = None, w: int = 24, h: int = 24) -> QIcon:
def getIcon(self, name: str, color: str, w: int = 24, h: int = 24) -> QIcon:
"""Return an icon from the icon buffer, or load it."""
variant = f"{name}-{color}" if color else name
if (key := f"{variant}-{w}x{h}") in self._qIcons:
@@ -778,7 +800,7 @@ class GuiIcons:
logger.debug("Icon: %s", key)
return icon
def getToggleIcon(self, name: str, size: tuple[int, int], color: str | None = None) -> QIcon:
def getToggleIcon(self, name: str, size: tuple[int, int], color: str) -> QIcon:
"""Return a toggle icon from the icon buffer, or load it."""
if name in self.TOGGLE_ICON_KEYS:
pOne = self.getPixmap(self.TOGGLE_ICON_KEYS[name][0], size, color)
@@ -830,7 +852,7 @@ class GuiIcons:
doesn't exist, return an empty QPixmap.
"""
w, h = size
return self.getIcon(name, color, w, h).pixmap(w, h, QIcon.Mode.Normal)
return self.getIcon(name, color or "default", w, h).pixmap(w, h, QIcon.Mode.Normal)
def getStandardButton(self, button: nwStandardButton, parent: QWidget) -> NPushButton:
"""Return a standard button with icon and text."""