Remove unneccessary dependency and polish the Accessibility Interfaces

This commit is contained in:
Amandeep Singh 2012-08-13 11:11:26 +05:30
parent 6770e617cb
commit dc85bf39c9
4 changed files with 60 additions and 161 deletions

View file

@ -22,8 +22,6 @@
***************************************************************************/ ***************************************************************************/
#include "kitemlistselectionmanager.h" #include "kitemlistselectionmanager.h"
#include "kitemlistcontroller.h"
#include "kitemlistview.h"
#include "kitemmodelbase.h" #include "kitemmodelbase.h"
#include <KDebug> #include <KDebug>
#include <QAccessible> #include <QAccessible>
@ -63,8 +61,6 @@ void KItemListSelectionManager::setCurrentItem(int current)
} }
} }
} }
KItemListController *controller = static_cast<KItemListController*>(parent());
QAccessible::updateAccessibility(controller->view(), current+1, QAccessible::Focus);
} }
int KItemListSelectionManager::currentItem() const int KItemListSelectionManager::currentItem() const

View file

@ -1267,6 +1267,7 @@ void KItemListView::slotCurrentChanged(int current, int previous)
if (currentWidget) { if (currentWidget) {
currentWidget->setCurrent(true); currentWidget->setCurrent(true);
} }
QAccessible::updateAccessibility(this, current+1, QAccessible::Focus);
} }
void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous) void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)

View file

@ -24,17 +24,6 @@ KItemListViewAccessible::KItemListViewAccessible(KItemListView *view_)
: QAccessibleObjectEx(view_) : QAccessibleObjectEx(view_)
{ {
Q_ASSERT(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() KItemListViewAccessible::~KItemListViewAccessible()
@ -46,21 +35,14 @@ void KItemListViewAccessible::modelReset()
QAccessibleTable2CellInterface *KItemListViewAccessible::cell(int index) const QAccessibleTable2CellInterface *KItemListViewAccessible::cell(int index) const
{ {
if (index > 0) if (index > 0) {
return new KItemListAccessibleCell(view(), index); return new KItemListAccessibleCell(view(), index);
}
return 0; return 0;
} }
QAccessibleTable2CellInterface *KItemListViewAccessible::cellAt(int row, int column) const 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);*/
return cell(column * (row - 1) + column) ; return cell(column * (row - 1) + column) ;
} }
@ -83,8 +65,9 @@ int KItemListViewAccessible::rowCount() const
{ {
int itemCount = view()->model()->count(); int itemCount = view()->model()->count();
int rowCount = itemCount / columnCount(); int rowCount = itemCount / columnCount();
if (itemCount % rowCount) if (itemCount % rowCount) {
++rowCount; ++rowCount;
}
return rowCount; return rowCount;
} }
@ -119,20 +102,12 @@ QList<QAccessibleTable2CellInterface*> KItemListViewAccessible::selectedCells()
QList<int> KItemListViewAccessible::selectedColumns() const QList<int> KItemListViewAccessible::selectedColumns() const
{ {
QList<int> columns; return QList<int>();
/*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedColumns()) {
columns.append(index.column());
}*/
return columns;
} }
QList<int> KItemListViewAccessible::selectedRows() const QList<int> KItemListViewAccessible::selectedRows() const
{ {
QList<int> rows; return QList<int>();
/*Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedRows()) {
rows.append(index.row());
}*/
return rows;
} }
QAccessibleInterface *KItemListViewAccessible::summary() const QAccessibleInterface *KItemListViewAccessible::summary() const
@ -180,18 +155,20 @@ QAccessible2::TableModelChange KItemListViewAccessible::modelChange() const
QAccessible::Role KItemListViewAccessible::role(int child) const QAccessible::Role KItemListViewAccessible::role(int child) const
{ {
Q_ASSERT(child >= 0); Q_ASSERT(child >= 0);
if (child > 0) if (child > 0) {
return QAccessible::Cell; return QAccessible::Cell;
}
return QAccessible::Table; return QAccessible::Table;
} }
QAccessible::State KItemListViewAccessible::state(int child) const QAccessible::State KItemListViewAccessible::state(int child) const
{ {
if(child){ if (child) {
QAccessibleInterface *iface; QAccessibleInterface *iface;
navigate(Child,child,&iface); navigate(Child,child,&iface);
if(iface) if (iface) {
return iface->state(0); return iface->state(0);
}
} }
return QAccessible::Normal | QAccessible::HasInvokeExtension; return QAccessible::Normal | QAccessible::HasInvokeExtension;
} }
@ -209,25 +186,6 @@ int KItemListViewAccessible::childCount() const
int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *iface) const 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 KItemListAccessibleCell *widget = static_cast<const KItemListAccessibleCell*>(iface); const KItemListAccessibleCell *widget = static_cast<const KItemListAccessibleCell*>(iface);
return widget->getIndex(); return widget->getIndex();
} }
@ -235,17 +193,18 @@ int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *iface) con
QString KItemListViewAccessible::text(Text t, int child) const QString KItemListViewAccessible::text(Text t, int child) const
{ {
Q_ASSERT(child == 0); Q_ASSERT(child == 0);
// FIXME: I don't think this is needed, but if at all it needs i18n if (t == QAccessible::Description) {
if (t == QAccessible::Description)
return QObject::tr("List of files present in the current directory"); return QObject::tr("List of files present in the current directory");
}
return QObject::tr("File List"); return QObject::tr("File List");
} }
QRect KItemListViewAccessible::rect(int child) const QRect KItemListViewAccessible::rect(int child) const
{ {
Q_UNUSED(child) Q_UNUSED(child)
if (!view()->isVisible()) if (!view()->isVisible()) {
return QRect(); return QRect();
}
QPoint origin = view()->scene()->views()[0]->mapToGlobal(QPoint(0, 0)); QPoint origin = view()->scene()->views()[0]->mapToGlobal(QPoint(0, 0));
QRect viewRect = view()->geometry().toRect(); QRect viewRect = view()->geometry().toRect();
return viewRect.translated(origin); return viewRect.translated(origin);
@ -255,24 +214,16 @@ int KItemListViewAccessible::navigate(RelationFlag relation, int index, QAccessi
{ {
*iface = 0; *iface = 0;
switch (relation) { switch (relation) {
/*case Ancestor: { case QAccessible::Child: {
if (index == 1 && view()->parent()) { Q_ASSERT(index > 0);
*iface = QAccessible::queryAccessibleInterface(view()->parent()); *iface = cell(index);
if (*iface) if (*iface) {
return 0; return 0;
}
break;
} }
break; default:
}*/ break;
case QAccessible::Child: {
Q_ASSERT(index > 0);
*iface = cell(index);
if (*iface) {
return 0;
}
break;
}
default:
break;
} }
return -1; return -1;
} }
@ -300,7 +251,7 @@ bool KItemListViewAccessible::doAction(int, int, const QVariantList &)
// TABLE CELL // TABLE CELL
KItemListAccessibleCell::KItemListAccessibleCell(KItemListView *view_, int index_) KItemListAccessibleCell::KItemListAccessibleCell(KItemListView *view_, int index_)
: /* QAccessibleSimpleEditableTextInterface(this), */ view(view_) : view(view_)
, index(index_) , index(index_)
{ {
Q_ASSERT(index_ > 0); Q_ASSERT(index_ > 0);
@ -318,20 +269,12 @@ int KItemListAccessibleCell::rowExtent() const
QList<QAccessibleInterface*> KItemListAccessibleCell::rowHeaderCells() const QList<QAccessibleInterface*> KItemListAccessibleCell::rowHeaderCells() const
{ {
QList<QAccessibleInterface*> headerCell; return QList<QAccessibleInterface*>();
/*if (verticalHeader()) {
headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.row(), Qt::Vertical));
}*/
return headerCell;
} }
QList<QAccessibleInterface*> KItemListAccessibleCell::columnHeaderCells() const QList<QAccessibleInterface*> KItemListAccessibleCell::columnHeaderCells() const
{ {
QList<QAccessibleInterface*> headerCell; return QList<QAccessibleInterface*>();
/*if (horizontalHeader()) {
headerCell.append(new QAccessibleTable2HeaderCell(view, m_index.column(), Qt::Horizontal));
}*/
return headerCell;
} }
int KItemListAccessibleCell::columnIndex() const int KItemListAccessibleCell::columnIndex() const
@ -341,12 +284,6 @@ int KItemListAccessibleCell::columnIndex() const
int KItemListAccessibleCell::rowIndex() const int KItemListAccessibleCell::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); return view->layouter()->itemRow(index);
} }
@ -381,46 +318,34 @@ QAccessible::State KItemListAccessibleCell::state(int child) const
Q_ASSERT(child == 0); Q_ASSERT(child == 0);
QAccessible::State st = Normal; QAccessible::State st = Normal;
//QRect globalRect = view->rect(); if (isSelected()) {
//globalRect.translate(view->mapToGlobal(QPoint(0,0)));
//if (!globalRect.intersects(rect(0)))
// st |= Invisible;
if (isSelected())
st |= Selected; st |= Selected;
if (view->controller()->selectionManager()->currentItem() == index) }
if (view->controller()->selectionManager()->currentItem() == index) {
st |= Focused; st |= Focused;
}
//if (m_index.model()->data(m_index, Qt::CheckStateRole).toInt() == Qt::Checked)
// st |= Checked;
//if (flags & Qt::ItemIsSelectable) {
st |= Selectable; st |= Selectable;
st |= Focusable; st |= Focusable;
if (view->controller()->selectionBehavior() == KItemListController::MultiSelection)
st |= MultiSelectable;
//if (view->selectionMode() == QAbstractItemView::ExtendedSelection) if (view->controller()->selectionBehavior() == KItemListController::MultiSelection){
//st |= ExtSelectable; st |= MultiSelectable;
//} }
//if (m_role == QAccessible::TreeItem) {
// const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
// if (treeView->isExpanded(m_index))
// st |= Expanded;
//}
return st; return st;
} }
bool KItemListAccessibleCell::isExpandable() const bool KItemListAccessibleCell::isExpandable() const
{ {
return false; //view->model()->hasChildren(m_index); return false;
} }
QRect KItemListAccessibleCell::rect(int) const QRect KItemListAccessibleCell::rect(int) const
{ {
QRect r = view->itemRect(index-1).toRect(); QRect r = view->itemRect(index-1).toRect();
if (r.isNull()) if (r.isNull()) {
return QRect(); return QRect();
}
r.translate(view->mapToScene(QPointF(0.0, 0.0)).toPoint()); r.translate(view->mapToScene(QPointF(0.0, 0.0)).toPoint());
r.translate(view->scene()->views()[0]->mapToGlobal(QPoint(0, 0))); r.translate(view->scene()->views()[0]->mapToGlobal(QPoint(0, 0)));
return r; return r;
@ -435,8 +360,6 @@ QString KItemListAccessibleCell::text(QAccessible::Text t, int child) const
case QAccessible::Value: case QAccessible::Value:
case QAccessible::Name: case QAccessible::Name:
return data["text"].toString(); return data["text"].toString();
//case QAccessible::Description:
//return data["text"].toString() + " : " + data["group"].toString();
default: default:
break; break;
} }
@ -457,16 +380,14 @@ bool KItemListAccessibleCell::isValid() const
int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
{ {
if (relation == Ancestor && index == 1) { if (relation == Ancestor && index == 1) {
//if (m_role == QAccessible::TreeItem) {
// *iface = new QAccessibleTree(view);
//} else {
*iface = new KItemListViewAccessible(view); *iface = new KItemListViewAccessible(view);
return 0; return 0;
} }
*iface = 0; *iface = 0;
if (!view) if (!view) {
return -1; return -1;
}
switch (relation) { switch (relation) {
@ -478,8 +399,9 @@ int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessi
QAccessibleInterface *parent = queryAccessibleInterface(view); QAccessibleInterface *parent = queryAccessibleInterface(view);
int ret = parent->navigate(QAccessible::Child, index, iface); int ret = parent->navigate(QAccessible::Child, index, iface);
delete parent; delete parent;
if (*iface) if (*iface) {
return ret; return ret;
}
} }
return -1; return -1;
default: default:
@ -493,16 +415,6 @@ QAccessible::Relation KItemListAccessibleCell::relationTo(int child, const QAcce
{ {
Q_ASSERT(child == 0); Q_ASSERT(child == 0);
Q_ASSERT(otherChild == 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::Unrelated;
} }
@ -538,8 +450,9 @@ int KItemListContainerAccessible::childCount () const
int KItemListContainerAccessible::indexOfChild ( const QAccessibleInterface * child ) const int KItemListContainerAccessible::indexOfChild ( const QAccessibleInterface * child ) const
{ {
if(child->object() == container()->controller()->view()) if (child->object() == container()->controller()->view()) {
return 1; return 1;
}
return -1; return -1;
} }

View file

@ -84,28 +84,8 @@ protected:
protected: protected:
inline QAccessibleTable2CellInterface *cell(int index) const; inline QAccessibleTable2CellInterface *cell(int index) const;
inline QAccessible::Role cellRole() const { inline QAccessible::Role cellRole() const {
/* return QAccessible::Cell;
switch (m_role) {
case QAccessible::List:
return QAccessible::ListItem;
case QAccessible::Table:
return QAccessible::Cell;
case QAccessible::Tree:
return QAccessible::TreeItem;
default:
Q_ASSERT(0);
}
return QAccessible::NoRole;
*/
return QAccessible::Cell;
} }
private:
//QAccessible::Role m_role;
// the child index for a model index
//inline int logicalIndex(const QModelIndex &index) const;
// the model index from the child index
//QAccessibleInterface *childFromLogical(int logicalIndex) const;
}; };
class KItemListAccessibleCell: public QAccessibleTable2CellInterface class KItemListAccessibleCell: public QAccessibleTable2CellInterface
@ -113,15 +93,24 @@ class KItemListAccessibleCell: public QAccessibleTable2CellInterface
public: public:
KItemListAccessibleCell(KItemListView *view, int m_index); KItemListAccessibleCell(KItemListView *view, int m_index);
QObject *object() const { return 0; } QObject *object() const
{
return 0;
}
Role role(int) const; Role role(int) const;
State state(int) const; State state(int) const;
QRect rect(int) const; QRect rect(int) const;
bool isValid() const; bool isValid() const;
int childAt(int, int) const { return 0; } inline int childAt(int, int) const {
int childCount() const { return 0; } return 0;
int indexOfChild(const QAccessibleInterface *) const { return -1; } }
inline int childCount() const {
return 0;
}
inline int indexOfChild(const QAccessibleInterface *) const {
return -1;
}
QString text(Text t, int child) const; QString text(Text t, int child) const;
void setText(Text t, int child, const QString &text); void setText(Text t, int child, const QString &text);
@ -148,15 +137,15 @@ public:
virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const; virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const;
virtual QAccessibleTable2Interface* table() const; virtual QAccessibleTable2Interface* table() const;
inline int getIndex() const inline int getIndex() const {
{ return index; } return index;
}
private: private:
QPointer<KItemListView> view; QPointer<KItemListView> view;
int index; int index;
friend class KItemListViewAccessible; friend class KItemListViewAccessible;
//friend class QAccessibleTree;
}; };
class KItemListContainerAccessible : public QAccessibleWidgetEx class KItemListContainerAccessible : public QAccessibleWidgetEx