VSettingsDialog: add MathJax configuration and tool bar icon size configuration

This commit is contained in:
Le Tan 2018-05-02 20:02:18 +08:00
parent de678b5d6d
commit 0faf79b45b
7 changed files with 160 additions and 16 deletions

View File

@ -56,6 +56,7 @@ VSettingsDialog::VSettingsDialog(QWidget *p_parent)
// Add tabs. // Add tabs.
addTab(new VGeneralTab(), tr("General")); addTab(new VGeneralTab(), tr("General"));
addTab(new VLookTab(), tr("Appearance"));
addTab(new VReadEditTab(), tr("Read/Edit")); addTab(new VReadEditTab(), tr("Read/Edit"));
addTab(new VNoteManagementTab(), tr("Note Management")); addTab(new VNoteManagementTab(), tr("Note Management"));
addTab(new VMarkdownTab(), tr("Markdown")); addTab(new VMarkdownTab(), tr("Markdown"));
@ -144,18 +145,28 @@ void VSettingsDialog::addTab(QWidget *p_widget, const QString &p_label)
void VSettingsDialog::loadConfiguration() void VSettingsDialog::loadConfiguration()
{ {
int idx = 0;
// General Tab. // General Tab.
{ {
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0)); VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(idx++));
Q_ASSERT(generalTab); Q_ASSERT(generalTab);
if (!generalTab->loadConfiguration()) { if (!generalTab->loadConfiguration()) {
goto err; goto err;
} }
} }
// Appearance Tab.
{
VLookTab *lookTab = dynamic_cast<VLookTab *>(m_tabs->widget(idx++));
Q_ASSERT(lookTab);
if (!lookTab->loadConfiguration()) {
goto err;
}
}
// Read/Edit Tab. // Read/Edit Tab.
{ {
VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(1)); VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(idx++));
Q_ASSERT(readEditTab); Q_ASSERT(readEditTab);
if (!readEditTab->loadConfiguration()) { if (!readEditTab->loadConfiguration()) {
goto err; goto err;
@ -164,7 +175,7 @@ void VSettingsDialog::loadConfiguration()
// Note Management Tab. // Note Management Tab.
{ {
VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(2)); VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(idx++));
Q_ASSERT(noteManagementTab); Q_ASSERT(noteManagementTab);
if (!noteManagementTab->loadConfiguration()) { if (!noteManagementTab->loadConfiguration()) {
goto err; goto err;
@ -173,7 +184,7 @@ void VSettingsDialog::loadConfiguration()
// Markdown Tab. // Markdown Tab.
{ {
VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(3)); VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(idx++));
Q_ASSERT(markdownTab); Q_ASSERT(markdownTab);
if (!markdownTab->loadConfiguration()) { if (!markdownTab->loadConfiguration()) {
goto err; goto err;
@ -190,18 +201,28 @@ err:
void VSettingsDialog::saveConfiguration() void VSettingsDialog::saveConfiguration()
{ {
int idx = 0;
// General Tab. // General Tab.
{ {
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0)); VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(idx++));
Q_ASSERT(generalTab); Q_ASSERT(generalTab);
if (!generalTab->saveConfiguration()) { if (!generalTab->saveConfiguration()) {
goto err; goto err;
} }
} }
// Appearance Tab.
{
VLookTab *lookTab = dynamic_cast<VLookTab *>(m_tabs->widget(idx++));
Q_ASSERT(lookTab);
if (!lookTab->saveConfiguration()) {
goto err;
}
}
// Read/Edit Tab. // Read/Edit Tab.
{ {
VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(1)); VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(idx++));
Q_ASSERT(readEditTab); Q_ASSERT(readEditTab);
if (!readEditTab->saveConfiguration()) { if (!readEditTab->saveConfiguration()) {
goto err; goto err;
@ -210,7 +231,7 @@ void VSettingsDialog::saveConfiguration()
// Note Management Tab. // Note Management Tab.
{ {
VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(2)); VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(idx++));
Q_ASSERT(noteManagementTab); Q_ASSERT(noteManagementTab);
if (!noteManagementTab->saveConfiguration()) { if (!noteManagementTab->saveConfiguration()) {
goto err; goto err;
@ -219,7 +240,7 @@ void VSettingsDialog::saveConfiguration()
// Markdown Tab. // Markdown Tab.
{ {
VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(3)); VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(idx++));
Q_ASSERT(markdownTab); Q_ASSERT(markdownTab);
if (!markdownTab->saveConfiguration()) { if (!markdownTab->saveConfiguration()) {
goto err; goto err;
@ -443,6 +464,51 @@ bool VGeneralTab::saveStartupPageType()
return true; return true;
} }
VLookTab::VLookTab(QWidget *p_parent)
: QWidget(p_parent)
{
m_tbIconSizeSpin = new QSpinBox(this);
m_tbIconSizeSpin->setToolTip(tr("Icon size in pixel of tool bar (restart VNote to make it work)"));
m_tbIconSizeSpin->setMaximum(100);
m_tbIconSizeSpin->setMinimum(5);
QFormLayout *layout = new QFormLayout();
layout->addRow(tr("Tool bar icon size:"), m_tbIconSizeSpin);
setLayout(layout);
}
bool VLookTab::loadConfiguration()
{
if (!loadToolBarIconSize()) {
return false;
}
return true;
}
bool VLookTab::saveConfiguration()
{
if (!saveToolBarIconSize()) {
return false;
}
return true;
}
bool VLookTab::loadToolBarIconSize()
{
int sz = g_config->getToolBarIconSize();
m_tbIconSizeSpin->setValue(sz);
return true;
}
bool VLookTab::saveToolBarIconSize()
{
g_config->setToolBarIconSize(m_tbIconSizeSpin->value());
return true;
}
VReadEditTab::VReadEditTab(QWidget *p_parent) VReadEditTab::VReadEditTab(QWidget *p_parent)
: QWidget(p_parent) : QWidget(p_parent)
{ {
@ -899,6 +965,11 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent)
QLabel *colorColumnLabel = new QLabel(tr("Color column:")); QLabel *colorColumnLabel = new QLabel(tr("Color column:"));
colorColumnLabel->setToolTip(m_colorColumnEdit->toolTip()); colorColumnLabel->setToolTip(m_colorColumnEdit->toolTip());
// MathJax.
m_mathjaxConfigEdit = new VLineEdit();
m_mathjaxConfigEdit->setToolTip(tr("Location of MathJax JavaScript and its configuration "
"(restart VNote to make it work in in-place preview)"));
// PlantUML. // PlantUML.
m_plantUMLModeCombo = VUtils::getComboBox(); m_plantUMLModeCombo = VUtils::getComboBox();
m_plantUMLModeCombo->setToolTip(tr("Enable PlantUML support in Markdown")); m_plantUMLModeCombo->setToolTip(tr("Enable PlantUML support in Markdown"));
@ -924,6 +995,7 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent)
mainLayout->addRow(tr("Note open mode:"), m_openModeCombo); mainLayout->addRow(tr("Note open mode:"), m_openModeCombo);
mainLayout->addRow(tr("Heading sequence:"), headingSequenceLayout); mainLayout->addRow(tr("Heading sequence:"), headingSequenceLayout);
mainLayout->addRow(colorColumnLabel, m_colorColumnEdit); mainLayout->addRow(colorColumnLabel, m_colorColumnEdit);
mainLayout->addRow(tr("MathJax configuration:"), m_mathjaxConfigEdit);
mainLayout->addRow(tr("PlantUML:"), m_plantUMLModeCombo); mainLayout->addRow(tr("PlantUML:"), m_plantUMLModeCombo);
mainLayout->addRow(tr("PlantUML server:"), m_plantUMLServerEdit); mainLayout->addRow(tr("PlantUML server:"), m_plantUMLServerEdit);
mainLayout->addRow(tr("PlantUML JAR:"), m_plantUMLJarEdit); mainLayout->addRow(tr("PlantUML JAR:"), m_plantUMLJarEdit);
@ -947,6 +1019,10 @@ bool VMarkdownTab::loadConfiguration()
return false; return false;
} }
if (!loadMathJax()) {
return false;
}
if (!loadPlantUML()) { if (!loadPlantUML()) {
return false; return false;
} }
@ -972,6 +1048,10 @@ bool VMarkdownTab::saveConfiguration()
return false; return false;
} }
if (!saveMathJax()) {
return false;
}
if (!savePlantUML()) { if (!savePlantUML()) {
return false; return false;
} }
@ -1051,6 +1131,18 @@ bool VMarkdownTab::saveColorColumn()
return true; return true;
} }
bool VMarkdownTab::loadMathJax()
{
m_mathjaxConfigEdit->setText(g_config->getMathjaxJavascript());
return true;
}
bool VMarkdownTab::saveMathJax()
{
g_config->setMathjaxJavascript(m_mathjaxConfigEdit->text());
return true;
}
bool VMarkdownTab::loadPlantUML() bool VMarkdownTab::loadPlantUML()
{ {
m_plantUMLModeCombo->setCurrentIndex(m_plantUMLModeCombo->findData(g_config->getPlantUMLMode())); m_plantUMLModeCombo->setCurrentIndex(m_plantUMLModeCombo->findData(g_config->getPlantUMLMode()));

View File

@ -9,6 +9,7 @@ class QDialogButtonBox;
class QComboBox; class QComboBox;
class QGroupBox; class QGroupBox;
class QDoubleSpinBox; class QDoubleSpinBox;
class QSpinBox;
class QCheckBox; class QCheckBox;
class VLineEdit; class VLineEdit;
class QStackedLayout; class QStackedLayout;
@ -54,6 +55,22 @@ private:
static const QVector<QString> c_availableLangs; static const QVector<QString> c_availableLangs;
}; };
class VLookTab: public QWidget
{
Q_OBJECT
public:
explicit VLookTab(QWidget *p_parent = 0);
bool loadConfiguration();
bool saveConfiguration();
private:
bool loadToolBarIconSize();
bool saveToolBarIconSize();
// Tool bar icon size.
QSpinBox *m_tbIconSizeSpin;
};
class VReadEditTab : public QWidget class VReadEditTab : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -157,6 +174,9 @@ private:
bool loadColorColumn(); bool loadColorColumn();
bool saveColorColumn(); bool saveColorColumn();
bool loadMathJax();
bool saveMathJax();
bool loadPlantUML(); bool loadPlantUML();
bool savePlantUML(); bool savePlantUML();
@ -173,6 +193,9 @@ private:
// Color column in code block. // Color column in code block.
VLineEdit *m_colorColumnEdit; VLineEdit *m_colorColumnEdit;
// MathJax.
VLineEdit *m_mathjaxConfigEdit;
// PlantUML. // PlantUML.
QComboBox *m_plantUMLModeCombo; QComboBox *m_plantUMLModeCombo;
VLineEdit *m_plantUMLServerEdit; VLineEdit *m_plantUMLServerEdit;

View File

@ -105,8 +105,8 @@ Expand the selection to the beginning or end of current line.
- `Ctrl+Shift+Home`, `Ctrl+Shift+End` - `Ctrl+Shift+Home`, `Ctrl+Shift+End`
Expand the selection to the beginning or end of current note. Expand the selection to the beginning or end of current note.
## Custom Shortcuts ## Customize Shortcuts
VNote supports customing some standard shortcuts, though it is not recommended. VNote stores shortcuts' configuration information in the `[shortcuts]` and `[captain_mode_shortcuts]` sections of user configuration file `vnote.ini`. VNote supports customizing some standard shortcuts, though it is not recommended. VNote stores shortcuts' configuration information in the `[shortcuts]` and `[captain_mode_shortcuts]` sections of user configuration file `vnote.ini`.
For example, the default configruation may look like this: For example, the default configruation may look like this:
@ -114,7 +114,7 @@ For example, the default configruation may look like this:
[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.
; Custom shortcuts may conflict with some key bindings in edit mode or Vim mode. ; Customized shortcuts may conflict with some key bindings in edit mode or Vim mode.
; Ctrl+Q is reserved for quitting VNote. ; Ctrl+Q is reserved for quitting VNote.
; Leader key of Captain mode ; Leader key of Captain mode

View File

@ -1,5 +1,5 @@
# Custom Shortcuts # Customize Shortcuts
VNote supports customing some standard shortcuts, though it is not recommended. VNote stores shortcuts' configuration information in the `[shortcuts]` and `[captain_mode_shortcuts]` sections of user configuration file `vnote.ini`. VNote supports customizing some standard shortcuts, though it is not recommended. VNote stores shortcuts' configuration information in the `[shortcuts]` and `[captain_mode_shortcuts]` sections of user configuration file `vnote.ini`.
For example, the default configruation may look like this: For example, the default configruation may look like this:
@ -7,7 +7,7 @@ For example, the default configruation may look like this:
[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.
; Custom shortcuts may conflict with some key bindings in edit mode or Vim mode. ; Customized shortcuts may conflict with some key bindings in edit mode or Vim mode.
; Ctrl+Q is reserved for quitting VNote. ; Ctrl+Q is reserved for quitting VNote.
; Leader key of Captain mode ; Leader key of Captain mode

View File

@ -287,7 +287,7 @@ graphviz_dot=
[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.
; Custom shortcuts may conflict with some key bindings in edit mode or Vim mode. ; Customized shortcuts may conflict with some key bindings in edit mode or Vim mode.
; Ctrl+Q is reserved for quitting VNote. ; Ctrl+Q is reserved for quitting VNote.
; Leader key of Captain mode ; Leader key of Captain mode

View File

@ -324,6 +324,7 @@ public:
void setEnableCodeBlockLineNumber(bool p_enabled); void setEnableCodeBlockLineNumber(bool p_enabled);
int getToolBarIconSize() const; int getToolBarIconSize() const;
void setToolBarIconSize(int p_size);
const MarkdownitOption &getMarkdownitOption() const; const MarkdownitOption &getMarkdownitOption() const;
void setMarkdownitOption(const MarkdownitOption &p_opt); void setMarkdownitOption(const MarkdownitOption &p_opt);
@ -339,6 +340,7 @@ public:
void setConfirmReloadFolder(bool p_enabled); void setConfirmReloadFolder(bool p_enabled);
const QString &getMathjaxJavascript() const; const QString &getMathjaxJavascript() const;
void setMathjaxJavascript(const QString &p_js);
bool getDoubleClickCloseTab() const; bool getDoubleClickCloseTab() const;
@ -1860,6 +1862,17 @@ inline int VConfigManager::getToolBarIconSize() const
return m_toolBarIconSize; return m_toolBarIconSize;
} }
inline void VConfigManager::setToolBarIconSize(int p_size)
{
if (m_toolBarIconSize == p_size) {
return;
}
m_toolBarIconSize = p_size;
setConfigToSettings("global",
"tool_bar_icon_size",
m_toolBarIconSize);
}
inline const MarkdownitOption &VConfigManager::getMarkdownitOption() const inline const MarkdownitOption &VConfigManager::getMarkdownitOption() const
{ {
return m_markdownItOpt; return m_markdownItOpt;
@ -1924,6 +1937,22 @@ inline const QString &VConfigManager::getMathjaxJavascript() const
return m_mathjaxJavascript; return m_mathjaxJavascript;
} }
inline void VConfigManager::setMathjaxJavascript(const QString &p_js)
{
if (m_mathjaxJavascript == p_js) {
return;
}
if (p_js.isEmpty()) {
m_mathjaxJavascript = resetDefaultConfig("web", "mathjax_javascript").toString();
} else {
m_mathjaxJavascript = p_js;
setConfigToSettings("web",
"mathjax_javascript",
m_mathjaxJavascript);
}
}
inline bool VConfigManager::getDoubleClickCloseTab() const inline bool VConfigManager::getDoubleClickCloseTab() const
{ {
return m_doubleClickCloseTab; return m_doubleClickCloseTab;

View File

@ -3073,7 +3073,7 @@ void VMainWindow::initThemeMenu(QMenu *p_menu)
void VMainWindow::customShortcut() void VMainWindow::customShortcut()
{ {
VTipsDialog dialog(VUtils::getDocFile("tips_custom_shortcut.md"), VTipsDialog dialog(VUtils::getDocFile("tips_custom_shortcut.md"),
tr("Custom Shortcuts"), tr("Customize Shortcuts"),
[]() { []() {
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) #if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
// On macOS, it seems that we could not open that ini file directly. // On macOS, it seems that we could not open that ini file directly.