author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 "complexwidgets.h" |
|
43 |
||
44 |
#include <qapplication.h> |
|
45 |
#include <qabstractbutton.h> |
|
46 |
#include <qevent.h> |
|
47 |
#include <qheaderview.h> |
|
48 |
#include <qtabbar.h> |
|
49 |
#include <qcombobox.h> |
|
50 |
#include <qlistview.h> |
|
51 |
#include <qtableview.h> |
|
52 |
#include <qlineedit.h> |
|
53 |
#include <qstyle.h> |
|
54 |
#include <qstyleoption.h> |
|
55 |
#include <qtooltip.h> |
|
56 |
#include <qwhatsthis.h> |
|
57 |
#include <qtreeview.h> |
|
58 |
#include <private/qtabbar_p.h> |
|
59 |
#include <QAbstractScrollArea> |
|
60 |
#include <QScrollArea> |
|
61 |
#include <QScrollBar> |
|
62 |
#include <QDebug> |
|
63 |
||
64 |
#ifndef QT_NO_ACCESSIBILITY |
|
65 |
||
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
QString Q_GUI_EXPORT qt_accStripAmp(const QString &text); |
|
69 |
||
70 |
#ifndef QT_NO_ITEMVIEWS |
|
71 |
/* |
|
72 |
The MSDN article "Exposing Data Tables through Microsoft Active Accessibility" explains |
|
73 |
how data tables should be exposed. Url: http://msdn2.microsoft.com/en-us/library/ms971325.aspx |
|
74 |
Basically, the model is like this: |
|
75 |
||
76 |
ROLE_SYSTEM_TABLE |
|
77 |
|- ROLE_SYSTEM_ROW |
|
78 |
| |- ROLE_SYSTEM_ROWHEADER |
|
79 |
| |- ROLE_SYSTEM_COLUMNHEADER |
|
80 |
| |- ROLE_SYSTEM_COLUMNHEADER |
|
81 |
| |- ROLE_SYSTEM_COLUMNHEADER |
|
82 |
| '- .. |
|
83 |
|- ROLE_SYSTEM_ROW |
|
84 |
| |- ROLE_SYSTEM_ROWHEADER |
|
85 |
| |- ROLE_SYSTEM_CELL |
|
86 |
| |- ROLE_SYSTEM_CELL |
|
87 |
| |- ROLE_SYSTEM_CELL |
|
88 |
| '- .. |
|
89 |
|- ROLE_SYSTEM_ROW |
|
90 |
| |- ROLE_SYSTEM_ROWHEADER |
|
91 |
| |- ROLE_SYSTEM_CELL |
|
92 |
| |- ROLE_SYSTEM_CELL |
|
93 |
| |- ROLE_SYSTEM_CELL |
|
94 |
| '- .. |
|
95 |
'- .. |
|
96 |
||
97 |
The headers of QTreeView is also represented like this. |
|
98 |
*/ |
|
99 |
QAccessibleItemRow::QAccessibleItemRow(QAbstractItemView *aView, const QModelIndex &index, bool isHeader) |
|
100 |
: row(index), view(aView), m_header(isHeader) |
|
101 |
{ |
|
102 |
} |
|
103 |
||
104 |
QHeaderView *QAccessibleItemRow::horizontalHeader() const |
|
105 |
{ |
|
106 |
QHeaderView *header = 0; |
|
107 |
if (m_header) { |
|
108 |
if (false) { |
|
109 |
#ifndef QT_NO_TABLEVIEW |
|
110 |
} else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) { |
|
111 |
header = tv->horizontalHeader(); |
|
112 |
#endif |
|
113 |
#ifndef QT_NO_TREEVIEW |
|
114 |
} else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view)) { |
|
115 |
header = tv->header(); |
|
116 |
#endif |
|
117 |
} |
|
118 |
} |
|
119 |
return header; |
|
120 |
} |
|
121 |
||
122 |
QHeaderView *QAccessibleItemRow::verticalHeader() const |
|
123 |
{ |
|
124 |
QHeaderView *header = 0; |
|
125 |
#ifndef QT_NO_TABLEVIEW |
|
126 |
if (const QTableView *tv = qobject_cast<const QTableView*>(view)) |
|
127 |
header = tv->verticalHeader(); |
|
128 |
#endif |
|
129 |
return header; |
|
130 |
} |
|
131 |
||
132 |
int QAccessibleItemRow::logicalFromChild(QHeaderView *header, int child) const |
|
133 |
{ |
|
134 |
int logical = -1; |
|
135 |
if (header->sectionsHidden()) { |
|
136 |
int kid = 0; |
|
137 |
for (int i = 0; i < header->count(); ++i) { |
|
138 |
if (!header->isSectionHidden(i)) |
|
139 |
++kid; |
|
140 |
if (kid == child) { |
|
141 |
logical = i; |
|
142 |
break; |
|
143 |
} |
|
144 |
} |
|
145 |
} else { |
|
146 |
logical = child - 1; |
|
147 |
} |
|
148 |
return logical; |
|
149 |
} |
|
150 |
||
151 |
QRect QAccessibleItemRow::rect(int child) const |
|
152 |
{ |
|
153 |
QRect r; |
|
154 |
if (view && view->isVisible()) { |
|
155 |
if (QHeaderView *header = horizontalHeader()) { |
|
156 |
if (!child) { |
|
157 |
r = header->rect(); |
|
158 |
} else { |
|
159 |
if (QHeaderView *vheader = verticalHeader()) { |
|
160 |
if (child == 1) { |
|
161 |
int w = vheader->width(); |
|
162 |
int h = header->height(); |
|
163 |
r.setRect(0, 0, w, h); |
|
164 |
} |
|
165 |
--child; |
|
166 |
} |
|
167 |
if (child) { |
|
168 |
int logical = logicalFromChild(header, child); |
|
169 |
int w = header->sectionSize(logical); |
|
170 |
r.setRect(header->sectionViewportPosition(logical), 0, w, header->height()); |
|
171 |
r.translate(header->mapTo(view, QPoint(0, 0))); |
|
172 |
} |
|
173 |
} |
|
174 |
} else if (row.isValid()) { |
|
175 |
if (!child) { |
|
176 |
QModelIndex parent = row.parent(); |
|
177 |
const int colCount = row.model()->columnCount(parent); |
|
178 |
for (int i = 0; i < colCount; ++i) |
|
179 |
r |= view->visualRect(row.model()->index(row.row(), i, parent)); |
|
180 |
r.translate(view->viewport()->mapTo(view, QPoint(0,0))); |
|
181 |
||
182 |
if (const QHeaderView *vheader = verticalHeader()) { // include the section of the vertical header |
|
183 |
QRect re; |
|
184 |
int logicalRow = row.row(); |
|
185 |
int h = vheader->sectionSize(logicalRow); |
|
186 |
re.setRect(0, vheader->sectionViewportPosition(logicalRow), vheader->width(), h); |
|
187 |
re.translate(vheader->mapTo(view, QPoint(0, 0))); |
|
188 |
r |= re; |
|
189 |
} |
|
190 |
} else { |
|
191 |
if (QHeaderView *vheader = verticalHeader()) { |
|
192 |
if (child == 1) { |
|
193 |
int logicalRow = row.row(); |
|
194 |
int h = vheader->sectionSize(logicalRow); |
|
195 |
r.setRect(0, vheader->sectionViewportPosition(logicalRow), vheader->width(), h); |
|
196 |
r.translate(vheader->mapTo(view, QPoint(0, 0))); |
|
197 |
} |
|
198 |
--child; |
|
199 |
} |
|
200 |
if (child) { |
|
201 |
r = view->visualRect(childIndex(child)); |
|
202 |
r.translate(view->viewport()->mapTo(view, QPoint(0,0))); |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
if (!r.isNull()) |
|
208 |
r.translate(view->mapToGlobal(QPoint(0, 0))); |
|
209 |
||
210 |
return r; |
|
211 |
} |
|
212 |
||
213 |
int QAccessibleItemRow::treeLevel() const |
|
214 |
{ |
|
215 |
int level = 0; |
|
216 |
QModelIndex idx = row; |
|
217 |
while (idx.isValid()) { |
|
218 |
idx = idx.parent(); |
|
219 |
++level; |
|
220 |
} |
|
221 |
return level; |
|
222 |
} |
|
223 |
||
224 |
QString QAccessibleItemRow::text_helper(int child) const |
|
225 |
{ |
|
226 |
QString value; |
|
227 |
if (m_header) { |
|
228 |
if (!child) |
|
229 |
return QString(); |
|
230 |
if (verticalHeader()) { |
|
231 |
if (child == 1) |
|
232 |
return QString(); |
|
233 |
--child; |
|
234 |
} |
|
235 |
QHeaderView *header = horizontalHeader(); |
|
236 |
int logical = logicalFromChild(header, child); |
|
237 |
value = view->model()->headerData(logical, Qt::Horizontal, Qt::AccessibleTextRole).toString(); |
|
238 |
if (value.isEmpty()) |
|
239 |
value = view->model()->headerData(logical, Qt::Horizontal).toString(); |
|
240 |
return value; |
|
241 |
} else { |
|
242 |
if (!child) { // for one-column views (i.e. QListView) |
|
243 |
if (children().count() >= 1) |
|
244 |
child = 1; |
|
245 |
else |
|
246 |
return QString(); |
|
247 |
} |
|
248 |
if (verticalHeader()) { |
|
249 |
if (child == 1) { |
|
250 |
int logical = row.row(); |
|
251 |
value = view->model()->headerData(logical, Qt::Vertical, Qt::AccessibleTextRole).toString(); |
|
252 |
if (value.isEmpty()) |
|
253 |
value = view->model()->headerData(logical, Qt::Vertical).toString(); |
|
254 |
return value; |
|
255 |
} else { |
|
256 |
--child; |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
if (value.isEmpty()) { |
|
261 |
QModelIndex idx = childIndex(child); |
|
262 |
if (idx.isValid()) { |
|
263 |
value = idx.model()->data(idx, Qt::AccessibleTextRole).toString(); |
|
264 |
if (value.isEmpty()) |
|
265 |
value = idx.model()->data(idx, Qt::DisplayRole).toString(); |
|
266 |
} |
|
267 |
} |
|
268 |
return value; |
|
269 |
} |
|
270 |
||
271 |
QString QAccessibleItemRow::text(Text t, int child) const |
|
272 |
{ |
|
273 |
QString value; |
|
274 |
if (t == Name) { |
|
275 |
value = text_helper(child); |
|
276 |
} else if (t == Value) { |
|
277 |
#ifndef QT_NO_TREEVIEW |
|
278 |
if (qobject_cast<const QTreeView*>(view)) { |
|
279 |
if (child == 0) |
|
280 |
value = QString::number(treeLevel()); |
|
281 |
} else |
|
282 |
#endif |
|
283 |
{ |
|
284 |
value = text_helper(child); |
|
285 |
} |
|
286 |
} else if (t == Description) { |
|
287 |
#ifndef QT_NO_TREEVIEW |
|
288 |
if (child == 0 && qobject_cast<const QTreeView*>(view)) { |
|
289 |
// We store the tree coordinates of the current item in the description. |
|
290 |
// This enables some screen readers to report where the focus is |
|
291 |
// in a tree view. (works in JAWS). Also, Firefox does the same thing. |
|
292 |
// For instance the description "L2, 4 of 25 with 24" means |
|
293 |
// "L2": Tree Level 2 |
|
294 |
// "4 of 25": We are item 4 out of in total 25 other siblings |
|
295 |
// "with 24": We have 24 children. (JAWS does not read this number) |
|
296 |
||
297 |
// level |
|
298 |
int level = treeLevel(); |
|
299 |
||
300 |
QAbstractItemModel *m = view->model(); |
|
301 |
// totalSiblings and itemIndex |
|
302 |
QModelIndex parent = row.parent(); |
|
303 |
int rowCount = m->rowCount(parent); |
|
304 |
int itemIndex = -1; |
|
305 |
int totalSiblings = 0; |
|
306 |
for (int i = 0 ; i < rowCount; ++i) { |
|
307 |
QModelIndex sibling = row.sibling(i, 0); |
|
308 |
if (!view->isIndexHidden(sibling)) |
|
309 |
++totalSiblings; |
|
310 |
if (row == sibling) |
|
311 |
itemIndex = totalSiblings; |
|
312 |
} |
|
313 |
int totalChildren = m->rowCount(row); // JAWS does not report child count, so we do |
|
314 |
// this simple and efficient. |
|
315 |
// (don't check if they are all visible). |
|
316 |
value = QString::fromAscii("L%1, %2 of %3 with %4").arg(level).arg(itemIndex).arg(totalSiblings).arg(totalChildren); |
|
317 |
} else |
|
318 |
#endif // QT_NO_TREEVIEW |
|
319 |
{ |
|
320 |
if (!m_header) { |
|
321 |
if (child == 0 && children().count() >= 1) |
|
322 |
child = 1; |
|
323 |
if (verticalHeader()) { |
|
324 |
if (child == 1) { |
|
325 |
value = view->model()->headerData(row.row(), Qt::Vertical).toString(); |
|
326 |
} |
|
327 |
--child; |
|
328 |
} |
|
329 |
if (child) { |
|
330 |
QModelIndex idx = childIndex(child); |
|
331 |
value = idx.model()->data(idx, Qt::AccessibleDescriptionRole).toString(); |
|
332 |
} |
|
333 |
||
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
return value; |
|
338 |
} |
|
339 |
||
340 |
void QAccessibleItemRow::setText(Text t, int child, const QString &text) |
|
341 |
{ |
|
342 |
if (m_header) { |
|
343 |
if (child) |
|
344 |
view->model()->setHeaderData(child - 1, Qt::Horizontal, text); |
|
345 |
// child == 0 means the cell to the left of the horizontal header, which is empty!? |
|
346 |
} else { |
|
347 |
if (!child) { |
|
348 |
if (children().count() == 1) |
|
349 |
child = 1; |
|
350 |
else |
|
351 |
return; |
|
352 |
} |
|
353 |
||
354 |
if (verticalHeader()) { |
|
355 |
if (child == 1) { |
|
356 |
view->model()->setHeaderData(row.row(), Qt::Vertical, text); |
|
357 |
return; |
|
358 |
} |
|
359 |
--child; |
|
360 |
} |
|
361 |
QModelIndex idx = childIndex(child); |
|
362 |
if (!idx.isValid()) |
|
363 |
return; |
|
364 |
||
365 |
switch (t) { |
|
366 |
case Description: |
|
367 |
const_cast<QAbstractItemModel *>(idx.model())->setData(idx, text, |
|
368 |
Qt::AccessibleDescriptionRole); |
|
369 |
break; |
|
370 |
case Value: |
|
371 |
const_cast<QAbstractItemModel *>(idx.model())->setData(idx, text, Qt::EditRole); |
|
372 |
break; |
|
373 |
default: |
|
374 |
break; |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
||
379 |
QModelIndex QAccessibleItemRow::childIndex(int child) const |
|
380 |
{ |
|
381 |
QList<QModelIndex> kids = children(); |
|
382 |
Q_ASSERT(child >= 1 && child <= kids.count()); |
|
383 |
return kids.at(child - 1); |
|
384 |
} |
|
385 |
||
386 |
QList<QModelIndex> QAccessibleItemRow::children() const |
|
387 |
{ |
|
388 |
QList<QModelIndex> kids; |
|
389 |
for (int i = 0; i < row.model()->columnCount(row.parent()); ++i) { |
|
390 |
QModelIndex idx = row.model()->index(row.row(), i, row.parent()); |
|
391 |
if (!view->isIndexHidden(idx)) { |
|
392 |
kids << idx; |
|
393 |
} |
|
394 |
} |
|
395 |
return kids; |
|
396 |
} |
|
397 |
||
398 |
bool QAccessibleItemRow::isValid() const |
|
399 |
{ |
|
400 |
return m_header ? true : row.isValid(); |
|
401 |
} |
|
402 |
||
403 |
QObject *QAccessibleItemRow::object() const |
|
404 |
{ |
|
405 |
return 0; |
|
406 |
} |
|
407 |
||
408 |
int QAccessibleItemRow::childCount() const |
|
409 |
{ |
|
410 |
int count = 0; |
|
411 |
if (QHeaderView *header = horizontalHeader()) { |
|
412 |
count = header->count() - header->hiddenSectionCount(); |
|
413 |
} else { |
|
414 |
count = children().count(); |
|
415 |
} |
|
416 |
#ifndef QT_NO_TABLEVIEW |
|
417 |
if (qobject_cast<const QTableView*>(view)) { |
|
418 |
if (verticalHeader()) |
|
419 |
++count; |
|
420 |
} |
|
421 |
#endif |
|
422 |
return count; |
|
423 |
} |
|
424 |
||
425 |
int QAccessibleItemRow::indexOfChild(const QAccessibleInterface *iface) const |
|
426 |
{ |
|
427 |
if (!iface || iface->role(0) != Row) |
|
428 |
return -1; |
|
429 |
||
430 |
//### meaningless code? |
|
431 |
QList<QModelIndex> kids = children(); |
|
432 |
QModelIndex idx = static_cast<const QAccessibleItemRow *>(iface)->row; |
|
433 |
if (!idx.isValid()) |
|
434 |
return -1; |
|
435 |
return kids.indexOf(idx) + 1; |
|
436 |
} |
|
437 |
||
438 |
QAccessible::Relation QAccessibleItemRow::relationTo(int child, const QAccessibleInterface *other, |
|
439 |
int otherChild) const |
|
440 |
{ |
|
441 |
if (!child && !otherChild && other->object() == view) |
|
442 |
return Child; |
|
443 |
if (!child && !otherChild && other == this) |
|
444 |
return Self; |
|
445 |
if (!child && otherChild && other == this) |
|
446 |
return Ancestor; |
|
447 |
if (child && otherChild && other == this) |
|
448 |
return Sibling; |
|
449 |
return Unrelated; |
|
450 |
} |
|
451 |
||
452 |
int QAccessibleItemRow::childAt(int x, int y) const |
|
453 |
{ |
|
454 |
if (!view || !view->isVisible()) |
|
455 |
return -1; |
|
456 |
||
457 |
for (int i = childCount(); i >= 0; --i) { |
|
458 |
if (rect(i).contains(x, y)) |
|
459 |
return i; |
|
460 |
} |
|
461 |
return -1; |
|
462 |
} |
|
463 |
||
464 |
QAbstractItemView::CursorAction QAccessibleItemRow::toCursorAction( |
|
465 |
QAccessible::Relation rel) |
|
466 |
{ |
|
467 |
switch (rel) { |
|
468 |
case QAccessible::Up: |
|
469 |
return QAbstractItemView::MoveUp; |
|
470 |
case QAccessible::Down: |
|
471 |
return QAbstractItemView::MoveDown; |
|
472 |
case QAccessible::Left: |
|
473 |
return QAbstractItemView::MoveLeft; |
|
474 |
case QAccessible::Right: |
|
475 |
return QAbstractItemView::MoveRight; |
|
476 |
default: |
|
477 |
Q_ASSERT(false); |
|
478 |
} |
|
479 |
// should never be reached. |
|
480 |
return QAbstractItemView::MoveRight; |
|
481 |
} |
|
482 |
||
483 |
int QAccessibleItemRow::navigate(RelationFlag relation, int index, |
|
484 |
QAccessibleInterface **iface) const |
|
485 |
{ |
|
486 |
*iface = 0; |
|
487 |
if (!view) |
|
488 |
return -1; |
|
489 |
||
490 |
switch (relation) { |
|
491 |
case Ancestor: { |
|
492 |
if (!index) |
|
493 |
return -1; |
|
494 |
QAccessibleItemView *ancestor = new QAccessibleItemView(view->viewport()); |
|
495 |
if (index == 1) { |
|
496 |
*iface = ancestor; |
|
497 |
return 0; |
|
498 |
} else if (index > 1) { |
|
499 |
int ret = ancestor->navigate(Ancestor, index - 1, iface); |
|
500 |
delete ancestor; |
|
501 |
return ret; |
|
502 |
} |
|
503 |
} |
|
504 |
case Child: { |
|
505 |
if (!index) |
|
506 |
return -1; |
|
507 |
if (index < 1 && index > childCount()) |
|
508 |
return -1; |
|
509 |
||
510 |
return index;} |
|
511 |
case Sibling: |
|
512 |
if (index) { |
|
513 |
QAccessibleInterface *ifaceParent = 0; |
|
514 |
navigate(Ancestor, 1, &ifaceParent); |
|
515 |
if (ifaceParent) { |
|
516 |
int entry = ifaceParent->navigate(Child, index, iface); |
|
517 |
delete ifaceParent; |
|
518 |
return entry; |
|
519 |
} |
|
520 |
} |
|
521 |
return -1; |
|
522 |
case Up: |
|
523 |
case Down: |
|
524 |
case Left: |
|
525 |
case Right: { |
|
526 |
// This is in the "not so nice" category. In order to find out which item |
|
527 |
// is geometrically around, we have to set the current index, navigate |
|
528 |
// and restore the index as well as the old selection |
|
529 |
view->setUpdatesEnabled(false); |
|
530 |
const QModelIndex oldIdx = view->currentIndex(); |
|
531 |
QList<QModelIndex> kids = children(); |
|
532 |
const QModelIndex currentIndex = index ? kids.at(index - 1) : QModelIndex(row); |
|
533 |
const QItemSelection oldSelection = view->selectionModel()->selection(); |
|
534 |
view->setCurrentIndex(currentIndex); |
|
535 |
const QModelIndex idx = view->moveCursor(toCursorAction(relation), Qt::NoModifier); |
|
536 |
view->setCurrentIndex(oldIdx); |
|
537 |
view->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect); |
|
538 |
view->setUpdatesEnabled(true); |
|
539 |
if (!idx.isValid()) |
|
540 |
return -1; |
|
541 |
||
542 |
if (idx.parent() != row.parent() || idx.row() != row.row()) |
|
543 |
*iface = new QAccessibleItemRow(view, idx); |
|
544 |
return index ? kids.indexOf(idx) + 1 : 0; } |
|
545 |
default: |
|
546 |
break; |
|
547 |
} |
|
548 |
||
549 |
return -1; |
|
550 |
} |
|
551 |
||
552 |
QAccessible::Role QAccessibleItemRow::role(int child) const |
|
553 |
{ |
|
554 |
if (false) { |
|
555 |
#ifndef QT_NO_TREEVIEW |
|
556 |
} else if (qobject_cast<const QTreeView*>(view)) { |
|
557 |
if (horizontalHeader()) { |
|
558 |
if (!child) |
|
559 |
return Row; |
|
560 |
return ColumnHeader; |
|
561 |
} |
|
562 |
return TreeItem; |
|
563 |
#endif |
|
564 |
#ifndef QT_NO_LISTVIEW |
|
565 |
} else if (qobject_cast<const QListView*>(view)) { |
|
566 |
return ListItem; |
|
567 |
#endif |
|
568 |
#ifndef QT_NO_TABLEVIEW |
|
569 |
} else if (qobject_cast<const QTableView *>(view)) { |
|
570 |
if (!child) |
|
571 |
return Row; |
|
572 |
if (child == 1) { |
|
573 |
if (verticalHeader()) |
|
574 |
return RowHeader; |
|
575 |
} |
|
576 |
if (m_header) |
|
577 |
return ColumnHeader; |
|
578 |
#endif |
|
579 |
} |
|
580 |
return Cell; |
|
581 |
} |
|
582 |
||
583 |
QAccessible::State QAccessibleItemRow::state(int child) const |
|
584 |
{ |
|
585 |
State st = Normal; |
|
586 |
||
587 |
if (!view) |
|
588 |
return st; |
|
589 |
||
590 |
QAccessibleInterface *parent = 0; |
|
591 |
QRect globalRect; |
|
592 |
if (navigate(Ancestor, 1, &parent) == 0) { |
|
593 |
globalRect = parent->rect(0); |
|
594 |
delete parent; |
|
595 |
} |
|
596 |
if (!globalRect.intersects(rect(child))) |
|
597 |
st |= Invisible; |
|
598 |
||
599 |
if (!horizontalHeader()) { |
|
600 |
if (!(st & Invisible)) { |
|
601 |
if (child) { |
|
602 |
if (QHeaderView *vheader = verticalHeader() ) { |
|
603 |
if (child == 1) { |
|
604 |
if (!vheader->isVisible()) |
|
605 |
st |= Invisible; |
|
606 |
} |
|
607 |
--child; |
|
608 |
} |
|
609 |
if (child) { |
|
610 |
QModelIndex idx = childIndex(child); |
|
611 |
if (!idx.isValid()) |
|
612 |
return st; |
|
613 |
||
614 |
if (view->selectionModel()->isSelected(idx)) |
|
615 |
st |= Selected; |
|
616 |
if (view->selectionModel()->currentIndex() == idx) |
|
617 |
st |= Focused; |
|
618 |
if (idx.model()->data(idx, Qt::CheckStateRole).toInt() == Qt::Checked) |
|
619 |
st |= Checked; |
|
620 |
||
621 |
Qt::ItemFlags flags = idx.flags(); |
|
622 |
if (flags & Qt::ItemIsSelectable) { |
|
623 |
st |= Selectable; |
|
624 |
if (view->selectionMode() == QAbstractItemView::MultiSelection) |
|
625 |
st |= MultiSelectable; |
|
626 |
if (view->selectionMode() == QAbstractItemView::ExtendedSelection) |
|
627 |
st |= ExtSelectable; |
|
628 |
} |
|
629 |
} |
|
630 |
} else { |
|
631 |
Qt::ItemFlags flags = row.flags(); |
|
632 |
if (flags & Qt::ItemIsSelectable) { |
|
633 |
st |= Selectable; |
|
634 |
st |= Focusable; |
|
635 |
} |
|
636 |
if (view->selectionModel()->isRowSelected(row.row(), row.parent())) |
|
637 |
st |= Selected; |
|
638 |
if (view->selectionModel()->currentIndex().row() == row.row()) |
|
639 |
st |= Focused; |
|
640 |
} |
|
641 |
} |
|
642 |
} |
|
643 |
||
644 |
return st; |
|
645 |
} |
|
646 |
||
647 |
int QAccessibleItemRow::userActionCount(int) const |
|
648 |
{ |
|
649 |
return 0; |
|
650 |
} |
|
651 |
||
652 |
QString QAccessibleItemRow::actionText(int, Text, int) const |
|
653 |
{ |
|
654 |
return QString(); |
|
655 |
} |
|
656 |
||
657 |
static QItemSelection rowAt(const QModelIndex &idx) |
|
658 |
{ |
|
659 |
return QItemSelection(idx.sibling(idx.row(), 0), |
|
660 |
idx.sibling(idx.row(), idx.model()->columnCount(idx.parent()))); |
|
661 |
} |
|
662 |
||
663 |
bool QAccessibleItemRow::doAction(int action, int child, const QVariantList & /*params*/) |
|
664 |
{ |
|
665 |
if (!view) |
|
666 |
return false; |
|
667 |
||
668 |
if (verticalHeader()) |
|
669 |
--child; |
|
670 |
||
671 |
QModelIndex idx = child ? childIndex(child) : QModelIndex(row); |
|
672 |
if (!idx.isValid()) |
|
673 |
return false; |
|
674 |
||
675 |
QItemSelectionModel::SelectionFlags command = QItemSelectionModel::NoUpdate; |
|
676 |
||
677 |
switch (action) { |
|
678 |
case SetFocus: |
|
679 |
view->setCurrentIndex(idx); |
|
680 |
return true; |
|
681 |
case ExtendSelection: |
|
682 |
if (!child) |
|
683 |
return false; |
|
684 |
view->selectionModel()->select(QItemSelection(view->currentIndex(), idx), |
|
685 |
QItemSelectionModel::SelectCurrent); |
|
686 |
return true; |
|
687 |
case Select: |
|
688 |
command = QItemSelectionModel::ClearAndSelect; |
|
689 |
break; |
|
690 |
case ClearSelection: |
|
691 |
command = QItemSelectionModel::Clear; |
|
692 |
break; |
|
693 |
case RemoveSelection: |
|
694 |
command = QItemSelectionModel::Deselect; |
|
695 |
break; |
|
696 |
case AddToSelection: |
|
697 |
command = QItemSelectionModel::SelectCurrent; |
|
698 |
break; |
|
699 |
} |
|
700 |
if (command == QItemSelectionModel::NoUpdate) |
|
701 |
return false; |
|
702 |
||
703 |
if (child) |
|
704 |
view->selectionModel()->select(idx, command); |
|
705 |
else |
|
706 |
view->selectionModel()->select(rowAt(row), command); |
|
707 |
return true; |
|
708 |
} |
|
709 |
||
710 |
class ModelIndexIterator |
|
711 |
{ |
|
712 |
public: |
|
713 |
ModelIndexIterator(QAbstractItemView *view, const QModelIndex &start = QModelIndex()) : m_view(view) |
|
714 |
{ |
|
715 |
#ifndef QT_NO_LISTVIEW |
|
716 |
list = qobject_cast<QListView*>(m_view); |
|
717 |
#endif |
|
718 |
#ifndef QT_NO_TREEVIEW |
|
719 |
tree = qobject_cast<QTreeView*>(m_view); |
|
720 |
#endif |
|
721 |
#ifndef QT_NO_TABLEVIEW |
|
722 |
table = qobject_cast<QTableView*>(m_view); |
|
723 |
#endif |
|
724 |
if (start.isValid()) { |
|
725 |
m_current = start; |
|
726 |
} else if (m_view && m_view->model()) { |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
727 |
m_current = view->rootIndex().isValid() ? |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
728 |
view->rootIndex().child(0,0) : view->model()->index(0, 0); |
0 | 729 |
} |
730 |
} |
|
731 |
||
732 |
bool next(int count = 1) { |
|
733 |
for (int i = 0; i < count; ++i) { |
|
734 |
do { |
|
735 |
if (m_current.isValid()) { |
|
736 |
const QAbstractItemModel *m = m_current.model(); |
|
737 |
#ifndef QT_NO_TREEVIEW |
|
738 |
if (tree && m_current.model()->hasChildren(m_current) && tree->isExpanded(m_current)) { |
|
739 |
m_current = m_current.child(0, 0); |
|
740 |
} else |
|
741 |
#endif |
|
742 |
{ |
|
743 |
int row = m_current.row(); |
|
744 |
QModelIndex par = m_current.parent(); |
|
745 |
||
746 |
// Go up to the parent if we reach the end of the rows |
|
747 |
// If m_curent becomses invalid, stop going up. |
|
748 |
while (row + 1 >= m->rowCount(par)) { |
|
749 |
m_current = par; |
|
750 |
if (m_current.isValid()) { |
|
751 |
row = m_current.row(); |
|
752 |
par = m_current.parent(); |
|
753 |
} else { |
|
754 |
row = 0; |
|
755 |
par = QModelIndex(); |
|
756 |
break; |
|
757 |
} |
|
758 |
} |
|
759 |
||
760 |
if (m_current.isValid()) |
|
761 |
m_current = m_current.sibling(row + 1, 0); |
|
762 |
} |
|
763 |
} |
|
764 |
} while (isHidden()); |
|
765 |
} |
|
766 |
return m_current.isValid(); |
|
767 |
} |
|
768 |
||
769 |
bool isHidden() const { |
|
770 |
if (false) { |
|
771 |
#ifndef QT_NO_LISTVIEW |
|
772 |
} else if (list) { |
|
773 |
return list->isRowHidden(m_current.row()); |
|
774 |
#endif |
|
775 |
#ifndef QT_NO_TREEVIEW |
|
776 |
} else if (tree) { |
|
777 |
return tree->isRowHidden(m_current.row(), m_current.parent()); |
|
778 |
#endif |
|
779 |
#ifndef QT_NO_TABLEVIEW |
|
780 |
} else if (table) { |
|
781 |
return table->isRowHidden(m_current.row()); |
|
782 |
#endif |
|
783 |
} |
|
784 |
return false; |
|
785 |
} |
|
786 |
||
787 |
QModelIndex current() const { |
|
788 |
return m_current; |
|
789 |
} |
|
790 |
||
791 |
private: |
|
792 |
QModelIndex m_current; |
|
793 |
QAbstractItemView *m_view; |
|
794 |
||
795 |
#ifndef QT_NO_TREEVIEW |
|
796 |
QTreeView *tree; |
|
797 |
#endif |
|
798 |
#ifndef QT_NO_LISTVIEW |
|
799 |
QListView *list; |
|
800 |
#endif |
|
801 |
#ifndef QT_NO_TABLEVIEW |
|
802 |
QTableView *table; |
|
803 |
#endif |
|
804 |
}; |
|
805 |
||
806 |
QAccessibleItemView::QAccessibleItemView(QWidget *w) |
|
807 |
: QAccessibleAbstractScrollArea(w->objectName() == QLatin1String("qt_scrollarea_viewport") ? w->parentWidget() : w) |
|
808 |
{ |
|
809 |
atVP = w->objectName() == QLatin1String("qt_scrollarea_viewport"); |
|
810 |
||
811 |
} |
|
812 |
||
813 |
||
814 |
QHeaderView *QAccessibleItemView::horizontalHeader() const |
|
815 |
{ |
|
816 |
QHeaderView *header = 0; |
|
817 |
if (false) { |
|
818 |
#ifndef QT_NO_TABLEVIEW |
|
819 |
} else if (const QTableView *tv = qobject_cast<const QTableView*>(itemView())) { |
|
820 |
header = tv->horizontalHeader(); |
|
821 |
#endif |
|
822 |
#ifndef QT_NO_TREEVIEW |
|
823 |
} else if (const QTreeView *tv = qobject_cast<const QTreeView*>(itemView())) { |
|
824 |
header = tv->header(); |
|
825 |
#endif |
|
826 |
} |
|
827 |
return header; |
|
828 |
} |
|
829 |
||
830 |
QHeaderView *QAccessibleItemView::verticalHeader() const |
|
831 |
{ |
|
832 |
QHeaderView *header = 0; |
|
833 |
if (false) { |
|
834 |
#ifndef QT_NO_TABLEVIEW |
|
835 |
} else if (const QTableView *tv = qobject_cast<const QTableView*>(itemView())) { |
|
836 |
header = tv->verticalHeader(); |
|
837 |
#endif |
|
838 |
} |
|
839 |
return header; |
|
840 |
} |
|
841 |
||
842 |
||
843 |
bool QAccessibleItemView::isValidChildRole(QAccessible::Role role) const |
|
844 |
{ |
|
845 |
if (atViewport()) { |
|
846 |
if (false) { |
|
847 |
#ifndef QT_NO_TREEVIEW |
|
848 |
} else if (qobject_cast<const QTreeView*>(itemView())) { |
|
849 |
return (role == TreeItem || role == Row); |
|
850 |
#endif |
|
851 |
#ifndef QT_NO_LISTVIEW |
|
852 |
} else if (qobject_cast<const QListView*>(itemView())) { |
|
853 |
return (role == ListItem); |
|
854 |
#endif |
|
855 |
} |
|
856 |
// TableView |
|
857 |
return role == Row; |
|
858 |
} else { |
|
859 |
if (false) { |
|
860 |
#ifndef QT_NO_TREEVIEW |
|
861 |
} else if (qobject_cast<const QTreeView*>(itemView())) { |
|
862 |
return (role == Tree); |
|
863 |
#endif |
|
864 |
#ifndef QT_NO_LISTVIEW |
|
865 |
} else if (qobject_cast<const QListView*>(itemView())) { |
|
866 |
return (role == List); |
|
867 |
#endif |
|
868 |
} |
|
869 |
// TableView |
|
870 |
return (role == Table); |
|
871 |
} |
|
872 |
} |
|
873 |
||
874 |
QObject *QAccessibleItemView::object() const |
|
875 |
{ |
|
876 |
QObject *view = QAccessibleAbstractScrollArea::object(); |
|
877 |
Q_ASSERT(qobject_cast<const QAbstractItemView *>(view)); |
|
878 |
if (atViewport()) |
|
879 |
view = qobject_cast<const QAbstractItemView *>(view)->viewport(); |
|
880 |
return view; |
|
881 |
} |
|
882 |
||
883 |
QAbstractItemView *QAccessibleItemView::itemView() const |
|
884 |
{ |
|
885 |
return qobject_cast<QAbstractItemView *>(QAccessibleAbstractScrollArea::object()); |
|
886 |
} |
|
887 |
||
888 |
int QAccessibleItemView::indexOfChild(const QAccessibleInterface *iface) const |
|
889 |
{ |
|
890 |
if (atViewport()) { |
|
891 |
if (!iface || !isValidChildRole(iface->role(0))) |
|
892 |
return -1; |
|
893 |
||
894 |
int entry = -1; |
|
895 |
// ### This will fail if a row is hidden. |
|
896 |
const QAccessibleItemRow *ifRow = static_cast<const QAccessibleItemRow *>(iface); |
|
897 |
if (ifRow->horizontalHeader()) |
|
898 |
return 1; |
|
899 |
||
900 |
QModelIndex idx = ifRow->row; |
|
901 |
if (!idx.isValid()) |
|
902 |
return -1; |
|
903 |
||
904 |
entry = entryFromIndex(idx); |
|
905 |
if (horizontalHeader()) |
|
906 |
++entry; |
|
907 |
||
908 |
return entry; |
|
909 |
||
910 |
} else { |
|
911 |
return QAccessibleAbstractScrollArea::indexOfChild(iface); |
|
912 |
} |
|
913 |
} |
|
914 |
||
915 |
QModelIndex QAccessibleItemView::childIndex(int child) const |
|
916 |
{ |
|
917 |
if (!atViewport()) |
|
918 |
return QModelIndex(); |
|
919 |
ModelIndexIterator it(itemView()); |
|
920 |
it.next(child - 1); |
|
921 |
return it.current(); |
|
922 |
} |
|
923 |
||
924 |
int QAccessibleItemView::entryFromIndex(const QModelIndex &index) const |
|
925 |
{ |
|
926 |
int entry = -1; |
|
927 |
if (false) { |
|
928 |
#ifndef QT_NO_TREEVIEW |
|
929 |
} else if (QTreeView *tree = qobject_cast<QTreeView*>(itemView())) { |
|
930 |
entry = tree->visualIndex(index) + 1; |
|
931 |
#endif |
|
932 |
#ifndef QT_NO_LISTVIEW |
|
933 |
} else if (QListView *list = qobject_cast<QListView*>(itemView())) { |
|
934 |
entry = list->visualIndex(index) + 1; |
|
935 |
#endif |
|
936 |
#ifndef QT_NO_TABLEVIEW |
|
937 |
} else if (QTableView *table = qobject_cast<QTableView*>(itemView())) { |
|
938 |
entry = table->visualIndex(index) + 1; |
|
939 |
#endif |
|
940 |
} |
|
941 |
return entry; |
|
942 |
} |
|
943 |
||
944 |
int QAccessibleItemView::childCount() const |
|
945 |
{ |
|
946 |
if (atViewport()) { |
|
947 |
if (itemView()->model() == 0) |
|
948 |
return 0; |
|
949 |
QAbstractItemModel *m = itemView()->model(); |
|
950 |
QModelIndex idx = m->index(0,0); |
|
951 |
if (!idx.isValid()) |
|
952 |
return 0; |
|
953 |
ModelIndexIterator it(itemView()); |
|
954 |
int count = 1; |
|
955 |
while (it.next()) { |
|
956 |
++count; |
|
957 |
} |
|
958 |
if (horizontalHeader()) |
|
959 |
++count; |
|
960 |
||
961 |
return count; |
|
962 |
} else { |
|
963 |
return QAccessibleAbstractScrollArea::childCount(); |
|
964 |
} |
|
965 |
} |
|
966 |
||
967 |
QString QAccessibleItemView::text(Text t, int child) const |
|
968 |
{ |
|
969 |
if (atViewport()) { |
|
970 |
if (!child) |
|
971 |
return QAccessibleAbstractScrollArea::text(t, child); |
|
972 |
||
973 |
QAccessibleItemRow item(itemView(), childIndex(child)); |
|
974 |
return item.text(t, 1); |
|
975 |
} else { |
|
976 |
return QAccessibleAbstractScrollArea::text(t, child); |
|
977 |
} |
|
978 |
} |
|
979 |
||
980 |
void QAccessibleItemView::setText(Text t, int child, const QString &text) |
|
981 |
{ |
|
982 |
if (atViewport()) { |
|
983 |
if (!child) { |
|
984 |
QAccessibleAbstractScrollArea::setText(t, child, text); |
|
985 |
return; |
|
986 |
} |
|
987 |
||
988 |
QAccessibleItemRow item(itemView(), childIndex(child)); |
|
989 |
item.setText(t, 1, text); |
|
990 |
} else { |
|
991 |
QAccessibleAbstractScrollArea::setText(t, child, text); |
|
992 |
} |
|
993 |
} |
|
994 |
||
995 |
QRect QAccessibleItemView::rect(int child) const |
|
996 |
{ |
|
997 |
if (atViewport()) { |
|
998 |
QRect r; |
|
999 |
if (!child) { |
|
1000 |
// Make sure that the rect *include* the vertical and horizontal headers, while |
|
1001 |
// not including the potential vertical and horizontal scrollbars. |
|
1002 |
QAbstractItemView *w = itemView(); |
|
1003 |
||
1004 |
int vscrollWidth = 0; |
|
1005 |
const QScrollBar *sb = w->verticalScrollBar(); |
|
1006 |
if (sb && sb->isVisible()) |
|
1007 |
vscrollWidth = sb->width(); |
|
1008 |
||
1009 |
int hscrollHeight = 0; |
|
1010 |
sb = w->horizontalScrollBar(); |
|
1011 |
if (sb && sb->isVisible()) |
|
1012 |
hscrollHeight = sb->height(); |
|
1013 |
||
1014 |
QPoint globalPos = w->mapToGlobal(QPoint(0,0)); |
|
1015 |
r = w->rect().translated(globalPos); |
|
1016 |
if (w->isRightToLeft()) { |
|
1017 |
r.adjust(vscrollWidth, 0, 0, -hscrollHeight); |
|
1018 |
} else { |
|
1019 |
r.adjust(0, 0, -vscrollWidth, -hscrollHeight); |
|
1020 |
} |
|
1021 |
} else { |
|
1022 |
QAccessibleInterface *iface = 0; |
|
1023 |
if (navigate(Child, child, &iface) == 0) { |
|
1024 |
r = iface->rect(0); |
|
1025 |
delete iface; |
|
1026 |
} |
|
1027 |
} |
|
1028 |
return r; |
|
1029 |
} else { |
|
1030 |
QRect r = QAccessibleAbstractScrollArea::rect(child); |
|
1031 |
if (child == 1) { |
|
1032 |
// include the potential vertical and horizontal headers |
|
1033 |
||
1034 |
const QHeaderView *header = verticalHeader(); |
|
1035 |
int headerWidth = (header && header->isVisible()) ? header->width() : 0; |
|
1036 |
header = horizontalHeader(); |
|
1037 |
int headerHeight= (header && header->isVisible()) ? header->height() : 0; |
|
1038 |
if (itemView()->isRightToLeft()) { |
|
1039 |
r.adjust(0, -headerHeight, headerWidth, 0); |
|
1040 |
} else { |
|
1041 |
r.adjust(-headerWidth, -headerHeight, 0, 0); |
|
1042 |
} |
|
1043 |
} |
|
1044 |
return r; |
|
1045 |
} |
|
1046 |
} |
|
1047 |
||
1048 |
int QAccessibleItemView::childAt(int x, int y) const |
|
1049 |
{ |
|
1050 |
if (atViewport()) { |
|
1051 |
QPoint p(x, y); |
|
1052 |
for (int i = childCount(); i >= 0; --i) { |
|
1053 |
if (rect(i).contains(p)) |
|
1054 |
return i; |
|
1055 |
} |
|
1056 |
return -1; |
|
1057 |
} else { |
|
1058 |
return QAccessibleAbstractScrollArea::childAt(x, y); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
||
1062 |
QAccessible::Role QAccessibleItemView::role(int child) const |
|
1063 |
{ |
|
1064 |
if ((!atViewport() && child) || (atViewport() && child == 0)) { |
|
1065 |
QAbstractItemView *view = itemView(); |
|
1066 |
#ifndef QT_NO_TABLEVIEW |
|
1067 |
if (qobject_cast<QTableView *>(view)) |
|
1068 |
return Table; |
|
1069 |
#endif |
|
1070 |
#ifndef QT_NO_LISTVIEW |
|
1071 |
if (qobject_cast<QListView *>(view)) |
|
1072 |
return List; |
|
1073 |
#endif |
|
1074 |
return Tree; |
|
1075 |
} |
|
1076 |
if (atViewport()) { |
|
1077 |
if (child) |
|
1078 |
return Row; |
|
1079 |
} |
|
1080 |
||
1081 |
return QAccessibleAbstractScrollArea::role(child); |
|
1082 |
} |
|
1083 |
||
1084 |
QAccessible::State QAccessibleItemView::state(int child) const |
|
1085 |
{ |
|
1086 |
State st = Normal; |
|
1087 |
||
1088 |
if (itemView() == 0) |
|
1089 |
return State(Unavailable); |
|
1090 |
||
1091 |
bool queryViewPort = (atViewport() && child == 0) || (!atViewport() && child == 1); |
|
1092 |
if (queryViewPort) { |
|
1093 |
if (itemView()->selectionMode() != QAbstractItemView::NoSelection) { |
|
1094 |
st |= Selectable; |
|
1095 |
st |= Focusable; |
|
1096 |
} |
|
1097 |
} else if (atViewport()) { // children of viewport |
|
1098 |
if (horizontalHeader()) |
|
1099 |
--child; |
|
1100 |
if (child) { |
|
1101 |
QAccessibleItemRow item(itemView(), childIndex(child)); |
|
1102 |
st |= item.state(0); |
|
1103 |
} |
|
1104 |
} else if (!atViewport() && child != 1) { |
|
1105 |
st = QAccessibleAbstractScrollArea::state(child); |
|
1106 |
} |
|
1107 |
return st; |
|
1108 |
} |
|
1109 |
||
1110 |
bool QAccessibleItemView::isValid() const |
|
1111 |
{ |
|
1112 |
if (atViewport()) |
|
1113 |
return QAccessibleWidgetEx::isValid(); |
|
1114 |
else |
|
1115 |
return QAccessibleAbstractScrollArea::isValid(); |
|
1116 |
} |
|
1117 |
||
1118 |
int QAccessibleItemView::navigate(RelationFlag relation, int index, |
|
1119 |
QAccessibleInterface **iface) const |
|
1120 |
{ |
|
1121 |
if (atViewport()) { |
|
1122 |
if (relation == Ancestor && index == 1) { |
|
1123 |
*iface = new QAccessibleItemView(itemView()); |
|
1124 |
return 0; |
|
1125 |
} else if (relation == Child && index >= 1) { |
|
1126 |
if (horizontalHeader()) { |
|
1127 |
if (index == 1) { |
|
1128 |
*iface = new QAccessibleItemRow(itemView(), QModelIndex(), true); |
|
1129 |
return 0; |
|
1130 |
} |
|
1131 |
--index; |
|
1132 |
} |
|
1133 |
||
1134 |
//###JAS hidden rows.. |
|
1135 |
QModelIndex idx = childIndex(index); |
|
1136 |
if (idx.isValid()) { |
|
1137 |
*iface = new QAccessibleItemRow(itemView(), idx); |
|
1138 |
return 0; |
|
1139 |
} |
|
1140 |
} else if (relation == Sibling && index >= 1) { |
|
1141 |
QAccessibleInterface *parent = new QAccessibleItemView(itemView()); |
|
1142 |
return parent->navigate(Child, index, iface); |
|
1143 |
} |
|
1144 |
*iface = 0; |
|
1145 |
return -1; |
|
1146 |
} else { |
|
1147 |
return QAccessibleAbstractScrollArea::navigate(relation, index, iface); |
|
1148 |
} |
|
1149 |
} |
|
1150 |
||
1151 |
/* returns the model index for a given row and column */ |
|
1152 |
QModelIndex QAccessibleItemView::index(int row, int column) const |
|
1153 |
{ |
|
1154 |
return itemView()->model()->index(row, column); |
|
1155 |
} |
|
1156 |
||
1157 |
QAccessibleInterface *QAccessibleItemView::accessibleAt(int row, int column) |
|
1158 |
{ |
|
1159 |
QWidget *indexWidget = itemView()->indexWidget(index(row, column)); |
|
1160 |
return QAccessible::queryAccessibleInterface(indexWidget); |
|
1161 |
} |
|
1162 |
||
1163 |
/* We don't have a concept of a "caption" in Qt's standard widgets */ |
|
1164 |
QAccessibleInterface *QAccessibleItemView::caption() |
|
1165 |
{ |
|
1166 |
return 0; |
|
1167 |
} |
|
1168 |
||
1169 |
/* childIndex is row * columnCount + columnIndex */ |
|
1170 |
int QAccessibleItemView::childIndex(int rowIndex, int columnIndex) |
|
1171 |
{ |
|
1172 |
return rowIndex * itemView()->model()->columnCount() + columnIndex; |
|
1173 |
} |
|
1174 |
||
1175 |
/* Return the header data as column description */ |
|
1176 |
QString QAccessibleItemView::columnDescription(int column) |
|
1177 |
{ |
|
1178 |
return itemView()->model()->headerData(column, Qt::Horizontal).toString(); |
|
1179 |
} |
|
1180 |
||
1181 |
/* We don't support column spanning atm */ |
|
1182 |
int QAccessibleItemView::columnSpan(int /* row */, int /* column */) |
|
1183 |
{ |
|
1184 |
return 1; |
|
1185 |
} |
|
1186 |
||
1187 |
/* Return the horizontal header view */ |
|
1188 |
QAccessibleInterface *QAccessibleItemView::columnHeader() |
|
1189 |
{ |
|
1190 |
#ifndef QT_NO_TREEVIEW |
|
1191 |
if (QTreeView *tree = qobject_cast<QTreeView *>(itemView())) |
|
1192 |
return QAccessible::queryAccessibleInterface(tree->header()); |
|
1193 |
#endif |
|
1194 |
#ifndef QT_NO_TABLEVIEW |
|
1195 |
if (QTableView *table = qobject_cast<QTableView *>(itemView())) |
|
1196 |
return QAccessible::queryAccessibleInterface(table->horizontalHeader()); |
|
1197 |
#endif |
|
1198 |
return 0; |
|
1199 |
} |
|
1200 |
||
1201 |
int QAccessibleItemView::columnIndex(int childIndex) |
|
1202 |
{ |
|
1203 |
int columnCount = itemView()->model()->columnCount(); |
|
1204 |
if (!columnCount) |
|
1205 |
return 0; |
|
1206 |
||
1207 |
return childIndex % columnCount; |
|
1208 |
} |
|
1209 |
||
1210 |
int QAccessibleItemView::columnCount() |
|
1211 |
{ |
|
1212 |
return itemView()->model()->columnCount(); |
|
1213 |
} |
|
1214 |
||
1215 |
int QAccessibleItemView::rowCount() |
|
1216 |
{ |
|
1217 |
return itemView()->model()->rowCount(); |
|
1218 |
} |
|
1219 |
||
1220 |
int QAccessibleItemView::selectedColumnCount() |
|
1221 |
{ |
|
1222 |
return itemView()->selectionModel()->selectedColumns().count(); |
|
1223 |
} |
|
1224 |
||
1225 |
int QAccessibleItemView::selectedRowCount() |
|
1226 |
{ |
|
1227 |
return itemView()->selectionModel()->selectedRows().count(); |
|
1228 |
} |
|
1229 |
||
1230 |
QString QAccessibleItemView::rowDescription(int row) |
|
1231 |
{ |
|
1232 |
return itemView()->model()->headerData(row, Qt::Vertical).toString(); |
|
1233 |
} |
|
1234 |
||
1235 |
/* We don't support row spanning */ |
|
1236 |
int QAccessibleItemView::rowSpan(int /*row*/, int /*column*/) |
|
1237 |
{ |
|
1238 |
return 1; |
|
1239 |
} |
|
1240 |
||
1241 |
QAccessibleInterface *QAccessibleItemView::rowHeader() |
|
1242 |
{ |
|
1243 |
#ifndef QT_NO_TABLEVIEW |
|
1244 |
if (QTableView *table = qobject_cast<QTableView *>(itemView())) |
|
1245 |
return QAccessible::queryAccessibleInterface(table->verticalHeader()); |
|
1246 |
#endif |
|
1247 |
return 0; |
|
1248 |
} |
|
1249 |
||
1250 |
int QAccessibleItemView::rowIndex(int childIndex) |
|
1251 |
{ |
|
1252 |
int columnCount = itemView()->model()->columnCount(); |
|
1253 |
if (!columnCount) |
|
1254 |
return 0; |
|
1255 |
||
1256 |
return int(childIndex / columnCount); |
|
1257 |
} |
|
1258 |
||
1259 |
int QAccessibleItemView::selectedRows(int maxRows, QList<int> *rows) |
|
1260 |
{ |
|
1261 |
Q_ASSERT(rows); |
|
1262 |
||
1263 |
const QModelIndexList selRows = itemView()->selectionModel()->selectedRows(); |
|
1264 |
int maxCount = qMin(selRows.count(), maxRows); |
|
1265 |
||
1266 |
for (int i = 0; i < maxCount; ++i) |
|
1267 |
rows->append(selRows.at(i).row()); |
|
1268 |
||
1269 |
return maxCount; |
|
1270 |
} |
|
1271 |
||
1272 |
int QAccessibleItemView::selectedColumns(int maxColumns, QList<int> *columns) |
|
1273 |
{ |
|
1274 |
Q_ASSERT(columns); |
|
1275 |
||
1276 |
const QModelIndexList selColumns = itemView()->selectionModel()->selectedColumns(); |
|
1277 |
int maxCount = qMin(selColumns.count(), maxColumns); |
|
1278 |
||
1279 |
for (int i = 0; i < maxCount; ++i) |
|
1280 |
columns->append(selColumns.at(i).row()); |
|
1281 |
||
1282 |
return maxCount; |
|
1283 |
} |
|
1284 |
||
1285 |
/* Qt widgets don't have a concept of a summary */ |
|
1286 |
QAccessibleInterface *QAccessibleItemView::summary() |
|
1287 |
{ |
|
1288 |
return 0; |
|
1289 |
} |
|
1290 |
||
1291 |
bool QAccessibleItemView::isColumnSelected(int column) |
|
1292 |
{ |
|
1293 |
return itemView()->selectionModel()->isColumnSelected(column, QModelIndex()); |
|
1294 |
} |
|
1295 |
||
1296 |
bool QAccessibleItemView::isRowSelected(int row) |
|
1297 |
{ |
|
1298 |
return itemView()->selectionModel()->isRowSelected(row, QModelIndex()); |
|
1299 |
} |
|
1300 |
||
1301 |
bool QAccessibleItemView::isSelected(int row, int column) |
|
1302 |
{ |
|
1303 |
return itemView()->selectionModel()->isSelected(index(row, column)); |
|
1304 |
} |
|
1305 |
||
1306 |
void QAccessibleItemView::selectRow(int row) |
|
1307 |
{ |
|
1308 |
QItemSelectionModel *s = itemView()->selectionModel(); |
|
1309 |
s->select(index(row, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
1310 |
} |
|
1311 |
||
1312 |
void QAccessibleItemView::selectColumn(int column) |
|
1313 |
{ |
|
1314 |
QItemSelectionModel *s = itemView()->selectionModel(); |
|
1315 |
s->select(index(0, column), QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
1316 |
} |
|
1317 |
||
1318 |
void QAccessibleItemView::unselectRow(int row) |
|
1319 |
{ |
|
1320 |
QItemSelectionModel *s = itemView()->selectionModel(); |
|
1321 |
s->select(index(row, 0), QItemSelectionModel::Deselect | QItemSelectionModel::Rows); |
|
1322 |
} |
|
1323 |
||
1324 |
void QAccessibleItemView::unselectColumn(int column) |
|
1325 |
{ |
|
1326 |
QItemSelectionModel *s = itemView()->selectionModel(); |
|
1327 |
s->select(index(0, column), QItemSelectionModel::Deselect | QItemSelectionModel::Columns); |
|
1328 |
} |
|
1329 |
||
1330 |
void QAccessibleItemView::cellAtIndex(int index, int *row, int *column, int *rSpan, |
|
1331 |
int *cSpan, bool *isSelect) |
|
1332 |
{ |
|
1333 |
*row = rowIndex(index); |
|
1334 |
*column = columnIndex(index); |
|
1335 |
*rSpan = rowSpan(*row, *column); |
|
1336 |
*cSpan = columnSpan(*row, *column); |
|
1337 |
*isSelect = isSelected(*row, *column); |
|
1338 |
} |
|
1339 |
||
1340 |
/*! |
|
1341 |
\class QAccessibleHeader |
|
1342 |
\brief The QAccessibleHeader class implements the QAccessibleInterface for header widgets. |
|
1343 |
\internal |
|
1344 |
||
1345 |
\ingroup accessibility |
|
1346 |
*/ |
|
1347 |
||
1348 |
/*! |
|
1349 |
Constructs a QAccessibleHeader object for \a w. |
|
1350 |
*/ |
|
1351 |
QAccessibleHeader::QAccessibleHeader(QWidget *w) |
|
1352 |
: QAccessibleWidgetEx(w) |
|
1353 |
{ |
|
1354 |
Q_ASSERT(header()); |
|
1355 |
addControllingSignal(QLatin1String("sectionClicked(int)")); |
|
1356 |
} |
|
1357 |
||
1358 |
/*! Returns the QHeaderView. */ |
|
1359 |
QHeaderView *QAccessibleHeader::header() const |
|
1360 |
{ |
|
1361 |
return qobject_cast<QHeaderView*>(object()); |
|
1362 |
} |
|
1363 |
||
1364 |
/*! \reimp */ |
|
1365 |
QRect QAccessibleHeader::rect(int child) const |
|
1366 |
{ |
|
1367 |
if (!child) |
|
1368 |
return QAccessibleWidgetEx::rect(0); |
|
1369 |
||
1370 |
QHeaderView *h = header(); |
|
1371 |
QPoint zero = h->mapToGlobal(QPoint(0, 0)); |
|
1372 |
int sectionSize = h->sectionSize(child - 1); |
|
1373 |
int sectionPos = h->sectionPosition(child - 1); |
|
1374 |
return h->orientation() == Qt::Horizontal |
|
1375 |
? QRect(zero.x() + sectionPos, zero.y(), sectionSize, h->height()) |
|
1376 |
: QRect(zero.x(), zero.y() + sectionPos, h->width(), sectionSize); |
|
1377 |
} |
|
1378 |
||
1379 |
/*! \reimp */ |
|
1380 |
int QAccessibleHeader::childCount() const |
|
1381 |
{ |
|
1382 |
return header()->count(); |
|
1383 |
} |
|
1384 |
||
1385 |
/*! \reimp */ |
|
1386 |
QString QAccessibleHeader::text(Text t, int child) const |
|
1387 |
{ |
|
1388 |
QString str; |
|
1389 |
||
1390 |
if (child > 0 && child <= childCount()) { |
|
1391 |
switch (t) { |
|
1392 |
case Name: |
|
1393 |
str = header()->model()->headerData(child - 1, header()->orientation()).toString(); |
|
1394 |
break; |
|
1395 |
case Description: { |
|
1396 |
QAccessibleEvent event(QEvent::AccessibilityDescription, child); |
|
1397 |
if (QApplication::sendEvent(widget(), &event)) |
|
1398 |
str = event.value(); |
|
1399 |
break; } |
|
1400 |
case Help: { |
|
1401 |
QAccessibleEvent event(QEvent::AccessibilityHelp, child); |
|
1402 |
if (QApplication::sendEvent(widget(), &event)) |
|
1403 |
str = event.value(); |
|
1404 |
break; } |
|
1405 |
default: |
|
1406 |
break; |
|
1407 |
} |
|
1408 |
} |
|
1409 |
if (str.isEmpty()) |
|
1410 |
str = QAccessibleWidgetEx::text(t, child); |
|
1411 |
return str; |
|
1412 |
} |
|
1413 |
||
1414 |
/*! \reimp */ |
|
1415 |
QAccessible::Role QAccessibleHeader::role(int) const |
|
1416 |
{ |
|
1417 |
return (header()->orientation() == Qt::Horizontal) ? ColumnHeader : RowHeader; |
|
1418 |
} |
|
1419 |
||
1420 |
/*! \reimp */ |
|
1421 |
QAccessible::State QAccessibleHeader::state(int child) const |
|
1422 |
{ |
|
1423 |
State state = QAccessibleWidgetEx::state(child); |
|
1424 |
||
1425 |
if (child) { |
|
1426 |
int section = child - 1; |
|
1427 |
if (header()->isSectionHidden(section)) |
|
1428 |
state |= Invisible; |
|
1429 |
if (header()->resizeMode(section) != QHeaderView::Custom) |
|
1430 |
state |= Sizeable; |
|
1431 |
} else { |
|
1432 |
if (header()->isMovable()) |
|
1433 |
state |= Movable; |
|
1434 |
} |
|
1435 |
if (!header()->isClickable()) |
|
1436 |
state |= Unavailable; |
|
1437 |
return state; |
|
1438 |
} |
|
1439 |
#endif // QT_NO_ITEMVIEWS |
|
1440 |
||
1441 |
#ifndef QT_NO_TABBAR |
|
1442 |
/*! |
|
1443 |
\class QAccessibleTabBar |
|
1444 |
\brief The QAccessibleTabBar class implements the QAccessibleInterface for tab bars. |
|
1445 |
\internal |
|
1446 |
||
1447 |
\ingroup accessibility |
|
1448 |
*/ |
|
1449 |
||
1450 |
/*! |
|
1451 |
Constructs a QAccessibleTabBar object for \a w. |
|
1452 |
*/ |
|
1453 |
QAccessibleTabBar::QAccessibleTabBar(QWidget *w) |
|
1454 |
: QAccessibleWidgetEx(w) |
|
1455 |
{ |
|
1456 |
Q_ASSERT(tabBar()); |
|
1457 |
} |
|
1458 |
||
1459 |
/*! Returns the QTabBar. */ |
|
1460 |
QTabBar *QAccessibleTabBar::tabBar() const |
|
1461 |
{ |
|
1462 |
return qobject_cast<QTabBar*>(object()); |
|
1463 |
} |
|
1464 |
||
1465 |
QAbstractButton *QAccessibleTabBar::button(int child) const |
|
1466 |
{ |
|
1467 |
if (child <= tabBar()->count()) |
|
1468 |
return 0; |
|
1469 |
QTabBarPrivate * const tabBarPrivate = tabBar()->d_func(); |
|
1470 |
if (child - tabBar()->count() == 1) |
|
1471 |
return tabBarPrivate->leftB; |
|
1472 |
if (child - tabBar()->count() == 2) |
|
1473 |
return tabBarPrivate->rightB; |
|
1474 |
Q_ASSERT(false); |
|
1475 |
return 0; |
|
1476 |
} |
|
1477 |
||
1478 |
/*! \reimp */ |
|
1479 |
QRect QAccessibleTabBar::rect(int child) const |
|
1480 |
{ |
|
1481 |
if (!child || !tabBar()->isVisible()) |
|
1482 |
return QAccessibleWidgetEx::rect(0); |
|
1483 |
||
1484 |
QPoint tp = tabBar()->mapToGlobal(QPoint(0,0)); |
|
1485 |
QRect rec; |
|
1486 |
if (child <= tabBar()->count()) { |
|
1487 |
rec = tabBar()->tabRect(child - 1); |
|
1488 |
} else { |
|
1489 |
QWidget *widget = button(child); |
|
1490 |
rec = widget ? widget->geometry() : QRect(); |
|
1491 |
} |
|
1492 |
return QRect(tp.x() + rec.x(), tp.y() + rec.y(), rec.width(), rec.height()); |
|
1493 |
} |
|
1494 |
||
1495 |
/*! \reimp */ |
|
1496 |
int QAccessibleTabBar::childCount() const |
|
1497 |
{ |
|
1498 |
// tabs + scroll buttons |
|
1499 |
return tabBar()->count() + 2; |
|
1500 |
} |
|
1501 |
||
1502 |
/*! \reimp */ |
|
1503 |
QString QAccessibleTabBar::text(Text t, int child) const |
|
1504 |
{ |
|
1505 |
QString str; |
|
1506 |
||
1507 |
if (child > tabBar()->count()) { |
|
1508 |
bool left = child - tabBar()->count() == 1; |
|
1509 |
switch (t) { |
|
1510 |
case Name: |
|
1511 |
return left ? QTabBar::tr("Scroll Left") : QTabBar::tr("Scroll Right"); |
|
1512 |
default: |
|
1513 |
break; |
|
1514 |
} |
|
1515 |
} else if (child > 0) { |
|
1516 |
switch (t) { |
|
1517 |
case Name: |
|
1518 |
return qt_accStripAmp(tabBar()->tabText(child - 1)); |
|
1519 |
default: |
|
1520 |
break; |
|
1521 |
} |
|
1522 |
} |
|
1523 |
||
1524 |
if (str.isEmpty()) |
|
1525 |
str = QAccessibleWidgetEx::text(t, child);; |
|
1526 |
return str; |
|
1527 |
} |
|
1528 |
||
1529 |
/*! \reimp */ |
|
1530 |
QAccessible::Role QAccessibleTabBar::role(int child) const |
|
1531 |
{ |
|
1532 |
if (!child) |
|
1533 |
return PageTabList; |
|
1534 |
if (child > tabBar()->count()) |
|
1535 |
return PushButton; |
|
1536 |
return PageTab; |
|
1537 |
} |
|
1538 |
||
1539 |
/*! \reimp */ |
|
1540 |
QAccessible::State QAccessibleTabBar::state(int child) const |
|
1541 |
{ |
|
1542 |
State st = QAccessibleWidgetEx::state(0); |
|
1543 |
||
1544 |
if (!child) |
|
1545 |
return st; |
|
1546 |
||
1547 |
QTabBar *tb = tabBar(); |
|
1548 |
||
1549 |
if (child > tb->count()) { |
|
1550 |
QWidget *bt = button(child); |
|
1551 |
if (!bt) |
|
1552 |
return st; |
|
1553 |
if (bt->isEnabled() == false) |
|
1554 |
st |= Unavailable; |
|
1555 |
if (bt->isVisible() == false) |
|
1556 |
st |= Invisible; |
|
1557 |
if (bt->focusPolicy() != Qt::NoFocus && bt->isActiveWindow()) |
|
1558 |
st |= Focusable; |
|
1559 |
if (bt->hasFocus()) |
|
1560 |
st |= Focused; |
|
1561 |
return st; |
|
1562 |
} |
|
1563 |
||
1564 |
if (!tb->isTabEnabled(child - 1)) |
|
1565 |
st |= Unavailable; |
|
1566 |
else |
|
1567 |
st |= Selectable; |
|
1568 |
||
1569 |
if (!tb->currentIndex() == child - 1) |
|
1570 |
st |= Selected; |
|
1571 |
||
1572 |
return st; |
|
1573 |
} |
|
1574 |
||
1575 |
/*! \reimp */ |
|
1576 |
bool QAccessibleTabBar::doAction(int action, int child, const QVariantList &) |
|
1577 |
{ |
|
1578 |
if (!child) |
|
1579 |
return false; |
|
1580 |
||
1581 |
if (action != QAccessible::DefaultAction && action != QAccessible::Press) |
|
1582 |
return false; |
|
1583 |
||
1584 |
if (child > tabBar()->count()) { |
|
1585 |
QAbstractButton *bt = button(child); |
|
1586 |
if (!bt->isEnabled()) |
|
1587 |
return false; |
|
1588 |
bt->animateClick(); |
|
1589 |
return true; |
|
1590 |
} |
|
1591 |
if (!tabBar()->isTabEnabled(child - 1)) |
|
1592 |
return false; |
|
1593 |
tabBar()->setCurrentIndex(child - 1); |
|
1594 |
return true; |
|
1595 |
} |
|
1596 |
||
1597 |
/*! |
|
1598 |
Selects the item with index \a child if \a on is true; otherwise |
|
1599 |
unselects it. If \a extend is true and the selection mode is not |
|
1600 |
\c Single and there is an existing selection, the selection is |
|
1601 |
extended to include all the items from the existing selection up |
|
1602 |
to and including the item with index \a child. Returns true if a |
|
1603 |
selection was made or extended; otherwise returns false. |
|
1604 |
||
1605 |
\sa selection() clearSelection() |
|
1606 |
*/ |
|
1607 |
bool QAccessibleTabBar::setSelected(int child, bool on, bool extend) |
|
1608 |
{ |
|
1609 |
if (!child || !on || extend || child > tabBar()->count()) |
|
1610 |
return false; |
|
1611 |
||
1612 |
if (!tabBar()->isTabEnabled(child - 1)) |
|
1613 |
return false; |
|
1614 |
tabBar()->setCurrentIndex(child - 1); |
|
1615 |
return true; |
|
1616 |
} |
|
1617 |
||
1618 |
/*! |
|
1619 |
Returns a (possibly empty) list of indexes of the items selected |
|
1620 |
in the list box. |
|
1621 |
||
1622 |
\sa setSelected() clearSelection() |
|
1623 |
*/ |
|
1624 |
QVector<int> QAccessibleTabBar::selection() const |
|
1625 |
{ |
|
1626 |
QVector<int> array; |
|
1627 |
if (tabBar()->currentIndex() != -1) |
|
1628 |
array +=tabBar()->currentIndex() + 1; |
|
1629 |
return array; |
|
1630 |
} |
|
1631 |
||
1632 |
#endif // QT_NO_TABBAR |
|
1633 |
||
1634 |
#ifndef QT_NO_COMBOBOX |
|
1635 |
/*! |
|
1636 |
\class QAccessibleComboBox |
|
1637 |
\brief The QAccessibleComboBox class implements the QAccessibleInterface for editable and read-only combo boxes. |
|
1638 |
\internal |
|
1639 |
||
1640 |
\ingroup accessibility |
|
1641 |
*/ |
|
1642 |
||
1643 |
/*! |
|
1644 |
\enum QAccessibleComboBox::ComboBoxElements |
|
1645 |
||
1646 |
\internal |
|
1647 |
||
1648 |
\value ComboBoxSelf |
|
1649 |
\value CurrentText |
|
1650 |
\value OpenList |
|
1651 |
\value PopupList |
|
1652 |
*/ |
|
1653 |
||
1654 |
/*! |
|
1655 |
Constructs a QAccessibleComboBox object for \a w. |
|
1656 |
*/ |
|
1657 |
QAccessibleComboBox::QAccessibleComboBox(QWidget *w) |
|
1658 |
: QAccessibleWidgetEx(w, ComboBox) |
|
1659 |
{ |
|
1660 |
Q_ASSERT(comboBox()); |
|
1661 |
} |
|
1662 |
||
1663 |
/*! |
|
1664 |
Returns the combobox. |
|
1665 |
*/ |
|
1666 |
QComboBox *QAccessibleComboBox::comboBox() const |
|
1667 |
{ |
|
1668 |
return qobject_cast<QComboBox*>(object()); |
|
1669 |
} |
|
1670 |
||
1671 |
/*! \reimp */ |
|
1672 |
QRect QAccessibleComboBox::rect(int child) const |
|
1673 |
{ |
|
1674 |
QPoint tp; |
|
1675 |
QStyle::SubControl sc; |
|
1676 |
QRect r; |
|
1677 |
switch (child) { |
|
1678 |
case CurrentText: |
|
1679 |
if (comboBox()->isEditable()) { |
|
1680 |
tp = comboBox()->lineEdit()->mapToGlobal(QPoint(0,0)); |
|
1681 |
r = comboBox()->lineEdit()->rect(); |
|
1682 |
sc = QStyle::SC_None; |
|
1683 |
} else { |
|
1684 |
tp = comboBox()->mapToGlobal(QPoint(0,0)); |
|
1685 |
sc = QStyle::SC_ComboBoxEditField; |
|
1686 |
} |
|
1687 |
break; |
|
1688 |
case OpenList: |
|
1689 |
tp = comboBox()->mapToGlobal(QPoint(0,0)); |
|
1690 |
sc = QStyle::SC_ComboBoxArrow; |
|
1691 |
break; |
|
1692 |
default: |
|
1693 |
return QAccessibleWidgetEx::rect(child); |
|
1694 |
} |
|
1695 |
||
1696 |
if (sc != QStyle::SC_None) { |
|
1697 |
QStyleOptionComboBox option; |
|
1698 |
option.initFrom(comboBox()); |
|
1699 |
r = comboBox()->style()->subControlRect(QStyle::CC_ComboBox, &option, sc, comboBox()); |
|
1700 |
} |
|
1701 |
return QRect(tp.x() + r.x(), tp.y() + r.y(), r.width(), r.height()); |
|
1702 |
} |
|
1703 |
||
1704 |
/*! \reimp */ |
|
1705 |
int QAccessibleComboBox::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const |
|
1706 |
{ |
|
1707 |
*target = 0; |
|
1708 |
if (entry > ComboBoxSelf) switch (rel) { |
|
1709 |
case Child: |
|
1710 |
if (entry < PopupList) |
|
1711 |
return entry; |
|
1712 |
if (entry == PopupList) { |
|
1713 |
QAbstractItemView *view = comboBox()->view(); |
|
1714 |
QWidget *parent = view ? view->parentWidget() : 0; |
|
1715 |
*target = QAccessible::queryAccessibleInterface(parent); |
|
1716 |
return *target ? 0 : -1; |
|
1717 |
} |
|
1718 |
case QAccessible::Left: |
|
1719 |
return entry == OpenList ? CurrentText : -1; |
|
1720 |
case QAccessible::Right: |
|
1721 |
return entry == CurrentText ? OpenList : -1; |
|
1722 |
case QAccessible::Up: |
|
1723 |
return -1; |
|
1724 |
case QAccessible::Down: |
|
1725 |
return -1; |
|
1726 |
default: |
|
1727 |
break; |
|
1728 |
} |
|
1729 |
return QAccessibleWidgetEx::navigate(rel, entry, target); |
|
1730 |
} |
|
1731 |
||
1732 |
/*! \reimp */ |
|
1733 |
int QAccessibleComboBox::childCount() const |
|
1734 |
{ |
|
1735 |
return comboBox()->view() ? PopupList : OpenList; |
|
1736 |
} |
|
1737 |
||
1738 |
/*! \reimp */ |
|
1739 |
int QAccessibleComboBox::childAt(int x, int y) const |
|
1740 |
{ |
|
1741 |
if (!comboBox()->isVisible()) |
|
1742 |
return -1; |
|
1743 |
QPoint gp = widget()->mapToGlobal(QPoint(0, 0)); |
|
1744 |
if (!QRect(gp.x(), gp.y(), widget()->width(), widget()->height()).contains(x, y)) |
|
1745 |
return -1; |
|
1746 |
||
1747 |
// a complex control |
|
1748 |
for (int i = 1; i < PopupList; ++i) { |
|
1749 |
if (rect(i).contains(x, y)) |
|
1750 |
return i; |
|
1751 |
} |
|
1752 |
return 0; |
|
1753 |
} |
|
1754 |
||
1755 |
/*! \reimp */ |
|
1756 |
int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const |
|
1757 |
{ |
|
1758 |
QObject *viewParent = comboBox()->view() ? comboBox()->view()->parentWidget() : 0; |
|
1759 |
if (child->object() == viewParent) |
|
1760 |
return PopupList; |
|
1761 |
return -1; |
|
1762 |
} |
|
1763 |
||
1764 |
/*! \reimp */ |
|
1765 |
QString QAccessibleComboBox::text(Text t, int child) const |
|
1766 |
{ |
|
1767 |
QString str; |
|
1768 |
||
1769 |
switch (t) { |
|
1770 |
case Name: |
|
1771 |
if (child == OpenList) |
|
1772 |
str = QComboBox::tr("Open"); |
|
1773 |
else |
|
1774 |
str = QAccessibleWidgetEx::text(t, 0); |
|
1775 |
break; |
|
1776 |
#ifndef QT_NO_SHORTCUT |
|
1777 |
case Accelerator: |
|
1778 |
if (child == OpenList) |
|
1779 |
str = (QString)QKeySequence(Qt::Key_Down); |
|
1780 |
// missing break? |
|
1781 |
#endif |
|
1782 |
case Value: |
|
1783 |
if (comboBox()->isEditable()) |
|
1784 |
str = comboBox()->lineEdit()->text(); |
|
1785 |
else |
|
1786 |
str = comboBox()->currentText(); |
|
1787 |
break; |
|
1788 |
default: |
|
1789 |
break; |
|
1790 |
} |
|
1791 |
if (str.isEmpty()) |
|
1792 |
str = QAccessibleWidgetEx::text(t, 0); |
|
1793 |
return str; |
|
1794 |
} |
|
1795 |
||
1796 |
/*! \reimp */ |
|
1797 |
QAccessible::Role QAccessibleComboBox::role(int child) const |
|
1798 |
{ |
|
1799 |
switch (child) { |
|
1800 |
case CurrentText: |
|
1801 |
if (comboBox()->isEditable()) |
|
1802 |
return EditableText; |
|
1803 |
return StaticText; |
|
1804 |
case OpenList: |
|
1805 |
return PushButton; |
|
1806 |
case PopupList: |
|
1807 |
return List; |
|
1808 |
default: |
|
1809 |
return ComboBox; |
|
1810 |
} |
|
1811 |
} |
|
1812 |
||
1813 |
/*! \reimp */ |
|
1814 |
QAccessible::State QAccessibleComboBox::state(int /*child*/) const |
|
1815 |
{ |
|
1816 |
return QAccessibleWidgetEx::state(0); |
|
1817 |
} |
|
1818 |
||
1819 |
/*! \reimp */ |
|
1820 |
bool QAccessibleComboBox::doAction(int action, int child, const QVariantList &) |
|
1821 |
{ |
|
1822 |
if (child == 2 && (action == DefaultAction || action == Press)) { |
|
1823 |
if (comboBox()->view()->isVisible()) { |
|
1824 |
comboBox()->hidePopup(); |
|
1825 |
} else { |
|
1826 |
comboBox()->showPopup(); |
|
1827 |
} |
|
1828 |
return true; |
|
1829 |
} |
|
1830 |
return false; |
|
1831 |
} |
|
1832 |
||
1833 |
QString QAccessibleComboBox::actionText(int action, Text t, int child) const |
|
1834 |
{ |
|
1835 |
QString text; |
|
1836 |
if (child == 2 && t == Name && (action == DefaultAction || action == Press)) |
|
1837 |
text = comboBox()->view()->isVisible() ? QComboBox::tr("Close") : QComboBox::tr("Open"); |
|
1838 |
return text; |
|
1839 |
} |
|
1840 |
#endif // QT_NO_COMBOBOX |
|
1841 |
||
1842 |
static inline void removeInvisibleWidgetsFromList(QWidgetList *list) |
|
1843 |
{ |
|
1844 |
if (!list || list->isEmpty()) |
|
1845 |
return; |
|
1846 |
||
1847 |
for (int i = 0; i < list->count(); ++i) { |
|
1848 |
QWidget *widget = list->at(i); |
|
1849 |
if (!widget->isVisible()) |
|
1850 |
list->removeAt(i); |
|
1851 |
} |
|
1852 |
} |
|
1853 |
||
1854 |
#ifndef QT_NO_SCROLLAREA |
|
1855 |
// ======================= QAccessibleAbstractScrollArea ======================= |
|
1856 |
QAccessibleAbstractScrollArea::QAccessibleAbstractScrollArea(QWidget *widget) |
|
1857 |
: QAccessibleWidgetEx(widget, Client) |
|
1858 |
{ |
|
1859 |
Q_ASSERT(qobject_cast<QAbstractScrollArea *>(widget)); |
|
1860 |
} |
|
1861 |
||
1862 |
QString QAccessibleAbstractScrollArea::text(Text textType, int child) const |
|
1863 |
{ |
|
1864 |
if (child == Self) |
|
1865 |
return QAccessibleWidgetEx::text(textType, 0); |
|
1866 |
QWidgetList children = accessibleChildren(); |
|
1867 |
if (child < 1 || child > children.count()) |
|
1868 |
return QString(); |
|
1869 |
QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1)); |
|
1870 |
if (!childInterface) |
|
1871 |
return QString(); |
|
1872 |
QString string = childInterface->text(textType, 0); |
|
1873 |
delete childInterface; |
|
1874 |
return string; |
|
1875 |
} |
|
1876 |
||
1877 |
void QAccessibleAbstractScrollArea::setText(Text textType, int child, const QString &text) |
|
1878 |
{ |
|
1879 |
if (text.isEmpty()) |
|
1880 |
return; |
|
1881 |
if (child == 0) { |
|
1882 |
QAccessibleWidgetEx::setText(textType, 0, text); |
|
1883 |
return; |
|
1884 |
} |
|
1885 |
QWidgetList children = accessibleChildren(); |
|
1886 |
if (child < 1 || child > children.count()) |
|
1887 |
return; |
|
1888 |
QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1)); |
|
1889 |
if (!childInterface) |
|
1890 |
return; |
|
1891 |
childInterface->setText(textType, 0, text); |
|
1892 |
delete childInterface; |
|
1893 |
} |
|
1894 |
||
1895 |
QAccessible::State QAccessibleAbstractScrollArea::state(int child) const |
|
1896 |
{ |
|
1897 |
if (child == Self) |
|
1898 |
return QAccessibleWidgetEx::state(child); |
|
1899 |
QWidgetList children = accessibleChildren(); |
|
1900 |
if (child < 1 || child > children.count()) |
|
1901 |
return QAccessibleWidgetEx::state(Self); |
|
1902 |
QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1)); |
|
1903 |
if (!childInterface) |
|
1904 |
return QAccessibleWidgetEx::state(Self); |
|
1905 |
QAccessible::State returnState = childInterface->state(0); |
|
1906 |
delete childInterface; |
|
1907 |
return returnState; |
|
1908 |
} |
|
1909 |
||
1910 |
QVariant QAccessibleAbstractScrollArea::invokeMethodEx(QAccessible::Method, int, const QVariantList &) |
|
1911 |
{ |
|
1912 |
return QVariant(); |
|
1913 |
} |
|
1914 |
||
1915 |
int QAccessibleAbstractScrollArea::childCount() const |
|
1916 |
{ |
|
1917 |
return accessibleChildren().count(); |
|
1918 |
} |
|
1919 |
||
1920 |
int QAccessibleAbstractScrollArea::indexOfChild(const QAccessibleInterface *child) const |
|
1921 |
{ |
|
1922 |
if (!child || !child->object()) |
|
1923 |
return -1; |
|
1924 |
int index = accessibleChildren().indexOf(qobject_cast<QWidget *>(child->object())); |
|
1925 |
if (index >= 0) |
|
1926 |
return ++index; |
|
1927 |
return -1; |
|
1928 |
} |
|
1929 |
||
1930 |
bool QAccessibleAbstractScrollArea::isValid() const |
|
1931 |
{ |
|
1932 |
return (QAccessibleWidgetEx::isValid() && abstractScrollArea() && abstractScrollArea()->viewport()); |
|
1933 |
} |
|
1934 |
||
1935 |
int QAccessibleAbstractScrollArea::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const |
|
1936 |
{ |
|
1937 |
if (!target) |
|
1938 |
return -1; |
|
1939 |
||
1940 |
*target = 0; |
|
1941 |
||
1942 |
QWidget *targetWidget = 0; |
|
1943 |
QWidget *entryWidget = 0; |
|
1944 |
||
1945 |
if (relation == Child || |
|
1946 |
relation == Left || relation == Up || relation == Right || relation == Down) { |
|
1947 |
QWidgetList children = accessibleChildren(); |
|
1948 |
if (entry < 0 || entry > children.count()) |
|
1949 |
return -1; |
|
1950 |
||
1951 |
if (entry == Self) |
|
1952 |
entryWidget = abstractScrollArea(); |
|
1953 |
else |
|
1954 |
entryWidget = children.at(entry - 1); |
|
1955 |
AbstractScrollAreaElement entryElement = elementType(entryWidget); |
|
1956 |
||
1957 |
// Not one of the most beautiful switches I've ever seen, but I believe it has |
|
1958 |
// to be like this since each case need special handling. |
|
1959 |
// It might be possible to make it more general, but I'll leave that as an exercise |
|
1960 |
// to the reader. :-) |
|
1961 |
switch (relation) { |
|
1962 |
case Child: |
|
1963 |
if (entry > 0) |
|
1964 |
targetWidget = children.at(entry - 1); |
|
1965 |
break; |
|
1966 |
case Left: |
|
1967 |
if (entry < 1) |
|
1968 |
break; |
|
1969 |
switch (entryElement) { |
|
1970 |
case Viewport: |
|
1971 |
if (!isLeftToRight()) |
|
1972 |
targetWidget = abstractScrollArea()->verticalScrollBar(); |
|
1973 |
break; |
|
1974 |
case HorizontalContainer: |
|
1975 |
if (!isLeftToRight()) |
|
1976 |
targetWidget = abstractScrollArea()->cornerWidget(); |
|
1977 |
break; |
|
1978 |
case VerticalContainer: |
|
1979 |
if (isLeftToRight()) |
|
1980 |
targetWidget = abstractScrollArea()->viewport(); |
|
1981 |
break; |
|
1982 |
case CornerWidget: |
|
1983 |
if (isLeftToRight()) |
|
1984 |
targetWidget = abstractScrollArea()->horizontalScrollBar(); |
|
1985 |
break; |
|
1986 |
default: |
|
1987 |
break; |
|
1988 |
} |
|
1989 |
break; |
|
1990 |
case Right: |
|
1991 |
if (entry < 1) |
|
1992 |
break; |
|
1993 |
switch (entryElement) { |
|
1994 |
case Viewport: |
|
1995 |
if (isLeftToRight()) |
|
1996 |
targetWidget = abstractScrollArea()->verticalScrollBar(); |
|
1997 |
break; |
|
1998 |
case HorizontalContainer: |
|
1999 |
targetWidget = abstractScrollArea()->cornerWidget(); |
|
2000 |
break; |
|
2001 |
case VerticalContainer: |
|
2002 |
if (!isLeftToRight()) |
|
2003 |
targetWidget = abstractScrollArea()->viewport(); |
|
2004 |
break; |
|
2005 |
case CornerWidget: |
|
2006 |
if (!isLeftToRight()) |
|
2007 |
targetWidget = abstractScrollArea()->horizontalScrollBar(); |
|
2008 |
break; |
|
2009 |
default: |
|
2010 |
break; |
|
2011 |
} |
|
2012 |
break; |
|
2013 |
case Up: |
|
2014 |
if (entry < 1) |
|
2015 |
break; |
|
2016 |
switch (entryElement) { |
|
2017 |
case HorizontalContainer: |
|
2018 |
targetWidget = abstractScrollArea()->viewport(); |
|
2019 |
break; |
|
2020 |
case CornerWidget: |
|
2021 |
targetWidget = abstractScrollArea()->verticalScrollBar(); |
|
2022 |
break; |
|
2023 |
default: |
|
2024 |
break; |
|
2025 |
} |
|
2026 |
break; |
|
2027 |
case Down: |
|
2028 |
if (entry < 1) |
|
2029 |
break; |
|
2030 |
switch (entryElement) { |
|
2031 |
case Viewport: |
|
2032 |
targetWidget = abstractScrollArea()->horizontalScrollBar(); |
|
2033 |
break; |
|
2034 |
case VerticalContainer: |
|
2035 |
targetWidget = abstractScrollArea()->cornerWidget(); |
|
2036 |
break; |
|
2037 |
default: |
|
2038 |
break; |
|
2039 |
} |
|
2040 |
break; |
|
2041 |
default: |
|
2042 |
break; |
|
2043 |
} |
|
2044 |
} else { |
|
2045 |
return QAccessibleWidgetEx::navigate(relation, entry, target); |
|
2046 |
} |
|
2047 |
||
2048 |
if (qobject_cast<const QScrollBar *>(targetWidget)) |
|
2049 |
targetWidget = targetWidget->parentWidget(); |
|
2050 |
*target = QAccessible::queryAccessibleInterface(targetWidget); |
|
2051 |
return *target ? 0: -1; |
|
2052 |
} |
|
2053 |
||
2054 |
QRect QAccessibleAbstractScrollArea::rect(int child) const |
|
2055 |
{ |
|
2056 |
if (!abstractScrollArea()->isVisible()) |
|
2057 |
return QRect(); |
|
2058 |
if (child == Self) |
|
2059 |
return QAccessibleWidgetEx::rect(child); |
|
2060 |
QWidgetList children = accessibleChildren(); |
|
2061 |
if (child < 1 || child > children.count()) |
|
2062 |
return QRect(); |
|
2063 |
const QWidget *childWidget = children.at(child - 1); |
|
2064 |
if (!childWidget->isVisible()) |
|
2065 |
return QRect(); |
|
2066 |
return QRect(childWidget->mapToGlobal(QPoint(0, 0)), childWidget->size()); |
|
2067 |
} |
|
2068 |
||
2069 |
int QAccessibleAbstractScrollArea::childAt(int x, int y) const |
|
2070 |
{ |
|
2071 |
if (!abstractScrollArea()->isVisible()) |
|
2072 |
return -1; |
|
2073 |
#if 0 |
|
2074 |
const QRect globalSelfGeometry = rect(Self); |
|
2075 |
if (!globalSelfGeometry.isValid() || !globalSelfGeometry.contains(QPoint(x, y))) |
|
2076 |
return -1; |
|
2077 |
const QWidgetList children = accessibleChildren(); |
|
2078 |
for (int i = 0; i < children.count(); ++i) { |
|
2079 |
const QWidget *child = children.at(i); |
|
2080 |
const QRect globalChildGeometry = QRect(child->mapToGlobal(QPoint(0, 0)), child->size()); |
|
2081 |
if (globalChildGeometry.contains(QPoint(x, y))) { |
|
2082 |
return ++i; |
|
2083 |
} |
|
2084 |
} |
|
2085 |
return 0; |
|
2086 |
#else |
|
2087 |
for (int i = childCount(); i >= 0; --i) { |
|
2088 |
if (rect(i).contains(x, y)) |
|
2089 |
return i; |
|
2090 |
} |
|
2091 |
return -1; |
|
2092 |
#endif |
|
2093 |
} |
|
2094 |
||
2095 |
QAbstractScrollArea *QAccessibleAbstractScrollArea::abstractScrollArea() const |
|
2096 |
{ |
|
2097 |
return static_cast<QAbstractScrollArea *>(object()); |
|
2098 |
} |
|
2099 |
||
2100 |
QWidgetList QAccessibleAbstractScrollArea::accessibleChildren() const |
|
2101 |
{ |
|
2102 |
QWidgetList children; |
|
2103 |
||
2104 |
// Viewport. |
|
2105 |
QWidget * viewport = abstractScrollArea()->viewport(); |
|
2106 |
if (viewport) |
|
2107 |
children.append(viewport); |
|
2108 |
||
2109 |
// Horizontal scrollBar container. |
|
2110 |
QScrollBar *horizontalScrollBar = abstractScrollArea()->horizontalScrollBar(); |
|
2111 |
if (horizontalScrollBar && horizontalScrollBar->isVisible()) { |
|
2112 |
children.append(horizontalScrollBar->parentWidget()); |
|
2113 |
} |
|
2114 |
||
2115 |
// Vertical scrollBar container. |
|
2116 |
QScrollBar *verticalScrollBar = abstractScrollArea()->verticalScrollBar(); |
|
2117 |
if (verticalScrollBar && verticalScrollBar->isVisible()) { |
|
2118 |
children.append(verticalScrollBar->parentWidget()); |
|
2119 |
} |
|
2120 |
||
2121 |
// CornerWidget. |
|
2122 |
QWidget *cornerWidget = abstractScrollArea()->cornerWidget(); |
|
2123 |
if (cornerWidget && cornerWidget->isVisible()) |
|
2124 |
children.append(cornerWidget); |
|
2125 |
||
2126 |
return children; |
|
2127 |
} |
|
2128 |
||
2129 |
QAccessibleAbstractScrollArea::AbstractScrollAreaElement |
|
2130 |
QAccessibleAbstractScrollArea::elementType(QWidget *widget) const |
|
2131 |
{ |
|
2132 |
if (!widget) |
|
2133 |
return Undefined; |
|
2134 |
||
2135 |
if (widget == abstractScrollArea()) |
|
2136 |
return Self; |
|
2137 |
if (widget == abstractScrollArea()->viewport()) |
|
2138 |
return Viewport; |
|
2139 |
if (widget->objectName() == QLatin1String("qt_scrollarea_hcontainer")) |
|
2140 |
return HorizontalContainer; |
|
2141 |
if (widget->objectName() == QLatin1String("qt_scrollarea_vcontainer")) |
|
2142 |
return VerticalContainer; |
|
2143 |
if (widget == abstractScrollArea()->cornerWidget()) |
|
2144 |
return CornerWidget; |
|
2145 |
||
2146 |
return Undefined; |
|
2147 |
} |
|
2148 |
||
2149 |
bool QAccessibleAbstractScrollArea::isLeftToRight() const |
|
2150 |
{ |
|
2151 |
return abstractScrollArea()->isLeftToRight(); |
|
2152 |
} |
|
2153 |
||
2154 |
// ======================= QAccessibleScrollArea =========================== |
|
2155 |
QAccessibleScrollArea::QAccessibleScrollArea(QWidget *widget) |
|
2156 |
: QAccessibleAbstractScrollArea(widget) |
|
2157 |
{ |
|
2158 |
Q_ASSERT(qobject_cast<QScrollArea *>(widget)); |
|
2159 |
} |
|
2160 |
#endif // QT_NO_SCROLLAREA |
|
2161 |
||
2162 |
QT_END_NAMESPACE |
|
2163 |
||
2164 |
#endif // QT_NO_ACCESSIBILITY |