]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistviewaccessible.cpp
Reverting KListSelectionManager, removing unneccessary a11y factories
[dolphin.git] / src / kitemviews / kitemlistviewaccessible.cpp
1 #include "kitemlistviewaccessible.h"
2 #include "kitemlistcontroller.h"
3 #include "kitemlistselectionmanager.h"
4 #include "private/kitemlistviewlayouter.h"
5 #include <klocalizedstring.h>
6
7 #include <QtGui/qtableview.h>
8 #include <QtGui/qaccessible2.h>
9 #include <qgraphicsscene.h>
10 #include <qgraphicsview.h>
11
12 #include <KDebug>
13 #include <QHash>
14
15 #ifndef QT_NO_ACCESSIBILITY
16
17 KItemListView *KItemListViewAccessible::view() const
18 {
19 return qobject_cast<KItemListView*>(object());
20 }
21
22 KItemListViewAccessible::KItemListViewAccessible(KItemListView *view_)
23 : QAccessibleObjectEx(view_)
24 {
25 Q_ASSERT(view());
26 }
27
28 KItemListViewAccessible::~KItemListViewAccessible()
29 {
30 }
31
32 void KItemListViewAccessible::modelReset()
33 {}
34
35 QAccessibleTable2CellInterface *KItemListViewAccessible::cell(int index) const
36 {
37 if (index > 0) {
38 return new KItemListAccessibleCell(view(), index);
39 }
40 return 0;
41 }
42
43 QAccessibleTable2CellInterface *KItemListViewAccessible::cellAt(int row, int column) const
44 {
45 return cell(column * (row - 1) + column) ;
46 }
47
48 QAccessibleInterface *KItemListViewAccessible::caption() const
49 {
50 return 0;
51 }
52
53 QString KItemListViewAccessible::columnDescription(int) const
54 {
55 return "";
56 }
57
58 int KItemListViewAccessible::columnCount() const
59 {
60 return view()->layouter()->columnCount();
61 }
62
63 int KItemListViewAccessible::rowCount() const
64 {
65 int itemCount = view()->model()->count();
66 int rowCount = itemCount / columnCount();
67 if (itemCount % rowCount) {
68 ++rowCount;
69 }
70 return rowCount;
71 }
72
73 int KItemListViewAccessible::selectedCellCount() const
74 {
75 return view()->controller()->selectionManager()->selectedItems().size();
76 }
77
78 int KItemListViewAccessible::selectedColumnCount() const
79 {
80 return 0;
81 }
82
83 int KItemListViewAccessible::selectedRowCount() const
84 {
85 return 0;
86 }
87
88 QString KItemListViewAccessible::rowDescription(int) const
89 {
90 return "";
91 }
92
93 QList<QAccessibleTable2CellInterface*> KItemListViewAccessible::selectedCells() const
94 {
95 QList<QAccessibleTable2CellInterface*> cells;
96 Q_FOREACH (int index, view()->controller()->selectionManager()->selectedItems()) {
97 cells.append(cell(index));
98 }
99 return cells;
100 }
101
102 QList<int> KItemListViewAccessible::selectedColumns() const
103 {
104 return QList<int>();
105 }
106
107 QList<int> KItemListViewAccessible::selectedRows() const
108 {
109 return QList<int>();
110 }
111
112 QAccessibleInterface *KItemListViewAccessible::summary() const
113 {
114 return 0;
115 }
116
117 bool KItemListViewAccessible::isColumnSelected(int) const
118 {
119 return false;
120 }
121
122 bool KItemListViewAccessible::isRowSelected(int) const
123 {
124 return false;
125 }
126
127 bool KItemListViewAccessible::selectRow(int row)
128 {
129 return true;
130 }
131
132 bool KItemListViewAccessible::selectColumn(int)
133 {
134 return true;
135 }
136
137 bool KItemListViewAccessible::unselectRow(int)
138 {
139 return true;
140 }
141
142 bool KItemListViewAccessible::unselectColumn(int)
143 {
144 return true;
145 }
146
147 QAccessible2::TableModelChange KItemListViewAccessible::modelChange() const
148 {
149 QAccessible2::TableModelChange change;
150 // FIXME
151 return change;
152 }
153
154 QAccessible::Role KItemListViewAccessible::role(int child) const
155 {
156 Q_ASSERT(child >= 0);
157 if (child > 0) {
158 return QAccessible::Cell;
159 }
160 return QAccessible::Table;
161 }
162
163 QAccessible::State KItemListViewAccessible::state(int child) const
164 {
165 if (child) {
166 QAccessibleInterface *iface;
167 navigate(Child,child,&iface);
168 if (iface) {
169 return iface->state(0);
170 }
171 }
172 return QAccessible::Normal | QAccessible::HasInvokeExtension;
173 }
174
175 int KItemListViewAccessible::childAt(int x, int y) const
176 {
177 QPointF point = QPointF(x,y);
178 return view()->itemAt(view()->mapFromScene(point));
179 }
180
181 int KItemListViewAccessible::childCount() const
182 {
183 return rowCount() * columnCount();
184 }
185
186 int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *iface) const
187 {
188 const KItemListAccessibleCell *widget = static_cast<const KItemListAccessibleCell*>(iface);
189 return widget->getIndex();
190 }
191
192 QString KItemListViewAccessible::text(Text t, int child) const
193 {
194 Q_ASSERT(child == 0);
195 if (t == QAccessible::Description) {
196 return i18n("List of files present in the current directory");
197 }
198 return i18n("File List");
199 }
200
201 QRect KItemListViewAccessible::rect(int child) const
202 {
203 Q_UNUSED(child)
204 if (!view()->isVisible()) {
205 return QRect();
206 }
207 QPoint origin = view()->scene()->views()[0]->mapToGlobal(QPoint(0, 0));
208 QRect viewRect = view()->geometry().toRect();
209 return viewRect.translated(origin);
210 }
211
212 int KItemListViewAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
213 {
214 *iface = 0;
215 switch (relation) {
216 case QAccessible::Child: {
217 Q_ASSERT(index > 0);
218 *iface = cell(index);
219 if (*iface) {
220 return 0;
221 }
222 break;
223 }
224 default:
225 break;
226 }
227 return -1;
228 }
229
230 QAccessible::Relation KItemListViewAccessible::relationTo(int, const QAccessibleInterface *, int) const
231 {
232 return QAccessible::Unrelated;
233 }
234
235 #ifndef QT_NO_ACTION
236 int KItemListViewAccessible::userActionCount(int) const
237 {
238 return 0;
239 }
240 QString KItemListViewAccessible::actionText(int, Text, int) const
241 {
242 return QString();
243 }
244 bool KItemListViewAccessible::doAction(int, int, const QVariantList &)
245 {
246 return false;
247 }
248 #endif
249
250 // TABLE CELL
251
252 KItemListAccessibleCell::KItemListAccessibleCell(KItemListView *view, int index)
253 : m_view(view)
254 , m_index(index)
255 {
256 Q_ASSERT(index > 0);
257 }
258
259 int KItemListAccessibleCell::columnExtent() const
260 {
261 return 1;
262 }
263
264 int KItemListAccessibleCell::rowExtent() const
265 {
266 return 1;
267 }
268
269 QList<QAccessibleInterface*> KItemListAccessibleCell::rowHeaderCells() const
270 {
271 return QList<QAccessibleInterface*>();
272 }
273
274 QList<QAccessibleInterface*> KItemListAccessibleCell::columnHeaderCells() const
275 {
276 return QList<QAccessibleInterface*>();
277 }
278
279 int KItemListAccessibleCell::columnIndex() const
280 {
281 return view->layouter()->itemColumn(m_index);
282 }
283
284 int KItemListAccessibleCell::rowIndex() const
285 {
286 return view->layouter()->itemRow(m_index);
287 }
288
289 bool KItemListAccessibleCell::isSelected() const
290 {
291 return view->controller()->selectionManager()->isSelected(m_index-1);
292 }
293
294 void KItemListAccessibleCell::rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const
295 {
296 KItemListViewLayouter* layouter = view->layouter();
297 *row = layouter->itemRow(m_index);
298 *column = layouter->itemColumn(m_index);
299 *rowExtents = 1;
300 *columnExtents = 1;
301 *selected = isSelected();
302 }
303
304 QAccessibleTable2Interface* KItemListAccessibleCell::table() const
305 {
306 return QAccessible::queryAccessibleInterface(view)->table2Interface();
307 }
308
309 QAccessible::Role KItemListAccessibleCell::role(int child) const
310 {
311 Q_ASSERT(child == 0);
312 return QAccessible::Cell;
313 }
314
315 QAccessible::State KItemListAccessibleCell::state(int child) const
316 {
317 Q_ASSERT(child == 0);
318 QAccessible::State st = Normal;
319
320 if (isSelected()) {
321 st |= Selected;
322 }
323 if (view->controller()->selectionManager()->currentItem() == m_index) {
324 st |= Focused;
325 }
326
327 st |= Selectable;
328 st |= Focusable;
329
330 if (view->controller()->selectionBehavior() == KItemListController::MultiSelection){
331 st |= MultiSelectable;
332 }
333
334 return st;
335 }
336
337 bool KItemListAccessibleCell::isExpandable() const
338 {
339 return false;
340 }
341
342 QRect KItemListAccessibleCell::rect(int) const
343 {
344 QRect r = view->itemRect(m_index-1).toRect();
345 if (r.isNull()) {
346 return QRect();
347 }
348 r.translate(view->mapToScene(QPointF(0.0, 0.0)).toPoint());
349 r.translate(view->scene()->views()[0]->mapToGlobal(QPoint(0, 0)));
350 return r;
351 }
352
353 QString KItemListAccessibleCell::text(QAccessible::Text t, int child) const
354 {
355 Q_ASSERT(child == 0);
356 Q_UNUSED(child)
357 const QHash<QByteArray, QVariant> data = view->model()->data(m_index-1);
358 switch (t) {
359 case QAccessible::Value:
360 case QAccessible::Name:
361 return data["text"].toString();
362 default:
363 break;
364 }
365 return QString();
366 }
367
368 void KItemListAccessibleCell::setText(QAccessible::Text /*t*/, int child, const QString &/*text*/)
369 {
370 Q_ASSERT(child == 0);
371 // FIXME - is this even allowed on the KItemListWidget?
372 }
373
374 bool KItemListAccessibleCell::isValid() const
375 {
376 return view && (m_index > 0);
377 }
378
379 int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
380 {
381 if (relation == Ancestor && index == 1) {
382 *iface = new KItemListViewAccessible(view);
383 return 0;
384 }
385
386 *iface = 0;
387 if (!view) {
388 return -1;
389 }
390
391 switch (relation) {
392
393 case Child: {
394 return -1;
395 }
396 case Sibling:
397 if (index > 0) {
398 QAccessibleInterface *parent = queryAccessibleInterface(view);
399 int ret = parent->navigate(QAccessible::Child, index, iface);
400 delete parent;
401 if (*iface) {
402 return ret;
403 }
404 }
405 return -1;
406 default:
407 break;
408 }
409
410 return -1;
411 }
412
413 QAccessible::Relation KItemListAccessibleCell::relationTo(int child, const QAccessibleInterface *, int otherChild) const
414 {
415 Q_ASSERT(child == 0);
416 Q_ASSERT(otherChild == 0);
417 return QAccessible::Unrelated;
418 }
419
420 #ifndef QT_NO_ACTION
421 int KItemListAccessibleCell::userActionCount(int) const
422 {
423 return 0;
424 }
425
426 QString KItemListAccessibleCell::actionText(int, Text, int) const
427 {
428 return QString();
429 }
430
431 bool KItemListAccessibleCell::doAction(int, int, const QVariantList &)
432 {
433 return false;
434 }
435
436 #endif
437
438 KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer *container)
439 : QAccessibleWidgetEx(container)
440 {}
441
442 KItemListContainerAccessible::~KItemListContainerAccessible ()
443 {}
444
445 int KItemListContainerAccessible::childCount () const
446 {
447 return 1;
448 }
449
450 int KItemListContainerAccessible::indexOfChild ( const QAccessibleInterface * child ) const
451 {
452 if (child->object() == container()->controller()->view()) {
453 return 1;
454 }
455 return -1;
456 }
457
458 int KItemListContainerAccessible::navigate ( QAccessible::RelationFlag relation, int index, QAccessibleInterface ** target ) const
459 {
460 if (relation == QAccessible::Child) {
461 *target = new KItemListViewAccessible(container()->controller()->view());
462 return 0;
463 }
464 return QAccessibleWidgetEx::navigate(relation, index, target);
465 }
466
467 #endif // QT_NO_ACCESSIBILITY