vexporter.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef VEXPORTER_H
  2. #define VEXPORTER_H
  3. #include <QObject>
  4. #include <QPageLayout>
  5. #include "dialog/vexportdialog.h"
  6. class QWidget;
  7. class VWebView;
  8. class VExporter : public QObject
  9. {
  10. public:
  11. explicit VExporter(QWidget *p_parent = nullptr);
  12. void prepareExport(const ExportOption &p_opt);
  13. bool exportPDF(VFile *p_file,
  14. const ExportOption &p_opt,
  15. const QString &p_outputFile,
  16. QString *p_errMsg = NULL);
  17. private slots:
  18. void handleLogicsFinished();
  19. void handleLoadFinished(bool p_ok);
  20. private:
  21. enum class ExportState
  22. {
  23. Idle = 0,
  24. Cancelled,
  25. Busy,
  26. Failed,
  27. Successful
  28. };
  29. enum NoteState
  30. {
  31. NotReady = 0,
  32. WebLogicsReady = 0x1,
  33. WebLoadFinished = 0x2,
  34. Ready = 0x3,
  35. Failed = 0x4
  36. };
  37. void initWebViewer(VFile *p_file, const ExportOption &p_opt);
  38. void clearWebViewer();
  39. void clearNoteState();
  40. bool isNoteStateReady() const;
  41. bool isNoteStateFailed() const;
  42. bool exportToPDF(VWebView *p_webViewer,
  43. const QString &p_filePath,
  44. const QPageLayout &p_layout);
  45. QPageLayout m_pageLayout;
  46. // Will be allocated and free for each conversion.
  47. VWebView *m_webViewer;
  48. QString m_htmlTemplate;
  49. NoteState m_noteState;
  50. ExportState m_state;
  51. };
  52. inline void VExporter::clearNoteState()
  53. {
  54. m_noteState = NoteState::NotReady;
  55. }
  56. inline bool VExporter::isNoteStateReady() const
  57. {
  58. return m_noteState == NoteState::Ready;
  59. }
  60. inline bool VExporter::isNoteStateFailed() const
  61. {
  62. return m_noteState & NoteState::Failed;
  63. }
  64. #endif // VEXPORTER_H