aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-01-10 16:36:05 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-27 16:00:13 +0100
commitf0595284cbe85b5716daaf307154c1ed7e660a26 (patch)
treea3a0c1347130b1b6c8418780d16d2d7f308ebf69 /src/quick
parenta1ee538395198f998a73f3ef7545392aeb680900 (diff)
Accessibility: add states to QQuickAccessibleAttached
This makes it possible to set the state of accessible objects in qml. Change-Id: Ide70b885dac8fed180d2b221540cf2b699ac78ff Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/items/qquickaccessibleattached.cpp51
-rw-r--r--src/quick/items/qquickaccessibleattached_p.h74
2 files changed, 116 insertions, 9 deletions
diff --git a/src/quick/items/qquickaccessibleattached.cpp b/src/quick/items/qquickaccessibleattached.cpp
index 3c00a7d62d..b5cc6ea3ef 100644
--- a/src/quick/items/qquickaccessibleattached.cpp
+++ b/src/quick/items/qquickaccessibleattached.cpp
@@ -139,6 +139,57 @@ QT_BEGIN_NAMESPACE
\endtable
*/
+/*! \qmlproperty bool focusable
+ \brief This property holds whether this item is focusable.
+
+ By default, this property is false except for items where the role is one of
+ CheckBox, RadioButton, Button, MenuItem, PageTab, EditableText, SpinBox, ComboBox,
+ Terminal or ScrollBar.
+*/
+/*! \qmlproperty bool focused
+ \brief This property holds whether this item currently has the active focus.
+
+ By default, this property is false, but it will return true for items that
+ have \l QQuickItem::hasActiveFocus() returning true.
+*/
+/*! \qmlproperty bool checkable
+ \brief This property holds whether this item is checkable (like a check box or some buttons).
+*/
+/*! \qmlproperty bool checked
+ \brief This property holds whether this item is currently checked.
+*/
+/*! \qmlproperty bool editable
+ \brief This property holds whether this item has editable text.
+*/
+/*! \qmlproperty bool multiLine
+ \brief This property holds whether this item has multiple text lines.
+*/
+/*! \qmlproperty bool readOnly
+ \brief This property holds whether this item while being of type \l QAccessible::EditableText
+ is set to read-only.
+*/
+/*! \qmlproperty bool selected
+ \brief This property holds whether this item is selected.
+*/
+/*! \qmlproperty bool selectable
+ \brief This property holds whether this item can be selected.
+*/
+/*! \qmlproperty bool pressed
+ \brief This property holds whether this item is pressed (for example a button during a mouse click).
+*/
+/*! \qmlproperty bool checkStateMixed
+ \brief This property holds whether this item is in the partially checked state.
+*/
+/*! \qmlproperty bool defaultButton
+ \brief This property holds whether this item is the default button of a dialog.
+*/
+/*! \qmlproperty bool passwordEdit
+ \brief This property holds whether this item is a password text edit.
+*/
+/*! \qmlproperty bool selectableText
+ \brief This property holds whether this item contains selectable text.
+*/
+
QQuickAccessibleAttached::QQuickAccessibleAttached(QObject *parent)
: QObject(parent), m_role(QAccessible::NoRole)
{
diff --git a/src/quick/items/qquickaccessibleattached_p.h b/src/quick/items/qquickaccessibleattached_p.h
index 298c473cf8..521151f3dd 100644
--- a/src/quick/items/qquickaccessibleattached_p.h
+++ b/src/quick/items/qquickaccessibleattached_p.h
@@ -55,15 +55,46 @@
QT_BEGIN_NAMESPACE
+#define STATE_PROPERTY(P) \
+ Q_PROPERTY(bool P READ P WRITE set_ ## P NOTIFY P ## Changed FINAL) \
+ bool P() const { return m_state.P ; } \
+ void set_ ## P(bool arg) \
+ { \
+ if (m_state.P == arg) \
+ return; \
+ m_state.P = arg; \
+ emit P ## Changed(arg); \
+ QAccessible::State changedState; \
+ changedState.P = true; \
+ QAccessibleStateChangeEvent ev(parent(), changedState); \
+ QAccessible::updateAccessibility(&ev); \
+ } \
+ Q_SIGNAL void P ## Changed(bool arg);
+
+
class Q_QUICK_PRIVATE_EXPORT QQuickAccessibleAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(QAccessible::Role role READ role WRITE setRole NOTIFY roleChanged)
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
- Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
+ Q_PROPERTY(QAccessible::Role role READ role WRITE setRole NOTIFY roleChanged FINAL)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged FINAL)
public:
- Q_ENUMS(QAccessible::Role QAccessible::Event QAccessible::State)
+ Q_ENUMS(QAccessible::Role QAccessible::Event)
+ STATE_PROPERTY(checkable)
+ STATE_PROPERTY(checked)
+ STATE_PROPERTY(editable)
+ STATE_PROPERTY(focusable)
+ STATE_PROPERTY(focused)
+ STATE_PROPERTY(multiLine)
+ STATE_PROPERTY(readOnly)
+ STATE_PROPERTY(selected)
+ STATE_PROPERTY(selectable)
+ STATE_PROPERTY(pressed)
+ STATE_PROPERTY(checkStateMixed)
+ STATE_PROPERTY(defaultButton)
+ STATE_PROPERTY(passwordEdit)
+ STATE_PROPERTY(selectableText)
QQuickAccessibleAttached(QObject *parent);
~QQuickAccessibleAttached();
@@ -76,6 +107,26 @@ public:
Q_EMIT roleChanged();
// There is no way to signify role changes at the moment.
// QAccessible::updateAccessibility(parent(), 0, QAccessible::);
+
+ switch (role) {
+ case QAccessible::CheckBox:
+ case QAccessible::RadioButton:
+ m_state.focusable = true;
+ m_state.checkable = true;
+ break;
+ case QAccessible::Button:
+ case QAccessible::MenuItem:
+ case QAccessible::PageTab:
+ case QAccessible::EditableText:
+ case QAccessible::SpinBox:
+ case QAccessible::ComboBox:
+ case QAccessible::Terminal:
+ case QAccessible::ScrollBar:
+ m_state.focusable = true;
+ break;
+ default:
+ break;
+ }
}
}
QString name() const { return m_name; }
@@ -102,12 +153,12 @@ public:
// Factory function
static QQuickAccessibleAttached *qmlAttachedProperties(QObject *obj);
- // Property getter
- static QObject *attachedProperties(const QObject *obj)
+ static QQuickAccessibleAttached *attachedProperties(const QObject *obj)
{
- return qmlAttachedPropertiesObject<QQuickAccessibleAttached>(obj, false);
+ return qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(obj, false));
}
+ // Property getter
static QVariant property(const QObject *object, const char *propertyName)
{
if (QObject *attachedObject = QQuickAccessibleAttached::attachedProperties(object))
@@ -128,8 +179,8 @@ public:
static QObject *findAccessible(QObject *object, QAccessible::Role role = QAccessible::NoRole)
{
while (object) {
- QObject *att = QQuickAccessibleAttached::attachedProperties(object);
- if (att && (role == QAccessible::NoRole || att->property("role").toInt() == role)) {
+ QQuickAccessibleAttached *att = QQuickAccessibleAttached::attachedProperties(object);
+ if (att && (role == QAccessible::NoRole || att->role() == role)) {
break;
}
object = object->parent();
@@ -137,6 +188,8 @@ public:
return object;
}
+ QAccessible::State state() { return m_state; }
+
public Q_SLOTS:
void valueChanged() {
QAccessibleValueChangeEvent ev(parent(), parent()->property("value"));
@@ -153,7 +206,10 @@ Q_SIGNALS:
void descriptionChanged();
private:
+ QQuickItem *item() const { return static_cast<QQuickItem*>(parent()); }
+
QAccessible::Role m_role;
+ QAccessible::State m_state;
QString m_name;
QString m_description;