32 #ifndef pqHelpWindowWebEngine_h 33 #define pqHelpWindowWebEngine_h 46 #include <QNetworkAccessManager> 47 #include <QNetworkProxy> 49 #include <QWebEngineHistory> 50 #include <QWebEngineProfile> 51 #include <QWebEngineUrlRequestJob> 52 #include <QWebEngineUrlSchemeHandler> 53 #include <QWebEngineView> 58 class pqUrlSchemeHandler :
public QWebEngineUrlSchemeHandler
60 typedef QWebEngineUrlSchemeHandler Superclass;
63 pqUrlSchemeHandler(QHelpEngineCore* engine)
67 ~pqUrlSchemeHandler() =
default;
69 void requestStarted(QWebEngineUrlRequestJob* request)
override 71 QMap<QString, QString> extension_type_map;
72 extension_type_map[
"jpg"] =
"image/jpeg";
73 extension_type_map[
"jpeg"] =
"image/jpeg";
74 extension_type_map[
"png"] =
"image/png";
75 extension_type_map[
"gif"] =
"image/gif";
76 extension_type_map[
"tiff"] =
"image/tiff";
77 extension_type_map[
"htm"] =
"text/html";
78 extension_type_map[
"html"] =
"text/html";
79 extension_type_map[
"css"] =
"text/css";
80 extension_type_map[
"xml"] =
"text/xml";
82 QUrl
url = request->requestUrl();
83 QString extension = QFileInfo(url.path()).suffix().toLower();
84 QString content_type = extension_type_map.value(extension,
"text/plain");
86 QByteArray array = this->Engine->fileData(url);
87 QBuffer* buffer =
new QBuffer;
88 buffer->setData(array);
89 buffer->open(QIODevice::ReadOnly);
90 connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater);
91 request->reply(content_type.toUtf8(), buffer);
95 QHelpEngineCore* Engine;
101 class pqWebView :
public QWebEngineView
103 typedef QWebEngineView Superclass;
106 pqWebView(QWidget* parentObject)
107 : Superclass(parentObject)
110 ~pqWebView() =
default;
112 static pqWebView* newInstance(QHelpEngine* engine,
pqHelpWindow*
self)
114 pqWebView* instance =
new pqWebView(
self);
115 QWebEngineProfile*
profile = QWebEngineProfile::defaultProfile();
116 profile->installUrlSchemeHandler(
"qthelp",
new pqUrlSchemeHandler(engine));
122 "This constructor is deprecated, please use the specialized one instead: pqWebView* " 123 "newInstance(QHelpEngine* engine, pqHelpWindow* self)");
124 static pqWebView* newInstance(QHelpEngine* engine, QWidget* parentObject)
126 pqWebView* instance =
new pqWebView(parentObject);
127 QWebEngineProfile* profile = QWebEngineProfile::defaultProfile();
128 profile->installUrlSchemeHandler(
"qthelp",
new pqUrlSchemeHandler(engine));
132 QUrl url() {
return this->history()->currentItem().url(); }
136 this->history()->back();
137 return this->history()->currentItem().url();
142 this->history()->forward();
143 return this->history()->currentItem().url();
146 bool canGoBackward() {
return this->history()->canGoBack(); }
148 bool canGoForward() {
return this->history()->canGoForward(); }
151 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.