vmdeditoperations.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef VMDEDITOPERATIONS_H
  2. #define VMDEDITOPERATIONS_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QUrl>
  6. #include <QImage>
  7. #include <QTextBlock>
  8. #include "veditoperations.h"
  9. class QTimer;
  10. // Editor operations for Markdown
  11. class VMdEditOperations : public VEditOperations
  12. {
  13. Q_OBJECT
  14. public:
  15. VMdEditOperations(VEdit *p_editor, VFile *p_file);
  16. bool insertImageFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE;
  17. bool insertImage() Q_DECL_OVERRIDE;
  18. bool handleKeyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
  19. bool insertImageFromURL(const QUrl &p_imageUrl) Q_DECL_OVERRIDE;
  20. private:
  21. void insertImageFromPath(const QString &title, const QString &path, const QString &oriImagePath);
  22. // @title: title of the inserted image;
  23. // @path: the image folder path to insert the image in;
  24. // @image: the image to be inserted;
  25. void insertImageFromQImage(const QString &title, const QString &path, const QImage &image);
  26. // Key press handlers.
  27. bool handleKeyTab(QKeyEvent *p_event);
  28. bool handleKeyBackTab(QKeyEvent *p_event);
  29. bool handleKeyB(QKeyEvent *p_event);
  30. bool handleKeyH(QKeyEvent *p_event);
  31. bool handleKeyI(QKeyEvent *p_event);
  32. bool handleKeyO(QKeyEvent *p_event);
  33. bool handleKeyU(QKeyEvent *p_event);
  34. bool handleKeyW(QKeyEvent *p_event);
  35. bool handleKeyEsc(QKeyEvent *p_event);
  36. bool handleKeyReturn(QKeyEvent *p_event);
  37. bool handleKeyBracketLeft(QKeyEvent *p_event);
  38. bool insertTitle(int p_level);
  39. void deleteIndentAndListMark();
  40. // Check if @p_block is a auto list block.
  41. // @p_seq will be the seq number of the ordered list, or -1.
  42. // Returns true if it is an auto list block.
  43. bool isListBlock(const QTextBlock &p_block, int *p_seq = NULL);
  44. // If the start of @p_block to postition @p_posInBlock are spaces.
  45. bool isSpaceToBlockStart(const QTextBlock &p_block, int p_posInBlock);
  46. // Change the sequence number of a list block.
  47. void changeListBlockSeqNumber(QTextBlock &p_block, int p_seq);
  48. // The cursor position after auto indent or auto list.
  49. // It will be -1 if last key press do not trigger the auto indent or auto list.
  50. int m_autoIndentPos;
  51. static const QString c_defaultImageTitle;
  52. };
  53. #endif // VMDEDITOPERATIONS_H