1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
|
#include "kitemlistviewaccessible.h"
#include "kitemlistcontroller.h"
#include "kitemlistselectionmanager.h"
#include "private/kitemlistviewlayouter.h"
#include <QtGui/qtableview.h>
#include <QtGui/qaccessible2.h>
#include <QDebug>
#ifndef QT_NO_ACCESSIBILITY
#ifndef QT_NO_ITEMVIEWS
/*
Implementation of the IAccessible2 table2 interface. Much simpler than
the other table interfaces since there is only the main table and cells:
TABLE/LIST/TREE
|- HEADER CELL
|- CELL
|- CELL
...
*/
KItemListView *KItemListViewAccessible::view() const
{
return qobject_cast<KItemListView*>(object());
}
KItemListViewAccessible::KItemListViewAccessible(KItemListView *view_)
: QAccessibleObjectEx(view_)
{
Q_ASSERT(view());
/*if (qobject_cast<const QTableView*>(view())) {
m_role = QAccessible::Table;
} else if (qobject_cast<const QTreeView*>(view())) {
m_role = QAccessible::Tree;
} else if (qobject_cast<const QListView*>(view())) {
m_role = QAccessible::List;
} else {
// is this our best guess?
m_role = QAccessible::Table;
}*/
}
KItemListViewAccessible::~KItemListViewAccessible()
{
}
void KItemListViewAccessible::modelReset()
{}
QAccessibleTable2CellInterface *KItemListViewAccessible::cell(int index) const
{
if (index > 0)
return new KItemListWidgetAccessible(view(), index);
return 0;
}
QAccessibleTable2CellInterface *KItemListViewAccessible::cellAt(int row, int column) const
{
/*Q_ASSERT(role(0) != QAccessible::Tree);
QModelIndex index = view()->model()->index(row, column);
//Q_ASSERT(index.isValid());
if (!index.isValid()) {
qWarning() << "QAccessibleTable2::cellAt: invalid index: " << index << " for " << view();
return 0;
}
return cell(index);*/
Q_UNUSED(row)
Q_UNUSED(column)
return cell(1);
}
QAccessibleInterface *KItemListViewAccessible::caption() const
{
return 0;
}
QString KItemListViewAccessible::columnDescription(int) const
{
return "No Column Description";
}
int KItemListViewAccessible::columnCount() const
{
return view()->layouter()->columnCount();
}
int KItemListViewAccessible::rowCount() const
{
int itemCount = view()->model()->count();
int rowCount = itemCount / columnCount();
if (itemCount % rowCount)
++rowCount;
return rowCount;
}
int KItemListViewAccessible::selectedCellCount() const
{
return view()->controller()->selectionManager()->selectedItems().size();
}
int KItemListViewAccessible::selectedColumnCount() const
{
return 0;
}
int KItemListViewAccessible::selectedRowCount() const
{
return 0;
}
QString KItemListViewAccessible::rowDescription(int) const
{
return "No Row Description";
}
QList<QAccessibleTable2CellInterface*> KItemListViewAccessible::selectedCells() const
{
QList<QAccessibleTable2CellInterface*> cells;
Q_FOREACH (int index, view()->controller()->selectionManager()->selectedItems()) {
cells.append(cell(index));
}
return cells;
}
QList<int> KItemListViewAccessible::selectedColumns() const
{
QList<int> columns;
/*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedColumns()) {
columns.append(index.column());
}*/
return columns;
}
QList<int> KItemListViewAccessible::selectedRows() const
{
QList<int> rows;
/*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedRows()) {
rows.append(index.row());
}*/
return rows;
}
QAccessibleInterface *KItemListViewAccessible::summary() const
{
return 0;
}
bool KItemListViewAccessible::isColumnSelected(int) const
{
return false; //view()->selectionModel()->isColumnSelected(column, QModelIndex());
}
bool KItemListViewAccessible::isRowSelected(int) const
{
return false; //view()->selectionModel()->isRowSelected(row, QModelIndex());
}
bool KItemListViewAccessible::selectRow(int)
{
/*QModelIndex index = view()->model()->index(row, 0);
if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection)
return false;
view()->selectionModel()->select(index, QItemSelectionModel::Select);*/
return true;
}
bool KItemListViewAccessible::selectColumn(int)
{
/*QModelIndex index = view()->model()->index(0, column);
if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection)
return false;
view()->selectionModel()->select(index, QItemSelectionModel::Select);*/
return true;
}
bool KItemListViewAccessible::unselectRow(int)
{
/*QModelIndex index = view()->model()->index(row, 0);
if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection)
return false;
view()->selectionModel()->select(index, QItemSelectionModel::Deselect);*/
return true;
}
bool KItemListViewAccessible::unselectColumn(int)
{
/*QModelIndex index = view()->model()->index(0, column);
if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection)
return false;
view()->selectionModel()->select(index, QItemSelectionModel::Columns & QItemSelectionModel::Deselect);*/
return true;
}
QAccessible2::TableModelChange KItemListViewAccessible::modelChange() const
{
QAccessible2::TableModelChange change;
// FIXME
return change;
}
QAccessible::Role KItemListViewAccessible::role(int child) const
{
Q_ASSERT(child >= 0);
if (child > 0)
return QAccessible::Cell;
return QAccessible::Table;
}
QAccessible::State KItemListViewAccessible::state(int child) const
{
Q_ASSERT(child == 0);
return QAccessible::Normal | HasInvokeExtension;
}
int KItemListViewAccessible::childAt(int x, int y) const
{
QPointF point = QPointF(x,y);
return view()->itemAt(view()->mapFromScene(point));
}
int KItemListViewAccessible::childCount() const
{
return rowCount() * columnCount();
}
int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *iface) const
{
/*Q_ASSERT(iface->role(0) != QAccessible::TreeItem); // should be handled by tree class
if (iface->role(0) == QAccessible::Cell || iface->role(0) == QAccessible::ListItem) {
const QAccessibleTable2Cell* cell = static_cast<const QAccessibleTable2Cell*>(iface);
return logicalIndex(cell->m_index);
} else if (iface->role(0) == QAccessible::ColumnHeader){
const QAccessibleTable2HeaderCell* cell = static_cast<const QAccessibleTable2HeaderCell*>(iface);
return cell->index + (verticalHeader() ? 1 : 0) + 1;
} else if (iface->role(0) == QAccessible::RowHeader){
const QAccessibleTable2HeaderCell* cell = static_cast<const QAccessibleTable2HeaderCell*>(iface);
return (cell->index+1) * (view()->model()->rowCount()+1) + 1;
} else if (iface->role(0) == QAccessible::Pane) {
return 1; // corner button
} else {
qWarning() << "WARNING QAccessibleTable2::indexOfChild Fix my children..."
<< iface->role(0) << iface->text(QAccessible::Name, 0);
}
// FIXME: we are in denial of our children. this should stop.
return -1;*/
const KItemListWidgetAccessible *widget = static_cast<const KItemListWidgetAccessible*>(iface);
return widget->getIndex();
}
QString KItemListViewAccessible::text(Text t, int child) const
{
Q_ASSERT(child == 0);
if (t == QAccessible::Description)
return "List of files present in the current directory";
return "File List";
}
QRect KItemListViewAccessible::rect(int child) const
{
Q_UNUSED(child)
if (!view()->isVisible())
return QRect();
return view()->geometry().toRect();
}
int KItemListViewAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
{
*iface = 0;
switch (relation) {
/*case Ancestor: {
if (index == 1 && view()->parent()) {
*iface = QAccessible::queryAccessibleInterface(view()->parent());
if (*iface)
return 0;
}
break;
}*/
case QAccessible::Child: {
Q_ASSERT(index > 0);
*iface = cell(index);
if (*iface) {
return 0;
}
break;
}
default:
break;
}
return -1;
}
QAccessible::Relation KItemListViewAccessible::relationTo(int, const QAccessibleInterface *, int) const
{
return QAccessible::Unrelated;
}
#ifndef QT_NO_ACTION
int KItemListViewAccessible::userActionCount(int) const
{
return 0;
}
QString KItemListViewAccessible::actionText(int, Text, int) const
{
return QString();
}
bool KItemListViewAccessible::doAction(int, int, const QVariantList &)
{
return false;
}
#endif
// TABLE CELL
KItemListWidgetAccessible::KItemListWidgetAccessible(KItemListView *view_, int index_)
: /* QAccessibleSimpleEditableTextInterface(this), */ view(view_), index(index_)
{
Q_ASSERT(index_>0);
}
int KItemListWidgetAccessible::columnExtent() const { return 1; }
int KItemListWidgetAccessible::rowExtent() const { return 1; }
QList<QAccessibleInterface*> KItemListWidgetAccessible::rowHeaderCells() const
{
QList<QAccessibleInterface*> headerCell;
/*if (verticalHeader()) {
headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.row(), Qt::Vertical));
}*/
return headerCell;
}
QList<QAccessibleInterface*> KItemListWidgetAccessible::columnHeaderCells() const
{
QList<QAccessibleInterface*> headerCell;
/*if (horizontalHeader()) {
headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.column(), Qt::Horizontal));
}*/
return headerCell;
}
int KItemListWidgetAccessible::columnIndex() const
{
return view->layouter()->itemColumn(index);
}
int KItemListWidgetAccessible::rowIndex() const
{
/*if (role(0) == QAccessible::TreeItem) {
const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
Q_ASSERT(treeView);
int row = treeView->d_func()->viewIndex(m_index);
return row;
}*/
return view->layouter()->itemRow(index);
}
//Done
bool KItemListWidgetAccessible::isSelected() const
{
return widget->isSelected();
}
void KItemListWidgetAccessible::rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const
{
KItemListViewLayouter* layouter = view->layouter();
*row = layouter->itemRow(index);
*column = layouter->itemColumn(index);
*rowExtents = 1;
*columnExtents = 1;
*selected = isSelected();
}
QAccessibleTable2Interface* KItemListWidgetAccessible::table() const
{
return QAccessible::queryAccessibleInterface(view)->table2Interface();
}
QAccessible::Role KItemListWidgetAccessible::role(int child) const
{
Q_ASSERT(child == 0);
return QAccessible::Cell;
}
QAccessible::State KItemListWidgetAccessible::state(int child) const
{
Q_ASSERT(child == 0);
QAccessible::State st = Normal;
//QRect globalRect = view->rect();
//globalRect.translate(view->mapToGlobal(QPoint(0,0)));
//if (!globalRect.intersects(rect(0)))
// st |= Invisible;
if (widget->isSelected())
st |= Selected;
if (view->controller()->selectionManager()->currentItem() == index)
st |= Focused;
//if (m_index.model()->data(m_index, Qt::CheckStateRole).toInt() == Qt::Checked)
// st |= Checked;
//if (flags & Qt::ItemIsSelectable) {
st |= Selectable;
st |= Focusable;
if (view->controller()->selectionBehavior() == KItemListController::MultiSelection)
st |= MultiSelectable;
//if (view->selectionMode() == QAbstractItemView::ExtendedSelection)
//st |= ExtSelectable;
//}
//if (m_role == QAccessible::TreeItem) {
// const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
// if (treeView->isExpanded(m_index))
// st |= Expanded;
//}
st |= HasInvokeExtension;
return st;
}
//Done
bool KItemListWidgetAccessible::isExpandable() const
{
return false; //view->model()->hasChildren(m_index);
}
//Done
QRect KItemListWidgetAccessible::rect(int child) const
{
Q_ASSERT(child == 0);
//QRect r;
//r = view->visualRect(m_index);
//if (!r.isNull())
// r.translate(view->viewport()->mapTo(view, QPoint(0,0)));
// r.translate(view->mapToGlobal(QPoint(0, 0)));
return widget->textRect().toRect();
}
//Done
QString KItemListWidgetAccessible::text(Text t, int child) const
{
Q_ASSERT(child == 0);
QHash<QByteArray, QVariant> data = widget->data();
switch (t) {
case QAccessible::Value:
case QAccessible::Name:
return data["text"].toString();
case QAccessible::Description:
return data["text"].toString() + " : " + data["group"].toString();
default:
break;
}
return "";
}
//Done
void KItemListWidgetAccessible::setText(QAccessible::Text /*t*/, int child, const QString &text)
{
Q_ASSERT(child == 0);
(widget->data())["text"]=QVariant(text);
}
//Done
bool KItemListWidgetAccessible::isValid() const
{
if (index <= 0) {
qDebug() << "Interface is not valid";
}
return index > 0;
}
int KItemListWidgetAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
{
if (relation == Ancestor && index == 1) {
//if (m_role == QAccessible::TreeItem) {
// *iface = new QAccessibleTree(view);
//} else {
*iface = new KItemListViewAccessible(view);
return 0;
}
*iface = 0;
if (!view)
return -1;
switch (relation) {
case Child: {
return -1;
}
case Sibling:
if (index > 0) {
QAccessibleInterface *parent = queryAccessibleInterface(view);
int ret = parent->navigate(QAccessible::Child, index, iface);
delete parent;
if (*iface)
return ret;
}
return -1;
// From table1 implementation:
// case Up:
// case Down:
// case Left:
// case Right: {
// // This is in the "not so nice" category. In order to find out which item
// // is geometrically around, we have to set the current index, navigate
// // and restore the index as well as the old selection
// view()->setUpdatesEnabled(false);
// const QModelIndex oldIdx = view()->currentIndex();
// QList<QModelIndex> kids = children();
// const QModelIndex currentIndex = index ? kids.at(index - 1) : QModelIndex(row);
// const QItemSelection oldSelection = view()->selectionModel()->selection();
// view()->setCurrentIndex(currentIndex);
// const QModelIndex idx = view()->moveCursor(toCursorAction(relation), Qt::NoModifier);
// view()->setCurrentIndex(oldIdx);
// view()->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect);
// view()->setUpdatesEnabled(true);
// if (!idx.isValid())
// return -1;
// if (idx.parent() != row.parent() || idx.row() != row.row())
// *iface = cell(idx);
// return index ? kids.indexOf(idx) + 1 : 0; }
default:
break;
}
return -1;
}
QAccessible::Relation KItemListWidgetAccessible::relationTo(int child, const QAccessibleInterface *, int otherChild) const
{
Q_ASSERT(child == 0);
Q_ASSERT(otherChild == 0);
/* we only check for parent-child relationships in trees
if (m_role == QAccessible::TreeItem && other->role(0) == QAccessible::TreeItem) {
QModelIndex otherIndex = static_cast<const QAccessibleTable2Cell*>(other)->m_index;
// is the other our parent?
if (otherIndex.parent() == m_index)
return QAccessible::Ancestor;
// are we the other's child?
if (m_index.parent() == otherIndex)
return QAccessible::Child;
}*/
return QAccessible::Unrelated;
}
#ifndef QT_NO_ACTION
int KItemListWidgetAccessible::userActionCount(int) const
{
return 0;
}
QString KItemListWidgetAccessible::actionText(int, Text, int) const
{
return QString();
}
bool KItemListWidgetAccessible::doAction(int, int, const QVariantList &)
{
return false;
}
#endif
KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer *container)
: QAccessibleWidgetEx(container)
, m_container(container)
{}
KItemListContainerAccessible::~KItemListContainerAccessible ()
{}
int KItemListContainerAccessible::childCount () const
{
return 1;
}
int KItemListContainerAccessible::indexOfChild ( const QAccessibleInterface * child ) const
{
if(child == QAccessible::queryAccessibleInterface(m_container->controller()->view()))
return 1;
return -1;
}
bool KItemListContainerAccessible::isValid () const
{
return true;
}
int KItemListContainerAccessible::navigate ( QAccessible::RelationFlag relation, int index, QAccessibleInterface ** target ) const
{
if (relation == QAccessible::Child) {
*target = new KItemListViewAccessible(m_container->controller()->view());
return 0;
}
return QAccessibleWidgetEx::navigate(relation, index, target);
}
QObject *KItemListContainerAccessible::object() const
{
return m_container;
}
QRect KItemListContainerAccessible::rect ( int child ) const
{
if(child){
KItemListViewAccessible *iface = static_cast<KItemListViewAccessible* >(QAccessible::queryAccessibleInterface(m_container->controller()->view()));
return iface->rect(0);
}
return m_container->frameRect();
}
QAccessible::Relation KItemListContainerAccessible::relationTo ( int , const QAccessibleInterface *, int ) const
{
return QAccessible::Unrelated;
}
QAccessible::Role KItemListContainerAccessible::role ( int child ) const
{
if(child)
return QAccessible::Table;
return QAccessible::Pane;
}
QAccessible::State KItemListContainerAccessible::state ( int child ) const
{
return Normal | HasInvokeExtension;
}
QString KItemListContainerAccessible::text ( QAccessible::Text, int ) const
{
return "";
}
#endif // QT_NO_ITEMVIEWS
#endif // QT_NO_ACCESSIBILITY
|