KVIrc 5.2.6
Developer APIs
KvsObject_webView.h
Go to the documentation of this file.
1#ifndef _CLASS_WEVBIEW_H_
2#define _CLASS_WEVBIEW_H_
3//=============================================================================
4//
5// File : KvsObject_webView.h
6// Creation date : Wed Mar 9 23:45:48 CEST 2011
7// by Alessandro Carbone(Noldor)
8//
9// This file is part of the KVIrc IRC client distribution
10// Copyright (C) 2011 Alessandro Carbone (elfonol at gmail dot com)
11//
12// This program is FREE software. You can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation; either version 2
15// of the License, or (at your option) any later version.
16//
17// This program is distributed in the HOPE that it will be USEFUL,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20// See the GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program. If not, write to the Free Software Foundation,
24// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25//
26//=============================================================================
27
28#include "kvi_settings.h"
29#if defined(COMPILE_WEBENGINE_SUPPORT)
30#include "object_macros.h"
31#include <QFile>
32#include <QNetworkAccessManager>
33#include <QWebEngineView>
34#include <QWebEnginePage>
35#include <QMouseEvent>
36#include <QContextMenuEvent>
37
38#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
39#define DOWNLOAD_CLASS_NAME QWebEngineDownloadItem
40#else
41#define DOWNLOAD_CLASS_NAME QWebEngineDownloadRequest
42#endif
43
44class DOWNLOAD_CLASS_NAME;
45
46class KvsObject_webView;
47
48class KviKvsWebView : public QWebEngineView
49{
50 Q_OBJECT
51public:
52 KviKvsWebView(QWidget * par, const char * name, KvsObject_webView *);
53 //void accept();
54 //void reject();
55 ~KviKvsWebView();
56
57protected:
58 KvsObject_webView * m_pParentScript;
59
60protected:
61 void mouseMoveEvent(QMouseEvent * ev) override;
62 void contextMenuEvent(QContextMenuEvent *) override;
63 bool event(QEvent * e) override;
64 /*protected slots:
65 void slotNextClicked();
66 void slotBackClicked();
67 */
68};
69
70class KviKvsWebViewPage : public QWebEnginePage
71{
72 Q_OBJECT
73public:
74 enum LinkDelegationPolicy
75 {
76 DontDelegateLinks,
77 DelegateAllLinks
78 };
79
80 KviKvsWebViewPage(QObject* parent = 0) : QWebEnginePage(parent){}
81
82 bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
83 {
84 if (type == QWebEnginePage::NavigationTypeLinkClicked)
85 {
86 emit linkClicked(url);
87 switch(m_ePolicy)
88 {
89 case DelegateAllLinks:
90 return false;
91 case DontDelegateLinks:
92 default:
93 return true;
94 }
95 }
96 return true;
97 }
98
99 void setLinkDelegationPolicy(LinkDelegationPolicy policy)
100 {
101 m_ePolicy = policy;
102 }
103
104protected:
105 LinkDelegationPolicy m_ePolicy = DontDelegateLinks;
106signals:
107 void linkClicked(const QUrl&);
108
109};
110
111class KvsObject_webView : public KviKvsObject
112{
113 Q_OBJECT
114public:
115 KVSO_DECLARE_OBJECT(KvsObject_webView)
116protected:
117 KviKvsRunTimeContext * m_pContext = nullptr;
118 KviPointerList<QNetworkReply> * m_pReplyList = nullptr;
119 QNetworkAccessManager * m_pNetworkManager = nullptr;
120
121public:
122 QWidget * widget() { return (QWidget *)object(); }
123protected:
124 bool init(KviKvsRunTimeContext * pContext, KviKvsVariantList * pParams) override;
125 bool makePreview(KviKvsObjectFunctionCall * c);
126 bool load(KviKvsObjectFunctionCall * c);
127 bool setHtml(KviKvsObjectFunctionCall * c);
128 bool findText(KviKvsObjectFunctionCall * c);
129 bool setLinkDelegationPolicy(KviKvsObjectFunctionCall * c);
130 bool setWebSetting(KviKvsObjectFunctionCall * c);
131 bool appendWebViewActionToMenu(KviKvsObjectFunctionCall * c);
132
133 bool loadStartedEvent(KviKvsObjectFunctionCall * c);
134 bool linkClickedEvent(KviKvsObjectFunctionCall * c);
135 bool loadFinishedEvent(KviKvsObjectFunctionCall * c);
136 bool loadProgressEvent(KviKvsObjectFunctionCall * c);
137 bool downloadCompletedEvent(KviKvsObjectFunctionCall * c);
138 bool downloadProgressEvent(KviKvsObjectFunctionCall * c);
139 bool downloadRequestEvent(KviKvsObjectFunctionCall * c);
140 bool addToJavaScriptWindowObject(KviKvsObjectFunctionCall * c);
141 bool evaluateJavaScript(KviKvsObjectFunctionCall * c);
142
143 //
144 bool jsChangeEvent(KviKvsObjectFunctionCall * c);
145 bool jsSubmitEvent(KviKvsObjectFunctionCall * c);
146 bool jsClickEvent(KviKvsObjectFunctionCall * c);
147 bool jsMouseOverEvent(KviKvsObjectFunctionCall * c);
148 bool jsMouseOutEvent(KviKvsObjectFunctionCall * c);
149protected slots:
150 void slotLoadFinished(bool);
151 void slotLoadProgress(int);
152 void slotLoadStarted();
153 void slotDownloadRequest(DOWNLOAD_CLASS_NAME *);
154 void slotLinkClicked(const QUrl &);
155
156 void slotOnChange(QString);
157 void slotOnSubmit(QString);
158 void slotOnClick(QString);
159 void slotOnMouseOver(QString);
160 void slotOnMouseOut(QString);
161};
162
163class KviKvsDownloadHandler : public QObject
164{
165 Q_OBJECT
166public:
167 KviKvsDownloadHandler(KvsObject_webView * pParent, QString &szFilePath, DOWNLOAD_CLASS_NAME * pDownload, int iId);
168
169 ~KviKvsDownloadHandler();
170
171protected:
172 KvsObject_webView * m_pParentScript;
173 DOWNLOAD_CLASS_NAME * m_pDownload;
174 int m_Id;
175protected slots:
176 void slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
177 void slotFinished();
178};
179
180#endif // COMPILE_WEBENGINE_SUPPORT
181#endif // _CLASS_WEBVIEW_H_
Definition KviKvsObject.h:51
QObject * object() const
Definition KviKvsObject.h:94
#define e
Definition detector.cpp:70
This file contains compile time settings.
#define KVSO_DECLARE_OBJECT(__className)
Definition object_macros.h:33
int init()
Definition winamp.cpp:118