4 #ifndef pqHelpWindowWebEngine_h 5 #define pqHelpWindowWebEngine_h 18 #include <QNetworkAccessManager> 19 #include <QNetworkProxy> 21 #include <QWebEngineHistory> 22 #include <QWebEngineProfile> 23 #include <QWebEngineUrlRequestJob> 24 #include <QWebEngineUrlSchemeHandler> 25 #include <QWebEngineView> 30 class pqUrlSchemeHandler :
public QWebEngineUrlSchemeHandler
32 typedef QWebEngineUrlSchemeHandler Superclass;
35 pqUrlSchemeHandler(QHelpEngineCore* engine)
39 ~pqUrlSchemeHandler() =
default;
41 void requestStarted(QWebEngineUrlRequestJob* request)
override 43 QMap<QString, QString> extension_type_map;
44 extension_type_map[
"jpg"] =
"image/jpeg";
45 extension_type_map[
"jpeg"] =
"image/jpeg";
46 extension_type_map[
"png"] =
"image/png";
47 extension_type_map[
"gif"] =
"image/gif";
48 extension_type_map[
"tiff"] =
"image/tiff";
49 extension_type_map[
"htm"] =
"text/html";
50 extension_type_map[
"html"] =
"text/html";
51 extension_type_map[
"css"] =
"text/css";
52 extension_type_map[
"xml"] =
"text/xml";
54 QUrl
url = request->requestUrl();
55 QString extension = QFileInfo(url.path()).suffix().toLower();
56 QString content_type = extension_type_map.value(extension,
"text/plain");
58 QByteArray array = this->Engine->fileData(url);
59 QBuffer* buffer =
new QBuffer;
60 buffer->setData(array);
61 buffer->open(QIODevice::ReadOnly);
62 connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater);
63 request->reply(content_type.toUtf8(), buffer);
67 QHelpEngineCore* Engine;
73 class pqWebView :
public QWebEngineView
75 typedef QWebEngineView Superclass;
78 pqWebView(QWidget* parentObject)
79 : Superclass(parentObject)
82 ~pqWebView() =
default;
84 static pqWebView* newInstance(QHelpEngine* engine,
pqHelpWindow*
self)
86 pqWebView* instance =
new pqWebView(
self);
87 QWebEngineProfile*
profile = QWebEngineProfile::defaultProfile();
88 profile->installUrlSchemeHandler(
"qthelp",
new pqUrlSchemeHandler(engine));
94 "This constructor is deprecated, please use the specialized one instead: pqWebView* " 95 "newInstance(QHelpEngine* engine, pqHelpWindow* self)")
96 static pqWebView* newInstance(QHelpEngine* engine, QWidget* parentObject)
98 pqWebView* instance =
new pqWebView(parentObject);
99 QWebEngineProfile* profile = QWebEngineProfile::defaultProfile();
100 profile->installUrlSchemeHandler(
"qthelp",
new pqUrlSchemeHandler(engine));
104 QUrl url() {
return this->history()->currentItem().url(); }
108 this->history()->back();
109 return this->history()->currentItem().url();
114 this->history()->forward();
115 return this->history()->currentItem().url();
118 bool canGoBackward() {
return this->history()->canGoBack(); }
120 bool canGoForward() {
return this->history()->canGoForward(); }
123 Q_DISABLE_COPY(pqWebView)
virtual void updateHistoryButtons()
Update the state of buttons used to navigate through history.
#define PARAVIEW_DEPRECATED_IN_5_12_0(reason)
pqHelpWindow provides a assistant-like window for showing help provided by a QHelpEngine.