]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistviewaccessible.cpp
Fix selection rect after porting from QFontMetrics::width()
[dolphin.git] / src / kitemviews / kitemlistviewaccessible.cpp
index 7ec72dcf672029e0d068a14021b322457091f527..0188408a7241b3e5fa0c6ca7a2268f320ed70ca7 100644 (file)
+/***************************************************************************
+ *   Copyright (C) 2012 by Amandeep Singh <aman.dedman@gmail.com>          *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef QT_NO_ACCESSIBILITY
+
 #include "kitemlistviewaccessible.h"
+
+#include "kitemlistcontainer.h"
 #include "kitemlistcontroller.h"
 #include "kitemlistselectionmanager.h"
+#include "kitemlistview.h"
 #include "private/kitemlistviewlayouter.h"
 
-#include <QtGui/qtableview.h>
-#include <QtGui/qaccessible2.h>
-#include <KDebug>
-
-#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
-  ...
-*/
+#include <QGraphicsScene>
+#include <QGraphicsView>
 
-KItemListView *KItemListViewAccessible::view() const
+KItemListViewKItemListViewAccessible::view() const
 {
     return qobject_cast<KItemListView*>(object());
 }
 
-KItemListViewAccessible::KItemListViewAccessible(KItemListView *view_)
-    : QAccessibleObjectEx(view_)
+KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) :
+    QAccessibleObject(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;
-    }*/
+    m_cells.resize(childCount());
 }
 
 KItemListViewAccessible::~KItemListViewAccessible()
 {
+    foreach (AccessibleIdWrapper idWrapper, m_cells) {
+        if (idWrapper.isValid) {
+            QAccessible::deleteAccessibleInterface(idWrapper.id);
+        }
+    }
 }
 
-void KItemListViewAccessible::modelReset()
-{}
+void* KItemListViewAccessible::interface_cast(QAccessible::InterfaceType type)
+{
+    if (type == QAccessible::TableInterface) {
+        return static_cast<QAccessibleTableInterface*>(this);
+    }
+    return nullptr;
+}
 
-QAccessibleTable2CellInterface *KItemListViewAccessible::cell(int index) const
+void KItemListViewAccessible::modelReset()
 {
-    if (index > 0)
-        return new KItemListWidgetAccessible(view(), index);
-    return 0;
 }
 
-QAccessibleTable2CellInterface *KItemListViewAccessible::cellAt(int row, int column) const
+QAccessibleInterface* KItemListViewAccessible::cell(int index) 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;
+    if (index < 0 || index >= view()->model()->count()) {
+        return nullptr;
+    }
+
+    if (m_cells.size() <= index) {
+        m_cells.resize(childCount());
     }
-    return cell(index);*/
-    Q_UNUSED(row)
-    Q_UNUSED(column)
-    return cell(1);
+    Q_ASSERT(index < m_cells.size());
 
+    AccessibleIdWrapper idWrapper = m_cells.at(index);
+    if (!idWrapper.isValid) {
+        idWrapper.id = QAccessible::registerAccessibleInterface(new KItemListAccessibleCell(view(), index));
+        idWrapper.isValid = true;
+        m_cells.insert(index, idWrapper);
+    }
+    return QAccessible::accessibleInterface(idWrapper.id);
 }
 
-QAccessibleInterface *KItemListViewAccessible::caption() const
+QAccessibleInterface* KItemListViewAccessible::cellAt(int row, int column) const
 {
-    return 0;
+    return cell(columnCount() * row + column);
+}
+
+QAccessibleInterface* KItemListViewAccessible::caption() const
+{
+    return nullptr;
 }
 
 QString KItemListViewAccessible::columnDescription(int) const
 {
-    // FIXME: no i18n
-    return "No Column Description";
+    return QString();
 }
 
 int KItemListViewAccessible::columnCount() const
 {
-    return view()->layouter()->columnCount();
+    return view()->m_layouter->columnCount();
 }
 
 int KItemListViewAccessible::rowCount() const
 {
+    if (columnCount() <= 0) {
+        return 0;
+    }
+
     int itemCount = view()->model()->count();
     int rowCount = itemCount / columnCount();
-    if (itemCount % rowCount)
+
+    if (rowCount <= 0) {
+        return 0;
+    }
+
+    if (itemCount % columnCount()) {
         ++rowCount;
+    }
     return rowCount;
 }
 
 int KItemListViewAccessible::selectedCellCount() const
 {
-    return view()->controller()->selectionManager()->selectedItems().size();
+    return view()->controller()->selectionManager()->selectedItems().count();
 }
 
 int KItemListViewAccessible::selectedColumnCount() const
@@ -115,13 +139,15 @@ int KItemListViewAccessible::selectedRowCount() const
 
 QString KItemListViewAccessible::rowDescription(int) const
 {
-    return "No Row Description";
+    return QString();
 }
 
-QList<QAccessibleTable2CellInterface*> KItemListViewAccessible::selectedCells() const
+QList<QAccessibleInterface*> KItemListViewAccessible::selectedCells() const
 {
-    QList<QAccessibleTable2CellInterface*> cells;
-    Q_FOREACH (int index, view()->controller()->selectionManager()->selectedItems()) {
+    QList<QAccessibleInterface*> cells;
+    const auto items = view()->controller()->selectionManager()->selectedItems();
+    cells.reserve(items.count());
+    for (int index : items) {
         cells.append(cell(index));
     }
     return cells;
@@ -129,478 +155,325 @@ QList<QAccessibleTable2CellInterface*> KItemListViewAccessible::selectedCells()
 
 QList<int> KItemListViewAccessible::selectedColumns() const
 {
-    QList<int> columns;
-    /*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedColumns()) {
-        columns.append(index.column());
-    }*/
-    return columns;
+    return QList<int>();
 }
 
 QList<int> KItemListViewAccessible::selectedRows() const
 {
-    QList<int> rows;
-    /*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedRows()) {
-        rows.append(index.row());
-    }*/
-    return rows;
+    return QList<int>();
 }
 
-QAccessibleInterface *KItemListViewAccessible::summary() const
+QAccessibleInterfaceKItemListViewAccessible::summary() const
 {
-    return 0;
+    return nullptr;
 }
 
 bool KItemListViewAccessible::isColumnSelected(int) const
 {
-    return false; //view()->selectionModel()->isColumnSelected(column, QModelIndex());
+    return false;
 }
 
 bool KItemListViewAccessible::isRowSelected(int) const
 {
-    return false; //view()->selectionModel()->isRowSelected(row, QModelIndex());
+    return false;
 }
 
 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;
-}
+void KItemListViewAccessible::modelChange(QAccessibleTableModelChangeEvent* /*event*/)
+{}
 
-QAccessible::Role KItemListViewAccessible::role(int child) const
+QAccessible::Role KItemListViewAccessible::role() const
 {
-    Q_ASSERT(child >= 0);
-    if (child > 0)
-        return QAccessible::Cell;
     return QAccessible::Table;
 }
 
-QAccessible::State KItemListViewAccessible::state(int child) const
+QAccessible::State KItemListViewAccessible::state() const
 {
-    Q_ASSERT(child == 0);
-    return QAccessible::Normal | HasInvokeExtension;
+    QAccessible::State s;
+    return s;
 }
 
-int KItemListViewAccessible::childAt(int x, int y) const
+QAccessibleInterface* KItemListViewAccessible::childAt(int x, int y) const
 {
-    QPointF point = QPointF(x,y);
-    return view()->itemAt(view()->mapFromScene(point));
+    const QPointF point = QPointF(x, y);
+    int itemIndex = view()->itemAt(view()->mapFromScene(point));
+    return child(itemIndex);
 }
 
-int KItemListViewAccessible::childCount() const
+QAccessibleInterface* KItemListViewAccessible::parent() const
 {
-    return rowCount() * columnCount();
+    // FIXME: return KItemListContainerAccessible here
+    return nullptr;
 }
 
-int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *iface) const
+int KItemListViewAccessible::childCount() 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();
+    return view()->model()->count();
 }
 
-QString KItemListViewAccessible::text(Text t, int child) const
+int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* interface) const
 {
-    Q_ASSERT(child == 0);
-    if (t == QAccessible::Description)
-        return "List of files present in the current directory";
-    return "File List";
+    const KItemListAccessibleCell* widget = static_cast<const KItemListAccessibleCell*>(interface);
+    return widget->index();
 }
 
-QRect KItemListViewAccessible::rect(int child) const
+QString KItemListViewAccessible::text(QAccessible::Text) const
 {
-    Q_UNUSED(child)
-    if (!view()->isVisible())
-        return QRect();
-    return view()->geometry().toRect();
+    return QString();
 }
 
-int KItemListViewAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
+QRect KItemListViewAccessible::rect() 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;
+    if (!view()->isVisible()) {
+        return QRect();
     }
-    default:
-        break;
+
+    const QGraphicsScene* scene = view()->scene();
+    if (scene) {
+        const QPoint origin = scene->views().at(0)->mapToGlobal(QPoint(0, 0));
+        const QRect viewRect = view()->geometry().toRect();
+        return viewRect.translated(origin);
+    } else {
+        return QRect();
     }
-    return -1;
 }
 
-QAccessible::Relation KItemListViewAccessible::relationTo(int, const QAccessibleInterface *, int) const
+QAccessibleInterface* KItemListViewAccessible::child(int index) const
 {
-    return QAccessible::Unrelated;
+    if (index >= 0 && index < childCount()) {
+        return cell(index);
+    }
+    return nullptr;
 }
 
-#ifndef QT_NO_ACTION
-int KItemListViewAccessible::userActionCount(int) const
+KItemListViewAccessible::AccessibleIdWrapper::AccessibleIdWrapper() :
+    isValid(false),
+    id(0)
 {
-    return 0;
 }
-QString KItemListViewAccessible::actionText(int, Text, int) const
+
+// Table Cell
+
+KItemListAccessibleCell::KItemListAccessibleCell(KItemListView* view, int index) :
+    m_view(view),
+    m_index(index)
 {
-    return QString();
+    Q_ASSERT(index >= 0 && index < view->model()->count());
 }
-bool KItemListViewAccessible::doAction(int, int, const QVariantList &)
+
+void* KItemListAccessibleCell::interface_cast(QAccessible::InterfaceType type)
 {
-    return false;
+    if (type == QAccessible::TableCellInterface) {
+        return static_cast<QAccessibleTableCellInterface*>(this);
+    }
+    return nullptr;
 }
-#endif
 
-// TABLE CELL
-
-KItemListWidgetAccessible::KItemListWidgetAccessible(KItemListView *view_, int index_)
-    : /* QAccessibleSimpleEditableTextInterface(this), */ view(view_), index(index_)
+int KItemListAccessibleCell::columnExtent() const
 {
-    Q_ASSERT(index_>0);
+    return 1;
 }
 
-int KItemListWidgetAccessible::columnExtent() const { return 1; }
-int KItemListWidgetAccessible::rowExtent() const { return 1; }
-
-QList<QAccessibleInterface*> KItemListWidgetAccessible::rowHeaderCells() const
+int KItemListAccessibleCell::rowExtent() const
 {
-    QList<QAccessibleInterface*> headerCell;
-    /*if (verticalHeader()) {
-        headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.row(), Qt::Vertical));
-    }*/
-    return headerCell;
+    return 1;
 }
 
-QList<QAccessibleInterface*> KItemListWidgetAccessible::columnHeaderCells() const
+QList<QAccessibleInterface*> KItemListAccessibleCell::rowHeaderCells() const
 {
-    QList<QAccessibleInterface*> headerCell;
-    /*if (horizontalHeader()) {
-        headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.column(), Qt::Horizontal));
-    }*/
-    return headerCell;
+    return QList<QAccessibleInterface*>();
 }
 
-int KItemListWidgetAccessible::columnIndex() const
+QList<QAccessibleInterface*> KItemListAccessibleCell::columnHeaderCells() const
 {
-    return view->layouter()->itemColumn(index);
+    return QList<QAccessibleInterface*>();
 }
 
-int KItemListWidgetAccessible::rowIndex() const
+int KItemListAccessibleCell::columnIndex() 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);
+    return m_view->m_layouter->itemColumn(m_index);
 }
 
-//Done
-bool KItemListWidgetAccessible::isSelected() const
+int KItemListAccessibleCell::rowIndex() const
 {
-    return widget->isSelected();
+    return m_view->m_layouter->itemRow(m_index);
 }
 
-void KItemListWidgetAccessible::rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const
+bool KItemListAccessibleCell::isSelected() const
 {
-    KItemListViewLayouter* layouter = view->layouter();
-    *row = layouter->itemRow(index);
-    *column = layouter->itemColumn(index);
-    *rowExtents = 1;
-    *columnExtents = 1;
-    *selected = isSelected();
+    return m_view->controller()->selectionManager()->isSelected(m_index);
 }
 
-QAccessibleTable2Interface* KItemListWidgetAccessible::table() const
+QAccessibleInterface* KItemListAccessibleCell::table() const
 {
-    return QAccessible::queryAccessibleInterface(view)->table2Interface();
+    return QAccessible::queryAccessibleInterface(m_view);
 }
 
-QAccessible::Role KItemListWidgetAccessible::role(int child) const
+QAccessible::Role KItemListAccessibleCell::role() const
 {
-    Q_ASSERT(child == 0);
     return QAccessible::Cell;
 }
 
-QAccessible::State KItemListWidgetAccessible::state(int child) const
+QAccessible::State KItemListAccessibleCell::state() const
 {
-    Q_ASSERT(child == 0);
-    QAccessible::State st = Normal;
+    QAccessible::State state;
 
-    //QRect globalRect = view->rect();
-    //globalRect.translate(view->mapToGlobal(QPoint(0,0)));
-    //if (!globalRect.intersects(rect(0)))
-    //    st |= Invisible;
+    state.selectable = true;
+    if (isSelected()) {
+        state.selected = true;
+    }
 
-    if (widget->isSelected())
-        st |= Selected;
-    if (view->controller()->selectionManager()->currentItem() == index)
-        st |= Focused;
+    state.focusable = true;
+    if (m_view->controller()->selectionManager()->currentItem() == m_index) {
+        state.focused = true;
+    }
 
-    //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 (m_view->controller()->selectionBehavior() == KItemListController::MultiSelection) {
+        state.multiSelectable = true;
+    }
 
-        //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;
-    //}
+    if (m_view->model()->isExpandable(m_index)) {
+        if (m_view->model()->isExpanded(m_index)) {
+            state.expanded = true;
+        } else {
+            state.collapsed = true;
+        }
+    }
 
-    st |= HasInvokeExtension;
-    return st;
+    return state;
 }
 
-//Done
-bool KItemListWidgetAccessible::isExpandable() const
+bool KItemListAccessibleCell::isExpandable() const
 {
-    return false; //view->model()->hasChildren(m_index);
+    return m_view->model()->isExpandable(m_index);
 }
 
-//Done
-QRect KItemListWidgetAccessible::rect(int child) const
+QRect KItemListAccessibleCell::rect() const
 {
-    Q_ASSERT(child == 0);
+    QRect rect = m_view->itemRect(m_index).toRect();
 
-    //QRect r;
-    //r = view->visualRect(m_index);
+    if (rect.isNull()) {
+        return QRect();
+    }
 
-    //if (!r.isNull())
-    //    r.translate(view->viewport()->mapTo(view, QPoint(0,0)));
-    //    r.translate(view->mapToGlobal(QPoint(0, 0)));
-    return widget->textRect().toRect();
+    rect.translate(m_view->mapToScene(QPointF(0.0, 0.0)).toPoint());
+    rect.translate(m_view->scene()->views()[0]->mapToGlobal(QPoint(0, 0)));
+    return rect;
 }
 
-//Done
-QString KItemListWidgetAccessible::text(Text t, int child) const
+QString KItemListAccessibleCell::text(QAccessible::Text t) const
 {
-    Q_ASSERT(child == 0);
-
-    QHash<QByteArray, QVariant> data = widget->data();
     switch (t) {
-    case QAccessible::Value:
-    case QAccessible::Name:
+    case QAccessible::Name: {
+        const QHash<QByteArray, QVariant> data = m_view->model()->data(m_index);
         return data["text"].toString();
-    case QAccessible::Description:
-        return data["text"].toString() + " : " + data["group"].toString();
+    }
+
     default:
         break;
     }
-    return "";
+
+    return QString();
 }
 
-//Done
-void KItemListWidgetAccessible::setText(QAccessible::Text /*t*/, int child, const QString &text)
+void KItemListAccessibleCell::setText(QAccessible::Text, const QString&)
 {
-    Q_ASSERT(child == 0);
-    (widget->data())["text"]=QVariant(text);
 }
 
-//Done
-bool KItemListWidgetAccessible::isValid() const
+QAccessibleInterface* KItemListAccessibleCell::child(int) const
 {
-    if (index <= 0) {
-        kDebug() << "Interface is not valid";
-    }
-
-    return index > 0;
+    return nullptr;
 }
 
-int KItemListWidgetAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
+bool KItemListAccessibleCell::isValid() 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;
+    return m_view && (m_index >= 0) && (m_index < m_view->model()->count());
+}
 
-    switch (relation) {
+QAccessibleInterface* KItemListAccessibleCell::childAt(int, int) const
+{
+    return nullptr;
+}
 
-    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;
-    }
+int KItemListAccessibleCell::childCount() const
+{
+    return 0;
+}
 
+int KItemListAccessibleCell::indexOfChild(const QAccessibleInterface* child) const
+{
+    Q_UNUSED(child)
     return -1;
 }
 
-QAccessible::Relation KItemListWidgetAccessible::relationTo(int child, const QAccessibleInterface *, int otherChild) const
+QAccessibleInterface* KItemListAccessibleCell::parent() 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;
+    return QAccessible::queryAccessibleInterface(m_view);
 }
 
-#ifndef QT_NO_ACTION
-int KItemListWidgetAccessible::userActionCount(int) const
+int KItemListAccessibleCell::index() const
 {
-    return 0;
+    return m_index;
 }
 
-QString KItemListWidgetAccessible::actionText(int, Text, int) const
+QObject* KItemListAccessibleCell::object() const
 {
-    return QString();
+    return nullptr;
 }
 
-bool KItemListWidgetAccessible::doAction(int, int, const QVariantList &)
+// Container Interface
+KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer* container) :
+    QAccessibleWidget(container)
 {
-    return false;
 }
 
-#endif
-
-KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer *container)
-    : QAccessibleWidgetEx(container)
-{}
-
-KItemListContainerAccessible::~KItemListContainerAccessible ()
-{}
+KItemListContainerAccessible::~KItemListContainerAccessible()
+{
+}
 
-int KItemListContainerAccessible::childCount () const
+int KItemListContainerAccessible::childCount() const
 {
     return 1;
 }
 
-int KItemListContainerAccessible::indexOfChild ( const QAccessibleInterface * child ) const
+int KItemListContainerAccessible::indexOfChild(const QAccessibleInterface* child) const
 {
-    if(child == QAccessible::queryAccessibleInterface(container()->controller()->view()))
-        return 1;
+    if (child->object() == container()->controller()->view()) {
+        return 0;
+    }
     return -1;
 }
 
-int KItemListContainerAccessible::navigate ( QAccessible::RelationFlag relation, int index, QAccessibleInterface ** target ) const
+QAccessibleInterface* KItemListContainerAccessible::child(int index) const
 {
-    if (relation == QAccessible::Child) {
-        *target = new KItemListViewAccessible(container()->controller()->view());
-        return 0;
+    if (index == 0) {
+        return QAccessible::queryAccessibleInterface(container()->controller()->view());
     }
-    return QAccessibleWidgetEx::navigate(relation, index, target);
+    return nullptr;
 }
 
-#endif // QT_NO_ITEMVIEWS
+const KItemListContainer* KItemListContainerAccessible::container() const
+{
+    return qobject_cast<KItemListContainer*>(object());
+}
 
 #endif // QT_NO_ACCESSIBILITY