Add override settings for project tree icon colours

This commit is contained in:
Veronica Berglyd Olsen
2025-01-08 22:22:53 +01:00
parent a0fea3c025
commit a6fde426a7
5 changed files with 78 additions and 17 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ orange = 255, 184, 108
yellow = 241, 250, 140 yellow = 241, 250, 140
green = 80, 250, 123 green = 80, 250, 123
aqua = 139, 233, 253 aqua = 139, 233, 253
blue = 139, 233, 253 blue = 147, 207, 249
purple = 189, 147, 249 purple = 189, 147, 249
[Project] [Project]
+8 -3
View File
@@ -114,7 +114,6 @@ class Config:
self.guiLocale = self._qLocale.name() self.guiLocale = self._qLocale.name()
self.guiTheme = "default" # GUI theme self.guiTheme = "default" # GUI theme
self.guiSyntax = "default_light" # Syntax theme self.guiSyntax = "default_light" # Syntax theme
self.guiIcons = "material_rounded_normal" # Icons theme
self.guiFont = QFont() # Main GUI font self.guiFont = QFont() # Main GUI font
self.guiScale = 1.0 # Set automatically by Theme class self.guiScale = 1.0 # Set automatically by Theme class
self.hideVScroll = False # Hide vertical scroll bars on main widgets self.hideVScroll = False # Hide vertical scroll bars on main widgets
@@ -122,6 +121,10 @@ class Config:
self.lastNotes = "0x0" # The latest release notes that have been shown self.lastNotes = "0x0" # The latest release notes that have been shown
self.nativeFont = True # Use native font dialog self.nativeFont = True # Use native font dialog
# Icons
self.iconTheme = "material_rounded_normal" # Icons theme
self.iconColTree = "theme" # Project tree icon colours
# Size Settings # Size Settings
self._mainWinSize = [1200, 650] # Last size of the main GUI window self._mainWinSize = [1200, 650] # Last size of the main GUI window
self._welcomeSize = [800, 550] # Last size of the welcome window self._welcomeSize = [800, 550] # Last size of the welcome window
@@ -606,7 +609,8 @@ class Config:
self.setGuiFont(conf.rdStr(sec, "font", "")) self.setGuiFont(conf.rdStr(sec, "font", ""))
self.guiTheme = conf.rdStr(sec, "theme", self.guiTheme) self.guiTheme = conf.rdStr(sec, "theme", self.guiTheme)
self.guiSyntax = conf.rdStr(sec, "syntax", self.guiSyntax) self.guiSyntax = conf.rdStr(sec, "syntax", self.guiSyntax)
self.guiIcons = conf.rdStr(sec, "icons", self.guiIcons) self.iconTheme = conf.rdStr(sec, "icons", self.iconTheme)
self.iconColTree = conf.rdStr(sec, "iconcoltree", self.iconColTree)
self.guiLocale = conf.rdStr(sec, "localisation", self.guiLocale) self.guiLocale = conf.rdStr(sec, "localisation", self.guiLocale)
self.hideVScroll = conf.rdBool(sec, "hidevscroll", self.hideVScroll) self.hideVScroll = conf.rdBool(sec, "hidevscroll", self.hideVScroll)
self.hideHScroll = conf.rdBool(sec, "hidehscroll", self.hideHScroll) self.hideHScroll = conf.rdBool(sec, "hidehscroll", self.hideHScroll)
@@ -718,7 +722,8 @@ class Config:
"font": self.guiFont.toString(), "font": self.guiFont.toString(),
"theme": str(self.guiTheme), "theme": str(self.guiTheme),
"syntax": str(self.guiSyntax), "syntax": str(self.guiSyntax),
"icons": str(self.guiIcons), "icons": str(self.iconTheme),
"iconcoltree": str(self.iconColTree),
"localisation": str(self.guiLocale), "localisation": str(self.guiLocale),
"hidevscroll": str(self.hideVScroll), "hidevscroll": str(self.hideVScroll),
"hidehscroll": str(self.hideHScroll), "hidehscroll": str(self.hideHScroll),
+11
View File
@@ -426,6 +426,17 @@ class nwLabels:
"Letter": (215.9, 279.4), "Letter": (215.9, 279.4),
"Custom": (-1.0, -1.0), "Custom": (-1.0, -1.0),
} }
THEME_COLORS = {
"theme": QT_TRANSLATE_NOOP("Constant", "Theme Colours"),
"default": QT_TRANSLATE_NOOP("Constant", "No Colours"),
"red": QT_TRANSLATE_NOOP("Constant", "Red"),
"orange": QT_TRANSLATE_NOOP("Constant", "Orange"),
"yellow": QT_TRANSLATE_NOOP("Constant", "Yellow"),
"green": QT_TRANSLATE_NOOP("Constant", "Green"),
"aqua": QT_TRANSLATE_NOOP("Constant", "Aqua"),
"blue": QT_TRANSLATE_NOOP("Constant", "Blue"),
"purple": QT_TRANSLATE_NOOP("Constant", "Purple"),
}
class nwHeadFmt: class nwHeadFmt:
+26 -11
View File
@@ -35,7 +35,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import compact, describeFont, uniqueCompact from novelwriter.common import compact, describeFont, uniqueCompact
from novelwriter.constants import nwUnicode from novelwriter.constants import nwLabels, nwUnicode, trConst
from novelwriter.dialogs.quotes import GuiQuoteSelect from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
from novelwriter.extensions.modified import ( from novelwriter.extensions.modified import (
@@ -177,17 +177,29 @@ class GuiPreferences(NDialog):
) )
# Icon Theme # Icon Theme
self.guiIcons = NComboBox(self) self.iconTheme = NComboBox(self)
self.guiIcons.setMinimumWidth(minWidth) self.iconTheme.setMinimumWidth(minWidth)
for theme, name in SHARED.theme.iconCache.listThemes(): for theme, name in SHARED.theme.iconCache.listThemes():
self.guiIcons.addItem(name, theme) self.iconTheme.addItem(name, theme)
self.guiIcons.setCurrentData(CONFIG.guiIcons, "material_rounded_bold") self.iconTheme.setCurrentData(CONFIG.iconTheme, "material_rounded_bold")
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Icon theme"), self.guiIcons, self.tr("Icon theme"), self.iconTheme,
self.tr("User interface icon theme."), stretch=(3, 2) self.tr("User interface icon theme."), stretch=(3, 2)
) )
# Tree Icon Colours
self.iconColTree = NComboBox(self)
self.iconColTree.setMinimumWidth(minWidth)
for key, label in nwLabels.THEME_COLORS.items():
self.iconColTree.addItem(trConst(label), key)
self.iconColTree.setCurrentData(CONFIG.iconColTree, "theme")
self.mainForm.addRow(
self.tr("Project tree icon colours"), self.iconColTree,
self.tr("Override colours for project icons."), stretch=(3, 2)
)
# Application Font Family # Application Font Family
self.guiFont = QLineEdit(self) self.guiFont = QLineEdit(self)
self.guiFont.setReadOnly(True) self.guiFont.setReadOnly(True)
@@ -912,18 +924,21 @@ class GuiPreferences(NDialog):
refreshTree = False refreshTree = False
# Appearance # Appearance
guiLocale = self.guiLocale.currentData() guiLocale = self.guiLocale.currentData()
guiTheme = self.guiTheme.currentData() guiTheme = self.guiTheme.currentData()
guiIcons = self.guiIcons.currentData() iconTheme = self.iconTheme.currentData()
iconColTree = self.iconColTree.currentData()
updateTheme |= CONFIG.guiTheme != guiTheme updateTheme |= CONFIG.guiTheme != guiTheme
updateTheme |= CONFIG.guiIcons != guiIcons updateTheme |= CONFIG.iconTheme != iconTheme
updateTheme |= CONFIG.iconColTree != iconColTree
needsRestart |= CONFIG.guiLocale != guiLocale needsRestart |= CONFIG.guiLocale != guiLocale
needsRestart |= CONFIG.guiFont != self._guiFont needsRestart |= CONFIG.guiFont != self._guiFont
CONFIG.guiLocale = guiLocale CONFIG.guiLocale = guiLocale
CONFIG.guiTheme = guiTheme CONFIG.guiTheme = guiTheme
CONFIG.guiIcons = guiIcons CONFIG.iconTheme = iconTheme
CONFIG.iconColTree = iconColTree
CONFIG.hideVScroll = self.hideVScroll.isChecked() CONFIG.hideVScroll = self.hideVScroll.isChecked()
CONFIG.hideHScroll = self.hideHScroll.isChecked() CONFIG.hideHScroll = self.hideHScroll.isChecked()
CONFIG.nativeFont = self.nativeFont.isChecked() CONFIG.nativeFont = self.nativeFont.isChecked()
+32 -2
View File
@@ -318,7 +318,7 @@ class GuiTheme:
) )
# Load icons after theme is parsed # Load icons after theme is parsed
self.iconCache.loadTheme(CONFIG.guiIcons) self.iconCache.loadTheme(CONFIG.iconTheme)
# Apply styles # Apply styles
QApplication.setPalette(self._guiPalette) QApplication.setPalette(self._guiPalette)
@@ -542,8 +542,27 @@ class GuiIcons:
def clear(self) -> None: def clear(self) -> None:
"""Clear the icon cache.""" """Clear the icon cache."""
text = QApplication.palette().windowText().color()
default = text.name(QColor.NameFormat.HexRgb).encode("utf-8")
self._svgData = {} self._svgData = {}
self._svgColours = {} self._svgColours = {
"default": default,
"red": b"#ff0000",
"orange": b"#ff7f00",
"yellow": b"#ffff00",
"green": b"#00ff00",
"aqua": b"#00ffff",
"blue": b"#0000ff",
"purple": b"#ff00ff",
"root": b"#0000ff",
"folder": b"#ffff00",
"file": default,
"title": b"#00ff00",
"chapter": b"#ff0000",
"scene": b"#0000ff",
"note": b"#ffff00",
}
self._qIcons = {} self._qIcons = {}
self._headerDec = [] self._headerDec = []
self._headerDecNarrow = [] self._headerDecNarrow = []
@@ -583,6 +602,17 @@ class GuiIcons:
logException() logException()
return False return False
# Set colour overrides for project item icons
if (override := CONFIG.iconColTree) != "theme":
color = self._svgColours.get(override, b"#000000")
self._svgColours["root"] = color
self._svgColours["folder"] = color
self._svgColours["file"] = color
self._svgColours["title"] = color
self._svgColours["chapter"] = color
self._svgColours["scene"] = color
self._svgColours["note"] = color
return True return True
def setIconColor(self, key: str, color: QColor) -> None: def setIconColor(self, key: str, color: QColor) -> None: