• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "qwebkitglobal.h"
24 #include "qwebpage.h"
25 #include <QtCore/qurl.h>
26 #include <QtGui/qevent.h>
27 #include <QtGui/qgraphicswidget.h>
28 #include <QtGui/qicon.h>
29 #include <QtGui/qpainter.h>
30 #include <QtNetwork/qnetworkaccessmanager.h>
31 
32 #if !defined(QT_NO_GRAPHICSVIEW)
33 
34 class QWebPage;
35 class QWebHistory;
36 class QWebSettings;
37 
38 class QGraphicsWebViewPrivate;
39 
40 class QWEBKIT_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 
56 public:
57     explicit QGraphicsWebView(QGraphicsItem* parent = 0);
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 = 0);
88 
89     bool resizesToContents() const;
90     void setResizesToContents(bool enabled);
91 
92     bool isTiledBackingStoreFrozen() const;
93     void setTiledBackingStoreFrozen(bool frozen);
94 
95     virtual void setGeometry(const QRectF& rect);
96     virtual void updateGeometry();
97     virtual void paint(QPainter*, const QStyleOptionGraphicsItem* options, QWidget* widget = 0);
98     virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value);
99     virtual bool event(QEvent*);
100 
101     virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const;
102 
103     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
104 
105     QPainter::RenderHints renderHints() const;
106     void setRenderHints(QPainter::RenderHints);
107     void setRenderHint(QPainter::RenderHint, bool enabled = true);
108 
109 public Q_SLOTS:
110     void stop();
111     void back();
112     void forward();
113     void reload();
114 
115 Q_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 
126 protected:
127     virtual void mousePressEvent(QGraphicsSceneMouseEvent*);
128     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
129     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
130     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*);
131     virtual void hoverMoveEvent(QGraphicsSceneHoverEvent*);
132     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
133 #ifndef QT_NO_WHEELEVENT
134     virtual void wheelEvent(QGraphicsSceneWheelEvent*);
135 #endif
136     virtual void keyPressEvent(QKeyEvent*);
137     virtual void keyReleaseEvent(QKeyEvent*);
138 #ifndef QT_NO_CONTEXTMENU
139     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*);
140 #endif
141     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent*);
142     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent*);
143     virtual void dragMoveEvent(QGraphicsSceneDragDropEvent*);
144     virtual void dropEvent(QGraphicsSceneDragDropEvent*);
145     virtual void focusInEvent(QFocusEvent*);
146     virtual void focusOutEvent(QFocusEvent*);
147     virtual void inputMethodEvent(QInputMethodEvent*);
148     virtual bool focusNextPrevChild(bool next);
149 
150     virtual bool sceneEvent(QEvent*);
151 
152 private:
153     Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success))
154     Q_PRIVATE_SLOT(d, void _q_pageDestroyed())
155     // we don't want to change the moc based on USE() macro, so this function is here
156     // but will be empty if ACCLERATED_COMPOSITING is disabled
157     Q_PRIVATE_SLOT(d, void syncLayers())
158     Q_PRIVATE_SLOT(d, void _q_contentsSizeChanged(const QSize&))
159     Q_PRIVATE_SLOT(d, void _q_scaleChanged())
160 
161     QGraphicsWebViewPrivate* const d;
162     friend class QGraphicsWebViewPrivate;
163 };
164 
165 #endif // QT_NO_GRAPHICSVIEW
166 
167 #endif // QGraphicsWebView_h
168