Add header decoration function to the icon class

This commit is contained in:
Veronica Berglyd Olsen
2022-10-14 10:19:31 +02:00
parent 234a527f25
commit 91e6b0671e
3 changed files with 28 additions and 24 deletions
+3 -8
View File
@@ -390,13 +390,6 @@ class GuiNovelTree(QTreeWidget):
fH2.setBold(True) fH2.setBold(True)
self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()] self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()]
self._pIndent = [
self.mainTheme.loadDecoration("deco_doc_h0", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h1", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h2", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h3", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h4", pxH=iPx),
]
self._pMore = self.mainTheme.loadDecoration("deco_doc_more", pxH=iPx) self._pMore = self.mainTheme.loadDecoration("deco_doc_more", pxH=iPx)
# Connect signals # Connect signals
@@ -619,8 +612,10 @@ class GuiNovelTree(QTreeWidget):
if iLevel == 0: if iLevel == 0:
continue continue
hDec = self.mainTheme.getHeaderDecoration(iLevel)
newItem = QTreeWidgetItem() newItem = QTreeWidgetItem()
newItem.setData(self.C_TITLE, Qt.DecorationRole, self._pIndent[iLevel]) newItem.setData(self.C_TITLE, Qt.DecorationRole, hDec)
newItem.setText(self.C_TITLE, novIdx.title) newItem.setText(self.C_TITLE, novIdx.title)
newItem.setData(self.C_TITLE, self.D_HANDLE, tHandle) newItem.setData(self.C_TITLE, self.D_HANDLE, tHandle)
newItem.setData(self.C_TITLE, self.D_TITLE, sTitle) newItem.setData(self.C_TITLE, self.D_TITLE, sTitle)
+2 -8
View File
@@ -391,13 +391,6 @@ class GuiOutlineTree(QTreeWidget):
fH2.setBold(True) fH2.setBold(True)
self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()] self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()]
self._pIndent = [
self.mainTheme.loadDecoration("deco_doc_h0", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h1", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h2", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h3", pxH=iPx),
self.mainTheme.loadDecoration("deco_doc_h4", pxH=iPx),
]
self._dIcon = { self._dIcon = {
"H0": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H0"), "H0": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H0"),
"H1": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H1"), "H1": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H1"),
@@ -698,8 +691,9 @@ class GuiOutlineTree(QTreeWidget):
trItem = QTreeWidgetItem() trItem = QTreeWidgetItem()
nwItem = self.theProject.tree[tHandle] nwItem = self.theProject.tree[tHandle]
hDec = self.mainTheme.getHeaderDecoration(iLevel)
trItem.setData(self._colIdx[nwOutline.TITLE], Qt.DecorationRole, self._pIndent[iLevel]) trItem.setData(self._colIdx[nwOutline.TITLE], Qt.DecorationRole, hDec)
trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title) trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title)
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle) trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle)
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle) trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle)
+23 -8
View File
@@ -38,7 +38,7 @@ from PyQt5.QtGui import (
from novelwriter.enum import nwItemLayout, nwItemType from novelwriter.enum import nwItemLayout, nwItemType
from novelwriter.error import logException from novelwriter.error import logException
from novelwriter.common import NWConfigParser, readTextFile from novelwriter.common import NWConfigParser, minmax, readTextFile
from novelwriter.constants import nwLabels from novelwriter.constants import nwLabels
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -134,6 +134,7 @@ class GuiTheme:
self.getPixmap = self.iconCache.getPixmap self.getPixmap = self.iconCache.getPixmap
self.getItemIcon = self.iconCache.getItemIcon self.getItemIcon = self.iconCache.getItemIcon
self.loadDecoration = self.iconCache.loadDecoration self.loadDecoration = self.iconCache.loadDecoration
self.getHeaderDecoration = self.iconCache.getHeaderDecoration
# Extract Other Info # Extract Other Info
self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX() self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX()
@@ -457,13 +458,12 @@ class GuiIcons:
ICON_KEYS = { ICON_KEYS = {
# Project and GUI icons # Project and GUI icons
"novelwriter", "cls_archive", "cls_character", "cls_custom", "cls_entity", "cls_none", "novelwriter", "cls_archive", "cls_character", "cls_custom", "cls_entity", "cls_none",
"cls_novel", "cls_object", "cls_plot", "cls_timeline", "cls_trash", "cls_world", "doc_h0", "cls_novel", "cls_object", "cls_plot", "cls_timeline", "cls_trash", "cls_world",
"doc_h1", "doc_h2", "doc_h3", "doc_h4", "proj_chapter", "proj_details", "proj_document", "proj_chapter", "proj_details", "proj_document", "proj_folder", "proj_note", "proj_nwx",
"proj_folder", "proj_note", "proj_nwx", "proj_section", "proj_scene", "proj_stats", "proj_section", "proj_scene", "proj_stats", "proj_title", "search_cancel", "search_case",
"proj_title", "search_cancel", "search_case", "search_loop", "search_preserve", "search_loop", "search_preserve", "search_project", "search_regex", "search_word",
"search_project", "search_regex", "search_word", "status_idle", "status_lang", "status_idle", "status_lang", "status_lines", "status_stats", "status_time", "view_build",
"status_lines", "status_stats", "status_time", "view_build", "view_editor", "view_novel", "view_editor", "view_novel", "view_outline",
"view_outline",
# General Button Icons # General Button Icons
"add", "backward", "check", "close", "cross", "down", "edit", "forward", "maximise", "add", "backward", "check", "close", "cross", "down", "edit", "forward", "maximise",
@@ -491,6 +491,7 @@ class GuiIcons:
self._qIcons = {} self._qIcons = {}
self._themeMap = {} self._themeMap = {}
self._themeList = [] self._themeList = []
self._headerDec = []
self._confName = "icons.conf" self._confName = "icons.conf"
# Icon Theme Path # Icon Theme Path
@@ -651,6 +652,20 @@ class GuiIcons:
return self.getIcon(iconName) return self.getIcon(iconName)
def getHeaderDecoration(self, hLevel):
"""Get the decoration for a specific header level.
"""
if not self._headerDec:
iPx = self.mainTheme.baseIconSize
self._headerDec = [
self.loadDecoration("deco_doc_h0", pxH=iPx),
self.loadDecoration("deco_doc_h1", pxH=iPx),
self.loadDecoration("deco_doc_h2", pxH=iPx),
self.loadDecoration("deco_doc_h3", pxH=iPx),
self.loadDecoration("deco_doc_h4", pxH=iPx),
]
return self._headerDec[minmax(hLevel, 0, 4)]
def listThemes(self): def listThemes(self):
"""Scan the icons themes folder and list all themes. """Scan the icons themes folder and list all themes.
""" """