vmdtab.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef VMDTAB_H
  2. #define VMDTAB_H
  3. #include <QString>
  4. #include <QPointer>
  5. #include "vedittab.h"
  6. #include "vconstants.h"
  7. #include "vmarkdownconverter.h"
  8. #include "vconfigmanager.h"
  9. class VWebView;
  10. class QStackedLayout;
  11. class VEdit;
  12. class VDocument;
  13. class VMdTab : public VEditTab
  14. {
  15. Q_OBJECT
  16. public:
  17. VMdTab(VFile *p_file, VEditArea *p_editArea, OpenFileMode p_mode, QWidget *p_parent = 0);
  18. // Close current tab.
  19. // @p_forced: if true, discard the changes.
  20. bool closeFile(bool p_forced) Q_DECL_OVERRIDE;
  21. // Enter read mode.
  22. // Will prompt user to save the changes.
  23. void readFile() Q_DECL_OVERRIDE;
  24. // Save file.
  25. bool saveFile() Q_DECL_OVERRIDE;
  26. // Scroll to anchor @p_anchor.
  27. void scrollToAnchor(const VAnchor& p_anchor) Q_DECL_OVERRIDE;
  28. void insertImage() Q_DECL_OVERRIDE;
  29. // Search @p_text in current note.
  30. void findText(const QString &p_text, uint p_options, bool p_peek,
  31. bool p_forward = true) Q_DECL_OVERRIDE;
  32. // Replace @p_text with @p_replaceText in current note.
  33. void replaceText(const QString &p_text, uint p_options,
  34. const QString &p_replaceText, bool p_findNext) Q_DECL_OVERRIDE;
  35. void replaceTextAll(const QString &p_text, uint p_options,
  36. const QString &p_replaceText) Q_DECL_OVERRIDE;
  37. QString getSelectedText() const Q_DECL_OVERRIDE;
  38. void clearSearchedWordHighlight() Q_DECL_OVERRIDE;
  39. VWebView *getWebViewer() const;
  40. MarkdownConverterType getMarkdownConverterType() const;
  41. public slots:
  42. // Enter edit mode.
  43. void editFile() Q_DECL_OVERRIDE;
  44. private slots:
  45. // Handle text changed in m_editor.
  46. void handleTextChanged();
  47. // Emit statusChanged() signal to notify that status of this tab has changed.
  48. void noticeStatusChanged();
  49. // Update m_toc according to @p_tocHtml for read mode.
  50. void updateTocFromHtml(const QString &p_tocHtml);
  51. // Update m_toc accroding to @p_headers for edit mode.
  52. void updateTocFromHeaders(const QVector<VHeader> &p_headers);
  53. // Web viewer requests to update current header.
  54. void updateCurHeader(const QString &p_anchor);
  55. // Editor requests to update current header.
  56. void updateCurHeader(VAnchor p_anchor);
  57. // Handle key press event in Web view.
  58. void handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift);
  59. // m_editor requests to save changes and enter read mode.
  60. void saveAndRead();
  61. // m_editor requests to discard changes and enter read mode.
  62. void discardAndRead();
  63. private:
  64. // Setup UI.
  65. void setupUI();
  66. // Show the file content in read mode.
  67. void showFileReadMode();
  68. // Show the file content in edit mode.
  69. void showFileEditMode();
  70. // Generate HTML template for Web view.
  71. QString fillHtmlTemplate() const;
  72. // Setup Markdown viewer.
  73. void setupMarkdownViewer();
  74. // Use VMarkdownConverter (hoedown) to generate the Web view.
  75. void viewWebByConverter();
  76. // Scroll Web view to given header.
  77. // @p_outlineIndex is the index in m_toc.headers.
  78. void scrollWebViewToHeader(int p_outlineIndex);
  79. // Search text in Web view.
  80. void findTextInWebView(const QString &p_text, uint p_options, bool p_peek,
  81. bool p_forward);
  82. // Called to zoom in/out content.
  83. void zoom(bool p_zoomIn, qreal p_step = 0.25) Q_DECL_OVERRIDE;
  84. // Zoom Web View.
  85. void zoomWebPage(bool p_zoomIn, qreal p_step = 0.25);
  86. VEdit *m_editor;
  87. VWebView *m_webViewer;
  88. VDocument *m_document;
  89. MarkdownConverterType m_mdConType;
  90. QStackedLayout *m_stacks;
  91. };
  92. #endif // VMDTAB_H