| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef WEBENGINEVIEWER_H |
| 4 | #define WEBENGINEVIEWER_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | #include "gui/webviewers/webviewer.h" |
| 8 | #include "miscellaneous/externaltool.h" |
| 9 | #include "network-web/webengine/webenginepage.h" |
| 10 | |
| 11 | #include <QWebEngineFullScreenRequest> |
| 12 | #include <QWebEngineView> |
| 13 | |
| 14 | class RootItem; |
| 15 | class WebBrowser; |
| 16 | |
| 17 | class RSSGUARD_DLLSPEC WebEngineViewer : public QWebEngineView, public WebViewer { |
| 18 | Q_OBJECT |
| 19 | Q_INTERFACES(WebViewer) |
| 20 | |
| 21 | public: |
| 22 | explicit WebEngineViewer(QWidget* parent = nullptr); |
| 23 | |
| 24 | public: |
| 25 | virtual void loadMessages(const QList<Message>& messages, RootItem* root); |
| 26 | virtual PreparedHtml htmlForMessages(const QList<Message>& messages, RootItem* root) const; |
| 27 | virtual void bindToBrowser(WebBrowser* browser); |
| 28 | virtual void findText(const QString& text, bool backwards); |
| 29 | virtual void setUrl(const QUrl& url); |
| 30 | virtual void setHtml(const QString& html, const QUrl& base_url = {}); |
| 31 | virtual void setReadabledHtml(const QString& html, const QUrl& base_url = {}); |
| 32 | virtual void clear(); |
| 33 | virtual double verticalScrollBarPosition() const; |
| 34 | virtual void setVerticalScrollBarPosition(double pos); |
| 35 | virtual void applyFont(const QFont& fon); |
| 36 | virtual qreal zoomFactor() const; |
| 37 | virtual void setZoomFactor(qreal zoom_factor); |
| 38 | virtual QString html() const; |
| 39 | virtual QUrl url() const; |
| 40 | |
| 41 | static QByteArray getJsEnabledHtml(const QString& url, bool worker_thread); |
| 42 | |
| 43 | signals: |
| 44 | void pageTitleChanged(const QString& new_title); |
| 45 | void pageUrlChanged(const QUrl& url); |
| 46 | void pageIconChanged(const QIcon&); |
| 47 | void linkMouseHighlighted(const QUrl& url); |
| 48 | void loadingStarted(); |
| 49 | void loadingProgress(int progress); |
| 50 | void loadingFinished(bool success); |
| 51 | void newWindowRequested(WebViewer* viewer); |
| 52 | void closeWindowRequested(); |
| 53 | |
| 54 | protected: |
| 55 | virtual ContextMenuData provideContextMenuData(QContextMenuEvent* event) const; |
| 56 | virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type); |
| 57 | virtual void contextMenuEvent(QContextMenuEvent* event); |
| 58 | virtual bool event(QEvent* event); |
| 59 | |
| 60 | private slots: |
| 61 | void onFullScreenRequested(QWebEngineFullScreenRequest request); |
| 62 | void openUrlWithExternalTool(ExternalTool tool, const QString& target_url); |
| 63 | |
| 64 | private: |
| 65 | WebEnginePage* page() const; |
| 66 | |
| 67 | private: |
| 68 | WebBrowser* m_browser; |
| 69 | RootItem* m_root; |
| 70 | QUrl m_messageBaseUrl; |
| 71 | QString m_messageContents; |
| 72 | }; |
| 73 | |
| 74 | #endif // WEBENGINEVIEWER_H |