diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> | 2011-05-13 07:01:28 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-05-13 07:01:28 (GMT) |
commit | 80db0a1e59658f9e445219fc48d9236a79edca72 (patch) | |
tree | f5ba50d3e31d038665d2cb15162a5baafa736688 /src | |
parent | 576d577438f1193bbc934e904b809d5b23b8d54e (diff) | |
download | Qt-80db0a1e59658f9e445219fc48d9236a79edca72.zip Qt-80db0a1e59658f9e445219fc48d9236a79edca72.tar.gz Qt-80db0a1e59658f9e445219fc48d9236a79edca72.tar.bz2 |
QDeclarativeMouseArea: block context menu events
If the MouseArea accepts the same button used to trigger a context
menu event, it should not let the event to be delivered to item
behind.
This is important for items that do implement contextMenuEvent(), like
QDeclarativeWebView. When there's a mouse area on top of this item and
that accepts the right click (in Linux), the event was still being
delivered and the WebView menu was incorrectly appearing.
QtWebKit bug https://bugs.webkit.org/show_bug.cgi?id=56526 documents this
problem.
Change-Id: I386fac6c96f47b8616e2eeb7e5f97043ba418980
Merge-request: 1185
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativemousearea.cpp | 26 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativemousearea_p.h | 3 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index d4e7f7b..6633256 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -660,6 +660,32 @@ void QDeclarativeMouseArea::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) setHovered(false); } +#ifndef QT_NO_CONTEXTMENU +void QDeclarativeMouseArea::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + bool acceptsContextMenuButton; +#if defined(Q_OS_SYMBIAN) + // In Symbian a Long Tap on the screen will trigger. See QSymbianControl::HandleLongTapEventL(). + acceptsContextMenuButton = acceptedButtons() & Qt::LeftButton; +#elif defined(Q_WS_WINCE) + // ### WinCE can trigger context menu event with a gesture in the left button or a + // click with the right button. Since we have no way here to differentiate them when + // event happens, accepting either of the them will block the event. + acceptsContextMenuButton = acceptedButtons() & (Qt::LeftButton | Qt::RightButton); +#else + acceptsContextMenuButton = acceptedButtons() & Qt::RightButton; +#endif + + if (isEnabled() && event->reason() == QGraphicsSceneContextMenuEvent::Mouse + && acceptsContextMenuButton) { + // Do not let the context menu event propagate to items behind. + return; + } + + QDeclarativeItem::contextMenuEvent(event); +} +#endif // QT_NO_CONTEXTMENU + bool QDeclarativeMouseArea::sceneEvent(QEvent *event) { bool rv = QDeclarativeItem::sceneEvent(event); diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h index 351d4de..0fe8c6a 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h @@ -190,6 +190,9 @@ protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); +#ifndef QT_NO_CONTEXTMENU + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); +#endif // QT_NO_CONTEXTMENU bool sceneEvent(QEvent *); bool sendMouseEvent(QGraphicsSceneMouseEvent *event); bool sceneEventFilter(QGraphicsItem *i, QEvent *e); |