diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-07-25 14:04:47 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-26 05:54:37 +0200 |
commit | 419296133aa68a317838e047b22513f1e5508b47 (patch) | |
tree | e3a0597f6d9c83cc2ac06eba385decd3ec12ff62 /src/quick/items/qquickwindow.cpp | |
parent | 57485805057eda17008d14ca618e9c1f69a5a35d (diff) |
Fix resolution of cursor when items are overlapping.
If MouseArea with cursorShapes are overlapping then cursor shape
of the foremost item under the mouse cursor should be shown, but because
the hover events are delivered to the foremost items first the opposite
is occuring. This makes QQuickWindow responsible for correctly setting
its own cursor instead of relying on items to work it out amongst
themselves.
Change-Id: Iedf144c583dfa3d1ff441e19db9601b5e171902a
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/quick/items/qquickwindow.cpp')
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 1d3adea5cb..4cfe1a101c 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -326,6 +326,9 @@ QQuickWindowPrivate::QQuickWindowPrivate() : rootItem(0) , activeFocusItem(0) , mouseGrabberItem(0) +#ifndef QT_NO_CURSOR + , cursorItem(0) +#endif , touchMouseId(-1) , touchMousePressTimestamp(0) , renderWithoutShowing(false) @@ -1301,6 +1304,10 @@ void QQuickWindow::mouseMoveEvent(QMouseEvent *event) qWarning() << "QQuickWindow::mouseMoveEvent()" << event->localPos() << event->button() << event->buttons(); #endif +#ifndef QT_NO_CURSOR + d->updateCursor(event->windowPos()); +#endif + if (!d->mouseGrabberItem) { if (d->lastMousePosition.isNull()) d->lastMousePosition = event->windowPos(); @@ -1832,6 +1839,49 @@ bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickIte } #endif // QT_NO_DRAGANDDROP +#ifndef QT_NO_CURSOR +void QQuickWindowPrivate::updateCursor(const QPointF &scenePos) +{ + Q_Q(QQuickWindow); + + QQuickItem *oldCursorItem = cursorItem; + cursorItem = findCursorItem(rootItem, scenePos); + + if (cursorItem != oldCursorItem) { + if (cursorItem) + q->setCursor(cursorItem->cursor()); + else + q->unsetCursor(); + } +} + +QQuickItem *QQuickWindowPrivate::findCursorItem(QQuickItem *item, const QPointF &scenePos) +{ + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { + QPointF p = item->mapFromScene(scenePos); + if (!item->contains(p)) + return 0; + } + + QList<QQuickItem *> children = itemPrivate->paintOrderChildItems(); + for (int ii = children.count() - 1; ii >= 0; --ii) { + QQuickItem *child = children.at(ii); + if (!child->isVisible() || !child->isEnabled()) + continue; + if (QQuickItem *cursorItem = findCursorItem(child, scenePos)) + return cursorItem; + } + + if (itemPrivate->hasCursor) { + QPointF p = item->mapFromScene(scenePos); + if (item->contains(p)) + return item; + } + return 0; +} +#endif + bool QQuickWindowPrivate::sendFilteredTouchEvent(QQuickItem *target, QQuickItem *item, QTouchEvent *event) { if (!target) |