| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #ifndef VMDEDIT_H
- #define VMDEDIT_H
- #include "vedit.h"
- #include <QVector>
- #include <QString>
- #include "vtoc.h"
- class HGMarkdownHighlighter;
- class VMdEdit : public VEdit
- {
- Q_OBJECT
- public:
- VMdEdit(VFile *p_file, QWidget *p_parent = 0);
- void beginEdit() Q_DECL_OVERRIDE;
- void endEdit() Q_DECL_OVERRIDE;
- void saveFile() Q_DECL_OVERRIDE;
- void reloadFile() Q_DECL_OVERRIDE;
- // An image has been inserted.
- void imageInserted(const QString &p_name);
- // Scroll to m_headers[p_headerIndex].
- void scrollToHeader(int p_headerIndex);
- // Like toPlainText(), but remove special blocks containing images.
- QString toPlainTextWithoutImg() const;
- signals:
- void headersChanged(const QVector<VHeader> &headers);
- void curHeaderChanged(int p_lineNumber, int p_outlineIndex);
- void statusChanged();
- private slots:
- void generateEditOutline();
- void updateCurHeader();
- // Update block list containing image links.
- void updateImageBlocks(QSet<int> p_imageBlocks);
- protected:
- void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
- bool canInsertFromMimeData(const QMimeData *source) const Q_DECL_OVERRIDE;
- void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE;
- private:
- void updateFontAndPalette();
- void updateTabSettings();
- void initInitImages();
- void clearUnusedImages();
- // p_text[p_index] is QChar::ObjectReplacementCharacter. Remove the line containing it.
- // Returns the index of previous line's '\n'.
- int removeObjectReplacementLine(QString &p_text, int p_index) const;
- void previewImageOfBlock(int p_block);
- bool isImagePreviewBlock(int p_block);
- bool isImagePreviewBlock(QTextBlock p_block);
- // p_block is a image preview block. We need to update it with image.
- void updateImagePreviewBlock(int p_block, const QString &p_image);
- // Insert a block after @p_block to preview image @p_image.
- void insertImagePreviewBlock(int p_block, const QString &p_image);
- // Clean up un-referenced image preview block.
- void clearOrphanImagePreviewBlock();
- void removeBlock(QTextBlock p_block);
- bool isOrphanImagePreviewBlock(QTextBlock p_block);
- // Returns the image relative path (image/xxx.png) only when
- // there is one and only one image link.
- QString fetchImageToPreview(const QString &p_text);
- HGMarkdownHighlighter *m_mdHighlighter;
- QVector<QString> m_insertedImages;
- QVector<QString> m_initImages;
- bool m_expandTab;
- QString m_tabSpaces;
- QVector<VHeader> m_headers;
- };
- #endif // VMDEDIT_H
|