| 1 | /*
|
|---|
| 2 | Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
|
|---|
| 3 | Copyright (C) 2009 Girish Ramakrishnan <[email protected]>
|
|---|
| 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 | #include "config.h"
|
|---|
| 22 | #include "qgraphicswebview.h"
|
|---|
| 23 |
|
|---|
| 24 | #include "qwebframe.h"
|
|---|
| 25 | #include "qwebpage.h"
|
|---|
| 26 | #include "qwebpage_p.h"
|
|---|
| 27 | #include "QWebPageClient.h"
|
|---|
| 28 | #include <QtGui/QGraphicsScene>
|
|---|
| 29 | #include <QtGui/QGraphicsView>
|
|---|
| 30 | #include <QtGui/qapplication.h>
|
|---|
| 31 | #include <QtGui/qgraphicssceneevent.h>
|
|---|
| 32 | #include <QtGui/qstyleoption.h>
|
|---|
| 33 | #include <QtGui/qinputcontext.h>
|
|---|
| 34 | #if defined(Q_WS_X11)
|
|---|
| 35 | #include <QX11Info>
|
|---|
| 36 | #endif
|
|---|
| 37 |
|
|---|
| 38 | class QGraphicsWebViewPrivate : public QWebPageClient {
|
|---|
| 39 | public:
|
|---|
| 40 | QGraphicsWebViewPrivate(QGraphicsWebView* parent)
|
|---|
| 41 | : q(parent)
|
|---|
| 42 | , page(0)
|
|---|
| 43 | {}
|
|---|
| 44 |
|
|---|
| 45 | virtual ~QGraphicsWebViewPrivate();
|
|---|
| 46 | virtual void scroll(int dx, int dy, const QRect&);
|
|---|
| 47 | virtual void update(const QRect& dirtyRect);
|
|---|
| 48 | virtual void setInputMethodEnabled(bool enable);
|
|---|
| 49 | virtual bool inputMethodEnabled() const;
|
|---|
| 50 | #if QT_VERSION >= 0x040600
|
|---|
| 51 | virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable);
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | #ifndef QT_NO_CURSOR
|
|---|
| 55 | virtual QCursor cursor() const;
|
|---|
| 56 | virtual void updateCursor(const QCursor& cursor);
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | virtual QPalette palette() const;
|
|---|
| 60 | virtual int screenNumber() const;
|
|---|
| 61 | virtual QWidget* ownerWidget() const;
|
|---|
| 62 |
|
|---|
| 63 | virtual QObject* pluginParent() const;
|
|---|
| 64 |
|
|---|
| 65 | void _q_doLoadFinished(bool success);
|
|---|
| 66 |
|
|---|
| 67 | void _q_updateMicroFocus();
|
|---|
| 68 | void _q_pageDestroyed();
|
|---|
| 69 |
|
|---|
| 70 | QGraphicsWebView* q;
|
|---|
| 71 | QWebPage* page;
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate()
|
|---|
| 75 | {
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | void QGraphicsWebViewPrivate::_q_doLoadFinished(bool success)
|
|---|
| 79 | {
|
|---|
| 80 | // If the page had no title, still make sure it gets the signal
|
|---|
| 81 | if (q->title().isEmpty())
|
|---|
| 82 | emit q->urlChanged(q->url());
|
|---|
| 83 |
|
|---|
| 84 | emit q->loadFinished(success);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void QGraphicsWebViewPrivate::_q_updateMicroFocus()
|
|---|
| 88 | {
|
|---|
| 89 | #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
|
|---|
| 90 | // Ideally, this should be handled by a common call to an updateMicroFocus function
|
|---|
| 91 | // in QGraphicsItem. See http://bugreports.qt.nokia.com/browse/QTBUG-7578.
|
|---|
| 92 | QList<QGraphicsView*> views = q->scene()->views();
|
|---|
| 93 | for (int c = 0; c < views.size(); ++c) {
|
|---|
| 94 | QInputContext* ic = views.at(c)->inputContext();
|
|---|
| 95 | if (ic)
|
|---|
| 96 | ic->update();
|
|---|
| 97 | }
|
|---|
| 98 | #endif
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | void QGraphicsWebViewPrivate::_q_pageDestroyed()
|
|---|
| 102 | {
|
|---|
| 103 | page = 0;
|
|---|
| 104 | q->setPage(0);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | void QGraphicsWebViewPrivate::scroll(int dx, int dy, const QRect& rectToScroll)
|
|---|
| 108 | {
|
|---|
| 109 | q->scroll(qreal(dx), qreal(dy), QRectF(rectToScroll));
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | void QGraphicsWebViewPrivate::update(const QRect & dirtyRect)
|
|---|
| 113 | {
|
|---|
| 114 | q->update(QRectF(dirtyRect));
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | void QGraphicsWebViewPrivate::setInputMethodEnabled(bool enable)
|
|---|
| 119 | {
|
|---|
| 120 | #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
|
|---|
| 121 | q->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable);
|
|---|
| 122 | #endif
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | bool QGraphicsWebViewPrivate::inputMethodEnabled() const
|
|---|
| 126 | {
|
|---|
| 127 | #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
|
|---|
| 128 | return q->flags() & QGraphicsItem::ItemAcceptsInputMethod;
|
|---|
| 129 | #else
|
|---|
| 130 | return false;
|
|---|
| 131 | #endif
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | #if QT_VERSION >= 0x040600
|
|---|
| 135 | void QGraphicsWebViewPrivate::setInputMethodHint(Qt::InputMethodHint hint, bool enable)
|
|---|
| 136 | {
|
|---|
| 137 | if (enable)
|
|---|
| 138 | q->setInputMethodHints(q->inputMethodHints() | hint);
|
|---|
| 139 | else
|
|---|
| 140 | q->setInputMethodHints(q->inputMethodHints() & ~hint);
|
|---|
| 141 | }
|
|---|
| 142 | #endif
|
|---|
| 143 | #ifndef QT_NO_CURSOR
|
|---|
| 144 | QCursor QGraphicsWebViewPrivate::cursor() const
|
|---|
| 145 | {
|
|---|
| 146 | return q->cursor();
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | void QGraphicsWebViewPrivate::updateCursor(const QCursor& cursor)
|
|---|
| 150 | {
|
|---|
| 151 | q->setCursor(cursor);
|
|---|
| 152 | }
|
|---|
| 153 | #endif
|
|---|
| 154 |
|
|---|
| 155 | QPalette QGraphicsWebViewPrivate::palette() const
|
|---|
| 156 | {
|
|---|
| 157 | return q->palette();
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | int QGraphicsWebViewPrivate::screenNumber() const
|
|---|
| 161 | {
|
|---|
| 162 | #if defined(Q_WS_X11)
|
|---|
| 163 | const QList<QGraphicsView*> views = q->scene()->views();
|
|---|
| 164 |
|
|---|
| 165 | if (!views.isEmpty())
|
|---|
| 166 | return views.at(0)->x11Info().screen();
|
|---|
| 167 | #endif
|
|---|
| 168 |
|
|---|
| 169 | return 0;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | QWidget* QGraphicsWebViewPrivate::ownerWidget() const
|
|---|
| 173 | {
|
|---|
| 174 | const QList<QGraphicsView*> views = q->scene()->views();
|
|---|
| 175 | return views.value(0);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | QObject* QGraphicsWebViewPrivate::pluginParent() const
|
|---|
| 179 | {
|
|---|
| 180 | return q;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | /*!
|
|---|
| 184 | \class QGraphicsWebView
|
|---|
| 185 | \brief The QGraphicsWebView class allows Web content to be added to a GraphicsView.
|
|---|
| 186 | \since 4.6
|
|---|
| 187 |
|
|---|
| 188 | An instance of this class renders Web content from a URL or supplied as data, using
|
|---|
| 189 | features of the QtWebKit module.
|
|---|
| 190 |
|
|---|
| 191 | If the width and height of the item are not set, they will default to 800 and 600,
|
|---|
| 192 | respectively. If the Web page contents is larger than that, scrollbars will be shown
|
|---|
| 193 | if not disabled explicitly.
|
|---|
| 194 |
|
|---|
| 195 | \section1 Browser Features
|
|---|
| 196 |
|
|---|
| 197 | Many of the functions, signals and properties provided by QWebView are also available
|
|---|
| 198 | for this item, making it simple to adapt existing code to use QGraphicsWebView instead
|
|---|
| 199 | of QWebView.
|
|---|
| 200 |
|
|---|
| 201 | The item uses a QWebPage object to perform the rendering of Web content, and this can
|
|---|
| 202 | be obtained with the page() function, enabling the document itself to be accessed and
|
|---|
| 203 | modified.
|
|---|
| 204 |
|
|---|
| 205 | As with QWebView, the item records the browsing history using a QWebHistory object,
|
|---|
| 206 | accessible using the history() function. The QWebSettings object that defines the
|
|---|
| 207 | configuration of the browser can be obtained with the settings() function, enabling
|
|---|
| 208 | features like plugin support to be customized for each item.
|
|---|
| 209 |
|
|---|
| 210 | \sa QWebView, QGraphicsTextItem
|
|---|
| 211 | */
|
|---|
| 212 |
|
|---|
| 213 | /*!
|
|---|
| 214 | \fn void QGraphicsWebView::titleChanged(const QString &title)
|
|---|
| 215 |
|
|---|
| 216 | This signal is emitted whenever the \a title of the main frame changes.
|
|---|
| 217 |
|
|---|
| 218 | \sa title()
|
|---|
| 219 | */
|
|---|
| 220 |
|
|---|
| 221 | /*!
|
|---|
| 222 | \fn void QGraphicsWebView::urlChanged(const QUrl &url)
|
|---|
| 223 |
|
|---|
| 224 | This signal is emitted when the \a url of the view changes.
|
|---|
| 225 |
|
|---|
| 226 | \sa url(), load()
|
|---|
| 227 | */
|
|---|
| 228 |
|
|---|
| 229 | /*!
|
|---|
| 230 | \fn void QGraphicsWebView::iconChanged()
|
|---|
| 231 |
|
|---|
| 232 | This signal is emitted whenever the icon of the page is loaded or changes.
|
|---|
| 233 |
|
|---|
| 234 | In order for icons to be loaded, you will need to set an icon database path
|
|---|
| 235 | using QWebSettings::setIconDatabasePath().
|
|---|
| 236 |
|
|---|
| 237 | \sa icon(), QWebSettings::setIconDatabasePath()
|
|---|
| 238 | */
|
|---|
| 239 |
|
|---|
| 240 | /*!
|
|---|
| 241 | \fn void QGraphicsWebView::loadStarted()
|
|---|
| 242 |
|
|---|
| 243 | This signal is emitted when a new load of the page is started.
|
|---|
| 244 |
|
|---|
| 245 | \sa loadProgress(), loadFinished()
|
|---|
| 246 | */
|
|---|
| 247 |
|
|---|
| 248 | /*!
|
|---|
| 249 | \fn void QGraphicsWebView::loadFinished(bool ok)
|
|---|
| 250 |
|
|---|
| 251 | This signal is emitted when a load of the page is finished.
|
|---|
| 252 | \a ok will indicate whether the load was successful or any error occurred.
|
|---|
| 253 |
|
|---|
| 254 | \sa loadStarted()
|
|---|
| 255 | */
|
|---|
| 256 |
|
|---|
| 257 | /*!
|
|---|
| 258 | Constructs an empty QGraphicsWebView with parent \a parent.
|
|---|
| 259 |
|
|---|
| 260 | \sa load()
|
|---|
| 261 | */
|
|---|
| 262 | QGraphicsWebView::QGraphicsWebView(QGraphicsItem* parent)
|
|---|
| 263 | : QGraphicsWidget(parent)
|
|---|
| 264 | , d(new QGraphicsWebViewPrivate(this))
|
|---|
| 265 | {
|
|---|
| 266 | #if QT_VERSION >= 0x040600
|
|---|
| 267 | setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
|
|---|
| 268 | #endif
|
|---|
| 269 | setAcceptHoverEvents(true);
|
|---|
| 270 | setFocusPolicy(Qt::StrongFocus);
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | /*!
|
|---|
| 274 | Destroys the item.
|
|---|
| 275 | */
|
|---|
| 276 | QGraphicsWebView::~QGraphicsWebView()
|
|---|
| 277 | {
|
|---|
| 278 | if (d->page) {
|
|---|
| 279 | #if QT_VERSION >= 0x040600
|
|---|
| 280 | d->page->d->view.clear();
|
|---|
| 281 | #else
|
|---|
| 282 | d->page->d->view = 0;
|
|---|
| 283 | #endif
|
|---|
| 284 | d->page->d->client = 0; // unset the page client
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | if (d->page && d->page->parent() == this)
|
|---|
| 288 | delete d->page;
|
|---|
| 289 |
|
|---|
| 290 | delete d;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | /*!
|
|---|
| 294 | Returns a pointer to the underlying web page.
|
|---|
| 295 |
|
|---|
| 296 | \sa setPage()
|
|---|
| 297 | */
|
|---|
| 298 | QWebPage* QGraphicsWebView::page() const
|
|---|
| 299 | {
|
|---|
| 300 | if (!d->page) {
|
|---|
| 301 | QGraphicsWebView* that = const_cast<QGraphicsWebView*>(this);
|
|---|
| 302 | QWebPage* page = new QWebPage(that);
|
|---|
| 303 |
|
|---|
| 304 | // Default to not having a background, in the case
|
|---|
| 305 | // the page doesn't provide one.
|
|---|
| 306 | QPalette palette = QApplication::palette();
|
|---|
| 307 | palette.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
|
|---|
| 308 | page->setPalette(palette);
|
|---|
| 309 |
|
|---|
| 310 | that->setPage(page);
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | return d->page;
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | /*! \reimp
|
|---|
| 317 | */
|
|---|
| 318 | void QGraphicsWebView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*)
|
|---|
| 319 | {
|
|---|
| 320 | page()->mainFrame()->render(painter, option->exposedRect.toRect());
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | /*! \reimp
|
|---|
| 324 | */
|
|---|
| 325 | bool QGraphicsWebView::sceneEvent(QEvent* event)
|
|---|
| 326 | {
|
|---|
| 327 | // Re-implemented in order to allows fixing event-related bugs in patch releases.
|
|---|
| 328 | return QGraphicsWidget::sceneEvent(event);
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | /*! \reimp
|
|---|
| 332 | */
|
|---|
| 333 | QVariant QGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant& value)
|
|---|
| 334 | {
|
|---|
| 335 | switch (change) {
|
|---|
| 336 | // Differently from QWebView, it is interesting to QGraphicsWebView to handle
|
|---|
| 337 | // post mouse cursor change notifications. Reason: 'ItemCursorChange' is sent
|
|---|
| 338 | // as the first action in QGraphicsItem::setCursor implementation, and at that
|
|---|
| 339 | // item widget's cursor has not been effectively changed yet.
|
|---|
| 340 | // After cursor is properly set (at 'ItemCursorHasChanged' emission time), we
|
|---|
| 341 | // fire 'CursorChange'.
|
|---|
| 342 | case ItemCursorChange:
|
|---|
| 343 | return value;
|
|---|
| 344 | case ItemCursorHasChanged:
|
|---|
| 345 | QEvent event(QEvent::CursorChange);
|
|---|
| 346 | QApplication::sendEvent(this, &event);
|
|---|
| 347 | return value;
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | return QGraphicsWidget::itemChange(change, value);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | /*! \reimp
|
|---|
| 354 | */
|
|---|
| 355 | QSizeF QGraphicsWebView::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
|
|---|
| 356 | {
|
|---|
| 357 | if (which == Qt::PreferredSize)
|
|---|
| 358 | return QSizeF(800, 600); // ###
|
|---|
| 359 | return QGraphicsWidget::sizeHint(which, constraint);
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | /*! \reimp
|
|---|
| 363 | */
|
|---|
| 364 | QVariant QGraphicsWebView::inputMethodQuery(Qt::InputMethodQuery query) const
|
|---|
| 365 | {
|
|---|
| 366 | if (d->page)
|
|---|
| 367 | return d->page->inputMethodQuery(query);
|
|---|
| 368 | return QVariant();
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | /*! \reimp
|
|---|
| 372 | */
|
|---|
| 373 | bool QGraphicsWebView::event(QEvent* event)
|
|---|
| 374 | {
|
|---|
| 375 | // Re-implemented in order to allows fixing event-related bugs in patch releases.
|
|---|
| 376 |
|
|---|
| 377 | if (d->page) {
|
|---|
| 378 | #ifndef QT_NO_CONTEXTMENU
|
|---|
| 379 | if (event->type() == QEvent::GraphicsSceneContextMenu) {
|
|---|
| 380 | if (!isEnabled())
|
|---|
| 381 | return false;
|
|---|
| 382 |
|
|---|
| 383 | QGraphicsSceneContextMenuEvent* ev = static_cast<QGraphicsSceneContextMenuEvent*>(event);
|
|---|
| 384 | QContextMenuEvent fakeEvent(QContextMenuEvent::Reason(ev->reason()), ev->pos().toPoint());
|
|---|
| 385 | if (d->page->swallowContextMenuEvent(&fakeEvent)) {
|
|---|
| 386 | event->accept();
|
|---|
| 387 | return true;
|
|---|
| 388 | }
|
|---|
| 389 | d->page->updatePositionDependentActions(fakeEvent.pos());
|
|---|
| 390 | } else
|
|---|
| 391 | #endif // QT_NO_CONTEXTMENU
|
|---|
| 392 | {
|
|---|
| 393 | #ifndef QT_NO_CURSOR
|
|---|
| 394 | #if QT_VERSION >= 0x040400
|
|---|
| 395 | if (event->type() == QEvent::CursorChange) {
|
|---|
| 396 | // An unsetCursor will set the cursor to Qt::ArrowCursor.
|
|---|
| 397 | // Thus this cursor change might be a QWidget::unsetCursor()
|
|---|
| 398 | // If this is not the case and it came from WebCore, the
|
|---|
| 399 | // QWebPageClient already has set its cursor internally
|
|---|
| 400 | // to Qt::ArrowCursor, so updating the cursor is always
|
|---|
| 401 | // right, as it falls back to the last cursor set by
|
|---|
| 402 | // WebCore.
|
|---|
| 403 | // FIXME: Add a QEvent::CursorUnset or similar to Qt.
|
|---|
| 404 | if (cursor().shape() == Qt::ArrowCursor)
|
|---|
| 405 | d->resetCursor();
|
|---|
| 406 | }
|
|---|
| 407 | #endif
|
|---|
| 408 | #endif
|
|---|
| 409 | }
|
|---|
| 410 | }
|
|---|
| 411 | return QGraphicsWidget::event(event);
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | /*!
|
|---|
| 415 | Makes \a page the new web page of the web graphicsitem.
|
|---|
| 416 |
|
|---|
| 417 | The parent QObject of the provided page remains the owner
|
|---|
| 418 | of the object. If the current document is a child of the web
|
|---|
| 419 | view, it will be deleted.
|
|---|
| 420 |
|
|---|
| 421 | \sa page()
|
|---|
| 422 | */
|
|---|
| 423 | void QGraphicsWebView::setPage(QWebPage* page)
|
|---|
| 424 | {
|
|---|
| 425 | if (d->page == page)
|
|---|
| 426 | return;
|
|---|
| 427 |
|
|---|
| 428 | if (d->page) {
|
|---|
| 429 | d->page->d->client = 0; // unset the page client
|
|---|
| 430 | if (d->page->parent() == this)
|
|---|
| 431 | delete d->page;
|
|---|
| 432 | else
|
|---|
| 433 | d->page->disconnect(this);
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | d->page = page;
|
|---|
| 437 | if (!d->page)
|
|---|
| 438 | return;
|
|---|
| 439 | d->page->d->client = d; // set the page client
|
|---|
| 440 |
|
|---|
| 441 | QSize size = geometry().size().toSize();
|
|---|
| 442 | page->setViewportSize(size);
|
|---|
| 443 |
|
|---|
| 444 | QWebFrame* mainFrame = d->page->mainFrame();
|
|---|
| 445 |
|
|---|
| 446 | connect(mainFrame, SIGNAL(titleChanged(QString)),
|
|---|
| 447 | this, SIGNAL(titleChanged(QString)));
|
|---|
| 448 | connect(mainFrame, SIGNAL(iconChanged()),
|
|---|
| 449 | this, SIGNAL(iconChanged()));
|
|---|
| 450 | connect(mainFrame, SIGNAL(urlChanged(QUrl)),
|
|---|
| 451 | this, SIGNAL(urlChanged(QUrl)));
|
|---|
| 452 | connect(d->page, SIGNAL(loadStarted()),
|
|---|
| 453 | this, SIGNAL(loadStarted()));
|
|---|
| 454 | connect(d->page, SIGNAL(loadProgress(int)),
|
|---|
| 455 | this, SIGNAL(loadProgress(int)));
|
|---|
| 456 | connect(d->page, SIGNAL(loadFinished(bool)),
|
|---|
| 457 | this, SLOT(_q_doLoadFinished(bool)));
|
|---|
| 458 | connect(d->page, SIGNAL(statusBarMessage(QString)),
|
|---|
| 459 | this, SIGNAL(statusBarMessage(QString)));
|
|---|
| 460 | connect(d->page, SIGNAL(linkClicked(QUrl)),
|
|---|
| 461 | this, SIGNAL(linkClicked(QUrl)));
|
|---|
| 462 | connect(d->page, SIGNAL(microFocusChanged()),
|
|---|
| 463 | this, SLOT(_q_updateMicroFocus()));
|
|---|
| 464 | connect(d->page, SIGNAL(destroyed()),
|
|---|
| 465 | this, SLOT(_q_pageDestroyed()));
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | /*!
|
|---|
| 469 | \property QGraphicsWebView::url
|
|---|
| 470 | \brief the url of the web page currently viewed
|
|---|
| 471 |
|
|---|
| 472 | Setting this property clears the view and loads the URL.
|
|---|
| 473 |
|
|---|
| 474 | By default, this property contains an empty, invalid URL.
|
|---|
| 475 |
|
|---|
| 476 | \sa load(), urlChanged()
|
|---|
| 477 | */
|
|---|
| 478 |
|
|---|
| 479 | void QGraphicsWebView::setUrl(const QUrl &url)
|
|---|
| 480 | {
|
|---|
| 481 | page()->mainFrame()->setUrl(url);
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | QUrl QGraphicsWebView::url() const
|
|---|
| 485 | {
|
|---|
| 486 | if (d->page)
|
|---|
| 487 | return d->page->mainFrame()->url();
|
|---|
| 488 |
|
|---|
| 489 | return QUrl();
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | /*!
|
|---|
| 493 | \property QGraphicsWebView::title
|
|---|
| 494 | \brief the title of the web page currently viewed
|
|---|
| 495 |
|
|---|
| 496 | By default, this property contains an empty string.
|
|---|
| 497 |
|
|---|
| 498 | \sa titleChanged()
|
|---|
| 499 | */
|
|---|
| 500 | QString QGraphicsWebView::title() const
|
|---|
| 501 | {
|
|---|
| 502 | if (d->page)
|
|---|
| 503 | return d->page->mainFrame()->title();
|
|---|
| 504 |
|
|---|
| 505 | return QString();
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | /*!
|
|---|
| 509 | \property QGraphicsWebView::icon
|
|---|
| 510 | \brief the icon associated with the web page currently viewed
|
|---|
| 511 |
|
|---|
| 512 | By default, this property contains a null icon.
|
|---|
| 513 |
|
|---|
| 514 | \sa iconChanged(), QWebSettings::iconForUrl()
|
|---|
| 515 | */
|
|---|
| 516 | QIcon QGraphicsWebView::icon() const
|
|---|
| 517 | {
|
|---|
| 518 | if (d->page)
|
|---|
| 519 | return d->page->mainFrame()->icon();
|
|---|
| 520 |
|
|---|
| 521 | return QIcon();
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | /*!
|
|---|
| 525 | \property QGraphicsWebView::zoomFactor
|
|---|
| 526 | \since 4.5
|
|---|
| 527 | \brief the zoom factor for the view
|
|---|
| 528 | */
|
|---|
| 529 |
|
|---|
| 530 | void QGraphicsWebView::setZoomFactor(qreal factor)
|
|---|
| 531 | {
|
|---|
| 532 | if (factor == page()->mainFrame()->zoomFactor())
|
|---|
| 533 | return;
|
|---|
| 534 |
|
|---|
| 535 | page()->mainFrame()->setZoomFactor(factor);
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | qreal QGraphicsWebView::zoomFactor() const
|
|---|
| 539 | {
|
|---|
| 540 | return page()->mainFrame()->zoomFactor();
|
|---|
| 541 | }
|
|---|
| 542 |
|
|---|
| 543 | /*! \reimp
|
|---|
| 544 | */
|
|---|
| 545 | void QGraphicsWebView::updateGeometry()
|
|---|
| 546 | {
|
|---|
| 547 | QGraphicsWidget::updateGeometry();
|
|---|
| 548 |
|
|---|
| 549 | if (!d->page)
|
|---|
| 550 | return;
|
|---|
| 551 |
|
|---|
| 552 | QSize size = geometry().size().toSize();
|
|---|
| 553 | d->page->setViewportSize(size);
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| 556 | /*! \reimp
|
|---|
| 557 | */
|
|---|
| 558 | void QGraphicsWebView::setGeometry(const QRectF& rect)
|
|---|
| 559 | {
|
|---|
| 560 | QGraphicsWidget::setGeometry(rect);
|
|---|
| 561 |
|
|---|
| 562 | if (!d->page)
|
|---|
| 563 | return;
|
|---|
| 564 |
|
|---|
| 565 | // NOTE: call geometry() as setGeometry ensures that
|
|---|
| 566 | // the geometry is within legal bounds (minimumSize, maximumSize)
|
|---|
| 567 | QSize size = geometry().size().toSize();
|
|---|
| 568 | d->page->setViewportSize(size);
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | /*!
|
|---|
| 572 | Convenience slot that stops loading the document.
|
|---|
| 573 |
|
|---|
| 574 | \sa reload(), loadFinished()
|
|---|
| 575 | */
|
|---|
| 576 | void QGraphicsWebView::stop()
|
|---|
| 577 | {
|
|---|
| 578 | if (d->page)
|
|---|
| 579 | d->page->triggerAction(QWebPage::Stop);
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | /*!
|
|---|
| 583 | Convenience slot that loads the previous document in the list of documents
|
|---|
| 584 | built by navigating links. Does nothing if there is no previous document.
|
|---|
| 585 |
|
|---|
| 586 | \sa forward()
|
|---|
| 587 | */
|
|---|
| 588 | void QGraphicsWebView::back()
|
|---|
| 589 | {
|
|---|
| 590 | if (d->page)
|
|---|
| 591 | d->page->triggerAction(QWebPage::Back);
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | /*!
|
|---|
| 595 | Convenience slot that loads the next document in the list of documents
|
|---|
| 596 | built by navigating links. Does nothing if there is no next document.
|
|---|
| 597 |
|
|---|
| 598 | \sa back()
|
|---|
| 599 | */
|
|---|
| 600 | void QGraphicsWebView::forward()
|
|---|
| 601 | {
|
|---|
| 602 | if (d->page)
|
|---|
| 603 | d->page->triggerAction(QWebPage::Forward);
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | /*!
|
|---|
| 607 | Reloads the current document.
|
|---|
| 608 |
|
|---|
| 609 | \sa stop(), loadStarted()
|
|---|
| 610 | */
|
|---|
| 611 | void QGraphicsWebView::reload()
|
|---|
| 612 | {
|
|---|
| 613 | if (d->page)
|
|---|
| 614 | d->page->triggerAction(QWebPage::Reload);
|
|---|
| 615 | }
|
|---|
| 616 |
|
|---|
| 617 | /*!
|
|---|
| 618 | Loads the specified \a url and displays it.
|
|---|
| 619 |
|
|---|
| 620 | \note The view remains the same until enough data has arrived to display the new \a url.
|
|---|
| 621 |
|
|---|
| 622 | \sa setUrl(), url(), urlChanged()
|
|---|
| 623 | */
|
|---|
| 624 | void QGraphicsWebView::load(const QUrl& url)
|
|---|
| 625 | {
|
|---|
| 626 | page()->mainFrame()->load(url);
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | /*!
|
|---|
| 630 | \fn void QGraphicsWebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body)
|
|---|
| 631 |
|
|---|
| 632 | Loads a network request, \a request, using the method specified in \a operation.
|
|---|
| 633 |
|
|---|
| 634 | \a body is optional and is only used for POST operations.
|
|---|
| 635 |
|
|---|
| 636 | \note The view remains the same until enough data has arrived to display the new url.
|
|---|
| 637 |
|
|---|
| 638 | \sa url(), urlChanged()
|
|---|
| 639 | */
|
|---|
| 640 |
|
|---|
| 641 | void QGraphicsWebView::load(const QNetworkRequest& request,
|
|---|
| 642 | QNetworkAccessManager::Operation operation,
|
|---|
| 643 | const QByteArray& body)
|
|---|
| 644 | {
|
|---|
| 645 | page()->mainFrame()->load(request, operation, body);
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | /*!
|
|---|
| 649 | Sets the content of the web view to the specified \a html.
|
|---|
| 650 |
|
|---|
| 651 | External objects such as stylesheets or images referenced in the HTML
|
|---|
| 652 | document are located relative to \a baseUrl.
|
|---|
| 653 |
|
|---|
| 654 | The \a html is loaded immediately; external objects are loaded asynchronously.
|
|---|
| 655 |
|
|---|
| 656 | When using this method, WebKit assumes that external resources such as
|
|---|
| 657 | JavaScript programs or style sheets are encoded in UTF-8 unless otherwise
|
|---|
| 658 | specified. For example, the encoding of an external script can be specified
|
|---|
| 659 | through the charset attribute of the HTML script tag. Alternatively, the
|
|---|
| 660 | encoding can also be specified by the web server.
|
|---|
| 661 |
|
|---|
| 662 | \sa load(), setContent(), QWebFrame::toHtml()
|
|---|
| 663 | */
|
|---|
| 664 | void QGraphicsWebView::setHtml(const QString& html, const QUrl& baseUrl)
|
|---|
| 665 | {
|
|---|
| 666 | page()->mainFrame()->setHtml(html, baseUrl);
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | /*!
|
|---|
| 670 | Sets the content of the web graphicsitem to the specified content \a data. If the \a mimeType argument
|
|---|
| 671 | is empty it is currently assumed that the content is HTML but in future versions we may introduce
|
|---|
| 672 | auto-detection.
|
|---|
| 673 |
|
|---|
| 674 | External objects referenced in the content are located relative to \a baseUrl.
|
|---|
| 675 |
|
|---|
| 676 | The \a data is loaded immediately; external objects are loaded asynchronously.
|
|---|
| 677 |
|
|---|
| 678 | \sa load(), setHtml(), QWebFrame::toHtml()
|
|---|
| 679 | */
|
|---|
| 680 | void QGraphicsWebView::setContent(const QByteArray& data, const QString& mimeType, const QUrl& baseUrl)
|
|---|
| 681 | {
|
|---|
| 682 | page()->mainFrame()->setContent(data, mimeType, baseUrl);
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 | /*!
|
|---|
| 686 | Returns a pointer to the view's history of navigated web pages.
|
|---|
| 687 |
|
|---|
| 688 | It is equivalent to
|
|---|
| 689 |
|
|---|
| 690 | \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 0
|
|---|
| 691 | */
|
|---|
| 692 | QWebHistory* QGraphicsWebView::history() const
|
|---|
| 693 | {
|
|---|
| 694 | return page()->history();
|
|---|
| 695 | }
|
|---|
| 696 |
|
|---|
| 697 | /*!
|
|---|
| 698 | \property QGraphicsWebView::modified
|
|---|
| 699 | \brief whether the document was modified by the user
|
|---|
| 700 |
|
|---|
| 701 | Parts of HTML documents can be editable for example through the
|
|---|
| 702 | \c{contenteditable} attribute on HTML elements.
|
|---|
| 703 |
|
|---|
| 704 | By default, this property is false.
|
|---|
| 705 | */
|
|---|
| 706 | bool QGraphicsWebView::isModified() const
|
|---|
| 707 | {
|
|---|
| 708 | if (d->page)
|
|---|
| 709 | return d->page->isModified();
|
|---|
| 710 | return false;
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 | /*!
|
|---|
| 714 | Returns a pointer to the view/page specific settings object.
|
|---|
| 715 |
|
|---|
| 716 | It is equivalent to
|
|---|
| 717 |
|
|---|
| 718 | \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 1
|
|---|
| 719 |
|
|---|
| 720 | \sa QWebSettings::globalSettings()
|
|---|
| 721 | */
|
|---|
| 722 | QWebSettings* QGraphicsWebView::settings() const
|
|---|
| 723 | {
|
|---|
| 724 | return page()->settings();
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | /*!
|
|---|
| 728 | Returns a pointer to a QAction that encapsulates the specified web action \a action.
|
|---|
| 729 | */
|
|---|
| 730 | QAction *QGraphicsWebView::pageAction(QWebPage::WebAction action) const
|
|---|
| 731 | {
|
|---|
| 732 | return page()->action(action);
|
|---|
| 733 | }
|
|---|
| 734 |
|
|---|
| 735 | /*!
|
|---|
| 736 | Triggers the specified \a action. If it is a checkable action the specified
|
|---|
| 737 | \a checked state is assumed.
|
|---|
| 738 |
|
|---|
| 739 | \sa pageAction()
|
|---|
| 740 | */
|
|---|
| 741 | void QGraphicsWebView::triggerPageAction(QWebPage::WebAction action, bool checked)
|
|---|
| 742 | {
|
|---|
| 743 | page()->triggerAction(action, checked);
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | /*!
|
|---|
| 747 | Finds the specified string, \a subString, in the page, using the given \a options.
|
|---|
| 748 |
|
|---|
| 749 | If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences
|
|---|
| 750 | that exist in the page. All subsequent calls will extend the highlight, rather than
|
|---|
| 751 | replace it, with occurrences of the new string.
|
|---|
| 752 |
|
|---|
| 753 | If the HighlightAllOccurrences flag is not passed, the function will select an occurrence
|
|---|
| 754 | and all subsequent calls will replace the current occurrence with the next one.
|
|---|
| 755 |
|
|---|
| 756 | To clear the selection, just pass an empty string.
|
|---|
| 757 |
|
|---|
| 758 | Returns true if \a subString was found; otherwise returns false.
|
|---|
| 759 |
|
|---|
| 760 | \sa QWebPage::selectedText(), QWebPage::selectionChanged()
|
|---|
| 761 | */
|
|---|
| 762 | bool QGraphicsWebView::findText(const QString &subString, QWebPage::FindFlags options)
|
|---|
| 763 | {
|
|---|
| 764 | if (d->page)
|
|---|
| 765 | return d->page->findText(subString, options);
|
|---|
| 766 | return false;
|
|---|
| 767 | }
|
|---|
| 768 |
|
|---|
| 769 | /*! \reimp
|
|---|
| 770 | */
|
|---|
| 771 | void QGraphicsWebView::hoverMoveEvent(QGraphicsSceneHoverEvent* ev)
|
|---|
| 772 | {
|
|---|
| 773 | if (d->page) {
|
|---|
| 774 | const bool accepted = ev->isAccepted();
|
|---|
| 775 | QMouseEvent me = QMouseEvent(QEvent::MouseMove,
|
|---|
| 776 | ev->pos().toPoint(), Qt::NoButton,
|
|---|
| 777 | Qt::NoButton, Qt::NoModifier);
|
|---|
| 778 | d->page->event(&me);
|
|---|
| 779 | ev->setAccepted(accepted);
|
|---|
| 780 | }
|
|---|
| 781 |
|
|---|
| 782 | if (!ev->isAccepted())
|
|---|
| 783 | QGraphicsItem::hoverMoveEvent(ev);
|
|---|
| 784 | }
|
|---|
| 785 |
|
|---|
| 786 | /*! \reimp
|
|---|
| 787 | */
|
|---|
| 788 | void QGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent* ev)
|
|---|
| 789 | {
|
|---|
| 790 | Q_UNUSED(ev);
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | /*! \reimp
|
|---|
| 794 | */
|
|---|
| 795 | void QGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent* ev)
|
|---|
| 796 | {
|
|---|
| 797 | if (d->page) {
|
|---|
| 798 | const bool accepted = ev->isAccepted();
|
|---|
| 799 | d->page->event(ev);
|
|---|
| 800 | ev->setAccepted(accepted);
|
|---|
| 801 | }
|
|---|
| 802 |
|
|---|
| 803 | if (!ev->isAccepted())
|
|---|
| 804 | QGraphicsItem::mouseMoveEvent(ev);
|
|---|
| 805 | }
|
|---|
| 806 |
|
|---|
| 807 | /*! \reimp
|
|---|
| 808 | */
|
|---|
| 809 | void QGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent* ev)
|
|---|
| 810 | {
|
|---|
| 811 | if (d->page) {
|
|---|
| 812 | const bool accepted = ev->isAccepted();
|
|---|
| 813 | d->page->event(ev);
|
|---|
| 814 | ev->setAccepted(accepted);
|
|---|
| 815 | }
|
|---|
| 816 |
|
|---|
| 817 | if (!ev->isAccepted())
|
|---|
| 818 | QGraphicsItem::mousePressEvent(ev);
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | /*! \reimp
|
|---|
| 822 | */
|
|---|
| 823 | void QGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent* ev)
|
|---|
| 824 | {
|
|---|
| 825 | if (d->page) {
|
|---|
| 826 | const bool accepted = ev->isAccepted();
|
|---|
| 827 | d->page->event(ev);
|
|---|
| 828 | ev->setAccepted(accepted);
|
|---|
| 829 | }
|
|---|
| 830 |
|
|---|
| 831 | if (!ev->isAccepted())
|
|---|
| 832 | QGraphicsItem::mouseReleaseEvent(ev);
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | /*! \reimp
|
|---|
| 836 | */
|
|---|
| 837 | void QGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* ev)
|
|---|
| 838 | {
|
|---|
| 839 | if (d->page) {
|
|---|
| 840 | const bool accepted = ev->isAccepted();
|
|---|
| 841 | d->page->event(ev);
|
|---|
| 842 | ev->setAccepted(accepted);
|
|---|
| 843 | }
|
|---|
| 844 |
|
|---|
| 845 | if (!ev->isAccepted())
|
|---|
| 846 | QGraphicsItem::mouseDoubleClickEvent(ev);
|
|---|
| 847 | }
|
|---|
| 848 |
|
|---|
| 849 | /*! \reimp
|
|---|
| 850 | */
|
|---|
| 851 | void QGraphicsWebView::keyPressEvent(QKeyEvent* ev)
|
|---|
| 852 | {
|
|---|
| 853 | if (d->page)
|
|---|
| 854 | d->page->event(ev);
|
|---|
| 855 |
|
|---|
| 856 | if (!ev->isAccepted())
|
|---|
| 857 | QGraphicsItem::keyPressEvent(ev);
|
|---|
| 858 | }
|
|---|
| 859 |
|
|---|
| 860 | /*! \reimp
|
|---|
| 861 | */
|
|---|
| 862 | void QGraphicsWebView::keyReleaseEvent(QKeyEvent* ev)
|
|---|
| 863 | {
|
|---|
| 864 | if (d->page)
|
|---|
| 865 | d->page->event(ev);
|
|---|
| 866 |
|
|---|
| 867 | if (!ev->isAccepted())
|
|---|
| 868 | QGraphicsItem::keyReleaseEvent(ev);
|
|---|
| 869 | }
|
|---|
| 870 |
|
|---|
| 871 | /*! \reimp
|
|---|
| 872 | */
|
|---|
| 873 | void QGraphicsWebView::focusInEvent(QFocusEvent* ev)
|
|---|
| 874 | {
|
|---|
| 875 | if (d->page)
|
|---|
| 876 | d->page->event(ev);
|
|---|
| 877 | else
|
|---|
| 878 | QGraphicsItem::focusInEvent(ev);
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 | /*! \reimp
|
|---|
| 882 | */
|
|---|
| 883 | void QGraphicsWebView::focusOutEvent(QFocusEvent* ev)
|
|---|
| 884 | {
|
|---|
| 885 | if (d->page)
|
|---|
| 886 | d->page->event(ev);
|
|---|
| 887 | else
|
|---|
| 888 | QGraphicsItem::focusOutEvent(ev);
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 | /*! \reimp
|
|---|
| 892 | */
|
|---|
| 893 | bool QGraphicsWebView::focusNextPrevChild(bool next)
|
|---|
| 894 | {
|
|---|
| 895 | if (d->page)
|
|---|
| 896 | return d->page->focusNextPrevChild(next);
|
|---|
| 897 |
|
|---|
| 898 | return QGraphicsWidget::focusNextPrevChild(next);
|
|---|
| 899 | }
|
|---|
| 900 |
|
|---|
| 901 | /*! \reimp
|
|---|
| 902 | */
|
|---|
| 903 | void QGraphicsWebView::dragEnterEvent(QGraphicsSceneDragDropEvent* ev)
|
|---|
| 904 | {
|
|---|
| 905 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 906 | //if (d->page)
|
|---|
| 907 | // d->page->event(ev);
|
|---|
| 908 | //Just remove this line below when the code above is working
|
|---|
| 909 | Q_UNUSED(ev);
|
|---|
| 910 | #else
|
|---|
| 911 | Q_UNUSED(ev);
|
|---|
| 912 | #endif
|
|---|
| 913 | }
|
|---|
| 914 |
|
|---|
| 915 | /*! \reimp
|
|---|
| 916 | */
|
|---|
| 917 | void QGraphicsWebView::dragLeaveEvent(QGraphicsSceneDragDropEvent* ev)
|
|---|
| 918 | {
|
|---|
| 919 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 920 | if (d->page) {
|
|---|
| 921 | const bool accepted = ev->isAccepted();
|
|---|
| 922 | d->page->event(ev);
|
|---|
| 923 | ev->setAccepted(accepted);
|
|---|
| 924 | }
|
|---|
| 925 |
|
|---|
| 926 | if (!ev->isAccepted())
|
|---|
| 927 | QGraphicsWidget::dragLeaveEvent(ev);
|
|---|
| 928 | #else
|
|---|
| 929 | Q_UNUSED(ev);
|
|---|
| 930 | #endif
|
|---|
| 931 | }
|
|---|
| 932 |
|
|---|
| 933 | /*! \reimp
|
|---|
| 934 | */
|
|---|
| 935 | void QGraphicsWebView::dragMoveEvent(QGraphicsSceneDragDropEvent* ev)
|
|---|
| 936 | {
|
|---|
| 937 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 938 | if (d->page) {
|
|---|
| 939 | const bool accepted = ev->isAccepted();
|
|---|
| 940 | d->page->event(ev);
|
|---|
| 941 | ev->setAccepted(accepted);
|
|---|
| 942 | }
|
|---|
| 943 |
|
|---|
| 944 | if (!ev->isAccepted())
|
|---|
| 945 | QGraphicsWidget::dragMoveEvent(ev);
|
|---|
| 946 | #else
|
|---|
| 947 | Q_UNUSED(ev);
|
|---|
| 948 | #endif
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | /*! \reimp
|
|---|
| 952 | */
|
|---|
| 953 | void QGraphicsWebView::dropEvent(QGraphicsSceneDragDropEvent* ev)
|
|---|
| 954 | {
|
|---|
| 955 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 956 | if (d->page) {
|
|---|
| 957 | const bool accepted = ev->isAccepted();
|
|---|
| 958 | d->page->event(ev);
|
|---|
| 959 | ev->setAccepted(accepted);
|
|---|
| 960 | }
|
|---|
| 961 |
|
|---|
| 962 | if (!ev->isAccepted())
|
|---|
| 963 | QGraphicsWidget::dropEvent(ev);
|
|---|
| 964 | #else
|
|---|
| 965 | Q_UNUSED(ev);
|
|---|
| 966 | #endif
|
|---|
| 967 | }
|
|---|
| 968 |
|
|---|
| 969 | #ifndef QT_NO_CONTEXTMENU
|
|---|
| 970 | /*! \reimp
|
|---|
| 971 | */
|
|---|
| 972 | void QGraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent* ev)
|
|---|
| 973 | {
|
|---|
| 974 | if (d->page) {
|
|---|
| 975 | const bool accepted = ev->isAccepted();
|
|---|
| 976 | d->page->event(ev);
|
|---|
| 977 | ev->setAccepted(accepted);
|
|---|
| 978 | }
|
|---|
| 979 | }
|
|---|
| 980 | #endif // QT_NO_CONTEXTMENU
|
|---|
| 981 |
|
|---|
| 982 | #ifndef QT_NO_WHEELEVENT
|
|---|
| 983 | /*! \reimp
|
|---|
| 984 | */
|
|---|
| 985 | void QGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent* ev)
|
|---|
| 986 | {
|
|---|
| 987 | if (d->page) {
|
|---|
| 988 | const bool accepted = ev->isAccepted();
|
|---|
| 989 | d->page->event(ev);
|
|---|
| 990 | ev->setAccepted(accepted);
|
|---|
| 991 | }
|
|---|
| 992 |
|
|---|
| 993 | if (!ev->isAccepted())
|
|---|
| 994 | QGraphicsItem::wheelEvent(ev);
|
|---|
| 995 | }
|
|---|
| 996 | #endif // QT_NO_WHEELEVENT
|
|---|
| 997 |
|
|---|
| 998 | /*! \reimp
|
|---|
| 999 | */
|
|---|
| 1000 | void QGraphicsWebView::inputMethodEvent(QInputMethodEvent* ev)
|
|---|
| 1001 | {
|
|---|
| 1002 | if (d->page)
|
|---|
| 1003 | d->page->event(ev);
|
|---|
| 1004 |
|
|---|
| 1005 | if (!ev->isAccepted())
|
|---|
| 1006 | QGraphicsItem::inputMethodEvent(ev);
|
|---|
| 1007 | }
|
|---|
| 1008 |
|
|---|
| 1009 | /*!
|
|---|
| 1010 | \fn void QGraphicsWebView::statusBarMessage(const QString& text)
|
|---|
| 1011 |
|
|---|
| 1012 | This signal is emitted when the statusbar \a text is changed by the page.
|
|---|
| 1013 | */
|
|---|
| 1014 |
|
|---|
| 1015 | /*!
|
|---|
| 1016 | \fn void QGraphicsWebView::loadProgress(int progress)
|
|---|
| 1017 |
|
|---|
| 1018 | This signal is emitted every time an element in the web page
|
|---|
| 1019 | completes loading and the overall loading progress advances.
|
|---|
| 1020 |
|
|---|
| 1021 | This signal tracks the progress of all child frames.
|
|---|
| 1022 |
|
|---|
| 1023 | The current value is provided by \a progress and scales from 0 to 100,
|
|---|
| 1024 | which is the default range of QProgressBar.
|
|---|
| 1025 |
|
|---|
| 1026 | \sa loadStarted(), loadFinished()
|
|---|
| 1027 | */
|
|---|
| 1028 |
|
|---|
| 1029 | /*!
|
|---|
| 1030 | \fn void QGraphicsWebView::linkClicked(const QUrl &url)
|
|---|
| 1031 |
|
|---|
| 1032 | This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy
|
|---|
| 1033 | property is set to delegate the link handling for the specified \a url.
|
|---|
| 1034 |
|
|---|
| 1035 | \sa QWebPage::linkDelegationPolicy()
|
|---|
| 1036 | */
|
|---|
| 1037 |
|
|---|
| 1038 | #include "moc_qgraphicswebview.cpp"
|
|---|