diff options
author | Jan-Arve Saether <jan-arve.saether@nokia.com> | 2012-01-03 09:40:16 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-12 12:21:59 +0100 |
commit | 9ab84bd46861557afb190ba4cb2481b35a7401e5 (patch) | |
tree | 32c2c128aa0783cbe0bfe9f43d437c9ac916a929 /src/plugins/accessible/quick/qaccessiblequickview.cpp | |
parent | 0cafd920cced1f726a8b6422b6fb496ecf846f34 (diff) |
Make QAccessibleQuickView::childAt() work properly with overlapping items
The previous code did not consider items that were overlapped due to
having different z coordinates.
The approach used is now the same as found in
QQuickCanvas::mousePressEvent().
Strictly speaking, this is a violation of childAt (since it will
disregard the implementation of childAt of all the descendants along
the path down to the item actually returned.)
However, I don't see any good reason for that the implementation for
childAt() would be different than how mousePressEvent behaves.
It should also perform better than any other solution I managed to
think of.
Change-Id: I2d3fa2282437c7b5533c6149c62fc456ccf2ccfa
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Diffstat (limited to 'src/plugins/accessible/quick/qaccessiblequickview.cpp')
-rw-r--r-- | src/plugins/accessible/quick/qaccessiblequickview.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/plugins/accessible/quick/qaccessiblequickview.cpp b/src/plugins/accessible/quick/qaccessiblequickview.cpp index 6a896efd29..d15e01d96c 100644 --- a/src/plugins/accessible/quick/qaccessiblequickview.cpp +++ b/src/plugins/accessible/quick/qaccessiblequickview.cpp @@ -42,6 +42,7 @@ #include "qaccessiblequickview.h" #include <QtQuick/qquickitem.h> +#include <QtQuick/private/qquickitem_p.h> #include "qaccessiblequickitem.h" #include "qdeclarativeaccessible.h" @@ -69,8 +70,8 @@ QAccessibleInterface *QAccessibleQuickView::parent() const QAccessibleInterface *QAccessibleQuickView::child(int index) const { if (index == 0) { - QQuickItem *declarativeRoot = view()->rootObject(); - return new QAccessibleQuickItem(declarativeRoot); + if (QQuickItem *declarativeRoot = view()->rootObject()) + return new QAccessibleQuickItem(declarativeRoot); } return 0; } @@ -108,11 +109,48 @@ QString QAccessibleQuickView::text(QAccessible::Text text) const return view()->windowTitle(); } + +/*! + \internal + + Can also return \a item itself + */ +static QQuickItem *childAt_helper(QQuickItem *item, int x, int y) +{ + if (item->opacity() == 0.0 || !item->isVisible() || !item->isEnabled()) + return 0; + + if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { + if (!itemScreenRect(item).contains(x, y)) + return 0; + } + + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + + QList<QQuickItem *> children = itemPrivate->paintOrderChildItems(); + for (int i = children.count() - 1; i >= 0; --i) { + QQuickItem *child = children.at(i); + if (QQuickItem *childChild = childAt_helper(child, x, y)) + return childChild; + } + + QRect screenRect = itemScreenRect(item); + + if (screenRect.contains(x, y)) + return item; + + return 0; +} + QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const { - Q_UNUSED(x); - Q_UNUSED(y); - return child(0); // return the top-level QML item + Q_ASSERT(view()); + QQuickItem *root = view()->rootItem(); + if (root) { + if (QQuickItem *item = childAt_helper(root, x, y)) + return QAccessible::queryAccessibleInterface(item); + } + return 0; } int QAccessibleQuickView::indexOfChild(const QAccessibleInterface *iface) const |