diff options
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 2722f48ce9..6ae74281ca 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -2724,8 +2724,11 @@ void QQuickItemPrivate::addChild(QQuickItem *child) #ifndef QT_NO_CURSOR QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child); - if (childPrivate->extra.isAllocated()) - incrementCursorCount(childPrivate->extra.value().numItemsWithCursor); + + // if the added child has a cursor and we do not currently have any children + // with cursors, bubble the notification up + if (childPrivate->hasCursorInChild && !hasCursorInChild) + setHasCursorInChild(true); #endif markSortedChildrenDirty(child); @@ -2747,8 +2750,10 @@ void QQuickItemPrivate::removeChild(QQuickItem *child) #ifndef QT_NO_CURSOR QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child); - if (childPrivate->extra.isAllocated()) - incrementCursorCount(-childPrivate->extra.value().numItemsWithCursor); + + // turn it off, if nothing else is using it + if (childPrivate->hasCursorInChild && hasCursorInChild) + setHasCursorInChild(false); #endif markSortedChildrenDirty(child); @@ -2843,10 +2848,8 @@ void QQuickItemPrivate::derefWindow() extra->opacityNode = 0; extra->clipNode = 0; extra->rootNode = 0; - extra->beforePaintNode = 0; } - groupNode = 0; paintNode = 0; for (int ii = 0; ii < childItems.count(); ++ii) { @@ -2952,6 +2955,7 @@ QQuickItemPrivate::QQuickItemPrivate() , isAccessible(false) , culled(false) , hasCursor(false) + , hasCursorInChild(false) , activeFocusOnTab(false) , implicitAntialiasing(false) , antialiasingValid(false) @@ -2971,7 +2975,6 @@ QQuickItemPrivate::QQuickItemPrivate() , implicitHeight(0) , baselineOffset(0) , itemNodeInstance(0) - , groupNode(0) , paintNode(0) { } @@ -6736,15 +6739,27 @@ void QQuickItem::setAcceptHoverEvents(bool enabled) d->hoverEnabled = enabled; } -void QQuickItemPrivate::incrementCursorCount(int delta) +void QQuickItemPrivate::setHasCursorInChild(bool hasCursor) { #ifndef QT_NO_CURSOR Q_Q(QQuickItem); - extra.value().numItemsWithCursor += delta; + + // if we're asked to turn it off (because of an unsetcursor call, or a node + // removal) then we should check our children and make sure it's really ok + // to turn it off. + if (!hasCursor && hasCursorInChild) { + foreach (QQuickItem *otherChild, childItems) { + QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild); + if (otherChildPrivate->hasCursorInChild) + return; // nope! sorry, something else wants it kept on. + } + } + + hasCursorInChild = hasCursor; QQuickItem *parent = q->parentItem(); if (parent) { QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent); - parentPrivate->incrementCursorCount(delta); + parentPrivate->setHasCursorInChild(hasCursor); } #endif } @@ -6807,7 +6822,7 @@ void QQuickItem::setCursor(const QCursor &cursor) } if (!d->hasCursor) { - d->incrementCursorCount(+1); + d->setHasCursorInChild(true); d->hasCursor = true; if (d->window) { QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window); @@ -6830,7 +6845,7 @@ void QQuickItem::unsetCursor() Q_D(QQuickItem); if (!d->hasCursor) return; - d->incrementCursorCount(-1); + d->setHasCursorInChild(false); d->hasCursor = false; if (d->extra.isAllocated()) d->extra->cursor = QCursor(); @@ -7819,11 +7834,8 @@ QQuickItemPrivate::ExtraData::ExtraData() : z(0), scale(1), rotation(0), opacity(1), contents(0), screenAttached(0), layoutDirectionAttached(0), keyHandler(0), layer(0), -#ifndef QT_NO_CURSOR - numItemsWithCursor(0), -#endif effectRefCount(0), hideRefCount(0), - opacityNode(0), clipNode(0), rootNode(0), beforePaintNode(0), + opacityNode(0), clipNode(0), rootNode(0), acceptedMouseButtons(0), origin(QQuickItem::Center), transparentForPositioner(false) { |