summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2010-06-08 09:30:28 (GMT)
committermae <qt-info@nokia.com>2010-06-08 09:32:55 (GMT)
commit9623b49fd3055ede03569e6e9a46a4237f6e119f (patch)
tree03fed02144775996c520b49f098bbf03ee6a997d
parenta46e97c429077022bc7f426a3adec588643abc57 (diff)
downloadQt-9623b49fd3055ede03569e6e9a46a4237f6e119f.zip
Qt-9623b49fd3055ede03569e6e9a46a4237f6e119f.tar.gz
Qt-9623b49fd3055ede03569e6e9a46a4237f6e119f.tar.bz2
Add qmlmethod Item::childAt() to delarative item
The method allows for more flexbile mouse and touch handling. It offers a fast way to identify a child item for a given pixel position.
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp24
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h1
2 files changed, 24 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 9949e65..bef09bb 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -1633,7 +1633,7 @@ void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *pro
QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
{
- QObjectList children = prop->object->children();
+ const QObjectList children = prop->object->children();
if (index < children.count())
return children.at(index);
else
@@ -2391,6 +2391,28 @@ void QDeclarativeItem::forceFocus()
}
}
+
+/*!
+ \qmlmethod Item::childAt(real x, real y)
+
+ Returns the visible child item at point (\a x, \a y), which is in this
+ item's coordinate system, or \c null if there is no such item.
+ */
+QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const
+{
+ const QList<QGraphicsItem *> children = childItems();
+ for (int i = children.count()-1; i >= 0; --i) {
+ if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) {
+ if (child->isVisible() && child->x() <= x
+ && child->x() + child->width() >= x
+ && child->y() <= y
+ && child->y() + child->height() >= y)
+ return child;
+ }
+ }
+ return 0;
+}
+
void QDeclarativeItemPrivate::focusChanged(bool flag)
{
Q_Q(QDeclarativeItem);
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index 77e316b..4f420f8 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -148,6 +148,7 @@ public:
Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
Q_INVOKABLE void forceFocus();
+ Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const;
Q_SIGNALS:
void childrenChanged();