From 3025e8e01c2bddbe47b8da2c97f2e9e48380b55c Mon Sep 17 00:00:00 2001 From: chendapao Date: Thu, 14 Jul 2022 08:51:45 +0800 Subject: [PATCH] feature/adj_mono_icons_render (#2174) * feature/adj_mono_icons_render * adj mono check * del space * feature/adj_mono_icons_render * adj color match * adj color hex match * adj color hex match * simple * simple * feature/adj_mono_icons_render * feature/adj_mono_icons_render * back QRegExp --- src/core/theme.cpp | 6 ---- src/core/theme.h | 6 ---- src/core/thememgr.cpp | 5 --- 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 +- .../extra/themes/solarized-dark/palette.json | 3 +- .../extra/themes/solarized-light/palette.json | 3 +- .../extra/themes/vscode-dark/palette.json | 3 +- src/utils/iconutils.cpp | 32 ++++++++++++++++--- src/utils/iconutils.h | 2 ++ 12 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/core/theme.cpp b/src/core/theme.cpp index 00439d47..e610de3d 100644 --- a/src/core/theme.cpp +++ b/src/core/theme.cpp @@ -86,7 +86,6 @@ 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; } @@ -441,11 +440,6 @@ 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 327c1b99..d44e56d2 100644 --- a/src/core/theme.h +++ b/src/core/theme.h @@ -45,8 +45,6 @@ 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); @@ -72,10 +70,6 @@ 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 f95606e0..e5fec023 100644 --- a/src/core/thememgr.cpp +++ b/src/core/thememgr.cpp @@ -179,11 +179,6 @@ 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 d739d181..2ad2d7ec 100644 --- a/src/core/thememgr.h +++ b/src/core/thememgr.h @@ -49,8 +49,6 @@ 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 39c43990..8e371d2e 100644 --- a/src/data/extra/themes/moonlight/palette.json +++ b/src/data/extra/themes/moonlight/palette.json @@ -10,8 +10,7 @@ "markdown-editor-highlight-theme" : "Markdown Breeze Dark", "display_name" : "Moonlight", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "月夜", - "icon-monochrome": true + "display_name_zh_CN" : "月夜" }, "palette" : { "bg1_1" : "#07080d", diff --git a/src/data/extra/themes/native/palette.json b/src/data/extra/themes/native/palette.json index 8c254c0d..77b2feea 100644 --- a/src/data/extra/themes/native/palette.json +++ b/src/data/extra/themes/native/palette.json @@ -10,8 +10,7 @@ "markdown-editor-highlight-theme" : "Markdown Default", "display_name" : "Native", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "原素", - "icon-monochrome": true + "display_name_zh_CN" : "原素" }, "base" : { "normal" : { diff --git a/src/data/extra/themes/pure/palette.json b/src/data/extra/themes/pure/palette.json index 0fa13969..17aebb83 100644 --- a/src/data/extra/themes/pure/palette.json +++ b/src/data/extra/themes/pure/palette.json @@ -10,8 +10,7 @@ "markdown-editor-highlight-theme" : "Markdown Default", "display_name" : "Pure", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "纯净", - "icon-monochrome": true + "display_name_zh_CN" : "纯净" }, "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 b5e03a96..9c1985c3 100644 --- a/src/data/extra/themes/solarized-dark/palette.json +++ b/src/data/extra/themes/solarized-dark/palette.json @@ -11,8 +11,7 @@ "display_name" : "Solarized-dark", "//comment" : "Display name for different locales", "display_name_zh_CN" : "Solarized-dark", - "author": "nriver", - "icon-monochrome": true + "author": "nriver" }, "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 25880489..11149ba8 100644 --- a/src/data/extra/themes/solarized-light/palette.json +++ b/src/data/extra/themes/solarized-light/palette.json @@ -11,8 +11,7 @@ "display_name" : "Solarized-light", "//comment" : "Display name for different locales", "display_name_zh_CN" : "Solarized-light", - "author": "nriver", - "icon-monochrome": true + "author": "nriver" }, "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 d8f49a91..ac566251 100644 --- a/src/data/extra/themes/vscode-dark/palette.json +++ b/src/data/extra/themes/vscode-dark/palette.json @@ -10,8 +10,7 @@ "markdown-editor-highlight-theme" : "vscode-dark", "display_name" : "VSCode-dark", "//comment" : "Display name for different locales", - "display_name_zh_CN" : "VSCode-深色", - "icon-monochrome": true + "display_name_zh_CN" : "VSCode-深色" }, "palette" : { "bg1_1" : "#07080d", diff --git a/src/utils/iconutils.cpp b/src/utils/iconutils.cpp index 90ac8edd..95ef353a 100644 --- a/src/utils/iconutils.cpp +++ b/src/utils/iconutils.cpp @@ -21,8 +21,7 @@ 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") - && VNoteX::getInst().getThemeMgr().getIconMonochrome()) { + if (p_overriddenColors.isEmpty() || suffix != "svg") { return QIcon(p_iconFile); } @@ -31,6 +30,10 @@ QIcon IconUtils::fetchIcon(const QString &p_iconFile, return QIcon(); } + if (!isMonochrome(content)) { + return QIcon(p_iconFile); + } + QIcon icon; for (const auto &color : p_overriddenColors) { auto overriddenContent = replaceForegroundOfIcon(content, color.m_foreground); @@ -49,9 +52,7 @@ QIcon IconUtils::fetchIcon(const QString &p_iconFile, QIcon IconUtils::fetchIcon(const QString &p_iconFile, const QString &p_overriddenForeground) { QVector colors; - const auto &themeMgr = VNoteX::getInst().getThemeMgr(); - - if (!p_overriddenForeground.isEmpty() && themeMgr.getIconMonochrome()) { + if (!p_overriddenForeground.isEmpty()) { colors.push_back(OverriddenColor(p_overriddenForeground, QIcon::Normal, QIcon::Off)); } @@ -75,6 +76,27 @@ QString IconUtils::replaceForegroundOfIcon(const QString &p_iconContent, const Q return p_iconContent; } +bool IconUtils::isMonochrome(const QString &p_iconContent) +{ + // Match color-hex codes. + QRegExp monoRe("#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})"); + + int i = 0; + QString cur, next = ""; + while ((i = monoRe.indexIn(p_iconContent, i)) != -1) { + if (i != 0) { + next = cur; + } + cur = monoRe.cap(1); + if (next != "" && cur != next) { + return false; + } + + i += monoRe.matchedLength(); + } + return true; +} + QIcon IconUtils::fetchIcon(const QString &p_iconFile) { return fetchIcon(p_iconFile, s_defaultIconForeground); diff --git a/src/utils/iconutils.h b/src/utils/iconutils.h index cf951915..64fdd83d 100644 --- a/src/utils/iconutils.h +++ b/src/utils/iconutils.h @@ -57,6 +57,8 @@ namespace vnotex static QString s_defaultIconForeground; static QString s_defaultIconDisabledForeground; + + static bool isMonochrome(const QString &p_iconContent); }; } // ns vnotex