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
This commit is contained in:
chendapao 2022-06-21 18:31:25 +08:00 committed by GitHub
parent 29b2093ef0
commit 1318427bb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 49 additions and 10 deletions

View File

@ -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);

View File

@ -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;

View File

@ -10,6 +10,7 @@
#include <vtextedit/vtexteditor.h>
#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);

View File

@ -49,6 +49,8 @@ namespace vnotex
QString getMarkdownEditorHighlightTheme() const;
bool getIconMonochrome() const;
const QColor &getBaseBackground() const;
void setBaseBackground(const QColor &p_bg);

View File

@ -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",

View File

@ -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" : {

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -6,6 +6,8 @@
#include <QPainter>
#include <QDebug>
#include <core/vnotex.h>
#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<OverriddenColor> 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));
}

View File

@ -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) {