1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qaccessibleobject.h"
44 #ifndef QT_NO_ACCESSIBILITY
46 #include <QtGui/QGuiApplication>
47 #include <QtGui/QWindow>
50 #include "qmetaobject.h"
54 class QAccessibleObjectPrivate
57 QPointer<QObject> object;
59 QList<QByteArray> actionList() const;
62 QList<QByteArray> QAccessibleObjectPrivate::actionList() const
64 QList<QByteArray> actionList;
69 const QMetaObject *mo = object->metaObject();
72 QByteArray defaultAction = QMetaObject::normalizedSignature(
73 mo->classInfo(mo->indexOfClassInfo("DefaultSlot")).value());
75 for (int i = 0; i < mo->methodCount(); ++i) {
76 const QMetaMethod member = mo->method(i);
77 if (member.methodType() != QMetaMethod::Slot && member.access() != QMetaMethod::Public)
80 if (!qstrcmp(member.tag(), "QACCESSIBLE_SLOT")) {
81 if (member.methodSignature() == defaultAction)
82 actionList.prepend(defaultAction);
84 actionList << member.methodSignature();
92 \class QAccessibleObject
93 \brief The QAccessibleObject class implements parts of the
94 QAccessibleInterface for QObjects.
97 \ingroup accessibility
100 This class is part of \l {Accessibility for QWidget Applications}.
102 This class is mainly provided for convenience. All subclasses of
103 the QAccessibleInterface that provide implementations of non-widget objects
104 should use this class as their base class.
106 \sa QAccessible, QAccessibleWidget
110 Creates a QAccessibleObject for \a object.
112 QAccessibleObject::QAccessibleObject(QObject *object)
114 d = new QAccessibleObjectPrivate;
119 Destroys the QAccessibleObject.
121 This only happens when a call to release() decrements the internal
122 reference counter to zero.
124 QAccessibleObject::~QAccessibleObject()
132 QObject *QAccessibleObject::object() const
136 qWarning("QAccessibleInterface is invalid. Crash pending...");
144 bool QAccessibleObject::isValid() const
146 return !d->object.isNull();
150 QRect QAccessibleObject::rect() const
156 void QAccessibleObject::setText(QAccessible::Text, const QString &)
161 QAccessibleInterface *QAccessibleObject::childAt(int x, int y) const
163 for (int i = 0; i < childCount(); ++i) {
164 QAccessibleInterface *childIface = child(i);
165 Q_ASSERT(childIface);
166 if (childIface->rect().contains(x,y)) {
174 \class QAccessibleApplication
175 \brief The QAccessibleApplication class implements the QAccessibleInterface for QApplication.
179 \ingroup accessibility
183 Creates a QAccessibleApplication for the QApplication object referenced by qApp.
185 QAccessibleApplication::QAccessibleApplication()
186 : QAccessibleObject(qApp)
190 QWindow *QAccessibleApplication::window() const
192 // an application can have several windows, and AFAIK we don't need
193 // to notify about changes on the application.
197 // all toplevel windows except popups and the desktop
198 static QObjectList topLevelObjects()
201 const QWindowList tlw(QGuiApplication::topLevelWindows());
202 for (int i = 0; i < tlw.count(); ++i) {
203 QWindow *w = tlw.at(i);
204 if (w->windowType() != Qt::Popup && w->windowType() != Qt::Desktop) {
205 if (QAccessibleInterface *root = w->accessibleRoot()) {
207 list.append(root->object());
217 int QAccessibleApplication::childCount() const
219 return topLevelObjects().count();
223 int QAccessibleApplication::indexOfChild(const QAccessibleInterface *child) const
225 const QObjectList tlw(topLevelObjects());
226 return tlw.indexOf(child->object());
229 QAccessibleInterface *QAccessibleApplication::parent() const
234 QAccessibleInterface *QAccessibleApplication::child(int index) const
236 const QObjectList tlo(topLevelObjects());
237 if (index >= 0 && index < tlo.count())
238 return QAccessible::queryAccessibleInterface(tlo.at(index));
244 QAccessibleInterface *QAccessibleApplication::focusChild() const
246 if (QWindow *window = QGuiApplication::focusWindow())
247 return window->accessibleRoot();
252 QString QAccessibleApplication::text(QAccessible::Text t) const
255 case QAccessible::Name:
256 return QGuiApplication::applicationName();
257 case QAccessible::Description:
258 return QGuiApplication::applicationFilePath();
266 QAccessible::Role QAccessibleApplication::role() const
268 return QAccessible::Application;
272 QAccessible::State QAccessibleApplication::state() const
274 return QAccessible::State();
280 #endif //QT_NO_ACCESSIBILITY