4 #ifndef pqHelpWindowWebEngine_h 5 #define pqHelpWindowWebEngine_h 16 #include <QNetworkAccessManager> 17 #include <QNetworkProxy> 19 #include <QWebEngineHistory> 20 #include <QWebEngineProfile> 21 #include <QWebEngineUrlRequestJob> 22 #include <QWebEngineUrlSchemeHandler> 23 #include <QWebEngineView> 28 class pqUrlSchemeHandler :
public QWebEngineUrlSchemeHandler
30 typedef QWebEngineUrlSchemeHandler Superclass;
33 pqUrlSchemeHandler(QHelpEngineCore* engine)
37 ~pqUrlSchemeHandler() =
default;
39 void requestStarted(QWebEngineUrlRequestJob* request)
override 41 QMap<QString, QString> extension_type_map;
42 extension_type_map[
"jpg"] =
"image/jpeg";
43 extension_type_map[
"jpeg"] =
"image/jpeg";
44 extension_type_map[
"png"] =
"image/png";
45 extension_type_map[
"gif"] =
"image/gif";
46 extension_type_map[
"tiff"] =
"image/tiff";
47 extension_type_map[
"htm"] =
"text/html";
48 extension_type_map[
"html"] =
"text/html";
49 extension_type_map[
"css"] =
"text/css";
50 extension_type_map[
"xml"] =
"text/xml";
52 QUrl
url = request->requestUrl();
53 QString extension = QFileInfo(url.path()).suffix().toLower();
54 QString content_type = extension_type_map.value(extension,
"text/plain");
56 QByteArray array = this->Engine->fileData(url);
57 QBuffer* buffer =
new QBuffer;
58 buffer->setData(array);
59 buffer->open(QIODevice::ReadOnly);
60 connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater);
61 request->reply(content_type.toUtf8(), buffer);
65 QHelpEngineCore* Engine;
71 class pqWebView :
public QWebEngineView
73 typedef QWebEngineView Superclass;
76 pqWebView(QWidget* parentObject)
77 : Superclass(parentObject)
80 ~pqWebView() =
default;
82 static pqWebView* newInstance(QHelpEngine* engine,
pqHelpWindow*
self)
84 pqWebView* instance =
new pqWebView(
self);
85 QWebEngineProfile*
profile = QWebEngineProfile::defaultProfile();
86 profile->installUrlSchemeHandler(
"qthelp",
new pqUrlSchemeHandler(engine));
91 QUrl url() {
return this->history()->currentItem().url(); }
95 this->history()->back();
96 return this->history()->currentItem().url();
101 this->history()->forward();
102 return this->history()->currentItem().url();
105 bool canGoBackward() {
return this->history()->canGoBack(); }
107 bool canGoForward() {
return this->history()->canGoForward(); }
110 Q_DISABLE_COPY(pqWebView)
virtual void updateHistoryButtons()
Update the state of buttons used to navigate through history.
pqHelpWindow provides a assistant-like window for showing help provided by a QHelpEngine.