QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgswebview.h
Go to the documentation of this file.
1 /***************************************************************************
2 
3  ----------------------------------------------------
4  date : 19.5.2015
5  copyright : (C) 2015 by Matthias Kuhn
6  email : matthias (at) opengis.ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSWEBVIEW_H
17 #define QGSWEBVIEW_H
18 
19 
20 #define SIP_NO_FILE
21 
22 #include <QWidget>
23 
24 #ifdef WITH_QTWEBKIT
25 #include <QWebView>
26 #include <QDesktopWidget>
27 
28 #include "qgis_core.h"
29 
30 
34 class CORE_EXPORT QgsWebView : public QWebView
35 {
36  Q_OBJECT
37 
38  public:
39  explicit QgsWebView( QWidget *parent = nullptr )
40  : QWebView( parent )
41  {
42  QDesktopWidget desktop;
43  // Apply zoom factor for HiDPI screens
44  if ( desktop.logicalDpiX() > 96 )
45  {
46  setZoomFactor( desktop.logicalDpiX() / 96 );
47  }
48  }
49 };
50 #else
51 #include "qgswebpage.h"
52 #include <QTextBrowser>
53 
54 class QPrinter;
55 
65 class CORE_EXPORT QgsWebView : public QTextBrowser
66 {
67 
69  Q_OBJECT
70  public:
71  explicit QgsWebView( QWidget *parent = nullptr )
72  : QTextBrowser( parent )
73  , mSettings( new QWebSettings() )
74  , mPage( new QWebPage( this ) )
75  {
76  connect( this, &QTextBrowser::anchorClicked, this, &QgsWebView::linkClicked );
77  connect( this, &QgsWebView::pageLoadFinished, mPage, &QWebPage::loadFinished );
78  }
79 
80  ~QgsWebView()
81  {
82  delete mSettings;
83  delete mPage;
84  }
85 
86  void setUrl( const QUrl &url )
87  {
88  setSource( url );
89  }
90 
91  void load( const QUrl &url )
92  {
93  setSource( url );
94  }
95 
96  QWebPage *page() const
97  {
98  return mPage;
99  }
100 
101  QWebSettings *settings() const
102  {
103  return mSettings;
104  }
105 
106  virtual QgsWebView *createWindow( QWebPage::WebWindowType )
107  {
108  return new QgsWebView();
109  }
110 
111  void setContent( const QByteArray &data, const QString &contentType, const QUrl & )
112  {
113  QString text = QString::fromUtf8( data );
114  if ( contentType == "text/html" )
115  setHtml( text );
116  else
117  setPlainText( text );
118 
119  emit pageLoadFinished( true );
120  }
121 
122  void print( QPrinter * )
123  {
124  }
125 
126  signals:
127  void linkClicked( const QUrl &link );
128 
129  void pageLoadFinished( bool ok );
130 
131  private:
132  QWebSettings *mSettings = nullptr;
133  QWebPage *mPage = nullptr;
134 
136 };
137 #endif
138 
139 #endif // QGSWEBVIEW_H
The QWebSettings class is a collection of stubs to mimic the API of a QWebSettings on systems where Q...
Definition: qgswebpage.h:42
The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real ...
Definition: qgswebview.h:65
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
Definition: qgswebpage.h:103