mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
refine editor style
1. Support editor-current-line and editor-selection style in MDHL; 2. Support vim-background in editor-current-line;
This commit is contained in:
parent
ee4bfb171a
commit
c48fbe16da
@ -6,6 +6,14 @@ editor
|
||||
# Do not use "" to quote the name
|
||||
font-family: Hiragino Sans GB, 冬青黑体, STXihei, 华文细黑, Microsoft YaHei, 微软雅黑, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Helvetica, sans-serif, Tahoma, Arial, Verdana, Geneva, Georgia, Times New Roman
|
||||
|
||||
editor-selection
|
||||
foreground: eeeeee
|
||||
background: 005fff
|
||||
|
||||
editor-current-line
|
||||
background: c5cae9
|
||||
vim-background: a5d6a7
|
||||
|
||||
H1
|
||||
foreground: 111111
|
||||
font-style: bold
|
||||
|
@ -227,6 +227,9 @@ bool VConfigManager::deleteDirectoryConfig(const QString &path)
|
||||
|
||||
void VConfigManager::updateMarkdownEditStyle()
|
||||
{
|
||||
static const QString defaultCurrentLineBackground = "#C5CAE9";
|
||||
static const QString defaultCurrentLineVimBackground = "#A5D6A7";
|
||||
|
||||
// Read style file .mdhl
|
||||
QString file(":/resources/styles/default.mdhl");
|
||||
|
||||
@ -240,7 +243,25 @@ void VConfigManager::updateMarkdownEditStyle()
|
||||
mdHighlightingStyles = parser.fetchMarkdownStyles(baseEditFont);
|
||||
mdEditPalette = baseEditPalette;
|
||||
mdEditFont = baseEditFont;
|
||||
parser.fetchMarkdownEditorStyles(mdEditPalette, mdEditFont);
|
||||
QMap<QString, QMap<QString, QString>> styles;
|
||||
parser.fetchMarkdownEditorStyles(mdEditPalette, mdEditFont, styles);
|
||||
|
||||
m_editorCurrentLineBackground = defaultCurrentLineBackground;
|
||||
m_editorCurrentLineVimBackground = defaultCurrentLineVimBackground;
|
||||
auto editorCurrentLineIt = styles.find("editor-current-line");
|
||||
if (editorCurrentLineIt != styles.end()) {
|
||||
auto backgroundIt = editorCurrentLineIt->find("background");
|
||||
if (backgroundIt != editorCurrentLineIt->end()) {
|
||||
m_editorCurrentLineBackground = *backgroundIt;
|
||||
}
|
||||
|
||||
auto vimBackgroundIt = editorCurrentLineIt->find("vim-background");
|
||||
if (vimBackgroundIt != editorCurrentLineIt->end()) {
|
||||
m_editorCurrentLineVimBackground = "#" + *vimBackgroundIt;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "editor-current-line:" << m_editorCurrentLineBackground << m_editorCurrentLineVimBackground;
|
||||
}
|
||||
|
||||
void VConfigManager::updatePaletteColor()
|
||||
|
@ -126,6 +126,9 @@ public:
|
||||
void setWebZoomFactor(qreal p_factor);
|
||||
inline bool isCustomWebZoomFactor();
|
||||
|
||||
inline QString getEditorCurrentLineBackground() const;
|
||||
inline QString getEditorCurrentLineVimBackground() const;
|
||||
|
||||
private:
|
||||
void updateMarkdownEditStyle();
|
||||
QVariant getConfigFromSettings(const QString §ion, const QString &key);
|
||||
@ -193,6 +196,11 @@ private:
|
||||
// Zoom factor of the QWebEngineView.
|
||||
qreal m_webZoomFactor;
|
||||
|
||||
// Current line background color in editor.
|
||||
QString m_editorCurrentLineBackground;
|
||||
// Current line background color in editor in Vim mode.
|
||||
QString m_editorCurrentLineVimBackground;
|
||||
|
||||
// The name of the config file in each directory
|
||||
static const QString dirConfigFileName;
|
||||
// The name of the default configuration file
|
||||
@ -550,4 +558,13 @@ inline bool VConfigManager::isCustomWebZoomFactor()
|
||||
return factorFromIni > 0;
|
||||
}
|
||||
|
||||
inline QString VConfigManager::getEditorCurrentLineBackground() const
|
||||
{
|
||||
return m_editorCurrentLineBackground;
|
||||
}
|
||||
|
||||
inline QString VConfigManager::getEditorCurrentLineVimBackground() const
|
||||
{
|
||||
return m_editorCurrentLineVimBackground;
|
||||
}
|
||||
#endif // VCONFIGMANAGER_H
|
||||
|
@ -13,16 +13,11 @@ extern VNote *g_vnote;
|
||||
|
||||
enum ImageProperty { ImagePath = 1 };
|
||||
|
||||
const QString VMdEdit::c_cursorLineColor = "Indigo1";
|
||||
const QString VMdEdit::c_cursorLineColorVim = "Green2";
|
||||
|
||||
VMdEdit::VMdEdit(VFile *p_file, QWidget *p_parent)
|
||||
: VEdit(p_file, p_parent), m_mdHighlighter(NULL), m_previewImage(true)
|
||||
{
|
||||
Q_ASSERT(p_file->getDocType() == DocType::Markdown);
|
||||
|
||||
m_cursorLineColor = QColor(g_vnote->getColorFromPalette(c_cursorLineColor));
|
||||
|
||||
setAcceptRichText(false);
|
||||
m_mdHighlighter = new HGMarkdownHighlighter(vconfig.getMdHighlightingStyles(),
|
||||
500, document());
|
||||
@ -50,6 +45,7 @@ void VMdEdit::updateFontAndPalette()
|
||||
{
|
||||
setFont(vconfig.getMdEditFont());
|
||||
setPalette(vconfig.getMdEditPalette());
|
||||
m_cursorLineColor = vconfig.getEditorCurrentLineBackground();
|
||||
}
|
||||
|
||||
void VMdEdit::beginEdit()
|
||||
@ -548,9 +544,9 @@ void VMdEdit::handleEditStateChanged(KeyState p_state)
|
||||
{
|
||||
qDebug() << "edit state" << (int)p_state;
|
||||
if (p_state == KeyState::Normal) {
|
||||
m_cursorLineColor = QColor(g_vnote->getColorFromPalette(c_cursorLineColor));
|
||||
m_cursorLineColor = vconfig.getEditorCurrentLineBackground();
|
||||
} else {
|
||||
m_cursorLineColor = QColor(g_vnote->getColorFromPalette(c_cursorLineColorVim));
|
||||
m_cursorLineColor = vconfig.getEditorCurrentLineVimBackground();
|
||||
}
|
||||
highlightCurrentLine();
|
||||
}
|
||||
|
@ -80,9 +80,6 @@ private:
|
||||
QVector<QString> m_initImages;
|
||||
QVector<VHeader> m_headers;
|
||||
bool m_previewImage;
|
||||
|
||||
static const QString c_cursorLineColor;
|
||||
static const QString c_cursorLineColorVim;
|
||||
};
|
||||
|
||||
#endif // VMDEDIT_H
|
||||
|
@ -130,8 +130,10 @@ QVector<HighlightingStyle> VStyleParser::fetchMarkdownStyles(const QFont &baseFo
|
||||
return styles;
|
||||
}
|
||||
|
||||
void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const
|
||||
void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font,
|
||||
QMap<QString, QMap<QString, QString>> &styles) const
|
||||
{
|
||||
QString ruleKey;
|
||||
// editor
|
||||
pmh_style_attribute *editorStyles = markdownStyles->editor_styles;
|
||||
while (editorStyles) {
|
||||
@ -164,8 +166,29 @@ void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font) con
|
||||
|
||||
// editor-current-line
|
||||
pmh_style_attribute *curLineStyles = markdownStyles->editor_current_line_styles;
|
||||
if (curLineStyles) {
|
||||
qWarning() << "editor-current-line style is not supported";
|
||||
ruleKey = "editor-current-line";
|
||||
while (curLineStyles) {
|
||||
switch (curLineStyles->type) {
|
||||
case pmh_attr_type_background_color:
|
||||
{
|
||||
QString attrName(curLineStyles->name);
|
||||
QString value = QColorFromPmhAttr(curLineStyles->value->argb_color).name();
|
||||
styles[ruleKey][attrName] = value;
|
||||
break;
|
||||
}
|
||||
|
||||
case pmh_attr_type_other:
|
||||
{
|
||||
QString attrName(curLineStyles->name);
|
||||
QString value(curLineStyles->value->string);
|
||||
styles[ruleKey][attrName] = value;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
qWarning() << "unimplemented current line attr type:" << curLineStyles->type;
|
||||
}
|
||||
curLineStyles = curLineStyles->next;
|
||||
}
|
||||
|
||||
// editor-selection
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QPalette>
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include "hgmarkdownhighlighter.h"
|
||||
|
||||
extern "C" {
|
||||
@ -22,7 +23,9 @@ public:
|
||||
|
||||
void parseMarkdownStyle(const QString &styleStr);
|
||||
QVector<HighlightingStyle> fetchMarkdownStyles(const QFont &baseFont) const;
|
||||
void fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const;
|
||||
// @styles: [rule] -> ([attr] -> value).
|
||||
void fetchMarkdownEditorStyles(QPalette &palette, QFont &font,
|
||||
QMap<QString, QMap<QString, QString>> &styles) const;
|
||||
|
||||
private:
|
||||
QColor QColorFromPmhAttr(pmh_attr_argb_color *attr) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user