/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
+** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_ACCESSIBILITY
+
QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item)
- : QDeclarativeAccessible(item)
- , m_item(item)
+ : QQmlAccessible(item)
{
}
QRect QAccessibleQuickItem::rect() const
{
- // ### no canvas in some cases.
- // ### Should we really check for 0 opacity?
- if (!m_item->canvas() ||!m_item->isVisible() || qFuzzyIsNull(m_item->opacity())) {
- return QRect();
- }
-
- QSizeF size = QSizeF(m_item->width(), m_item->height());
- // ### If the bounding rect fails, we first try the implicit size, then we go for the
- // parent size. WE MIGHT HAVE TO REVISIT THESE FALLBACKS.
- if (size.isEmpty()) {
- size = QSizeF(m_item->implicitWidth(), m_item->implicitHeight());
- if (size.isEmpty())
- // ### Seems that the above fallback is not enough, fallback to use the parent size...
- size = QSizeF(m_item->parentItem()->width(), m_item->parentItem()->height());
- }
-
- QRectF sceneRect = m_item->mapRectToScene(QRectF(QPointF(0, 0), size));
- QPoint screenPos = m_item->canvas()->mapToGlobal(sceneRect.topLeft().toPoint());
-
- QRect r = QRect(screenPos, sceneRect.size().toSize());
+ const QRect r = itemScreenRect(item());
if (!r.isValid()) {
- qWarning() << m_item->metaObject()->className() << m_item->property("accessibleText") << r;
+ qWarning() << item()->metaObject()->className() << item()->property("accessibleText") << r;
}
return r;
}
QRect QAccessibleQuickItem::viewRect() const
{
- // ### no canvas in some cases.
- if (!m_item->canvas()) {
+ // ### no window in some cases.
+ if (!item()->window()) {
return QRect();
}
- QQuickCanvas *canvas = m_item->canvas();
- QPoint screenPos = canvas->mapToGlobal(QPoint(0,0));
- return QRect(screenPos, canvas->size());
+ QQuickWindow *window = item()->window();
+ QPoint screenPos = window->mapToGlobal(QPoint(0,0));
+ return QRect(screenPos, window->size());
}
bool QAccessibleQuickItem::clipsChildren() const
{
- return static_cast<QQuickItem *>(m_item)->clip();
+ return static_cast<QQuickItem *>(item())->clip();
}
QAccessibleInterface *QAccessibleQuickItem::parent() const
{
- QQuickItem *parent = m_item->parentItem();
+ QQuickItem *parent = item()->parentItem();
if (parent) {
- QQuickCanvas *canvas = m_item->canvas();
+ QQuickWindow *window = item()->window();
// Jump out to the scene widget if the parent is the root item.
- // There are two root items, QQuickCanvas::rootItem and
+ // There are two root items, QQuickWindow::rootItem and
// QQuickView::declarativeRoot. The former is the true root item,
// but is not a part of the accessibility tree. Check if we hit
// it here and return an interface for the scene instead.
- if (parent == canvas->rootItem()) {
- return QAccessible::queryAccessibleInterface(canvas);
+ if (window && (parent == window->contentItem())) {
+ return QAccessible::queryAccessibleInterface(window);
} else {
- QDeclarativeAccessible *ancestor = new QAccessibleQuickItem(parent);
- return ancestor;
+ return QAccessible::queryAccessibleInterface(parent);
}
}
return 0;
if (!child) // FIXME can this happen?
return 0;
- return new QAccessibleQuickItem(child);
-}
-
-int QAccessibleQuickItem::navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const
-{
- *target = 0;
- if (entry == 0) {
- *target = new QAccessibleQuickItem(m_item);
- return 0;
- }
-
- switch (rel) {
- case QAccessible::Child: { // FIMXE
- QList<QQuickItem *> children = childItems();
- const int childIndex = entry - 1;
-
- if (childIndex >= children.count())
- return -1;
-
- QQuickItem *child = children.at(childIndex);
- if (!child)
- return -1;
-
- *target = new QAccessibleQuickItem(child);
- return 0;
- break;}
- case QAccessible::Ancestor: { // FIMXE
- QQuickItem *parent = m_item->parentItem();
- if (parent) {
- QDeclarativeAccessible *ancestor = new QAccessibleQuickItem(parent);
- if (entry == 1) {
- QQuickCanvas *canvas = m_item->canvas();
- // Jump out to the scene widget if the parent is the root item.
- // There are two root items, QQuickCanvas::rootItem and
- // QQuickView::declarativeRoot. The former is the true root item,
- // but is not a part of the accessibility tree. Check if we hit
- // it here and return an interface for the scene instead.
- if (parent == canvas->rootItem()) {
- *target = QAccessible::queryAccessibleInterface(canvas);
- } else {
- *target = ancestor;
- }
- return 0;
- } else if (entry > 1) {
- int ret = ancestor->navigate(QAccessible::Ancestor, entry - 1, target);
- delete ancestor;
- return ret;
- }
- }
- return -1;
- break;}
- default: break;
- }
-
- return -1;
+ return QAccessible::queryAccessibleInterface(child);
}
int QAccessibleQuickItem::indexOfChild(const QAccessibleInterface *iface) const
{
QList<QQuickItem*> kids = childItems();
- int idx = kids.indexOf(static_cast<QQuickItem*>(iface->object()));
- if (idx != -1)
- ++idx;
- return idx;
+ return kids.indexOf(static_cast<QQuickItem*>(iface->object()));
}
QList<QQuickItem *> QAccessibleQuickItem::childItems() const
{
- if (role() == QAccessible::Button)
+ if ( role() == QAccessible::Button ||
+ role() == QAccessible::CheckBox ||
+ role() == QAccessible::RadioButton ||
+ role() == QAccessible::SpinBox ||
+ role() == QAccessible::EditableText ||
+ role() == QAccessible::Slider ||
+ role() == QAccessible::PageTab ||
+ role() == QAccessible::ProgressBar)
return QList<QQuickItem *>();
- return m_item->childItems();
+
+ QList<QQuickItem *> items;
+ Q_FOREACH (QQuickItem *child, item()->childItems()) {
+ QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(child);
+ if (itemPrivate->isAccessible)
+ items.append(child);
+ }
+ return items;
}
-QFlags<QAccessible::StateFlag> QAccessibleQuickItem::state() const
+QAccessible::State QAccessibleQuickItem::state() const
{
- QAccessible::State state = QAccessible::Normal;
+ QAccessible::State state;
+
+ if (item()->hasActiveFocus())
+ state.focused = true;
- if (m_item->hasActiveFocus()) {
- state |= QAccessible::Focused;
+ if (!item()->window() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity()))
+ state.invisible = true;
+
+ QAccessible::Role r = role();
+ switch (r) {
+ case QAccessible::Button: {
+ QVariant checkable = item()->property("checkable");
+ if (!checkable.toBool())
+ break;
+ // fall through
+ }
+ case QAccessible::CheckBox:
+ case QAccessible::RadioButton: {
+ state.checkable = true;
+ state.checked = item()->property("checked").toBool();
+ break;
+ }
+ default:
+ break;
}
+
return state;
}
-
QAccessible::Role QAccessibleQuickItem::role() const
{
// Workaround for setAccessibleRole() not working for
// Text items. Text items are special since they are defined
// entirely from C++ (setting the role from QML works.)
- if (qobject_cast<QQuickText*>(const_cast<QQuickItem *>(m_item)))
+ if (qobject_cast<QQuickText*>(const_cast<QQuickItem *>(item())))
return QAccessible::StaticText;
- QVariant v = QQuickAccessibleAttached::property(m_item, "role");
+ QVariant v = QQuickAccessibleAttached::property(item(), "role");
bool ok;
QAccessible::Role role = (QAccessible::Role)v.toInt(&ok);
if (!ok) // Not sure if this check is needed.
bool QAccessibleQuickItem::isAccessible() const
{
- return m_item->d_func()->isAccessible;
+ return item()->d_func()->isAccessible;
}
QString QAccessibleQuickItem::text(QAccessible::Text textType) const
#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION
case QAccessible::DebugDescription: {
QString debugString;
- debugString = QString::fromAscii(object()->metaObject()->className()) + QLatin1Char(' ');
+ debugString = QString::fromLatin1(object()->metaObject()->className()) + QLatin1Char(' ');
debugString += isAccessible() ? QLatin1String("enabled") : QLatin1String("disabled");
return debugString;
break; }
} else if (textType == QAccessible::Name) {
return object()->objectName();
}
- } else {
- if (textType == QAccessible::Name) {
- QVariant text = object()->property("text");
- return text.toString();
- }
}
-
return QString();
}
+void *QAccessibleQuickItemValueInterface::interface_cast(QAccessible::InterfaceType t)
+{
+ if (t == QAccessible::ValueInterface)
+ return static_cast<QAccessibleValueInterface*>(this);
+ return QAccessibleQuickItem::interface_cast(t);
+}
+
+QVariant QAccessibleQuickItemValueInterface::currentValue() const
+{
+ return item()->property("value");
+}
+
+void QAccessibleQuickItemValueInterface::setCurrentValue(const QVariant &value)
+{
+ item()->setProperty("value", value);
+}
+
+QVariant QAccessibleQuickItemValueInterface::maximumValue() const
+{
+ return item()->property("maximumValue");
+}
+
+QVariant QAccessibleQuickItemValueInterface::minimumValue() const
+{
+ return item()->property("minimumValue");
+}
+
+/*!
+ \internal
+ Shared between QAccessibleQuickItem and QAccessibleQuickView
+*/
+QRect itemScreenRect(QQuickItem *item)
+{
+ // ### no window in some cases.
+ // ### Should we really check for 0 opacity?
+ if (!item->window() ||!item->isVisible() || qFuzzyIsNull(item->opacity())) {
+ return QRect();
+ }
+
+ QSize itemSize((int)item->width(), (int)item->height());
+ // ### If the bounding rect fails, we first try the implicit size, then we go for the
+ // parent size. WE MIGHT HAVE TO REVISIT THESE FALLBACKS.
+ if (itemSize.isEmpty()) {
+ itemSize = QSize((int)item->implicitWidth(), (int)item->implicitHeight());
+ if (itemSize.isEmpty() && item->parentItem())
+ // ### Seems that the above fallback is not enough, fallback to use the parent size...
+ itemSize = QSize((int)item->parentItem()->width(), (int)item->parentItem()->height());
+ }
+
+ QPointF scenePoint = item->mapToScene(QPointF(0, 0));
+ QPoint screenPos = item->window()->mapToGlobal(scenePoint.toPoint());
+ return QRect(screenPos, itemSize);
+}
+
+#endif // QT_NO_ACCESSIBILITY
+
QT_END_NAMESPACE