support auto bracket and overridding font family

This commit is contained in:
Le Tan 2021-06-04 20:34:07 +08:00
parent f80fe2629a
commit 7c768c446b
11 changed files with 95 additions and 6 deletions

@ -1 +1 @@
Subproject commit 32678afe91f4ad15acb4f4d24d92e1fa61bb1df7
Subproject commit c3889fc666816ae64d5a71b4c7bcd8fccb15b45f

View File

@ -93,6 +93,8 @@ namespace vnotex
void setSpellCheckDefaultDictionary(const QString &p_dict);
private:
friend class MainConfig;
void loadCore(const QJsonObject &p_app, const QJsonObject &p_user);
QJsonObject saveCore() const;

View File

@ -123,4 +123,8 @@ void MainConfig::doVersionSpecificOverride()
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::LocationListDock] = "Ctrl+G, L";
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::NewWorkspace] = "Ctrl+G, M";
m_coreConfig->writeToSettings();
m_editorConfig->m_shortcuts[EditorConfig::Shortcut::TypeMath] = "Ctrl+.";
m_editorConfig->m_shortcuts[EditorConfig::Shortcut::TypeMathBlock] = "Ctrl+G, .";
m_editorConfig->writeToSettings();
}

View File

@ -62,6 +62,8 @@ void MarkdownEditorConfig::init(const QJsonObject &p_app, const QJsonObject &p_u
m_smartTableInterval = READINT(QStringLiteral("smart_table_interval"));
m_spellCheckEnabled = READBOOL(QStringLiteral("spell_check"));
m_editorOverriddenFontFamily = READSTR(QStringLiteral("editor_overridden_font_family"));
}
QJsonObject MarkdownEditorConfig::toJson() const
@ -94,6 +96,7 @@ QJsonObject MarkdownEditorConfig::toJson() const
obj[QStringLiteral("smart_table")] = m_smartTableEnabled;
obj[QStringLiteral("smart_table_interval")] = m_smartTableInterval;
obj[QStringLiteral("spell_check")] = m_spellCheckEnabled;
obj[QStringLiteral("editor_overridden_font_family")] = m_editorOverriddenFontFamily;
return obj;
}
@ -430,3 +433,13 @@ void MarkdownEditorConfig::setSpellCheckEnabled(bool p_enabled)
{
updateConfig(m_spellCheckEnabled, p_enabled, this);
}
const QString &MarkdownEditorConfig::getEditorOverriddenFontFamily() const
{
return m_editorOverriddenFontFamily;
}
void MarkdownEditorConfig::setEditorOverriddenFontFamily(const QString &p_family)
{
updateConfig(m_editorOverriddenFontFamily, p_family, this);
}

View File

@ -112,6 +112,9 @@ namespace vnotex
bool isSpellCheckEnabled() const;
void setSpellCheckEnabled(bool p_enabled);
const QString &getEditorOverriddenFontFamily() const;
void setEditorOverriddenFontFamily(const QString &p_family);
private:
QString sectionNumberModeToString(SectionNumberMode p_mode) const;
SectionNumberMode stringToSectionNumberMode(const QString &p_str) const;
@ -197,6 +200,9 @@ namespace vnotex
// Override the config in TextEditorConfig.
bool m_spellCheckEnabled = true;
// Font family to override the editor's theme.
QString m_editorOverriddenFontFamily;
};
}

View File

@ -83,8 +83,8 @@
"TypeOrderedList" : "Ctrl+9",
"TypeCode" : "Ctrl+;",
"TypeCodeBlock" : "Ctrl+'",
"TypeMath" : "Ctrl+,",
"TypeMathBlock" : "Ctrl+.",
"TypeMath" : "Ctrl+.",
"TypeMathBlock" : "Ctrl+G, .",
"TypeTable" : "Ctrl+/",
"TypeMark" : "Ctrl+G, M",
"Outline" : "Ctrl+G, O",
@ -114,7 +114,7 @@
"spell_check": false
},
"markdown_editor" : {
"override_viewer_resource" : true,
"override_viewer_resource" : false,
"viewer_resource" : {
"template" : "web/markdown-viewer-template.html",
"resources" : [
@ -318,7 +318,8 @@
"smart_table" : true,
"//comment" : "Time interval (milliseconds) to do smart table formatting",
"smart_table_interval" : 1000,
"spell_check" : true
"spell_check" : true,
"editor_overridden_font_family" : ""
}
},
"widget" : {

View File

@ -10,6 +10,8 @@
#include <QHBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QFontComboBox>
#include <QFont>
#include <widgets/widgetsfactory.h>
#include <core/editorconfig.h>
@ -96,6 +98,16 @@ void MarkdownEditorPage::loadInternal()
}
m_graphvizFileInput->setText(markdownConfig.getGraphvizExe());
{
const auto &fontFamily = markdownConfig.getEditorOverriddenFontFamily();
m_editorOverriddenFontFamilyCheckBox->setChecked(!fontFamily.isEmpty());
if (!fontFamily.isEmpty()) {
QFont font;
font.setFamily(fontFamily);
m_editorOverriddenFontFamilyComboBox->setCurrentFont(font);
}
}
}
void MarkdownEditorPage::saveInternal()
@ -146,6 +158,11 @@ void MarkdownEditorPage::saveInternal()
markdownConfig.setGraphvizExe(m_graphvizFileInput->text());
{
bool checked = m_editorOverriddenFontFamilyCheckBox->isChecked();
markdownConfig.setEditorOverriddenFontFamily(checked ? m_editorOverriddenFontFamilyComboBox->currentFont().family() : QString());
}
EditorPage::notifyEditorConfigChange();
}
@ -281,6 +298,33 @@ QGroupBox *MarkdownEditorPage::setupEditGroup()
this, &MarkdownEditorPage::pageIsChanged);
}
{
auto fontLayout = new QHBoxLayout();
fontLayout->setContentsMargins(0, 0, 0, 0);
const QString label(tr("Override font"));
m_editorOverriddenFontFamilyCheckBox = WidgetsFactory::createCheckBox(label, box);
m_editorOverriddenFontFamilyCheckBox->setToolTip(tr("Override editor font family of theme"));
fontLayout->addWidget(m_editorOverriddenFontFamilyCheckBox);
addSearchItem(label, m_editorOverriddenFontFamilyCheckBox->toolTip(), m_editorOverriddenFontFamilyCheckBox);
m_editorOverriddenFontFamilyComboBox = new QFontComboBox(box);
m_editorOverriddenFontFamilyComboBox->setEnabled(false);
fontLayout->addWidget(m_editorOverriddenFontFamilyComboBox);
connect(m_editorOverriddenFontFamilyComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &MarkdownEditorPage::pageIsChanged);
fontLayout->addStretch();
connect(m_editorOverriddenFontFamilyCheckBox, &QCheckBox::stateChanged,
this, [this](int state) {
m_editorOverriddenFontFamilyComboBox->setEnabled(state == Qt::Checked);
emit pageIsChanged();
});
layout->addRow(fontLayout);
}
return box;
}
@ -291,6 +335,7 @@ QGroupBox *MarkdownEditorPage::setupGeneralGroup()
{
auto sectionLayout = new QHBoxLayout();
sectionLayout->setContentsMargins(0, 0, 0, 0);
m_sectionNumberComboBox = WidgetsFactory::createComboBox(box);
m_sectionNumberComboBox->setToolTip(tr("Section number mode"));
@ -305,6 +350,7 @@ QGroupBox *MarkdownEditorPage::setupGeneralGroup()
m_sectionNumberBaseLevelSpinBox->setToolTip(tr("Base level to start section numbering in edit mode"));
m_sectionNumberBaseLevelSpinBox->setRange(1, 6);
m_sectionNumberBaseLevelSpinBox->setSingleStep(1);
m_sectionNumberBaseLevelSpinBox->setEnabled(false);
sectionLayout->addWidget(m_sectionNumberBaseLevelSpinBox);
connect(m_sectionNumberBaseLevelSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &MarkdownEditorPage::pageIsChanged);
@ -313,6 +359,7 @@ QGroupBox *MarkdownEditorPage::setupGeneralGroup()
m_sectionNumberStyleComboBox->setToolTip(tr("Section number style"));
m_sectionNumberStyleComboBox->addItem(tr("1.1."), (int)MarkdownEditorConfig::SectionNumberStyle::DigDotDigDot);
m_sectionNumberStyleComboBox->addItem(tr("1.1"), (int)MarkdownEditorConfig::SectionNumberStyle::DigDotDig);
m_sectionNumberStyleComboBox->setEnabled(false);
sectionLayout->addWidget(m_sectionNumberStyleComboBox);
connect(m_sectionNumberStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &MarkdownEditorPage::pageIsChanged);
@ -344,6 +391,7 @@ QGroupBox *MarkdownEditorPage::setupGeneralGroup()
{
auto jarLayout = new QHBoxLayout();
jarLayout->setContentsMargins(0, 0, 0, 0);
m_plantUmlJarFileInput = new LocationInputWithBrowseButton(box);
m_plantUmlJarFileInput->setToolTip(tr("Local JAR file to render PlantUML graphs"));
@ -403,6 +451,7 @@ QGroupBox *MarkdownEditorPage::setupGeneralGroup()
{
auto fileLayout = new QHBoxLayout();
fileLayout->setContentsMargins(0, 0, 0, 0);
m_graphvizFileInput = new LocationInputWithBrowseButton(box);
m_graphvizFileInput->setToolTip(tr("Local executable file to render Graphviz graphs"));

View File

@ -8,6 +8,7 @@ class QGroupBox;
class QDoubleSpinBox;
class QSpinBox;
class QComboBox;
class QFontComboBox;
namespace vnotex
{
@ -70,6 +71,10 @@ namespace vnotex
QComboBox *m_graphvizModeComboBox = nullptr;
LocationInputWithBrowseButton *m_graphvizFileInput = nullptr;
QCheckBox *m_editorOverriddenFontFamilyCheckBox = nullptr;
QFontComboBox *m_editorOverriddenFontFamilyComboBox = nullptr;
};
}

View File

@ -34,8 +34,10 @@ void GraphvizHelper::prepareProgramAndArgs(const QString &p_graphvizFile,
QString &p_program,
QStringList &p_args)
{
p_program = p_graphvizFile.isEmpty() ? QStringLiteral("dot") : p_graphvizFile;
p_program.clear();
p_args.clear();
p_program = p_graphvizFile.isEmpty() ? QStringLiteral("dot") : p_graphvizFile;
}
QPair<bool, QString> GraphvizHelper::testGraphviz(const QString &p_graphvizFile)

View File

@ -45,6 +45,9 @@ void PlantUmlHelper::prepareProgramAndArgs(const QString &p_plantUmlJarFile,
QString &p_program,
QStringList &p_args)
{
p_program.clear();
p_args.clear();
#if defined(Q_OS_WIN)
p_program = "java";
#else

View File

@ -784,10 +784,14 @@ void MarkdownViewWindow::setupOutlineProvider()
QSharedPointer<vte::MarkdownEditorConfig> MarkdownViewWindow::createMarkdownEditorConfig(const MarkdownEditorConfig &p_config)
{
const auto &themeMgr = VNoteX::getInst().getThemeMgr();
auto textEditorConfig = TextViewWindowHelper::createTextEditorConfig(p_config.getTextEditorConfig(),
themeMgr.getFile(Theme::File::MarkdownEditorStyle),
themeMgr.getMarkdownEditorHighlightTheme());
auto editorConfig = QSharedPointer<vte::MarkdownEditorConfig>::create(textEditorConfig);
editorConfig->overrideTextFontFamily(p_config.getEditorOverriddenFontFamily());
editorConfig->m_constrainInPlacePreviewWidthEnabled = p_config.getConstrainInPlacePreviewWidthEnabled();
return editorConfig;
}