From 1318427bb742b77eb2f2e3da3c5796f159f2c2ed Mon Sep 17 00:00:00 2001 From: chendapao Date: Tue, 21 Jun 2022 18:31:25 +0800 Subject: [PATCH] feature/add_custom_icons (#2145) * first boold * adj * base spec amendment * add monochrome optional fields to the theme * add monochrome optional fields to the theme * adj default value --- src/core/theme.cpp | 8 ++++++++ src/core/theme.h | 7 +++++++ src/core/thememgr.cpp | 14 +++++++++++++- src/core/thememgr.h | 2 ++ src/data/extra/themes/moonlight/palette.json | 3 ++- src/data/extra/themes/native/palette.json | 3 ++- src/data/extra/themes/pure/palette.json | 3 ++- src/data/extra/themes/solarized-dark/palette.json | 3 ++- src/data/extra/themes/solarized-light/palette.json | 3 ++- src/data/extra/themes/vscode-dark/palette.json | 3 ++- src/utils/iconutils.cpp | 9 +++++++-- src/widgets/dockwidgethelper.cpp | 1 - 12 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/core/theme.cpp b/src/core/theme.cpp index de00ec33..00439d47 100644 --- a/src/core/theme.cpp +++ b/src/core/theme.cpp @@ -86,6 +86,7 @@ Theme::Metadata Theme::readMetadata(const Palette &p_obj) data.m_revision = metaObj[QStringLiteral("revision")].toInt(); data.m_editorHighlightTheme = metaObj[QStringLiteral("editor-highlight-theme")].toString(); data.m_markdownEditorHighlightTheme = metaObj[QStringLiteral("markdown-editor-highlight-theme")].toString(); + data.m_IconMonochrome = metaObj[QStringLiteral("icon-monochrome")].toBool(); return data; } @@ -408,6 +409,8 @@ QString Theme::getFileName(File p_fileType) return QStringLiteral("markdown-editor-highlight.theme"); case File::Cover: return QStringLiteral("cover.png"); + case File::Icon: + return QStringLiteral("icons"); default: Q_ASSERT(false); return ""; @@ -438,6 +441,11 @@ QString Theme::getMarkdownEditorHighlightTheme() const return getEditorHighlightTheme(); } +bool Theme::getIconMonochrome() const +{ + return m_metadata.m_IconMonochrome; +} + QString Theme::name() const { return PathUtils::dirName(m_themeFolderPath); diff --git a/src/core/theme.h b/src/core/theme.h index 5fea8622..327c1b99 100644 --- a/src/core/theme.h +++ b/src/core/theme.h @@ -28,6 +28,7 @@ namespace vnotex EditorHighlightStyle, MarkdownEditorHighlightStyle, Cover, + Icon, Max }; @@ -44,6 +45,8 @@ namespace vnotex // Return the file path of the theme or just the theme name. QString getMarkdownEditorHighlightTheme() const; + bool getIconMonochrome() const; + QString name() const; static bool isValidThemeFolder(const QString &p_folder); @@ -69,6 +72,10 @@ namespace vnotex // If not specified, will use m_editorHighlightTheme. // Valid only when KSyntaxCodeBlockHighlighter is used. QString m_markdownEditorHighlightTheme; + + // Whether the icon of the current theme uses monochrome. + // Default is monochrome. + bool m_IconMonochrome = true; }; typedef QJsonObject Palette; diff --git a/src/core/thememgr.cpp b/src/core/thememgr.cpp index 82d9b555..f95606e0 100644 --- a/src/core/thememgr.cpp +++ b/src/core/thememgr.cpp @@ -10,6 +10,7 @@ #include #include "configmgr.h" #include "coreconfig.h" +#include "theme.h" using namespace vnotex; @@ -36,7 +37,13 @@ QString ThemeMgr::getIconFile(const QString &p_icon) const return p_icon; } - return ":/vnotex/data/core/icons/" + p_icon; + // If there is an ICONS folder in the theme configuration, use the custom ICONS from it. + QString customIcon = getFile(Theme::File::Icon) + "/" + p_icon; + if (QFile::exists(customIcon)) { + return customIcon; + } else { + return ":/vnotex/data/core/icons/" + p_icon; + } } void ThemeMgr::loadAvailableThemes() @@ -172,6 +179,11 @@ QString ThemeMgr::getMarkdownEditorHighlightTheme() const return m_currentTheme->getMarkdownEditorHighlightTheme(); } +bool ThemeMgr::getIconMonochrome() const +{ + return m_currentTheme->getIconMonochrome(); +} + void ThemeMgr::addSyntaxHighlightingSearchPaths(const QStringList &p_paths) { vte::VTextEditor::addSyntaxCustomSearchPaths(p_paths); diff --git a/src/core/thememgr.h b/src/core/thememgr.h index 2ad2d7ec..d739d181 100644 --- a/src/core/thememgr.h +++ b/src/core/thememgr.h @@ -49,6 +49,8 @@ namespace vnotex QString getMarkdownEditorHighlightTheme() const; + bool getIconMonochrome() const; + const QColor &getBaseBackground() const; void setBaseBackground(const QColor &p_bg); diff --git a/src/data/extra/themes/moonlight/palette.json b/src/data/extra/themes/moonlight/palette.json index 8e371d2e..39c43990 100644 --- a/src/data/extra/themes/moonlight/palette.json +++ b/src/data/extra/themes/moonlight/palette.json @@ -10,7 +10,8 @@ "markdown-editor-highlight-theme" : "Markdown Breeze Dark", "display_name" : "Moonlight", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "月夜" + "display_name_zh_CN" : "月夜", + "icon-monochrome": true }, "palette" : { "bg1_1" : "#07080d", diff --git a/src/data/extra/themes/native/palette.json b/src/data/extra/themes/native/palette.json index 77b2feea..8c254c0d 100644 --- a/src/data/extra/themes/native/palette.json +++ b/src/data/extra/themes/native/palette.json @@ -10,7 +10,8 @@ "markdown-editor-highlight-theme" : "Markdown Default", "display_name" : "Native", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "原素" + "display_name_zh_CN" : "原素", + "icon-monochrome": true }, "base" : { "normal" : { diff --git a/src/data/extra/themes/pure/palette.json b/src/data/extra/themes/pure/palette.json index 17aebb83..0fa13969 100644 --- a/src/data/extra/themes/pure/palette.json +++ b/src/data/extra/themes/pure/palette.json @@ -10,7 +10,8 @@ "markdown-editor-highlight-theme" : "Markdown Default", "display_name" : "Pure", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "纯净" + "display_name_zh_CN" : "纯净", + "icon-monochrome": true }, "palette" : { "bg3_0" : "#bbbbbb", diff --git a/src/data/extra/themes/solarized-dark/palette.json b/src/data/extra/themes/solarized-dark/palette.json index 9c1985c3..b5e03a96 100644 --- a/src/data/extra/themes/solarized-dark/palette.json +++ b/src/data/extra/themes/solarized-dark/palette.json @@ -11,7 +11,8 @@ "display_name" : "Solarized-dark", "//comment" : "Display name for different locales", "display_name_zh_CN" : "Solarized-dark", - "author": "nriver" + "author": "nriver", + "icon-monochrome": true }, "palette" : { "bg1_1" : "#002b36", diff --git a/src/data/extra/themes/solarized-light/palette.json b/src/data/extra/themes/solarized-light/palette.json index 11149ba8..25880489 100644 --- a/src/data/extra/themes/solarized-light/palette.json +++ b/src/data/extra/themes/solarized-light/palette.json @@ -11,7 +11,8 @@ "display_name" : "Solarized-light", "//comment" : "Display name for different locales", "display_name_zh_CN" : "Solarized-light", - "author": "nriver" + "author": "nriver", + "icon-monochrome": true }, "palette" : { "bg1_1" : "#FFFFF5", diff --git a/src/data/extra/themes/vscode-dark/palette.json b/src/data/extra/themes/vscode-dark/palette.json index ac566251..d8f49a91 100644 --- a/src/data/extra/themes/vscode-dark/palette.json +++ b/src/data/extra/themes/vscode-dark/palette.json @@ -10,7 +10,8 @@ "markdown-editor-highlight-theme" : "vscode-dark", "display_name" : "VSCode-dark", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "VSCode-深色" + "display_name_zh_CN" : "VSCode-深色", + "icon-monochrome": true }, "palette" : { "bg1_1" : "#07080d", diff --git a/src/utils/iconutils.cpp b/src/utils/iconutils.cpp index 946a8d9c..10c8e6e3 100644 --- a/src/utils/iconutils.cpp +++ b/src/utils/iconutils.cpp @@ -6,6 +6,8 @@ #include #include +#include + #include "fileutils.h" using namespace vnotex; @@ -19,7 +21,8 @@ QIcon IconUtils::fetchIcon(const QString &p_iconFile, qreal p_angle) { const auto suffix = QFileInfo(p_iconFile).suffix().toLower().toStdString(); - if (p_overriddenColors.isEmpty() || suffix != "svg") { + if ((p_overriddenColors.isEmpty() || suffix != "svg") + && !VNoteX::getInst().getThemeMgr().getIconMonochrome()) { return QIcon(p_iconFile); } @@ -46,7 +49,9 @@ QIcon IconUtils::fetchIcon(const QString &p_iconFile, QIcon IconUtils::fetchIcon(const QString &p_iconFile, const QString &p_overriddenForeground) { QVector colors; - if (!p_overriddenForeground.isEmpty()) { + const auto &themeMgr = VNoteX::getInst().getThemeMgr(); + + if (!p_overriddenForeground.isEmpty() && themeMgr.getIconMonochrome()) { colors.push_back(OverriddenColor(p_overriddenForeground, QIcon::Normal, QIcon::Off)); } diff --git a/src/widgets/dockwidgethelper.cpp b/src/widgets/dockwidgethelper.cpp index 699823a7..714939ad 100644 --- a/src/widgets/dockwidgethelper.cpp +++ b/src/widgets/dockwidgethelper.cpp @@ -514,7 +514,6 @@ const QIcon &DockWidgetHelper::getDockIcon(DockIndex p_dockIndex) { static const auto fg = VNoteX::getInst().getThemeMgr().paletteColor("widgets#mainwindow#dockwidget_tabbar#icon#fg"); static const auto selectedFg = VNoteX::getInst().getThemeMgr().paletteColor("widgets#mainwindow#dockwidget_tabbar#icon#selected#fg"); - const auto area = m_mainWindow->dockWidgetArea(m_docks[p_dockIndex]); const int newAngle = rotationAngle(area); if (m_dockIcons[p_dockIndex].m_rotationAngle != newAngle && area != Qt::NoDockWidgetArea) {