vexportdialog.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef VEXPORTDIALOG_H
  2. #define VEXPORTDIALOG_H
  3. #include <QDialog>
  4. #include <QPageLayout>
  5. #include "vconstants.h"
  6. class QLabel;
  7. class VLineEdit;
  8. class QDialogButtonBox;
  9. class QComboBox;
  10. class QPushButton;
  11. class QGroupBox;
  12. class QPlainTextEdit;
  13. class VNotebook;
  14. class VDirectory;
  15. class VFile;
  16. class VCart;
  17. class VExporter;
  18. enum class ExportSource
  19. {
  20. CurrentNote = 0,
  21. CurrentDirectory,
  22. CurrentNotebook,
  23. Cart
  24. };
  25. enum class ExportFormat
  26. {
  27. Markdown = 0,
  28. HTML,
  29. PDF
  30. };
  31. struct ExportOption
  32. {
  33. ExportOption(ExportSource p_source,
  34. ExportFormat p_format,
  35. MarkdownConverterType p_renderer,
  36. const QString &p_renderBg,
  37. const QString &p_renderStyle,
  38. const QString &p_renderCodeBlockStyle,
  39. QPageLayout *p_layout)
  40. : m_source(p_source),
  41. m_format(p_format),
  42. m_renderer(p_renderer),
  43. m_renderBg(p_renderBg),
  44. m_renderStyle(p_renderStyle),
  45. m_renderCodeBlockStyle(p_renderCodeBlockStyle),
  46. m_layout(p_layout)
  47. {
  48. }
  49. ExportSource m_source;
  50. ExportFormat m_format;
  51. MarkdownConverterType m_renderer;
  52. // Background name.
  53. QString m_renderBg;
  54. QString m_renderStyle;
  55. QString m_renderCodeBlockStyle;
  56. QPageLayout *m_layout;
  57. };
  58. class VExportDialog : public QDialog
  59. {
  60. Q_OBJECT
  61. public:
  62. VExportDialog(VNotebook *p_notebook,
  63. VDirectory *p_directory,
  64. VFile *p_file,
  65. VCart *p_cart,
  66. MarkdownConverterType p_renderer,
  67. QWidget *p_parent = nullptr);
  68. private slots:
  69. void startExport();
  70. void handleBrowseBtnClicked();
  71. void handleInputChanged();
  72. void handleLayoutBtnClicked();
  73. void handleCurrentFormatChanged(int p_index);
  74. private:
  75. void setupUI();
  76. QWidget *setupPDFAdvancedSettings();
  77. void initUIFields(MarkdownConverterType p_renderer);
  78. QString getOutputDirectory() const;
  79. void appendLogLine(const QString &p_text);
  80. // Return number of files exported.
  81. int doExport(VFile *p_file,
  82. const ExportOption &p_opt,
  83. const QString &p_outputFolder,
  84. QString *p_errMsg = NULL);
  85. int doExport(VDirectory *p_directory,
  86. const ExportOption &p_opt,
  87. const QString &p_outputFolder,
  88. QString *p_errMsg = NULL);
  89. int doExport(VNotebook *p_notebook,
  90. const ExportOption &p_opt,
  91. const QString &p_outputFolder,
  92. QString *p_errMsg = NULL);
  93. int doExport(VCart *p_cart,
  94. const ExportOption &p_opt,
  95. const QString &p_outputFolder,
  96. QString *p_errMsg = NULL);
  97. int doExportMarkdown(VFile *p_file,
  98. const ExportOption &p_opt,
  99. const QString &p_outputFolder,
  100. QString *p_errMsg = NULL);
  101. int doExportPDF(VFile *p_file,
  102. const ExportOption &p_opt,
  103. const QString &p_outputFolder,
  104. QString *p_errMsg = NULL);
  105. int doExportHTML(VFile *p_file,
  106. const ExportOption &p_opt,
  107. const QString &p_outputFolder,
  108. QString *p_errMsg = NULL);
  109. // Return false if we could not continue.
  110. bool checkUserAction();
  111. void updatePageLayoutLabel();
  112. QComboBox *m_srcCB;
  113. QComboBox *m_formatCB;
  114. QComboBox *m_rendererCB;
  115. QComboBox *m_renderBgCB;
  116. QComboBox *m_renderStyleCB;
  117. QComboBox *m_renderCodeBlockStyleCB;
  118. VLineEdit *m_outputEdit;
  119. QPushButton *m_browseBtn;
  120. QGroupBox *m_basicBox;
  121. QGroupBox *m_settingBox;
  122. QWidget *m_pdfSettings;
  123. QPlainTextEdit *m_consoleEdit;
  124. QDialogButtonBox *m_btnBox;
  125. QPushButton *m_openBtn;
  126. QPushButton *m_exportBtn;
  127. QLabel *m_layoutLabel;
  128. QPushButton *m_layoutBtn;
  129. VNotebook *m_notebook;
  130. VDirectory *m_directory;
  131. VFile *m_file;
  132. VCart *m_cart;
  133. QPageLayout m_pageLayout;
  134. // Whether we are exporting files.
  135. bool m_inExport;
  136. // Asked to stop exporting by user.
  137. bool m_askedToStop;
  138. // Exporter used to export PDF and HTML.
  139. VExporter *m_exporter;
  140. // Last output folder path.
  141. static QString s_lastOutputFolder;
  142. // Last export format.
  143. static ExportFormat s_lastExportFormat;
  144. };
  145. #endif // VEXPORTDIALOG_H