qaccessiblewidget.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9