diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-11-25 03:02:56 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-11-25 03:02:56 (GMT) |
commit | 84f405aa315dfec7c3d26d40a50185046d30164a (patch) | |
tree | 44b1ab7198745b8ce74aa10c662f583701884fbf /src/declarative/graphicsitems | |
parent | 3509b9b5036a3c7d7512c7f0f3f98b2af4227fc2 (diff) | |
download | Qt-84f405aa315dfec7c3d26d40a50185046d30164a.zip Qt-84f405aa315dfec7c3d26d40a50185046d30164a.tar.gz Qt-84f405aa315dfec7c3d26d40a50185046d30164a.tar.bz2 |
Allow dragging be press and hold, in which case don't let Flickable take the drag.
When not press-and-hold, don't pass drags to WebKit.
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicswebview.cpp | 52 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicswebview_p.h | 3 |
2 files changed, 48 insertions, 7 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index aedf787..e21bda3 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -79,6 +79,7 @@ public: : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), newWindowComponent(0), newWindowParent(0), + pressTime(400), windowObjects(this), rendering(true) { @@ -99,6 +100,11 @@ public: QmlComponent *newWindowComponent; QmlGraphicsItem *newWindowParent; + QBasicTimer pressTimer; + QPoint pressPoint; + int pressTime; // milliseconds before it's a "hold" XXX not currently settable + static const int pressDragLength = 15; // XXX #pixels before it's no longer a "hold"; device-specific + void updateWindowObjects(); class WindowObjectList : public QmlConcreteList<QObject *> { @@ -613,8 +619,15 @@ bool QmlGraphicsWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) { + Q_D(QmlGraphicsWebView); + setFocus (true); QMouseEvent *me = sceneMouseEventToMouseEvent(event); + + d->pressPoint = me->pos(); + d->pressTimer.start(d->pressTime,this); + setKeepMouseGrab(false); + page()->event(me); event->setAccepted( /* @@ -636,8 +649,11 @@ void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) void QmlGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + Q_D(QmlGraphicsWebView); + QMouseEvent *me = sceneMouseEventToMouseEvent(event); page()->event(me); + d->pressTimer.stop(); event->setAccepted( /* It is not correct to send the press event upwards, if it is not accepted by WebKit @@ -653,24 +669,45 @@ void QmlGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (!event->isAccepted()) { QmlGraphicsPaintedItem::mouseReleaseEvent(event); } + setKeepMouseGrab(false); + ungrabMouse(); +} + +void QmlGraphicsWebView::timerEvent(QTimerEvent *event) +{ + Q_D(QmlGraphicsWebView); + if (event->timerId() == d->pressTimer.timerId()) { + d->pressTimer.stop(); + grabMouse(); + setKeepMouseGrab(true); + } } void QmlGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + Q_D(QmlGraphicsWebView); + QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - event->setAccepted( + if (d->pressTimer.isActive()) { + if ((me->pos() - d->pressPoint).manhattanLength() > d->pressDragLength) { + d->pressTimer.stop(); + } + } + if (keepMouseGrab()) { + page()->event(me); + event->setAccepted( /* It is not correct to send the press event upwards, if it is not accepted by WebKit e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit Might be a bug in WebKit, though */ #if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 - true + true #else - me->isAccepted() + me->isAccepted() #endif - ); + ); + } delete me; if (!event->isAccepted()) QmlGraphicsPaintedItem::mouseMoveEvent(event); @@ -722,7 +759,6 @@ bool QmlGraphicsWebView::sceneEvent(QEvent *event) } - /*! \qmlproperty action WebView::back This property holds the action for causing the previous URL in the history to be displayed. @@ -1161,6 +1197,8 @@ void QmlGraphicsWebPage::javaScriptConsoleMessage(const QString& message, int li QString QmlGraphicsWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) { // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(oldFile) return oldFile; } @@ -1172,6 +1210,8 @@ void QmlGraphicsWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QStr bool QmlGraphicsWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) { // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) return false; } diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 17546c1..7ff51f3 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -89,7 +89,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem { Q_OBJECT - Q_ENUMS(Status) + Q_ENUMS(Status SelectionMode) Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) @@ -220,6 +220,7 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); void hoverMoveEvent (QGraphicsSceneHoverEvent * event); void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); |