diff options
author | Martin Jones <martin.jones@nokia.com> | 2012-01-06 09:58:27 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-06 03:56:26 +0100 |
commit | 8e0ea24115bcc9bf88ff09572feb05493ebc35c4 (patch) | |
tree | aeaaf11e9cb4237a9c7f3a5727df5cbe8ad27da8 /src | |
parent | c13098fa6e0dcaca1022f1c50ced6cba4d5f7168 (diff) |
Add itemAt(x,y) function to GridView and ListView.
Task-number: QTBUG-21592
Change-Id: I3169e789da701ce261250421239584abd7f29b57
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickgridview.cpp | 13 | ||||
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 12 | ||||
-rw-r--r-- | src/quick/items/qquickitemview_p.h | 1 | ||||
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 13 |
4 files changed, 39 insertions, 0 deletions
diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index b3734e34b4..582f46251d 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -1975,6 +1975,19 @@ bool QQuickGridViewPrivate::needsRefillForAddedOrRemovedIndex(int modelIndex) co \bold Note: methods should only be called after the Component has completed. */ +/*! + \qmlmethod Item QtQuick2::GridView::itemAt(int x, int y) + + Returns the visible item containing the point \a x, \a y in content + coordinates. If there is no item at the point specified, or the item is + not visible null is returned. + + If the item is outside the visible area, null is returned, regardless of + whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. +*/ + QQuickGridViewAttached *QQuickGridView::qmlAttachedProperties(QObject *obj) { return new QQuickGridViewAttached(obj); diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 927d107e6e..879c02f4cb 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -700,6 +700,18 @@ int QQuickItemView::indexAt(qreal x, qreal y) const return -1; } +QQuickItem *QQuickItemView::itemAt(qreal x, qreal y) const +{ + Q_D(const QQuickItemView); + for (int i = 0; i < d->visibleItems.count(); ++i) { + const FxViewItem *item = d->visibleItems.at(i); + if (item->contains(x, y)) + return item->item; + } + + return 0; +} + void QQuickItemViewPrivate::applyPendingChanges() { Q_Q(QQuickItemView); diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h index 99aafc9720..c659893091 100644 --- a/src/quick/items/qquickitemview_p.h +++ b/src/quick/items/qquickitemview_p.h @@ -147,6 +147,7 @@ public: Q_INVOKABLE void positionViewAtIndex(int index, int mode); Q_INVOKABLE int indexAt(qreal x, qreal y) const; + Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const; Q_INVOKABLE void positionViewAtBeginning(); Q_INVOKABLE void positionViewAtEnd(); diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 960565a155..b2e9c614bc 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -2550,6 +2550,19 @@ bool QQuickListViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::In \bold Note: methods should only be called after the Component has completed. */ +/*! + \qmlmethod Item QtQuick2::ListView::itemAt(int x, int y) + + Returns the visible item containing the point \a x, \a y in content + coordinates. If there is no item at the point specified, or the item is + not visible null is returned. + + If the item is outside the visible area, null is returned, regardless of + whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. +*/ + QQuickListViewAttached *QQuickListView::qmlAttachedProperties(QObject *obj) { return new QQuickListViewAttached(obj); |