Add editor toolbar icons
This commit is contained in:
@@ -2107,18 +2107,39 @@ class GuiDocToolBar(QWidget):
|
||||
# General Buttons
|
||||
# ===============
|
||||
|
||||
self.tbSticky = QToolButton(self)
|
||||
self.tbSticky.setIconSize(iconSize)
|
||||
self.tbMode = QToolButton(self)
|
||||
self.tbMode.setIconSize(iconSize)
|
||||
self.tbMode.setCheckable(True)
|
||||
|
||||
self.tbEdit = QToolButton(self)
|
||||
self.tbEdit.setIconSize(iconSize)
|
||||
self.tbBold = QToolButton(self)
|
||||
self.tbBold.setIconSize(iconSize)
|
||||
|
||||
self.tbItalic = QToolButton(self)
|
||||
self.tbItalic.setIconSize(iconSize)
|
||||
|
||||
self.tbStrike = QToolButton(self)
|
||||
self.tbStrike.setIconSize(iconSize)
|
||||
|
||||
self.tbUnderline = QToolButton(self)
|
||||
self.tbUnderline.setIconSize(iconSize)
|
||||
|
||||
self.tbSuperscript = QToolButton(self)
|
||||
self.tbSuperscript.setIconSize(iconSize)
|
||||
|
||||
self.tbSubscript = QToolButton(self)
|
||||
self.tbSubscript.setIconSize(iconSize)
|
||||
|
||||
# Assemble
|
||||
# ========
|
||||
|
||||
self.outerBox = QVBoxLayout()
|
||||
self.outerBox.addWidget(self.tbSticky)
|
||||
self.outerBox.addWidget(self.tbEdit)
|
||||
self.outerBox.addWidget(self.tbMode)
|
||||
self.outerBox.addWidget(self.tbBold)
|
||||
self.outerBox.addWidget(self.tbItalic)
|
||||
self.outerBox.addWidget(self.tbStrike)
|
||||
self.outerBox.addWidget(self.tbUnderline)
|
||||
self.outerBox.addWidget(self.tbSuperscript)
|
||||
self.outerBox.addWidget(self.tbSubscript)
|
||||
self.outerBox.setContentsMargins(cM, cM, cM, cM)
|
||||
self.outerBox.setSpacing(cM)
|
||||
|
||||
@@ -2150,8 +2171,14 @@ class GuiDocToolBar(QWidget):
|
||||
# buttonStyleMenu = f"{buttonStyle} QToolButton::menu-indicator {{image: none;}}"
|
||||
# self.tbEdit.setStyleSheet(buttonStyle)
|
||||
|
||||
self.tbSticky.setIcon(SHARED.theme.getIcon("sticky-off"))
|
||||
self.tbEdit.setIcon(SHARED.theme.getIcon("edit"))
|
||||
tPx = int(0.8*SHARED.theme.fontPixelSize)
|
||||
self.tbMode.setIcon(SHARED.theme.getToggleIcon("fmt_mode", (tPx, tPx)))
|
||||
self.tbBold.setIcon(SHARED.theme.getIcon("fmt_bold"))
|
||||
self.tbItalic.setIcon(SHARED.theme.getIcon("fmt_italic"))
|
||||
self.tbStrike.setIcon(SHARED.theme.getIcon("fmt_strike"))
|
||||
self.tbUnderline.setIcon(SHARED.theme.getIcon("fmt_underline"))
|
||||
self.tbSuperscript.setIcon(SHARED.theme.getIcon("fmt_superscript"))
|
||||
self.tbSubscript.setIcon(SHARED.theme.getIcon("fmt_subscript"))
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QPoint, QSize, Qt, QUrl
|
||||
from PyQt5.QtGui import (
|
||||
QColor, QCursor, QFont, QIcon, QMouseEvent, QPalette, QResizeEvent,
|
||||
QTextCursor, QTextOption
|
||||
QColor, QCursor, QFont, QMouseEvent, QPalette, QResizeEvent, QTextCursor,
|
||||
QTextOption
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QAction, qApp, QFrame, QHBoxLayout, QLabel, QMenu, QScrollArea,
|
||||
@@ -1020,24 +1020,12 @@ class GuiDocViewFooter(QWidget):
|
||||
# Methods
|
||||
##
|
||||
|
||||
def updateTheme(self):
|
||||
"""Update theme elements.
|
||||
"""
|
||||
def updateTheme(self) -> None:
|
||||
"""Update theme elements."""
|
||||
# Icons
|
||||
|
||||
fPx = int(0.9*SHARED.theme.fontPixelSize)
|
||||
|
||||
stickyOn = SHARED.theme.getPixmap("sticky-on", (fPx, fPx))
|
||||
stickyOff = SHARED.theme.getPixmap("sticky-off", (fPx, fPx))
|
||||
stickyIcon = QIcon()
|
||||
stickyIcon.addPixmap(stickyOn, QIcon.Normal, QIcon.On)
|
||||
stickyIcon.addPixmap(stickyOff, QIcon.Normal, QIcon.Off)
|
||||
|
||||
bulletOn = SHARED.theme.getPixmap("bullet-on", (fPx, fPx))
|
||||
bulletOff = SHARED.theme.getPixmap("bullet-off", (fPx, fPx))
|
||||
bulletIcon = QIcon()
|
||||
bulletIcon.addPixmap(bulletOn, QIcon.Normal, QIcon.On)
|
||||
bulletIcon.addPixmap(bulletOff, QIcon.Normal, QIcon.Off)
|
||||
stickyIcon = SHARED.theme.getToggleIcon("sticky", (fPx, fPx))
|
||||
bulletIcon = SHARED.theme.getToggleIcon("bullet", (fPx, fPx))
|
||||
|
||||
self.showHide.setIcon(SHARED.theme.getIcon("reference"))
|
||||
self.stickyRefs.setIcon(stickyIcon)
|
||||
|
||||
+35
-12
@@ -130,6 +130,7 @@ class GuiTheme:
|
||||
self.getIcon = self.iconCache.getIcon
|
||||
self.getPixmap = self.iconCache.getPixmap
|
||||
self.getItemIcon = self.iconCache.getItemIcon
|
||||
self.getToggleIcon = self.iconCache.getToggleIcon
|
||||
self.loadDecoration = self.iconCache.loadDecoration
|
||||
self.getHeaderDecoration = self.iconCache.getHeaderDecoration
|
||||
|
||||
@@ -447,14 +448,22 @@ class GuiIcons:
|
||||
ICON_KEYS = {
|
||||
# Project and GUI Icons
|
||||
"novelwriter", "alert_error", "alert_info", "alert_question", "alert_warn",
|
||||
"build_excluded", "build_filtered", "build_included", "cls_archive", "cls_character",
|
||||
"cls_custom", "cls_entity", "cls_none", "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",
|
||||
"build_excluded", "build_filtered", "build_included", "proj_chapter", "proj_details",
|
||||
"proj_document", "proj_folder", "proj_note", "proj_nwx", "proj_section", "proj_scene",
|
||||
"proj_stats", "proj_title", "status_idle", "status_lang", "status_lines", "status_stats",
|
||||
"status_time", "view_build", "view_editor", "view_novel", "view_outline",
|
||||
|
||||
# Class Icons
|
||||
"cls_archive", "cls_character", "cls_custom", "cls_entity", "cls_none", "cls_novel",
|
||||
"cls_object", "cls_plot", "cls_timeline", "cls_trash", "cls_world",
|
||||
|
||||
# Search Icons
|
||||
"search_cancel", "search_case", "search_loop", "search_preserve", "search_project",
|
||||
"search_regex", "search_word",
|
||||
|
||||
# Format Icons
|
||||
"fmt_bold", "fmt_italic", "fmt_mode-md", "fmt_mode-sc", "fmt_strike", "fmt_subscript",
|
||||
"fmt_superscript", "fmt_underline",
|
||||
|
||||
# General Button Icons
|
||||
"add", "backward", "bookmark", "browse", "checked", "close", "cross", "down", "edit",
|
||||
@@ -469,6 +478,12 @@ class GuiIcons:
|
||||
"deco_doc_h0", "deco_doc_h1", "deco_doc_h2", "deco_doc_h3", "deco_doc_h4", "deco_doc_more",
|
||||
}
|
||||
|
||||
TOGGLE_ICON_KEYS = {
|
||||
"sticky": ("sticky-on", "sticky-off"),
|
||||
"bullet": ("bullet-on", "bullet-off"),
|
||||
"fmt_mode": ("fmt_mode-sc", "fmt_mode-md"),
|
||||
}
|
||||
|
||||
IMAGE_MAP = {
|
||||
"wiz-back": "wizard-back.jpg",
|
||||
}
|
||||
@@ -602,10 +617,7 @@ class GuiIcons:
|
||||
return theDeco
|
||||
|
||||
def getIcon(self, iconKey):
|
||||
"""Return an icon from the icon buffer. If it doesn't exist,
|
||||
return, load it, and if it still doesn't exist, return an empty
|
||||
icon.
|
||||
"""
|
||||
"""Return an icon from the icon buffer, or load it."""
|
||||
if iconKey in self._qIcons:
|
||||
return self._qIcons[iconKey]
|
||||
else:
|
||||
@@ -613,6 +625,17 @@ class GuiIcons:
|
||||
self._qIcons[iconKey] = qIcon
|
||||
return qIcon
|
||||
|
||||
def getToggleIcon(self, iconKey: str, iconSize: tuple[int, int]) -> QIcon:
|
||||
"""Return a toggle icon from the icon buffer. or load it."""
|
||||
if iconKey in self.TOGGLE_ICON_KEYS:
|
||||
pixOne = self.getPixmap(self.TOGGLE_ICON_KEYS[iconKey][0], iconSize)
|
||||
pixTwo = self.getPixmap(self.TOGGLE_ICON_KEYS[iconKey][1], iconSize)
|
||||
qIcon = QIcon()
|
||||
qIcon.addPixmap(pixOne, QIcon.Normal, QIcon.On)
|
||||
qIcon.addPixmap(pixTwo, QIcon.Normal, QIcon.Off)
|
||||
return qIcon
|
||||
return QIcon()
|
||||
|
||||
def getPixmap(self, iconKey, iconSize):
|
||||
"""Return an icon from the icon buffer as a QPixmap. If it
|
||||
doesn't exist, return an empty QPixmap.
|
||||
|
||||
Reference in New Issue
Block a user