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 QtQml 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 <qnamespace.h>
43
#include "qqmlaccessible.h"
45
#ifndef QT_NO_ACCESSIBILITY
50
QString Q_GUI_EXPORT qTextBeforeOffsetFromString(int offset, QAccessible2::BoundaryType boundaryType,
51
int *startOffset, int *endOffset, const QString& text);
52
QString Q_GUI_EXPORT qTextAtOffsetFromString(int offset, QAccessible2::BoundaryType boundaryType,
53
int *startOffset, int *endOffset, const QString& text);
54
QString Q_GUI_EXPORT qTextAfterOffsetFromString(int offset, QAccessible2::BoundaryType boundaryType,
55
int *startOffset, int *endOffset, const QString& text);
57
QQmlAccessible::QQmlAccessible(QObject *object)
58
:QAccessibleObject(object)
62
void *QQmlAccessible::interface_cast(QAccessible::InterfaceType t)
64
if (t == QAccessible::ActionInterface)
65
return static_cast<QAccessibleActionInterface*>(this);
66
return QAccessibleObject::interface_cast(t);
69
QQmlAccessible::~QQmlAccessible()
73
QAccessibleInterface *QQmlAccessible::childAt(int x, int y) const
75
// Note that this function will disregard stacking order.
76
// (QAccessibleQuickView::childAt() does this correctly and more efficient)
78
// If the item clips its children, we can return early if the coordinate is outside its rect
79
if (clipsChildren()) {
80
if (!rect().contains(x, y))
84
for (int i = childCount() - 1; i >= 0; --i) {
85
QAccessibleInterface *childIface = child(i);
86
if (childIface && !childIface->state().invisible) {
87
if (childIface->rect().contains(x, y))
95
QAccessible::State QQmlAccessible::state() const
97
QAccessible::State state;
99
//QRect viewRect(QPoint(0, 0), m_implementation->size());
100
//QRect itemRect(m_item->scenePos().toPoint(), m_item->boundingRect().size().toSize());
102
QRect viewRect_ = viewRect();
103
QRect itemRect = rect();
105
// qDebug() << "viewRect" << viewRect << "itemRect" << itemRect;
107
if (viewRect_.isNull() || itemRect.isNull()) {
108
state.invisible = true;
111
if (!viewRect_.intersects(itemRect)) {
112
state.offscreen = true;
113
// state.invisible = true; // no set at this point to ease development
116
if (!object()->property("visible").toBool() || qFuzzyIsNull(object()->property("opacity").toDouble())) {
117
state.invisible = true;
120
if ((role() == QAccessible::CheckBox || role() == QAccessible::RadioButton) && object()->property("checked").toBool()) {
121
state.checked = true;
124
if (role() == QAccessible::EditableText)
125
state.focusable = true;
127
//qDebug() << "state?" << m_item->property("state").toString() << m_item->property("status").toString() << m_item->property("visible").toString();
132
QStringList QQmlAccessible::actionNames() const
136
case QAccessible::PushButton:
137
actions << QAccessibleActionInterface::pressAction();
139
case QAccessible::RadioButton:
140
case QAccessible::CheckBox:
141
actions << QAccessibleActionInterface::toggleAction();
143
case QAccessible::Slider:
144
case QAccessible::SpinBox:
145
case QAccessible::ScrollBar:
146
actions << QAccessibleActionInterface::increaseAction()
147
<< QAccessibleActionInterface::decreaseAction();
155
void QQmlAccessible::doAction(const QString &actionName)
157
// Look for and call the accessible[actionName]Action() function on the item.
158
// This allows for overriding the default action handling.
159
const QByteArray functionName = "accessible" + actionName.toLatin1() + "Action";
160
if (object()->metaObject()->indexOfMethod(functionName + "()") != -1) {
161
QMetaObject::invokeMethod(object(), functionName);
165
// Role-specific default action handling follows. Items are excepted to provide
166
// properties according to role conventions. These will then be read and/or updated
167
// by the accessibility system.
168
// Checkable roles : checked
169
// Value-based roles : (via the value interface: value, minimumValue, maximumValue), stepSize
171
case QAccessible::RadioButton:
172
case QAccessible::CheckBox: {
173
QVariant checked = object()->property("checked");
174
if (checked.isValid()) {
175
if (actionName == QAccessibleActionInterface::toggleAction()) {
176
object()->setProperty("checked", QVariant(!checked.toBool()));
181
case QAccessible::Slider:
182
case QAccessible::SpinBox:
183
case QAccessible::Dial:
184
case QAccessible::ScrollBar: {
185
if (actionName != QAccessibleActionInterface::increaseAction() &&
186
actionName != QAccessibleActionInterface::decreaseAction())
189
// Update the value using QAccessibleValueInterface, respecting
190
// the minimum and maximum value (if set). Also check for and
191
// use the "stepSize" property on the item
192
if (QAccessibleValueInterface *valueIface = valueInterface()) {
193
QVariant valueV = valueIface->currentValue();
194
qreal newValue = valueV.toInt();
196
QVariant stepSizeV = object()->property("stepSize");
197
qreal stepSize = stepSizeV.isValid() ? stepSizeV.toReal() : qreal(1.0);
198
if (actionName == QAccessibleActionInterface::increaseAction()) {
199
newValue += stepSize;
201
newValue -= stepSize;
204
QVariant minimumValueV = valueIface->minimumValue();
205
if (minimumValueV.isValid()) {
206
newValue = qMax(newValue, minimumValueV.toReal());
208
QVariant maximumValueV = valueIface->maximumValue();
209
if (maximumValueV.isValid()) {
210
newValue = qMin(newValue, maximumValueV.toReal());
213
valueIface->setCurrentValue(QVariant(newValue));
222
QStringList QQmlAccessible::keyBindingsForAction(const QString &actionName) const
225
return QStringList();
230
#endif // QT_NO_ACCESSIBILITY