1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qaccessiblewidgets_p.h"
5#include "qaccessiblemenu_p.h"
6#include "private/qwidget_p.h"
7#include "simplewidgets_p.h"
8#include "rangecontrols_p.h"
9#include "complexwidgets_p.h"
10#if QT_CONFIG(itemviews)
11#include "itemviews_p.h"
12#endif
13
14#if QT_CONFIG(toolbutton)
15#include <qtoolbutton.h>
16#endif
17#if QT_CONFIG(treeview)
18#include <qtreeview.h>
19#endif
20#include <qvariant.h>
21#include <qaccessible.h>
22
23#if QT_CONFIG(accessibility)
24
25QT_BEGIN_NAMESPACE
26
27using namespace Qt::StringLiterals;
28
29QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *object)
30{
31 QAccessibleInterface *iface = nullptr;
32 if (!object || !object->isWidgetType())
33 return iface;
34
35 QWidget *widget = static_cast<QWidget*>(object);
36 // QWidget emits destroyed() from its destructor instead of letting the QObject
37 // destructor do it, which means the QWidget is unregistered from the accessibillity
38 // cache. But QWidget destruction also emits enter and leave events, which may end
39 // up here, so we have to ensure that we don't fill the cache with an entry of
40 // a widget that is going away.
41 if (QWidgetPrivate::get(w: widget)->data.in_destructor)
42 return iface;
43
44 if (false) {
45#if QT_CONFIG(lineedit)
46 } else if (classname == "QLineEdit"_L1) {
47 if (widget->objectName() == "qt_spinbox_lineedit"_L1)
48 iface = nullptr;
49 else
50 iface = new QAccessibleLineEdit(widget);
51#endif
52#if QT_CONFIG(combobox)
53 } else if (classname == "QComboBox"_L1) {
54 iface = new QAccessibleComboBox(widget);
55#endif
56#if QT_CONFIG(spinbox)
57 } else if (classname == "QAbstractSpinBox"_L1) {
58 iface = new QAccessibleAbstractSpinBox(widget);
59 } else if (classname == "QSpinBox"_L1) {
60 iface = new QAccessibleSpinBox(widget);
61 } else if (classname == "QDoubleSpinBox"_L1) {
62 iface = new QAccessibleDoubleSpinBox(widget);
63#endif
64#if QT_CONFIG(scrollbar)
65 } else if (classname == "QScrollBar"_L1) {
66 iface = new QAccessibleScrollBar(widget);
67#endif
68#if QT_CONFIG(slider)
69 } else if (classname == "QAbstractSlider"_L1) {
70 iface = new QAccessibleAbstractSlider(widget);
71 } else if (classname == "QSlider"_L1) {
72 iface = new QAccessibleSlider(widget);
73#endif
74#if QT_CONFIG(toolbutton)
75 } else if (classname == "QToolButton"_L1) {
76 iface = new QAccessibleToolButton(widget);
77#endif // QT_CONFIG(toolbutton)
78#if QT_CONFIG(abstractbutton)
79 } else if (classname == "QCheckBox"_L1
80 || classname == "QRadioButton"_L1
81 || classname == "QPushButton"_L1
82 || classname == "QAbstractButton"_L1) {
83 iface = new QAccessibleButton(widget);
84#endif
85 } else if (classname == "QDialog"_L1) {
86 iface = new QAccessibleWidget(widget, QAccessible::Dialog);
87#if QT_CONFIG(messagebox)
88 } else if (classname == "QMessageBox"_L1) {
89 iface = new QAccessibleMessageBox(widget);
90#endif
91#if QT_CONFIG(mainwindow)
92 } else if (classname == "QMainWindow"_L1) {
93 iface = new QAccessibleMainWindow(widget);
94#endif
95 } else if (classname == "QLabel"_L1 || classname == "QLCDNumber"_L1) {
96 iface = new QAccessibleDisplay(widget);
97#if QT_CONFIG(groupbox)
98 } else if (classname == "QGroupBox"_L1) {
99 iface = new QAccessibleGroupBox(widget);
100#endif
101 } else if (classname == "QStatusBar"_L1) {
102 iface = new QAccessibleDisplay(widget);
103#if QT_CONFIG(progressbar)
104 } else if (classname == "QProgressBar"_L1) {
105 iface = new QAccessibleProgressBar(widget);
106#endif
107 } else if (classname == "QToolBar"_L1) {
108 iface = new QAccessibleWidget(widget, QAccessible::ToolBar, widget->windowTitle());
109#if QT_CONFIG(menubar)
110 } else if (classname == "QMenuBar"_L1) {
111 iface = new QAccessibleMenuBar(widget);
112#endif
113#if QT_CONFIG(menu)
114 } else if (classname == "QMenu"_L1) {
115 iface = new QAccessibleMenu(widget);
116#endif
117#if QT_CONFIG(treeview)
118 } else if (classname == "QTreeView"_L1) {
119 iface = new QAccessibleTree(widget);
120#endif // QT_CONFIG(treeview)
121#if QT_CONFIG(itemviews)
122 } else if (classname == "QTableView"_L1 || classname == "QListView"_L1) {
123 iface = new QAccessibleTable(widget);
124 // ### This should be cleaned up. We return the parent for the scrollarea to hide it.
125#endif // QT_CONFIG(itemviews)
126#if QT_CONFIG(tabbar)
127 } else if (classname == "QTabBar"_L1) {
128 iface = new QAccessibleTabBar(widget);
129#endif
130 } else if (classname == "QSizeGrip"_L1) {
131 iface = new QAccessibleWidget(widget, QAccessible::Grip);
132#if QT_CONFIG(splitter)
133 } else if (classname == "QSplitter"_L1) {
134 iface = new QAccessibleWidget(widget, QAccessible::Splitter);
135 } else if (classname == "QSplitterHandle"_L1) {
136 iface = new QAccessibleWidget(widget, QAccessible::Grip);
137#endif
138#if QT_CONFIG(textedit) && !defined(QT_NO_CURSOR)
139 } else if (classname == "QTextEdit"_L1) {
140 iface = new QAccessibleTextEdit(widget);
141 } else if (classname == "QPlainTextEdit"_L1) {
142 iface = new QAccessiblePlainTextEdit(widget);
143#endif
144 } else if (classname == "QTipLabel"_L1) {
145 iface = new QAccessibleDisplay(widget, QAccessible::ToolTip);
146 } else if (classname == "QFrame"_L1) {
147 iface = new QAccessibleWidget(widget, QAccessible::Border);
148#if QT_CONFIG(stackedwidget)
149 } else if (classname == "QStackedWidget"_L1) {
150 iface = new QAccessibleStackedWidget(widget);
151#endif
152#if QT_CONFIG(toolbox)
153 } else if (classname == "QToolBox"_L1) {
154 iface = new QAccessibleToolBox(widget);
155#endif
156#if QT_CONFIG(mdiarea)
157 } else if (classname == "QMdiArea"_L1) {
158 iface = new QAccessibleMdiArea(widget);
159 } else if (classname == "QMdiSubWindow"_L1) {
160 iface = new QAccessibleMdiSubWindow(widget);
161#endif
162#if QT_CONFIG(dialogbuttonbox)
163 } else if (classname == "QDialogButtonBox"_L1) {
164 iface = new QAccessibleDialogButtonBox(widget);
165#endif
166#if QT_CONFIG(dial)
167 } else if (classname == "QDial"_L1) {
168 iface = new QAccessibleDial(widget);
169#endif
170#if QT_CONFIG(rubberband)
171 } else if (classname == "QRubberBand"_L1) {
172 iface = new QAccessibleWidget(widget, QAccessible::Border);
173#endif
174#if QT_CONFIG(textbrowser) && !defined(QT_NO_CURSOR)
175 } else if (classname == "QTextBrowser"_L1) {
176 iface = new QAccessibleTextBrowser(widget);
177#endif
178#if QT_CONFIG(scrollarea)
179 } else if (classname == "QAbstractScrollArea"_L1) {
180 iface = new QAccessibleAbstractScrollArea(widget);
181 } else if (classname == "QScrollArea"_L1) {
182 iface = new QAccessibleScrollArea(widget);
183#endif
184#if QT_CONFIG(calendarwidget)
185 } else if (classname == "QCalendarWidget"_L1) {
186 iface = new QAccessibleCalendarWidget(widget);
187#endif
188#if QT_CONFIG(dockwidget)
189 } else if (classname == "QDockWidget"_L1) {
190 iface = new QAccessibleDockWidget(widget);
191#endif
192
193 } else if (classname == "QWidget"_L1) {
194 iface = new QAccessibleWidget(widget);
195 } else if (classname == "QWindowContainer"_L1) {
196 iface = new QAccessibleWindowContainer(widget);
197 }
198
199 return iface;
200}
201
202QT_END_NAMESPACE
203
204#endif // QT_CONFIG(accessibility)
205

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