QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
34class CORE_EXPORT QgsWebView : public QWebView
35{
36 Q_OBJECT
37
38 public:
39 explicit QgsWebView( QWidget *parent = nullptr )
40 : QWebView( parent )
41 {
42 const 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
54class QPrinter;
55
65class 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
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 QUrl url() const
97 {
98 return source();
99 }
100
101 QWebPage *page() const
102 {
103 return mPage;
104 }
105
106 QWebSettings *settings() const
107 {
108 return mSettings;
109 }
110
111 virtual QgsWebView *createWindow( QWebPage::WebWindowType )
112 {
113 return new QgsWebView();
114 }
115
116 void setContent( const QByteArray &data, const QString &contentType, const QUrl & )
117 {
118 QString text = QString::fromUtf8( data );
119 if ( contentType == "text/html" )
120 setHtml( text );
121 else
122 setPlainText( text );
123
124 emit pageLoadFinished( true );
125 }
126
127 void print( QPrinter * )
128 {
129 }
130
131 signals:
132 void linkClicked( const QUrl &link );
133
134 void pageLoadFinished( bool ok );
135
136 public slots:
137
138 void setHtml( const QString &text )
139 {
140 QTextBrowser::setHtml( text );
141 emit pageLoadFinished( true );
142 }
143
144 void setText( const QString &text )
145 {
146 QTextBrowser::setText( text );
147 emit pageLoadFinished( true );
148 }
149
150 private:
151 QWebSettings *mSettings = nullptr;
152 QWebPage *mPage = nullptr;
153
155};
156#endif
157
158#endif // QGSWEBVIEW_H
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
Definition qgswebpage.h:104
The QWebSettings class is a collection of stubs to mimic the API of a QWebSettings on systems where Q...
Definition qgswebpage.h:43
The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real ...
Definition qgswebview.h:66