Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "simplewidgets_p.h" | - |
41 | | - |
42 | #include <qabstractbutton.h> | - |
43 | #include <qcheckbox.h> | - |
44 | #include <qpushbutton.h> | - |
45 | #include <qprogressbar.h> | - |
46 | #include <qstatusbar.h> | - |
47 | #include <qradiobutton.h> | - |
48 | #include <qtoolbutton.h> | - |
49 | #include <qmenu.h> | - |
50 | #include <qlabel.h> | - |
51 | #include <qgroupbox.h> | - |
52 | #include <qlcdnumber.h> | - |
53 | #include <qlineedit.h> | - |
54 | #include <private/qlineedit_p.h> | - |
55 | #include <qstyle.h> | - |
56 | #include <qstyleoption.h> | - |
57 | #include <qtextdocument.h> | - |
58 | #include <qwindow.h> | - |
59 | #include <private/qwindowcontainer_p.h> | - |
60 | #include <QtCore/qvarlengtharray.h> | - |
61 | | - |
62 | #ifdef Q_OS_MAC | - |
63 | #include <qfocusframe.h> | - |
64 | #endif | - |
65 | | - |
66 | QT_BEGIN_NAMESPACE | - |
67 | | - |
68 | #ifndef QT_NO_ACCESSIBILITY | - |
69 | | - |
70 | extern QList<QWidget*> childWidgets(const QWidget *widget); | - |
71 | | - |
72 | QString qt_accStripAmp(const QString &text); | - |
73 | QString qt_accHotKey(const QString &text); | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | QAccessibleButton::QAccessibleButton(QWidget *w) | - |
87 | : QAccessibleWidget(w) | - |
88 | { | - |
89 | Q_ASSERT(button()); | - |
90 | | - |
91 | | - |
92 | | - |
93 | if (button()->isCheckable()) | - |
94 | addControllingSignal(QLatin1String("toggled(bool)")); | - |
95 | else | - |
96 | addControllingSignal(QLatin1String("clicked()")); | - |
97 | } | - |
98 | | - |
99 | | - |
100 | QAbstractButton *QAccessibleButton::button() const | - |
101 | { | - |
102 | return qobject_cast<QAbstractButton*>(object()); | - |
103 | } | - |
104 | | - |
105 | | - |
106 | QString QAccessibleButton::text(QAccessible::Text t) const | - |
107 | { | - |
108 | QString str; | - |
109 | switch (t) { | - |
110 | case QAccessible::Accelerator: | - |
111 | { | - |
112 | #ifndef QT_NO_SHORTCUT | - |
113 | QPushButton *pb = qobject_cast<QPushButton*>(object()); | - |
114 | if (pb && pb->isDefault()) | - |
115 | str = QKeySequence(Qt::Key_Enter).toString(QKeySequence::NativeText); | - |
116 | #endif | - |
117 | if (str.isEmpty()) | - |
118 | str = qt_accHotKey(button()->text()); | - |
119 | } | - |
120 | break; | - |
121 | case QAccessible::Name: | - |
122 | str = widget()->accessibleName(); | - |
123 | if (str.isEmpty()) | - |
124 | str = qt_accStripAmp(button()->text()); | - |
125 | break; | - |
126 | default: | - |
127 | break; | - |
128 | } | - |
129 | if (str.isEmpty()) | - |
130 | str = QAccessibleWidget::text(t); | - |
131 | return str; | - |
132 | } | - |
133 | | - |
134 | QAccessible::State QAccessibleButton::state() const | - |
135 | { | - |
136 | QAccessible::State state = QAccessibleWidget::state(); | - |
137 | | - |
138 | QAbstractButton *b = button(); | - |
139 | QCheckBox *cb = qobject_cast<QCheckBox *>(b); | - |
140 | if (b->isCheckable()) | - |
141 | state.checkable = true; | - |
142 | if (b->isChecked()) | - |
143 | state.checked = true; | - |
144 | else if (cb && cb->checkState() == Qt::PartiallyChecked) | - |
145 | state.checkStateMixed = true; | - |
146 | if (b->isDown()) | - |
147 | state.pressed = true; | - |
148 | QPushButton *pb = qobject_cast<QPushButton*>(b); | - |
149 | if (pb) { | - |
150 | if (pb->isDefault()) | - |
151 | state.defaultButton = true; | - |
152 | #ifndef QT_NO_MENU | - |
153 | if (pb->menu()) | - |
154 | state.hasPopup = true; | - |
155 | #endif | - |
156 | } | - |
157 | | - |
158 | return state; | - |
159 | } | - |
160 | | - |
161 | QRect QAccessibleButton::rect() const | - |
162 | { | - |
163 | QAbstractButton *ab = button(); | - |
164 | if (!ab->isVisible()) | - |
165 | return QRect(); | - |
166 | | - |
167 | if (QCheckBox *cb = qobject_cast<QCheckBox *>(ab)) { | - |
168 | QPoint wpos = cb->mapToGlobal(QPoint(0, 0)); | - |
169 | QStyleOptionButton opt; | - |
170 | cb->initStyleOption(&opt); | - |
171 | return cb->style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, cb).translated(wpos); | - |
172 | } else if (QRadioButton *rb = qobject_cast<QRadioButton *>(ab)) { | - |
173 | QPoint wpos = rb->mapToGlobal(QPoint(0, 0)); | - |
174 | QStyleOptionButton opt; | - |
175 | rb->initStyleOption(&opt); | - |
176 | return rb->style()->subElementRect(QStyle::SE_RadioButtonClickRect, &opt, rb).translated(wpos); | - |
177 | } | - |
178 | return QAccessibleWidget::rect(); | - |
179 | } | - |
180 | | - |
181 | QAccessible::Role QAccessibleButton::role() const | - |
182 | { | - |
183 | QAbstractButton *ab = button(); | - |
184 | | - |
185 | #ifndef QT_NO_MENU | - |
186 | if (QPushButton *pb = qobject_cast<QPushButton*>(ab)) { | - |
187 | if (pb->menu()) | - |
188 | return QAccessible::ButtonMenu; | - |
189 | } | - |
190 | #endif | - |
191 | | - |
192 | if (ab->isCheckable()) | - |
193 | return ab->autoExclusive() ? QAccessible::RadioButton : QAccessible::CheckBox; | - |
194 | | - |
195 | return QAccessible::Button; | - |
196 | } | - |
197 | | - |
198 | QStringList QAccessibleButton::actionNames() const | - |
199 | { | - |
200 | QStringList names; | - |
201 | if (widget()->isEnabled()) { | - |
202 | switch (role()) { | - |
203 | case QAccessible::ButtonMenu: | - |
204 | names << showMenuAction(); | - |
205 | break; | - |
206 | case QAccessible::RadioButton: | - |
207 | names << toggleAction(); | - |
208 | break; | - |
209 | default: | - |
210 | if (button()->isCheckable()) { | - |
211 | names << toggleAction(); | - |
212 | } else { | - |
213 | names << pressAction(); | - |
214 | } | - |
215 | break; | - |
216 | } | - |
217 | } | - |
218 | names << QAccessibleWidget::actionNames(); | - |
219 | return names; | - |
220 | } | - |
221 | | - |
222 | void QAccessibleButton::doAction(const QString &actionName) | - |
223 | { | - |
224 | if (!widget()->isEnabled()) | - |
225 | return; | - |
226 | if (actionName == pressAction() || | - |
227 | actionName == showMenuAction()) { | - |
228 | #ifndef QT_NO_MENU | - |
229 | QPushButton *pb = qobject_cast<QPushButton*>(object()); | - |
230 | if (pb && pb->menu()) | - |
231 | pb->showMenu(); | - |
232 | else | - |
233 | #endif | - |
234 | button()->animateClick(); | - |
235 | } else if (actionName == toggleAction()) { | - |
236 | button()->toggle(); | - |
237 | } else { | - |
238 | QAccessibleWidget::doAction(actionName); | - |
239 | } | - |
240 | } | - |
241 | | - |
242 | QStringList QAccessibleButton::keyBindingsForAction(const QString &actionName) const | - |
243 | { | - |
244 | if (actionName == pressAction()) { | - |
245 | #ifndef QT_NO_SHORTCUT | - |
246 | return QStringList() << button()->shortcut().toString(); | - |
247 | #endif | - |
248 | } | - |
249 | return QStringList(); | - |
250 | } | - |
251 | | - |
252 | | - |
253 | #ifndef QT_NO_TOOLBUTTON | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | QAccessibleToolButton::QAccessibleToolButton(QWidget *w) | - |
266 | : QAccessibleButton(w) | - |
267 | { | - |
268 | Q_ASSERT(toolButton()); | - |
269 | } | - |
270 | | - |
271 | | - |
272 | QToolButton *QAccessibleToolButton::toolButton() const | - |
273 | { | - |
274 | return qobject_cast<QToolButton*>(object()); | - |
275 | } | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | bool QAccessibleToolButton::isSplitButton() const | - |
281 | { | - |
282 | #ifndef QT_NO_MENU | - |
283 | return toolButton()->menu() && toolButton()->popupMode() == QToolButton::MenuButtonPopup; | - |
284 | #else | - |
285 | return false; | - |
286 | #endif | - |
287 | } | - |
288 | | - |
289 | QAccessible::State QAccessibleToolButton::state() const | - |
290 | { | - |
291 | QAccessible::State st = QAccessibleButton::state(); | - |
292 | if (toolButton()->autoRaise()) | - |
293 | st.hotTracked = true; | - |
294 | #ifndef QT_NO_MENU | - |
295 | if (toolButton()->menu()) | - |
296 | st.hasPopup = true; | - |
297 | #endif | - |
298 | return st; | - |
299 | } | - |
300 | | - |
301 | int QAccessibleToolButton::childCount() const | - |
302 | { | - |
303 | return isSplitButton() ? 1 : 0; | - |
304 | } | - |
305 | | - |
306 | QAccessible::Role QAccessibleToolButton::role() const | - |
307 | { | - |
308 | QAbstractButton *ab = button(); | - |
309 | | - |
310 | #ifndef QT_NO_MENU | - |
311 | QToolButton *tb = qobject_cast<QToolButton*>(ab); | - |
312 | if (!tb->menu()) | - |
313 | return tb->isCheckable() ? QAccessible::CheckBox : QAccessible::PushButton; | - |
314 | else if (tb->popupMode() == QToolButton::DelayedPopup) | - |
315 | return QAccessible::ButtonDropDown; | - |
316 | #endif | - |
317 | | - |
318 | return QAccessible::ButtonMenu; | - |
319 | } | - |
320 | | - |
321 | QAccessibleInterface *QAccessibleToolButton::child(int index) const | - |
322 | { | - |
323 | #ifndef QT_NO_MENU | - |
324 | if (index == 0 && toolButton()->menu()) | - |
325 | { | - |
326 | return QAccessible::queryAccessibleInterface(toolButton()->menu()); | - |
327 | } | - |
328 | #endif | - |
329 | return 0; | - |
330 | } | - |
331 | | - |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | QStringList QAccessibleToolButton::actionNames() const | - |
339 | { | - |
340 | QStringList names; | - |
341 | if (widget()->isEnabled()) { | - |
342 | if (toolButton()->menu()) | - |
343 | names << showMenuAction(); | - |
344 | if (toolButton()->popupMode() != QToolButton::InstantPopup) | - |
345 | names << QAccessibleButton::actionNames(); | - |
346 | } | - |
347 | return names; | - |
348 | } | - |
349 | | - |
350 | void QAccessibleToolButton::doAction(const QString &actionName) | - |
351 | { | - |
352 | if (!widget()->isEnabled()) | - |
353 | return; | - |
354 | | - |
355 | if (actionName == pressAction()) { | - |
356 | button()->click(); | - |
357 | } else if (actionName == showMenuAction()) { | - |
358 | if (toolButton()->popupMode() != QToolButton::InstantPopup) { | - |
359 | toolButton()->setDown(true); | - |
360 | #ifndef QT_NO_MENU | - |
361 | toolButton()->showMenu(); | - |
362 | #endif | - |
363 | } | - |
364 | } else { | - |
365 | QAccessibleButton::doAction(actionName); | - |
366 | } | - |
367 | | - |
368 | } | - |
369 | | - |
370 | #endif // QT_NO_TOOLBUTTON | - |
371 | | - |
372 | | - |
373 | | - |
374 | | - |
375 | | - |
376 | | - |
377 | | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | QAccessibleDisplay::QAccessibleDisplay(QWidget *w, QAccessible::Role role) | - |
385 | : QAccessibleWidget(w, role) | - |
386 | { | - |
387 | } | - |
388 | | - |
389 | QAccessible::Role QAccessibleDisplay::role() const | - |
390 | { | - |
391 | QLabel *l = qobject_cast<QLabel*>(object()); | - |
392 | if (l) { | - |
393 | if (l->pixmap()) | - |
394 | return QAccessible::Graphic; | - |
395 | #ifndef QT_NO_PICTURE | - |
396 | if (l->picture()) | - |
397 | return QAccessible::Graphic; | - |
398 | #endif | - |
399 | #ifndef QT_NO_MOVIE | - |
400 | if (l->movie()) | - |
401 | return QAccessible::Animation; | - |
402 | #endif | - |
403 | #ifndef QT_NO_PROGRESSBAR | - |
404 | } else if (qobject_cast<QProgressBar*>(object())) { | - |
405 | return QAccessible::ProgressBar; | - |
406 | #endif | - |
407 | } else if (qobject_cast<QStatusBar*>(object())) { | - |
408 | return QAccessible::StatusBar; | - |
409 | } | - |
410 | return QAccessibleWidget::role(); | - |
411 | } | - |
412 | | - |
413 | QString QAccessibleDisplay::text(QAccessible::Text t) const | - |
414 | { | - |
415 | QString str; | - |
416 | switch (t) { | - |
417 | case QAccessible::Name: | - |
418 | str = widget()->accessibleName(); | - |
419 | if (str.isEmpty()) { | - |
420 | if (qobject_cast<QLabel*>(object())) { | - |
421 | QLabel *label = qobject_cast<QLabel*>(object()); | - |
422 | str = label->text(); | - |
423 | #ifndef QT_NO_TEXTHTMLPARSER | - |
424 | if (label->textFormat() == Qt::RichText | - |
425 | || (label->textFormat() == Qt::AutoText && Qt::mightBeRichText(str))) { | - |
426 | QTextDocument doc; | - |
427 | doc.setHtml(str); | - |
428 | str = doc.toPlainText(); | - |
429 | } | - |
430 | #endif | - |
431 | if (label->buddy()) | - |
432 | str = qt_accStripAmp(str); | - |
433 | #ifndef QT_NO_LCDNUMBER | - |
434 | } else if (qobject_cast<QLCDNumber*>(object())) { | - |
435 | QLCDNumber *l = qobject_cast<QLCDNumber*>(object()); | - |
436 | if (l->digitCount()) | - |
437 | str = QString::number(l->value()); | - |
438 | else | - |
439 | str = QString::number(l->intValue()); | - |
440 | #endif | - |
441 | } else if (qobject_cast<QStatusBar*>(object())) { | - |
442 | return qobject_cast<QStatusBar*>(object())->currentMessage(); | - |
443 | } | - |
444 | } | - |
445 | break; | - |
446 | case QAccessible::Value: | - |
447 | #ifndef QT_NO_PROGRESSBAR | - |
448 | if (qobject_cast<QProgressBar*>(object())) | - |
449 | str = QString::number(qobject_cast<QProgressBar*>(object())->value()); | - |
450 | #endif | - |
451 | break; | - |
452 | default: | - |
453 | break; | - |
454 | } | - |
455 | if (str.isEmpty()) | - |
456 | str = QAccessibleWidget::text(t); | - |
457 | return str; | - |
458 | } | - |
459 | | - |
460 | | - |
461 | QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > | - |
462 | QAccessibleDisplay::relations(QAccessible::Relation match ) const | - |
463 | { | - |
464 | QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match); | - |
465 | if (match & QAccessible::Labelled) { | - |
466 | QVarLengthArray<QObject *, 4> relatedObjects; | - |
467 | | - |
468 | #ifndef QT_NO_SHORTCUT | - |
469 | if (QLabel *label = qobject_cast<QLabel*>(object())) { | - |
470 | relatedObjects.append(label->buddy()); | - |
471 | } | - |
472 | #endif | - |
473 | for (int i = 0; i < relatedObjects.count(); ++i) { | - |
474 | const QAccessible::Relation rel = QAccessible::Labelled; | - |
475 | QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(relatedObjects.at(i)); | - |
476 | if (iface) | - |
477 | rels.append(qMakePair(iface, rel)); | - |
478 | } | - |
479 | } | - |
480 | return rels; | - |
481 | } | - |
482 | | - |
483 | void *QAccessibleDisplay::interface_cast(QAccessible::InterfaceType t) | - |
484 | { | - |
485 | if (t == QAccessible::ImageInterface) | - |
486 | return static_cast<QAccessibleImageInterface*>(this); | - |
487 | return QAccessibleWidget::interface_cast(t); | - |
488 | } | - |
489 | | - |
490 | | - |
491 | QString QAccessibleDisplay::imageDescription() const | - |
492 | { | - |
493 | #ifndef QT_NO_TOOLTIP | - |
494 | return widget()->toolTip(); | - |
495 | #else | - |
496 | return QString::null; | - |
497 | #endif | - |
498 | } | - |
499 | | - |
500 | | - |
501 | QSize QAccessibleDisplay::imageSize() const | - |
502 | { | - |
503 | QLabel *label = qobject_cast<QLabel *>(widget()); | - |
504 | if (!label) | - |
505 | return QSize(); | - |
506 | const QPixmap *pixmap = label->pixmap(); | - |
507 | if (!pixmap) | - |
508 | return QSize(); | - |
509 | return pixmap->size(); | - |
510 | } | - |
511 | | - |
512 | | - |
513 | QPoint QAccessibleDisplay::imagePosition() const | - |
514 | { | - |
515 | QLabel *label = qobject_cast<QLabel *>(widget()); | - |
516 | if (!label) | - |
517 | return QPoint(); | - |
518 | const QPixmap *pixmap = label->pixmap(); | - |
519 | if (!pixmap) | - |
520 | return QPoint(); | - |
521 | | - |
522 | return QPoint(label->mapToGlobal(label->pos())); | - |
523 | } | - |
524 | | - |
525 | #ifndef QT_NO_GROUPBOX | - |
526 | QAccessibleGroupBox::QAccessibleGroupBox(QWidget *w) | - |
527 | : QAccessibleWidget(w) | - |
528 | { | - |
529 | } | - |
530 | | - |
531 | QGroupBox* QAccessibleGroupBox::groupBox() const | - |
532 | { | - |
533 | return static_cast<QGroupBox *>(widget()); | - |
534 | } | - |
535 | | - |
536 | QString QAccessibleGroupBox::text(QAccessible::Text t) const | - |
537 | { | - |
538 | QString txt = QAccessibleWidget::text(t); | - |
539 | | - |
540 | if (txt.isEmpty()) { | - |
541 | switch (t) { | - |
542 | case QAccessible::Name: | - |
543 | txt = qt_accStripAmp(groupBox()->title()); | - |
544 | break; | - |
545 | case QAccessible::Description: | - |
546 | txt = groupBox()->toolTip(); | - |
547 | break; | - |
548 | case QAccessible::Accelerator: | - |
549 | txt = qt_accHotKey(groupBox()->title()); | - |
550 | break; | - |
551 | default: | - |
552 | break; | - |
553 | } | - |
554 | } | - |
555 | | - |
556 | return txt; | - |
557 | } | - |
558 | | - |
559 | QAccessible::State QAccessibleGroupBox::state() const | - |
560 | { | - |
561 | QAccessible::State st = QAccessibleWidget::state(); | - |
562 | st.checkable = groupBox()->isCheckable(); | - |
563 | st.checked = groupBox()->isChecked(); | - |
564 | return st; | - |
565 | } | - |
566 | | - |
567 | QAccessible::Role QAccessibleGroupBox::role() const | - |
568 | { | - |
569 | return groupBox()->isCheckable() ? QAccessible::CheckBox : QAccessible::Grouping; | - |
570 | } | - |
571 | | - |
572 | QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > | - |
573 | QAccessibleGroupBox::relations(QAccessible::Relation match ) const | - |
574 | { | - |
575 | QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match); | - |
576 | | - |
577 | if ((match & QAccessible::Labelled) && (!groupBox()->title().isEmpty())) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
578 | const QList<QWidget*> kids = childWidgets(widget()); | - |
579 | for (int i = 0; i <QWidget *kid : kids.count(); ++i) { | - |
580 | QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(kids.at(i));kid); | - |
581 | if (iface)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
582 | rels.append(qMakePair(iface, QAccessible::Relation(QAccessible::Labelled))); never executed: rels.append(qMakePair(iface, QAccessible::Relation(QAccessible::Labelled))); | 0 |
583 | } never executed: end of block | 0 |
584 | } never executed: end of block | 0 |
585 | return rels; never executed: return rels; | 0 |
586 | } | - |
587 | | - |
588 | QStringList QAccessibleGroupBox::actionNames() const | - |
589 | { | - |
590 | QStringList actions = QAccessibleWidget::actionNames(); | - |
591 | | - |
592 | if (groupBox()->isCheckable()) { | - |
593 | actions.prepend(QAccessibleActionInterface::toggleAction()); | - |
594 | } | - |
595 | return actions; | - |
596 | } | - |
597 | | - |
598 | void QAccessibleGroupBox::doAction(const QString &actionName) | - |
599 | { | - |
600 | if (actionName == QAccessibleActionInterface::toggleAction()) | - |
601 | groupBox()->setChecked(!groupBox()->isChecked()); | - |
602 | } | - |
603 | | - |
604 | QStringList QAccessibleGroupBox::keyBindingsForAction(const QString &) const | - |
605 | { | - |
606 | return QStringList(); | - |
607 | } | - |
608 | | - |
609 | #endif | - |
610 | | - |
611 | #ifndef QT_NO_LINEEDIT | - |
612 | | - |
613 | | - |
614 | | - |
615 | | - |
616 | | - |
617 | | - |
618 | | - |
619 | | - |
620 | | - |
621 | | - |
622 | | - |
623 | | - |
624 | QAccessibleLineEdit::QAccessibleLineEdit(QWidget *w, const QString &name) | - |
625 | : QAccessibleWidget(w, QAccessible::EditableText, name) | - |
626 | { | - |
627 | addControllingSignal(QLatin1String("textChanged(const QString&)")); | - |
628 | addControllingSignal(QLatin1String("returnPressed()")); | - |
629 | } | - |
630 | | - |
631 | | - |
632 | QLineEdit *QAccessibleLineEdit::lineEdit() const | - |
633 | { | - |
634 | return qobject_cast<QLineEdit*>(object()); | - |
635 | } | - |
636 | | - |
637 | QString QAccessibleLineEdit::text(QAccessible::Text t) const | - |
638 | { | - |
639 | QString str; | - |
640 | switch (t) { | - |
641 | case QAccessible::Value: | - |
642 | if (lineEdit()->echoMode() == QLineEdit::Normal) | - |
643 | str = lineEdit()->text(); | - |
644 | else if (lineEdit()->echoMode() != QLineEdit::NoEcho) | - |
645 | str = QString(lineEdit()->text().length(), QChar::fromLatin1('*')); | - |
646 | break; | - |
647 | default: | - |
648 | break; | - |
649 | } | - |
650 | if (str.isEmpty()) | - |
651 | str = QAccessibleWidget::text(t); | - |
652 | return str; | - |
653 | } | - |
654 | | - |
655 | void QAccessibleLineEdit::setText(QAccessible::Text t, const QString &text) | - |
656 | { | - |
657 | if (t != QAccessible::Value) { | - |
658 | QAccessibleWidget::setText(t, text); | - |
659 | return; | - |
660 | } | - |
661 | | - |
662 | QString newText = text; | - |
663 | if (lineEdit()->validator()) { | - |
664 | int pos = 0; | - |
665 | if (lineEdit()->validator()->validate(newText, pos) != QValidator::Acceptable) | - |
666 | return; | - |
667 | } | - |
668 | lineEdit()->setText(newText); | - |
669 | } | - |
670 | | - |
671 | QAccessible::State QAccessibleLineEdit::state() const | - |
672 | { | - |
673 | QAccessible::State state = QAccessibleWidget::state(); | - |
674 | | - |
675 | QLineEdit *l = lineEdit(); | - |
676 | if (l->isReadOnly()) | - |
677 | state.readOnly = true; | - |
678 | else | - |
679 | state.editable = true; | - |
680 | | - |
681 | if (l->echoMode() != QLineEdit::Normal) | - |
682 | state.passwordEdit = true; | - |
683 | | - |
684 | state.selectableText = true; | - |
685 | return state; | - |
686 | } | - |
687 | | - |
688 | void *QAccessibleLineEdit::interface_cast(QAccessible::InterfaceType t) | - |
689 | { | - |
690 | if (t == QAccessible::TextInterface) | - |
691 | return static_cast<QAccessibleTextInterface*>(this); | - |
692 | if (t == QAccessible::EditableTextInterface) | - |
693 | return static_cast<QAccessibleEditableTextInterface*>(this); | - |
694 | return QAccessibleWidget::interface_cast(t); | - |
695 | } | - |
696 | | - |
697 | void QAccessibleLineEdit::addSelection(int startOffset, int endOffset) | - |
698 | { | - |
699 | setSelection(0, startOffset, endOffset); | - |
700 | } | - |
701 | | - |
702 | QString QAccessibleLineEdit::attributes(int offset, int *startOffset, int *endOffset) const | - |
703 | { | - |
704 | | - |
705 | *startOffset = *endOffset = offset; | - |
706 | return QString(); | - |
707 | } | - |
708 | | - |
709 | int QAccessibleLineEdit::cursorPosition() const | - |
710 | { | - |
711 | return lineEdit()->cursorPosition(); | - |
712 | } | - |
713 | | - |
714 | QRect QAccessibleLineEdit::characterRect(int offset) const | - |
715 | { | - |
716 | int x = lineEdit()->d_func()->control->cursorToX(offset); | - |
717 | int y; | - |
718 | lineEdit()->getTextMargins(0, &y, 0, 0); | - |
719 | QFontMetrics fm(lineEdit()->font()); | - |
720 | const QString ch = text(offset, offset + 1); | - |
721 | if (ch.isEmpty()) | - |
722 | return QRect(); | - |
723 | int w = fm.width(ch); | - |
724 | int h = fm.height(); | - |
725 | QRect r(x, y, w, h); | - |
726 | r.moveTo(lineEdit()->mapToGlobal(r.topLeft())); | - |
727 | return r; | - |
728 | } | - |
729 | | - |
730 | int QAccessibleLineEdit::selectionCount() const | - |
731 | { | - |
732 | return lineEdit()->hasSelectedText() ? 1 : 0; | - |
733 | } | - |
734 | | - |
735 | int QAccessibleLineEdit::offsetAtPoint(const QPoint &point) const | - |
736 | { | - |
737 | QPoint p = lineEdit()->mapFromGlobal(point); | - |
738 | | - |
739 | return lineEdit()->cursorPositionAt(p); | - |
740 | } | - |
741 | | - |
742 | void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *endOffset) const | - |
743 | { | - |
744 | *startOffset = *endOffset = 0; | - |
745 | if (selectionIndex != 0) | - |
746 | return; | - |
747 | | - |
748 | *startOffset = lineEdit()->selectionStart(); | - |
749 | *endOffset = *startOffset + lineEdit()->selectedText().count(); | - |
750 | } | - |
751 | | - |
752 | QString QAccessibleLineEdit::text(int startOffset, int endOffset) const | - |
753 | { | - |
754 | if (startOffset > endOffset) | - |
755 | return QString(); | - |
756 | | - |
757 | if (lineEdit()->echoMode() != QLineEdit::Normal) | - |
758 | return QString(); | - |
759 | | - |
760 | return lineEdit()->text().mid(startOffset, endOffset - startOffset); | - |
761 | } | - |
762 | | - |
763 | QString QAccessibleLineEdit::textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, | - |
764 | int *startOffset, int *endOffset) const | - |
765 | { | - |
766 | if (lineEdit()->echoMode() != QLineEdit::Normal) { | - |
767 | *startOffset = *endOffset = -1; | - |
768 | return QString(); | - |
769 | } | - |
770 | if (offset == -2) | - |
771 | offset = cursorPosition(); | - |
772 | return QAccessibleTextInterface::textBeforeOffset(offset, boundaryType, startOffset, endOffset); | - |
773 | } | - |
774 | | - |
775 | QString QAccessibleLineEdit::textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, | - |
776 | int *startOffset, int *endOffset) const | - |
777 | { | - |
778 | if (lineEdit()->echoMode() != QLineEdit::Normal) { | - |
779 | *startOffset = *endOffset = -1; | - |
780 | return QString(); | - |
781 | } | - |
782 | if (offset == -2) | - |
783 | offset = cursorPosition(); | - |
784 | return QAccessibleTextInterface::textAfterOffset(offset, boundaryType, startOffset, endOffset); | - |
785 | } | - |
786 | | - |
787 | QString QAccessibleLineEdit::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, | - |
788 | int *startOffset, int *endOffset) const | - |
789 | { | - |
790 | if (lineEdit()->echoMode() != QLineEdit::Normal) { | - |
791 | *startOffset = *endOffset = -1; | - |
792 | return QString(); | - |
793 | } | - |
794 | if (offset == -2) | - |
795 | offset = cursorPosition(); | - |
796 | return QAccessibleTextInterface::textAtOffset(offset, boundaryType, startOffset, endOffset); | - |
797 | } | - |
798 | | - |
799 | void QAccessibleLineEdit::removeSelection(int selectionIndex) | - |
800 | { | - |
801 | if (selectionIndex != 0) | - |
802 | return; | - |
803 | | - |
804 | lineEdit()->deselect(); | - |
805 | } | - |
806 | | - |
807 | void QAccessibleLineEdit::setCursorPosition(int position) | - |
808 | { | - |
809 | lineEdit()->setCursorPosition(position); | - |
810 | } | - |
811 | | - |
812 | void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int endOffset) | - |
813 | { | - |
814 | if (selectionIndex != 0) | - |
815 | return; | - |
816 | | - |
817 | lineEdit()->setSelection(startOffset, endOffset - startOffset); | - |
818 | } | - |
819 | | - |
820 | int QAccessibleLineEdit::characterCount() const | - |
821 | { | - |
822 | return lineEdit()->text().count(); | - |
823 | } | - |
824 | | - |
825 | void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex) | - |
826 | { | - |
827 | lineEdit()->setCursorPosition(endIndex); | - |
828 | lineEdit()->setCursorPosition(startIndex); | - |
829 | } | - |
830 | | - |
831 | void QAccessibleLineEdit::deleteText(int startOffset, int endOffset) | - |
832 | { | - |
833 | lineEdit()->setText(lineEdit()->text().remove(startOffset, endOffset - startOffset)); | - |
834 | } | - |
835 | | - |
836 | void QAccessibleLineEdit::insertText(int offset, const QString &text) | - |
837 | { | - |
838 | lineEdit()->setText(lineEdit()->text().insert(offset, text)); | - |
839 | } | - |
840 | | - |
841 | void QAccessibleLineEdit::replaceText(int startOffset, int endOffset, const QString &text) | - |
842 | { | - |
843 | lineEdit()->setText(lineEdit()->text().replace(startOffset, endOffset - startOffset, text)); | - |
844 | } | - |
845 | | - |
846 | #endif // QT_NO_LINEEDIT | - |
847 | | - |
848 | #ifndef QT_NO_PROGRESSBAR | - |
849 | QAccessibleProgressBar::QAccessibleProgressBar(QWidget *o) | - |
850 | : QAccessibleDisplay(o) | - |
851 | { | - |
852 | Q_ASSERT(progressBar()); | - |
853 | } | - |
854 | | - |
855 | void *QAccessibleProgressBar::interface_cast(QAccessible::InterfaceType t) | - |
856 | { | - |
857 | if (t == QAccessible::ValueInterface) | - |
858 | return static_cast<QAccessibleValueInterface*>(this); | - |
859 | return QAccessibleDisplay::interface_cast(t); | - |
860 | } | - |
861 | | - |
862 | QVariant QAccessibleProgressBar::currentValue() const | - |
863 | { | - |
864 | return progressBar()->value(); | - |
865 | } | - |
866 | | - |
867 | QVariant QAccessibleProgressBar::maximumValue() const | - |
868 | { | - |
869 | return progressBar()->maximum(); | - |
870 | } | - |
871 | | - |
872 | QVariant QAccessibleProgressBar::minimumValue() const | - |
873 | { | - |
874 | return progressBar()->minimum(); | - |
875 | } | - |
876 | | - |
877 | QVariant QAccessibleProgressBar::minimumStepSize() const | - |
878 | { | - |
879 | | - |
880 | | - |
881 | | - |
882 | return (progressBar()->maximum() - progressBar()->minimum()) / 100.0; | - |
883 | } | - |
884 | | - |
885 | QProgressBar *QAccessibleProgressBar::progressBar() const | - |
886 | { | - |
887 | return qobject_cast<QProgressBar *>(object()); | - |
888 | } | - |
889 | #endif | - |
890 | | - |
891 | | - |
892 | QAccessibleWindowContainer::QAccessibleWindowContainer(QWidget *w) | - |
893 | : QAccessibleWidget(w) | - |
894 | { | - |
895 | } | - |
896 | | - |
897 | int QAccessibleWindowContainer::childCount() const | - |
898 | { | - |
899 | if (container()->containedWindow()) | - |
900 | return 1; | - |
901 | return 0; | - |
902 | } | - |
903 | | - |
904 | int QAccessibleWindowContainer::indexOfChild(const QAccessibleInterface *child) const | - |
905 | { | - |
906 | if (child->object() == container()->containedWindow()) | - |
907 | return 0; | - |
908 | return -1; | - |
909 | } | - |
910 | | - |
911 | QAccessibleInterface *QAccessibleWindowContainer::child(int i) const | - |
912 | { | - |
913 | if (i == 0) | - |
914 | return QAccessible::queryAccessibleInterface(container()->containedWindow()); | - |
915 | return 0; | - |
916 | } | - |
917 | | - |
918 | QWindowContainer *QAccessibleWindowContainer::container() const | - |
919 | { | - |
920 | return static_cast<QWindowContainer *>(widget()); | - |
921 | } | - |
922 | | - |
923 | #endif // QT_NO_ACCESSIBILITY | - |
924 | | - |
925 | QT_END_NAMESPACE | - |
| | |