0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the plugins of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 |
#ifdef QT_NO_SHORTCUT
|
|
260 |
case 0:
|
|
261 |
return 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->numDigits())
|
|
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 |
#ifndef QT_NO_LINEEDIT
|
|
606 |
/*!
|
|
607 |
\class QAccessibleLineEdit
|
|
608 |
\brief The QAccessibleLineEdit class implements the QAccessibleInterface for widgets with editable text
|
|
609 |
\internal
|
|
610 |
|
|
611 |
\ingroup accessibility
|
|
612 |
*/
|
|
613 |
|
|
614 |
/*!
|
|
615 |
Constructs a QAccessibleLineEdit object for \a w.
|
|
616 |
\a name is propagated to the QAccessibleWidgetEx constructor.
|
|
617 |
*/
|
|
618 |
QAccessibleLineEdit::QAccessibleLineEdit(QWidget *w, const QString &name)
|
|
619 |
: QAccessibleWidgetEx(w, EditableText, name), QAccessibleSimpleEditableTextInterface(this)
|
|
620 |
{
|
|
621 |
addControllingSignal(QLatin1String("textChanged(const QString&)"));
|
|
622 |
addControllingSignal(QLatin1String("returnPressed()"));
|
|
623 |
}
|
|
624 |
|
|
625 |
/*! Returns the line edit. */
|
|
626 |
QLineEdit *QAccessibleLineEdit::lineEdit() const
|
|
627 |
{
|
|
628 |
return qobject_cast<QLineEdit*>(object());
|
|
629 |
}
|
|
630 |
|
|
631 |
/*! \reimp */
|
|
632 |
QString QAccessibleLineEdit::text(Text t, int child) const
|
|
633 |
{
|
|
634 |
QString str;
|
|
635 |
if (!lineEdit()->isVisible())
|
|
636 |
return str;
|
|
637 |
switch (t) {
|
|
638 |
case Value:
|
|
639 |
if (lineEdit()->echoMode() == QLineEdit::Normal)
|
|
640 |
str = lineEdit()->text();
|
|
641 |
break;
|
|
642 |
default:
|
|
643 |
break;
|
|
644 |
}
|
|
645 |
if (str.isEmpty())
|
|
646 |
str = QAccessibleWidgetEx::text(t, child);;
|
|
647 |
return qt_accStripAmp(str);
|
|
648 |
}
|
|
649 |
|
|
650 |
/*! \reimp */
|
|
651 |
void QAccessibleLineEdit::setText(Text t, int control, const QString &text)
|
|
652 |
{
|
|
653 |
if (!lineEdit()->isVisible())
|
|
654 |
return;
|
|
655 |
if (t != Value || control) {
|
|
656 |
QAccessibleWidgetEx::setText(t, control, text);
|
|
657 |
return;
|
|
658 |
}
|
|
659 |
lineEdit()->setText(text);
|
|
660 |
}
|
|
661 |
|
|
662 |
/*! \reimp */
|
|
663 |
QAccessible::State QAccessibleLineEdit::state(int child) const
|
|
664 |
{
|
|
665 |
State state = QAccessibleWidgetEx::state(child);
|
|
666 |
|
|
667 |
QLineEdit *l = lineEdit();
|
|
668 |
if (l->isReadOnly())
|
|
669 |
state |= ReadOnly;
|
|
670 |
if (l->echoMode() != QLineEdit::Normal)
|
|
671 |
state |= Protected;
|
|
672 |
state |= Selectable;
|
|
673 |
if (l->hasSelectedText())
|
|
674 |
state |= Selected;
|
|
675 |
|
|
676 |
if (l->contextMenuPolicy() != Qt::NoContextMenu
|
|
677 |
&& l->contextMenuPolicy() != Qt::PreventContextMenu)
|
|
678 |
state |= HasPopup;
|
|
679 |
|
|
680 |
return state;
|
|
681 |
}
|
|
682 |
|
|
683 |
QVariant QAccessibleLineEdit::invokeMethodEx(QAccessible::Method method, int child,
|
|
684 |
const QVariantList ¶ms)
|
|
685 |
{
|
|
686 |
if (child)
|
|
687 |
return QVariant();
|
|
688 |
|
|
689 |
switch (method) {
|
|
690 |
case ListSupportedMethods: {
|
|
691 |
QSet<QAccessible::Method> set;
|
|
692 |
set << ListSupportedMethods << SetCursorPosition << GetCursorPosition;
|
|
693 |
return qVariantFromValue(set | qvariant_cast<QSet<QAccessible::Method> >(
|
|
694 |
QAccessibleWidgetEx::invokeMethodEx(method, child, params)));
|
|
695 |
}
|
|
696 |
case SetCursorPosition:
|
|
697 |
setCursorPosition(params.value(0).toInt());
|
|
698 |
return true;
|
|
699 |
case GetCursorPosition:
|
|
700 |
return cursorPosition();
|
|
701 |
default:
|
|
702 |
return QAccessibleWidgetEx::invokeMethodEx(method, child, params);
|
|
703 |
}
|
|
704 |
}
|
|
705 |
|
|
706 |
void QAccessibleLineEdit::addSelection(int startOffset, int endOffset)
|
|
707 |
{
|
|
708 |
setSelection(0, startOffset, endOffset);
|
|
709 |
}
|
|
710 |
|
|
711 |
QString QAccessibleLineEdit::attributes(int offset, int *startOffset, int *endOffset)
|
|
712 |
{
|
|
713 |
// QLineEdit doesn't have text attributes
|
|
714 |
*startOffset = *endOffset = offset;
|
|
715 |
return QString();
|
|
716 |
}
|
|
717 |
|
|
718 |
int QAccessibleLineEdit::cursorPosition()
|
|
719 |
{
|
|
720 |
return lineEdit()->cursorPosition();
|
|
721 |
}
|
|
722 |
|
|
723 |
QRect QAccessibleLineEdit::characterRect(int /*offset*/, CoordinateType /*coordType*/)
|
|
724 |
{
|
|
725 |
// QLineEdit doesn't hand out character rects
|
|
726 |
return QRect();
|
|
727 |
}
|
|
728 |
|
|
729 |
int QAccessibleLineEdit::selectionCount()
|
|
730 |
{
|
|
731 |
return lineEdit()->hasSelectedText() ? 1 : 0;
|
|
732 |
}
|
|
733 |
|
|
734 |
int QAccessibleLineEdit::offsetAtPoint(const QPoint &point, CoordinateType coordType)
|
|
735 |
{
|
|
736 |
QPoint p = point;
|
|
737 |
if (coordType == RelativeToScreen)
|
|
738 |
p = lineEdit()->mapFromGlobal(p);
|
|
739 |
|
|
740 |
return lineEdit()->cursorPositionAt(p);
|
|
741 |
}
|
|
742 |
|
|
743 |
void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *endOffset)
|
|
744 |
{
|
|
745 |
*startOffset = *endOffset = 0;
|
|
746 |
if (selectionIndex != 0)
|
|
747 |
return;
|
|
748 |
|
|
749 |
*startOffset = lineEdit()->selectionStart();
|
|
750 |
*endOffset = *startOffset + lineEdit()->selectedText().count();
|
|
751 |
}
|
|
752 |
|
|
753 |
QString QAccessibleLineEdit::text(int startOffset, int endOffset)
|
|
754 |
{
|
|
755 |
if (startOffset > endOffset)
|
|
756 |
return QString();
|
|
757 |
return lineEdit()->text().mid(startOffset, endOffset - startOffset);
|
|
758 |
}
|
|
759 |
|
|
760 |
QString QAccessibleLineEdit::textBeforeOffset (int /*offset*/, BoundaryType /*boundaryType*/,
|
|
761 |
int * /*startOffset*/, int * /*endOffset*/)
|
|
762 |
{
|
|
763 |
// TODO
|
|
764 |
return QString();
|
|
765 |
}
|
|
766 |
|
|
767 |
QString QAccessibleLineEdit::textAfterOffset(int /*offset*/, BoundaryType /*boundaryType*/,
|
|
768 |
int * /*startOffset*/, int * /*endOffset*/)
|
|
769 |
{
|
|
770 |
// TODO
|
|
771 |
return QString();
|
|
772 |
}
|
|
773 |
|
|
774 |
QString QAccessibleLineEdit::textAtOffset(int /*offset*/, BoundaryType /*boundaryType*/,
|
|
775 |
int * /*startOffset*/, int * /*endOffset*/)
|
|
776 |
{
|
|
777 |
// TODO
|
|
778 |
return QString();
|
|
779 |
}
|
|
780 |
|
|
781 |
void QAccessibleLineEdit::removeSelection(int selectionIndex)
|
|
782 |
{
|
|
783 |
if (selectionIndex != 0)
|
|
784 |
return;
|
|
785 |
|
|
786 |
lineEdit()->deselect();
|
|
787 |
}
|
|
788 |
|
|
789 |
void QAccessibleLineEdit::setCursorPosition(int position)
|
|
790 |
{
|
|
791 |
lineEdit()->setCursorPosition(position);
|
|
792 |
}
|
|
793 |
|
|
794 |
void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int endOffset)
|
|
795 |
{
|
|
796 |
if (selectionIndex != 0)
|
|
797 |
return;
|
|
798 |
|
|
799 |
lineEdit()->setSelection(startOffset, endOffset - startOffset);
|
|
800 |
}
|
|
801 |
|
|
802 |
int QAccessibleLineEdit::characterCount()
|
|
803 |
{
|
|
804 |
return lineEdit()->text().count();
|
|
805 |
}
|
|
806 |
|
|
807 |
void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex)
|
|
808 |
{
|
|
809 |
lineEdit()->setCursorPosition(endIndex);
|
|
810 |
lineEdit()->setCursorPosition(startIndex);
|
|
811 |
}
|
|
812 |
|
|
813 |
#endif // QT_NO_LINEEDIT
|
|
814 |
|
|
815 |
#ifndef QT_NO_PROGRESSBAR
|
|
816 |
QAccessibleProgressBar::QAccessibleProgressBar(QWidget *o)
|
|
817 |
: QAccessibleDisplay(o)
|
|
818 |
{
|
|
819 |
Q_ASSERT(progressBar());
|
|
820 |
}
|
|
821 |
|
|
822 |
QVariant QAccessibleProgressBar::currentValue()
|
|
823 |
{
|
|
824 |
return progressBar()->value();
|
|
825 |
}
|
|
826 |
|
|
827 |
QVariant QAccessibleProgressBar::maximumValue()
|
|
828 |
{
|
|
829 |
return progressBar()->maximum();
|
|
830 |
}
|
|
831 |
|
|
832 |
QVariant QAccessibleProgressBar::minimumValue()
|
|
833 |
{
|
|
834 |
return progressBar()->minimum();
|
|
835 |
}
|
|
836 |
|
|
837 |
QProgressBar *QAccessibleProgressBar::progressBar() const
|
|
838 |
{
|
|
839 |
return qobject_cast<QProgressBar *>(object());
|
|
840 |
}
|
|
841 |
#endif
|
|
842 |
|
|
843 |
#endif // QT_NO_ACCESSIBILITY
|
|
844 |
|
|
845 |
QT_END_NAMESPACE
|
|
846 |
|