+/***************************************************************************
+ * 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/qaccessible2.h>
#include <KDebug>
#include <QHash>
-#ifndef QT_NO_ACCESSIBILITY
-
KItemListView* KItemListViewAccessible::view() const
{
return qobject_cast<KItemListView*>(object());
}
void KItemListViewAccessible::modelReset()
-{}
+{
+}
QAccessible::Role KItemListViewAccessible::cellRole() const
{
QAccessibleTable2CellInterface* KItemListViewAccessible::cell(int index) const
{
- if (index < 0 || index >= view()->model()->count())
+ if (index < 0 || index >= view()->model()->count()) {
return 0;
- return new KItemListAccessibleCell(view(), index);
+ } else {
+ return new KItemListAccessibleCell(view(), index);
+ }
}
-QVariant KItemListViewAccessible::invokeMethodEx(Method, int, const QVariantList &)
+QVariant KItemListViewAccessible::invokeMethodEx(Method, int, const QVariantList&)
{
return QVariant();
}
QAccessibleTable2CellInterface* KItemListViewAccessible::cellAt(int row, int column) const
{
- qDebug() << "cellAt: " << row << column << " is: " << column*row + column;
- return cell(columnCount()*row + column);
+ return cell(columnCount() * row + column);
}
QAccessibleInterface* KItemListViewAccessible::caption() const
int KItemListViewAccessible::rowCount() const
{
- if(columnCount() <= 0) {
+ if (columnCount() <= 0) {
return 0;
}
+
int itemCount = view()->model()->count();
int rowCount = itemCount / columnCount();
- if(rowCount <= 0){
+
+ if (rowCount <= 0) {
return 0;
}
+
if (itemCount % columnCount()) {
++rowCount;
}
int KItemListViewAccessible::selectedCellCount() const
{
- return view()->controller()->selectionManager()->selectedItems().size();
+ return view()->controller()->selectionManager()->selectedItems().count();
}
int KItemListViewAccessible::selectedColumnCount() const
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 = 0;
- 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));
}
return view()->model()->count();
}
-int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* iface) const
+int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* interface) const
{
- const KItemListAccessibleCell* widget = static_cast<const KItemListAccessibleCell*>(iface);
+ const KItemListAccessibleCell* widget = static_cast<const KItemListAccessibleCell*>(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();
if (!view()->isVisible()) {
return QRect();
}
- QPoint origin = view()->scene()->views()[0]->mapToGlobal(QPoint(0, 0));
- QRect viewRect = view()->geometry().toRect();
- return viewRect.translated(origin);
+
+ 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 QAccessible::Child: {
- Q_ASSERT(index > 0);
- *iface = cell(index - 1);
- 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;
}
return QString();
}
-bool KItemListViewAccessible::doAction(int, int, const QVariantList &)
+bool KItemListViewAccessible::doAction(int, int, const QVariantList&)
{
return false;
}
void KItemListAccessibleCell::rowColumnExtents(int* row, int* column, int* rowExtents, int* columnExtents, bool* selected) const
{
- KItemListViewLayouter* layouter = m_view->m_layouter;
+ const KItemListViewLayouter* layouter = m_view->m_layouter;
*row = layouter->itemRow(m_index);
*column = layouter->itemColumn(m_index);
*rowExtents = 1;
QAccessible::State state = Normal;
if (isSelected()) {
- state |= Selected;
+ state |= Selected;
}
+
if (m_view->controller()->selectionManager()->currentItem() == m_index) {
state |= Focused;
}
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)) {
+ if (m_view->model()->isExpanded(m_index)) {
state |= Expanded;
- }
- else {
+ } else {
state |= Collapsed;
}
}
+
return state;
}
QRect KItemListAccessibleCell::rect(int) const
{
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;
{
Q_ASSERT(child == 0);
Q_UNUSED(child)
- const QHash<QByteArray, QVariant> data = m_view->model()->data(m_index);
+
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();
+ }
+
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);
}
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;
- }
- default:
- break;
- }
-
+ *interface = 0;
return -1;
}
return QString();
}
-bool KItemListAccessibleCell::doAction(int, int, const QVariantList &)
+bool KItemListAccessibleCell::doAction(int, int, const QVariantList&)
{
return false;
}
// 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<KItemListContainer*>(object());
}
#endif // QT_NO_ACCESSIBILITY