From cff464392ae5656eb9fd1d117c161ad781517b25 Mon Sep 17 00:00:00 2001
From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com>
Date: Wed, 15 Jun 2022 16:15:29 +0200
Subject: [PATCH] Use the indenta decorators of the novel tree to indicate type
---
.../assets/icons/typicons_dark/icons.conf | 5 +++
.../assets/icons/typicons_dark/nw_deco-h0.svg | 35 +++++++++++++++++++
.../assets/icons/typicons_dark/nw_deco-h1.svg | 35 +++++++++++++++++++
.../assets/icons/typicons_dark/nw_deco-h2.svg | 35 +++++++++++++++++++
.../assets/icons/typicons_dark/nw_deco-h3.svg | 35 +++++++++++++++++++
.../assets/icons/typicons_dark/nw_deco-h4.svg | 35 +++++++++++++++++++
.../assets/icons/typicons_light/icons.conf | 5 +++
.../icons/typicons_light/nw_deco-h0.svg | 35 +++++++++++++++++++
.../icons/typicons_light/nw_deco-h1.svg | 35 +++++++++++++++++++
.../icons/typicons_light/nw_deco-h2.svg | 35 +++++++++++++++++++
.../icons/typicons_light/nw_deco-h3.svg | 35 +++++++++++++++++++
.../icons/typicons_light/nw_deco-h4.svg | 35 +++++++++++++++++++
novelwriter/gui/noveltree.py | 24 ++++++-------
novelwriter/gui/theme.py | 22 +++++++-----
sample/nwProject.nwx | 16 ++++-----
tests/test_gui/test_gui_theme.py | 2 +-
16 files changed, 393 insertions(+), 31 deletions(-)
create mode 100644 novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg
create mode 100644 novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg
create mode 100644 novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg
create mode 100644 novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg
create mode 100644 novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg
create mode 100644 novelwriter/assets/icons/typicons_light/nw_deco-h0.svg
create mode 100644 novelwriter/assets/icons/typicons_light/nw_deco-h1.svg
create mode 100644 novelwriter/assets/icons/typicons_light/nw_deco-h2.svg
create mode 100644 novelwriter/assets/icons/typicons_light/nw_deco-h3.svg
create mode 100644 novelwriter/assets/icons/typicons_light/nw_deco-h4.svg
diff --git a/novelwriter/assets/icons/typicons_dark/icons.conf b/novelwriter/assets/icons/typicons_dark/icons.conf
index ae157e2c..d4106803 100644
--- a/novelwriter/assets/icons/typicons_dark/icons.conf
+++ b/novelwriter/assets/icons/typicons_dark/icons.conf
@@ -83,3 +83,8 @@ view_build = typ_export.svg
view_editor = mixed_edit.svg
view_novel = typ_book-grey.svg
view_outline = typ_puzzle-outline.svg
+
+deco_doc_h1 = nw_deco-h1.svg
+deco_doc_h2 = nw_deco-h2.svg
+deco_doc_h3 = nw_deco-h3.svg
+deco_doc_h4 = nw_deco-h4.svg
diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg
new file mode 100644
index 00000000..3c1618c9
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg
new file mode 100644
index 00000000..1c0dec9b
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg
new file mode 100644
index 00000000..0f86e5bb
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg
new file mode 100644
index 00000000..f05e46e6
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg
new file mode 100644
index 00000000..aa74e6f3
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_light/icons.conf b/novelwriter/assets/icons/typicons_light/icons.conf
index 4683bb19..8d267a47 100644
--- a/novelwriter/assets/icons/typicons_light/icons.conf
+++ b/novelwriter/assets/icons/typicons_light/icons.conf
@@ -83,3 +83,8 @@ view_build = typ_export.svg
view_editor = mixed_edit.svg
view_novel = typ_book-grey.svg
view_outline = typ_puzzle-outline.svg
+
+deco_doc_h1 = nw_deco-h1.svg
+deco_doc_h2 = nw_deco-h2.svg
+deco_doc_h3 = nw_deco-h3.svg
+deco_doc_h4 = nw_deco-h4.svg
diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h0.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h0.svg
new file mode 100644
index 00000000..3c1618c9
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_light/nw_deco-h0.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h1.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h1.svg
new file mode 100644
index 00000000..e6c8efdc
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_light/nw_deco-h1.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h2.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h2.svg
new file mode 100644
index 00000000..7caa4203
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_light/nw_deco-h2.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h3.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h3.svg
new file mode 100644
index 00000000..61feca1b
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_light/nw_deco-h3.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h4.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h4.svg
new file mode 100644
index 00000000..b76fd7da
--- /dev/null
+++ b/novelwriter/assets/icons/typicons_light/nw_deco-h4.svg
@@ -0,0 +1,35 @@
+
+
diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py
index 2332bc7c..8711dc8d 100644
--- a/novelwriter/gui/noveltree.py
+++ b/novelwriter/gui/noveltree.py
@@ -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}")
diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py
index 3a59e7e2..6c4ff50e 100644
--- a/novelwriter/gui/theme.py
+++ b/novelwriter/gui/theme.py
@@ -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)
diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx
index af509400..6ba4b5f1 100644
--- a/sample/nwProject.nwx
+++ b/sample/nwProject.nwx
@@ -1,13 +1,13 @@
-
+
Sample Project
Sample Project
Jane Smith
Jay Doh
- 1367
- 231
- 68784
+ 1371
+ 236
+ 69222
False
@@ -35,9 +35,9 @@
- New
+ New
Notes
- Started
+ Started
1st Draft
2nd Draft
3rd Draft
@@ -92,7 +92,7 @@
Chapter Two
-
-
+
We Found John!
-
@@ -101,7 +101,7 @@
-
- Title Page
+ Title Page
-
diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py
index 756b2a81..8c7b934a 100644
--- a/tests/test_gui/test_gui_theme.py
+++ b/tests/test_gui/test_gui_theme.py
@@ -127,7 +127,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir):
assert anImg.isNull()
# Add a non-existent file and request it
- iconCache.DECO_MAP["nonsense"] = "nofile.jpg"
+ iconCache.IMAGE_MAP["nonsense"] = "nofile.jpg"
anImg = iconCache.loadDecoration("nonsense", 20, 20)
assert isinstance(anImg, QPixmap)
assert anImg.isNull()