1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qaccessiblewidgets_p.h"
41#include "qaccessiblemenu_p.h"
42#include "private/qwidget_p.h"
43#include "simplewidgets_p.h"
44#include "rangecontrols_p.h"
45#include "complexwidgets_p.h"
46#if QT_CONFIG(itemviews)
47#include "itemviews_p.h"
48#endif
49
50#if QT_CONFIG(toolbutton)
51#include <qtoolbutton.h>
52#endif
53#if QT_CONFIG(treeview)
54#include <qtreeview.h>
55#endif
56#include <qvariant.h>
57#include <qaccessible.h>
58
59#ifndef QT_NO_ACCESSIBILITY
60
61QT_BEGIN_NAMESPACE
62
63QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *object)
64{
65 QAccessibleInterface *iface = nullptr;
66 if (!object || !object->isWidgetType())
67 return iface;
68
69 QWidget *widget = static_cast<QWidget*>(object);
70 // QWidget emits destroyed() from its destructor instead of letting the QObject
71 // destructor do it, which means the QWidget is unregistered from the accessibillity
72 // cache. But QWidget destruction also emits enter and leave events, which may end
73 // up here, so we have to ensure that we don't fill the cache with an entry of
74 // a widget that is going away.
75 if (QWidgetPrivate::get(w: widget)->data.in_destructor)
76 return iface;
77
78 if (false) {
79#if QT_CONFIG(lineedit)
80 } else if (classname == QLatin1String("QLineEdit")) {
81 if (widget->objectName() == QLatin1String("qt_spinbox_lineedit"))
82 iface = nullptr;
83 else
84 iface = new QAccessibleLineEdit(widget);
85#endif
86#if QT_CONFIG(combobox)
87 } else if (classname == QLatin1String("QComboBox")) {
88 iface = new QAccessibleComboBox(widget);
89#endif
90#if QT_CONFIG(spinbox)
91 } else if (classname == QLatin1String("QAbstractSpinBox")) {
92 iface = new QAccessibleAbstractSpinBox(widget);
93 } else if (classname == QLatin1String("QSpinBox")) {
94 iface = new QAccessibleSpinBox(widget);
95 } else if (classname == QLatin1String("QDoubleSpinBox")) {
96 iface = new QAccessibleDoubleSpinBox(widget);
97#endif
98#if QT_CONFIG(scrollbar)
99 } else if (classname == QLatin1String("QScrollBar")) {
100 iface = new QAccessibleScrollBar(widget);
101#endif
102#if QT_CONFIG(slider)
103 } else if (classname == QLatin1String("QAbstractSlider")) {
104 iface = new QAccessibleAbstractSlider(widget);
105 } else if (classname == QLatin1String("QSlider")) {
106 iface = new QAccessibleSlider(widget);
107#endif
108#if QT_CONFIG(toolbutton)
109 } else if (classname == QLatin1String("QToolButton")) {
110 iface = new QAccessibleToolButton(widget);
111#endif // QT_CONFIG(toolbutton)
112#if QT_CONFIG(abstractbutton)
113 } else if (classname == QLatin1String("QCheckBox")
114 || classname == QLatin1String("QRadioButton")
115 || classname == QLatin1String("QPushButton")
116 || classname == QLatin1String("QAbstractButton")) {
117 iface = new QAccessibleButton(widget);
118#endif
119 } else if (classname == QLatin1String("QDialog")) {
120 iface = new QAccessibleWidget(widget, QAccessible::Dialog);
121 } else if (classname == QLatin1String("QMessageBox")) {
122 iface = new QAccessibleWidget(widget, QAccessible::AlertMessage);
123#if QT_CONFIG(mainwindow)
124 } else if (classname == QLatin1String("QMainWindow")) {
125 iface = new QAccessibleMainWindow(widget);
126#endif
127 } else if (classname == QLatin1String("QLabel") || classname == QLatin1String("QLCDNumber")) {
128 iface = new QAccessibleDisplay(widget);
129#if QT_CONFIG(groupbox)
130 } else if (classname == QLatin1String("QGroupBox")) {
131 iface = new QAccessibleGroupBox(widget);
132#endif
133 } else if (classname == QLatin1String("QStatusBar")) {
134 iface = new QAccessibleDisplay(widget);
135#if QT_CONFIG(progressbar)
136 } else if (classname == QLatin1String("QProgressBar")) {
137 iface = new QAccessibleProgressBar(widget);
138#endif
139 } else if (classname == QLatin1String("QToolBar")) {
140 iface = new QAccessibleWidget(widget, QAccessible::ToolBar, widget->windowTitle());
141#if QT_CONFIG(menubar)
142 } else if (classname == QLatin1String("QMenuBar")) {
143 iface = new QAccessibleMenuBar(widget);
144#endif
145#if QT_CONFIG(menu)
146 } else if (classname == QLatin1String("QMenu")) {
147 iface = new QAccessibleMenu(widget);
148#endif
149#if QT_CONFIG(treeview)
150 } else if (classname == QLatin1String("QTreeView")) {
151 iface = new QAccessibleTree(widget);
152#endif // QT_CONFIG(treeview)
153#if QT_CONFIG(itemviews)
154 } else if (classname == QLatin1String("QTableView") || classname == QLatin1String("QListView")) {
155 iface = new QAccessibleTable(widget);
156 // ### This should be cleaned up. We return the parent for the scrollarea to hide it.
157#endif // QT_CONFIG(itemviews)
158#if QT_CONFIG(tabbar)
159 } else if (classname == QLatin1String("QTabBar")) {
160 iface = new QAccessibleTabBar(widget);
161#endif
162 } else if (classname == QLatin1String("QSizeGrip")) {
163 iface = new QAccessibleWidget(widget, QAccessible::Grip);
164#if QT_CONFIG(splitter)
165 } else if (classname == QLatin1String("QSplitter")) {
166 iface = new QAccessibleWidget(widget, QAccessible::Splitter);
167 } else if (classname == QLatin1String("QSplitterHandle")) {
168 iface = new QAccessibleWidget(widget, QAccessible::Grip);
169#endif
170#if QT_CONFIG(textedit) && !defined(QT_NO_CURSOR)
171 } else if (classname == QLatin1String("QTextEdit")) {
172 iface = new QAccessibleTextEdit(widget);
173 } else if (classname == QLatin1String("QPlainTextEdit")) {
174 iface = new QAccessiblePlainTextEdit(widget);
175#endif
176 } else if (classname == QLatin1String("QTipLabel")) {
177 iface = new QAccessibleDisplay(widget, QAccessible::ToolTip);
178 } else if (classname == QLatin1String("QFrame")) {
179 iface = new QAccessibleWidget(widget, QAccessible::Border);
180#if QT_CONFIG(stackedwidget)
181 } else if (classname == QLatin1String("QStackedWidget")) {
182 iface = new QAccessibleStackedWidget(widget);
183#endif
184#if QT_CONFIG(toolbox)
185 } else if (classname == QLatin1String("QToolBox")) {
186 iface = new QAccessibleToolBox(widget);
187#endif
188#if QT_CONFIG(mdiarea)
189 } else if (classname == QLatin1String("QMdiArea")) {
190 iface = new QAccessibleMdiArea(widget);
191 } else if (classname == QLatin1String("QMdiSubWindow")) {
192 iface = new QAccessibleMdiSubWindow(widget);
193#endif
194#if QT_CONFIG(dialogbuttonbox)
195 } else if (classname == QLatin1String("QDialogButtonBox")) {
196 iface = new QAccessibleDialogButtonBox(widget);
197#endif
198#if QT_CONFIG(dial)
199 } else if (classname == QLatin1String("QDial")) {
200 iface = new QAccessibleDial(widget);
201#endif
202#if QT_CONFIG(rubberband)
203 } else if (classname == QLatin1String("QRubberBand")) {
204 iface = new QAccessibleWidget(widget, QAccessible::Border);
205#endif
206#if QT_CONFIG(textbrowser) && !defined(QT_NO_CURSOR)
207 } else if (classname == QLatin1String("QTextBrowser")) {
208 iface = new QAccessibleTextBrowser(widget);
209#endif
210#if QT_CONFIG(scrollarea)
211 } else if (classname == QLatin1String("QAbstractScrollArea")) {
212 iface = new QAccessibleAbstractScrollArea(widget);
213 } else if (classname == QLatin1String("QScrollArea")) {
214 iface = new QAccessibleScrollArea(widget);
215#endif
216#if QT_CONFIG(calendarwidget)
217 } else if (classname == QLatin1String("QCalendarWidget")) {
218 iface = new QAccessibleCalendarWidget(widget);
219#endif
220#if QT_CONFIG(dockwidget)
221 } else if (classname == QLatin1String("QDockWidget")) {
222 iface = new QAccessibleDockWidget(widget);
223#endif
224
225 } else if (classname == QLatin1String("QDesktopScreenWidget")) {
226 iface = nullptr;
227 } else if (classname == QLatin1String("QWidget")) {
228 iface = new QAccessibleWidget(widget);
229 } else if (classname == QLatin1String("QWindowContainer")) {
230 iface = new QAccessibleWindowContainer(widget);
231 }
232
233 return iface;
234}
235
236QT_END_NAMESPACE
237
238#endif // QT_NO_ACCESSIBILITY
239

source code of qtbase/src/widgets/accessible/qaccessiblewidgetfactory.cpp