mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 14:29:54 +08:00
change predefined_colors to custom_colors
This commit is contained in:
parent
488fe2cc65
commit
be1827b0c4
@ -83,9 +83,9 @@ editor_line_number=0
|
|||||||
; 1: minimize to system tray
|
; 1: minimize to system tray
|
||||||
minimize_to_system_tray=-1
|
minimize_to_system_tray=-1
|
||||||
|
|
||||||
; Suffixes list of Markdown files separated by :
|
; Suffixes list of Markdown files separated by ,
|
||||||
; Case-insensitive
|
; Case-insensitive
|
||||||
markdown_suffix=md:markdown:mkd
|
markdown_suffix=md,markdown,mkd
|
||||||
|
|
||||||
; Markdown highlight timer interval (milliseconds)
|
; Markdown highlight timer interval (milliseconds)
|
||||||
markdown_highlight_interval=400
|
markdown_highlight_interval=400
|
||||||
@ -181,21 +181,15 @@ flash_page=flash_page.md
|
|||||||
; Whether close note before editting with external editor
|
; Whether close note before editting with external editor
|
||||||
close_before_external_editor=true
|
close_before_external_editor=true
|
||||||
|
|
||||||
|
; Custom color list to be used in VNote, such as background color
|
||||||
|
; Separated by ,
|
||||||
|
; Each item is in the form "Name:Color"
|
||||||
|
custom_colors=White:#EEEEEE,Green:#CCE8CF,Wheat:#DFC7B2,LightGrey:#D3D3D3
|
||||||
|
|
||||||
[web]
|
[web]
|
||||||
; Location and configuration for Mathjax
|
; Location and configuration for Mathjax
|
||||||
mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML
|
mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML
|
||||||
|
|
||||||
[predefined_colors]
|
|
||||||
1\name=White
|
|
||||||
1\rgb=EEEEEE
|
|
||||||
2\name=Green
|
|
||||||
2\rgb=CCE8CF
|
|
||||||
3\name=Wheat2
|
|
||||||
3\rgb=DFC7B2
|
|
||||||
4\name=LightGrey
|
|
||||||
4\rgb=D3D3D3
|
|
||||||
size=4
|
|
||||||
|
|
||||||
[shortcuts]
|
[shortcuts]
|
||||||
; Define shortcuts here, with each item in the form "operation=keysequence".
|
; Define shortcuts here, with each item in the form "operation=keysequence".
|
||||||
; Leave keysequence empty to disable the shortcut of an operation.
|
; Leave keysequence empty to disable the shortcut of an operation.
|
||||||
|
@ -116,28 +116,6 @@ QJsonObject VUtils::readJsonFromDisk(const QString &p_filePath)
|
|||||||
return QJsonDocument::fromJson(file.readAll()).object();
|
return QJsonDocument::fromJson(file.readAll()).object();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRgb VUtils::QRgbFromString(const QString &str)
|
|
||||||
{
|
|
||||||
Q_ASSERT(str.length() == 6);
|
|
||||||
QString rStr = str.left(2);
|
|
||||||
QString gStr = str.mid(2, 2);
|
|
||||||
QString bStr = str.right(2);
|
|
||||||
|
|
||||||
bool ok, ret = true;
|
|
||||||
int red = rStr.toInt(&ok, 16);
|
|
||||||
ret = ret && ok;
|
|
||||||
int green = gStr.toInt(&ok, 16);
|
|
||||||
ret = ret && ok;
|
|
||||||
int blue = bStr.toInt(&ok, 16);
|
|
||||||
ret = ret && ok;
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
return qRgb(red, green, blue);
|
|
||||||
}
|
|
||||||
qWarning() << "fail to construct QRgb from string" << str;
|
|
||||||
return QRgb();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString VUtils::generateImageFileName(const QString &path,
|
QString VUtils::generateImageFileName(const QString &path,
|
||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &format)
|
const QString &format)
|
||||||
|
@ -86,9 +86,6 @@ public:
|
|||||||
|
|
||||||
static QJsonObject readJsonFromDisk(const QString &p_filePath);
|
static QJsonObject readJsonFromDisk(const QString &p_filePath);
|
||||||
|
|
||||||
// Transform FFFFFF string to QRgb
|
|
||||||
static QRgb QRgbFromString(const QString &str);
|
|
||||||
|
|
||||||
static QString generateImageFileName(const QString &path, const QString &title,
|
static QString generateImageFileName(const QString &path, const QString &title,
|
||||||
const QString &format = "png");
|
const QString &format = "png");
|
||||||
|
|
||||||
|
@ -92,7 +92,8 @@ void VConfigManager::initialize()
|
|||||||
m_autoIndent = getConfigFromSettings("global", "auto_indent").toBool();
|
m_autoIndent = getConfigFromSettings("global", "auto_indent").toBool();
|
||||||
m_autoList = getConfigFromSettings("global", "auto_list").toBool();
|
m_autoList = getConfigFromSettings("global", "auto_list").toBool();
|
||||||
|
|
||||||
readPredefinedColorsFromSettings();
|
readCustomColors();
|
||||||
|
|
||||||
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
||||||
|
|
||||||
updateEditStyle();
|
updateEditStyle();
|
||||||
@ -337,20 +338,26 @@ void VConfigManager::initFromSessionSettings()
|
|||||||
"navi_splitter_state").toByteArray();
|
"navi_splitter_state").toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::readPredefinedColorsFromSettings()
|
void VConfigManager::readCustomColors()
|
||||||
{
|
{
|
||||||
predefinedColors.clear();
|
m_customColors.clear();
|
||||||
int size = defaultSettings->beginReadArray("predefined_colors");
|
QStringList str = getConfigFromSettings("global", "custom_colors").toStringList();
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
defaultSettings->setArrayIndex(i);
|
for (auto const & item : str) {
|
||||||
|
QStringList parts = item.split(':', QString::SkipEmptyParts);
|
||||||
|
if (parts.size() != 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!QColor(parts[1]).isValid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
VColor color;
|
VColor color;
|
||||||
color.name = defaultSettings->value("name").toString();
|
color.m_name = parts[0];
|
||||||
color.rgb = defaultSettings->value("rgb").toString();
|
color.m_color = parts[1];
|
||||||
predefinedColors.append(color);
|
m_customColors.append(color);
|
||||||
}
|
}
|
||||||
defaultSettings->endArray();
|
|
||||||
qDebug() << "read" << predefinedColors.size()
|
|
||||||
<< "pre-defined colors from [predefined_colors] section";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::readNotebookFromSettings(QSettings *p_settings,
|
void VConfigManager::readNotebookFromSettings(QSettings *p_settings,
|
||||||
@ -690,14 +697,10 @@ void VConfigManager::updateEditStyle()
|
|||||||
QColor newColor = defaultColor;
|
QColor newColor = defaultColor;
|
||||||
bool force = false;
|
bool force = false;
|
||||||
if (curBackgroundColor != "System") {
|
if (curBackgroundColor != "System") {
|
||||||
for (int i = 0; i < predefinedColors.size(); ++i) {
|
for (int i = 0; i < m_customColors.size(); ++i) {
|
||||||
if (predefinedColors[i].name == curBackgroundColor) {
|
if (m_customColors[i].m_name == curBackgroundColor) {
|
||||||
QString rgb = predefinedColors[i].rgb;
|
newColor = QColor(m_customColors[i].m_color);
|
||||||
if (!rgb.isEmpty()) {
|
force = true;
|
||||||
newColor = QColor(VUtils::QRgbFromString(rgb));
|
|
||||||
force = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1040,17 +1043,27 @@ void VConfigManager::initDocSuffixes()
|
|||||||
{
|
{
|
||||||
m_docSuffixes.clear();
|
m_docSuffixes.clear();
|
||||||
|
|
||||||
QString mdSuffix = getConfigFromSettings("global",
|
QStringList mdSuffix = getConfigFromSettings("global",
|
||||||
"markdown_suffix").toString();
|
"markdown_suffix").toStringList();
|
||||||
if (mdSuffix.isEmpty()) {
|
if (mdSuffix.isEmpty()) {
|
||||||
mdSuffix = getDefaultConfig("global",
|
mdSuffix = getDefaultConfig("global",
|
||||||
"markdown_suffix").toString();
|
"markdown_suffix").toStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = mdSuffix.begin(); it != mdSuffix.end();) {
|
||||||
|
if (it->isEmpty()) {
|
||||||
|
it = mdSuffix.erase(it);
|
||||||
|
} else {
|
||||||
|
*it = it->toLower();
|
||||||
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(!mdSuffix.isEmpty());
|
Q_ASSERT(!mdSuffix.isEmpty());
|
||||||
QList<QString> md = mdSuffix.toLower().split(':', QString::SkipEmptyParts);
|
|
||||||
md.removeDuplicates();
|
mdSuffix.removeDuplicates();
|
||||||
m_docSuffixes[(int)DocType::Markdown] = md;
|
|
||||||
|
m_docSuffixes[(int)DocType::Markdown] = mdSuffix;
|
||||||
|
|
||||||
QList<QString> list;
|
QList<QString> list;
|
||||||
list << "ls" << "list";
|
list << "ls" << "list";
|
||||||
|
@ -28,8 +28,8 @@ enum MarkdownConverterType
|
|||||||
|
|
||||||
struct VColor
|
struct VColor
|
||||||
{
|
{
|
||||||
QString name;
|
QString m_name;
|
||||||
QString rgb; // 'FFFFFF', without '#'
|
QString m_color; // #RGB or color name.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MarkdownitOption
|
struct MarkdownitOption
|
||||||
@ -147,7 +147,7 @@ public:
|
|||||||
bool getAutoList() const;
|
bool getAutoList() const;
|
||||||
void setAutoList(bool p_autoList);
|
void setAutoList(bool p_autoList);
|
||||||
|
|
||||||
const QVector<VColor> &getPredefinedColors() const;
|
const QVector<VColor> &getCustomColors() const;
|
||||||
|
|
||||||
const QString &getCurBackgroundColor() const;
|
const QString &getCurBackgroundColor() const;
|
||||||
void setCurBackgroundColor(const QString &colorName);
|
void setCurBackgroundColor(const QString &colorName);
|
||||||
@ -435,7 +435,7 @@ private:
|
|||||||
void writeNotebookToSettings(QSettings *p_settings,
|
void writeNotebookToSettings(QSettings *p_settings,
|
||||||
const QVector<VNotebook *> &p_notebooks);
|
const QVector<VNotebook *> &p_notebooks);
|
||||||
|
|
||||||
void readPredefinedColorsFromSettings();
|
void readCustomColors();
|
||||||
|
|
||||||
// 1. Update styles common in HTML and Markdown;
|
// 1. Update styles common in HTML and Markdown;
|
||||||
// 2. Update styles for Markdown.
|
// 2. Update styles for Markdown.
|
||||||
@ -526,8 +526,10 @@ private:
|
|||||||
bool m_autoList;
|
bool m_autoList;
|
||||||
|
|
||||||
// App defined color
|
// App defined color
|
||||||
QVector<VColor> predefinedColors;
|
QVector<VColor> m_customColors;
|
||||||
|
|
||||||
QString curBackgroundColor;
|
QString curBackgroundColor;
|
||||||
|
|
||||||
QString curRenderBackgroundColor;
|
QString curRenderBackgroundColor;
|
||||||
|
|
||||||
bool m_toolsDockChecked;
|
bool m_toolsDockChecked;
|
||||||
@ -1020,9 +1022,9 @@ inline void VConfigManager::setAutoList(bool p_autoList)
|
|||||||
m_autoList);
|
m_autoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const QVector<VColor>& VConfigManager::getPredefinedColors() const
|
inline const QVector<VColor>& VConfigManager::getCustomColors() const
|
||||||
{
|
{
|
||||||
return predefinedColors;
|
return m_customColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const QString& VConfigManager::getCurBackgroundColor() const
|
inline const QString& VConfigManager::getCurBackgroundColor() const
|
||||||
|
@ -50,6 +50,8 @@ const int VMainWindow::c_sharedMemTimerInterval = 1000;
|
|||||||
extern QFile g_logFile;
|
extern QFile g_logFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define COLOR_PIXMAP_ICON_SIZE 64
|
||||||
|
|
||||||
|
|
||||||
VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
||||||
: QMainWindow(p_parent), m_guard(p_guard),
|
: QMainWindow(p_parent), m_guard(p_guard),
|
||||||
@ -62,7 +64,6 @@ VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
|||||||
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
|
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
|
||||||
vnote = new VNote(this);
|
vnote = new VNote(this);
|
||||||
g_vnote = vnote;
|
g_vnote = vnote;
|
||||||
initPredefinedColorPixmaps();
|
|
||||||
|
|
||||||
if (g_config->getEnableCompactMode()) {
|
if (g_config->getEnableCompactMode()) {
|
||||||
m_panelViewState = PanelViewState::CompactMode;
|
m_panelViewState = PanelViewState::CompactMode;
|
||||||
@ -1335,20 +1336,6 @@ void VMainWindow::setEditorBackgroundColor(QAction *action)
|
|||||||
g_config->setCurBackgroundColor(action->data().toString());
|
g_config->setCurBackgroundColor(action->data().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::initPredefinedColorPixmaps()
|
|
||||||
{
|
|
||||||
const QVector<VColor> &bgColors = g_config->getPredefinedColors();
|
|
||||||
predefinedColorPixmaps.clear();
|
|
||||||
int size = 256;
|
|
||||||
for (int i = 0; i < bgColors.size(); ++i) {
|
|
||||||
// Generate QPixmap filled in this color
|
|
||||||
QColor color(VUtils::QRgbFromString(bgColors[i].rgb));
|
|
||||||
QPixmap pixmap(size, size);
|
|
||||||
pixmap.fill(color);
|
|
||||||
predefinedColorPixmaps.append(pixmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VMainWindow::initConverterMenu(QMenu *p_menu)
|
void VMainWindow::initConverterMenu(QMenu *p_menu)
|
||||||
{
|
{
|
||||||
QMenu *converterMenu = p_menu->addMenu(tr("&Converter"));
|
QMenu *converterMenu = p_menu->addMenu(tr("&Converter"));
|
||||||
@ -1468,18 +1455,21 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
|
|||||||
}
|
}
|
||||||
renderBgMenu->addAction(tmpAct);
|
renderBgMenu->addAction(tmpAct);
|
||||||
|
|
||||||
const QVector<VColor> &bgColors = g_config->getPredefinedColors();
|
const QVector<VColor> &bgColors = g_config->getCustomColors();
|
||||||
for (int i = 0; i < bgColors.size(); ++i) {
|
for (int i = 0; i < bgColors.size(); ++i) {
|
||||||
tmpAct = new QAction(bgColors[i].name, renderBackgroundAct);
|
tmpAct = new QAction(bgColors[i].m_name, renderBackgroundAct);
|
||||||
tmpAct->setToolTip(tr("Set as the background color for Markdown rendering"));
|
tmpAct->setToolTip(tr("Set as the background color for Markdown rendering"));
|
||||||
tmpAct->setCheckable(true);
|
tmpAct->setCheckable(true);
|
||||||
tmpAct->setData(bgColors[i].name);
|
tmpAct->setData(bgColors[i].m_name);
|
||||||
|
|
||||||
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
|
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
|
||||||
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
QColor color(bgColors[i].m_color);
|
||||||
|
QPixmap pixmap(COLOR_PIXMAP_ICON_SIZE, COLOR_PIXMAP_ICON_SIZE);
|
||||||
|
pixmap.fill(color);
|
||||||
|
tmpAct->setIcon(QIcon(pixmap));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (curBgColor == bgColors[i].name) {
|
if (curBgColor == bgColors[i].m_name) {
|
||||||
tmpAct->setChecked(true);
|
tmpAct->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1612,16 +1602,21 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
|
|||||||
tmpAct->setChecked(true);
|
tmpAct->setChecked(true);
|
||||||
}
|
}
|
||||||
backgroundColorMenu->addAction(tmpAct);
|
backgroundColorMenu->addAction(tmpAct);
|
||||||
const QVector<VColor> &bgColors = g_config->getPredefinedColors();
|
const QVector<VColor> &bgColors = g_config->getCustomColors();
|
||||||
for (int i = 0; i < bgColors.size(); ++i) {
|
for (int i = 0; i < bgColors.size(); ++i) {
|
||||||
tmpAct = new QAction(bgColors[i].name, backgroundColorAct);
|
tmpAct = new QAction(bgColors[i].m_name, backgroundColorAct);
|
||||||
tmpAct->setToolTip(tr("Set as the background color for editor"));
|
tmpAct->setToolTip(tr("Set as the background color for editor"));
|
||||||
tmpAct->setCheckable(true);
|
tmpAct->setCheckable(true);
|
||||||
tmpAct->setData(bgColors[i].name);
|
tmpAct->setData(bgColors[i].m_name);
|
||||||
|
|
||||||
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
|
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
|
||||||
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
QColor color(bgColors[i].m_color);
|
||||||
|
QPixmap pixmap(COLOR_PIXMAP_ICON_SIZE, COLOR_PIXMAP_ICON_SIZE);
|
||||||
|
pixmap.fill(color);
|
||||||
|
tmpAct->setIcon(QIcon(pixmap));
|
||||||
#endif
|
#endif
|
||||||
if (curBgColor == bgColors[i].name) {
|
|
||||||
|
if (curBgColor == bgColors[i].m_name) {
|
||||||
tmpAct->setChecked(true);
|
tmpAct->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ private:
|
|||||||
void initHelpMenu();
|
void initHelpMenu();
|
||||||
|
|
||||||
void initDockWindows();
|
void initDockWindows();
|
||||||
void initPredefinedColorPixmaps();
|
|
||||||
void initRenderBackgroundMenu(QMenu *menu);
|
void initRenderBackgroundMenu(QMenu *menu);
|
||||||
|
|
||||||
void initRenderStyleMenu(QMenu *p_menu);
|
void initRenderStyleMenu(QMenu *p_menu);
|
||||||
@ -361,8 +361,6 @@ private:
|
|||||||
|
|
||||||
QPushButton *m_avatarBtn;
|
QPushButton *m_avatarBtn;
|
||||||
|
|
||||||
QVector<QPixmap> predefinedColorPixmaps;
|
|
||||||
|
|
||||||
// Single instance guard.
|
// Single instance guard.
|
||||||
VSingleInstanceGuard *m_guard;
|
VSingleInstanceGuard *m_guard;
|
||||||
|
|
||||||
|
@ -101,21 +101,21 @@ void VNote::updateTemplate()
|
|||||||
const QString c_markdownTemplatePath(":/resources/markdown_template.html");
|
const QString c_markdownTemplatePath(":/resources/markdown_template.html");
|
||||||
|
|
||||||
// Get background color
|
// Get background color
|
||||||
QString rgb;
|
QString color;
|
||||||
const QString &curRenderBg = g_config->getCurRenderBackgroundColor();
|
const QString &curRenderBg = g_config->getCurRenderBackgroundColor();
|
||||||
const QVector<VColor> &predefinedColors = g_config->getPredefinedColors();
|
const QVector<VColor> &customColors = g_config->getCustomColors();
|
||||||
if (curRenderBg != "System") {
|
if (curRenderBg != "System") {
|
||||||
for (int i = 0; i < predefinedColors.size(); ++i) {
|
for (int i = 0; i < customColors.size(); ++i) {
|
||||||
if (predefinedColors[i].name == curRenderBg) {
|
if (customColors[i].m_name == curRenderBg) {
|
||||||
rgb = predefinedColors[i].rgb;
|
color = customColors[i].m_color;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString cssStyle;
|
QString cssStyle;
|
||||||
if (!rgb.isEmpty()) {
|
if (!color.isEmpty()) {
|
||||||
cssStyle += "body { background-color: #" + rgb + " !important; }\n";
|
cssStyle += "body { background-color: " + color + " !important; }\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_config->getEnableImageConstraint()) {
|
if (g_config->getEnableImageConstraint()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user