diff options
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index ffaec540a2..628e19dbec 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -4886,9 +4886,7 @@ bool QQuickItem::isUnderMouse() const return false; QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition; - if (QRectF(0, 0, width(), height()).contains(mapFromScene(cursorPos))) // ### refactor: d->canvas->mapFromGlobal(cursorPos)))) - return true; - return false; + return contains(mapFromScene(cursorPos)); // ### refactor: d->canvas->mapFromGlobal(cursorPos)))) } bool QQuickItem::acceptHoverEvents() const @@ -5056,6 +5054,24 @@ void QQuickItem::setKeepTouchGrab(bool keep) } /*! + Returns true if this item contains \a point, which is in local coordinates; + returns false otherwise. + + This function can be overwritten in order to handle point collisions in items + with custom shapes. The default implementation checks if the point is inside + the item's bounding rect. + + Note that it's normally used to check if the item is under the mouse cursor, + and for that reason, the implementation of this function should be as light-weight + as possible. +*/ +bool QQuickItem::contains(const QPointF &point) const +{ + Q_D(const QQuickItem); + return QRectF(0, 0, d->width, d->height).contains(point); +} + +/*! \qmlmethod object QtQuick2::Item::mapFromItem(Item item, real x, real y) Maps the point (\a x, \a y), which is in \a item's coordinate system, to |