X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/9def70cf8bd1bb11cbecbd637b747b0fa6daf600..fc4315d57e8fe64d05aad2a1c24800f0149b21da:/src/kitemviews/kitemlistviewaccessible.cpp diff --git a/src/kitemviews/kitemlistviewaccessible.cpp b/src/kitemviews/kitemlistviewaccessible.cpp index 1d1974820..d9ddd58f8 100644 --- a/src/kitemviews/kitemlistviewaccessible.cpp +++ b/src/kitemviews/kitemlistviewaccessible.cpp @@ -1,97 +1,115 @@ +/*************************************************************************** + * Copyright (C) 2012 by Amandeep Singh * + * * + * 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 #include +#include +#include + #include #include -#ifndef QT_NO_ACCESSIBILITY - -#ifndef QT_NO_ITEMVIEWS - -KItemListView *KItemListViewAccessible::view() const +KItemListView* KItemListViewAccessible::view() const { return qobject_cast(object()); } -KItemListViewAccessible::KItemListViewAccessible(KItemListView *view_) - : QAccessibleObjectEx(view_) +KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) : + QAccessibleObjectEx(view_) { Q_ASSERT(view()); - - /*if (qobject_cast(view())) { - m_role = QAccessible::Table; - } else if (qobject_cast(view())) { - m_role = QAccessible::Tree; - } else if (qobject_cast(view())) { - m_role = QAccessible::List; - } else { - // is this our best guess? - m_role = QAccessible::Table; - }*/ } -KItemListViewAccessible::~KItemListViewAccessible() +void KItemListViewAccessible::modelReset() { } -void KItemListViewAccessible::modelReset() -{} - -QAccessibleTable2CellInterface *KItemListViewAccessible::cell(int index) const +QAccessible::Role KItemListViewAccessible::cellRole() const { - if (index > 0) - return new KItemListAccessibleCell(view(), index); - return 0; + return QAccessible::Cell; } -QAccessibleTable2CellInterface *KItemListViewAccessible::cellAt(int row, int column) const +QAccessibleTable2CellInterface* 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(); + if (index < 0 || index >= view()->model()->count()) { return 0; + } else { + return new KItemListAccessibleCell(view(), index); } - return cell(index);*/ - Q_UNUSED(row) - Q_UNUSED(column) - return cell(1); +} + +QVariant KItemListViewAccessible::invokeMethodEx(Method, int, const QVariantList&) +{ + return QVariant(); +} +QAccessibleTable2CellInterface* KItemListViewAccessible::cellAt(int row, int column) const +{ + return cell(columnCount() * row + column); } -QAccessibleInterface *KItemListViewAccessible::caption() const +QAccessibleInterface* KItemListViewAccessible::caption() const { return 0; } QString KItemListViewAccessible::columnDescription(int) const { - // FIXME: no i18n - return QObject::tr("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 @@ -106,7 +124,7 @@ int KItemListViewAccessible::selectedRowCount() const QString KItemListViewAccessible::rowDescription(int) const { - return "No Row Description"; + return QString(); } QList KItemListViewAccessible::selectedCells() const @@ -120,201 +138,172 @@ QList KItemListViewAccessible::selectedCells() QList KItemListViewAccessible::selectedColumns() const { - QList columns; - /*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedColumns()) { - columns.append(index.column()); - }*/ - return columns; + return QList(); } QList KItemListViewAccessible::selectedRows() const { - QList rows; - /*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedRows()) { - rows.append(index.row()); - }*/ - return rows; + return QList(); } -QAccessibleInterface *KItemListViewAccessible::summary() const +QAccessibleInterface* KItemListViewAccessible::summary() const { return 0; } 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 + change.lastRow = rowCount(); + change.lastColumn = columnCount(); return change; } QAccessible::Role KItemListViewAccessible::role(int child) const { Q_ASSERT(child >= 0); - if (child > 0) + + if (child > 0) { return QAccessible::Cell; - return QAccessible::Table; + } else { + return QAccessible::Table; + } } QAccessible::State KItemListViewAccessible::state(int child) const { - Q_ASSERT(child == 0); - return QAccessible::Normal; + if (child) { + QAccessibleInterface* interface = 0; + navigate(Child, child, &interface); + if (interface) { + return interface->state(0); + } + } + + return QAccessible::Normal | QAccessible::HasInvokeExtension; } int KItemListViewAccessible::childAt(int x, int y) const { - QPointF point = QPointF(x,y); + const QPointF point = QPointF(x,y); return view()->itemAt(view()->mapFromScene(point)); } int KItemListViewAccessible::childCount() const { - return rowCount() * columnCount(); + return view()->model()->count(); } -int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *iface) const +int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* interface) 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(iface); - return logicalIndex(cell->m_index); - } else if (iface->role(0) == QAccessible::ColumnHeader){ - const QAccessibleTable2HeaderCell* cell = static_cast(iface); - return cell->index + (verticalHeader() ? 1 : 0) + 1; - } else if (iface->role(0) == QAccessible::RowHeader){ - const QAccessibleTable2HeaderCell* cell = static_cast(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 KItemListAccessibleCell *widget = static_cast(iface); - return widget->getIndex(); + const KItemListAccessibleCell* widget = static_cast(interface); + return widget->index() + 1; } -QString KItemListViewAccessible::text(Text t, int child) const +QString KItemListViewAccessible::text(Text, int child) const { Q_ASSERT(child == 0); - // FIXME: I don't think this is needed, but if at all it needs i18n - if (t == QAccessible::Description) - return QObject::tr("List of files present in the current directory"); - return QObject::tr("File List"); + return QString(); } QRect KItemListViewAccessible::rect(int child) const { Q_UNUSED(child) - if (!view()->isVisible()) + if (!view()->isVisible()) { return QRect(); - // FIXME: map to global - return view()->rect().toRect(); + } + + const QGraphicsScene* scene = view()->scene(); + if (scene) { + const QPoint origin = scene->views()[0]->mapToGlobal(QPoint(0, 0)); + const QRect viewRect = view()->geometry().toRect(); + return viewRect.translated(origin); + } else { + return QRect(); + } } -int KItemListViewAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const +int KItemListViewAccessible::navigate(RelationFlag relation, int index, QAccessibleInterface** interface) const { - *iface = 0; + *interface = 0; + switch (relation) { - /*case Ancestor: { - if (index == 1 && view()->parent()) { - *iface = QAccessible::queryAccessibleInterface(view()->parent()); - if (*iface) - return 0; - } - break; - }*/ - case QAccessible::Child: { + case QAccessible::Child: Q_ASSERT(index > 0); - *iface = cell(index); - if (*iface) { + *interface = cell(index - 1); + if (*interface) { return 0; } break; - } + default: break; } + return -1; } -QAccessible::Relation KItemListViewAccessible::relationTo(int, const QAccessibleInterface *, int) const +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 &) + +bool KItemListViewAccessible::doAction(int, int, const QVariantList&) { return false; } + #endif -// TABLE CELL +// Table Cell -KItemListAccessibleCell::KItemListAccessibleCell(KItemListView *view_, int index_) - : /* QAccessibleSimpleEditableTextInterface(this), */ view(view_) - , index(index_) +KItemListAccessibleCell::KItemListAccessibleCell(KItemListView* view, int index) : + m_view(view), + m_index(index) { - Q_ASSERT(index_ > 0); + Q_ASSERT(index >= 0 && index < view->model()->count()); } int KItemListAccessibleCell::columnExtent() const @@ -329,51 +318,34 @@ int KItemListAccessibleCell::rowExtent() const QList KItemListAccessibleCell::rowHeaderCells() const { - QList headerCell; - /*if (verticalHeader()) { - headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.row(), Qt::Vertical)); - }*/ - return headerCell; + return QList(); } QList KItemListAccessibleCell::columnHeaderCells() const { - QList headerCell; - /*if (horizontalHeader()) { - headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.column(), Qt::Horizontal)); - }*/ - return headerCell; + return QList(); } int KItemListAccessibleCell::columnIndex() const { - return view->layouter()->itemColumn(index); + return m_view->m_layouter->itemColumn(m_index); } int KItemListAccessibleCell::rowIndex() const { - /*if (role(0) == QAccessible::TreeItem) { - const QTreeView *treeView = qobject_cast(view); - Q_ASSERT(treeView); - int row = treeView->d_func()->viewIndex(m_index); - return row; - }*/ - return view->layouter()->itemRow(index); + return m_view->m_layouter->itemRow(m_index); } -//Done bool KItemListAccessibleCell::isSelected() const { - //return widget->isSelected(); - // FIXME - return false; + return m_view->controller()->selectionManager()->isSelected(m_index); } -void KItemListAccessibleCell::rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const +void KItemListAccessibleCell::rowColumnExtents(int* row, int* column, int* rowExtents, int* columnExtents, bool* selected) const { - KItemListViewLayouter* layouter = view->layouter(); - *row = layouter->itemRow(index); - *column = layouter->itemColumn(index); + const KItemListViewLayouter* layouter = m_view->m_layouter; + *row = layouter->itemRow(m_index); + *column = layouter->itemColumn(m_index); *rowExtents = 1; *columnExtents = 1; *selected = isSelected(); @@ -381,7 +353,7 @@ void KItemListAccessibleCell::rowColumnExtents(int *row, int *column, int *rowEx QAccessibleTable2Interface* KItemListAccessibleCell::table() const { - return QAccessible::queryAccessibleInterface(view)->table2Interface(); + return QAccessible::queryAccessibleInterface(m_view)->table2Interface(); } QAccessible::Role KItemListAccessibleCell::role(int child) const @@ -393,171 +365,117 @@ QAccessible::Role KItemListAccessibleCell::role(int child) const QAccessible::State KItemListAccessibleCell::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(view); - // if (treeView->isExpanded(m_index)) - // st |= Expanded; - //} - - return st; -} - -//Done + QAccessible::State state = Normal; + + if (isSelected()) { + state |= Selected; + } + + if (m_view->controller()->selectionManager()->currentItem() == m_index) { + state |= Focused; + } + + state |= Selectable; + state |= Focusable; + + if (m_view->controller()->selectionBehavior() == KItemListController::MultiSelection) { + state |= MultiSelectable; + } + + if (m_view->model()->isExpandable(m_index)) { + if (m_view->model()->isExpanded(m_index)) { + state |= Expanded; + } else { + state |= Collapsed; + } + } + + return state; +} + bool KItemListAccessibleCell::isExpandable() const { - return false; //view->model()->hasChildren(m_index); + return m_view->model()->isExpandable(m_index); } -//Done -QRect KItemListAccessibleCell::rect(int child) const +QRect KItemListAccessibleCell::rect(int) const { - // Q_ASSERT(child == 0); - return QRect(); - - // FIXME + 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; } QString KItemListAccessibleCell::text(QAccessible::Text t, int child) const { - //Q_ASSERT(child == 0) + Q_ASSERT(child == 0); Q_UNUSED(child) - QHash data = view->model()->data(index); + switch (t) { case QAccessible::Value: - case QAccessible::Name: + case QAccessible::Name: { + const QHash data = m_view->model()->data(m_index); return data["text"].toString(); - case QAccessible::Description: - return data["text"].toString() + " : " + data["group"].toString(); + } + default: break; } + return QString(); } -void KItemListAccessibleCell::setText(QAccessible::Text /*t*/, int child, const QString &text) +void KItemListAccessibleCell::setText(QAccessible::Text, int child, const QString&) { Q_ASSERT(child == 0); - // FIXME - is this even allowed on the KItemListWidget? } bool KItemListAccessibleCell::isValid() const { - if (index <= 0) { - kDebug() << "Interface is not valid"; - } - - return index > 0; + return m_view && (m_index >= 0) && (m_index < m_view->model()->count()); } -int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const +int KItemListAccessibleCell::childAt(int, int) 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 0; +} - switch (relation) { +int KItemListAccessibleCell::childCount() const +{ + return 0; +} - 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; +int KItemListAccessibleCell::indexOfChild(const QAccessibleInterface* child) const +{ + Q_UNUSED(child); + 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 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::navigate(RelationFlag relation, int index, QAccessibleInterface** interface) const +{ + if (relation == Ancestor && index == 1) { + *interface = new KItemListViewAccessible(m_view); + return 0; } + *interface = 0; return -1; } -QAccessible::Relation KItemListAccessibleCell::relationTo(int child, const QAccessibleInterface *, int otherChild) const +QAccessible::Relation KItemListAccessibleCell::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(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 KItemListAccessibleCell::userActionCount(int) const { return 0; @@ -568,41 +486,60 @@ QString KItemListAccessibleCell::actionText(int, Text, int) const return QString(); } -bool KItemListAccessibleCell::doAction(int, int, const QVariantList &) +bool KItemListAccessibleCell::doAction(int, int, const QVariantList&) { return false; } #endif -KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer *container) - : QAccessibleWidgetEx(container) -{} +int KItemListAccessibleCell::index() const +{ + return m_index; +} -KItemListContainerAccessible::~KItemListContainerAccessible () -{} +QObject* KItemListAccessibleCell::object() const +{ + return 0; +} + +// Container Interface +KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer* container) : + QAccessibleWidgetEx(container) +{ +} + +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())) + if (child->object() == container()->controller()->view()) { return 1; - return -1; + } else { + return -1; + } } -int KItemListContainerAccessible::navigate ( QAccessible::RelationFlag relation, int index, QAccessibleInterface ** target ) const +int KItemListContainerAccessible::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface** target) const { if (relation == QAccessible::Child) { *target = new KItemListViewAccessible(container()->controller()->view()); return 0; + } else { + return QAccessibleWidgetEx::navigate(relation, index, target); } - return QAccessibleWidgetEx::navigate(relation, index, target); } -#endif // QT_NO_ITEMVIEWS +const KItemListContainer* KItemListContainerAccessible::container() const +{ + return qobject_cast(object()); +} #endif // QT_NO_ACCESSIBILITY