1/*
2    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3    Copyright (C) 2007 Staikos Computing Services Inc.
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19*/
20
21#ifndef QWEBVIEW_H
22#define QWEBVIEW_H
23
24#include <QtWebKit/qwebkitglobal.h>
25#include <QtWebKitWidgets/qwebpage.h>
26#include <QtCore/qurl.h>
27#include <QtGui/qicon.h>
28#include <QtGui/qpainter.h>
29#include <QtNetwork/qnetworkaccessmanager.h>
30#include <QtWidgets/qwidget.h>
31
32QT_BEGIN_NAMESPACE
33class QNetworkRequest;
34class QPrinter;
35QT_END_NAMESPACE
36
37class QWebPage;
38class QWebViewPrivate;
39class QWebNetworkRequest;
40
41class QWEBKITWIDGETS_EXPORT QWebView : public QWidget {
42    Q_OBJECT
43    Q_PROPERTY(QString title READ title)
44    Q_PROPERTY(QUrl url READ url WRITE setUrl)
45    Q_PROPERTY(QIcon icon READ icon)
46    Q_PROPERTY(QString selectedText READ selectedText)
47    Q_PROPERTY(QString selectedHtml READ selectedHtml)
48    Q_PROPERTY(bool hasSelection READ hasSelection)
49    Q_PROPERTY(bool modified READ isModified)
50    //Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
51    Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
52    Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
53
54    Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
55    Q_FLAGS(QPainter::RenderHints)
56public:
57    explicit QWebView(QWidget* parent = 0);
58    virtual ~QWebView();
59
60    QWebPage* page() const;
61    void setPage(QWebPage* page);
62
63    void load(const QUrl& url);
64    void load(const QNetworkRequest& request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray());
65    void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
66    void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
67
68    QWebHistory* history() const;
69    QWebSettings* settings() const;
70
71    QString title() const;
72    void setUrl(const QUrl &url);
73    QUrl url() const;
74    QIcon icon() const;
75
76    bool hasSelection() const;
77    QString selectedText() const;
78    QString selectedHtml() const;
79
80#ifndef QT_NO_ACTION
81    QAction* pageAction(QWebPage::WebAction action) const;
82#endif
83    void triggerPageAction(QWebPage::WebAction action, bool checked = false);
84
85    bool isModified() const;
86
87    /*
88    Qt::TextInteractionFlags textInteractionFlags() const;
89    void setTextInteractionFlags(Qt::TextInteractionFlags flags);
90    void setTextInteractionFlag(Qt::TextInteractionFlag flag);
91    */
92
93    QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
94
95    QSize sizeHint() const;
96
97    qreal zoomFactor() const;
98    void setZoomFactor(qreal factor);
99
100    void setTextSizeMultiplier(qreal factor);
101    qreal textSizeMultiplier() const;
102
103    QPainter::RenderHints renderHints() const;
104    void setRenderHints(QPainter::RenderHints hints);
105    void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
106
107    bool findText(const QString& subString, QWebPage::FindFlags options = 0);
108
109    virtual bool event(QEvent*);
110
111public Q_SLOTS:
112    void stop();
113    void back();
114    void forward();
115    void reload();
116
117    void print(QPrinter*) const;
118
119Q_SIGNALS:
120    void loadStarted();
121    void loadProgress(int progress);
122    void loadFinished(bool);
123    void titleChanged(const QString& title);
124    void statusBarMessage(const QString& text);
125    void linkClicked(const QUrl&);
126    void selectionChanged();
127    void iconChanged();
128    void urlChanged(const QUrl&);
129
130protected:
131    void resizeEvent(QResizeEvent*);
132    void paintEvent(QPaintEvent*);
133
134    virtual QWebView *createWindow(QWebPage::WebWindowType type);
135
136    virtual void changeEvent(QEvent*);
137    virtual void mouseMoveEvent(QMouseEvent*);
138    virtual void mousePressEvent(QMouseEvent*);
139    virtual void mouseDoubleClickEvent(QMouseEvent*);
140    virtual void mouseReleaseEvent(QMouseEvent*);
141#ifndef QT_NO_CONTEXTMENU
142    virtual void contextMenuEvent(QContextMenuEvent*);
143#endif
144#ifndef QT_NO_WHEELEVENT
145    virtual void wheelEvent(QWheelEvent*);
146#endif
147    virtual void keyPressEvent(QKeyEvent*);
148    virtual void keyReleaseEvent(QKeyEvent*);
149    virtual void dragEnterEvent(QDragEnterEvent*);
150    virtual void dragLeaveEvent(QDragLeaveEvent*);
151    virtual void dragMoveEvent(QDragMoveEvent*);
152    virtual void dropEvent(QDropEvent*);
153    virtual void focusInEvent(QFocusEvent*);
154    virtual void focusOutEvent(QFocusEvent*);
155    virtual void inputMethodEvent(QInputMethodEvent*);
156
157    virtual bool focusNextPrevChild(bool next);
158
159private:
160    friend class QWebPage;
161    QWebViewPrivate* d;
162    Q_PRIVATE_SLOT(d, void _q_pageDestroyed())
163};
164
165#endif // QWEBVIEW_H
166