Slicer  4.11
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(QString url READ url WRITE setUrl)
51  friend class qSlicerWebEnginePage;
52 public:
54  typedef QWidget Superclass;
55 
57  explicit qSlicerWebWidget(QWidget* parent = nullptr);
58 
60  ~qSlicerWebWidget() override;
61 
70  bool handleExternalUrlWithDesktopService() const;
71  void setHandleExternalUrlWithDesktopService(bool enable);
72 
76  QStringList internalHosts() const;
77  void setInternalHosts(const QStringList& hosts);
78 
79 // QWebEngineProfile* profile()const;
80 // void setProfile(QWebEngineProfile* profile);
81 
83  Q_INVOKABLE QWebEngineView * webView();
84 
87  Q_INVOKABLE QString evalJS(const QString &js);
88 
90  Q_INVOKABLE QString url();
91 
93  Q_INVOKABLE void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
94 
95 public slots:
96 
98  void setUrl(const QString &url);
99 
100  void onDownloadStarted(QNetworkReply* reply);
101 
102  void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
103 
104  void onDownloadFinished(QNetworkReply* reply);
105 
114  void printToPdf(const QString& filePath);
115 
116 signals:
118  void evalResult(QString js, QString result);
119 
121  void loadStarted();
122  void loadProgress(int progress);
123  void loadFinished(bool ok);
124 
126  void pdfPrintingFinished(const QString &filePath, bool success);
127 
128 protected slots:
129  virtual void initJavascript();
130  virtual void onLoadStarted();
131  virtual void onLoadProgress(int progress);
132  virtual void onLoadFinished(bool ok);
133  void handleSslErrors(QNetworkReply* reply, const QList<QSslError> &errors);
134 
135 protected:
136  qSlicerWebWidget(qSlicerWebWidgetPrivate* pimpl, QWidget* parent = nullptr);
137  QScopedPointer<qSlicerWebWidgetPrivate> d_ptr;
138 
141  bool eventFilter(QObject *obj, QEvent *event) override;
142 
143  virtual bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool isMainFrame);
144 
145 private:
146  Q_DECLARE_PRIVATE(qSlicerWebWidget);
147  Q_DISABLE_COPY(qSlicerWebWidget);
148 };
149 
150 #endif
QWidget Superclass
Superclass typedef.