From 91e6b0671e637ac4f5aef701983942decfaf38e2 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Fri, 14 Oct 2022 10:19:31 +0200 Subject: [PATCH] Add header decoration function to the icon class --- novelwriter/gui/noveltree.py | 11 +++-------- novelwriter/gui/outline.py | 10 ++-------- novelwriter/gui/theme.py | 31 +++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index b68fb812..80e3b66e 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -390,13 +390,6 @@ class GuiNovelTree(QTreeWidget): fH2.setBold(True) 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) # Connect signals @@ -619,8 +612,10 @@ class GuiNovelTree(QTreeWidget): if iLevel == 0: continue + hDec = self.mainTheme.getHeaderDecoration(iLevel) + 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.setData(self.C_TITLE, self.D_HANDLE, tHandle) newItem.setData(self.C_TITLE, self.D_TITLE, sTitle) diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index ea76676f..d0837360 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -391,13 +391,6 @@ class GuiOutlineTree(QTreeWidget): fH2.setBold(True) 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 = { "H0": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H0"), "H1": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H1"), @@ -698,8 +691,9 @@ class GuiOutlineTree(QTreeWidget): trItem = QTreeWidgetItem() 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.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle) trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle) diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index f2d0b066..7227ed11 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -38,7 +38,7 @@ from PyQt5.QtGui import ( from novelwriter.enum import nwItemLayout, nwItemType from novelwriter.error import logException -from novelwriter.common import NWConfigParser, readTextFile +from novelwriter.common import NWConfigParser, minmax, readTextFile from novelwriter.constants import nwLabels logger = logging.getLogger(__name__) @@ -134,6 +134,7 @@ class GuiTheme: self.getPixmap = self.iconCache.getPixmap self.getItemIcon = self.iconCache.getItemIcon self.loadDecoration = self.iconCache.loadDecoration + self.getHeaderDecoration = self.iconCache.getHeaderDecoration # Extract Other Info self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX() @@ -457,13 +458,12 @@ class GuiIcons: ICON_KEYS = { # Project and GUI icons "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", - "doc_h1", "doc_h2", "doc_h3", "doc_h4", "proj_chapter", "proj_details", "proj_document", - "proj_folder", "proj_note", "proj_nwx", "proj_section", "proj_scene", "proj_stats", - "proj_title", "search_cancel", "search_case", "search_loop", "search_preserve", - "search_project", "search_regex", "search_word", "status_idle", "status_lang", - "status_lines", "status_stats", "status_time", "view_build", "view_editor", "view_novel", - "view_outline", + "cls_novel", "cls_object", "cls_plot", "cls_timeline", "cls_trash", "cls_world", + "proj_chapter", "proj_details", "proj_document", "proj_folder", "proj_note", "proj_nwx", + "proj_section", "proj_scene", "proj_stats", "proj_title", "search_cancel", "search_case", + "search_loop", "search_preserve", "search_project", "search_regex", "search_word", + "status_idle", "status_lang", "status_lines", "status_stats", "status_time", "view_build", + "view_editor", "view_novel", "view_outline", # General Button Icons "add", "backward", "check", "close", "cross", "down", "edit", "forward", "maximise", @@ -491,6 +491,7 @@ class GuiIcons: self._qIcons = {} self._themeMap = {} self._themeList = [] + self._headerDec = [] self._confName = "icons.conf" # Icon Theme Path @@ -651,6 +652,20 @@ class GuiIcons: 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): """Scan the icons themes folder and list all themes. """