refine native theme

This commit is contained in:
Le Tan 2020-12-27 10:48:28 +08:00
parent 2600d12fc2
commit 88df448177
17 changed files with 89 additions and 194 deletions

View File

@ -22,6 +22,11 @@ const QString &CoreConfig::getTheme() const
return m_theme;
}
void CoreConfig::setTheme(const QString &p_name)
{
updateConfig(m_theme, p_name, this);
}
void CoreConfig::init(const QJsonObject &p_app,
const QJsonObject &p_user)
{
@ -60,9 +65,7 @@ const QString &CoreConfig::getLocale() const
void CoreConfig::setLocale(const QString &p_locale)
{
updateConfig(m_locale,
p_locale,
this);
updateConfig(m_locale, p_locale, this);
}
QString CoreConfig::getLocaleToUse() const

View File

@ -42,6 +42,7 @@ namespace vnotex
QJsonObject toJson() const Q_DECL_OVERRIDE;
const QString &getTheme() const;
void setTheme(const QString &p_name);
const QString &getLocale() const;
void setLocale(const QString &p_locale);

View File

@ -326,7 +326,7 @@ QString Theme::paletteColor(const QString &p_name) const
return val;
}
qWarning() << "undefined or invalid palette color" << p_name;
return QString();
return QString("#ff0000");
}
QJsonObject Theme::readJsonFile(const QString &p_filePath)

View File

@ -22,7 +22,7 @@ ThemeMgr::ThemeMgr(const QString &p_currentThemeName, QObject *p_parent)
loadCurrentTheme(p_currentThemeName);
IconUtils::setDefaultIconForeground(paletteColor("base#icon#fg"), paletteColor("base#icon#disabled_fg"));
IconUtils::setDefaultIconForeground(paletteColor("base#icon#fg"), paletteColor("base#icon#disabled#fg"));
}
QString ThemeMgr::getIconFile(const QString &p_icon) const

View File

@ -1,144 +0,0 @@
{
"metadata" : {
"revision" : 3,
"name" : "Default"
},
"text-styles": {
"Normal" : {
"text-color" : "#1f1c1b",
"selected-text-color" : "#ffffff",
"bold" : true,
"italic" : false,
"underline" : false,
"strike-through" : false
},
"Keyword" : {
"text-color" : "#1f1c1b",
"selected-text-color" : "#ffffff",
"bold" : true
},
"Function" : {
"text-color" : "#644a9b",
"selected-text-color" : "#452886"
},
"Variable" : {
"text-color" : "#0057ae",
"selected-text-color" : "#00316e"
},
"ControlFlow" : {
"text-color" : "#1f1c1b",
"selected-text-color" : "#ffffff",
"bold" : true
},
"Operator" : {
"text-color" : "#1f1c1b",
"selected-text-color" : "#ffffff"
},
"BuiltIn" : {
"text-color" : "#644a9b",
"selected-text-color" : "#452886",
"bold" : true
},
"Extension" : {
"text-color" : "#0095ff",
"selected-text-color" : "#ffffff",
"bold" : true
},
"Preprocessor" : {
"text-color" : "#006e28",
"selected-text-color" : "#006e28"
},
"Attribute" : {
"text-color" : "#0057ae",
"selected-text-color" : "#00316e"
},
"Char" : {
"text-color" : "#924c9d",
"selected-text-color" : "#6c2477"
},
"SpecialChar" : {
"text-color" : "#3daee9",
"selected-text-color" : "#fcfcfc"
},
"String" : {
"text-color" : "#bf0303",
"selected-text-color" : "#9c0e0e"
},
"VerbatimString" : {
"text-color" : "#bf0303",
"selected-text-color" : "#9c0e0e"
},
"SpecialString" : {
"text-color" : "#ff5500",
"selected-text-color" : "#ff5500"
},
"Import" : {
"text-color" : "#ff5500",
"selected-text-color" : "#ff5500"
},
"DataType" : {
"text-color" : "#0057ae",
"selected-text-color" : "#00316e"
},
"DecVal" : {
"text-color" : "#b08000",
"selected-text-color" : "#805c00"
},
"BaseN" : {
"text-color" : "#b08000",
"selected-text-color" : "#805c00"
},
"Float" : {
"text-color" : "#b08000",
"selected-text-color" : "#805c00"
},
"Constant" : {
"text-color" : "#aa5500",
"selected-text-color" : "#5e2f00"
},
"Comment" : {
"text-color" : "#898887",
"selected-text-color" : "#5e5d5d"
},
"Documentation" : {
"text-color" : "#607880",
"selected-text-color" : "#46585e"
},
"Annotation" : {
"text-color" : "#ca60ca",
"selected-text-color" : "#a44ea4"
},
"CommentVar" : {
"text-color" : "#0095ff",
"selected-text-color" : "#ffffff"
},
"RegionMarker" : {
"text-color" : "#0057ae",
"selected-text-color" : "#00316e",
"background-color" : "#e0e9f8"
},
"Information" : {
"text-color" : "#b08000",
"selected-text-color" : "#805c00"
},
"Warning" : {
"text-color" : "#bf0303",
"selected-text-color" : "#9c0e0e"
},
"Alert" : {
"text-color" : "#bf0303",
"selected-text-color" : "#9c0e0e",
"background-color" : "#f7e6e6",
"bold" : true
},
"Error" : {
"text-color" : "#bf0303",
"selected-text-color" : "#9c0e0e",
"underline" : true
},
"Others" : {
"text-color" : "#006e28",
"selected-text-color" : "#006e28"
}
}
}

View File

@ -1,6 +1,6 @@
/* Qt Style Sheets file
* Please refer to https://doc.qt.io/qt-5.12/stylesheet-reference.html
* for detail inforamtion.
* for detailed inforamtion.
* VNote specific syntax:
* - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
* - $2px: 2 will be scaled by multiplying current display scaled factor.
@ -22,8 +22,8 @@ vnotex--ToolBox QToolButton[ToolBoxTitleButton="true"] {
vnotex--ToolBox QToolButton[ToolBoxTitleButton="true"]:checked {
font-weight: bold;
/* Reverse */
color: @widgets#toolbox#title#button#active_fg;
background-color: @widgets#toolbox#title#button#active_bg;
color: @widgets#toolbox#title#button#active#fg;
background-color: @widgets#toolbox#title#button#active#bg;
}
/* TitleBar */
@ -85,9 +85,9 @@ QToolButton[NoMenuIndicator="true"]::menu-indicator {
}
/* QPushButton, QToolButton */
QPushButton[DangerousButton="true"]:hover, QToolButton[DangerousButton="true"]:hover {
color: @base#dangerous_fg;
background-color: @base#dangerous_bg;
QPushButton[DangerButton="true"]:hover, QToolButton[DangerButton="true"]:hover {
color: @base#danger#fg;
background-color: @base#danger#bg;
border: none;
}
@ -106,13 +106,13 @@ vnotex--DragDropAreaIndicator QLabel {
/* All widgets */
*[State="info"] {
border: 2px solid @base#info_fg;
border: 2px solid @base#info#fg;
}
*[State="warning"] {
border: 2px solid @base#warning_fg;
border: 2px solid @base#warning#fg;
}
*[State="error"] {
border: 2px solid @base#error_fg;
border: 2px solid @base#error#fg;
}

View File

@ -2,40 +2,60 @@
"metadata" : {
"revision" : 0,
"//comment" : "If there is a file named 'editor-highlight.theme' under theme folder, this value will be ignored.",
"//comment" : "Otherwise, this value specify the theme name to use.",
"//comment" : "Otherwise, this value specify the theme name to use for syntax highlighting.",
"editor-highlight-theme" : "Default",
"//comment" : "If there is a file named 'markdown-editor-highlight.theme' under theme folder, this value will be ignored.",
"//comment" : "Otherwise, this value specify the theme name to use.",
"//comment" : "If empty, editor-highlight-theme will be used.",
"//comment" : "Otherwise, this value specify the theme name to use for syntax highlighting.",
"//comment" : "If empty, 'editor-highlight-theme' will be used.",
"markdown-editor-highlight-theme" : "Markdown Default",
"display_name" : "Native",
"//comment" : "Display name for different locales",
"display_name_zh_CN" : "原素"
},
"base" : {
"fg1" : "#31373c",
"fg2" : "#babdc1",
"error_fg" : "#b71c1c",
"warning_fg" : "#880e4f",
"info_fg" : "#283593",
"border" : "@base#fg2",
"dangerous_fg": "#f5f5f5",
"dangerous_bg": "#c9302c",
"normal" : {
"fg" : "#31373c",
"border" : "@base#lighter#fg"
},
"lighter" : {
"fg" : "#babdc1"
},
"error" : {
"fg" : "#b71c1c"
},
"warning" : {
"fg" : "#880e4f"
},
"info" : {
"fg" : "#283593"
},
"danger" : {
"fg": "#f5f5f5",
"bg": "#c9302c"
},
"icon" : {
"fg" : "#434b52",
"disabled_fg" : "@base#fg2",
"warning_fg" : "@base#warning_fg",
"dangerous_fg": "@base#dangerous_fg"
"disabled" : {
"fg" : "@base#lighter#fg"
},
"warning" : {
"fg" : "@base#warning#fg"
},
"danger" : {
"fg": "@base#danger#fg"
}
}
},
"widgets" : {
"toolbox" : {
"title" : {
"border" : "@widgets#toolbox#title#button#active_bg",
"border" : "@widgets#toolbox#title#button#active#bg",
"button": {
"fg" : "@base#fg1",
"active_fg" : "#fbffff",
"active_bg" : "#535c65"
"fg" : "@base#normal#fg",
"active" : {
"fg" : "#fbffff",
"bg" : "#535c65"
}
}
}
},
@ -45,14 +65,20 @@
},
"menu_icon" : {
"fg" : "@base#icon#fg",
"disabled_fg" : "@base#icon#disabled_fg"
"disabled" : {
"fg" : "@base#icon#disabled#fg"
}
}
},
"toolbar" : {
"icon" : {
"fg" : "@base#icon#fg",
"disabled_fg" : "@base#icon#disabled_fg",
"dangerous_fg" : "@base#icon#dangerous_fg"
"disabled" : {
"fg" : "@base#icon#disabled#fg"
},
"danger" : {
"fg" : "@base#icon#danger#fg"
}
}
},
"notebookexplorer" : {
@ -63,21 +89,23 @@
"viewsplit" : {
"action_button" : {
"fg" : "#808080",
"active_fg" : "@base#icon#fg"
"active" : {
"fg" : "@base#icon#fg"
}
}
},
"qmainwindow" : {
"separator" : {
"bg" : "@base#border"
"bg" : "@base#normal#border"
}
},
"dragdropareaindicator" : {
"fg" : "@base#fg1",
"fg" : "@base#normal#fg",
"border" : "@widgets#dragdropareaindicator#fg"
},
"navigationlabel" : {
"fg" : "@widgets#toolbox#title#button#active_fg",
"bg" : "@widgets#toolbox#title#button#active_bg"
"fg" : "@widgets#toolbox#title#button#active#fg",
"bg" : "@widgets#toolbox#title#button#active#bg"
}
}
}

View File

@ -70,7 +70,7 @@ void ManageNotebooksDialog::setupUI()
});
m_deleteNotebookBtn = new QPushButton(tr("Delete"), infoWidget);
WidgetUtils::setPropertyDynamically(m_deleteNotebookBtn, PropertyDefs::s_dangerousButton, true);
WidgetUtils::setPropertyDynamically(m_deleteNotebookBtn, PropertyDefs::s_dangerButton, true);
btnLayout->addWidget(m_deleteNotebookBtn);
connect(m_deleteNotebookBtn, &QPushButton::clicked,
this, [this]() {

View File

@ -17,6 +17,7 @@
#include <core/thememgr.h>
#include <core/vnotex.h>
#include <core/configmgr.h>
#include <core/coreconfig.h>
#include <utils/widgetutils.h>
using namespace vnotex;
@ -99,6 +100,10 @@ void ThemePage::loadInternal()
void ThemePage::saveInternal()
{
auto theme = currentTheme();
if (!theme.isEmpty()) {
ConfigMgr::getInst().getCoreConfig().setTheme(theme);
}
}
QString ThemePage::title() const

View File

@ -6,6 +6,6 @@ const char *PropertyDefs::s_actionToolButton = "ActionToolButton";
const char *PropertyDefs::s_toolButtonWithoutMenuIndicator = "NoMenuIndicator";
const char *PropertyDefs::s_dangerousButton = "DangerousButton";
const char *PropertyDefs::s_dangerButton = "DangerButton";
const char *PropertyDefs::s_state = "State";

View File

@ -13,7 +13,7 @@ namespace vnotex
static const char *s_toolButtonWithoutMenuIndicator;
static const char *s_dangerousButton;
static const char *s_dangerButton;
// Values: info/warning/error.
static const char *s_state;

View File

@ -20,7 +20,7 @@ const QString TitleBar::c_actionButtonForegroundName = "widgets#titlebar#button#
const QString TitleBar::c_menuIconForegroundName = "widgets#titlebar#menu_icon#fg";
const QString TitleBar::c_menuIconDisabledForegroundName = "widgets#titlebar#menu_icon#disabled_fg";
const QString TitleBar::c_menuIconDisabledForegroundName = "widgets#titlebar#menu_icon#disabled#fg";
TitleBar::TitleBar(const QString &p_title,
TitleBar::Actions p_actionFlags,

View File

@ -5,6 +5,8 @@
#include <QCoreApplication>
#include <QToolButton>
#include "propertydefs.h"
using namespace vnotex;
TitleToolBar::TitleToolBar(QWidget *p_parent)
@ -90,7 +92,7 @@ void TitleToolBar::addTitleBarIcons(const QIcon &p_minimizeIcon,
m_window->close();
});
auto btn = static_cast<QToolButton *>(widgetForAction(closeAct));
btn->setProperty("DangerousButton", true);
btn->setProperty(PropertyDefs::s_dangerButton, true);
}
updateMaximizeAct();

View File

@ -406,8 +406,8 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too
}
static const QString c_fgPalette = QStringLiteral("widgets#toolbar#icon#fg");
static const QString c_disabledPalette = QStringLiteral("widgets#toolbar#icon#disabled_fg");
static const QString c_dangerousPalette = QStringLiteral("widgets#toolbar#icon#dangerous_fg");
static const QString c_disabledPalette = QStringLiteral("widgets#toolbar#icon#disabled#fg");
static const QString c_dangerousPalette = QStringLiteral("widgets#toolbar#icon#danger#fg");
QIcon ToolBarHelper::generateIcon(const QString &p_iconName)
{

View File

@ -22,7 +22,7 @@ const char *ToolBox::c_titleButtonProp = "ToolBoxTitleButton";
const QString ToolBox::c_titleButtonForegroundName = "widgets#toolbox#title#button#fg";
const QString ToolBox::c_titleButtonActiveForegroundName = "widgets#toolbox#title#button#active_fg";
const QString ToolBox::c_titleButtonActiveForegroundName = "widgets#toolbox#title#button#active#fg";
ToolBox::ToolBox(QWidget *p_parent)
: QFrame(p_parent),

View File

@ -36,7 +36,7 @@ QIcon ViewSplit::s_menuIcon;
QIcon ViewSplit::s_menuActiveIcon;
const QString ViewSplit::c_activeActionButtonForegroundName = "widgets#viewsplit#action_button#active_fg";
const QString ViewSplit::c_activeActionButtonForegroundName = "widgets#viewsplit#action_button#active#fg";
const QString ViewSplit::c_actionButtonForegroundName = "widgets#viewsplit#action_button#fg";

View File

@ -125,7 +125,7 @@ void ViewWindow::initIcons()
const auto &themeMgr = VNoteX::getInst().getThemeMgr();
const QString savedIconName("saved.svg");
const QString unsavedIconFg("base#icon#warning_fg");
const QString unsavedIconFg("base#icon#warning#fg");
s_savedIcon = IconUtils::fetchIcon(themeMgr.getIconFile(savedIconName));
s_modifiedIcon = IconUtils::fetchIcon(themeMgr.getIconFile(savedIconName),
themeMgr.paletteColor(unsavedIconFg));