Skip to content

Commit

Permalink
Create a value interface for qml accessibles.
Browse files Browse the repository at this point in the history
Change-Id: I472052c6d61a3a32033544ebb5afc5b11fb093e2
Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
  • Loading branch information
Frederik Gladhorn authored and Qt by Nokia committed Jan 6, 2012
1 parent 1976dcf commit afbcb4f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/plugins/accessible/quick/main.cpp
Expand Up @@ -46,6 +46,7 @@

#include <QtQuick/QQuickView>
#include <QtQuick/QQuickItem>
#include <QtQuick/private/qquickaccessibleattached_p.h>

#include <qaccessibleplugin.h>
#include <qvariant.h>
Expand Down Expand Up @@ -82,9 +83,23 @@ QAccessibleInterface *AccessibleQuickFactory::create(const QString &classname, Q
if (classname == QLatin1String("QQuickView")) {
return new QAccessibleQuickView(qobject_cast<QQuickView *>(object)); // FIXME
} else if (classname == QLatin1String("QQuickItem")) {
QQuickItem * item = qobject_cast<QQuickItem *>(object);
Q_ASSERT(item);
QQuickItem * item = qobject_cast<QQuickItem *>(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;
Expand Down
29 changes: 28 additions & 1 deletion src/plugins/accessible/quick/qaccessiblequickitem.cpp
Expand Up @@ -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<QAccessibleValueInterface*>(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
17 changes: 16 additions & 1 deletion src/plugins/accessible/quick/qaccessiblequickitem.h
Expand Up @@ -72,10 +72,25 @@ class QAccessibleQuickItem : public QDeclarativeAccessible
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
Expand Down

0 comments on commit afbcb4f

Please sign in to comment.