1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qaccessiblequickview.h"
44 #include <QtGui/qguiapplication.h>
46 #include <QtQuick/qquickitem.h>
47 #include <QtQuick/private/qquickitem_p.h>
49 #include "qaccessiblequickitem.h"
50 #include "qqmlaccessible.h"
52 #ifndef QT_NO_ACCESSIBILITY
56 QAccessibleQuickView::QAccessibleQuickView(QQuickView *object)
57 :QAccessibleObject(object)
61 int QAccessibleQuickView::childCount() const
63 return view()->rootItem() ? 1 : 0;
66 QAccessibleInterface *QAccessibleQuickView::parent() const
68 // FIXME: for now we assume to be a top level window...
69 return QAccessible::queryAccessibleInterface(qApp);
72 QAccessibleInterface *QAccessibleQuickView::child(int index) const
75 if (QQuickItem *declarativeRoot = view()->rootObject())
76 return new QAccessibleQuickItem(declarativeRoot);
81 QAccessible::Role QAccessibleQuickView::role() const
83 return QAccessible::Window; // FIXME
86 QAccessible::State QAccessibleQuickView::state() const
88 QAccessible::State st;
89 if (view() == QGuiApplication::focusWindow())
91 if (!view()->isVisible())
96 QRect QAccessibleQuickView::rect() const
98 return QRect(view()->x(), view()->y(), view()->width(), view()->height());
101 QString QAccessibleQuickView::text(QAccessible::Text text) const
103 #ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION
104 if (text == QAccessible::DebugDescription) {
105 return QString::fromAscii(object()->metaObject()->className()) ;
110 return view()->windowTitle();
117 Can also return \a item itself
119 static QQuickItem *childAt_helper(QQuickItem *item, int x, int y)
121 if (item->opacity() == 0.0 || !item->isVisible() || !item->isEnabled())
124 if (item->flags() & QQuickItem::ItemClipsChildrenToShape) {
125 if (!itemScreenRect(item).contains(x, y))
129 QScopedPointer<QAccessibleInterface> accessibleInterface(QAccessible::queryAccessibleInterface(item));
130 if (accessibleInterface->childCount() == 0) {
131 return (itemScreenRect(item).contains(x, y)) ? item : 0;
134 QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
136 QList<QQuickItem *> children = itemPrivate->paintOrderChildItems();
137 for (int i = children.count() - 1; i >= 0; --i) {
138 QQuickItem *child = children.at(i);
139 if (QQuickItem *childChild = childAt_helper(child, x, y))
143 QRect screenRect = itemScreenRect(item);
145 if (screenRect.contains(x, y))
151 QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const
154 QQuickItem *root = view()->rootItem();
156 if (QQuickItem *item = childAt_helper(root, x, y))
157 return QAccessible::queryAccessibleInterface(item);
162 int QAccessibleQuickView::indexOfChild(const QAccessibleInterface *iface) const
165 QQuickItem *declarativeRoot = view()->rootObject();
166 if (declarativeRoot == iface->object())
175 #endif // QT_NO_ACCESSIBILITY