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 void QWebView::load(const QWebNetworkRequest &request)
137 page()->mainFrame()->load(request);
141 Sets the content of the web view to the specified \a html.
143 External objects referenced in the HTML document are located relative to \a baseUrl.
145 void QWebView::setHtml(const QString &html, const QUrl &baseUrl)
147 page()->mainFrame()->setHtml(html, baseUrl);
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 QByteArray &html, const QUrl &baseUrl)
157 page()->mainFrame()->setHtml(html, baseUrl);
161 Sets the content of the web view to the specified content \a data. If the \a mimeType argument
162 is empty it is assumed that the content is HTML.
164 External objects referenced in the HTML document are located relative to \a baseUrl.
166 void QWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
168 page()->mainFrame()->setContent(data, mimeType, baseUrl);
172 Returns a pointer to the view's history of navigated web pages.
177 view->page()->history();
180 QWebPageHistory *QWebView::history() const
182 return page()->history();
186 Returns a pointer to the view/page specific settings object.
191 view->page()->settings();
194 QWebSettings *QWebView::settings() const
196 return page()->settings();
200 \property QWebView::documentTitle
201 \brief the title of the web page currently viewed.
204 QString QWebView::title() const
207 return d->page->mainFrame()->title();
212 \property QWebView::url
213 \brief the url of the web page currently viewed.
216 QUrl QWebView::url() const
219 return d->page->mainFrame()->url();
224 \property QWebView::icon
225 \brief the icon associated with the web page currently viewed.
228 QPixmap QWebView::icon() const
231 return d->page->mainFrame()->icon();
236 \property QWebView::selectedText
237 \brief the text currently selected.
240 QString QWebView::selectedText() const
243 return d->page->selectedText();
248 Returns a pointer to a QAction that encapsulates the specified web action \a action.
250 QAction *QWebView::action(QWebPage::WebAction action) const
252 return page()->action(action);
256 Triggers the specified \a action. If it is a checkable action the specified \a checked state is assumed.
258 The following example triggers the copy action and therefore copies any selected text to the clipboard.
261 view->triggerAction(QWebPage::Copy);
264 void QWebView::triggerAction(QWebPage::WebAction action, bool checked)
266 page()->triggerAction(action, checked);
270 \propery QWebView::modified
271 \brief Indicates whether the document was modified by the user or not.
273 Parts of HTML documents can be editable for example through the \c{contenteditable} attribute on
276 bool QWebView::isModified() const
279 return d->page->isModified();
283 Qt::TextInteractionFlags QWebView::textInteractionFlags() const
285 // ### FIXME (add to page)
286 return Qt::TextInteractionFlags();
290 \property QWebView::textInteractionFlags
292 Specifies how the view should interact with user input.
295 void QWebView::setTextInteractionFlags(Qt::TextInteractionFlags flags)
298 // ### FIXME (add to page)
301 QSize QWebView::sizeHint() const
303 return QSize(800, 600); // ####...
307 Convenience slot that stops loading the document.
312 view->page()->triggerAction(QWebPage::Stop);
315 void QWebView::stop()
318 d->page->triggerAction(QWebPage::Stop);
322 Convenience slot that loads the previous document in the list of
323 documents built by navigating links. Does nothing if there is no
329 view->page()->triggerAction(QWebPage::GoBack);
332 void QWebView::backward()
335 d->page->triggerAction(QWebPage::GoBack);
339 Convenience slot that loads the next document in the list of
340 documents built by navigating links. Does nothing if there is no
346 view->page()->triggerAction(QWebPage::GoForward);
349 void QWebView::forward()
352 d->page->triggerAction(QWebPage::GoForward);
356 Reloads the current document.
358 void QWebView::reload()
361 d->page->triggerAction(QWebPage::Reload);
366 void QWebView::resizeEvent(QResizeEvent *e)
369 d->page->setViewportSize(e->size());
373 void QWebView::paintEvent(QPaintEvent *ev)
375 #ifdef QWEBKIT_TIME_RENDERING
380 QWebFrame *frame = d->page->mainFrame();
383 QVector<QRect> vector = ev->region().rects();
384 if (!vector.isEmpty()) {
385 for (int i = 0; i < vector.size(); ++i) {
386 frame->render(&p, vector.at(i));
389 frame->render(&p, ev->rect());
392 #ifdef QWEBKIT_TIME_RENDERING
393 int elapsed = time.elapsed();
394 qDebug()<<"paint event on "<<ev->region()<<", took to render = "<<elapsed;
400 void QWebView::mouseMoveEvent(QMouseEvent* ev)
407 void QWebView::mousePressEvent(QMouseEvent* ev)
414 void QWebView::mouseDoubleClickEvent(QMouseEvent* ev)
421 void QWebView::mouseReleaseEvent(QMouseEvent* ev)
428 void QWebView::contextMenuEvent(QContextMenuEvent* ev)
435 void QWebView::wheelEvent(QWheelEvent* ev)
439 if (!ev->isAccepted())
440 return QWidget::wheelEvent(ev);
445 void QWebView::keyPressEvent(QKeyEvent* ev)
452 void QWebView::keyReleaseEvent(QKeyEvent* ev)
459 void QWebView::focusInEvent(QFocusEvent* ev)
462 QWidget::focusInEvent(ev);
467 void QWebView::focusOutEvent(QFocusEvent* ev)
469 QWidget::focusOutEvent(ev);
475 void QWebView::dragEnterEvent(QDragEnterEvent* ev)
482 void QWebView::dragLeaveEvent(QDragLeaveEvent* ev)
489 void QWebView::dragMoveEvent(QDragMoveEvent* ev)
496 void QWebView::dropEvent(QDropEvent* ev)
503 bool QWebView::focusNextPrevChild(bool next)
505 return d->page->focusNextPrevChild(next);