markdowneditorconfig.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef MARKDOWNEDITORCONFIG_H
  2. #define MARKDOWNEDITORCONFIG_H
  3. #include "iconfig.h"
  4. #include "webresource.h"
  5. #include <QSharedPointer>
  6. #include <QVector>
  7. namespace vnotex
  8. {
  9. class TextEditorConfig;
  10. class MarkdownEditorConfig : public IConfig
  11. {
  12. public:
  13. enum SectionNumberMode
  14. {
  15. None,
  16. Read,
  17. Edit
  18. };
  19. enum SectionNumberStyle
  20. {
  21. // 1.1.
  22. DigDotDigDot,
  23. // 1.1
  24. DigDotDig
  25. };
  26. MarkdownEditorConfig(ConfigMgr *p_mgr,
  27. IConfig *p_topConfig,
  28. const QSharedPointer<TextEditorConfig> &p_textEditorConfig);
  29. void init(const QJsonObject &p_app, const QJsonObject &p_user) Q_DECL_OVERRIDE;
  30. QJsonObject toJson() const Q_DECL_OVERRIDE;
  31. int revision() const Q_DECL_OVERRIDE;
  32. TextEditorConfig &getTextEditorConfig();
  33. const TextEditorConfig &getTextEditorConfig() const;
  34. const WebResource &getViewerResource() const;
  35. const WebResource &getExportResource() const;
  36. bool getWebPlantUml() const;
  37. void setWebPlantUml(bool p_enabled);
  38. const QString &getPlantUmlJar() const;
  39. void setPlantUmlJar(const QString &p_jar);
  40. const QString &getPlantUmlCommand() const;
  41. bool getWebGraphviz() const;
  42. void setWebGraphviz(bool p_enabled);
  43. const QString &getGraphvizExe() const;
  44. void setGraphvizExe(const QString &p_exe);
  45. bool getPrependDotInRelativeLink() const;
  46. bool getConfirmBeforeClearObsoleteImages() const;
  47. void setConfirmBeforeClearObsoleteImages(bool p_confirm);
  48. bool getInsertFileNameAsTitle() const;
  49. void setInsertFileNameAsTitle(bool p_enabled);
  50. SectionNumberMode getSectionNumberMode() const;
  51. void setSectionNumberMode(SectionNumberMode p_mode);
  52. int getSectionNumberBaseLevel() const;
  53. void setSectionNumberBaseLevel(int p_level);
  54. SectionNumberStyle getSectionNumberStyle() const;
  55. void setSectionNumberStyle(SectionNumberStyle p_style);
  56. bool getConstrainImageWidthEnabled() const;
  57. void setConstrainImageWidthEnabled(bool p_enabled);
  58. bool getConstrainInPlacePreviewWidthEnabled() const;
  59. void setConstrainInPlacePreviewWidthEnabled(bool p_enabled);
  60. qreal getZoomFactorInReadMode() const;
  61. void setZoomFactorInReadMode(qreal p_factor);
  62. bool getFetchImagesInParseAndPaste() const;
  63. void setFetchImagesInParseAndPaste(bool p_enabled);
  64. bool getProtectFromXss() const;
  65. bool getHtmlTagEnabled() const;
  66. void setHtmlTagEnabled(bool p_enabled);
  67. bool getAutoBreakEnabled() const;
  68. void setAutoBreakEnabled(bool p_enabled);
  69. bool getLinkifyEnabled() const;
  70. void setLinkifyEnabled(bool p_enabled);
  71. bool getIndentFirstLineEnabled() const;
  72. void setIndentFirstLineEnabled(bool p_enabled);
  73. bool getSmartTableEnabled() const;
  74. void setSmartTableEnabled(bool p_enabled);
  75. int getSmartTableInterval() const;
  76. bool isSpellCheckEnabled() const;
  77. void setSpellCheckEnabled(bool p_enabled);
  78. private:
  79. QString sectionNumberModeToString(SectionNumberMode p_mode) const;
  80. SectionNumberMode stringToSectionNumberMode(const QString &p_str) const;
  81. QString sectionNumberStyleToString(SectionNumberStyle p_style) const;
  82. SectionNumberStyle stringToSectionNumberStyle(const QString &p_str) const;
  83. void loadViewerResource(const QJsonObject &p_app, const QJsonObject &p_user);
  84. QJsonObject saveViewerResource() const;
  85. void loadExportResource(const QJsonObject &p_app, const QJsonObject &p_user);
  86. QJsonObject saveExportResource() const;
  87. QSharedPointer<TextEditorConfig> m_textEditorConfig;
  88. WebResource m_viewerResource;
  89. WebResource m_exportResource;
  90. // Whether use javascript or external program to render PlantUML.
  91. bool m_webPlantUml = true;
  92. // File path of the JAR to render PlantUmL.
  93. QString m_plantUmlJar;
  94. // Command to render PlantUml. If set, will ignore m_plantUmlJar.
  95. // %1: the format to render in.
  96. QString m_plantUmlCommand;
  97. bool m_webGraphviz = true;
  98. // Graphviz executable file.
  99. QString m_graphvizExe;
  100. // Whether prepend a dot in front of the relative link, like images.
  101. bool m_prependDotInRelativeLink = false;
  102. // Whether ask for user confirmation before clearing obsolete images.
  103. bool m_confirmBeforeClearObsoleteImages = true;
  104. // Whether insert the name of the new file as title.
  105. bool m_insertFileNameAsTitle = true;
  106. // Whether enable section numbering.
  107. SectionNumberMode m_sectionNumberMode = SectionNumberMode::Read;
  108. // 1 based.
  109. int m_sectionNumberBaseLevel = 2;
  110. // Section number style.
  111. SectionNumberStyle m_sectionNumberStyle = SectionNumberStyle::DigDotDigDot;
  112. // Whether enable image width constraint.
  113. bool m_constrainImageWidthEnabled = true;
  114. // Whether enable in-place preview width constraint.
  115. bool m_constrainInPlacePreviewWidthEnabled = false;
  116. qreal m_zoomFactorInReadMode = 1.0;
  117. // Whether fetch images to local in Parse To Markdown And Paste.
  118. bool m_fetchImagesInParseAndPaste = true;
  119. // Whether protect from Cross-Site Scripting.
  120. bool m_protectFromXss = false;
  121. // Whether allow HTML tag in Markdown source.
  122. bool m_htmlTagEnabled = true;
  123. // Whether auto break a line with `\n`.
  124. bool m_autoBreakEnabled = false;
  125. // Whether convert URL-like text to links.
  126. bool m_linkifyEnabled = true;
  127. // Whether indent the first line of a paragraph.
  128. bool m_indentFirstLineEnabled = false;
  129. bool m_smartTableEnabled = true;
  130. // Interval time to do smart table format.
  131. int m_smartTableInterval = 2000;
  132. // Override the config in TextEditorConfig.
  133. bool m_spellCheckEnabled = true;
  134. };
  135. }
  136. #endif // MARKDOWNEDITORCONFIG_H