• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "qwebkitglobal.h"
25 #include "qwebpage.h"
26 #include <QtGui/qwidget.h>
27 #include <QtGui/qicon.h>
28 #include <QtGui/qpainter.h>
29 #include <QtCore/qurl.h>
30 #if QT_VERSION >= 0x040400
31 #include <QtNetwork/qnetworkaccessmanager.h>
32 #endif
33 
34 QT_BEGIN_NAMESPACE
35 class QNetworkRequest;
36 class QPrinter;
37 QT_END_NAMESPACE
38 
39 class QWebPage;
40 class QWebViewPrivate;
41 class QWebNetworkRequest;
42 
43 class QWEBKIT_EXPORT QWebView : public QWidget {
44     Q_OBJECT
45     Q_PROPERTY(QString title READ title)
46     Q_PROPERTY(QUrl url READ url WRITE setUrl)
47     Q_PROPERTY(QIcon icon READ icon)
48     Q_PROPERTY(QString selectedText READ selectedText)
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     Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
54     Q_FLAGS(QPainter::RenderHints)
55 public:
56     explicit QWebView(QWidget* parent = 0);
57     virtual ~QWebView();
58 
59     QWebPage* page() const;
60     void setPage(QWebPage* page);
61 
62     static QUrl guessUrlFromString(const QString& string);
63 
64     void load(const QUrl& url);
65 #if QT_VERSION < 0x040400 && !defined(qdoc)
66     void load(const QWebNetworkRequest& request);
67 #else
68     void load(const QNetworkRequest& request,
69               QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
70               const QByteArray &body = QByteArray());
71 #endif
72     void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
73     void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
74 
75     QWebHistory* history() const;
76     QWebSettings* settings() const;
77 
78     QString title() const;
79     void setUrl(const QUrl &url);
80     QUrl url() const;
81     QIcon icon() const;
82 
83     QString selectedText() const;
84 
85     QAction* pageAction(QWebPage::WebAction action) const;
86     void triggerPageAction(QWebPage::WebAction action, bool checked = false);
87 
88     bool isModified() const;
89 
90     /*
91     Qt::TextInteractionFlags textInteractionFlags() const;
92     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
93     void setTextInteractionFlag(Qt::TextInteractionFlag flag);
94     */
95 
96     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
97 
98     QSize sizeHint() const;
99 
100     qreal zoomFactor() const;
101     void setZoomFactor(qreal factor);
102 
103     void setTextSizeMultiplier(qreal factor);
104     qreal textSizeMultiplier() const;
105 
106     QPainter::RenderHints renderHints() const;
107     void setRenderHints(QPainter::RenderHints hints);
108     void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
109 
110     bool findText(const QString& subString, QWebPage::FindFlags options = 0);
111 
112     virtual bool event(QEvent*);
113 
114 public Q_SLOTS:
115     void stop();
116     void back();
117     void forward();
118     void reload();
119 
120     void print(QPrinter*) const;
121 
122 Q_SIGNALS:
123     void loadStarted();
124     void loadProgress(int progress);
125     void loadFinished(bool);
126     void titleChanged(const QString& title);
127     void statusBarMessage(const QString& text);
128     void linkClicked(const QUrl&);
129     void selectionChanged();
130     void iconChanged();
131     void urlChanged(const QUrl&);
132 
133 protected:
134     void resizeEvent(QResizeEvent*);
135     void paintEvent(QPaintEvent*);
136 
137     virtual QWebView *createWindow(QWebPage::WebWindowType type);
138 
139     virtual void changeEvent(QEvent*);
140     virtual void mouseMoveEvent(QMouseEvent*);
141     virtual void mousePressEvent(QMouseEvent*);
142     virtual void mouseDoubleClickEvent(QMouseEvent*);
143     virtual void mouseReleaseEvent(QMouseEvent*);
144 #ifndef QT_NO_CONTEXTMENU
145     virtual void contextMenuEvent(QContextMenuEvent*);
146 #endif
147 #ifndef QT_NO_WHEELEVENT
148     virtual void wheelEvent(QWheelEvent*);
149 #endif
150     virtual void keyPressEvent(QKeyEvent*);
151     virtual void keyReleaseEvent(QKeyEvent*);
152     virtual void dragEnterEvent(QDragEnterEvent*);
153     virtual void dragLeaveEvent(QDragLeaveEvent*);
154     virtual void dragMoveEvent(QDragMoveEvent*);
155     virtual void dropEvent(QDropEvent*);
156     virtual void focusInEvent(QFocusEvent*);
157     virtual void focusOutEvent(QFocusEvent*);
158     virtual void inputMethodEvent(QInputMethodEvent*);
159 
160     virtual bool focusNextPrevChild(bool next);
161 
162 private:
163     friend class QWebPage;
164     QWebViewPrivate* d;
165 };
166 
167 #endif // QWEBVIEW_H
168