Slicer  4.10
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, Slicer_HAVE_WEBKIT_SUPPORT
32 
33 class QNetworkReply;
34 class qSlicerWebWidgetPrivate;
35 class QUrl;
36 #ifdef Slicer_HAVE_WEBKIT_SUPPORT
37 class QWebView;
38 #else
39 class QWebChannel;
40 #include <QWebEnginePage>
41 class QWebEngineView;
42 #endif
43 
44 #if (QT_VERSION < QT_VERSION_CHECK(5, 3, 0))
45 #ifdef QT_NO_OPENSSL
46 struct QSslError{};
47 #endif
48 #else
49 #ifdef QT_NO_SSL
50 struct QSslError{};
51 #endif
52 #endif
53 
54 class Q_SLICER_BASE_QTGUI_EXPORT qSlicerWebWidget
55  : public QWidget
56 {
57  Q_OBJECT
58  Q_PROPERTY(bool handleExternalUrlWithDesktopService READ handleExternalUrlWithDesktopService WRITE setHandleExternalUrlWithDesktopService)
59  Q_PROPERTY(QStringList internalHosts READ internalHosts WRITE setInternalHosts)
60  Q_PROPERTY(QString url READ url WRITE setUrl)
61  friend class qSlicerWebEnginePage;
62 public:
64  typedef QWidget Superclass;
65 
67  explicit qSlicerWebWidget(QWidget* parent = 0);
68 
70  virtual ~qSlicerWebWidget();
71 
80  bool handleExternalUrlWithDesktopService() const;
81  void setHandleExternalUrlWithDesktopService(bool enable);
82 
86  QStringList internalHosts() const;
87  void setInternalHosts(const QStringList& hosts);
88 
89 // QWebEngineProfile* profile()const;
90 // void setProfile(QWebEngineProfile* profile);
91 
93 #ifdef Slicer_HAVE_WEBKIT_SUPPORT
94  Q_INVOKABLE QWebView * webView();
95 #else
96  Q_INVOKABLE QWebEngineView * webView();
97 #endif
98 
101  Q_INVOKABLE QString evalJS(const QString &js);
102 
104  Q_INVOKABLE QString url();
105 
106 public slots:
107 
109  void setUrl(const QString &url);
110 
111  void onDownloadStarted(QNetworkReply* reply);
112 
113  void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
114 
115  void onDownloadFinished(QNetworkReply* reply);
116 
117 signals:
119  void evalResult(QString js, QString result);
120 
122  void loadStarted();
123  void loadProgress(int progress);
124  void loadFinished(bool ok);
125 
126 protected slots:
127  virtual void initJavascript();
128  virtual void onLoadStarted();
129  virtual void onLoadProgress(int progress);
130  virtual void onLoadFinished(bool ok);
131 #ifdef Slicer_HAVE_WEBKIT_SUPPORT
132  virtual void onLinkClicked(const QUrl& url);
133 #endif
134  void handleSslErrors(QNetworkReply* reply, const QList<QSslError> &errors);
135 
136 protected:
137  qSlicerWebWidget(qSlicerWebWidgetPrivate* pimpl, QWidget* parent = 0);
138  QScopedPointer<qSlicerWebWidgetPrivate> d_ptr;
139 
142  bool eventFilter(QObject *obj, QEvent *event);
143 
144 #ifndef Slicer_HAVE_WEBKIT_SUPPORT
145  virtual bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool isMainFrame);
146 #endif
147 
148 private:
149  Q_DECLARE_PRIVATE(qSlicerWebWidget);
150  Q_DISABLE_COPY(qSlicerWebWidget);
151 };
152 
153 #endif
QScopedPointer< qSlicerWebWidgetPrivate > d_ptr
QWidget Superclass
Superclass typedef.