vmdedit.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef VMDEDIT_H
  2. #define VMDEDIT_H
  3. #include "vedit.h"
  4. #include <QVector>
  5. #include <QString>
  6. #include <QColor>
  7. #include <QClipboard>
  8. #include <QImage>
  9. #include "vtoc.h"
  10. #include "veditoperations.h"
  11. #include "vconfigmanager.h"
  12. #include "utils/vutils.h"
  13. class HGMarkdownHighlighter;
  14. class VCodeBlockHighlightHelper;
  15. class VDocument;
  16. class VImagePreviewer;
  17. class VMdEdit : public VEdit
  18. {
  19. Q_OBJECT
  20. public:
  21. VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type,
  22. QWidget *p_parent = 0);
  23. void beginEdit() Q_DECL_OVERRIDE;
  24. void endEdit() Q_DECL_OVERRIDE;
  25. void saveFile() Q_DECL_OVERRIDE;
  26. void reloadFile() Q_DECL_OVERRIDE;
  27. // An image has been inserted. The image is relative.
  28. // @p_path is the absolute path of the inserted image.
  29. void imageInserted(const QString &p_path);
  30. // Scroll to m_headers[p_headerIndex].
  31. void scrollToHeader(int p_headerIndex);
  32. // Like toPlainText(), but remove special blocks containing images.
  33. QString toPlainTextWithoutImg() const;
  34. signals:
  35. void headersChanged(const QVector<VHeader> &headers);
  36. void curHeaderChanged(int p_lineNumber, int p_outlineIndex);
  37. void statusChanged();
  38. private slots:
  39. void generateEditOutline();
  40. void updateCurHeader();
  41. void handleEditStateChanged(KeyState p_state);
  42. void handleSelectionChanged();
  43. void handleClipboardChanged(QClipboard::Mode p_mode);
  44. protected:
  45. void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
  46. bool canInsertFromMimeData(const QMimeData *source) const Q_DECL_OVERRIDE;
  47. void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE;
  48. void updateFontAndPalette() Q_DECL_OVERRIDE;
  49. void resizeEvent(QResizeEvent *p_event) Q_DECL_OVERRIDE;
  50. private:
  51. void initInitImages();
  52. void clearUnusedImages();
  53. // p_text[p_index] is QChar::ObjectReplacementCharacter. Remove the line containing it.
  54. // Returns the index of previous line's '\n'.
  55. int removeObjectReplacementLine(QString &p_text, int p_index) const;
  56. // There is a QChar::ObjectReplacementCharacter in the selection.
  57. // Get the QImage.
  58. QImage selectedImage();
  59. HGMarkdownHighlighter *m_mdHighlighter;
  60. VCodeBlockHighlightHelper *m_cbHighlighter;
  61. VImagePreviewer *m_imagePreviewer;
  62. // Image links inserted while editing.
  63. QVector<ImageLink> m_insertedImages;
  64. // Image links right at the beginning of the edit.
  65. QVector<ImageLink> m_initImages;
  66. QVector<VHeader> m_headers;
  67. };
  68. #endif // VMDEDIT_H