2 Copyright (C) 2007 Trolltech ASA
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.
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.
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.
22 #include "qwebframe.h"
35 \brief The QWebview class provides a widget that is used to view and edit web documents.
37 QWebView is the main widget component of the QtWebKit web browsing module.
41 Constructs an empty QWebView with parent \a parent.
43 QWebView::QWebView(QWidget *parent)
46 d = new QWebViewPrivate;
49 QPalette pal = palette();
50 pal.setBrush(QPalette::Background, Qt::white);
52 setAttribute(Qt::WA_OpaquePaintEvent);
57 setMouseTracking(true);
58 setFocusPolicy(Qt::ClickFocus);
66 if (d->page && d->page->parent() == this)
72 Returns a pointer to the underlying web page.
76 QWebPage *QWebView::page() const
79 QWebView *that = const_cast<QWebView *>(this);
80 that->setPage(new QWebPage(that));
86 Makes \a page the new web page of the web view.
88 The parent QObject of the provided page remains the owner
89 of the object. If the current document is a child of the web
90 view, then it is deleted.
94 void QWebView::setPage(QWebPage *page)
99 if (d->page->parent() == this) {
102 d->page->disconnect(this);
107 d->page->setView(this);
108 // #### connect signals
109 QWebFrame *mainFrame = d->page->mainFrame();
110 connect(mainFrame, SIGNAL(loadStarted()),
111 this, SIGNAL(loadStarted()));
112 connect(mainFrame, SIGNAL(loadFinished()),
113 this, SIGNAL(loadFinished()));
114 connect(mainFrame, SIGNAL(titleChanged(const QString&)),
115 this, SIGNAL(titleChanged(const QString&)));
116 connect(mainFrame, SIGNAL(iconLoaded()),
117 this, SIGNAL(iconLoaded()));
119 connect(d->page, SIGNAL(loadProgressChanged(int)),
120 this, SIGNAL(loadProgressChanged(int)));
121 connect(d->page, SIGNAL(statusBarTextChanged(const QString &)),
122 this, SIGNAL(statusBarTextChanged(const QString &)));
128 Downloads the specified \a url and displays it.
130 void QWebView::load(const QUrl &url)
132 page()->mainFrame()->load(url);
135 #if QT_VERSION < 0x040400
136 void QWebView::load(const QWebNetworkRequest &request)
138 void QWebView::load(const QNetworkRequest &request,
139 QNetworkAccessManager::Operation operation,
140 const QByteArray &body)
143 page()->mainFrame()->load(request
144 #if QT_VERSION >= 0x040400
151 Sets the content of the web view to the specified \a html.
153 External objects referenced in the HTML document are located relative to \a baseUrl.
155 void QWebView::setHtml(const QString &html, const QUrl &baseUrl)
157 page()->mainFrame()->setHtml(html, baseUrl);
161 Sets the content of the web view to the specified \a html.
163 External objects referenced in the HTML document are located relative to \a baseUrl.
165 void QWebView::setHtml(const QByteArray &html, const QUrl &baseUrl)
167 page()->mainFrame()->setHtml(html, baseUrl);
171 Sets the content of the web view to the specified content \a data. If the \a mimeType argument
172 is empty it is assumed that the content is HTML.
174 External objects referenced in the HTML document are located relative to \a baseUrl.
176 void QWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
178 page()->mainFrame()->setContent(data, mimeType, baseUrl);
182 Returns a pointer to the view's history of navigated web pages.
187 view->page()->history();
190 QWebPageHistory *QWebView::history() const
192 return page()->history();
196 Returns a pointer to the view/page specific settings object.
201 view->page()->settings();
204 QWebSettings *QWebView::settings() const
206 return page()->settings();
210 \property QWebView::documentTitle
211 \brief the title of the web page currently viewed.
214 QString QWebView::title() const
217 return d->page->mainFrame()->title();
222 \property QWebView::url
223 \brief the url of the web page currently viewed.
226 QUrl QWebView::url() const
229 return d->page->mainFrame()->url();
234 \property QWebView::icon
235 \brief the icon associated with the web page currently viewed.
238 QPixmap QWebView::icon() const
241 return d->page->mainFrame()->icon();
246 \property QWebView::selectedText
247 \brief the text currently selected.
250 QString QWebView::selectedText() const
253 return d->page->selectedText();
258 Returns a pointer to a QAction that encapsulates the specified web action \a action.
260 QAction *QWebView::action(QWebPage::WebAction action) const
262 return page()->action(action);
266 Triggers the specified \a action. If it is a checkable action the specified \a checked state is assumed.
268 The following example triggers the copy action and therefore copies any selected text to the clipboard.
271 view->triggerAction(QWebPage::Copy);
274 void QWebView::triggerAction(QWebPage::WebAction action, bool checked)
276 page()->triggerAction(action, checked);
280 \propery QWebView::modified
281 \brief Indicates whether the document was modified by the user or not.
283 Parts of HTML documents can be editable for example through the \c{contenteditable} attribute on
286 bool QWebView::isModified() const
289 return d->page->isModified();
293 Qt::TextInteractionFlags QWebView::textInteractionFlags() const
295 // ### FIXME (add to page)
296 return Qt::TextInteractionFlags();
300 \property QWebView::textInteractionFlags
302 Specifies how the view should interact with user input.
305 void QWebView::setTextInteractionFlags(Qt::TextInteractionFlags flags)
308 // ### FIXME (add to page)
311 QSize QWebView::sizeHint() const
313 return QSize(800, 600); // ####...
317 Convenience slot that stops loading the document.
322 view->page()->triggerAction(QWebPage::Stop);
325 void QWebView::stop()
328 d->page->triggerAction(QWebPage::Stop);
332 Convenience slot that loads the previous document in the list of
333 documents built by navigating links. Does nothing if there is no
339 view->page()->triggerAction(QWebPage::GoBack);
342 void QWebView::backward()
345 d->page->triggerAction(QWebPage::GoBack);
349 Convenience slot that loads the next document in the list of
350 documents built by navigating links. Does nothing if there is no
356 view->page()->triggerAction(QWebPage::GoForward);
359 void QWebView::forward()
362 d->page->triggerAction(QWebPage::GoForward);
366 Reloads the current document.
368 void QWebView::reload()
371 d->page->triggerAction(QWebPage::Reload);
376 void QWebView::resizeEvent(QResizeEvent *e)
379 d->page->setViewportSize(e->size());
383 void QWebView::paintEvent(QPaintEvent *ev)
385 #ifdef QWEBKIT_TIME_RENDERING
390 QWebFrame *frame = d->page->mainFrame();
393 QVector<QRect> vector = ev->region().rects();
394 if (!vector.isEmpty()) {
395 for (int i = 0; i < vector.size(); ++i) {
396 frame->render(&p, vector.at(i));
399 frame->render(&p, ev->rect());
402 #ifdef QWEBKIT_TIME_RENDERING
403 int elapsed = time.elapsed();
404 qDebug()<<"paint event on "<<ev->region()<<", took to render = "<<elapsed;
410 void QWebView::mouseMoveEvent(QMouseEvent* ev)
417 void QWebView::mousePressEvent(QMouseEvent* ev)
424 void QWebView::mouseDoubleClickEvent(QMouseEvent* ev)
431 void QWebView::mouseReleaseEvent(QMouseEvent* ev)
438 void QWebView::contextMenuEvent(QContextMenuEvent* ev)
445 void QWebView::wheelEvent(QWheelEvent* ev)
449 if (!ev->isAccepted())
450 return QWidget::wheelEvent(ev);
455 void QWebView::keyPressEvent(QKeyEvent* ev)
462 void QWebView::keyReleaseEvent(QKeyEvent* ev)
469 void QWebView::focusInEvent(QFocusEvent* ev)
472 QWidget::focusInEvent(ev);
477 void QWebView::focusOutEvent(QFocusEvent* ev)
479 QWidget::focusOutEvent(ev);
485 void QWebView::dragEnterEvent(QDragEnterEvent* ev)
492 void QWebView::dragLeaveEvent(QDragLeaveEvent* ev)
499 void QWebView::dragMoveEvent(QDragMoveEvent* ev)
506 void QWebView::dropEvent(QDropEvent* ev)
513 bool QWebView::focusNextPrevChild(bool next)
515 return d->page->focusNextPrevChild(next);