Add a more obvious placeholder icon (#1780)

This commit is contained in:
Veronica Berglyd Olsen
2024-03-27 12:32:55 +01:00
parent 1771dd2130
commit 3e66968387
3 changed files with 17 additions and 10 deletions
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24" height="24" version="1.2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="m0 0v4l8 8-8 8v4h4l8-8 8 8h4v-4l-8-8 8-8v-4h-4l-8 8-8-8h-4z" fill="#f00" stroke-width=".70711"/>
</svg>

After

Width:  |  Height:  |  Size: 251 B

+7 -4
View File
@@ -544,6 +544,9 @@ class GuiIcons:
self._confName = "icons.conf" self._confName = "icons.conf"
self._iconPath = CONFIG.assetPath("icons") self._iconPath = CONFIG.assetPath("icons")
# None Icon
self._noIcon = QIcon(str(self._iconPath / "none.svg"))
# Icon Theme Meta # Icon Theme Meta
self.themeName = "" self.themeName = ""
self.themeDescription = "" self.themeDescription = ""
@@ -680,7 +683,7 @@ class GuiIcons:
icon.addPixmap(pOne, QIcon.Mode.Normal, QIcon.State.On) icon.addPixmap(pOne, QIcon.Mode.Normal, QIcon.State.On)
icon.addPixmap(pTwo, QIcon.Mode.Normal, QIcon.State.Off) icon.addPixmap(pTwo, QIcon.Mode.Normal, QIcon.State.Off)
return icon return icon
return QIcon() return self._noIcon
def getPixmap(self, name: str, size: tuple[int, int]) -> QPixmap: def getPixmap(self, name: str, size: tuple[int, int]) -> QPixmap:
"""Return an icon from the icon buffer as a QPixmap. If it """Return an icon from the icon buffer as a QPixmap. If it
@@ -712,7 +715,7 @@ class GuiIcons:
elif tLayout == nwItemLayout.NOTE: elif tLayout == nwItemLayout.NOTE:
iconName = "proj_note" iconName = "proj_note"
if iconName is None: if iconName is None:
return QIcon() return self._noIcon
return self.getIcon(iconName) return self.getIcon(iconName)
@@ -753,7 +756,7 @@ class GuiIcons:
""" """
if name not in self.ICON_KEYS: if name not in self.ICON_KEYS:
logger.error("Requested unknown icon name '%s'", name) logger.error("Requested unknown icon name '%s'", name)
return QIcon() return self._noIcon
# If we just want the app icons, return right away # If we just want the app icons, return right away
if name == "novelwriter": if name == "novelwriter":
@@ -769,7 +772,7 @@ class GuiIcons:
# If we didn't find one, give up and return an empty icon # If we didn't find one, give up and return an empty icon
logger.warning("Did not load an icon for '%s'", name) logger.warning("Did not load an icon for '%s'", name)
return QIcon() return self._noIcon
# END Class GuiIcons # END Class GuiIcons
+6 -6
View File
@@ -332,7 +332,7 @@ def testGuiTheme_LoadIcons(qtbot):
# Load an unknown icon # Load an unknown icon
qIcon = iconCache.getIcon("stuff") qIcon = iconCache.getIcon("stuff")
assert isinstance(qIcon, QIcon) assert isinstance(qIcon, QIcon)
assert qIcon.isNull() is True assert qIcon == iconCache._noIcon
# Load an icon, it is likely already cached # Load an icon, it is likely already cached
qIcon = iconCache.getIcon("add") qIcon = iconCache.getIcon("add")
@@ -349,17 +349,17 @@ def testGuiTheme_LoadIcons(qtbot):
# Load app icon # Load app icon
qIcon = iconCache.getIcon("novelwriter") qIcon = iconCache.getIcon("novelwriter")
assert isinstance(qIcon, QIcon) assert isinstance(qIcon, QIcon)
assert qIcon.isNull() is False assert qIcon != iconCache._noIcon
# Load mime icon # Load mime icon
qIcon = iconCache.getIcon("proj_nwx") qIcon = iconCache.getIcon("proj_nwx")
assert isinstance(qIcon, QIcon) assert isinstance(qIcon, QIcon)
assert qIcon.isNull() is False assert qIcon != iconCache._noIcon
# Toggle icon # Toggle icon
qIcon = iconCache.getToggleIcon("bullet", (24, 24)) qIcon = iconCache.getToggleIcon("bullet", (24, 24))
assert isinstance(qIcon, QIcon) assert isinstance(qIcon, QIcon)
assert qIcon.isNull() is False assert qIcon != iconCache._noIcon
pOn = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.On) pOn = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.On)
pOff = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.Off) pOff = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.Off)
assert pOn != pOff assert pOn != pOff
@@ -367,7 +367,7 @@ def testGuiTheme_LoadIcons(qtbot):
# Unknown toggle icon # Unknown toggle icon
qIcon = iconCache.getToggleIcon("stuff", (24, 24)) qIcon = iconCache.getToggleIcon("stuff", (24, 24))
assert isinstance(qIcon, QIcon) assert isinstance(qIcon, QIcon)
assert qIcon.isNull() is True assert qIcon == iconCache._noIcon
# Load Item Icons # Load Item Icons
# =============== # ===============
@@ -420,7 +420,7 @@ def testGuiTheme_LoadIcons(qtbot):
# No Type -> Null # No Type -> Null
assert iconCache.getItemIcon( assert iconCache.getItemIcon(
nwItemType.NO_TYPE, nwItemClass.NOVEL, nwItemLayout.DOCUMENT, hLevel="H0" nwItemType.NO_TYPE, nwItemClass.NOVEL, nwItemLayout.DOCUMENT, hLevel="H0"
).isNull() is True ) == iconCache._noIcon
# qtbot.stop() # qtbot.stop()