simplewidgets.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/accessible/simplewidgets.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the plugins of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
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-
66QT_BEGIN_NAMESPACE-
67-
68#ifndef QT_NO_ACCESSIBILITY-
69-
70extern QList<QWidget*> childWidgets(const QWidget *widget);-
71-
72QString qt_accStripAmp(const QString &text);-
73QString qt_accHotKey(const QString &text);-
74-
75/*!-
76 \class QAccessibleButton-
77 \brief The QAccessibleButton class implements the QAccessibleInterface for button type widgets.-
78 \internal-
79-
80 \ingroup accessibility-
81*/-
82-
83/*!-
84 Creates a QAccessibleButton object for \a w.-
85*/-
86QAccessibleButton::QAccessibleButton(QWidget *w)-
87: QAccessibleWidget(w)-
88{-
89 Q_ASSERT(button());-
90-
91 // FIXME: The checkable state of the button is dynamic,-
92 // while we only update the controlling signal once :(-
93 if (button()->isCheckable())-
94 addControllingSignal(QLatin1String("toggled(bool)"));-
95 else-
96 addControllingSignal(QLatin1String("clicked()"));-
97}-
98-
99/*! Returns the button. */-
100QAbstractButton *QAccessibleButton::button() const-
101{-
102 return qobject_cast<QAbstractButton*>(object());-
103}-
104-
105/*! \reimp */-
106QString 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-
134QAccessible::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-
161QRect 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-
181QAccessible::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-
198QStringList 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-
222void 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-
242QStringList 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 \class QAccessibleToolButton-
256 \brief The QAccessibleToolButton class implements the QAccessibleInterface for tool buttons.-
257 \internal-
258-
259 \ingroup accessibility-
260*/-
261-
262/*!-
263 Creates a QAccessibleToolButton object for \a w.-
264*/-
265QAccessibleToolButton::QAccessibleToolButton(QWidget *w)-
266: QAccessibleButton(w)-
267{-
268 Q_ASSERT(toolButton());-
269}-
270-
271/*! Returns the button. */-
272QToolButton *QAccessibleToolButton::toolButton() const-
273{-
274 return qobject_cast<QToolButton*>(object());-
275}-
276-
277/*!-
278 Returns \c true if this tool button is a split button.-
279*/-
280bool 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-
289QAccessible::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-
301int QAccessibleToolButton::childCount() const-
302{-
303 return isSplitButton() ? 1 : 0;-
304}-
305-
306QAccessible::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-
321QAccessibleInterface *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 The three different tool button types can have the following actions:-
334| DelayedPopup | ShowMenuAction + (PressedAction || CheckedAction) |-
335| MenuButtonPopup | ShowMenuAction + (PressedAction || CheckedAction) |-
336| InstantPopup | ShowMenuAction |-
337*/-
338QStringList 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-
350void 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 \class QAccessibleDisplay-
374 \brief The QAccessibleDisplay class implements the QAccessibleInterface for widgets that display information.-
375 \internal-
376-
377 \ingroup accessibility-
378*/-
379-
380/*!-
381 Constructs a QAccessibleDisplay object for \a w.-
382 \a role is propagated to the QAccessibleWidget constructor.-
383*/-
384QAccessibleDisplay::QAccessibleDisplay(QWidget *w, QAccessible::Role role)-
385: QAccessibleWidget(w, role)-
386{-
387}-
388-
389QAccessible::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-
413QString 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/*! \reimp */-
461QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >-
462QAccessibleDisplay::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) 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-
483void *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/*! \internal */-
491QString QAccessibleDisplay::imageDescription() const-
492{-
493#ifndef QT_NO_TOOLTIP-
494 return widget()->toolTip();-
495#else-
496 return QString::null;-
497#endif-
498}-
499-
500/*! \internal */-
501QSize 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/*! \internal */-
513QPoint 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-
526QAccessibleGroupBox::QAccessibleGroupBox(QWidget *w)-
527: QAccessibleWidget(w)-
528{-
529}-
530-
531QGroupBox* QAccessibleGroupBox::groupBox() const-
532{-
533 return static_cast<QGroupBox *>(widget());-
534}-
535-
536QString 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-
559QAccessible::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-
567QAccessible::Role QAccessibleGroupBox::role() const-
568{-
569 return groupBox()->isCheckable() ? QAccessible::CheckBox : QAccessible::Grouping;-
570}-
571-
572QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >-
573QAccessibleGroupBox::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const-
574{-
575 QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match);-
576-
577 if ((match & QAccessible::Labelled) && (!groupBox()->title().isEmpty())) {
(match & QAcce...ble::Labelled)Description
TRUEnever evaluated
FALSEnever evaluated
(!groupBox()->...e().isEmpty())Description
TRUEnever evaluated
FALSEnever 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)
ifaceDescription
TRUEnever evaluated
FALSEnever 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-
588QStringList 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-
598void QAccessibleGroupBox::doAction(const QString &actionName)-
599{-
600 if (actionName == QAccessibleActionInterface::toggleAction())-
601 groupBox()->setChecked(!groupBox()->isChecked());-
602}-
603-
604QStringList QAccessibleGroupBox::keyBindingsForAction(const QString &) const-
605{-
606 return QStringList();-
607}-
608-
609#endif-
610-
611#ifndef QT_NO_LINEEDIT-
612/*!-
613 \class QAccessibleLineEdit-
614 \brief The QAccessibleLineEdit class implements the QAccessibleInterface for widgets with editable text-
615 \internal-
616-
617 \ingroup accessibility-
618*/-
619-
620/*!-
621 Constructs a QAccessibleLineEdit object for \a w.-
622 \a name is propagated to the QAccessibleWidget constructor.-
623*/-
624QAccessibleLineEdit::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/*! Returns the line edit. */-
632QLineEdit *QAccessibleLineEdit::lineEdit() const-
633{-
634 return qobject_cast<QLineEdit*>(object());-
635}-
636-
637QString 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-
655void 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-
671QAccessible::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-
688void *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-
697void QAccessibleLineEdit::addSelection(int startOffset, int endOffset)-
698{-
699 setSelection(0, startOffset, endOffset);-
700}-
701-
702QString QAccessibleLineEdit::attributes(int offset, int *startOffset, int *endOffset) const-
703{-
704 // QLineEdit doesn't have text attributes-
705 *startOffset = *endOffset = offset;-
706 return QString();-
707}-
708-
709int QAccessibleLineEdit::cursorPosition() const-
710{-
711 return lineEdit()->cursorPosition();-
712}-
713-
714QRect 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-
730int QAccessibleLineEdit::selectionCount() const-
731{-
732 return lineEdit()->hasSelectedText() ? 1 : 0;-
733}-
734-
735int QAccessibleLineEdit::offsetAtPoint(const QPoint &point) const-
736{-
737 QPoint p = lineEdit()->mapFromGlobal(point);-
738-
739 return lineEdit()->cursorPositionAt(p);-
740}-
741-
742void 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-
752QString 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-
763QString 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-
775QString 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-
787QString 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-
799void QAccessibleLineEdit::removeSelection(int selectionIndex)-
800{-
801 if (selectionIndex != 0)-
802 return;-
803-
804 lineEdit()->deselect();-
805}-
806-
807void QAccessibleLineEdit::setCursorPosition(int position)-
808{-
809 lineEdit()->setCursorPosition(position);-
810}-
811-
812void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int endOffset)-
813{-
814 if (selectionIndex != 0)-
815 return;-
816-
817 lineEdit()->setSelection(startOffset, endOffset - startOffset);-
818}-
819-
820int QAccessibleLineEdit::characterCount() const-
821{-
822 return lineEdit()->text().count();-
823}-
824-
825void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex)-
826{-
827 lineEdit()->setCursorPosition(endIndex);-
828 lineEdit()->setCursorPosition(startIndex);-
829}-
830-
831void QAccessibleLineEdit::deleteText(int startOffset, int endOffset)-
832{-
833 lineEdit()->setText(lineEdit()->text().remove(startOffset, endOffset - startOffset));-
834}-
835-
836void QAccessibleLineEdit::insertText(int offset, const QString &text)-
837{-
838 lineEdit()->setText(lineEdit()->text().insert(offset, text));-
839}-
840-
841void 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-
849QAccessibleProgressBar::QAccessibleProgressBar(QWidget *o)-
850 : QAccessibleDisplay(o)-
851{-
852 Q_ASSERT(progressBar());-
853}-
854-
855void *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-
862QVariant QAccessibleProgressBar::currentValue() const-
863{-
864 return progressBar()->value();-
865}-
866-
867QVariant QAccessibleProgressBar::maximumValue() const-
868{-
869 return progressBar()->maximum();-
870}-
871-
872QVariant QAccessibleProgressBar::minimumValue() const-
873{-
874 return progressBar()->minimum();-
875}-
876-
877QVariant QAccessibleProgressBar::minimumStepSize() const-
878{-
879 // This is arbitrary since any value between min and max is valid.-
880 // Some screen readers (orca use it to calculate how many digits to display though,-
881 // so it makes sense to return a "sensible" value. Providing 100 increments seems ok.-
882 return (progressBar()->maximum() - progressBar()->minimum()) / 100.0;-
883}-
884-
885QProgressBar *QAccessibleProgressBar::progressBar() const-
886{-
887 return qobject_cast<QProgressBar *>(object());-
888}-
889#endif-
890-
891-
892QAccessibleWindowContainer::QAccessibleWindowContainer(QWidget *w)-
893 : QAccessibleWidget(w)-
894{-
895}-
896-
897int QAccessibleWindowContainer::childCount() const-
898{-
899 if (container()->containedWindow())-
900 return 1;-
901 return 0;-
902}-
903-
904int QAccessibleWindowContainer::indexOfChild(const QAccessibleInterface *child) const-
905{-
906 if (child->object() == container()->containedWindow())-
907 return 0;-
908 return -1;-
909}-
910-
911QAccessibleInterface *QAccessibleWindowContainer::child(int i) const-
912{-
913 if (i == 0)-
914 return QAccessible::queryAccessibleInterface(container()->containedWindow());-
915 return 0;-
916}-
917-
918QWindowContainer *QAccessibleWindowContainer::container() const-
919{-
920 return static_cast<QWindowContainer *>(widget());-
921}-
922-
923#endif // QT_NO_ACCESSIBILITY-
924-
925QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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