mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00

1. Support editor-current-line and editor-selection style in MDHL; 2. Support vim-background in editor-current-line;
571 lines
15 KiB
C++
571 lines
15 KiB
C++
#ifndef VCONFIGMANAGER_H
|
|
#define VCONFIGMANAGER_H
|
|
|
|
#include <QFont>
|
|
#include <QPalette>
|
|
#include <QVector>
|
|
#include <QSettings>
|
|
#include "vnotebook.h"
|
|
#include "hgmarkdownhighlighter.h"
|
|
#include "vmarkdownconverter.h"
|
|
|
|
class QJsonObject;
|
|
class QString;
|
|
|
|
enum MarkdownConverterType
|
|
{
|
|
Hoedown = 0,
|
|
Marked,
|
|
MarkdownIt
|
|
};
|
|
|
|
struct VColor
|
|
{
|
|
QString name;
|
|
QString rgb; // 'FFFFFF', ithout '#'
|
|
};
|
|
|
|
class VConfigManager
|
|
{
|
|
public:
|
|
VConfigManager();
|
|
~VConfigManager();
|
|
void initialize();
|
|
|
|
// Static helper functions
|
|
// Read config from the directory config json file into a QJsonObject
|
|
static QJsonObject readDirectoryConfig(const QString &path);
|
|
static bool writeDirectoryConfig(const QString &path, const QJsonObject &configJson);
|
|
static bool directoryConfigExist(const QString &path);
|
|
static bool deleteDirectoryConfig(const QString &path);
|
|
|
|
// Constants
|
|
static const QString orgName;
|
|
static const QString appName;
|
|
static const QString c_version;
|
|
|
|
inline QFont getMdEditFont() const;
|
|
|
|
inline QPalette getMdEditPalette() const;
|
|
|
|
inline QVector<HighlightingStyle> getMdHighlightingStyles() const;
|
|
|
|
inline QString getWelcomePagePath() const;
|
|
|
|
inline QString getTemplateCssUrl() const;
|
|
|
|
inline QFont getBaseEditFont() const;
|
|
inline QPalette getBaseEditPalette() const;
|
|
|
|
inline int getCurNotebookIndex() const;
|
|
inline void setCurNotebookIndex(int index);
|
|
|
|
inline void getNotebooks(QVector<VNotebook *> &p_notebooks, QObject *parent);
|
|
inline void setNotebooks(const QVector<VNotebook *> &p_notebooks);
|
|
|
|
inline hoedown_extensions getMarkdownExtensions() const;
|
|
inline MarkdownConverterType getMdConverterType() const;
|
|
inline void setMarkdownConverterType(MarkdownConverterType type);
|
|
|
|
inline int getTabStopWidth() const;
|
|
inline void setTabStopWidth(int tabStopWidth);
|
|
inline bool getIsExpandTab() const;
|
|
inline void setIsExpandTab(bool isExpandTab);
|
|
|
|
inline bool getHighlightCursorLine() const;
|
|
inline void setHighlightCursorLine(bool p_cursorLine);
|
|
|
|
inline bool getHighlightSelectedWord() const;
|
|
inline void setHighlightSelectedWord(bool p_selectedWord);
|
|
|
|
inline bool getHighlightSearchedWord() const;
|
|
inline void setHighlightSearchedWord(bool p_searchedWord);
|
|
|
|
inline const QVector<VColor> &getPredefinedColors() const;
|
|
|
|
inline const QString &getCurBackgroundColor() const;
|
|
inline void setCurBackgroundColor(const QString &colorName);
|
|
|
|
inline const QString &getCurRenderBackgroundColor() const;
|
|
inline void setCurRenderBackgroundColor(const QString &colorName);
|
|
|
|
inline bool getToolsDockChecked() const;
|
|
inline void setToolsDockChecked(bool p_checked);
|
|
|
|
inline const QByteArray &getMainWindowGeometry() const;
|
|
inline void setMainWindowGeometry(const QByteArray &p_geometry);
|
|
|
|
inline const QByteArray &getMainWindowState() const;
|
|
inline void setMainWindowState(const QByteArray &p_state);
|
|
|
|
inline const QByteArray &getMainSplitterState() const;
|
|
inline void setMainSplitterState(const QByteArray &p_state);
|
|
|
|
inline bool getFindCaseSensitive() const;
|
|
inline void setFindCaseSensitive(bool p_enabled);
|
|
|
|
inline bool getFindWholeWordOnly() const;
|
|
inline void setFindWholeWordOnly(bool p_enabled);
|
|
|
|
inline bool getFindRegularExpression() const;
|
|
inline void setFindRegularExpression(bool p_enabled);
|
|
|
|
inline bool getFindIncrementalSearch() const;
|
|
inline void setFindIncrementalSearch(bool p_enabled);
|
|
|
|
inline QString getLanguage() const;
|
|
inline void setLanguage(const QString &p_language);
|
|
|
|
inline bool getEnableMermaid() const;
|
|
inline void setEnableMermaid(bool p_enabled);
|
|
|
|
inline bool getEnableMathjax() const;
|
|
inline void setEnableMathjax(bool p_enabled);
|
|
|
|
inline qreal getWebZoomFactor() const;
|
|
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);
|
|
void setConfigToSettings(const QString §ion, const QString &key, const QVariant &value);
|
|
void readNotebookFromSettings(QVector<VNotebook *> &p_notebooks, QObject *parent);
|
|
void writeNotebookToSettings(const QVector<VNotebook *> &p_notebooks);
|
|
void readPredefinedColorsFromSettings();
|
|
// Update baseEditPalette according to curBackgroundColor
|
|
void updatePaletteColor();
|
|
|
|
int m_editorFontSize;
|
|
QFont baseEditFont;
|
|
QPalette baseEditPalette;
|
|
QFont mdEditFont;
|
|
QPalette mdEditPalette;
|
|
QVector<HighlightingStyle> mdHighlightingStyles;
|
|
QString welcomePagePath;
|
|
QString templateCssUrl;
|
|
int curNotebookIndex;
|
|
|
|
// Markdown Converter
|
|
hoedown_extensions markdownExtensions;
|
|
MarkdownConverterType mdConverterType;
|
|
|
|
// Num of spaces
|
|
int tabStopWidth;
|
|
// Expand tab to @tabStopWidth spaces
|
|
bool isExpandTab;
|
|
|
|
// Highlight current cursor line.
|
|
bool m_highlightCursorLine;
|
|
|
|
// Highlight selected word.
|
|
bool m_highlightSelectedWord;
|
|
|
|
// Highlight searched word.
|
|
bool m_highlightSearchedWord;
|
|
|
|
// App defined color
|
|
QVector<VColor> predefinedColors;
|
|
QString curBackgroundColor;
|
|
QString curRenderBackgroundColor;
|
|
|
|
bool m_toolsDockChecked;
|
|
|
|
QByteArray m_mainWindowGeometry;
|
|
QByteArray m_mainWindowState;
|
|
QByteArray m_mainSplitterState;
|
|
|
|
// Find/Replace dialog options
|
|
bool m_findCaseSensitive;
|
|
bool m_findWholeWordOnly;
|
|
bool m_findRegularExpression;
|
|
bool m_findIncrementalSearch;
|
|
|
|
// Language
|
|
QString m_language;
|
|
|
|
// Enable Mermaid.
|
|
bool m_enableMermaid;
|
|
|
|
// Enable Mathjax.
|
|
bool m_enableMathjax;
|
|
|
|
// 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
|
|
static const QString defaultConfigFilePath;
|
|
// QSettings for the user configuration
|
|
QSettings *userSettings;
|
|
// Qsettings for @defaultConfigFileName
|
|
QSettings *defaultSettings;
|
|
};
|
|
|
|
|
|
inline QFont VConfigManager::getMdEditFont() const
|
|
{
|
|
return mdEditFont;
|
|
}
|
|
|
|
inline QPalette VConfigManager::getMdEditPalette() const
|
|
{
|
|
return mdEditPalette;
|
|
}
|
|
|
|
inline QVector<HighlightingStyle> VConfigManager::getMdHighlightingStyles() const
|
|
{
|
|
return mdHighlightingStyles;
|
|
}
|
|
|
|
inline QString VConfigManager::getWelcomePagePath() const
|
|
{
|
|
return welcomePagePath;
|
|
}
|
|
|
|
inline QString VConfigManager::getTemplateCssUrl() const
|
|
{
|
|
return templateCssUrl;
|
|
}
|
|
|
|
inline QFont VConfigManager::getBaseEditFont() const
|
|
{
|
|
return baseEditFont;
|
|
}
|
|
|
|
inline QPalette VConfigManager::getBaseEditPalette() const
|
|
{
|
|
return baseEditPalette;
|
|
}
|
|
|
|
inline int VConfigManager::getCurNotebookIndex() const
|
|
{
|
|
return curNotebookIndex;
|
|
}
|
|
|
|
inline void VConfigManager::setCurNotebookIndex(int index)
|
|
{
|
|
if (index == curNotebookIndex) {
|
|
return;
|
|
}
|
|
curNotebookIndex = index;
|
|
setConfigToSettings("global", "current_notebook", index);
|
|
}
|
|
|
|
inline void VConfigManager::getNotebooks(QVector<VNotebook *> &p_notebooks, QObject *parent)
|
|
{
|
|
readNotebookFromSettings(p_notebooks, parent);
|
|
}
|
|
|
|
inline void VConfigManager::setNotebooks(const QVector<VNotebook *> &p_notebooks)
|
|
{
|
|
writeNotebookToSettings(p_notebooks);
|
|
}
|
|
|
|
inline hoedown_extensions VConfigManager::getMarkdownExtensions() const
|
|
{
|
|
return markdownExtensions;
|
|
}
|
|
|
|
inline MarkdownConverterType VConfigManager::getMdConverterType() const
|
|
{
|
|
return mdConverterType;
|
|
}
|
|
|
|
inline void VConfigManager::setMarkdownConverterType(MarkdownConverterType type)
|
|
{
|
|
if (mdConverterType == type) {
|
|
return;
|
|
}
|
|
mdConverterType = type;
|
|
setConfigToSettings("global", "markdown_converter", type);
|
|
}
|
|
|
|
inline int VConfigManager::getTabStopWidth() const
|
|
{
|
|
return tabStopWidth;
|
|
}
|
|
|
|
inline bool VConfigManager::getIsExpandTab() const
|
|
{
|
|
return isExpandTab;
|
|
}
|
|
|
|
inline void VConfigManager::setTabStopWidth(int tabStopWidth)
|
|
{
|
|
if (tabStopWidth == this->tabStopWidth) {
|
|
return;
|
|
}
|
|
this->tabStopWidth = tabStopWidth;
|
|
setConfigToSettings("global", "tab_stop_width", tabStopWidth);
|
|
}
|
|
|
|
inline void VConfigManager::setIsExpandTab(bool isExpandTab)
|
|
{
|
|
if (isExpandTab == this->isExpandTab) {
|
|
return;
|
|
}
|
|
this->isExpandTab = 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 bool VConfigManager::getHighlightSelectedWord() const
|
|
{
|
|
return m_highlightSelectedWord;
|
|
}
|
|
|
|
inline void VConfigManager::setHighlightSelectedWord(bool p_selectedWord)
|
|
{
|
|
if (p_selectedWord == m_highlightSelectedWord) {
|
|
return;
|
|
}
|
|
m_highlightSelectedWord = p_selectedWord;
|
|
setConfigToSettings("global", "highlight_selected_word",
|
|
m_highlightSelectedWord);
|
|
}
|
|
|
|
inline bool VConfigManager::getHighlightSearchedWord() const
|
|
{
|
|
return m_highlightSearchedWord;
|
|
}
|
|
|
|
inline void VConfigManager::setHighlightSearchedWord(bool p_searchedWord)
|
|
{
|
|
if (p_searchedWord == m_highlightSearchedWord) {
|
|
return;
|
|
}
|
|
m_highlightSearchedWord = p_searchedWord;
|
|
setConfigToSettings("global", "highlight_searched_word",
|
|
m_highlightSearchedWord);
|
|
}
|
|
|
|
inline const QVector<VColor>& VConfigManager::getPredefinedColors() const
|
|
{
|
|
return predefinedColors;
|
|
}
|
|
|
|
inline const QString& VConfigManager::getCurBackgroundColor() const
|
|
{
|
|
return curBackgroundColor;
|
|
}
|
|
|
|
inline void VConfigManager::setCurBackgroundColor(const QString &colorName)
|
|
{
|
|
if (curBackgroundColor == colorName) {
|
|
return;
|
|
}
|
|
curBackgroundColor = colorName;
|
|
setConfigToSettings("global", "current_background_color",
|
|
curBackgroundColor);
|
|
updatePaletteColor();
|
|
}
|
|
|
|
inline const QString& VConfigManager::getCurRenderBackgroundColor() const
|
|
{
|
|
return curRenderBackgroundColor;
|
|
}
|
|
|
|
inline void VConfigManager::setCurRenderBackgroundColor(const QString &colorName)
|
|
{
|
|
if (curRenderBackgroundColor == colorName) {
|
|
return;
|
|
}
|
|
curRenderBackgroundColor = colorName;
|
|
setConfigToSettings("global", "current_render_background_color",
|
|
curRenderBackgroundColor);
|
|
}
|
|
|
|
inline bool VConfigManager::getToolsDockChecked() const
|
|
{
|
|
return m_toolsDockChecked;
|
|
}
|
|
|
|
inline void VConfigManager::setToolsDockChecked(bool p_checked)
|
|
{
|
|
m_toolsDockChecked = p_checked;
|
|
setConfigToSettings("session", "tools_dock_checked",
|
|
m_toolsDockChecked);
|
|
}
|
|
|
|
inline const QByteArray& VConfigManager::getMainWindowGeometry() const
|
|
{
|
|
return m_mainWindowGeometry;
|
|
}
|
|
|
|
inline void VConfigManager::setMainWindowGeometry(const QByteArray &p_geometry)
|
|
{
|
|
m_mainWindowGeometry = p_geometry;
|
|
setConfigToSettings("session", "main_window_geometry",
|
|
m_mainWindowGeometry);
|
|
}
|
|
|
|
inline const QByteArray& VConfigManager::getMainWindowState() const
|
|
{
|
|
return m_mainWindowState;
|
|
}
|
|
|
|
inline void VConfigManager::setMainWindowState(const QByteArray &p_state)
|
|
{
|
|
m_mainWindowState = p_state;
|
|
setConfigToSettings("session", "main_window_state",
|
|
m_mainWindowState);
|
|
}
|
|
|
|
inline const QByteArray& VConfigManager::getMainSplitterState() const
|
|
{
|
|
return m_mainSplitterState;
|
|
}
|
|
|
|
inline void VConfigManager::setMainSplitterState(const QByteArray &p_state)
|
|
{
|
|
m_mainSplitterState = p_state;
|
|
setConfigToSettings("session", "main_splitter_state", m_mainSplitterState);
|
|
}
|
|
|
|
inline bool VConfigManager::getFindCaseSensitive() const
|
|
{
|
|
return m_findCaseSensitive;
|
|
}
|
|
|
|
inline void VConfigManager::setFindCaseSensitive(bool p_enabled)
|
|
{
|
|
if (m_findCaseSensitive == p_enabled) {
|
|
return;
|
|
}
|
|
m_findCaseSensitive = p_enabled;
|
|
setConfigToSettings("global", "find_case_sensitive", m_findCaseSensitive);
|
|
}
|
|
|
|
inline bool VConfigManager::getFindWholeWordOnly() const
|
|
{
|
|
return m_findWholeWordOnly;
|
|
}
|
|
|
|
inline void VConfigManager::setFindWholeWordOnly(bool p_enabled)
|
|
{
|
|
if (m_findWholeWordOnly == p_enabled) {
|
|
return;
|
|
}
|
|
m_findWholeWordOnly = p_enabled;
|
|
setConfigToSettings("global", "find_whole_word_only", m_findWholeWordOnly);
|
|
}
|
|
|
|
inline bool VConfigManager::getFindRegularExpression() const
|
|
{
|
|
return m_findRegularExpression;
|
|
}
|
|
|
|
inline void VConfigManager::setFindRegularExpression(bool p_enabled)
|
|
{
|
|
if (m_findRegularExpression == p_enabled) {
|
|
return;
|
|
}
|
|
m_findRegularExpression = p_enabled;
|
|
setConfigToSettings("global", "find_regular_expression",
|
|
m_findRegularExpression);
|
|
}
|
|
|
|
inline bool VConfigManager::getFindIncrementalSearch() const
|
|
{
|
|
return m_findIncrementalSearch;
|
|
}
|
|
|
|
inline void VConfigManager::setFindIncrementalSearch(bool p_enabled)
|
|
{
|
|
if (m_findIncrementalSearch == p_enabled) {
|
|
return;
|
|
}
|
|
m_findIncrementalSearch = p_enabled;
|
|
setConfigToSettings("global", "find_incremental_search",
|
|
m_findIncrementalSearch);
|
|
}
|
|
|
|
inline QString VConfigManager::getLanguage() const
|
|
{
|
|
return m_language;
|
|
}
|
|
|
|
inline void VConfigManager::setLanguage(const QString &p_language)
|
|
{
|
|
if (m_language == p_language) {
|
|
return;
|
|
}
|
|
m_language = p_language;
|
|
setConfigToSettings("global", "language",
|
|
m_language);
|
|
}
|
|
|
|
inline bool VConfigManager::getEnableMermaid() const
|
|
{
|
|
return m_enableMermaid;
|
|
}
|
|
|
|
inline void VConfigManager::setEnableMermaid(bool p_enabled)
|
|
{
|
|
if (m_enableMermaid == p_enabled) {
|
|
return;
|
|
}
|
|
m_enableMermaid = p_enabled;
|
|
setConfigToSettings("global", "enable_mermaid", m_enableMermaid);
|
|
}
|
|
|
|
inline bool VConfigManager::getEnableMathjax() const
|
|
{
|
|
return m_enableMathjax;
|
|
}
|
|
|
|
inline void VConfigManager::setEnableMathjax(bool p_enabled)
|
|
{
|
|
if (m_enableMathjax == p_enabled) {
|
|
return;
|
|
}
|
|
m_enableMathjax = p_enabled;
|
|
setConfigToSettings("global", "enable_mathjax", m_enableMathjax);
|
|
}
|
|
|
|
inline qreal VConfigManager::getWebZoomFactor() const
|
|
{
|
|
return m_webZoomFactor;
|
|
}
|
|
|
|
inline bool VConfigManager::isCustomWebZoomFactor()
|
|
{
|
|
qreal factorFromIni = getConfigFromSettings("global", "web_zoom_factor").toReal();
|
|
// -1 indicates let system automatically calculate the factor.
|
|
return factorFromIni > 0;
|
|
}
|
|
|
|
inline QString VConfigManager::getEditorCurrentLineBackground() const
|
|
{
|
|
return m_editorCurrentLineBackground;
|
|
}
|
|
|
|
inline QString VConfigManager::getEditorCurrentLineVimBackground() const
|
|
{
|
|
return m_editorCurrentLineVimBackground;
|
|
}
|
|
#endif // VCONFIGMANAGER_H
|