diff options
author | Jan Arve Saether <jan-arve.saether@digia.com> | 2014-10-15 13:58:34 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@theqtcompany.com> | 2014-10-27 14:53:16 +0100 |
commit | 8f6436f125faae91eb472ddddbbae06dba5da671 (patch) | |
tree | cd99bd534e9e01ebddda584eb24a8bae3b195895 /src/quick/items/qquickaccessibleattached.cpp | |
parent | 32af8055985c1f978574eec62512638f472e8290 (diff) |
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: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'src/quick/items/qquickaccessibleattached.cpp')
-rw-r--r-- | src/quick/items/qquickaccessibleattached.cpp | 82 |
1 files changed, 73 insertions, 9 deletions
diff --git a/src/quick/items/qquickaccessibleattached.cpp b/src/quick/items/qquickaccessibleattached.cpp index a4ab0a96b1..38b26a53d0 100644 --- a/src/quick/items/qquickaccessibleattached.cpp +++ b/src/quick/items/qquickaccessibleattached.cpp @@ -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 |