mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
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
This commit is contained in:
parent
e5f7a23157
commit
3025e8e01c
@ -86,7 +86,6 @@ Theme::Metadata Theme::readMetadata(const Palette &p_obj)
|
|||||||
data.m_revision = metaObj[QStringLiteral("revision")].toInt();
|
data.m_revision = metaObj[QStringLiteral("revision")].toInt();
|
||||||
data.m_editorHighlightTheme = metaObj[QStringLiteral("editor-highlight-theme")].toString();
|
data.m_editorHighlightTheme = metaObj[QStringLiteral("editor-highlight-theme")].toString();
|
||||||
data.m_markdownEditorHighlightTheme = metaObj[QStringLiteral("markdown-editor-highlight-theme")].toString();
|
data.m_markdownEditorHighlightTheme = metaObj[QStringLiteral("markdown-editor-highlight-theme")].toString();
|
||||||
data.m_IconMonochrome = metaObj[QStringLiteral("icon-monochrome")].toBool();
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -441,11 +440,6 @@ QString Theme::getMarkdownEditorHighlightTheme() const
|
|||||||
return getEditorHighlightTheme();
|
return getEditorHighlightTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Theme::getIconMonochrome() const
|
|
||||||
{
|
|
||||||
return m_metadata.m_IconMonochrome;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Theme::name() const
|
QString Theme::name() const
|
||||||
{
|
{
|
||||||
return PathUtils::dirName(m_themeFolderPath);
|
return PathUtils::dirName(m_themeFolderPath);
|
||||||
|
@ -45,8 +45,6 @@ namespace vnotex
|
|||||||
// Return the file path of the theme or just the theme name.
|
// Return the file path of the theme or just the theme name.
|
||||||
QString getMarkdownEditorHighlightTheme() const;
|
QString getMarkdownEditorHighlightTheme() const;
|
||||||
|
|
||||||
bool getIconMonochrome() const;
|
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
|
|
||||||
static bool isValidThemeFolder(const QString &p_folder);
|
static bool isValidThemeFolder(const QString &p_folder);
|
||||||
@ -72,10 +70,6 @@ namespace vnotex
|
|||||||
// If not specified, will use m_editorHighlightTheme.
|
// If not specified, will use m_editorHighlightTheme.
|
||||||
// Valid only when KSyntaxCodeBlockHighlighter is used.
|
// Valid only when KSyntaxCodeBlockHighlighter is used.
|
||||||
QString m_markdownEditorHighlightTheme;
|
QString m_markdownEditorHighlightTheme;
|
||||||
|
|
||||||
// Whether the icon of the current theme uses monochrome.
|
|
||||||
// Default is monochrome.
|
|
||||||
bool m_IconMonochrome = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QJsonObject Palette;
|
typedef QJsonObject Palette;
|
||||||
|
@ -179,11 +179,6 @@ QString ThemeMgr::getMarkdownEditorHighlightTheme() const
|
|||||||
return m_currentTheme->getMarkdownEditorHighlightTheme();
|
return m_currentTheme->getMarkdownEditorHighlightTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThemeMgr::getIconMonochrome() const
|
|
||||||
{
|
|
||||||
return m_currentTheme->getIconMonochrome();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThemeMgr::addSyntaxHighlightingSearchPaths(const QStringList &p_paths)
|
void ThemeMgr::addSyntaxHighlightingSearchPaths(const QStringList &p_paths)
|
||||||
{
|
{
|
||||||
vte::VTextEditor::addSyntaxCustomSearchPaths(p_paths);
|
vte::VTextEditor::addSyntaxCustomSearchPaths(p_paths);
|
||||||
|
@ -49,8 +49,6 @@ namespace vnotex
|
|||||||
|
|
||||||
QString getMarkdownEditorHighlightTheme() const;
|
QString getMarkdownEditorHighlightTheme() const;
|
||||||
|
|
||||||
bool getIconMonochrome() const;
|
|
||||||
|
|
||||||
const QColor &getBaseBackground() const;
|
const QColor &getBaseBackground() const;
|
||||||
void setBaseBackground(const QColor &p_bg);
|
void setBaseBackground(const QColor &p_bg);
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
"markdown-editor-highlight-theme" : "Markdown Breeze Dark",
|
"markdown-editor-highlight-theme" : "Markdown Breeze Dark",
|
||||||
"display_name" : "Moonlight",
|
"display_name" : "Moonlight",
|
||||||
"//comment" : "Display name for different locales",
|
"//comment" : "Display name for different locales",
|
||||||
"display_name_zh_CN" : "月夜",
|
"display_name_zh_CN" : "月夜"
|
||||||
"icon-monochrome": true
|
|
||||||
},
|
},
|
||||||
"palette" : {
|
"palette" : {
|
||||||
"bg1_1" : "#07080d",
|
"bg1_1" : "#07080d",
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
"markdown-editor-highlight-theme" : "Markdown Default",
|
"markdown-editor-highlight-theme" : "Markdown Default",
|
||||||
"display_name" : "Native",
|
"display_name" : "Native",
|
||||||
"//comment" : "Display name for different locales",
|
"//comment" : "Display name for different locales",
|
||||||
"display_name_zh_CN" : "原素",
|
"display_name_zh_CN" : "原素"
|
||||||
"icon-monochrome": true
|
|
||||||
},
|
},
|
||||||
"base" : {
|
"base" : {
|
||||||
"normal" : {
|
"normal" : {
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
"markdown-editor-highlight-theme" : "Markdown Default",
|
"markdown-editor-highlight-theme" : "Markdown Default",
|
||||||
"display_name" : "Pure",
|
"display_name" : "Pure",
|
||||||
"//comment" : "Display name for different locales",
|
"//comment" : "Display name for different locales",
|
||||||
"display_name_zh_CN" : "纯净",
|
"display_name_zh_CN" : "纯净"
|
||||||
"icon-monochrome": true
|
|
||||||
},
|
},
|
||||||
"palette" : {
|
"palette" : {
|
||||||
"bg3_0" : "#bbbbbb",
|
"bg3_0" : "#bbbbbb",
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
"display_name" : "Solarized-dark",
|
"display_name" : "Solarized-dark",
|
||||||
"//comment" : "Display name for different locales",
|
"//comment" : "Display name for different locales",
|
||||||
"display_name_zh_CN" : "Solarized-dark",
|
"display_name_zh_CN" : "Solarized-dark",
|
||||||
"author": "nriver",
|
"author": "nriver"
|
||||||
"icon-monochrome": true
|
|
||||||
},
|
},
|
||||||
"palette" : {
|
"palette" : {
|
||||||
"bg1_1" : "#002b36",
|
"bg1_1" : "#002b36",
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
"display_name" : "Solarized-light",
|
"display_name" : "Solarized-light",
|
||||||
"//comment" : "Display name for different locales",
|
"//comment" : "Display name for different locales",
|
||||||
"display_name_zh_CN" : "Solarized-light",
|
"display_name_zh_CN" : "Solarized-light",
|
||||||
"author": "nriver",
|
"author": "nriver"
|
||||||
"icon-monochrome": true
|
|
||||||
},
|
},
|
||||||
"palette" : {
|
"palette" : {
|
||||||
"bg1_1" : "#FFFFF5",
|
"bg1_1" : "#FFFFF5",
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
"markdown-editor-highlight-theme" : "vscode-dark",
|
"markdown-editor-highlight-theme" : "vscode-dark",
|
||||||
"display_name" : "VSCode-dark",
|
"display_name" : "VSCode-dark",
|
||||||
"//comment" : "Display name for different locales",
|
"//comment" : "Display name for different locales",
|
||||||
"display_name_zh_CN" : "VSCode-深色",
|
"display_name_zh_CN" : "VSCode-深色"
|
||||||
"icon-monochrome": true
|
|
||||||
},
|
},
|
||||||
"palette" : {
|
"palette" : {
|
||||||
"bg1_1" : "#07080d",
|
"bg1_1" : "#07080d",
|
||||||
|
@ -21,8 +21,7 @@ QIcon IconUtils::fetchIcon(const QString &p_iconFile,
|
|||||||
qreal p_angle)
|
qreal p_angle)
|
||||||
{
|
{
|
||||||
const auto suffix = QFileInfo(p_iconFile).suffix().toLower().toStdString();
|
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);
|
return QIcon(p_iconFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +30,10 @@ QIcon IconUtils::fetchIcon(const QString &p_iconFile,
|
|||||||
return QIcon();
|
return QIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isMonochrome(content)) {
|
||||||
|
return QIcon(p_iconFile);
|
||||||
|
}
|
||||||
|
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
for (const auto &color : p_overriddenColors) {
|
for (const auto &color : p_overriddenColors) {
|
||||||
auto overriddenContent = replaceForegroundOfIcon(content, color.m_foreground);
|
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)
|
QIcon IconUtils::fetchIcon(const QString &p_iconFile, const QString &p_overriddenForeground)
|
||||||
{
|
{
|
||||||
QVector<OverriddenColor> colors;
|
QVector<OverriddenColor> colors;
|
||||||
const auto &themeMgr = VNoteX::getInst().getThemeMgr();
|
if (!p_overriddenForeground.isEmpty()) {
|
||||||
|
|
||||||
if (!p_overriddenForeground.isEmpty() && themeMgr.getIconMonochrome()) {
|
|
||||||
colors.push_back(OverriddenColor(p_overriddenForeground, QIcon::Normal, QIcon::Off));
|
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;
|
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)
|
QIcon IconUtils::fetchIcon(const QString &p_iconFile)
|
||||||
{
|
{
|
||||||
return fetchIcon(p_iconFile, s_defaultIconForeground);
|
return fetchIcon(p_iconFile, s_defaultIconForeground);
|
||||||
|
@ -57,6 +57,8 @@ namespace vnotex
|
|||||||
static QString s_defaultIconForeground;
|
static QString s_defaultIconForeground;
|
||||||
|
|
||||||
static QString s_defaultIconDisabledForeground;
|
static QString s_defaultIconDisabledForeground;
|
||||||
|
|
||||||
|
static bool isMonochrome(const QString &p_iconContent);
|
||||||
};
|
};
|
||||||
} // ns vnotex
|
} // ns vnotex
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user