Use new plugin system in qtbase.
[profile/ivi/qtbase.git] / src / plugins / accessible / widgets / main.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 plugins 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 "qaccessiblewidgets.h"
43 #include "qaccessiblemenu.h"
44 #include "simplewidgets.h"
45 #include "rangecontrols.h"
46 #include "complexwidgets.h"
47 #include "itemviews.h"
48
49 #include <qaccessibleplugin.h>
50 #include <qplugin.h>
51 #include <qpushbutton.h>
52 #include <qtoolbutton.h>
53 #include <qtreeview.h>
54 #include <qvariant.h>
55 #include <qaccessible.h>
56
57 #ifndef QT_NO_ACCESSIBILITY
58
59 QT_BEGIN_NAMESPACE
60
61
62 class AccessibleFactory : public QAccessiblePlugin
63 {
64     Q_OBJECT
65     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QAccessibleFactoryInterface" FILE "widgets.json")
66
67 public:
68     AccessibleFactory();
69
70     QStringList keys() const;
71     QAccessibleInterface *create(const QString &classname, QObject *object);
72 };
73
74 AccessibleFactory::AccessibleFactory()
75 {
76 }
77
78 QStringList AccessibleFactory::keys() const
79 {
80     QStringList list;
81 #ifndef QT_NO_LINEEDIT
82     list << QLatin1String("QLineEdit");
83 #endif
84 #ifndef QT_NO_COMBOBOX
85     list << QLatin1String("QComboBox");
86 #endif
87 #ifndef QT_NO_SPINBOX
88     list << QLatin1String("QAbstractSpinBox");
89     list << QLatin1String("QSpinBox");
90     list << QLatin1String("QDoubleSpinBox");
91 #endif
92 #ifndef QT_NO_SCROLLBAR
93     list << QLatin1String("QScrollBar");
94 #endif
95 #ifndef QT_NO_SLIDER
96     list << QLatin1String("QSlider");
97 #endif
98     list << QLatin1String("QAbstractSlider");
99 #ifndef QT_NO_TOOLBUTTON
100     list << QLatin1String("QToolButton");
101 #endif
102     list << QLatin1String("QCheckBox");
103     list << QLatin1String("QRadioButton");
104     list << QLatin1String("QPushButton");
105     list << QLatin1String("QAbstractButton");
106     list << QLatin1String("QDialog");
107     list << QLatin1String("QMessageBox");
108     list << QLatin1String("QMainWindow");
109     list << QLatin1String("QLabel");
110     list << QLatin1String("QLCDNumber");
111     list << QLatin1String("QGroupBox");
112     list << QLatin1String("QStatusBar");
113     list << QLatin1String("QProgressBar");
114     list << QLatin1String("QMenuBar");
115     list << QLatin1String("QMenu");
116     list << QLatin1String("QHeaderView");
117     list << QLatin1String("QTabBar");
118     list << QLatin1String("QToolBar");
119     list << QLatin1String("QWorkspaceChild");
120     list << QLatin1String("QSizeGrip");
121     list << QLatin1String("QAbstractItemView");
122     list << QLatin1String("QWidget");
123 #ifndef QT_NO_SPLITTER
124     list << QLatin1String("QSplitter");
125     list << QLatin1String("QSplitterHandle");
126 #endif
127 #ifndef QT_NO_TEXTEDIT
128     list << QLatin1String("QTextEdit");
129 #endif
130     list << QLatin1String("QTipLabel");
131     list << QLatin1String("QFrame");
132     list << QLatin1String("QStackedWidget");
133     list << QLatin1String("QToolBox");
134     list << QLatin1String("QMdiArea");
135     list << QLatin1String("QMdiSubWindow");
136     list << QLatin1String("QWorkspace");
137     list << QLatin1String("QDialogButtonBox");
138 #ifndef QT_NO_DIAL
139     list << QLatin1String("QDial");
140 #endif
141 #ifndef QT_NO_RUBBERBAND
142     list << QLatin1String("QRubberBand");
143 #endif
144 #ifndef QT_NO_TEXTBROWSER
145     list << QLatin1String("QTextBrowser");
146 #endif
147 #ifndef QT_NO_SCROLLAREA
148     list << QLatin1String("QAbstractScrollArea");
149     list << QLatin1String("QScrollArea");
150 #endif
151 #ifndef QT_NO_CALENDARWIDGET
152     list << QLatin1String("QCalendarWidget");
153 #endif
154
155 #ifndef QT_NO_DOCKWIDGET
156     list << QLatin1String("QDockWidget");
157 #endif
158     list << QLatin1String("QAccessibleWidget");
159     return list;
160 }
161
162 QAccessibleInterface *AccessibleFactory::create(const QString &classname, QObject *object)
163 {
164     QAccessibleInterface *iface = 0;
165     if (!object || !object->isWidgetType())
166         return iface;
167     QWidget *widget = static_cast<QWidget*>(object);
168
169     if (false) {
170 #ifndef QT_NO_LINEEDIT
171     } else if (classname == QLatin1String("QLineEdit")) {
172         iface = new QAccessibleLineEdit(widget);
173 #endif
174 #ifndef QT_NO_COMBOBOX
175     } else if (classname == QLatin1String("QComboBox")) {
176         iface = new QAccessibleComboBox(widget);
177 #endif
178 #ifndef QT_NO_SPINBOX
179     } else if (classname == QLatin1String("QAbstractSpinBox")) {
180         iface = new QAccessibleAbstractSpinBox(widget);
181     } else if (classname == QLatin1String("QSpinBox")) {
182         iface = new QAccessibleSpinBox(widget);
183     } else if (classname == QLatin1String("QDoubleSpinBox")) {
184         iface = new QAccessibleDoubleSpinBox(widget);
185 #endif
186 #ifndef QT_NO_SCROLLBAR
187     } else if (classname == QLatin1String("QScrollBar")) {
188         iface = new QAccessibleScrollBar(widget);
189 #endif
190     } else if (classname == QLatin1String("QAbstractSlider")) {
191         iface = new QAccessibleAbstractSlider(widget);
192 #ifndef QT_NO_SLIDER
193     } else if (classname == QLatin1String("QSlider")) {
194         iface = new QAccessibleSlider(widget);
195 #endif
196 #ifndef QT_NO_TOOLBUTTON
197     } else if (classname == QLatin1String("QToolButton")) {
198         QAccessible::Role role = QAccessible::NoRole;
199 #ifndef QT_NO_MENU
200         QToolButton *tb = qobject_cast<QToolButton*>(widget);
201         if (!tb->menu())
202             role = tb->isCheckable() ? QAccessible::CheckBox : QAccessible::PushButton;
203         else if (!tb->popupMode() != QToolButton::DelayedPopup)
204             role = QAccessible::ButtonDropDown;
205         else
206 #endif
207             role = QAccessible::ButtonMenu;
208         iface = new QAccessibleToolButton(widget, role);
209 #endif // QT_NO_TOOLBUTTON
210     } else if (classname == QLatin1String("QCheckBox")) {
211         iface = new QAccessibleButton(widget, QAccessible::CheckBox);
212     } else if (classname == QLatin1String("QRadioButton")) {
213         iface = new QAccessibleButton(widget, QAccessible::RadioButton);
214     } else if (classname == QLatin1String("QPushButton")) {
215         QAccessible::Role role = QAccessible::NoRole;
216         QPushButton *pb = qobject_cast<QPushButton*>(widget);
217 #ifndef QT_NO_MENU
218         if (pb->menu())
219             role = QAccessible::ButtonMenu;
220         else
221 #endif
222         if (pb->isCheckable())
223             role = QAccessible::CheckBox;
224         else
225             role = QAccessible::PushButton;
226         iface = new QAccessibleButton(widget, role);
227     } else if (classname == QLatin1String("QAbstractButton")) {
228         iface = new QAccessibleButton(widget, QAccessible::PushButton);
229     } else if (classname == QLatin1String("QDialog")) {
230         iface = new QAccessibleWidget(widget, QAccessible::Dialog);
231     } else if (classname == QLatin1String("QMessageBox")) {
232         iface = new QAccessibleWidget(widget, QAccessible::AlertMessage);
233 #ifndef QT_NO_MAINWINDOW
234     } else if (classname == QLatin1String("QMainWindow")) {
235         iface = new QAccessibleMainWindow(widget);
236 #endif
237     } else if (classname == QLatin1String("QLabel") || classname == QLatin1String("QLCDNumber")) {
238         iface = new QAccessibleDisplay(widget);
239     } else if (classname == QLatin1String("QGroupBox")) {
240         iface = new QAccessibleDisplay(widget, QAccessible::Grouping);
241     } else if (classname == QLatin1String("QStatusBar")) {
242         iface = new QAccessibleWidget(widget, QAccessible::StatusBar);
243 #ifndef QT_NO_PROGRESSBAR
244     } else if (classname == QLatin1String("QProgressBar")) {
245         iface = new QAccessibleProgressBar(widget);
246 #endif
247     } else if (classname == QLatin1String("QToolBar")) {
248         iface = new QAccessibleWidget(widget, QAccessible::ToolBar, widget->windowTitle());
249 #ifndef QT_NO_MENUBAR
250     } else if (classname == QLatin1String("QMenuBar")) {
251         iface = new QAccessibleMenuBar(widget);
252 #endif
253 #ifndef QT_NO_MENU
254     } else if (classname == QLatin1String("QMenu")) {
255         iface = new QAccessibleMenu(widget);
256 #endif
257 #ifndef QT_NO_ITEMVIEWS
258     } else if (classname == QLatin1String("QAbstractItemView")) {
259         if (qobject_cast<const QTreeView*>(widget)) {
260             iface = new QAccessibleTree(widget);
261         } else {
262             iface = new QAccessibleTable(widget);
263         }
264     } else if (classname == QLatin1String("QWidget")
265                && widget->objectName() == QLatin1String("qt_scrollarea_viewport")
266                && qobject_cast<QAbstractItemView*>(widget->parentWidget())) {
267         if (qobject_cast<const QTreeView*>(widget->parentWidget())) {
268             iface = new QAccessibleTree(widget->parentWidget());
269         } else {
270             iface = new QAccessibleTable(widget->parentWidget());
271         }
272 #endif // QT_NO_ITEMVIEWS
273 #ifndef QT_NO_TABBAR
274     } else if (classname == QLatin1String("QTabBar")) {
275         iface = new QAccessibleTabBar(widget);
276 #endif
277     } else if (classname == QLatin1String("QWorkspaceChild")) {
278         iface = new QAccessibleWidget(widget, QAccessible::Window);
279     } else if (classname == QLatin1String("QSizeGrip")) {
280         iface = new QAccessibleWidget(widget, QAccessible::Grip);
281 #ifndef QT_NO_SPLITTER
282     } else if (classname == QLatin1String("QSplitter")) {
283         iface = new QAccessibleWidget(widget, QAccessible::Splitter);
284     } else if (classname == QLatin1String("QSplitterHandle")) {
285         iface = new QAccessibleWidget(widget, QAccessible::Grip);
286 #endif
287 #ifndef QT_NO_TEXTEDIT
288     } else if (classname == QLatin1String("QTextEdit")) {
289         iface = new QAccessibleTextEdit(widget);
290 #endif
291     } else if (classname == QLatin1String("QTipLabel")) {
292         iface = new QAccessibleDisplay(widget, QAccessible::ToolTip);
293     } else if (classname == QLatin1String("QFrame")) {
294         iface = new QAccessibleWidget(widget, QAccessible::Border);
295 #ifndef QT_NO_STACKEDWIDGET
296     } else if (classname == QLatin1String("QStackedWidget")) {
297         iface = new QAccessibleStackedWidget(widget);
298 #endif
299 #ifndef QT_NO_TOOLBOX
300     } else if (classname == QLatin1String("QToolBox")) {
301         iface = new QAccessibleToolBox(widget);
302 #endif
303 #ifndef QT_NO_MDIAREA
304     } else if (classname == QLatin1String("QMdiArea")) {
305         iface = new QAccessibleMdiArea(widget);
306     } else if (classname == QLatin1String("QMdiSubWindow")) {
307         iface = new QAccessibleMdiSubWindow(widget);
308 #endif
309 #ifndef QT_NO_WORKSPACE
310     } else if (classname == QLatin1String("QWorkspace")) {
311         iface = new QAccessibleWorkspace(widget);
312 #endif
313     } else if (classname == QLatin1String("QDialogButtonBox")) {
314         iface = new QAccessibleDialogButtonBox(widget);
315 #ifndef QT_NO_DIAL
316     } else if (classname == QLatin1String("QDial")) {
317         iface = new QAccessibleDial(widget);
318 #endif
319 #ifndef QT_NO_RUBBERBAND
320     } else if (classname == QLatin1String("QRubberBand")) {
321         iface = new QAccessibleWidget(widget, QAccessible::Border);
322 #endif
323 #ifndef QT_NO_TEXTBROWSER
324     } else if (classname == QLatin1String("QTextBrowser")) {
325         iface = new QAccessibleTextBrowser(widget);
326 #endif
327 #ifndef QT_NO_SCROLLAREA
328     } else if (classname == QLatin1String("QAbstractScrollArea")) {
329         iface = new QAccessibleAbstractScrollArea(widget);
330     } else if (classname == QLatin1String("QScrollArea")) {
331         iface = new QAccessibleScrollArea(widget);
332 #endif
333 #ifndef QT_NO_CALENDARWIDGET
334     } else if (classname == QLatin1String("QCalendarWidget")) {
335         iface = new QAccessibleCalendarWidget(widget);
336 #endif
337 #ifndef QT_NO_DOCKWIDGET
338     } else if (classname == QLatin1String("QDockWidget")) {
339         iface = new QAccessibleDockWidget(widget);
340 #endif
341     } else {
342         iface = new QAccessibleWidget(widget);
343     }
344
345     return iface;
346 }
347
348
349 QT_END_NAMESPACE
350
351 #include "main.moc"
352
353 #endif // QT_NO_ACCESSIBILITY