Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerWebWidget.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qSlicerWebWidget_h
22 #define __qSlicerWebWidget_h
23 
24 // Qt includes
25 #include <QSslError>
26 #include <QWidget>
27 
28 // QtGUI includes
29 #include "qSlicerBaseQTGUIExport.h"
30 
31 #include "vtkSlicerConfigure.h" // For Slicer_USE_PYTHONQT_WITH_OPENSSL
32 
33 class QNetworkReply;
34 class qSlicerWebWidgetPrivate;
35 class QUrl;
36 class QWebChannel;
37 #include <QWebEnginePage>
38 class QWebEngineView;
39 
40 #ifdef QT_NO_SSL
41 struct QSslError{};
42 #endif
43 
44 class Q_SLICER_BASE_QTGUI_EXPORT qSlicerWebWidget
45  : public QWidget
46 {
47  Q_OBJECT
48  Q_PROPERTY(bool handleExternalUrlWithDesktopService READ handleExternalUrlWithDesktopService WRITE setHandleExternalUrlWithDesktopService)
49  Q_PROPERTY(QStringList internalHosts READ internalHosts WRITE setInternalHosts)
50  Q_PROPERTY(bool javaScriptConsoleMessageLoggingEnabled READ javaScriptConsoleMessageLoggingEnabled WRITE setJavaScriptConsoleMessageLoggingEnabled)
51  Q_PROPERTY(QString url READ url WRITE setUrl)
52  friend class qSlicerWebEnginePage;
53 public:
55  typedef QWidget Superclass;
56 
58  explicit qSlicerWebWidget(QWidget* parent = nullptr);
59 
61  ~qSlicerWebWidget() override;
62 
71  bool handleExternalUrlWithDesktopService() const;
72  void setHandleExternalUrlWithDesktopService(bool enable);
73 
77  QStringList internalHosts() const;
78  void setInternalHosts(const QStringList& hosts);
79 
86  bool javaScriptConsoleMessageLoggingEnabled() const;
87  void setJavaScriptConsoleMessageLoggingEnabled(bool enable);
88 
89 // QWebEngineProfile* profile()const;
90 // void setProfile(QWebEngineProfile* profile);
91 
93  Q_INVOKABLE QWebEngineView * webView();
94 
97  Q_INVOKABLE QString evalJS(const QString &js);
98 
100  Q_INVOKABLE QString url();
101 
103  Q_INVOKABLE void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
104 
105 public slots:
106 
108  void setUrl(const QString &url);
109 
110  void onDownloadStarted(QNetworkReply* reply);
111 
112  void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
113 
114  void onDownloadFinished(QNetworkReply* reply);
115 
125  void printToPdf(const QString& filePath);
126  void printToPdf(const QString& filePath, const QPageLayout& pageLayout);
128 
129 signals:
131  void evalResult(QString js, QString result);
132 
134  void loadStarted();
135  void loadProgress(int progress);
136  void loadFinished(bool ok);
137 
139  void pdfPrintingFinished(const QString &filePath, bool success);
140 
141 protected slots:
142  virtual void initJavascript();
143  virtual void onLoadStarted();
144  virtual void onLoadProgress(int progress);
145  virtual void onLoadFinished(bool ok);
146  void handleSslErrors(QNetworkReply* reply, const QList<QSslError> &errors);
147 
148 protected:
149  qSlicerWebWidget(qSlicerWebWidgetPrivate* pimpl, QWidget* parent = nullptr);
150  QScopedPointer<qSlicerWebWidgetPrivate> d_ptr;
151 
154  bool eventFilter(QObject *obj, QEvent *event) override;
155 
156  virtual bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool isMainFrame);
157 
158 private:
159  Q_DECLARE_PRIVATE(qSlicerWebWidget);
160  Q_DISABLE_COPY(qSlicerWebWidget);
161 };
162 
163 #endif
QWidget Superclass
Superclass typedef.