mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support changing rendering background color
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
0c3fc3b006
commit
53bce98db6
@ -2,6 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<head>
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
<!-- BACKGROUND_PLACE_HOLDER -->
|
||||||
|
</style>
|
||||||
<link rel="stylesheet" type="text/css" href="CSS_PLACE_HOLDER">
|
<link rel="stylesheet" type="text/css" href="CSS_PLACE_HOLDER">
|
||||||
<link rel="stylesheet" type="text/css" href="qrc:/utils/highlightjs/styles/default.css">
|
<link rel="stylesheet" type="text/css" href="qrc:/utils/highlightjs/styles/default.css">
|
||||||
<script src="qrc:/utils/highlightjs/highlight.pack.js"></script>
|
<script src="qrc:/utils/highlightjs/highlight.pack.js"></script>
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<head>
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
<!-- BACKGROUND_PLACE_HOLDER -->
|
||||||
|
</style>
|
||||||
<link rel="stylesheet" type="text/css" href="CSS_PLACE_HOLDER">
|
<link rel="stylesheet" type="text/css" href="CSS_PLACE_HOLDER">
|
||||||
<link rel="stylesheet" type="text/css" href="qrc:/utils/highlightjs/styles/default.css">
|
<link rel="stylesheet" type="text/css" href="qrc:/utils/highlightjs/styles/default.css">
|
||||||
<script src="qrc:/utils/marked/marked.min.js"></script>
|
<script src="qrc:/utils/marked/marked.min.js"></script>
|
||||||
|
@ -8,6 +8,7 @@ current_notebook=0
|
|||||||
tab_stop_width=4
|
tab_stop_width=4
|
||||||
is_expand_tab=1
|
is_expand_tab=1
|
||||||
current_background_color=System
|
current_background_color=System
|
||||||
|
current_render_background_color=System
|
||||||
|
|
||||||
[predefined_colors]
|
[predefined_colors]
|
||||||
1\name=White
|
1\name=White
|
||||||
|
@ -40,8 +40,6 @@ QRgb VUtils::QRgbFromString(const QString &str)
|
|||||||
QString gStr = str.mid(2, 2);
|
QString gStr = str.mid(2, 2);
|
||||||
QString bStr = str.right(2);
|
QString bStr = str.right(2);
|
||||||
|
|
||||||
qDebug() << rStr << gStr << bStr;
|
|
||||||
|
|
||||||
bool ok, ret = true;
|
bool ok, ret = true;
|
||||||
int red = rStr.toInt(&ok, 16);
|
int red = rStr.toInt(&ok, 16);
|
||||||
ret = ret && ok;
|
ret = ret && ok;
|
||||||
|
@ -55,10 +55,12 @@ void VConfigManager::initialize()
|
|||||||
|
|
||||||
readPredefinedColorsFromSettings();
|
readPredefinedColorsFromSettings();
|
||||||
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
||||||
customBackgroundColor = getConfigFromSettings("global", "custom_background_color").toString();
|
|
||||||
|
|
||||||
updatePaletteColor();
|
updatePaletteColor();
|
||||||
|
|
||||||
|
curRenderBackgroundColor = getConfigFromSettings("global",
|
||||||
|
"current_render_background_color").toString();
|
||||||
|
|
||||||
// Update notebooks
|
// Update notebooks
|
||||||
readNotebookFromSettings();
|
readNotebookFromSettings();
|
||||||
|
|
||||||
@ -209,9 +211,7 @@ void VConfigManager::updateMarkdownEditStyle()
|
|||||||
void VConfigManager::updatePaletteColor()
|
void VConfigManager::updatePaletteColor()
|
||||||
{
|
{
|
||||||
QString rgb;
|
QString rgb;
|
||||||
if (curBackgroundColor == "Custom") {
|
if (curBackgroundColor == "System") {
|
||||||
rgb = customBackgroundColor;
|
|
||||||
} else if (curBackgroundColor == "System") {
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < predefinedColors.size(); ++i) {
|
for (int i = 0; i < predefinedColors.size(); ++i) {
|
||||||
|
@ -80,8 +80,8 @@ public:
|
|||||||
inline const QString &getCurBackgroundColor() const;
|
inline const QString &getCurBackgroundColor() const;
|
||||||
inline void setCurBackgroundColor(const QString &colorName);
|
inline void setCurBackgroundColor(const QString &colorName);
|
||||||
|
|
||||||
inline const QString &getCustomBackgroundColor() const;
|
inline const QString &getCurRenderBackgroundColor() const;
|
||||||
inline void setCustomBackgroundColor(const QString &colorRgb);
|
inline void setCurRenderBackgroundColor(const QString &colorName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateMarkdownEditStyle();
|
void updateMarkdownEditStyle();
|
||||||
@ -118,7 +118,7 @@ private:
|
|||||||
// App defined color
|
// App defined color
|
||||||
QVector<VColor> predefinedColors;
|
QVector<VColor> predefinedColors;
|
||||||
QString curBackgroundColor;
|
QString curBackgroundColor;
|
||||||
QString customBackgroundColor;
|
QString curRenderBackgroundColor;
|
||||||
|
|
||||||
// The name of the config file in each directory
|
// The name of the config file in each directory
|
||||||
static const QString dirConfigFileName;
|
static const QString dirConfigFileName;
|
||||||
@ -274,20 +274,19 @@ inline void VConfigManager::setCurBackgroundColor(const QString &colorName)
|
|||||||
updatePaletteColor();
|
updatePaletteColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const QString& VConfigManager::getCustomBackgroundColor() const
|
inline const QString& VConfigManager::getCurRenderBackgroundColor() const
|
||||||
{
|
{
|
||||||
return customBackgroundColor;
|
return curRenderBackgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void VConfigManager::setCustomBackgroundColor(const QString &colorRgb)
|
inline void VConfigManager::setCurRenderBackgroundColor(const QString &colorName)
|
||||||
{
|
{
|
||||||
if (customBackgroundColor == colorRgb) {
|
if (curRenderBackgroundColor == colorName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
customBackgroundColor = colorRgb;
|
curRenderBackgroundColor = colorName;
|
||||||
setConfigToSettings("global", "custom_background_color",
|
setConfigToSettings("global", "current_render_background_color",
|
||||||
customBackgroundColor);
|
curRenderBackgroundColor);
|
||||||
updatePaletteColor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // VCONFIGMANAGER_H
|
#endif // VCONFIGMANAGER_H
|
||||||
|
@ -211,6 +211,10 @@ void VMainWindow::initActions()
|
|||||||
backgroundColorAct = new QActionGroup(this);
|
backgroundColorAct = new QActionGroup(this);
|
||||||
connect(backgroundColorAct, &QActionGroup::triggered,
|
connect(backgroundColorAct, &QActionGroup::triggered,
|
||||||
this, &VMainWindow::setEditorBackgroundColor);
|
this, &VMainWindow::setEditorBackgroundColor);
|
||||||
|
|
||||||
|
renderBackgroundAct = new QActionGroup(this);
|
||||||
|
connect(renderBackgroundAct, &QActionGroup::triggered,
|
||||||
|
this, &VMainWindow::setRenderBackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::initToolBar()
|
void VMainWindow::initToolBar()
|
||||||
@ -258,43 +262,7 @@ void VMainWindow::initMenuBar()
|
|||||||
default:
|
default:
|
||||||
qWarning() << "error: unsupported tab stop width" << tabStopWidth << "in config";
|
qWarning() << "error: unsupported tab stop width" << tabStopWidth << "in config";
|
||||||
}
|
}
|
||||||
|
initEditorBackgroundMenu(editMenu);
|
||||||
QMenu *backgroundColorMenu = editMenu->addMenu(tr("&Background Color"));
|
|
||||||
// System background color
|
|
||||||
const QString &curBgColor = vconfig.getCurBackgroundColor();
|
|
||||||
QAction *tmpAct = new QAction(tr("System"), backgroundColorAct);
|
|
||||||
tmpAct->setStatusTip(tr("Use system's background color configuration for editor"));
|
|
||||||
tmpAct->setCheckable(true);
|
|
||||||
tmpAct->setData("System");
|
|
||||||
if (curBgColor == "System") {
|
|
||||||
tmpAct->setChecked(true);
|
|
||||||
}
|
|
||||||
backgroundColorMenu->addAction(tmpAct);
|
|
||||||
const QVector<VColor> &bgColors = vconfig.getPredefinedColors();
|
|
||||||
for (int i = 0; i < bgColors.size(); ++i) {
|
|
||||||
tmpAct = new QAction(bgColors[i].name, backgroundColorAct);
|
|
||||||
tmpAct->setStatusTip(tr("Set background color for editor"));
|
|
||||||
tmpAct->setCheckable(true);
|
|
||||||
tmpAct->setData(bgColors[i].name);
|
|
||||||
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
|
||||||
if (curBgColor == bgColors[i].name) {
|
|
||||||
tmpAct->setChecked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
backgroundColorMenu->addAction(tmpAct);
|
|
||||||
}
|
|
||||||
// Custom background color
|
|
||||||
tmpAct = new QAction(tr("Custom"), backgroundColorAct);
|
|
||||||
tmpAct->setStatusTip(tr("Set customed background color for editor"));
|
|
||||||
tmpAct->setCheckable(true);
|
|
||||||
tmpAct->setData("Custom");
|
|
||||||
if (!vconfig.getCustomBackgroundColor().isEmpty()) {
|
|
||||||
tmpAct->setIcon(QIcon(predefinedColorPixmaps.back()));
|
|
||||||
}
|
|
||||||
if (curBgColor == "Custom") {
|
|
||||||
tmpAct->setChecked(true);
|
|
||||||
}
|
|
||||||
backgroundColorMenu->addAction(tmpAct);
|
|
||||||
|
|
||||||
// Markdown Menu
|
// Markdown Menu
|
||||||
QMenu *converterMenu = markdownMenu->addMenu(tr("&Converter"));
|
QMenu *converterMenu = markdownMenu->addMenu(tr("&Converter"));
|
||||||
@ -307,6 +275,8 @@ void VMainWindow::initMenuBar()
|
|||||||
hoedownAct->setChecked(true);
|
hoedownAct->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initRenderBackgroundMenu(markdownMenu);
|
||||||
|
|
||||||
// Help menu
|
// Help menu
|
||||||
helpMenu->addAction(aboutQtAct);
|
helpMenu->addAction(aboutQtAct);
|
||||||
helpMenu->addAction(aboutAct);
|
helpMenu->addAction(aboutAct);
|
||||||
@ -534,10 +504,6 @@ void VMainWindow::setEditorBackgroundColor(QAction *action)
|
|||||||
if (!action) {
|
if (!action) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: implement custom color logics
|
|
||||||
if (action->data().toString() == "Custom") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
vconfig.setCurBackgroundColor(action->data().toString());
|
vconfig.setCurBackgroundColor(action->data().toString());
|
||||||
}
|
}
|
||||||
@ -554,12 +520,69 @@ void VMainWindow::initPredefinedColorPixmaps()
|
|||||||
pixmap.fill(color);
|
pixmap.fill(color);
|
||||||
predefinedColorPixmaps.append(pixmap);
|
predefinedColorPixmaps.append(pixmap);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const QString &customBgColor = vconfig.getCustomBackgroundColor();
|
void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
|
||||||
if (!customBgColor.isEmpty()) {
|
{
|
||||||
QColor color(VUtils::QRgbFromString(customBgColor));
|
QMenu *renderBgMenu = menu->addMenu(tr("&Rendering background"));
|
||||||
QPixmap pixmap(size, size);
|
const QString &curBgColor = vconfig.getCurRenderBackgroundColor();
|
||||||
pixmap.fill(color);
|
QAction *tmpAct = new QAction(tr("System"), renderBackgroundAct);
|
||||||
predefinedColorPixmaps.append(pixmap);
|
tmpAct->setStatusTip(tr("Use system's background color configuration for rendering"));
|
||||||
|
tmpAct->setCheckable(true);
|
||||||
|
tmpAct->setData("System");
|
||||||
|
if (curBgColor == "System") {
|
||||||
|
tmpAct->setChecked(true);
|
||||||
|
}
|
||||||
|
renderBgMenu->addAction(tmpAct);
|
||||||
|
|
||||||
|
const QVector<VColor> &bgColors = vconfig.getPredefinedColors();
|
||||||
|
for (int i = 0; i < bgColors.size(); ++i) {
|
||||||
|
tmpAct = new QAction(bgColors[i].name, renderBackgroundAct);
|
||||||
|
tmpAct->setStatusTip(tr("Set background color for rendering"));
|
||||||
|
tmpAct->setCheckable(true);
|
||||||
|
tmpAct->setData(bgColors[i].name);
|
||||||
|
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
||||||
|
if (curBgColor == bgColors[i].name) {
|
||||||
|
tmpAct->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderBgMenu->addAction(tmpAct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
|
||||||
|
{
|
||||||
|
QMenu *backgroundColorMenu = menu->addMenu(tr("&Background Color"));
|
||||||
|
// System background color
|
||||||
|
const QString &curBgColor = vconfig.getCurBackgroundColor();
|
||||||
|
QAction *tmpAct = new QAction(tr("System"), backgroundColorAct);
|
||||||
|
tmpAct->setStatusTip(tr("Use system's background color configuration for editor"));
|
||||||
|
tmpAct->setCheckable(true);
|
||||||
|
tmpAct->setData("System");
|
||||||
|
if (curBgColor == "System") {
|
||||||
|
tmpAct->setChecked(true);
|
||||||
|
}
|
||||||
|
backgroundColorMenu->addAction(tmpAct);
|
||||||
|
const QVector<VColor> &bgColors = vconfig.getPredefinedColors();
|
||||||
|
for (int i = 0; i < bgColors.size(); ++i) {
|
||||||
|
tmpAct = new QAction(bgColors[i].name, backgroundColorAct);
|
||||||
|
tmpAct->setStatusTip(tr("Set background color for editor"));
|
||||||
|
tmpAct->setCheckable(true);
|
||||||
|
tmpAct->setData(bgColors[i].name);
|
||||||
|
tmpAct->setIcon(QIcon(predefinedColorPixmaps[i]));
|
||||||
|
if (curBgColor == bgColors[i].name) {
|
||||||
|
tmpAct->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
backgroundColorMenu->addAction(tmpAct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VMainWindow::setRenderBackgroundColor(QAction *action)
|
||||||
|
{
|
||||||
|
if (!action) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vconfig.setCurRenderBackgroundColor(action->data().toString());
|
||||||
|
vnote->updateTemplate();
|
||||||
|
}
|
||||||
|
@ -43,6 +43,7 @@ private slots:
|
|||||||
void changeExpandTab(bool checked);
|
void changeExpandTab(bool checked);
|
||||||
void setTabStopWidth(QAction *action);
|
void setTabStopWidth(QAction *action);
|
||||||
void setEditorBackgroundColor(QAction *action);
|
void setEditorBackgroundColor(QAction *action);
|
||||||
|
void setRenderBackgroundColor(QAction *action);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void curNotebookChanged(const QString ¬ebookName);
|
void curNotebookChanged(const QString ¬ebookName);
|
||||||
@ -54,6 +55,8 @@ private:
|
|||||||
void initMenuBar();
|
void initMenuBar();
|
||||||
bool isConflictWithExistingNotebooks(const QString &name);
|
bool isConflictWithExistingNotebooks(const QString &name);
|
||||||
void initPredefinedColorPixmaps();
|
void initPredefinedColorPixmaps();
|
||||||
|
void initRenderBackgroundMenu(QMenu *menu);
|
||||||
|
void initEditorBackgroundMenu(QMenu *menu);
|
||||||
|
|
||||||
// If true, comboBox changes will not trigger any signal out
|
// If true, comboBox changes will not trigger any signal out
|
||||||
bool notebookComboMuted;
|
bool notebookComboMuted;
|
||||||
@ -89,6 +92,7 @@ private:
|
|||||||
QAction *fourSpaceTabAct;
|
QAction *fourSpaceTabAct;
|
||||||
QAction *eightSpaceTabAct;
|
QAction *eightSpaceTabAct;
|
||||||
QActionGroup *backgroundColorAct;
|
QActionGroup *backgroundColorAct;
|
||||||
|
QActionGroup *renderBackgroundAct;
|
||||||
|
|
||||||
QVector<QPixmap> predefinedColorPixmaps;
|
QVector<QPixmap> predefinedColorPixmaps;
|
||||||
};
|
};
|
||||||
|
@ -16,24 +16,52 @@ QString VNote::postTemplateHtml;
|
|||||||
VNote::VNote() : QObject()
|
VNote::VNote() : QObject()
|
||||||
{
|
{
|
||||||
vconfig.initialize();
|
vconfig.initialize();
|
||||||
decorateTemplate();
|
initTemplate();
|
||||||
notebooks = vconfig.getNotebooks();
|
notebooks = vconfig.getNotebooks();
|
||||||
emit notebooksChanged(notebooks);
|
emit notebooksChanged(notebooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VNote::decorateTemplate()
|
void VNote::initTemplate()
|
||||||
{
|
{
|
||||||
if (templateHtml.isEmpty()) {
|
if (templateHtml.isEmpty() || preTemplateHtml.isEmpty()
|
||||||
|
|| postTemplateHtml.isEmpty()) {
|
||||||
|
updateTemplate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VNote::updateTemplate()
|
||||||
|
{
|
||||||
|
// Get background color
|
||||||
|
QString rgb;
|
||||||
|
const QString &curRenderBg = vconfig.getCurRenderBackgroundColor();
|
||||||
|
const QVector<VColor> &predefinedColors = vconfig.getPredefinedColors();
|
||||||
|
if (curRenderBg != "System") {
|
||||||
|
for (int i = 0; i < predefinedColors.size(); ++i) {
|
||||||
|
if (predefinedColors[i].name == curRenderBg) {
|
||||||
|
rgb = predefinedColors[i].rgb;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QString cssStyle;
|
||||||
|
if (!rgb.isEmpty()) {
|
||||||
|
cssStyle = "body { background-color: #" + rgb + "; }";
|
||||||
|
}
|
||||||
|
QString styleHolder("<!-- BACKGROUND_PLACE_HOLDER -->");
|
||||||
|
QString cssHolder("CSS_PLACE_HOLDER");
|
||||||
templateHtml = VUtils::readFileFromDisk(vconfig.getTemplatePath());
|
templateHtml = VUtils::readFileFromDisk(vconfig.getTemplatePath());
|
||||||
templateHtml.replace("CSS_PLACE_HOLDER", vconfig.getTemplateCssUrl());
|
templateHtml.replace(cssHolder, vconfig.getTemplateCssUrl());
|
||||||
|
if (!cssStyle.isEmpty()) {
|
||||||
|
templateHtml.replace(styleHolder, cssStyle);
|
||||||
}
|
}
|
||||||
if (preTemplateHtml.isEmpty()) {
|
|
||||||
preTemplateHtml = VUtils::readFileFromDisk(vconfig.getPreTemplatePath());
|
preTemplateHtml = VUtils::readFileFromDisk(vconfig.getPreTemplatePath());
|
||||||
preTemplateHtml.replace("CSS_PLACE_HOLDER", vconfig.getTemplateCssUrl());
|
preTemplateHtml.replace(cssHolder, vconfig.getTemplateCssUrl());
|
||||||
|
if (!cssStyle.isEmpty()) {
|
||||||
|
preTemplateHtml.replace(styleHolder, cssStyle);
|
||||||
}
|
}
|
||||||
if (postTemplateHtml.isEmpty()) {
|
|
||||||
postTemplateHtml = VUtils::readFileFromDisk(vconfig.getPostTemplatePath());
|
postTemplateHtml = VUtils::readFileFromDisk(vconfig.getPostTemplatePath());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<VNotebook>& VNote::getNotebooks()
|
const QVector<VNotebook>& VNote::getNotebooks()
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
const QVector<VNotebook>& getNotebooks();
|
const QVector<VNotebook>& getNotebooks();
|
||||||
|
|
||||||
static void decorateTemplate();
|
void initTemplate();
|
||||||
|
|
||||||
// Used by Marked
|
// Used by Marked
|
||||||
static QString templateHtml;
|
static QString templateHtml;
|
||||||
@ -31,6 +31,9 @@ public:
|
|||||||
void removeNotebook(const QString &name);
|
void removeNotebook(const QString &name);
|
||||||
void renameNotebook(const QString &name, const QString &newName);
|
void renameNotebook(const QString &name, const QString &newName);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateTemplate();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// Force to do a fully update
|
// Force to do a fully update
|
||||||
void notebooksChanged(const QVector<VNotebook> ¬ebooks);
|
void notebooksChanged(const QVector<VNotebook> ¬ebooks);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user