1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the accessibility module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qaccessibleobject.h"
31
#ifndef QT_NO_ACCESSIBILITY
33
#include "qapplication.h"
36
#include "qmetaobject.h"
37
#include "qvarlengtharray.h"
39
class QAccessibleObjectPrivate
42
QPointer<QObject> object;
44
QList<QByteArray> actionList() const;
47
QList<QByteArray> QAccessibleObjectPrivate::actionList() const
49
QList<QByteArray> actionList;
54
const QMetaObject *mo = object->metaObject();
57
QByteArray defaultAction = QMetaObject::normalizedSignature(
58
mo->classInfo(mo->indexOfClassInfo("DefaultSlot")).value());
60
for (int i = 0; i < mo->methodCount(); ++i) {
61
const QMetaMethod member = mo->method(i);
62
if (member.methodType() != QMetaMethod::Slot && member.access() != QMetaMethod::Public)
65
if (!qstrcmp(member.tag(), "QACCESSIBLE_SLOT")) {
66
if (member.signature() == defaultAction)
67
actionList.prepend(defaultAction);
69
actionList << member.signature();
77
\class QAccessibleObject
78
\brief The QAccessibleObject class implements parts of the
79
QAccessibleInterface for QObjects.
81
\ingroup accessibility
83
This class is mainly provided for convenience. All subclasses of
84
the QAccessibleInterface that provide implementations of non-widget objects
85
should use this class as their base class.
87
\sa QAccessible, QAccessibleWidget
91
Creates a QAccessibleObject for \a object.
93
QAccessibleObject::QAccessibleObject(QObject *object)
95
d = new QAccessibleObjectPrivate;
100
Destroys the QAccessibleObject.
102
This only happens when a call to release() decrements the internal
103
reference counter to zero.
105
QAccessibleObject::~QAccessibleObject()
113
QObject *QAccessibleObject::object() const
117
qWarning("QAccessibleInterface is invalid. Crash pending...");
125
bool QAccessibleObject::isValid() const
127
return !d->object.isNull();
131
QRect QAccessibleObject::rect(int) const
137
void QAccessibleObject::setText(Text, int, const QString &)
142
int QAccessibleObject::userActionCount(int) const
148
bool QAccessibleObject::doAction(int, int, const QVariantList &)
153
static const char * const action_text[][5] =
155
// Name, Description, Value, Help, Accelerator
156
{ "Press", "", "", "", "Space" },
157
{ "SetFocus", "Passes focus to this widget", "", "", "" },
158
{ "Increase", "", "", "", "" },
159
{ "Decrease", "", "", "", "" },
160
{ "Accept", "", "", "", "" },
161
{ "Cancel", "", "", "", "" },
162
{ "Select", "", "", "", "" },
163
{ "ClearSelection", "", "", "", "" },
164
{ "RemoveSelection", "", "", "", "" },
165
{ "ExtendSelection", "", "", "", "" },
166
{ "AddToSelection", "", "", "", "" }
170
QString QAccessibleObject::actionText(int action, Text t, int child) const
172
if (child || action > FirstStandardAction || action < LastStandardAction || t > Accelerator)
175
return QString(action_text[-(action - FirstStandardAction)][t]);
180
\class QAccessibleApplication
181
\brief The QAccessibleApplication class implements the QAccessibleInterface for QApplication.
185
\ingroup accessibility
189
Creates a QAccessibleApplication for the QApplication object referenced by qApp.
191
QAccessibleApplication::QAccessibleApplication()
192
: QAccessibleObject(qApp)
196
// all toplevel widgets except popups and the desktop
197
static QWidgetList topLevelWidgets()
200
const QWidgetList tlw(qApp->topLevelWidgets());
201
for (int i = 0; i < tlw.count(); ++i) {
202
QWidget *w = tlw.at(i);
203
if (!(w->windowType() == Qt::Popup) && !(w->windowType() == Qt::Desktop))
211
int QAccessibleApplication::childCount() const
213
return topLevelWidgets().count();
217
int QAccessibleApplication::indexOfChild(const QAccessibleInterface *child) const
219
if (!child->object()->isWidgetType())
222
const QWidgetList tlw(topLevelWidgets());
223
int index = tlw.indexOf(static_cast<QWidget*>(child->object()));
230
int QAccessibleApplication::childAt(int x, int y) const
232
const QWidgetList tlw(topLevelWidgets());
233
for (int i = 0; i < tlw.count(); ++i) {
234
QWidget *w = tlw.at(i);
235
if (w->frameGeometry().contains(x,y))
242
QAccessible::Relation QAccessibleApplication::relationTo(int child, const
243
QAccessibleInterface *other, int otherChild) const
245
QObject *o = other ? other->object() : 0;
250
if (child && !otherChild)
252
if (!child && otherChild)
254
if (!child && !otherChild)
258
QWidgetList tlw(topLevelWidgets());
259
if (tlw.contains(qobject_cast<QWidget*>(o)))
262
for (int i = 0; i < tlw.count(); ++i) {
263
QWidget *w = tlw.at(i);
264
QObjectList cl = qFindChildren<QObject *>(w, QString());
273
int QAccessibleApplication::navigate(RelationFlag relation, int entry,
274
QAccessibleInterface **target) const
280
QObject *targetObject = 0;
284
targetObject = object();
287
if (entry > 0 && entry <= childCount()) {
288
const QWidgetList tlw(topLevelWidgets());
289
if (tlw.count() >= entry)
290
targetObject = tlw.at(entry-1);
296
targetObject = qApp->activeWindow();
301
*target = QAccessible::queryAccessibleInterface(targetObject);
302
return *target ? 0 : -1;
306
QString QAccessibleApplication::text(Text t, int) const
310
if (qApp->activeWindow())
311
return qApp->activeWindow()->windowTitle();
314
return qApp->applicationFilePath();
322
QAccessible::Role QAccessibleApplication::role(int) const
328
QAccessible::State QAccessibleApplication::state(int) const
330
return qApp->activeWindow() ? Focused : Normal;
334
int QAccessibleApplication::userActionCount(int) const
340
bool QAccessibleApplication::doAction(int action, int child, const QVariantList ¶m)
342
if (action == 0 || action == 1) {
344
w = qApp->activeWindow();
346
w = topLevelWidgets().at(0);
352
return QAccessibleObject::doAction(action, child, param);
356
QString QAccessibleApplication::actionText(int action, Text text, int child) const
359
if ((action == 0 || action == 1) && !child) switch (text) {
361
return QApplication::tr("Activate");
363
return QApplication::tr("Activates the application main widget");
367
return QAccessibleObject::actionText(action, text, child);
370
#endif //QT_NO_ACCESSIBILITY