mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
highlight curren cursor line
Add configuration "highlight_cursor_line" in vnote.ini. Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
76bd2c7d64
commit
3b442f55a9
@ -7,6 +7,7 @@ template_css_url=qrc:/resources/markdown.css
|
|||||||
current_notebook=0
|
current_notebook=0
|
||||||
tab_stop_width=4
|
tab_stop_width=4
|
||||||
is_expand_tab=1
|
is_expand_tab=1
|
||||||
|
highlight_cursor_line=1
|
||||||
current_background_color=System
|
current_background_color=System
|
||||||
current_render_background_color=System
|
current_render_background_color=System
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ void VConfigManager::initialize()
|
|||||||
|
|
||||||
tabStopWidth = getConfigFromSettings("global", "tab_stop_width").toInt();
|
tabStopWidth = getConfigFromSettings("global", "tab_stop_width").toInt();
|
||||||
isExpandTab = getConfigFromSettings("global", "is_expand_tab").toBool();
|
isExpandTab = getConfigFromSettings("global", "is_expand_tab").toBool();
|
||||||
|
m_highlightCursorLine = getConfigFromSettings("global", "highlight_cursor_line").toBool();
|
||||||
|
|
||||||
readPredefinedColorsFromSettings();
|
readPredefinedColorsFromSettings();
|
||||||
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
||||||
|
@ -76,6 +76,9 @@ public:
|
|||||||
inline bool getIsExpandTab() const;
|
inline bool getIsExpandTab() const;
|
||||||
inline void setIsExpandTab(bool isExpandTab);
|
inline void setIsExpandTab(bool isExpandTab);
|
||||||
|
|
||||||
|
inline bool getHighlightCursorLine() const;
|
||||||
|
inline void setHighlightCursorLine(bool p_cursorLine);
|
||||||
|
|
||||||
inline const QVector<VColor> &getPredefinedColors() const;
|
inline const QVector<VColor> &getPredefinedColors() const;
|
||||||
|
|
||||||
inline const QString &getCurBackgroundColor() const;
|
inline const QString &getCurBackgroundColor() const;
|
||||||
@ -124,6 +127,9 @@ private:
|
|||||||
// Expand tab to @tabStopWidth spaces
|
// Expand tab to @tabStopWidth spaces
|
||||||
bool isExpandTab;
|
bool isExpandTab;
|
||||||
|
|
||||||
|
// Highlight current cursor line.
|
||||||
|
bool m_highlightCursorLine;
|
||||||
|
|
||||||
// App defined color
|
// App defined color
|
||||||
QVector<VColor> predefinedColors;
|
QVector<VColor> predefinedColors;
|
||||||
QString curBackgroundColor;
|
QString curBackgroundColor;
|
||||||
@ -266,6 +272,20 @@ inline void VConfigManager::setIsExpandTab(bool isExpandTab)
|
|||||||
setConfigToSettings("global", "is_expand_tab", this->isExpandTab);
|
setConfigToSettings("global", "is_expand_tab", this->isExpandTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool VConfigManager::getHighlightCursorLine() const
|
||||||
|
{
|
||||||
|
return m_highlightCursorLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VConfigManager::setHighlightCursorLine(bool p_cursorLine)
|
||||||
|
{
|
||||||
|
if (p_cursorLine == m_highlightCursorLine) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_highlightCursorLine = p_cursorLine;
|
||||||
|
setConfigToSettings("global", "highlight_cursor_line", m_highlightCursorLine);
|
||||||
|
}
|
||||||
|
|
||||||
inline const QVector<VColor>& VConfigManager::getPredefinedColors() const
|
inline const QVector<VColor>& VConfigManager::getPredefinedColors() const
|
||||||
{
|
{
|
||||||
return predefinedColors;
|
return predefinedColors;
|
||||||
|
@ -13,12 +13,15 @@
|
|||||||
|
|
||||||
extern VConfigManager vconfig;
|
extern VConfigManager vconfig;
|
||||||
|
|
||||||
|
VNote *g_vnote;
|
||||||
|
|
||||||
VMainWindow::VMainWindow(QWidget *parent)
|
VMainWindow::VMainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
|
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
|
||||||
// Must be called before those who uses VConfigManager
|
// Must be called before those who uses VConfigManager
|
||||||
vnote = new VNote(this);
|
vnote = new VNote(this);
|
||||||
|
g_vnote = vnote;
|
||||||
vnote->initPalette(palette());
|
vnote->initPalette(palette());
|
||||||
initPredefinedColorPixmaps();
|
initPredefinedColorPixmaps();
|
||||||
setupUI();
|
setupUI();
|
||||||
@ -210,6 +213,12 @@ void VMainWindow::initActions()
|
|||||||
connect(backgroundColorAct, &QActionGroup::triggered,
|
connect(backgroundColorAct, &QActionGroup::triggered,
|
||||||
this, &VMainWindow::setEditorBackgroundColor);
|
this, &VMainWindow::setEditorBackgroundColor);
|
||||||
|
|
||||||
|
m_cursorLineAct = new QAction(tr("Highlight Cursor Line"), this);
|
||||||
|
m_cursorLineAct->setStatusTip(tr("Highlight current cursor line"));
|
||||||
|
m_cursorLineAct->setCheckable(true);
|
||||||
|
connect(m_cursorLineAct, &QAction::triggered,
|
||||||
|
this, &VMainWindow::changeHighlightCursorLine);
|
||||||
|
|
||||||
renderBackgroundAct = new QActionGroup(this);
|
renderBackgroundAct = new QActionGroup(this);
|
||||||
connect(renderBackgroundAct, &QActionGroup::triggered,
|
connect(renderBackgroundAct, &QActionGroup::triggered,
|
||||||
this, &VMainWindow::setRenderBackgroundColor);
|
this, &VMainWindow::setRenderBackgroundColor);
|
||||||
@ -348,6 +357,12 @@ void VMainWindow::initMenuBar()
|
|||||||
qWarning() << "unsupported tab stop width" << tabStopWidth << "in config";
|
qWarning() << "unsupported tab stop width" << tabStopWidth << "in config";
|
||||||
}
|
}
|
||||||
initEditorBackgroundMenu(editMenu);
|
initEditorBackgroundMenu(editMenu);
|
||||||
|
editMenu->addAction(m_cursorLineAct);
|
||||||
|
if (vconfig.getHighlightCursorLine()) {
|
||||||
|
m_cursorLineAct->setChecked(true);
|
||||||
|
} else {
|
||||||
|
m_cursorLineAct->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
// Markdown Menu
|
// Markdown Menu
|
||||||
QMenu *converterMenu = markdownMenu->addMenu(tr("&Converter"));
|
QMenu *converterMenu = markdownMenu->addMenu(tr("&Converter"));
|
||||||
@ -446,6 +461,11 @@ void VMainWindow::changeExpandTab(bool checked)
|
|||||||
vconfig.setIsExpandTab(checked);
|
vconfig.setIsExpandTab(checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::changeHighlightCursorLine(bool p_checked)
|
||||||
|
{
|
||||||
|
vconfig.setHighlightCursorLine(p_checked);
|
||||||
|
}
|
||||||
|
|
||||||
void VMainWindow::setTabStopWidth(QAction *action)
|
void VMainWindow::setTabStopWidth(QAction *action)
|
||||||
{
|
{
|
||||||
if (!action) {
|
if (!action) {
|
||||||
|
@ -45,6 +45,7 @@ private slots:
|
|||||||
void setTabStopWidth(QAction *action);
|
void setTabStopWidth(QAction *action);
|
||||||
void setEditorBackgroundColor(QAction *action);
|
void setEditorBackgroundColor(QAction *action);
|
||||||
void setRenderBackgroundColor(QAction *action);
|
void setRenderBackgroundColor(QAction *action);
|
||||||
|
void changeHighlightCursorLine(bool p_checked);
|
||||||
void handleCurTabStatusChanged(const VFile *p_file, const VEditTab *p_editTab, bool p_editMode);
|
void handleCurTabStatusChanged(const VFile *p_file, const VEditTab *p_editTab, bool p_editMode);
|
||||||
void onePanelView();
|
void onePanelView();
|
||||||
void twoPanelView();
|
void twoPanelView();
|
||||||
@ -122,6 +123,7 @@ private:
|
|||||||
QAction *fourSpaceTabAct;
|
QAction *fourSpaceTabAct;
|
||||||
QAction *eightSpaceTabAct;
|
QAction *eightSpaceTabAct;
|
||||||
QActionGroup *backgroundColorAct;
|
QActionGroup *backgroundColorAct;
|
||||||
|
QAction *m_cursorLineAct;
|
||||||
QActionGroup *renderBackgroundAct;
|
QActionGroup *renderBackgroundAct;
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
|
|
||||||
extern VConfigManager vconfig;
|
extern VConfigManager vconfig;
|
||||||
|
extern VNote *g_vnote;
|
||||||
|
|
||||||
enum ImageProperty { ImagePath = 1 };
|
enum ImageProperty { ImagePath = 1 };
|
||||||
|
|
||||||
@ -27,6 +28,10 @@ VMdEdit::VMdEdit(VFile *p_file, QWidget *p_parent)
|
|||||||
|
|
||||||
connect(this, &VMdEdit::cursorPositionChanged,
|
connect(this, &VMdEdit::cursorPositionChanged,
|
||||||
this, &VMdEdit::updateCurHeader);
|
this, &VMdEdit::updateCurHeader);
|
||||||
|
if (vconfig.getHighlightCursorLine()) {
|
||||||
|
connect(this, &VMdEdit::cursorPositionChanged,
|
||||||
|
this, &VMdEdit::highlightCurrentLine);
|
||||||
|
}
|
||||||
|
|
||||||
m_editOps->updateTabSettings();
|
m_editOps->updateTabSettings();
|
||||||
updateFontAndPalette();
|
updateFontAndPalette();
|
||||||
@ -452,3 +457,20 @@ int VMdEdit::removeObjectReplacementLine(QString &p_text, int p_index) const
|
|||||||
p_text.remove(prevLineIdx + 1, p_index - prevLineIdx + 1);
|
p_text.remove(prevLineIdx + 1, p_index - prevLineIdx + 1);
|
||||||
return prevLineIdx;
|
return prevLineIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMdEdit::highlightCurrentLine()
|
||||||
|
{
|
||||||
|
static QColor lineColor = QColor(g_vnote->getColorFromPalette("Indigo1"));
|
||||||
|
QList<QTextEdit::ExtraSelection> extraSelects;
|
||||||
|
|
||||||
|
if (!isReadOnly()) {
|
||||||
|
QTextEdit::ExtraSelection select;
|
||||||
|
|
||||||
|
select.format.setBackground(lineColor);
|
||||||
|
select.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
|
select.cursor = textCursor();
|
||||||
|
select.cursor.clearSelection();
|
||||||
|
extraSelects.append(select);
|
||||||
|
}
|
||||||
|
setExtraSelections(extraSelects);
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ private slots:
|
|||||||
void updateCurHeader();
|
void updateCurHeader();
|
||||||
// Update block list containing image links.
|
// Update block list containing image links.
|
||||||
void updateImageBlocks(QSet<int> p_imageBlocks);
|
void updateImageBlocks(QSet<int> p_imageBlocks);
|
||||||
|
void highlightCurrentLine();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user