Use the indenta decorators of the novel tree to indicate type

This commit is contained in:
Veronica Berglyd Olsen
2022-06-15 16:15:29 +02:00
parent 3a061eec3f
commit cff464392a
16 changed files with 393 additions and 31 deletions
+10 -14
View File
@@ -31,7 +31,7 @@ import novelwriter
from enum import Enum
from time import time
from PyQt5.QtGui import QPalette, QPixmap, QColor
from PyQt5.QtGui import QPalette
from PyQt5.QtCore import Qt, QSize, pyqtSlot, pyqtSignal
from PyQt5.QtWidgets import (
QAbstractItemView, QActionGroup, QFrame, QHBoxLayout, QHeaderView, QLabel,
@@ -349,11 +349,9 @@ class GuiNovelTree(QTreeWidget):
# =========
iPx = self.mainTheme.baseIconSize
nPx = self.mainTheme.textNWidth
cMg = self.mainConf.pxInt(6)
nMg = self.mainConf.pxInt(6)
# self.setIconSize(QSize(iPx, iPx))
self.setIconSize(QSize(iPx, iPx))
self.setFrameStyle(QFrame.NoFrame)
self.setHeaderHidden(True)
self.setIndentation(0)
@@ -380,15 +378,13 @@ class GuiNovelTree(QTreeWidget):
fH2.setBold(True)
self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()]
self._hIndent = ["", "", "", "\u203a\u00a0", "\u00bb\u00a0"]
self._pIndent = [QPixmap(), QPixmap()]
hPix = QPixmap(QSize(iPx, iPx))
hPix.fill(QColor(0, 0, 0, 0))
for m in range(1, 4):
self._pIndent.append(hPix.scaled(
max(nPx*m - nMg, nMg), 2, Qt.IgnoreAspectRatio, Qt.FastTransformation
))
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),
]
# Connect signals
self.itemDoubleClicked.connect(self._treeDoubleClick)
@@ -571,7 +567,7 @@ class GuiNovelTree(QTreeWidget):
theData = (tHandle, sTitle[1:].lstrip("0"), tKey)
newItem.setData(self.C_TITLE, Qt.DecorationRole, self._pIndent[iLevel])
newItem.setText(self.C_TITLE, self._hIndent[iLevel] + novIdx.title)
newItem.setText(self.C_TITLE, novIdx.title)
newItem.setData(self.C_TITLE, Qt.UserRole, theData)
newItem.setFont(self.C_TITLE, self._hFonts[iLevel])
newItem.setText(self.C_WORDS, f"{novIdx.wordCount:n}")
+14 -8
View File
@@ -472,9 +472,12 @@ class GuiIcons:
# Switches
"sticky-on", "sticky-off",
"bullet-on", "bullet-off",
# Decorations
"deco_doc_h0", "deco_doc_h1", "deco_doc_h2", "deco_doc_h3", "deco_doc_h4",
}
DECO_MAP = {
IMAGE_MAP = {
"wiz-back": "wizard-back.jpg",
}
@@ -573,19 +576,22 @@ class GuiIcons:
# Access Functions
##
def loadDecoration(self, decoKey, pxW, pxH):
def loadDecoration(self, decoKey, pxW=None, pxH=None):
"""Load graphical decoration element based on the decoration
map. This function always returns a QSwgWidget.
map or the icon map. This function always returns a QPixmap.
"""
if decoKey not in self.DECO_MAP:
if decoKey in self._themeMap:
imgPath = self._themeMap[decoKey]
elif decoKey in self.IMAGE_MAP:
imgPath = os.path.join(
self.mainConf.assetPath, "images", self.IMAGE_MAP[decoKey]
)
else:
logger.error("Decoration with name '%s' does not exist", decoKey)
return QPixmap()
imgPath = os.path.join(
self.mainConf.assetPath, "images", self.DECO_MAP[decoKey]
)
if not os.path.isfile(imgPath):
logger.error("Decoration file '%s' not in assets folder", self.DECO_MAP[decoKey])
logger.error("Asset '%s' not found", self.IMAGE_MAP[decoKey])
return QPixmap()
theDeco = QPixmap(imgPath)