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.
addTab(new VGeneralTab(), tr("General"));
addTab(new VLookTab(), tr("Appearance"));
addTab(new VReadEditTab(), tr("Read/Edit"));
addTab(new VNoteManagementTab(), tr("Note Management"));
addTab(new VMarkdownTab(), tr("Markdown"));
@ -144,18 +145,28 @@ void VSettingsDialog::addTab(QWidget *p_widget, const QString &p_label)
void VSettingsDialog::loadConfiguration()
{
int idx = 0;
// General Tab.
{
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(idx++));
Q_ASSERT(generalTab);
if (!generalTab->loadConfiguration()) {
goto err;
}
}
// Appearance Tab.
{
VLookTab *lookTab = dynamic_cast<VLookTab *>(m_tabs->widget(idx++));
Q_ASSERT(lookTab);
if (!lookTab->loadConfiguration()) {
goto err;
}
}
// Read/Edit Tab.
{
VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(1));
VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(idx++));
Q_ASSERT(readEditTab);
if (!readEditTab->loadConfiguration()) {
goto err;
@ -164,7 +175,7 @@ void VSettingsDialog::loadConfiguration()
// Note Management Tab.
{
VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(2));
VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(idx++));
Q_ASSERT(noteManagementTab);
if (!noteManagementTab->loadConfiguration()) {
goto err;
@ -173,7 +184,7 @@ void VSettingsDialog::loadConfiguration()
// Markdown Tab.
{
VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(3));
VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(idx++));
Q_ASSERT(markdownTab);
if (!markdownTab->loadConfiguration()) {
goto err;
@ -190,18 +201,28 @@ err:
void VSettingsDialog::saveConfiguration()
{
int idx = 0;
// General Tab.
{
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(idx++));
Q_ASSERT(generalTab);
if (!generalTab->saveConfiguration()) {
goto err;
}
}
// Appearance Tab.
{
VLookTab *lookTab = dynamic_cast<VLookTab *>(m_tabs->widget(idx++));
Q_ASSERT(lookTab);
if (!lookTab->saveConfiguration()) {
goto err;
}
}
// Read/Edit Tab.
{
VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(1));
VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(idx++));
Q_ASSERT(readEditTab);
if (!readEditTab->saveConfiguration()) {
goto err;
@ -210,7 +231,7 @@ void VSettingsDialog::saveConfiguration()
// Note Management Tab.
{
VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(2));
VNoteManagementTab *noteManagementTab = dynamic_cast<VNoteManagementTab *>(m_tabs->widget(idx++));
Q_ASSERT(noteManagementTab);
if (!noteManagementTab->saveConfiguration()) {
goto err;
@ -219,7 +240,7 @@ void VSettingsDialog::saveConfiguration()
// Markdown Tab.
{
VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(3));
VMarkdownTab *markdownTab = dynamic_cast<VMarkdownTab *>(m_tabs->widget(idx++));
Q_ASSERT(markdownTab);
if (!markdownTab->saveConfiguration()) {
goto err;
@ -443,6 +464,51 @@ bool VGeneralTab::saveStartupPageType()
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)
: QWidget(p_parent)
{
@ -899,6 +965,11 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent)
QLabel *colorColumnLabel = new QLabel(tr("Color column:"));
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.
m_plantUMLModeCombo = VUtils::getComboBox();
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("Heading sequence:"), headingSequenceLayout);
mainLayout->addRow(colorColumnLabel, m_colorColumnEdit);
mainLayout->addRow(tr("MathJax configuration:"), m_mathjaxConfigEdit);
mainLayout->addRow(tr("PlantUML:"), m_plantUMLModeCombo);
mainLayout->addRow(tr("PlantUML server:"), m_plantUMLServerEdit);
mainLayout->addRow(tr("PlantUML JAR:"), m_plantUMLJarEdit);
@ -947,6 +1019,10 @@ bool VMarkdownTab::loadConfiguration()
return false;
}
if (!loadMathJax()) {
return false;
}
if (!loadPlantUML()) {
return false;
}
@ -972,6 +1048,10 @@ bool VMarkdownTab::saveConfiguration()
return false;
}
if (!saveMathJax()) {
return false;
}
if (!savePlantUML()) {
return false;
}
@ -1051,6 +1131,18 @@ bool VMarkdownTab::saveColorColumn()
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()
{
m_plantUMLModeCombo->setCurrentIndex(m_plantUMLModeCombo->findData(g_config->getPlantUMLMode()));

View File

@ -9,6 +9,7 @@ class QDialogButtonBox;
class QComboBox;
class QGroupBox;
class QDoubleSpinBox;
class QSpinBox;
class QCheckBox;
class VLineEdit;
class QStackedLayout;
@ -54,6 +55,22 @@ private:
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
{
Q_OBJECT
@ -157,6 +174,9 @@ private:
bool loadColorColumn();
bool saveColorColumn();
bool loadMathJax();
bool saveMathJax();
bool loadPlantUML();
bool savePlantUML();
@ -173,6 +193,9 @@ private:
// Color column in code block.
VLineEdit *m_colorColumnEdit;
// MathJax.
VLineEdit *m_mathjaxConfigEdit;
// PlantUML.
QComboBox *m_plantUMLModeCombo;
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`
Expand the selection to the beginning or end of current note.
## Custom 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`.
## Customize Shortcuts
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:
@ -114,7 +114,7 @@ For example, the default configruation may look like this:
[shortcuts]
; Define shortcuts here, with each item in the form "operation=keysequence".
; 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.
; Leader key of Captain mode

View File

@ -1,5 +1,5 @@
# Custom 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`.
# Customize Shortcuts
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:
@ -7,7 +7,7 @@ For example, the default configruation may look like this:
[shortcuts]
; Define shortcuts here, with each item in the form "operation=keysequence".
; 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.
; Leader key of Captain mode

View File

@ -287,7 +287,7 @@ graphviz_dot=
[shortcuts]
; Define shortcuts here, with each item in the form "operation=keysequence".
; 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.
; Leader key of Captain mode

View File

@ -324,6 +324,7 @@ public:
void setEnableCodeBlockLineNumber(bool p_enabled);
int getToolBarIconSize() const;
void setToolBarIconSize(int p_size);
const MarkdownitOption &getMarkdownitOption() const;
void setMarkdownitOption(const MarkdownitOption &p_opt);
@ -339,6 +340,7 @@ public:
void setConfirmReloadFolder(bool p_enabled);
const QString &getMathjaxJavascript() const;
void setMathjaxJavascript(const QString &p_js);
bool getDoubleClickCloseTab() const;
@ -1860,6 +1862,17 @@ inline int VConfigManager::getToolBarIconSize() const
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
{
return m_markdownItOpt;
@ -1924,6 +1937,22 @@ inline const QString &VConfigManager::getMathjaxJavascript() const
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
{
return m_doubleClickCloseTab;

View File

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