Ver código fonte

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
chendapao 3 anos atrás
pai
commit
3025e8e01c

+ 0 - 6
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);

+ 0 - 6
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;

+ 0 - 5
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);

+ 0 - 2
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);
 

+ 1 - 2
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",

+ 1 - 2
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" : {

+ 1 - 2
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",

+ 1 - 2
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",

+ 1 - 2
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",

+ 1 - 2
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",

+ 27 - 5
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<OverriddenColor> 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);

+ 2 - 0
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