| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- #include "markdowneditorpage.h"
- #include <QFormLayout>
- #include <QVBoxLayout>
- #include <QCheckBox>
- #include <QGroupBox>
- #include <QDoubleSpinBox>
- #include <QComboBox>
- #include <QSpinBox>
- #include <QHBoxLayout>
- #include <widgets/widgetsfactory.h>
- #include <core/editorconfig.h>
- #include <core/markdowneditorconfig.h>
- #include <core/configmgr.h>
- #include <utils/widgetutils.h>
- #include "editorpage.h"
- using namespace vnotex;
- MarkdownEditorPage::MarkdownEditorPage(QWidget *p_parent)
- : SettingsPage(p_parent)
- {
- setupUI();
- }
- void MarkdownEditorPage::setupUI()
- {
- auto mainLayout = new QVBoxLayout(this);
- auto generalBox = setupGeneralGroup();
- mainLayout->addWidget(generalBox);
- auto readBox = setupReadGroup();
- mainLayout->addWidget(readBox);
- auto editBox = setupEditGroup();
- mainLayout->addWidget(editBox);
- }
- void MarkdownEditorPage::loadInternal()
- {
- const auto &markdownConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
- m_insertFileNameAsTitleCheckBox->setChecked(markdownConfig.getInsertFileNameAsTitle());
- {
- int idx = m_sectionNumberComboBox->findData(static_cast<int>(markdownConfig.getSectionNumberMode()));
- Q_ASSERT(idx != -1);
- m_sectionNumberComboBox->setCurrentIndex(idx);
- m_sectionNumberBaseLevelSpinBox->setValue(markdownConfig.getSectionNumberBaseLevel());
- idx = m_sectionNumberStyleComboBox->findData(static_cast<int>(markdownConfig.getSectionNumberStyle()));
- Q_ASSERT(idx != -1);
- m_sectionNumberStyleComboBox->setCurrentIndex(idx);
- }
- m_constrainImageWidthCheckBox->setChecked(markdownConfig.getConstrainImageWidthEnabled());
- m_zoomFactorSpinBox->setValue(markdownConfig.getZoomFactorInReadMode());
- m_constrainInPlacePreviewWidthCheckBox->setChecked(markdownConfig.getConstrainInPlacePreviewWidthEnabled());
- m_fetchImagesToLocalCheckBox->setChecked(markdownConfig.getFetchImagesInParseAndPaste());
- m_htmlTagCheckBox->setChecked(markdownConfig.getHtmlTagEnabled());
- m_autoBreakCheckBox->setChecked(markdownConfig.getAutoBreakEnabled());
- m_linkifyCheckBox->setChecked(markdownConfig.getLinkifyEnabled());
- m_indentFirstLineCheckBox->setChecked(markdownConfig.getIndentFirstLineEnabled());
- m_smartTableCheckBox->setChecked(markdownConfig.getSmartTableEnabled());
- m_spellCheckCheckBox->setChecked(markdownConfig.isSpellCheckEnabled());
- }
- void MarkdownEditorPage::saveInternal()
- {
- auto &markdownConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
- markdownConfig.setInsertFileNameAsTitle(m_insertFileNameAsTitleCheckBox->isChecked());
- {
- auto mode = m_sectionNumberComboBox->currentData().toInt();
- markdownConfig.setSectionNumberMode(static_cast<MarkdownEditorConfig::SectionNumberMode>(mode));
- if (m_sectionNumberBaseLevelSpinBox->isEnabled()) {
- markdownConfig.setSectionNumberBaseLevel(m_sectionNumberBaseLevelSpinBox->value());
- }
- if (m_sectionNumberStyleComboBox->isEnabled()) {
- auto style = m_sectionNumberStyleComboBox->currentData().toInt();
- markdownConfig.setSectionNumberStyle(static_cast<MarkdownEditorConfig::SectionNumberStyle>(style));
- }
- }
- markdownConfig.setConstrainImageWidthEnabled(m_constrainImageWidthCheckBox->isChecked());
- markdownConfig.setZoomFactorInReadMode(m_zoomFactorSpinBox->value());
- markdownConfig.setConstrainInPlacePreviewWidthEnabled(m_constrainInPlacePreviewWidthCheckBox->isChecked());
- markdownConfig.setFetchImagesInParseAndPaste(m_fetchImagesToLocalCheckBox->isChecked());
- markdownConfig.setHtmlTagEnabled(m_htmlTagCheckBox->isChecked());
- markdownConfig.setAutoBreakEnabled(m_autoBreakCheckBox->isChecked());
- markdownConfig.setLinkifyEnabled(m_linkifyCheckBox->isChecked());
- markdownConfig.setIndentFirstLineEnabled(m_indentFirstLineCheckBox->isChecked());
- markdownConfig.setSmartTableEnabled(m_smartTableCheckBox->isChecked());
- markdownConfig.setSpellCheckEnabled(m_spellCheckCheckBox->isChecked());
- EditorPage::notifyEditorConfigChange();
- }
- QString MarkdownEditorPage::title() const
- {
- return tr("Markdown Editor");
- }
- QGroupBox *MarkdownEditorPage::setupReadGroup()
- {
- auto box = new QGroupBox(tr("Read"), this);
- auto layout = WidgetsFactory::createFormLayout(box);
- {
- const QString label(tr("Constrain image width"));
- m_constrainImageWidthCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_constrainImageWidthCheckBox->setToolTip(tr("Constrain image width to the window"));
- layout->addRow(m_constrainImageWidthCheckBox);
- addSearchItem(label, m_constrainImageWidthCheckBox->toolTip(), m_constrainImageWidthCheckBox);
- connect(m_constrainImageWidthCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- m_zoomFactorSpinBox = WidgetsFactory::createDoubleSpinBox(box);
- m_zoomFactorSpinBox->setToolTip(tr("Zoom factor in read mode"));
- m_zoomFactorSpinBox->setRange(0.1, 10);
- m_zoomFactorSpinBox->setSingleStep(0.1);
- const QString label(tr("Zoom factor:"));
- layout->addRow(label, m_zoomFactorSpinBox);
- addSearchItem(label, m_zoomFactorSpinBox->toolTip(), m_zoomFactorSpinBox);
- connect(m_zoomFactorSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("HTML tag"));
- m_htmlTagCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_htmlTagCheckBox->setToolTip(tr("Allow HTML tags in source"));
- layout->addRow(m_htmlTagCheckBox);
- addSearchItem(label, m_htmlTagCheckBox->toolTip(), m_htmlTagCheckBox);
- connect(m_htmlTagCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Auto break"));
- m_autoBreakCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_autoBreakCheckBox->setToolTip(tr("Automatically break a line with '\\n'"));
- layout->addRow(m_autoBreakCheckBox);
- addSearchItem(label, m_autoBreakCheckBox->toolTip(), m_autoBreakCheckBox);
- connect(m_autoBreakCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Linkify"));
- m_linkifyCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_linkifyCheckBox->setToolTip(tr("Convert URL-like text to links"));
- layout->addRow(m_linkifyCheckBox);
- addSearchItem(label, m_linkifyCheckBox->toolTip(), m_linkifyCheckBox);
- connect(m_linkifyCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Indent first line"));
- m_indentFirstLineCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_indentFirstLineCheckBox->setToolTip(tr("Indent the first line of each paragraph"));
- layout->addRow(m_indentFirstLineCheckBox);
- addSearchItem(label, m_indentFirstLineCheckBox->toolTip(), m_indentFirstLineCheckBox);
- connect(m_indentFirstLineCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- return box;
- }
- QGroupBox *MarkdownEditorPage::setupEditGroup()
- {
- auto box = new QGroupBox(tr("Edit"), this);
- auto layout = WidgetsFactory::createFormLayout(box);
- {
- const QString label(tr("Insert file name as title"));
- m_insertFileNameAsTitleCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_insertFileNameAsTitleCheckBox->setToolTip(tr("Insert file name as title when creating note"));
- layout->addRow(m_insertFileNameAsTitleCheckBox);
- addSearchItem(label, m_insertFileNameAsTitleCheckBox->toolTip(), m_insertFileNameAsTitleCheckBox);
- connect(m_insertFileNameAsTitleCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Constrain in-place preview width"));
- m_constrainInPlacePreviewWidthCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_constrainInPlacePreviewWidthCheckBox->setToolTip(tr("Constrain in-place preview width to the window"));
- layout->addRow(m_constrainInPlacePreviewWidthCheckBox);
- addSearchItem(label, m_constrainInPlacePreviewWidthCheckBox->toolTip(), m_constrainInPlacePreviewWidthCheckBox);
- connect(m_constrainInPlacePreviewWidthCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Fetch images to local in Parse And Paste"));
- m_fetchImagesToLocalCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_fetchImagesToLocalCheckBox->setToolTip(tr("Fetch images to local in Parse To Markdown And Paste"));
- layout->addRow(m_fetchImagesToLocalCheckBox);
- addSearchItem(label, m_fetchImagesToLocalCheckBox->toolTip(), m_fetchImagesToLocalCheckBox);
- connect(m_fetchImagesToLocalCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Smart table"));
- m_smartTableCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_smartTableCheckBox->setToolTip(tr("Smart table formation"));
- layout->addRow(m_smartTableCheckBox);
- addSearchItem(label, m_smartTableCheckBox->toolTip(), m_smartTableCheckBox);
- connect(m_smartTableCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- {
- const QString label(tr("Spell check"));
- m_spellCheckCheckBox = WidgetsFactory::createCheckBox(label, box);
- m_spellCheckCheckBox->setToolTip(tr("Spell check"));
- layout->addRow(m_spellCheckCheckBox);
- addSearchItem(label, m_spellCheckCheckBox->toolTip(), m_spellCheckCheckBox);
- connect(m_spellCheckCheckBox, &QCheckBox::stateChanged,
- this, &MarkdownEditorPage::pageIsChanged);
- }
- return box;
- }
- QGroupBox *MarkdownEditorPage::setupGeneralGroup()
- {
- auto box = new QGroupBox(tr("General"), this);
- auto layout = WidgetsFactory::createFormLayout(box);
- {
- auto sectionLayout = new QHBoxLayout();
- m_sectionNumberComboBox = WidgetsFactory::createComboBox(this);
- m_sectionNumberComboBox->setToolTip(tr("Section number mode"));
- m_sectionNumberComboBox->addItem(tr("None"), (int)MarkdownEditorConfig::SectionNumberMode::None);
- m_sectionNumberComboBox->addItem(tr("Read"), (int)MarkdownEditorConfig::SectionNumberMode::Read);
- m_sectionNumberComboBox->addItem(tr("Edit"), (int)MarkdownEditorConfig::SectionNumberMode::Edit);
- sectionLayout->addWidget(m_sectionNumberComboBox);
- connect(m_sectionNumberComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
- this, &MarkdownEditorPage::pageIsChanged);
- m_sectionNumberBaseLevelSpinBox = WidgetsFactory::createSpinBox(this);
- m_sectionNumberBaseLevelSpinBox->setToolTip(tr("Base level to start section numbering in edit mode"));
- m_sectionNumberBaseLevelSpinBox->setRange(1, 6);
- m_sectionNumberBaseLevelSpinBox->setSingleStep(1);
- sectionLayout->addWidget(m_sectionNumberBaseLevelSpinBox);
- connect(m_sectionNumberBaseLevelSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
- this, &MarkdownEditorPage::pageIsChanged);
- m_sectionNumberStyleComboBox = WidgetsFactory::createComboBox(this);
- 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);
- sectionLayout->addWidget(m_sectionNumberStyleComboBox);
- connect(m_sectionNumberStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
- this, &MarkdownEditorPage::pageIsChanged);
- connect(m_sectionNumberComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
- this, [this](int p_index) {
- m_sectionNumberBaseLevelSpinBox->setEnabled(p_index != MarkdownEditorConfig::SectionNumberMode::None);
- m_sectionNumberStyleComboBox->setEnabled(p_index == MarkdownEditorConfig::SectionNumberMode::Edit);
- });
- const QString label(tr("Section number:"));
- layout->addRow(label, sectionLayout);
- addSearchItem(label, m_sectionNumberComboBox->toolTip(), m_sectionNumberComboBox);
- }
- return box;
- }
|