diff --git a/src/resources/styles/default.mdhl b/src/resources/styles/default.mdhl index 5632aa00..853721b4 100644 --- a/src/resources/styles/default.mdhl +++ b/src/resources/styles/default.mdhl @@ -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 diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 48d232a4..36b7fb1c 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -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> 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() diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index aac5d9bb..89a3b0a6 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -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 diff --git a/src/vmdedit.cpp b/src/vmdedit.cpp index 5a0c76e7..e67164ef 100644 --- a/src/vmdedit.cpp +++ b/src/vmdedit.cpp @@ -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(); } diff --git a/src/vmdedit.h b/src/vmdedit.h index 7143c93e..b72db889 100644 --- a/src/vmdedit.h +++ b/src/vmdedit.h @@ -80,9 +80,6 @@ private: QVector m_initImages; QVector m_headers; bool m_previewImage; - - static const QString c_cursorLineColor; - static const QString c_cursorLineColorVim; }; #endif // VMDEDIT_H diff --git a/src/vstyleparser.cpp b/src/vstyleparser.cpp index da6cdf14..524a381d 100644 --- a/src/vstyleparser.cpp +++ b/src/vstyleparser.cpp @@ -130,8 +130,10 @@ QVector VStyleParser::fetchMarkdownStyles(const QFont &baseFo return styles; } -void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const +void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font, + QMap> &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 diff --git a/src/vstyleparser.h b/src/vstyleparser.h index bd05aab3..e54e3a3a 100644 --- a/src/vstyleparser.h +++ b/src/vstyleparser.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "hgmarkdownhighlighter.h" extern "C" { @@ -22,7 +23,9 @@ public: void parseMarkdownStyle(const QString &styleStr); QVector fetchMarkdownStyles(const QFont &baseFont) const; - void fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const; + // @styles: [rule] -> ([attr] -> value). + void fetchMarkdownEditorStyles(QPalette &palette, QFont &font, + QMap> &styles) const; private: QColor QColorFromPmhAttr(pmh_attr_argb_color *attr) const;