support foreground for selected/searched word in MDHL

This commit is contained in:
Le Tan 2017-12-25 19:43:40 +08:00
parent be1827b0c4
commit b0c5961552
7 changed files with 130 additions and 52 deletions

View File

@ -21,13 +21,17 @@ trailing-space: 636d81
line-number-background: 2c313a
line-number-foreground: 5c6370
# [VNote] Style for selected word highlight
selected-word-background: 454bb2
selected-word-foreground: 222222
selected-word-background: dfdf00
# [VNote] Style for searched word highlight
searched-word-background: 424956
searched-word-foreground: 222222
searched-word-background: 4db6ac
# [VNote] Style for searched word under cursor highlight
searched-word-cursor-background: 596173
searched-word-cursor-foreground: 222222
searched-word-cursor-background: 66bb6a
# [VNote] Style for incremental searched word highlight
incremental-searched-word-background: 596173
incremental-searched-word-foreground: 222222
incremental-searched-word-background: ce93d8
# [VNote] Style for color column in fenced code block
color-column-background: c9302c
color-column-foreground: eeeeee

View File

@ -21,12 +21,16 @@ trailing-space: a8a8a8
line-number-background: eaeaea
line-number-foreground: 424242
# [VNote] Style for selected word highlight
selected-word-foreground: 222222
selected-word-background: dfdf00
# [VNote] Style for searched word highlight
searched-word-foreground: 222222
searched-word-background: 4db6ac
# [VNote] Style for searched word under cursor highlight
searched-word-cursor-foreground: 222222
searched-word-cursor-background: 66bb6a
# [VNote] Style for incremental searched word highlight
incremental-searched-word-foreground: 222222
incremental-searched-word-background: ce93d8
# [VNote] Style for color column in fenced code block
color-column-background: dd0000

View File

@ -20,12 +20,16 @@ trailing-space: a8a8a8
line-number-background: f5f5f5
line-number-foreground: 424242
# [VNote] Style for selected word highlight
selected-word-foreground: 222222
selected-word-background: dfdf00
# [VNote] Style for searched word highlight
searched-word-foreground: 222222
searched-word-background: 4db6ac
# [VNote] Style for searched word under cursor highlight
searched-word-cursor-foreground: 222222
searched-word-cursor-background: 66bb6a
# [VNote] Style for incremental searched word highlight
incremental-searched-word-foreground: 222222
incremental-searched-word-background: ce93d8
# [VNote] Style for color column in fenced code block
color-column-background: dd0000

View File

@ -548,23 +548,7 @@ QString VConfigManager::getLogFilePath() const
void VConfigManager::updateMarkdownEditStyle()
{
static const QString defaultCurrentLineBackground = "#C5CAE9";
static const QString defaultVimNormalBg = "#BCBCBC";
static const QString defaultVimInsertBg = "#C5CAE9";
static const QString defaultVimVisualBg = "#90CAF9";
static const QString defaultVimReplaceBg = "#F8BBD0";
static const QString defaultTrailingSpaceBg = "#A8A8A8";
static const QString defaultSelectedWordBg = "#DFDF00";
static const QString defaultSearchedWordBg = "#81C784";
static const QString defaultSearchedWordCursorBg = "#4DB6AC";
static const QString defaultIncrementalSearchedWordBg = "#CE93D8";
static const QString defaultLineNumberBg = "#BDBDBD";
static const QString defaultLineNumberFg = "#424242";
static const QString defaultColorColumnBg = "#DD0000";
static const QString defaultColorColumnFg = "#FFFF00";
static const QString defaultPreviewImageLineFg = "#9575CD";
static const QString defaultColor = "#00897B";
// Read style file .mdhl
QString file(getEditorStyleFile());
@ -588,11 +572,11 @@ void VConfigManager::updateMarkdownEditStyle()
mdHighlightingStyles = parser.fetchMarkdownStyles(mdEditFont);
m_codeBlockStyles = parser.fetchCodeBlockStyles(mdEditFont);
m_editorCurrentLineBg = defaultCurrentLineBackground;
m_editorVimInsertBg = defaultVimInsertBg;
m_editorVimNormalBg = defaultVimNormalBg;
m_editorVimVisualBg = defaultVimVisualBg;
m_editorVimReplaceBg = defaultVimReplaceBg;
m_editorCurrentLineBg = defaultColor;
m_editorVimInsertBg = defaultColor;
m_editorVimNormalBg = defaultColor;
m_editorVimVisualBg = defaultColor;
m_editorVimReplaceBg = defaultColor;
auto editorCurrentLineIt = styles.find("editor-current-line");
if (editorCurrentLineIt != styles.end()) {
@ -623,16 +607,21 @@ void VConfigManager::updateMarkdownEditStyle()
}
}
m_editorTrailingSpaceBg = defaultTrailingSpaceBg;
m_editorSelectedWordBg = defaultSelectedWordBg;
m_editorSearchedWordBg = defaultSearchedWordBg;
m_editorSearchedWordCursorBg = defaultSearchedWordCursorBg;
m_editorIncrementalSearchedWordBg = defaultIncrementalSearchedWordBg;
m_editorLineNumberBg = defaultLineNumberBg;
m_editorLineNumberFg = defaultLineNumberFg;
m_editorColorColumnBg = defaultColorColumnBg;
m_editorColorColumnFg = defaultColorColumnFg;
m_editorPreviewImageLineFg = defaultPreviewImageLineFg;
m_editorTrailingSpaceBg = defaultColor;
m_editorSelectedWordFg = defaultColor;
m_editorSelectedWordBg = defaultColor;
m_editorSearchedWordFg = defaultColor;
m_editorSearchedWordBg = defaultColor;
m_editorSearchedWordCursorFg = defaultColor;
m_editorSearchedWordCursorBg = defaultColor;
m_editorIncrementalSearchedWordFg = defaultColor;
m_editorIncrementalSearchedWordBg = defaultColor;
m_editorLineNumberBg = defaultColor;
m_editorLineNumberFg = defaultColor;
m_editorColorColumnBg = defaultColor;
m_editorColorColumnFg = defaultColor;
m_editorPreviewImageLineFg = defaultColor;
auto editorIt = styles.find("editor");
if (editorIt != styles.end()) {
auto it = editorIt->find("trailing-space");
@ -650,21 +639,41 @@ void VConfigManager::updateMarkdownEditStyle()
m_editorLineNumberFg = "#" + *it;
}
it = editorIt->find("selected-word-foreground");
if (it != editorIt->end()) {
m_editorSelectedWordFg = "#" + *it;
}
it = editorIt->find("selected-word-background");
if (it != editorIt->end()) {
m_editorSelectedWordBg = "#" + *it;
}
it = editorIt->find("searched-word-foreground");
if (it != editorIt->end()) {
m_editorSearchedWordFg = "#" + *it;
}
it = editorIt->find("searched-word-background");
if (it != editorIt->end()) {
m_editorSearchedWordBg = "#" + *it;
}
it = editorIt->find("searched-word-cursor-foreground");
if (it != editorIt->end()) {
m_editorSearchedWordCursorFg = "#" + *it;
}
it = editorIt->find("searched-word-cursor-background");
if (it != editorIt->end()) {
m_editorSearchedWordCursorBg = "#" + *it;
}
it = editorIt->find("incremental-searched-word-foreground");
if (it != editorIt->end()) {
m_editorIncrementalSearchedWordFg = "#" + *it;
}
it = editorIt->find("incremental-searched-word-background");
if (it != editorIt->end()) {
m_editorIncrementalSearchedWordBg = "#" + *it;

View File

@ -199,10 +199,19 @@ public:
bool isCustomWebZoomFactor();
const QString &getEditorCurrentLineBg() const;
const QString &getEditorTrailingSpaceBg() const;
const QString &getEditorSelectedWordFg() const;
const QString &getEditorSelectedWordBg() const;
const QString &getEditorSearchedWordFg() const;
const QString &getEditorSearchedWordBg() const;
const QString &getEditorSearchedWordCursorFg() const;
const QString &getEditorSearchedWordCursorBg() const;
const QString &getEditorIncrementalSearchedWordFg() const;
const QString &getEditorIncrementalSearchedWordBg() const;
const QString &getEditorVimNormalBg() const;
@ -578,16 +587,24 @@ private:
// Trailing space background color in editor.
QString m_editorTrailingSpaceBg;
// Background color of selected word in editor.
// Foreground and background color of selected word in editor.
QString m_editorSelectedWordFg;
QString m_editorSelectedWordBg;
// Background color of searched word in editor.
// Foreground and background color of searched word in editor.
QString m_editorSearchedWordFg;
QString m_editorSearchedWordBg;
// Background color of searched word under cursor in editor.
// Foreground and background color of searched word under cursor in editor.
QString m_editorSearchedWordCursorFg;
QString m_editorSearchedWordCursorBg;
// Background color of incremental searched word in editor.
// Foreground and background color of incremental searched word in editor.
QString m_editorIncrementalSearchedWordFg;
QString m_editorIncrementalSearchedWordBg;
// Enable colde block syntax highlight.
@ -1260,21 +1277,41 @@ inline const QString &VConfigManager::getEditorTrailingSpaceBg() const
return m_editorTrailingSpaceBg;
}
inline const QString &VConfigManager::getEditorSelectedWordFg() const
{
return m_editorSelectedWordFg;
}
inline const QString &VConfigManager::getEditorSelectedWordBg() const
{
return m_editorSelectedWordBg;
}
inline const QString &VConfigManager::getEditorSearchedWordFg() const
{
return m_editorSearchedWordFg;
}
inline const QString &VConfigManager::getEditorSearchedWordBg() const
{
return m_editorSearchedWordBg;
}
inline const QString &VConfigManager::getEditorSearchedWordCursorFg() const
{
return m_editorSearchedWordCursorFg;
}
inline const QString &VConfigManager::getEditorSearchedWordCursorBg() const
{
return m_editorSearchedWordCursorBg;
}
inline const QString &VConfigManager::getEditorIncrementalSearchedWordFg() const
{
return m_editorIncrementalSearchedWordFg;
}
inline const QString &VConfigManager::getEditorIncrementalSearchedWordBg() const
{
return m_editorIncrementalSearchedWordBg;

View File

@ -37,10 +37,18 @@ void VEditor::init()
m_document = documentW();
m_selectedWordColor = QColor(g_config->getEditorSelectedWordBg());
m_searchedWordColor = QColor(g_config->getEditorSearchedWordBg());
m_searchedWordCursorColor = QColor(g_config->getEditorSearchedWordCursorBg());
m_incrementalSearchedWordColor = QColor(g_config->getEditorIncrementalSearchedWordBg());
m_selectedWordFg = QColor(g_config->getEditorSelectedWordFg());
m_selectedWordBg = QColor(g_config->getEditorSelectedWordBg());
m_searchedWordFg = QColor(g_config->getEditorSearchedWordFg());
m_searchedWordBg = QColor(g_config->getEditorSearchedWordBg());
m_searchedWordCursorFg = QColor(g_config->getEditorSearchedWordCursorFg());
m_searchedWordCursorBg = QColor(g_config->getEditorSearchedWordCursorBg());
m_incrementalSearchedWordFg = QColor(g_config->getEditorIncrementalSearchedWordFg());
m_incrementalSearchedWordBg = QColor(g_config->getEditorIncrementalSearchedWordBg());
m_trailingSpaceColor = QColor(g_config->getEditorTrailingSpaceBg());
QPixmap wrapPixmap(":/resources/icons/search_wrap.svg");
@ -314,7 +322,8 @@ void VEditor::highlightSelectedWord()
}
QTextCharFormat format;
format.setBackground(m_selectedWordColor);
format.setForeground(m_selectedWordFg);
format.setBackground(m_selectedWordBg);
highlightTextAll(text,
FindOption::CaseSensitive,
SelectionId::SelectedWord,
@ -494,7 +503,8 @@ void VEditor::highlightIncrementalSearchedWord(const QTextCursor &p_cursor)
selects.clear();
QTextEdit::ExtraSelection select;
select.format.setBackground(m_incrementalSearchedWordColor);
select.format.setForeground(m_incrementalSearchedWordFg);
select.format.setBackground(m_incrementalSearchedWordBg);
select.cursor = p_cursor;
selects.append(select);
@ -657,7 +667,8 @@ void VEditor::highlightSearchedWord(const QString &p_text, uint p_options)
}
QTextCharFormat format;
format.setBackground(m_searchedWordColor);
format.setForeground(m_searchedWordFg);
format.setBackground(m_searchedWordBg);
highlightTextAll(p_text, p_options, SelectionId::SearchedKeyword, format);
}
@ -675,7 +686,8 @@ void VEditor::highlightSearchedWordUnderCursor(const QTextCursor &p_cursor)
selects.clear();
QTextEdit::ExtraSelection select;
select.format.setBackground(m_searchedWordCursorColor);
select.format.setForeground(m_searchedWordCursorFg);
select.format.setBackground(m_searchedWordCursorBg);
select.cursor = p_cursor;
selects.append(select);

View File

@ -276,10 +276,18 @@ private:
// Selections are indexed by SelectionId.
QVector<QList<QTextEdit::ExtraSelection> > m_extraSelections;
QColor m_selectedWordColor;
QColor m_searchedWordColor;
QColor m_searchedWordCursorColor;
QColor m_incrementalSearchedWordColor;
QColor m_selectedWordFg;
QColor m_selectedWordBg;
QColor m_searchedWordFg;
QColor m_searchedWordBg;
QColor m_searchedWordCursorFg;
QColor m_searchedWordCursorBg;
QColor m_incrementalSearchedWordFg;
QColor m_incrementalSearchedWordBg;
QColor m_trailingSpaceColor;
// Timer for extra selections highlight.