| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #ifndef VDOCUMENT_H
- #define VDOCUMENT_H
- #include <QObject>
- #include <QString>
- #include "vwordcountinfo.h"
- class VFile;
- class VPlantUMLHelper;
- class VGraphvizHelper;
- class VDocument : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)
- Q_PROPERTY(QString toc MEMBER m_toc NOTIFY tocChanged)
- Q_PROPERTY(QString html MEMBER m_html NOTIFY htmlChanged)
- public:
- // @p_file could be NULL.
- VDocument(const VFile *p_file, QObject *p_parent = 0);
- QString getToc();
- // Scroll to @anchor in the web.
- // @anchor is the id without '#', like "toc_1". If empty, will scroll to top.
- void scrollToAnchor(const QString &anchor);
- void setHtml(const QString &html);
- // Request to highlight a segment text.
- // Use p_id to identify the result.
- void highlightTextAsync(const QString &p_text, int p_id, int p_timeStamp);
- // Request to convert @p_text to HTML.
- void textToHtmlAsync(int p_identitifer,
- int p_id,
- int p_timeStamp,
- const QString &p_text,
- bool p_inlineStyle);
- void setFile(const VFile *p_file);
- bool isReadyToHighlight() const;
- bool isReadyToTextToHtml() const;
- // Request to get the HTML content.
- void getHtmlContentAsync();
- const VWordCountInfo &getWordCountInfo() const;
- // Whether change to preview mode.
- void setPreviewEnabled(bool p_enabled);
- // @p_livePreview: if true, display the result in the preview-div; otherwise,
- // call previewCodeBlockCB() to pass back the result.
- // Only for online parser.
- void previewCodeBlock(int p_id,
- const QString &p_lang,
- const QString &p_text,
- bool p_livePreview);
- // Set the content of the preview.
- void setPreviewContent(const QString &p_lang, const QString &p_html);
- int registerIdentifier();
- public slots:
- // Will be called in the HTML side
- // @toc: the HTML of the TOC.
- // @baseLevel: the base level of @toc, starting from 1. It is the top level
- // in the @toc.
- void setToc(const QString &toc, int baseLevel);
- // When the Web view has been scrolled, it will signal current header anchor.
- // Empty @anchor to indicate an invalid header.
- // The header does not begins with '#'.
- void setHeader(const QString &anchor);
- void setLog(const QString &p_log);
- void keyPressEvent(int p_key, bool p_ctrl, bool p_shift, bool p_meta);
- void updateText();
- void highlightTextCB(const QString &p_html, int p_id, int p_timeStamp);
- void noticeReadyToHighlightText();
- void textToHtmlCB(int p_identitifer, int p_id, int p_timeStamp, const QString &p_html);
- void noticeReadyToTextToHtml();
- // Web-side handle logics (MathJax etc.) is finished.
- // But the page may not finish loading, such as images.
- void finishLogics();
- void htmlContentCB(const QString &p_head,
- const QString &p_style,
- const QString &p_body);
- void updateWordCountInfo(int p_wordCount,
- int p_charWithoutSpacesCount,
- int p_charWithSpacesCount);
- // Web-side call this to process PlantUML locally.
- void processPlantUML(int p_id, const QString &p_format, const QString &p_text);
- // Web-side call this to process Graphviz locally.
- void processGraphviz(int p_id, const QString &p_format, const QString &p_text);
- void previewCodeBlockCB(int p_id, const QString &p_lang, const QString &p_html);
- signals:
- void textChanged(const QString &text);
- void tocChanged(const QString &toc);
- void requestScrollToAnchor(const QString &anchor);
- // @anchor is the id of that anchor, without '#'.
- void headerChanged(const QString &anchor);
- void htmlChanged(const QString &html);
- void logChanged(const QString &p_log);
- void keyPressed(int p_key, bool p_ctrl, bool p_shift, bool p_meta);
- void requestHighlightText(const QString &p_text, int p_id, int p_timeStamp);
- void textHighlighted(const QString &p_html, int p_id, int p_timeStamp);
- void readyToHighlightText();
- void logicsFinished();
- void requestTextToHtml(int p_identitifer,
- int p_id,
- int p_timeStamp,
- const QString &p_text,
- bool p_inlineStyle);
- void textToHtmlFinished(int p_identitifer, int p_id, int p_timeStamp, const QString &p_html);
- void requestHtmlContent();
- void htmlContentFinished(const QString &p_headContent,
- const QString &p_styleContent,
- const QString &p_bodyContent);
- void wordCountInfoUpdated();
- void plantUMLResultReady(int p_id,
- unsigned long long p_timeStamp,
- const QString &p_format,
- const QString &p_result);
- void graphvizResultReady(int p_id,
- unsigned long long p_timeStamp,
- const QString &p_format,
- const QString &p_result);
- void requestPreviewEnabled(bool p_enabled);
- void requestPreviewCodeBlock(int p_id,
- const QString &p_lang,
- const QString &p_text,
- bool p_livePreview);
- void requestSetPreviewContent(const QString &p_lang, const QString &p_html);
- void codeBlockPreviewReady(int p_id, const QString &p_lang, const QString &p_html);
- private:
- QString m_toc;
- QString m_header;
- // m_text does NOT contain actual content.
- QString m_text;
- // When using Hoedown, m_html will contain the html content.
- QString m_html;
- const VFile *m_file;
- // Whether the web side is ready to handle highlight text request.
- bool m_readyToHighlight;
- // Whether the web side is ready to convert text to html.
- bool m_readyToTextToHtml;
- VWordCountInfo m_wordCountInfo;
- VPlantUMLHelper *m_plantUMLHelper;
- VGraphvizHelper *m_graphvizHelper;
- int m_nextID;
- };
- inline bool VDocument::isReadyToHighlight() const
- {
- return m_readyToHighlight;
- }
- inline bool VDocument::isReadyToTextToHtml() const
- {
- return m_readyToTextToHtml;
- }
- inline const VWordCountInfo &VDocument::getWordCountInfo() const
- {
- return m_wordCountInfo;
- }
- inline int VDocument::registerIdentifier()
- {
- return ++m_nextID;
- }
- #endif // VDOCUMENT_H
|