QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / plugins / accessible / quick / qaccessiblequickitem.cpp
index fd087c4..c1307bb 100644 (file)
@@ -1,10 +1,9 @@
 /****************************************************************************
 **
 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** 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
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
 
 QT_BEGIN_NAMESPACE
 
+#ifndef QT_NO_ACCESSIBILITY
+
 QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item)
-    : QDeclarativeAccessible(item)
+    : QQmlAccessible(item)
 {
 }
 
@@ -68,14 +70,14 @@ QRect QAccessibleQuickItem::rect() const
 
 QRect QAccessibleQuickItem::viewRect() const
 {
-    // ### no canvas in some cases.
-    if (!item()->canvas()) {
+    // ### no window in some cases.
+    if (!item()->window()) {
         return QRect();
     }
 
-    QQuickCanvas *canvas = 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());
 }
 
 
@@ -89,17 +91,16 @@ QAccessibleInterface *QAccessibleQuickItem::parent() const
 {
     QQuickItem *parent = item()->parentItem();
     if (parent) {
-        QQuickCanvas *canvas = 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;
@@ -116,20 +117,7 @@ QAccessibleInterface *QAccessibleQuickItem::child(int index) const
     if (!child) // FIXME can this happen?
         return 0;
 
-    return new QAccessibleQuickItem(child);
-}
-
-int QAccessibleQuickItem::navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const
-{
-    Q_UNUSED(rel);
-    Q_UNUSED(entry);
-    Q_UNUSED(target);
-    *target = 0;
-    if (entry == 0) {
-        *target = new QAccessibleQuickItem(item());
-        return 0;
-    }
-    return -1;
+    return QAccessible::queryAccessibleInterface(child);
 }
 
 int QAccessibleQuickItem::indexOfChild(const QAccessibleInterface *iface) const
@@ -149,7 +137,14 @@ QList<QQuickItem *> QAccessibleQuickItem::childItems() const
             role() == QAccessible::PageTab ||
             role() == QAccessible::ProgressBar)
         return QList<QQuickItem *>();
-    return item()->childItems();
+
+    QList<QQuickItem *> items;
+    Q_FOREACH (QQuickItem *child, item()->childItems()) {
+        QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(child);
+        if (itemPrivate->isAccessible)
+            items.append(child);
+    }
+    return items;
 }
 
 QAccessible::State QAccessibleQuickItem::state() const
@@ -159,6 +154,9 @@ QAccessible::State QAccessibleQuickItem::state() const
     if (item()->hasActiveFocus())
         state.focused = true;
 
+    if (!item()->window() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity()))
+        state.invisible = true;
+
     QAccessible::Role r = role();
     switch (r) {
     case QAccessible::Button: {
@@ -169,7 +167,7 @@ QAccessible::State QAccessibleQuickItem::state() const
     }
     case QAccessible::CheckBox:
     case QAccessible::RadioButton: {
-        // FIXME when states are extended: state.checkable = true;
+        state.checkable = true;
         state.checked = item()->property("checked").toBool();
         break;
     }
@@ -218,7 +216,7 @@ 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; }
@@ -238,11 +236,6 @@ QString QAccessibleQuickItem::text(QAccessible::Text textType) const
         } else if (textType == QAccessible::Name) {
             return object()->objectName();
         }
-    } else {
-        if (textType == QAccessible::Name) {
-            QVariant text = object()->property("text");
-            return text.toString();
-        }
     }
 
     return QString();
@@ -281,9 +274,9 @@ QVariant QAccessibleQuickItemValueInterface::minimumValue() const
 */
 QRect itemScreenRect(QQuickItem *item)
 {
-    // ### no canvas in some cases.
+    // ### no window in some cases.
     // ### Should we really check for 0 opacity?
-    if (!item->canvas() ||!item->isVisible() || qFuzzyIsNull(item->opacity())) {
+    if (!item->window() ||!item->isVisible() || qFuzzyIsNull(item->opacity())) {
         return QRect();
     }
 
@@ -292,16 +285,16 @@ QRect itemScreenRect(QQuickItem *item)
     // parent size. WE MIGHT HAVE TO REVISIT THESE FALLBACKS.
     if (itemSize.isEmpty()) {
         itemSize = QSize((int)item->implicitWidth(), (int)item->implicitHeight());
-        if (itemSize.isEmpty())
+        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->canvas()->mapToGlobal(scenePoint.toPoint());
+    QPoint screenPos = item->window()->mapToGlobal(scenePoint.toPoint());
     return QRect(screenPos, itemSize);
 }
 
-
+#endif // QT_NO_ACCESSIBILITY
 
 QT_END_NAMESPACE