X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0ae031a4e6bdd702da573ac7ce048b6cf825e32e..509464cce954f7fc4b00a9dafc2bc6355eb99ec6:/src/kitemviews/kitemlistviewaccessible.cpp diff --git a/src/kitemviews/kitemlistviewaccessible.cpp b/src/kitemviews/kitemlistviewaccessible.cpp index c0b64fcdc..a9ec69b43 100644 --- a/src/kitemviews/kitemlistviewaccessible.cpp +++ b/src/kitemviews/kitemlistviewaccessible.cpp @@ -1,6 +1,30 @@ +/*************************************************************************** + * 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 @@ -10,8 +34,6 @@ #include #include -#ifndef QT_NO_ACCESSIBILITY - KItemListView* KItemListViewAccessible::view() const { return qobject_cast(object()); @@ -24,7 +46,8 @@ KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) : } void KItemListViewAccessible::modelReset() -{} +{ +} QAccessible::Role KItemListViewAccessible::cellRole() const { @@ -33,20 +56,21 @@ QAccessible::Role KItemListViewAccessible::cellRole() const QAccessibleTable2CellInterface* KItemListViewAccessible::cell(int index) const { - if (index > 0) { + if (index < 0 || index >= view()->model()->count()) { + return 0; + } else { return new KItemListAccessibleCell(view(), index); } - return 0; } -QVariant KItemListViewAccessible::invokeMethodEx(Method, int, const QVariantList &) +QVariant KItemListViewAccessible::invokeMethodEx(Method, int, const QVariantList&) { return QVariant(); } QAccessibleTable2CellInterface* KItemListViewAccessible::cellAt(int row, int column) const { - return cell(column* (row - 1) + column) ; + return cell(columnCount() * row + column); } QAccessibleInterface* KItemListViewAccessible::caption() const @@ -61,14 +85,23 @@ QString KItemListViewAccessible::columnDescription(int) const 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; @@ -151,33 +184,38 @@ bool KItemListViewAccessible::unselectColumn(int) QAccessible2::TableModelChange KItemListViewAccessible::modelChange() const { QAccessible2::TableModelChange change; + change.lastRow = rowCount(); + change.lastColumn = columnCount(); return change; } QAccessible::Role KItemListViewAccessible::role(int child) const { Q_ASSERT(child >= 0); + if (child > 0) { return QAccessible::Cell; + } else { + return QAccessible::Table; } - return QAccessible::Table; } QAccessible::State KItemListViewAccessible::state(int child) const { if (child) { - QAccessibleInterface* iface; - navigate(Child,child,&iface); - if (iface) { - return iface->state(0); + 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)); } @@ -186,13 +224,13 @@ int KItemListViewAccessible::childCount() const return view()->model()->count(); } -int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* iface) const +int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* interface) const { - const KItemListAccessibleCell* widget = static_cast(iface); - return widget->index(); + const KItemListAccessibleCell* widget = static_cast(interface); + return widget->index() + 1; } -QString KItemListViewAccessible::text(Text , int child) const +QString KItemListViewAccessible::text(Text, int child) const { Q_ASSERT(child == 0); return QString(); @@ -204,30 +242,32 @@ QRect KItemListViewAccessible::rect(int child) const if (!view()->isVisible()) { return QRect(); } - QPoint origin = view()->scene()->views()[0]->mapToGlobal(QPoint(0, 0)); - QRect viewRect = view()->geometry().toRect(); + const QPoint origin = view()->scene()->views()[0]->mapToGlobal(QPoint(0, 0)); + const QRect viewRect = view()->geometry().toRect(); return viewRect.translated(origin); } -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 QAccessible::Child: { - Q_ASSERT(index > 0); - *iface = cell(index); - if (*iface) { - return 0; - } - break; + case QAccessible::Child: + Q_ASSERT(index > 0); + *interface = cell(index - 1); + if (*interface) { + return 0; } - default: - break; + 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; } @@ -244,7 +284,7 @@ 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; } @@ -257,7 +297,7 @@ 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 @@ -282,22 +322,22 @@ QList KItemListAccessibleCell::columnHeaderCells() const int KItemListAccessibleCell::columnIndex() const { - return m_view->layouter()->itemColumn(m_index); + return m_view->m_layouter->itemColumn(m_index); } int KItemListAccessibleCell::rowIndex() const { - return m_view->layouter()->itemRow(m_index); + return m_view->m_layouter->itemRow(m_index); } bool KItemListAccessibleCell::isSelected() const { - return m_view->controller()->selectionManager()->isSelected(m_index-1); + return m_view->controller()->selectionManager()->isSelected(m_index); } void KItemListAccessibleCell::rowColumnExtents(int* row, int* column, int* rowExtents, int* columnExtents, bool* selected) const { - KItemListViewLayouter* layouter = m_view->layouter(); + const KItemListViewLayouter* layouter = m_view->m_layouter; *row = layouter->itemRow(m_index); *column = layouter->itemColumn(m_index); *rowExtents = 1; @@ -324,6 +364,7 @@ QAccessible::State KItemListAccessibleCell::state(int child) const if (isSelected()) { state |= Selected; } + if (m_view->controller()->selectionManager()->currentItem() == m_index) { state |= Focused; } @@ -331,24 +372,34 @@ QAccessible::State KItemListAccessibleCell::state(int child) const state |= Selectable; state |= Focusable; - if (m_view->controller()->selectionBehavior() == KItemListController::MultiSelection){ + 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; + return m_view->model()->isExpandable(m_index); } QRect KItemListAccessibleCell::rect(int) const { - QRect rect = m_view->itemRect(m_index-1).toRect(); + QRect rect = m_view->itemRect(m_index).toRect(); + if (rect.isNull()) { return QRect(); } + rect.translate(m_view->mapToScene(QPointF(0.0, 0.0)).toPoint()); rect.translate(m_view->scene()->views()[0]->mapToGlobal(QPoint(0, 0))); return rect; @@ -358,25 +409,29 @@ QString KItemListAccessibleCell::text(QAccessible::Text t, int child) const { Q_ASSERT(child == 0); Q_UNUSED(child) - const QHash data = m_view->model()->data(m_index-1); + switch (t) { case QAccessible::Value: - case QAccessible::Name: + case QAccessible::Name: { + const QHash data = m_view->model()->data(m_index); return data["text"].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); } bool KItemListAccessibleCell::isValid() const { - return m_view && (m_index > 0); + return m_view && (m_index >= 0) && (m_index < m_view->model()->count()); } int KItemListAccessibleCell::childAt(int, int) const @@ -391,40 +446,18 @@ int KItemListAccessibleCell::childCount() const int KItemListAccessibleCell::indexOfChild(const QAccessibleInterface* child) const { + Q_UNUSED(child); return -1; } -int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessibleInterface* *iface) const +int KItemListAccessibleCell::navigate(RelationFlag relation, int index, QAccessibleInterface** interface) const { if (relation == Ancestor && index == 1) { - *iface = new KItemListViewAccessible(m_view); + *interface = new KItemListViewAccessible(m_view); return 0; } - *iface = 0; - if (!m_view) { - return -1; - } - - switch (relation) { - - case Child: { - return -1; - } - case Sibling: - if (index > 0) { - QAccessibleInterface* parent = queryAccessibleInterface(m_view); - int ret = parent->navigate(QAccessible::Child, index, iface); - delete parent; - if (*iface) { - return ret; - } - } - return -1; - default: - break; - } - + *interface = 0; return -1; } @@ -447,7 +480,7 @@ 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; } @@ -464,33 +497,43 @@ QObject* KItemListAccessibleCell::object() const return 0; } +// Container Interface 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->object() == container()->controller()->view()) { return 1; + } else { + return -1; } - 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); +} + +const KItemListContainer* KItemListContainerAccessible::container() const +{ + return qobject_cast(object()); } #endif // QT_NO_ACCESSIBILITY