Remove redundant QT_NO_ACCESSIBILTY.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickaccessibleattached.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qquickaccessibleattached_p.h"
43
44 #ifndef QT_NO_ACCESSIBILITY
45
46 #include "private/qquickitem_p.h"
47
48 QT_BEGIN_NAMESPACE
49
50 /*!
51     \qmltype Accessible
52     \instantiates QQuickAccessibleAttached
53     \brief Enables accessibility of QML items
54
55     \inqmlmodule QtQuick 2
56     \ingroup qtquick-visual-utility
57     \ingroup accessibility
58
59     This class is part of \l {Accessibility for Qt Quick Applications}.
60
61     Items the user interacts with or that give information to the user
62     need to expose their information in a semantic way.
63     Then assistive tools can make use of that information to enable
64     users to interact with the application in various ways.
65
66     This enables Qt Quick applications to be used with screen-readers for example.
67
68     The most important properties to set are \l name and \l role.
69
70     \sa Accessibility
71 */
72
73 /*!
74     \qmlproperty string QtQuick2::Accessible::name
75
76     This property sets an accessible name.
77     For a button for example, this should have a binding to its text.
78     In general this property should be set to a simple and concise
79     but human readable name. Do not include the type of control
80     you want to represent but just the name.
81 */
82
83 /*!
84     \qmlproperty string QtQuick2::Accessible::description
85
86     This property sets an accessible description.
87     Similar to the name it describes the item. The description
88     can be a little more verbose and tell what the item does,
89     for example the functionallity of the button it describes.
90 */
91
92 /*!
93     \qmlproperty enumeration QtQuick2::Accessible::role
94
95     This flags sets the semantic type of the widget.
96     A button for example would have "Button" as type.
97     The value must be one of \l QAccessible::Role .
98     Example:
99     \qml
100     Item {
101         id: myButton
102
103         Text {
104             id: label
105             // ...
106         }
107
108         Accessible.name: label.text
109         Accessible.role: Accessible.Button
110
111         function accessiblePressAction() {
112             //...
113         }
114     }
115     \endqml
116
117     Some roles have special semantics.
118     In order to implement check boxes for example a "checked" property is expected.
119
120     \table
121     \header
122         \li \b {Role}
123         \li \b {Expected property}
124         \li
125
126     \row
127         \li Button
128         \li function accessiblePressAction
129         \li Called when the button receives a press action. The implementation should visually simulate a button click and perform the button action.
130     \row
131        \li CheckBox, Radiobutton
132        \li checked
133        \li The check state of the check box. Updated on Press, Check and Uncheck actions.
134     \row
135        \li Slider, SpinBox, Dial, ScrollBar
136        \li value, minimumValue, maximumValue, stepSize
137        \li value will be updated on increase and decrase actions, in accordance with the other properties
138
139     \endtable
140 */
141
142 QQuickAccessibleAttached::QQuickAccessibleAttached(QObject *parent)
143     : QObject(parent), m_role(QAccessible::NoRole)
144 {
145     Q_ASSERT(parent);
146     QQuickItem *item = qobject_cast<QQuickItem*>(parent);
147     if (!item)
148         return;
149
150     // Enable accessibility for items with accessible content. This also
151     // enables accessibility for the ancestors of souch items.
152     item->d_func()->setAccessibleFlagAndListener();
153     QAccessibleEvent ev(item, QAccessible::ObjectCreated);
154     QAccessible::updateAccessibility(&ev);
155 }
156
157 QQuickAccessibleAttached::~QQuickAccessibleAttached()
158 {
159 }
160
161 QQuickAccessibleAttached *QQuickAccessibleAttached::qmlAttachedProperties(QObject *obj)
162 {
163     return new QQuickAccessibleAttached(obj);
164 }
165
166 QT_END_NAMESPACE
167
168 #endif