1/*
2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef QGraphicsWebView_h
21#define QGraphicsWebView_h
22
23#include <QtWebKit/qwebkitglobal.h>
24#include <QtWebKitWidgets/qwebpage.h>
25#include <QtCore/qurl.h>
26#include <QtGui/qevent.h>
27#include <QtGui/qicon.h>
28#include <QtGui/qpainter.h>
29#include <QtNetwork/qnetworkaccessmanager.h>
30#include <QtWidgets/qgraphicswidget.h>
31
32#if !defined(QT_NO_GRAPHICSVIEW)
33
34class QWebPage;
35class QWebHistory;
36class QWebSettings;
37
38class QGraphicsWebViewPrivate;
39
40class QWEBKITWIDGETS_EXPORT QGraphicsWebView : public QGraphicsWidget {
41 Q_OBJECT
42
43 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
44 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
45 Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
46
47 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
48
49 Q_PROPERTY(bool modified READ isModified)
50 Q_PROPERTY(bool resizesToContents READ resizesToContents WRITE setResizesToContents)
51 Q_PROPERTY(bool tiledBackingStoreFrozen READ isTiledBackingStoreFrozen WRITE setTiledBackingStoreFrozen)
52
53 Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
54 Q_FLAGS(QPainter::RenderHints)
55
56public:
57 explicit QGraphicsWebView(QGraphicsItem* parent = Q_NULLPTR);
58 ~QGraphicsWebView();
59
60 QWebPage* page() const;
61 void setPage(QWebPage*);
62
63 QUrl url() const;
64 void setUrl(const QUrl&);
65
66 QString title() const;
67 QIcon icon() const;
68
69 qreal zoomFactor() const;
70 void setZoomFactor(qreal);
71
72 bool isModified() const;
73
74 void load(const QUrl& url);
75 void load(const QNetworkRequest& request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray& body = QByteArray());
76
77 void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
78 // FIXME: Consider rename to setHtml?
79 void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
80
81 QWebHistory* history() const;
82 QWebSettings* settings() const;
83
84 QAction* pageAction(QWebPage::WebAction action) const;
85 void triggerPageAction(QWebPage::WebAction action, bool checked = false);
86
87 bool findText(const QString& subString, QWebPage::FindFlags options = QWebPage::FindFlags());
88
89 bool resizesToContents() const;
90 void setResizesToContents(bool enabled);
91
92 bool isTiledBackingStoreFrozen() const;
93 void setTiledBackingStoreFrozen(bool frozen);
94
95 void setGeometry(const QRectF& rect) Q_DECL_OVERRIDE;
96 void updateGeometry() Q_DECL_OVERRIDE;
97 void paint(QPainter*, const QStyleOptionGraphicsItem* options, QWidget* widget = Q_NULLPTR) Q_DECL_OVERRIDE;
98 QVariant itemChange(GraphicsItemChange change, const QVariant& value) Q_DECL_OVERRIDE;
99 bool event(QEvent*) Q_DECL_OVERRIDE;
100
101 QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const Q_DECL_OVERRIDE;
102
103 QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
104
105 QPainter::RenderHints renderHints() const;
106 void setRenderHints(QPainter::RenderHints);
107 void setRenderHint(QPainter::RenderHint, bool enabled = true);
108
109public Q_SLOTS:
110 void stop();
111 void back();
112 void forward();
113 void reload();
114
115Q_SIGNALS:
116 void loadStarted();
117 void loadFinished(bool);
118
119 void loadProgress(int progress);
120 void urlChanged(const QUrl&);
121 void titleChanged(const QString&);
122 void iconChanged();
123 void statusBarMessage(const QString& message);
124 void linkClicked(const QUrl&);
125
126protected:
127 void mousePressEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE;
128 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE;
129 void mouseReleaseEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE;
130 void mouseMoveEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE;
131 void hoverMoveEvent(QGraphicsSceneHoverEvent*) Q_DECL_OVERRIDE;
132 void hoverLeaveEvent(QGraphicsSceneHoverEvent*) Q_DECL_OVERRIDE;
133#ifndef QT_NO_WHEELEVENT
134 void wheelEvent(QGraphicsSceneWheelEvent*) Q_DECL_OVERRIDE;
135#endif
136 void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE;
137 void keyReleaseEvent(QKeyEvent*) Q_DECL_OVERRIDE;
138#ifndef QT_NO_CONTEXTMENU
139 void contextMenuEvent(QGraphicsSceneContextMenuEvent*) Q_DECL_OVERRIDE;
140#endif
141 void dragEnterEvent(QGraphicsSceneDragDropEvent*) Q_DECL_OVERRIDE;
142 void dragLeaveEvent(QGraphicsSceneDragDropEvent*) Q_DECL_OVERRIDE;
143 void dragMoveEvent(QGraphicsSceneDragDropEvent*) Q_DECL_OVERRIDE;
144 void dropEvent(QGraphicsSceneDragDropEvent*) Q_DECL_OVERRIDE;
145 void focusInEvent(QFocusEvent*) Q_DECL_OVERRIDE;
146 void focusOutEvent(QFocusEvent*) Q_DECL_OVERRIDE;
147 void inputMethodEvent(QInputMethodEvent*) Q_DECL_OVERRIDE;
148 bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;
149
150 bool sceneEvent(QEvent*) Q_DECL_OVERRIDE;
151
152private:
153 Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success))
154 Q_PRIVATE_SLOT(d, void _q_pageDestroyed())
155 Q_PRIVATE_SLOT(d, void _q_contentsSizeChanged(const QSize&))
156 Q_PRIVATE_SLOT(d, void _q_scaleChanged())
157
158 QGraphicsWebViewPrivate* const d;
159 friend class QGraphicsWebViewPrivate;
160};
161
162#endif // QT_NO_GRAPHICSVIEW
163
164#endif // QGraphicsWebView_h
165