Commit 8f6436f1 authored by Jan Arve Saether's avatar Jan Arve Saether Committed by Jan Arve Sæther
Browse files

Move action handlers to the Accessible attached object


With this change, instead of writing:

    function accessiblePressAction() { submit() }

You should write:

    Accessible.onPressAction: { submit() }

For the moment, only 4 actions are added:
press, toggle, increase and decrease.

The old style action handlers are deprecated, and removed from the
documentation. New style action handlers will be preferred in case an
item declares both styles.

Change-Id: I11919e631d8476d55540f94252757b911c44ade4
Reviewed-by: default avatarFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>
parent 32af8055
dev 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 6.0 6.0.0 6.1 6.1.0 6.1.1 6.1.2 6.1.3 6.2 6.2.0 6.2.1 6.2.2 wip/cmake wip/dbus wip/itemviews wip/nacl wip/new-backend wip/pointerhandler wip/propertycache-refactor wip/qquickdeliveryagent wip/scenegraphng wip/tizen wip/webassembly v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1
No related merge requests found
Showing with 97 additions and 16 deletions
......@@ -42,7 +42,7 @@ Rectangle {
Accessible.name: text
Accessible.description: "This button does " + text
Accessible.role: Accessible.Button
function accessiblePressAction() {
Accessible.onPressAction: {
button.clicked()
}
//! [button]
......
......@@ -39,7 +39,6 @@
#include "QtQuick/private/qquicktext_p.h"
#include "QtQuick/private/qquickaccessibleattached_p.h"
#include "QtQuick/qquicktextdocument.h"
QT_BEGIN_NAMESPACE
#ifndef QT_NO_ACCESSIBILITY
......@@ -217,16 +216,24 @@ QStringList QAccessibleQuickItem::actionNames() const
QStringList actions = QQmlAccessible::actionNames();
if (state().focusable)
actions.append(QAccessibleActionInterface::setFocusAction());
// ### The following can lead to duplicate action names. We'll fix that when we kill QQmlAccessible
if (QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(item()))
attached->availableActions(&actions);
return actions;
}
void QAccessibleQuickItem::doAction(const QString &actionName)
{
bool accepted = false;
if (actionName == QAccessibleActionInterface::setFocusAction()) {
item()->forceActiveFocus();
} else {
QQmlAccessible::doAction(actionName);
accepted = true;
}
if (QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(item()))
accepted = attached->doAction(actionName);
if (!accepted)
QQmlAccessible::doAction(actionName);
}
QStringList QAccessibleQuickItem::keyBindingsForAction(const QString &actionName) const
......
......@@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE
Accessible.role: Accessible.Button
Accessible.name: label.text
Accessible.description: "shows the next page"
function accessiblePressAction() {
Accessible.onPressAction: {
// do a button click
}
}
......@@ -79,8 +79,8 @@ QT_BEGIN_NAMESPACE
The name is a short and consise description of the control and should reflect the visual label.
In this case it is not clear what the button does with the name only, so \l description contains
an explanation.
There is also a function \c accessiblePressAction() which can be invoked by assistive tools to trigger
the button. This function needs to have the same effect as tapping or clicking the button would have.
There is also a signal handler \l {Accessible::pressAction}{Accessible.pressAction} which can be invoked by assistive tools to trigger
the button. This signal handler needs to have the same effect as tapping or clicking the button would have.
\sa Accessibility
*/
......@@ -117,7 +117,7 @@ QT_BEGIN_NAMESPACE
\table
\header
\li \b {Role}
\li \b {Properties and functions}
\li \b {Properties and signals}
\li \b {Explanation}
\row
\li All interactive elements
......@@ -128,13 +128,14 @@ QT_BEGIN_NAMESPACE
can be moved from item to item.
\row
\li Button, CheckBox, RadioButton
\li \c accessiblePressAction()
\li A button should have a function with the name \c accessiblePressAction.
This function may be called by an assistive tool such as a screen-reader.
\li \l {Accessible::pressAction}{Accessible.pressAction}
\li A button should have a signal handler with the name \c onPressAction.
This signal may be emitted by an assistive tool such as a screen-reader.
The implementation needs to behave the same as a mouse click or tap on the button.
\row
\li CheckBox, RadioButton
\li \l checkable, \l checked
\li \l checkable, \l checked, \l {Accessible::toggleAction}{Accessible.toggleAction}
\li The check state of the check box. Updated on Press, Check and Uncheck actions.
\row
\li Slider, SpinBox, Dial, ScrollBar
......@@ -142,7 +143,7 @@ QT_BEGIN_NAMESPACE
\li These properties reflect the state and possible values for the elements.
\row
\li Slider, SpinBox, Dial, ScrollBar
\li \c accessibleIncreaseAction(), \c accessibleDecreaseAction()
\li \l {Accessible::increaseAction}{Accessible.increaseAction}, \l {Accessible::decreaseAction}{Accessible.decreaseAction}
\li Actions to increase and decrease the value of the element.
\endtable
*/
......@@ -262,6 +263,40 @@ QT_BEGIN_NAMESPACE
By default this property is \c false.
*/
/*!
\qmlsignal QtQuick::Accessible::pressAction()
This signal is emitted when a press action is received from an assistive tool such as a screen-reader.
The corresponding handler is \c onPressAction.
*/
/*!
\qmlsignal QtQuick::Accessible::toggleAction()
This signal is emitted when a toggle action is received from an assistive tool such as a screen-reader.
The corresponding handler is \c onToggleAction.
*/
/*!
\qmlsignal QtQuick::Accessible::increaseAction()
This signal is emitted when a increase action is received from an assistive tool such as a screen-reader.
The corresponding handler is \c onIncreaseAction.
*/
/*!
\qmlsignal QtQuick::Accessible::decreaseAction()
This signal is emitted when a decrease action is received from an assistive tool such as a screen-reader.
The corresponding handler is \c onDecreaseAction.
*/
const QMetaMethod QQuickAccessibleAttached::sigPress = QMetaMethod::fromSignal(&QQuickAccessibleAttached::pressAction);
const QMetaMethod QQuickAccessibleAttached::sigToggle = QMetaMethod::fromSignal(&QQuickAccessibleAttached::toggleAction);
const QMetaMethod QQuickAccessibleAttached::sigIncrease = QMetaMethod::fromSignal(&QQuickAccessibleAttached::increaseAction);
const QMetaMethod QQuickAccessibleAttached::sigDecrease = QMetaMethod::fromSignal(&QQuickAccessibleAttached::decreaseAction);
QQuickAccessibleAttached::QQuickAccessibleAttached(QObject *parent)
: QObject(parent), m_role(QAccessible::NoRole)
{
......@@ -306,6 +341,35 @@ void QQuickAccessibleAttached::setIgnored(bool ignored)
}
}
bool QQuickAccessibleAttached::doAction(const QString &actionName)
{
const QMetaMethod *sig = 0;
if (actionName == QAccessibleActionInterface::pressAction())
sig = &sigPress;
else if (actionName == QAccessibleActionInterface::toggleAction())
sig = &sigToggle;
else if (actionName == QAccessibleActionInterface::increaseAction())
sig = &sigIncrease;
else if (actionName == QAccessibleActionInterface::decreaseAction())
sig = &sigDecrease;
if (sig && isSignalConnected(*sig))
return sig->invoke(this);
return false;
}
void QQuickAccessibleAttached::availableActions(QStringList *actions) const
{
if (isSignalConnected(sigPress))
actions->append(QAccessibleActionInterface::pressAction());
if (isSignalConnected(sigToggle))
actions->append(QAccessibleActionInterface::toggleAction());
if (isSignalConnected(sigIncrease))
actions->append(QAccessibleActionInterface::increaseAction());
if (isSignalConnected(sigDecrease))
actions->append(QAccessibleActionInterface::decreaseAction());
}
QT_END_NAMESPACE
#endif
......@@ -188,6 +188,8 @@ public:
QAccessible::State state() { return m_state; }
bool ignored() const;
bool doAction(const QString &actionName);
void availableActions(QStringList *actions) const;
public Q_SLOTS:
void valueChanged() {
......@@ -206,6 +208,10 @@ Q_SIGNALS:
void nameChanged();
void descriptionChanged();
void ignoredChanged();
void pressAction();
void toggleAction();
void increaseAction();
void decreaseAction();
private:
QQuickItem *item() const { return static_cast<QQuickItem*>(parent()); }
......@@ -215,6 +221,11 @@ private:
QString m_name;
QString m_description;
static const QMetaMethod sigPress;
static const QMetaMethod sigToggle;
static const QMetaMethod sigIncrease;
static const QMetaMethod sigDecrease;
public:
using QObject::property;
};
......
......@@ -50,9 +50,8 @@ Rectangle {
Accessible.role : Accessible.Button
function accessibleAction(action) {
if (action == Qt.Press)
buttonAction()
Accessible.onPressAction: {
buttonAction()
}
function buttonAction() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment