mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +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
|
||||
minimize_to_system_tray=-1
|
||||
|
||||
; Suffixes list of Markdown files separated by :
|
||||
; Suffixes list of Markdown files separated by ,
|
||||
; Case-insensitive
|
||||
markdown_suffix=md:markdown:mkd
|
||||
markdown_suffix=md,markdown,mkd
|
||||
|
||||
; Markdown highlight timer interval (milliseconds)
|
||||
markdown_highlight_interval=400
|
||||
@ -181,21 +181,15 @@ flash_page=flash_page.md
|
||||
; Whether close note before editting with external editor
|
||||
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]
|
||||
; Location and configuration for Mathjax
|
||||
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]
|
||||
; Define shortcuts here, with each item in the form "operation=keysequence".
|
||||
; 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();
|
||||
}
|
||||
|
||||
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,
|
||||
const QString &title,
|
||||
const QString &format)
|
||||
|
@ -86,9 +86,6 @@ public:
|
||||
|
||||
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,
|
||||
const QString &format = "png");
|
||||
|
||||
|
@ -92,7 +92,8 @@ void VConfigManager::initialize()
|
||||
m_autoIndent = getConfigFromSettings("global", "auto_indent").toBool();
|
||||
m_autoList = getConfigFromSettings("global", "auto_list").toBool();
|
||||
|
||||
readPredefinedColorsFromSettings();
|
||||
readCustomColors();
|
||||
|
||||
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
||||
|
||||
updateEditStyle();
|
||||
@ -337,20 +338,26 @@ void VConfigManager::initFromSessionSettings()
|
||||
"navi_splitter_state").toByteArray();
|
||||
}
|
||||
|
||||
void VConfigManager::readPredefinedColorsFromSettings()
|
||||
void VConfigManager::readCustomColors()
|
||||
{
|
||||
predefinedColors.clear();
|
||||
int size = defaultSettings->beginReadArray("predefined_colors");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
defaultSettings->setArrayIndex(i);
|
||||
VColor color;
|
||||
color.name = defaultSettings->value("name").toString();
|
||||
color.rgb = defaultSettings->value("rgb").toString();
|
||||
predefinedColors.append(color);
|
||||
m_customColors.clear();
|
||||
QStringList str = getConfigFromSettings("global", "custom_colors").toStringList();
|
||||
|
||||
for (auto const & item : str) {
|
||||
QStringList parts = item.split(':', QString::SkipEmptyParts);
|
||||
if (parts.size() != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!QColor(parts[1]).isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
VColor color;
|
||||
color.m_name = parts[0];
|
||||
color.m_color = parts[1];
|
||||
m_customColors.append(color);
|
||||
}
|
||||
defaultSettings->endArray();
|
||||
qDebug() << "read" << predefinedColors.size()
|
||||
<< "pre-defined colors from [predefined_colors] section";
|
||||
}
|
||||
|
||||
void VConfigManager::readNotebookFromSettings(QSettings *p_settings,
|
||||
@ -690,14 +697,10 @@ void VConfigManager::updateEditStyle()
|
||||
QColor newColor = defaultColor;
|
||||
bool force = false;
|
||||
if (curBackgroundColor != "System") {
|
||||
for (int i = 0; i < predefinedColors.size(); ++i) {
|
||||
if (predefinedColors[i].name == curBackgroundColor) {
|
||||
QString rgb = predefinedColors[i].rgb;
|
||||
if (!rgb.isEmpty()) {
|
||||
newColor = QColor(VUtils::QRgbFromString(rgb));
|
||||
for (int i = 0; i < m_customColors.size(); ++i) {
|
||||
if (m_customColors[i].m_name == curBackgroundColor) {
|
||||
newColor = QColor(m_customColors[i].m_color);
|
||||
force = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1040,17 +1043,27 @@ void VConfigManager::initDocSuffixes()
|
||||
{
|
||||
m_docSuffixes.clear();
|
||||
|
||||
QString mdSuffix = getConfigFromSettings("global",
|
||||
"markdown_suffix").toString();
|
||||
QStringList mdSuffix = getConfigFromSettings("global",
|
||||
"markdown_suffix").toStringList();
|
||||
if (mdSuffix.isEmpty()) {
|
||||
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());
|
||||
QList<QString> md = mdSuffix.toLower().split(':', QString::SkipEmptyParts);
|
||||
md.removeDuplicates();
|
||||
m_docSuffixes[(int)DocType::Markdown] = md;
|
||||
|
||||
mdSuffix.removeDuplicates();
|
||||
|
||||
m_docSuffixes[(int)DocType::Markdown] = mdSuffix;
|
||||
|
||||
QList<QString> list;
|
||||
list << "ls" << "list";
|
||||
|
@ -28,8 +28,8 @@ enum MarkdownConverterType
|
||||
|
||||
struct VColor
|
||||
{
|
||||
QString name;
|
||||
QString rgb; // 'FFFFFF', without '#'
|
||||
QString m_name;
|
||||
QString m_color; // #RGB or color name.
|
||||
};
|
||||
|
||||
struct MarkdownitOption
|
||||
@ -147,7 +147,7 @@ public:
|
||||
bool getAutoList() const;
|
||||
void setAutoList(bool p_autoList);
|
||||
|
||||
const QVector<VColor> &getPredefinedColors() const;
|
||||
const QVector<VColor> &getCustomColors() const;
|
||||
|
||||
const QString &getCurBackgroundColor() const;
|
||||
void setCurBackgroundColor(const QString &colorName);
|
||||
@ -435,7 +435,7 @@ private:
|
||||
void writeNotebookToSettings(QSettings *p_settings,
|
||||
const QVector<VNotebook *> &p_notebooks);
|
||||
|
||||
void readPredefinedColorsFromSettings();
|
||||
void readCustomColors();
|
||||
|
||||
// 1. Update styles common in HTML and Markdown;
|
||||
// 2. Update styles for Markdown.
|
||||
@ -526,8 +526,10 @@ private:
|
||||
bool m_autoList;
|
||||
|
||||
// App defined color
|
||||
QVector<VColor> predefinedColors;
|
||||
QVector<VColor> m_customColors;
|
||||
|
||||
QString curBackgroundColor;
|
||||
|
||||
QString curRenderBackgroundColor;
|
||||
|
||||
bool m_toolsDockChecked;
|
||||
@ -1020,9 +1022,9 @@ inline void VConfigManager::setAutoList(bool p_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
|
||||
|
@ -50,6 +50,8 @@ const int VMainWindow::c_sharedMemTimerInterval = 1000;
|
||||
extern QFile g_logFile;
|
||||
#endif
|
||||
|
||||
#define COLOR_PIXMAP_ICON_SIZE 64
|
||||
|
||||
|
||||
VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
||||
: 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"));
|
||||
vnote = new VNote(this);
|
||||
g_vnote = vnote;
|
||||
initPredefinedColorPixmaps();
|
||||
|
||||
if (g_config->getEnableCompactMode()) {
|
||||
m_panelViewState = PanelViewState::CompactMode;
|
||||
@ -1335,20 +1336,6 @@ void VMainWindow::setEditorBackgroundColor(QAction *action)
|
||||
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)
|
||||
{
|
||||
QMenu *converterMenu = p_menu->addMenu(tr("&Converter"));
|
||||
@ -1468,18 +1455,21 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
|
||||
}
|
||||
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) {
|
||||
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->setCheckable(true);
|
||||
tmpAct->setData(bgColors[i].name);
|
||||
tmpAct->setData(bgColors[i].m_name);
|
||||
|
||||
#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
|
||||
|
||||
if (curBgColor == bgColors[i].name) {
|
||||
if (curBgColor == bgColors[i].m_name) {
|
||||
tmpAct->setChecked(true);
|
||||
}
|
||||
|
||||
@ -1612,16 +1602,21 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
|
||||
tmpAct->setChecked(true);
|
||||
}
|
||||
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) {
|
||||
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->setCheckable(true);
|
||||
tmpAct->setData(bgColors[i].name);
|
||||
tmpAct->setData(bgColors[i].m_name);
|
||||
|
||||
#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
|
||||
if (curBgColor == bgColors[i].name) {
|
||||
|
||||
if (curBgColor == bgColors[i].m_name) {
|
||||
tmpAct->setChecked(true);
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ private:
|
||||
void initHelpMenu();
|
||||
|
||||
void initDockWindows();
|
||||
void initPredefinedColorPixmaps();
|
||||
|
||||
void initRenderBackgroundMenu(QMenu *menu);
|
||||
|
||||
void initRenderStyleMenu(QMenu *p_menu);
|
||||
@ -361,8 +361,6 @@ private:
|
||||
|
||||
QPushButton *m_avatarBtn;
|
||||
|
||||
QVector<QPixmap> predefinedColorPixmaps;
|
||||
|
||||
// Single instance guard.
|
||||
VSingleInstanceGuard *m_guard;
|
||||
|
||||
|
@ -101,21 +101,21 @@ void VNote::updateTemplate()
|
||||
const QString c_markdownTemplatePath(":/resources/markdown_template.html");
|
||||
|
||||
// Get background color
|
||||
QString rgb;
|
||||
QString color;
|
||||
const QString &curRenderBg = g_config->getCurRenderBackgroundColor();
|
||||
const QVector<VColor> &predefinedColors = g_config->getPredefinedColors();
|
||||
const QVector<VColor> &customColors = g_config->getCustomColors();
|
||||
if (curRenderBg != "System") {
|
||||
for (int i = 0; i < predefinedColors.size(); ++i) {
|
||||
if (predefinedColors[i].name == curRenderBg) {
|
||||
rgb = predefinedColors[i].rgb;
|
||||
for (int i = 0; i < customColors.size(); ++i) {
|
||||
if (customColors[i].m_name == curRenderBg) {
|
||||
color = customColors[i].m_color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString cssStyle;
|
||||
if (!rgb.isEmpty()) {
|
||||
cssStyle += "body { background-color: #" + rgb + " !important; }\n";
|
||||
if (!color.isEmpty()) {
|
||||
cssStyle += "body { background-color: " + color + " !important; }\n";
|
||||
}
|
||||
|
||||
if (g_config->getEnableImageConstraint()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user