From: Frederik Gladhorn Date: Wed, 4 Jan 2012 12:02:10 +0000 (+0100) Subject: Create a value interface for qml accessibles. X-Git-Tag: qt-v5.0.0-alpha1~726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afbcb4fd4e3f22eac1b68fb9f44b8492c265d9f0;p=profile%2Fivi%2Fqtdeclarative.git Create a value interface for qml accessibles. Change-Id: I472052c6d61a3a32033544ebb5afc5b11fb093e2 Reviewed-by: Jan-Arve Sæther --- diff --git a/src/plugins/accessible/quick/main.cpp b/src/plugins/accessible/quick/main.cpp index 533ea52..15d5b95 100644 --- a/src/plugins/accessible/quick/main.cpp +++ b/src/plugins/accessible/quick/main.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -82,9 +83,23 @@ QAccessibleInterface *AccessibleQuickFactory::create(const QString &classname, Q if (classname == QLatin1String("QQuickView")) { return new QAccessibleQuickView(qobject_cast(object)); // FIXME } else if (classname == QLatin1String("QQuickItem")) { - QQuickItem * item = qobject_cast(object); - Q_ASSERT(item); + QQuickItem * item = qobject_cast(object); + Q_ASSERT(item); + + 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. + return new QAccessibleQuickItem(item); + + switch (role) { + case QAccessible::Slider: + case QAccessible::SpinBox: + case QAccessible::Dial: + return new QAccessibleQuickItemValueInterface(item); + default: return new QAccessibleQuickItem(item); + } } return 0; diff --git a/src/plugins/accessible/quick/qaccessiblequickitem.cpp b/src/plugins/accessible/quick/qaccessiblequickitem.cpp index 206168e..7fe4401 100644 --- a/src/plugins/accessible/quick/qaccessiblequickitem.cpp +++ b/src/plugins/accessible/quick/qaccessiblequickitem.cpp @@ -251,8 +251,35 @@ QString QAccessibleQuickItem::text(QAccessible::Text textType) const } } - return QString(); } +void *QAccessibleQuickItemValueInterface::interface_cast(QAccessible::InterfaceType t) +{ + if (t == QAccessible::ValueInterface) + return static_cast(this); + return QAccessibleQuickItem::interface_cast(t); +} + +QVariant QAccessibleQuickItemValueInterface::currentValue() +{ + return m_item->property("value"); +} + +void QAccessibleQuickItemValueInterface::setCurrentValue(const QVariant &value) +{ + m_item->setProperty("value", value); +} + +QVariant QAccessibleQuickItemValueInterface::maximumValue() +{ + return m_item->property("maximumValue"); +} + +QVariant QAccessibleQuickItemValueInterface::minimumValue() +{ + return m_item->property("minimumValue"); +} + + QT_END_NAMESPACE diff --git a/src/plugins/accessible/quick/qaccessiblequickitem.h b/src/plugins/accessible/quick/qaccessiblequickitem.h index 6e0bf2e..92aa8ed 100644 --- a/src/plugins/accessible/quick/qaccessiblequickitem.h +++ b/src/plugins/accessible/quick/qaccessiblequickitem.h @@ -72,10 +72,25 @@ public: QString text(QAccessible::Text) const; bool isAccessible() const; -private: + +protected: QQuickItem *m_item; }; +class QAccessibleQuickItemValueInterface: public QAccessibleQuickItem, public QAccessibleValueInterface +{ +public: + QAccessibleQuickItemValueInterface(QQuickItem *item) : QAccessibleQuickItem(item) + {} + + void *interface_cast(QAccessible::InterfaceType t); + + QVariant currentValue(); + void setCurrentValue(const QVariant &value); + QVariant maximumValue(); + QVariant minimumValue(); +}; + #endif // QT_NO_ACCESSIBILITY QT_END_NAMESPACE