accessible/qaccessiblewidget.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7static QList<QWidget*> childWidgets(const QWidget *widget) -
8{ -
9 QList<QObject*> list = widget->children(); -
10 QList<QWidget*> widgets; -
11 for (int i = 0; i < list.size(); ++i) {
-
12 QWidget *w = qobject_cast<QWidget *>(list.at(i)); -
13 if (w && !w->isWindow()
-
14 && !qobject_cast<QFocusFrame*>(w)
-
15 -
16 && !qobject_cast<QMenu*>(w)
-
17 -
18 && w->objectName() != QLatin1String("qt_rubberband"))
-
19 widgets.append(w);
-
20 }
-
21 return widgets;
-
22} -
23 -
24static QString buddyString(const QWidget *widget) -
25{ -
26 if (!widget)
-
27 return QString();
-
28 QWidget *parent = widget->parentWidget(); -
29 if (!parent)
-
30 return QString();
-
31 -
32 QObjectList ol = parent->children(); -
33 for (int i = 0; i < ol.size(); ++i) {
-
34 QLabel *label = qobject_cast<QLabel*>(ol.at(i)); -
35 if (label && label->buddy() == widget)
-
36 return label->text();
-
37 }
-
38 -
39 -
40 -
41 QGroupBox *groupbox = qobject_cast<QGroupBox*>(parent); -
42 if (groupbox)
-
43 return groupbox->title();
-
44 -
45 -
46 return QString();
-
47} -
48 -
49 -
50 -
51 -
52static int qt_accAmpIndex(const QString &text) -
53{ -
54 -
55 if (text.isEmpty())
-
56 return -1;
-
57 -
58 int fa = 0; -
59 QChar ac; -
60 while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) {
-
61 ++fa; -
62 if (fa < text.length()) {
-
63 -
64 if (text.at(fa) == QLatin1Char('&')) {
-
65 -
66 ++fa; -
67 continue;
-
68 } else { -
69 return fa - 1;
-
70 break;
dead code: break;
-
71 } -
72 } -
73 }
-
74 -
75 return -1;
-
76 -
77 -
78 -
79 -
80} -
81 -
82QString __attribute__((visibility("default"))) qt_accStripAmp(const QString &text) -
83{ -
84 QString newText(text); -
85 int ampIndex = qt_accAmpIndex(newText); -
86 if (ampIndex != -1)
-
87 newText.remove(ampIndex, 1);
-
88 -
89 return newText.replace(QLatin1String("&&"), QLatin1String("&"));
-
90} -
91 -
92QString __attribute__((visibility("default"))) qt_accHotKey(const QString &text) -
93{ -
94 int ampIndex = qt_accAmpIndex(text); -
95 if (ampIndex != -1)
-
96 return QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + text.at(ampIndex + 1);
-
97 -
98 return QString();
-
99} -
100 -
101class QAccessibleWidgetPrivate -
102{ -
103public: -
104 QAccessibleWidgetPrivate() -
105 :role(QAccessible::Client) -
106 {}
-
107 -
108 QAccessible::Role role; -
109 QString name; -
110 QStringList primarySignals; -
111}; -
112QAccessibleWidget::QAccessibleWidget(QWidget *w, QAccessible::Role role, const QString &name) -
113: QAccessibleObject(w) -
114{ -
115 qt_noop(); -
116 d = new QAccessibleWidgetPrivate(); -
117 d->role = role; -
118 d->name = name; -
119}
-
120 -
121 -
122QWindow *QAccessibleWidget::window() const -
123{ -
124 return widget()->windowHandle();
-
125} -
126 -
127 -
128 -
129 -
130QAccessibleWidget::~QAccessibleWidget() -
131{ -
132 delete d; -
133}
-
134 -
135 -
136 -
137 -
138QWidget *QAccessibleWidget::widget() const -
139{ -
140 return qobject_cast<QWidget*>(object());
-
141} -
142 -
143 -
144 -
145 -
146 -
147QObject *QAccessibleWidget::parentObject() const -
148{ -
149 QObject *parent = object()->parent(); -
150 if (!parent)
-
151 parent = (static_cast<QApplication *>(QCoreApplication::instance()));
-
152 return parent;
-
153} -
154 -
155 -
156QRect QAccessibleWidget::rect() const -
157{ -
158 QWidget *w = widget(); -
159 if (!w->isVisible())
-
160 return QRect();
-
161 QPoint wpos = w->mapToGlobal(QPoint(0, 0)); -
162 -
163 return QRect(wpos.x(), wpos.y(), w->width(), w->height());
-
164} -
165 -
166 -
167 -
168 -
169class QACConnectionObject : public QObject -
170{ -
171 inline QObjectPrivate* d_func() { return reinterpret_cast<QObjectPrivate *>(qGetPtrHelper(d_ptr)); } inline const QObjectPrivate* d_func() const { return reinterpret_cast<const QObjectPrivate *>(qGetPtrHelper(d_ptr)); } friend class QObjectPrivate;
-
172public: -
173 inline bool isSender(const QObject *receiver, const char *signal) const -
174 { return d_func()->isSender(receiver, signal); }
-
175 inline QObjectList receiverList(const char *signal) const -
176 { return d_func()->receiverList(signal); }
-
177 inline QObjectList senderList() const -
178 { return d_func()->senderList(); }
-
179}; -
180 -
181 -
182 -
183 -
184 -
185 -
186 -
187void QAccessibleWidget::addControllingSignal(const QString &signal) -
188{ -
189 QByteArray s = QMetaObject::normalizedSignature(signal.toLatin1()); -
190 if (object()->metaObject()->indexOfSignal(s) < 0)
-
191 QMessageLogger("accessible/qaccessiblewidget.cpp", 276, __PRETTY_FUNCTION__).warning("Signal %s unknown in %s", s.constData(), object()->metaObject()->className());
-
192 d->primarySignals << QLatin1String(s); -
193}
-
194 -
195static inline bool isAncestor(const QObject *obj, const QObject *child) -
196{ -
197 while (child) {
-
198 if (child == obj)
-
199 return true;
-
200 child = child->parent(); -
201 }
-
202 return false;
-
203} -
204 -
205 -
206QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > -
207QAccessibleWidget::relations(QAccessible::Relation match ) const -
208{ -
209 QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels; -
210 if (match & QAccessible::Label) {
-
211 const QAccessible::Relation rel = QAccessible::Label; -
212 if (QWidget *parent = widget()->parentWidget()) {
-
213 -
214 -
215 -
216 -
217 const QList<QWidget*> kids = childWidgets(parent); -
218 for (int i = 0; i < kids.count(); ++i) {
-
219 if (QLabel *labelSibling = qobject_cast<QLabel*>(kids.at(i))) {
-
220 if (labelSibling->buddy() == widget()) {
-
221 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(labelSibling); -
222 rels.append(qMakePair(iface, rel)); -
223 }
-
224 }
-
225 }
-
226 -
227 -
228 QGroupBox *groupbox = qobject_cast<QGroupBox*>(parent); -
229 if (groupbox && !groupbox->title().isEmpty()) {
-
230 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(groupbox); -
231 rels.append(qMakePair(iface, rel)); -
232 }
-
233 -
234 }
-
235 }
-
236 -
237 if (match & QAccessible::Controlled) {
-
238 QObjectList allReceivers; -
239 QACConnectionObject *connectionObject = (QACConnectionObject*)object(); -
240 for (int sig = 0; sig < d->primarySignals.count(); ++sig) {
-
241 const QObjectList receivers = connectionObject->receiverList(d->primarySignals.at(sig).toLatin1()); -
242 allReceivers += receivers; -
243 }
-
244 -
245 allReceivers.removeAll(object()); -
246 -
247 for (int i = 0; i < allReceivers.count(); ++i) {
-
248 const QAccessible::Relation rel = QAccessible::Controlled; -
249 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(allReceivers.at(i)); -
250 if (iface)
-
251 rels.append(qMakePair(iface, rel));
-
252 }
-
253 }
-
254 -
255 return rels;
-
256} -
257 -
258 -
259QAccessibleInterface *QAccessibleWidget::parent() const -
260{ -
261 QObject *parentWidget= widget()->parentWidget(); -
262 if (!parentWidget)
-
263 parentWidget = (static_cast<QApplication *>(QCoreApplication::instance()));
-
264 return QAccessible::queryAccessibleInterface(parentWidget);
-
265} -
266 -
267 -
268QAccessibleInterface *QAccessibleWidget::child(int index) const -
269{ -
270 QWidgetList childList = childWidgets(widget()); -
271 if (index >= 0 && index < childList.size())
-
272 return QAccessible::queryAccessibleInterface(childList.at(index));
-
273 return 0;
-
274} -
275 -
276 -
277QAccessibleInterface *QAccessibleWidget::focusChild() const -
278{ -
279 if (widget()->hasFocus())
-
280 return QAccessible::queryAccessibleInterface(object());
-
281 -
282 QWidget *fw = widget()->focusWidget(); -
283 if (!fw)
-
284 return 0;
-
285 -
286 if (isAncestor(widget(), fw) || fw == widget())
-
287 return QAccessible::queryAccessibleInterface(fw);
-
288 return 0;
-
289} -
290 -
291 -
292int QAccessibleWidget::childCount() const -
293{ -
294 QWidgetList cl = childWidgets(widget()); -
295 return cl.size();
-
296} -
297 -
298 -
299int QAccessibleWidget::indexOfChild(const QAccessibleInterface *child) const -
300{ -
301 QWidgetList cl = childWidgets(widget()); -
302 return cl.indexOf(qobject_cast<QWidget *>(child->object()));
-
303} -
304 -
305 -
306extern QString qt_setWindowTitle_helperHelper(const QString &, const QWidget*); -
307 -
308 -
309QString QAccessibleWidget::text(QAccessible::Text t) const -
310{ -
311 QString str; -
312 -
313 switch (t) { -
314 case QAccessible::Name: -
315 if (!d->name.isEmpty()) {
-
316 str = d->name; -
317 } else if (!widget()->accessibleName().isEmpty()) {
-
318 str = widget()->accessibleName(); -
319 } else if (widget()->isWindow()) {
-
320 if (widget()->isMinimized())
-
321 str = qt_setWindowTitle_helperHelper(widget()->windowIconText(), widget());
-
322 else -
323 str = qt_setWindowTitle_helperHelper(widget()->windowTitle(), widget());
-
324 } else { -
325 str = qt_accStripAmp(buddyString(widget())); -
326 }
-
327 break;
-
328 case QAccessible::Description: -
329 if (!widget()->accessibleDescription().isEmpty())
-
330 str = widget()->accessibleDescription();
-
331 -
332 else -
333 str = widget()->toolTip();
-
334 -
335 break;
-
336 case QAccessible::Help: -
337 -
338 str = widget()->whatsThis(); -
339 -
340 break;
-
341 case QAccessible::Accelerator: -
342 str = qt_accHotKey(buddyString(widget())); -
343 break;
-
344 case QAccessible::Value: -
345 break;
-
346 default: -
347 break;
-
348 } -
349 return str;
-
350} -
351 -
352 -
353QStringList QAccessibleWidget::actionNames() const -
354{ -
355 QStringList names; -
356 if (widget()->isEnabled()) {
-
357 if (widget()->focusPolicy() != Qt::NoFocus)
-
358 names << setFocusAction();
-
359 }
-
360 return names;
-
361} -
362 -
363 -
364void QAccessibleWidget::doAction(const QString &actionName) -
365{ -
366 if (!widget()->isEnabled())
-
367 return;
-
368 -
369 if (actionName == setFocusAction()) {
-
370 if (widget()->isWindow())
-
371 widget()->activateWindow();
-
372 widget()->setFocus(); -
373 }
-
374}
-
375 -
376 -
377QStringList QAccessibleWidget::keyBindingsForAction(const QString & ) const -
378{ -
379 return QStringList();
-
380} -
381 -
382 -
383QAccessible::Role QAccessibleWidget::role() const -
384{ -
385 return d->role;
-
386} -
387 -
388 -
389QAccessible::State QAccessibleWidget::state() const -
390{ -
391 QAccessible::State state; -
392 -
393 QWidget *w = widget(); -
394 if (w->testAttribute(Qt::WA_WState_Visible) == false)
-
395 state.invisible = true;
-
396 if (w->focusPolicy() != Qt::NoFocus)
-
397 state.focusable = true;
-
398 if (w->hasFocus())
-
399 state.focused = true;
-
400 if (!w->isEnabled())
-
401 state.disabled = true;
-
402 if (w->isWindow()) {
-
403 if (w->windowFlags() & Qt::WindowSystemMenuHint)
-
404 state.movable = true;
-
405 if (w->minimumSize() != w->maximumSize())
-
406 state.sizeable = true;
-
407 if (w->isActiveWindow())
-
408 state.active = true;
-
409 }
-
410 -
411 return state;
-
412} -
413 -
414 -
415QColor QAccessibleWidget::foregroundColor() const -
416{ -
417 return widget()->palette().color(widget()->foregroundRole());
-
418} -
419 -
420 -
421QColor QAccessibleWidget::backgroundColor() const -
422{ -
423 return widget()->palette().color(widget()->backgroundRole());
-
424} -
425 -
426 -
427void *QAccessibleWidget::interface_cast(QAccessible::InterfaceType t) -
428{ -
429 if (t == QAccessible::ActionInterface)
-
430 return static_cast<QAccessibleActionInterface*>(this);
-
431 return 0;
-
432} -
433 -
434 -
435 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial