1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the plugins of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "simplewidgets.h"
|
---|
43 |
|
---|
44 | #include <qabstractbutton.h>
|
---|
45 | #include <qcheckbox.h>
|
---|
46 | #include <qpushbutton.h>
|
---|
47 | #include <qprogressbar.h>
|
---|
48 | #include <qradiobutton.h>
|
---|
49 | #include <qtoolbutton.h>
|
---|
50 | #include <qlabel.h>
|
---|
51 | #include <qgroupbox.h>
|
---|
52 | #include <qlcdnumber.h>
|
---|
53 | #include <qlineedit.h>
|
---|
54 | #include <qstyle.h>
|
---|
55 | #include <qstyleoption.h>
|
---|
56 |
|
---|
57 | #ifdef Q_OS_MAC
|
---|
58 | #include <qfocusframe.h>
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | QT_BEGIN_NAMESPACE
|
---|
62 |
|
---|
63 | #ifndef QT_NO_ACCESSIBILITY
|
---|
64 |
|
---|
65 | using namespace QAccessible2;
|
---|
66 | extern QList<QWidget*> childWidgets(const QWidget *widget, bool includeTopLevel = false);
|
---|
67 |
|
---|
68 | QString Q_GUI_EXPORT qt_accStripAmp(const QString &text);
|
---|
69 | QString Q_GUI_EXPORT qt_accHotKey(const QString &text);
|
---|
70 |
|
---|
71 | /*!
|
---|
72 | \class QAccessibleButton
|
---|
73 | \brief The QAccessibleButton class implements the QAccessibleInterface for button type widgets.
|
---|
74 | \internal
|
---|
75 |
|
---|
76 | \ingroup accessibility
|
---|
77 | */
|
---|
78 |
|
---|
79 | /*!
|
---|
80 | Creates a QAccessibleButton object for \a w.
|
---|
81 | \a role is propagated to the QAccessibleWidgetEx constructor.
|
---|
82 | */
|
---|
83 | QAccessibleButton::QAccessibleButton(QWidget *w, Role role)
|
---|
84 | : QAccessibleWidgetEx(w, role)
|
---|
85 | {
|
---|
86 | Q_ASSERT(button());
|
---|
87 | if (button()->isCheckable())
|
---|
88 | addControllingSignal(QLatin1String("toggled(bool)"));
|
---|
89 | else
|
---|
90 | addControllingSignal(QLatin1String("clicked()"));
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*! Returns the button. */
|
---|
94 | QAbstractButton *QAccessibleButton::button() const
|
---|
95 | {
|
---|
96 | return qobject_cast<QAbstractButton*>(object());
|
---|
97 | }
|
---|
98 |
|
---|
99 | /*! \reimp */
|
---|
100 | QString QAccessibleButton::actionText(int action, Text text, int child) const
|
---|
101 | {
|
---|
102 | if (child)
|
---|
103 | return QString();
|
---|
104 |
|
---|
105 | if (text == Name) switch (action) {
|
---|
106 | case Press:
|
---|
107 | case DefaultAction: // press, checking or open
|
---|
108 | switch (role(0)) {
|
---|
109 | case ButtonMenu:
|
---|
110 | return QPushButton::tr("Open");
|
---|
111 | case CheckBox:
|
---|
112 | {
|
---|
113 | if (state(child) & Checked)
|
---|
114 | return QCheckBox::tr("Uncheck");
|
---|
115 | QCheckBox *cb = qobject_cast<QCheckBox*>(object());
|
---|
116 | if (!cb || !cb->isTristate() || cb->checkState() == Qt::PartiallyChecked)
|
---|
117 | return QCheckBox::tr("Check");
|
---|
118 | return QCheckBox::tr("Toggle");
|
---|
119 | }
|
---|
120 | break;
|
---|
121 | case RadioButton:
|
---|
122 | return QRadioButton::tr("Check");
|
---|
123 | default:
|
---|
124 | break;
|
---|
125 | }
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | return QAccessibleWidgetEx::actionText(action, text, child);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /*! \reimp */
|
---|
132 | bool QAccessibleButton::doAction(int action, int child, const QVariantList ¶ms)
|
---|
133 | {
|
---|
134 | if (child || !widget()->isEnabled() || !widget()->isVisible())
|
---|
135 | return false;
|
---|
136 |
|
---|
137 | switch (action) {
|
---|
138 | case DefaultAction:
|
---|
139 | case Press:
|
---|
140 | {
|
---|
141 | #ifndef QT_NO_MENU
|
---|
142 | QPushButton *pb = qobject_cast<QPushButton*>(object());
|
---|
143 | if (pb && pb->menu())
|
---|
144 | pb->showMenu();
|
---|
145 | else
|
---|
146 | #endif
|
---|
147 | button()->animateClick();
|
---|
148 | }
|
---|
149 | return true;
|
---|
150 | }
|
---|
151 | return QAccessibleWidgetEx::doAction(action, child, params);
|
---|
152 | }
|
---|
153 |
|
---|
154 | /*! \reimp */
|
---|
155 | QString QAccessibleButton::text(Text t, int child) const
|
---|
156 | {
|
---|
157 | QString str;
|
---|
158 | if (!widget()->isVisible())
|
---|
159 | return str;
|
---|
160 |
|
---|
161 | switch (t) {
|
---|
162 | case Accelerator:
|
---|
163 | {
|
---|
164 | #ifndef QT_NO_SHORTCUT
|
---|
165 | QPushButton *pb = qobject_cast<QPushButton*>(object());
|
---|
166 | if (pb && pb->isDefault())
|
---|
167 | str = (QString)QKeySequence(Qt::Key_Enter);
|
---|
168 | #endif
|
---|
169 | if (str.isEmpty())
|
---|
170 | str = qt_accHotKey(button()->text());
|
---|
171 | }
|
---|
172 | break;
|
---|
173 | case Name:
|
---|
174 | str = widget()->accessibleName();
|
---|
175 | if (str.isEmpty())
|
---|
176 | str = button()->text();
|
---|
177 | break;
|
---|
178 | default:
|
---|
179 | break;
|
---|
180 | }
|
---|
181 | if (str.isEmpty())
|
---|
182 | str = QAccessibleWidgetEx::text(t, child);;
|
---|
183 | return qt_accStripAmp(str);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*! \reimp */
|
---|
187 | QAccessible::State QAccessibleButton::state(int child) const
|
---|
188 | {
|
---|
189 | State state = QAccessibleWidgetEx::state(child);
|
---|
190 |
|
---|
191 | QAbstractButton *b = button();
|
---|
192 | QCheckBox *cb = qobject_cast<QCheckBox *>(b);
|
---|
193 | if (b->isChecked())
|
---|
194 | state |= Checked;
|
---|
195 | else if (cb && cb->checkState() == Qt::PartiallyChecked)
|
---|
196 | state |= Mixed;
|
---|
197 | if (b->isDown())
|
---|
198 | state |= Pressed;
|
---|
199 | QPushButton *pb = qobject_cast<QPushButton*>(b);
|
---|
200 | if (pb) {
|
---|
201 | if (pb->isDefault())
|
---|
202 | state |= DefaultButton;
|
---|
203 | #ifndef QT_NO_MENU
|
---|
204 | if (pb->menu())
|
---|
205 | state |= HasPopup;
|
---|
206 | #endif
|
---|
207 | }
|
---|
208 |
|
---|
209 | return state;
|
---|
210 | }
|
---|
211 |
|
---|
212 | int QAccessibleButton::actionCount()
|
---|
213 | {
|
---|
214 | return 1;
|
---|
215 | }
|
---|
216 |
|
---|
217 | void QAccessibleButton::doAction(int actionIndex)
|
---|
218 | {
|
---|
219 | switch (actionIndex) {
|
---|
220 | case 0:
|
---|
221 | button()->click();
|
---|
222 | break;
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | QString QAccessibleButton::description(int actionIndex)
|
---|
227 | {
|
---|
228 | switch (actionIndex) {
|
---|
229 | case 0:
|
---|
230 | return QLatin1String("Clicks the button.");
|
---|
231 | default:
|
---|
232 | return QString();
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | QString QAccessibleButton::name(int actionIndex)
|
---|
237 | {
|
---|
238 | switch (actionIndex) {
|
---|
239 | case 0:
|
---|
240 | return QLatin1String("Press");
|
---|
241 | default:
|
---|
242 | return QString();
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | QString QAccessibleButton::localizedName(int actionIndex)
|
---|
247 | {
|
---|
248 | switch (actionIndex) {
|
---|
249 | case 0:
|
---|
250 | return tr("Press");
|
---|
251 | default:
|
---|
252 | return QString();
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | QStringList QAccessibleButton::keyBindings(int actionIndex)
|
---|
257 | {
|
---|
258 | switch (actionIndex) {
|
---|
259 | #ifndef QT_NO_SHORTCUT
|
---|
260 | case 0:
|
---|
261 | return QStringList() << button()->shortcut().toString();
|
---|
262 | #endif
|
---|
263 | default:
|
---|
264 | return QStringList();
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | #ifndef QT_NO_TOOLBUTTON
|
---|
269 | /*!
|
---|
270 | \class QAccessibleToolButton
|
---|
271 | \brief The QAccessibleToolButton class implements the QAccessibleInterface for tool buttons.
|
---|
272 | \internal
|
---|
273 |
|
---|
274 | \ingroup accessibility
|
---|
275 | */
|
---|
276 |
|
---|
277 | /*!
|
---|
278 | \enum QAccessibleToolButton::ToolButtonElements
|
---|
279 |
|
---|
280 | This enum identifies the components of the tool button.
|
---|
281 |
|
---|
282 | \value ToolButtonSelf The tool button as a whole.
|
---|
283 | \value ButtonExecute The button.
|
---|
284 | \value ButtonDropMenu The drop down menu.
|
---|
285 | */
|
---|
286 |
|
---|
287 | /*!
|
---|
288 | Creates a QAccessibleToolButton object for \a w.
|
---|
289 | \a role is propagated to the QAccessibleWidgetEx constructor.
|
---|
290 | */
|
---|
291 | QAccessibleToolButton::QAccessibleToolButton(QWidget *w, Role role)
|
---|
292 | : QAccessibleButton(w, role)
|
---|
293 | {
|
---|
294 | Q_ASSERT(toolButton());
|
---|
295 | }
|
---|
296 |
|
---|
297 | /*! Returns the button. */
|
---|
298 | QToolButton *QAccessibleToolButton::toolButton() const
|
---|
299 | {
|
---|
300 | return qobject_cast<QToolButton*>(object());
|
---|
301 | }
|
---|
302 |
|
---|
303 | /*!
|
---|
304 | Returns true if this tool button is a split button.
|
---|
305 | */
|
---|
306 | bool QAccessibleToolButton::isSplitButton() const
|
---|
307 | {
|
---|
308 | #ifndef QT_NO_MENU
|
---|
309 | return toolButton()->menu() && toolButton()->popupMode() == QToolButton::MenuButtonPopup;
|
---|
310 | #else
|
---|
311 | return false;
|
---|
312 | #endif
|
---|
313 | }
|
---|
314 |
|
---|
315 | /*! \reimp */
|
---|
316 | QAccessible::Role QAccessibleToolButton::role(int child) const
|
---|
317 | {
|
---|
318 | if (isSplitButton()) switch(child) {
|
---|
319 | case ButtonExecute:
|
---|
320 | return PushButton;
|
---|
321 | case ButtonDropMenu:
|
---|
322 | return ButtonMenu;
|
---|
323 | }
|
---|
324 | return QAccessibleButton::role(child);
|
---|
325 | }
|
---|
326 |
|
---|
327 | /*! \reimp */
|
---|
328 | QAccessible::State QAccessibleToolButton::state(int child) const
|
---|
329 | {
|
---|
330 | QAccessible::State st = QAccessibleButton::state(child);
|
---|
331 | if (toolButton()->autoRaise())
|
---|
332 | st |= HotTracked;
|
---|
333 | #ifndef QT_NO_MENU
|
---|
334 | if (toolButton()->menu() && child != ButtonExecute)
|
---|
335 | st |= HasPopup;
|
---|
336 | #endif
|
---|
337 | return st;
|
---|
338 | }
|
---|
339 |
|
---|
340 | /*! \reimp */
|
---|
341 | int QAccessibleToolButton::childCount() const
|
---|
342 | {
|
---|
343 | if (!toolButton()->isVisible())
|
---|
344 | return 0;
|
---|
345 | return isSplitButton() ? ButtonDropMenu : 0;
|
---|
346 | }
|
---|
347 |
|
---|
348 | /*!
|
---|
349 | \internal
|
---|
350 |
|
---|
351 | Returns the rectangle occupied by this button, depending on \a
|
---|
352 | child.
|
---|
353 | */
|
---|
354 | QRect QAccessibleToolButton::rect(int child) const
|
---|
355 | {
|
---|
356 | if (!toolButton()->isVisible())
|
---|
357 | return QRect();
|
---|
358 | if (!child)
|
---|
359 | return QAccessibleButton::rect(child);
|
---|
360 |
|
---|
361 | QStyleOptionToolButton opt;
|
---|
362 | opt.init(widget());
|
---|
363 | QRect subrect = widget()->style()->subControlRect(QStyle::CC_ToolButton, &opt,
|
---|
364 | QStyle::SC_ToolButtonMenu, toolButton());
|
---|
365 |
|
---|
366 | if (child == ButtonExecute)
|
---|
367 | subrect = QRect(0, 0, subrect.x(), widget()->height());
|
---|
368 |
|
---|
369 | QPoint ntl = widget()->mapToGlobal(subrect.topLeft());
|
---|
370 | subrect.moveTopLeft(ntl);
|
---|
371 | return subrect;
|
---|
372 | }
|
---|
373 |
|
---|
374 | /*!
|
---|
375 | \internal
|
---|
376 |
|
---|
377 | Returns the button's text label, depending on the text \a t, and
|
---|
378 | the \a child.
|
---|
379 | */
|
---|
380 | QString QAccessibleToolButton::text(Text t, int child) const
|
---|
381 | {
|
---|
382 | QString str;
|
---|
383 | if (!toolButton()->isVisible())
|
---|
384 | return str;
|
---|
385 |
|
---|
386 | switch (t) {
|
---|
387 | case Name:
|
---|
388 | str = toolButton()->text();
|
---|
389 | if (str.isEmpty())
|
---|
390 | str = toolButton()->text();
|
---|
391 | break;
|
---|
392 | default:
|
---|
393 | break;
|
---|
394 | }
|
---|
395 | if (str.isEmpty())
|
---|
396 | str = QAccessibleButton::text(t, child);;
|
---|
397 | return qt_accStripAmp(str);
|
---|
398 | }
|
---|
399 |
|
---|
400 | /*!
|
---|
401 | \internal
|
---|
402 |
|
---|
403 | Returns the number of actions which is 0, 1, or 2, in part
|
---|
404 | depending on \a child.
|
---|
405 | */
|
---|
406 | int QAccessibleToolButton::actionCount(int child) const
|
---|
407 | {
|
---|
408 | // each subelement has one action
|
---|
409 | if (child)
|
---|
410 | return isSplitButton() ? 1 : 0;
|
---|
411 | int ac = widget()->focusPolicy() != Qt::NoFocus ? 1 : 0;
|
---|
412 | // button itself has two actions if a menu button
|
---|
413 | #ifndef QT_NO_MENU
|
---|
414 | return ac + (toolButton()->menu() ? 2 : 1);
|
---|
415 | #else
|
---|
416 | return ac + 1;
|
---|
417 | #endif
|
---|
418 | }
|
---|
419 |
|
---|
420 | /*!
|
---|
421 | \internal
|
---|
422 |
|
---|
423 | If \a text is \c Name, then depending on the \a child or the \a
|
---|
424 | action, an action text is returned. This is a translated string
|
---|
425 | which in English is one of "Press", "Open", or "Set Focus". If \a
|
---|
426 | text is not \c Name, an empty string is returned.
|
---|
427 | */
|
---|
428 | QString QAccessibleToolButton::actionText(int action, Text text, int child) const
|
---|
429 | {
|
---|
430 | if (text == Name) switch(child) {
|
---|
431 | case ButtonExecute:
|
---|
432 | return QToolButton::tr("Press");
|
---|
433 | case ButtonDropMenu:
|
---|
434 | return QToolButton::tr("Open");
|
---|
435 | default:
|
---|
436 | switch(action) {
|
---|
437 | case 0:
|
---|
438 | return QToolButton::tr("Press");
|
---|
439 | case 1:
|
---|
440 | #ifndef QT_NO_MENU
|
---|
441 | if (toolButton()->menu())
|
---|
442 | return QToolButton::tr("Open");
|
---|
443 | #endif
|
---|
444 | //fall through
|
---|
445 | case 2:
|
---|
446 | return QLatin1String("Set Focus");
|
---|
447 | }
|
---|
448 | }
|
---|
449 | return QString();
|
---|
450 | }
|
---|
451 |
|
---|
452 | /*!
|
---|
453 | \internal
|
---|
454 | */
|
---|
455 | bool QAccessibleToolButton::doAction(int action, int child, const QVariantList ¶ms)
|
---|
456 | {
|
---|
457 | if (!widget()->isEnabled() || !widget()->isVisible())
|
---|
458 | return false;
|
---|
459 | if (action == 1 || child == ButtonDropMenu) {
|
---|
460 | if(!child)
|
---|
461 | toolButton()->setDown(true);
|
---|
462 | #ifndef QT_NO_MENU
|
---|
463 | toolButton()->showMenu();
|
---|
464 | #endif
|
---|
465 | return true;
|
---|
466 | }
|
---|
467 | return QAccessibleButton::doAction(action, 0, params);
|
---|
468 | }
|
---|
469 |
|
---|
470 | #endif // QT_NO_TOOLBUTTON
|
---|
471 |
|
---|
472 | /*!
|
---|
473 | \class QAccessibleDisplay
|
---|
474 | \brief The QAccessibleDisplay class implements the QAccessibleInterface for widgets that display information.
|
---|
475 | \internal
|
---|
476 |
|
---|
477 | \ingroup accessibility
|
---|
478 | */
|
---|
479 |
|
---|
480 | /*!
|
---|
481 | Constructs a QAccessibleDisplay object for \a w.
|
---|
482 | \a role is propagated to the QAccessibleWidgetEx constructor.
|
---|
483 | */
|
---|
484 | QAccessibleDisplay::QAccessibleDisplay(QWidget *w, Role role)
|
---|
485 | : QAccessibleWidgetEx(w, role)
|
---|
486 | {
|
---|
487 | }
|
---|
488 |
|
---|
489 | /*! \reimp */
|
---|
490 | QAccessible::Role QAccessibleDisplay::role(int child) const
|
---|
491 | {
|
---|
492 | QLabel *l = qobject_cast<QLabel*>(object());
|
---|
493 | if (l) {
|
---|
494 | if (l->pixmap())
|
---|
495 | return Graphic;
|
---|
496 | #ifndef QT_NO_PICTURE
|
---|
497 | if (l->picture())
|
---|
498 | return Graphic;
|
---|
499 | #endif
|
---|
500 | #ifndef QT_NO_MOVIE
|
---|
501 | if (l->movie())
|
---|
502 | return Animation;
|
---|
503 | #endif
|
---|
504 | #ifndef QT_NO_PROGRESSBAR
|
---|
505 | } else if (qobject_cast<QProgressBar*>(object())) {
|
---|
506 | return ProgressBar;
|
---|
507 | #endif
|
---|
508 | }
|
---|
509 | return QAccessibleWidgetEx::role(child);
|
---|
510 | }
|
---|
511 |
|
---|
512 | /*! \reimp */
|
---|
513 | QString QAccessibleDisplay::text(Text t, int child) const
|
---|
514 | {
|
---|
515 | QString str;
|
---|
516 | if (!widget()->isVisible())
|
---|
517 | return str;
|
---|
518 | switch (t) {
|
---|
519 | case Name:
|
---|
520 | str = widget()->accessibleName();
|
---|
521 | if (str.isEmpty()) {
|
---|
522 | if (qobject_cast<QLabel*>(object())) {
|
---|
523 | str = qobject_cast<QLabel*>(object())->text();
|
---|
524 | #ifndef QT_NO_GROUPBOX
|
---|
525 | } else if (qobject_cast<QGroupBox*>(object())) {
|
---|
526 | str = qobject_cast<QGroupBox*>(object())->title();
|
---|
527 | #endif
|
---|
528 | #ifndef QT_NO_LCDNUMBER
|
---|
529 | } else if (qobject_cast<QLCDNumber*>(object())) {
|
---|
530 | QLCDNumber *l = qobject_cast<QLCDNumber*>(object());
|
---|
531 | if (l->digitCount())
|
---|
532 | str = QString::number(l->value());
|
---|
533 | else
|
---|
534 | str = QString::number(l->intValue());
|
---|
535 | #endif
|
---|
536 | }
|
---|
537 | }
|
---|
538 | break;
|
---|
539 | case Value:
|
---|
540 | #ifndef QT_NO_PROGRESSBAR
|
---|
541 | if (qobject_cast<QProgressBar*>(object()))
|
---|
542 | str = QString::number(qobject_cast<QProgressBar*>(object())->value());
|
---|
543 | #endif
|
---|
544 | break;
|
---|
545 | default:
|
---|
546 | break;
|
---|
547 | }
|
---|
548 | if (str.isEmpty())
|
---|
549 | str = QAccessibleWidgetEx::text(t, child);;
|
---|
550 | return qt_accStripAmp(str);
|
---|
551 | }
|
---|
552 |
|
---|
553 | /*! \reimp */
|
---|
554 | QAccessible::Relation QAccessibleDisplay::relationTo(int child, const QAccessibleInterface *other,
|
---|
555 | int otherChild) const
|
---|
556 | {
|
---|
557 | Relation relation = QAccessibleWidgetEx::relationTo(child, other, otherChild);
|
---|
558 | if (child || otherChild)
|
---|
559 | return relation;
|
---|
560 |
|
---|
561 | QObject *o = other->object();
|
---|
562 | QLabel *label = qobject_cast<QLabel*>(object());
|
---|
563 | if (label) {
|
---|
564 | #ifndef QT_NO_SHORTCUT
|
---|
565 | if (o == label->buddy())
|
---|
566 | relation |= Label;
|
---|
567 | #endif
|
---|
568 | #ifndef QT_NO_GROUPBOX
|
---|
569 | } else {
|
---|
570 | QGroupBox *groupbox = qobject_cast<QGroupBox*>(object());
|
---|
571 | if (groupbox && !groupbox->title().isEmpty())
|
---|
572 | if (groupbox->children().contains(o))
|
---|
573 | relation |= Label;
|
---|
574 | #endif
|
---|
575 | }
|
---|
576 | return relation;
|
---|
577 | }
|
---|
578 |
|
---|
579 | /*! \reimp */
|
---|
580 | int QAccessibleDisplay::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
|
---|
581 | {
|
---|
582 | *target = 0;
|
---|
583 | if (rel == Labelled) {
|
---|
584 | QObject *targetObject = 0;
|
---|
585 | QLabel *label = qobject_cast<QLabel*>(object());
|
---|
586 | if (label) {
|
---|
587 | #ifndef QT_NO_SHORTCUT
|
---|
588 | if (entry == 1)
|
---|
589 | targetObject = label->buddy();
|
---|
590 | #endif
|
---|
591 | #ifndef QT_NO_GROUPBOX
|
---|
592 | } else {
|
---|
593 | QGroupBox *groupbox = qobject_cast<QGroupBox*>(object());
|
---|
594 | if (groupbox && !groupbox->title().isEmpty())
|
---|
595 | rel = Child;
|
---|
596 | #endif
|
---|
597 | }
|
---|
598 | *target = QAccessible::queryAccessibleInterface(targetObject);
|
---|
599 | if (*target)
|
---|
600 | return 0;
|
---|
601 | }
|
---|
602 | return QAccessibleWidgetEx::navigate(rel, entry, target);
|
---|
603 | }
|
---|
604 |
|
---|
605 | /*! \reimp */
|
---|
606 | QString QAccessibleDisplay::imageDescription()
|
---|
607 | {
|
---|
608 | return widget()->toolTip();
|
---|
609 | }
|
---|
610 |
|
---|
611 | /*! \reimp */
|
---|
612 | QSize QAccessibleDisplay::imageSize()
|
---|
613 | {
|
---|
614 | QLabel *label = qobject_cast<QLabel *>(widget());
|
---|
615 | if (!label)
|
---|
616 | return QSize();
|
---|
617 | const QPixmap *pixmap = label->pixmap();
|
---|
618 | if (!pixmap)
|
---|
619 | return QSize();
|
---|
620 | return pixmap->size();
|
---|
621 | }
|
---|
622 |
|
---|
623 | /*! \reimp */
|
---|
624 | QRect QAccessibleDisplay::imagePosition(QAccessible2::CoordinateType coordType)
|
---|
625 | {
|
---|
626 | QLabel *label = qobject_cast<QLabel *>(widget());
|
---|
627 | if (!label)
|
---|
628 | return QRect();
|
---|
629 | const QPixmap *pixmap = label->pixmap();
|
---|
630 | if (!pixmap)
|
---|
631 | return QRect();
|
---|
632 |
|
---|
633 | switch (coordType) {
|
---|
634 | case QAccessible2::RelativeToScreen:
|
---|
635 | return QRect(label->mapToGlobal(label->pos()), label->size());
|
---|
636 | case QAccessible2::RelativeToParent:
|
---|
637 | return label->geometry();
|
---|
638 | }
|
---|
639 |
|
---|
640 | return QRect();
|
---|
641 | }
|
---|
642 |
|
---|
643 | #ifndef QT_NO_LINEEDIT
|
---|
644 | /*!
|
---|
645 | \class QAccessibleLineEdit
|
---|
646 | \brief The QAccessibleLineEdit class implements the QAccessibleInterface for widgets with editable text
|
---|
647 | \internal
|
---|
648 |
|
---|
649 | \ingroup accessibility
|
---|
650 | */
|
---|
651 |
|
---|
652 | /*!
|
---|
653 | Constructs a QAccessibleLineEdit object for \a w.
|
---|
654 | \a name is propagated to the QAccessibleWidgetEx constructor.
|
---|
655 | */
|
---|
656 | QAccessibleLineEdit::QAccessibleLineEdit(QWidget *w, const QString &name)
|
---|
657 | : QAccessibleWidgetEx(w, EditableText, name), QAccessibleSimpleEditableTextInterface(this)
|
---|
658 | {
|
---|
659 | addControllingSignal(QLatin1String("textChanged(const QString&)"));
|
---|
660 | addControllingSignal(QLatin1String("returnPressed()"));
|
---|
661 | }
|
---|
662 |
|
---|
663 | /*! Returns the line edit. */
|
---|
664 | QLineEdit *QAccessibleLineEdit::lineEdit() const
|
---|
665 | {
|
---|
666 | return qobject_cast<QLineEdit*>(object());
|
---|
667 | }
|
---|
668 |
|
---|
669 | /*! \reimp */
|
---|
670 | QString QAccessibleLineEdit::text(Text t, int child) const
|
---|
671 | {
|
---|
672 | QString str;
|
---|
673 | if (!lineEdit()->isVisible())
|
---|
674 | return str;
|
---|
675 | switch (t) {
|
---|
676 | case Value:
|
---|
677 | if (lineEdit()->echoMode() == QLineEdit::Normal)
|
---|
678 | str = lineEdit()->text();
|
---|
679 | break;
|
---|
680 | default:
|
---|
681 | break;
|
---|
682 | }
|
---|
683 | if (str.isEmpty())
|
---|
684 | str = QAccessibleWidgetEx::text(t, child);;
|
---|
685 | return qt_accStripAmp(str);
|
---|
686 | }
|
---|
687 |
|
---|
688 | /*! \reimp */
|
---|
689 | void QAccessibleLineEdit::setText(Text t, int control, const QString &text)
|
---|
690 | {
|
---|
691 | if (!lineEdit()->isVisible())
|
---|
692 | return;
|
---|
693 | if (t != Value || control) {
|
---|
694 | QAccessibleWidgetEx::setText(t, control, text);
|
---|
695 | return;
|
---|
696 | }
|
---|
697 | lineEdit()->setText(text);
|
---|
698 | }
|
---|
699 |
|
---|
700 | /*! \reimp */
|
---|
701 | QAccessible::State QAccessibleLineEdit::state(int child) const
|
---|
702 | {
|
---|
703 | State state = QAccessibleWidgetEx::state(child);
|
---|
704 |
|
---|
705 | QLineEdit *l = lineEdit();
|
---|
706 | if (l->isReadOnly())
|
---|
707 | state |= ReadOnly;
|
---|
708 | if (l->echoMode() != QLineEdit::Normal)
|
---|
709 | state |= Protected;
|
---|
710 | state |= Selectable;
|
---|
711 | if (l->hasSelectedText())
|
---|
712 | state |= Selected;
|
---|
713 |
|
---|
714 | if (l->contextMenuPolicy() != Qt::NoContextMenu
|
---|
715 | && l->contextMenuPolicy() != Qt::PreventContextMenu)
|
---|
716 | state |= HasPopup;
|
---|
717 |
|
---|
718 | return state;
|
---|
719 | }
|
---|
720 |
|
---|
721 | QVariant QAccessibleLineEdit::invokeMethodEx(QAccessible::Method method, int child,
|
---|
722 | const QVariantList ¶ms)
|
---|
723 | {
|
---|
724 | if (child)
|
---|
725 | return QVariant();
|
---|
726 |
|
---|
727 | switch (method) {
|
---|
728 | case ListSupportedMethods: {
|
---|
729 | QSet<QAccessible::Method> set;
|
---|
730 | set << ListSupportedMethods << SetCursorPosition << GetCursorPosition;
|
---|
731 | return qVariantFromValue(set | qvariant_cast<QSet<QAccessible::Method> >(
|
---|
732 | QAccessibleWidgetEx::invokeMethodEx(method, child, params)));
|
---|
733 | }
|
---|
734 | case SetCursorPosition:
|
---|
735 | setCursorPosition(params.value(0).toInt());
|
---|
736 | return true;
|
---|
737 | case GetCursorPosition:
|
---|
738 | return cursorPosition();
|
---|
739 | default:
|
---|
740 | return QAccessibleWidgetEx::invokeMethodEx(method, child, params);
|
---|
741 | }
|
---|
742 | }
|
---|
743 |
|
---|
744 | void QAccessibleLineEdit::addSelection(int startOffset, int endOffset)
|
---|
745 | {
|
---|
746 | setSelection(0, startOffset, endOffset);
|
---|
747 | }
|
---|
748 |
|
---|
749 | QString QAccessibleLineEdit::attributes(int offset, int *startOffset, int *endOffset)
|
---|
750 | {
|
---|
751 | // QLineEdit doesn't have text attributes
|
---|
752 | *startOffset = *endOffset = offset;
|
---|
753 | return QString();
|
---|
754 | }
|
---|
755 |
|
---|
756 | int QAccessibleLineEdit::cursorPosition()
|
---|
757 | {
|
---|
758 | return lineEdit()->cursorPosition();
|
---|
759 | }
|
---|
760 |
|
---|
761 | QRect QAccessibleLineEdit::characterRect(int /*offset*/, CoordinateType /*coordType*/)
|
---|
762 | {
|
---|
763 | // QLineEdit doesn't hand out character rects
|
---|
764 | return QRect();
|
---|
765 | }
|
---|
766 |
|
---|
767 | int QAccessibleLineEdit::selectionCount()
|
---|
768 | {
|
---|
769 | return lineEdit()->hasSelectedText() ? 1 : 0;
|
---|
770 | }
|
---|
771 |
|
---|
772 | int QAccessibleLineEdit::offsetAtPoint(const QPoint &point, CoordinateType coordType)
|
---|
773 | {
|
---|
774 | QPoint p = point;
|
---|
775 | if (coordType == RelativeToScreen)
|
---|
776 | p = lineEdit()->mapFromGlobal(p);
|
---|
777 |
|
---|
778 | return lineEdit()->cursorPositionAt(p);
|
---|
779 | }
|
---|
780 |
|
---|
781 | void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *endOffset)
|
---|
782 | {
|
---|
783 | *startOffset = *endOffset = 0;
|
---|
784 | if (selectionIndex != 0)
|
---|
785 | return;
|
---|
786 |
|
---|
787 | *startOffset = lineEdit()->selectionStart();
|
---|
788 | *endOffset = *startOffset + lineEdit()->selectedText().count();
|
---|
789 | }
|
---|
790 |
|
---|
791 | QString QAccessibleLineEdit::text(int startOffset, int endOffset)
|
---|
792 | {
|
---|
793 | if (startOffset > endOffset)
|
---|
794 | return QString();
|
---|
795 | return lineEdit()->text().mid(startOffset, endOffset - startOffset);
|
---|
796 | }
|
---|
797 |
|
---|
798 | QString QAccessibleLineEdit::textBeforeOffset (int /*offset*/, BoundaryType /*boundaryType*/,
|
---|
799 | int * /*startOffset*/, int * /*endOffset*/)
|
---|
800 | {
|
---|
801 | // TODO
|
---|
802 | return QString();
|
---|
803 | }
|
---|
804 |
|
---|
805 | QString QAccessibleLineEdit::textAfterOffset(int /*offset*/, BoundaryType /*boundaryType*/,
|
---|
806 | int * /*startOffset*/, int * /*endOffset*/)
|
---|
807 | {
|
---|
808 | // TODO
|
---|
809 | return QString();
|
---|
810 | }
|
---|
811 |
|
---|
812 | QString QAccessibleLineEdit::textAtOffset(int /*offset*/, BoundaryType /*boundaryType*/,
|
---|
813 | int * /*startOffset*/, int * /*endOffset*/)
|
---|
814 | {
|
---|
815 | // TODO
|
---|
816 | return QString();
|
---|
817 | }
|
---|
818 |
|
---|
819 | void QAccessibleLineEdit::removeSelection(int selectionIndex)
|
---|
820 | {
|
---|
821 | if (selectionIndex != 0)
|
---|
822 | return;
|
---|
823 |
|
---|
824 | lineEdit()->deselect();
|
---|
825 | }
|
---|
826 |
|
---|
827 | void QAccessibleLineEdit::setCursorPosition(int position)
|
---|
828 | {
|
---|
829 | lineEdit()->setCursorPosition(position);
|
---|
830 | }
|
---|
831 |
|
---|
832 | void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int endOffset)
|
---|
833 | {
|
---|
834 | if (selectionIndex != 0)
|
---|
835 | return;
|
---|
836 |
|
---|
837 | lineEdit()->setSelection(startOffset, endOffset - startOffset);
|
---|
838 | }
|
---|
839 |
|
---|
840 | int QAccessibleLineEdit::characterCount()
|
---|
841 | {
|
---|
842 | return lineEdit()->text().count();
|
---|
843 | }
|
---|
844 |
|
---|
845 | void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex)
|
---|
846 | {
|
---|
847 | lineEdit()->setCursorPosition(endIndex);
|
---|
848 | lineEdit()->setCursorPosition(startIndex);
|
---|
849 | }
|
---|
850 |
|
---|
851 | #endif // QT_NO_LINEEDIT
|
---|
852 |
|
---|
853 | #ifndef QT_NO_PROGRESSBAR
|
---|
854 | QAccessibleProgressBar::QAccessibleProgressBar(QWidget *o)
|
---|
855 | : QAccessibleDisplay(o)
|
---|
856 | {
|
---|
857 | Q_ASSERT(progressBar());
|
---|
858 | }
|
---|
859 |
|
---|
860 | QVariant QAccessibleProgressBar::currentValue()
|
---|
861 | {
|
---|
862 | return progressBar()->value();
|
---|
863 | }
|
---|
864 |
|
---|
865 | QVariant QAccessibleProgressBar::maximumValue()
|
---|
866 | {
|
---|
867 | return progressBar()->maximum();
|
---|
868 | }
|
---|
869 |
|
---|
870 | QVariant QAccessibleProgressBar::minimumValue()
|
---|
871 | {
|
---|
872 | return progressBar()->minimum();
|
---|
873 | }
|
---|
874 |
|
---|
875 | QProgressBar *QAccessibleProgressBar::progressBar() const
|
---|
876 | {
|
---|
877 | return qobject_cast<QProgressBar *>(object());
|
---|
878 | }
|
---|
879 | #endif
|
---|
880 |
|
---|
881 | #endif // QT_NO_ACCESSIBILITY
|
---|
882 |
|
---|
883 | QT_END_NAMESPACE
|
---|
884 |
|
---|