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