From eb57da5b3ff9915d2254fdbf57992fa0320d9041 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 7 Mar 2012 13:51:31 +0100 Subject: Update accessibility StateChange by custom event. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subclass QAccessibleEvent to give details what changed in the state change. Change-Id: I9005d311e85a3c8bfa6e062833fa6a8a7dc6a4a4 Reviewed-by: Jan-Arve Sæther --- src/gui/accessible/qaccessible.cpp | 3 ++- src/gui/accessible/qaccessible.h | 15 +++++++++++++++ src/widgets/kernel/qwidget.cpp | 14 +++++--------- src/widgets/widgets/qabstractbutton.cpp | 10 +++++++--- src/widgets/widgets/qpushbutton.cpp | 4 +++- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 2 -- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index a7843ba227..91b0b5fbe6 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -257,7 +257,8 @@ QT_BEGIN_NAMESPACE \value SelectionWithin Several changes to a selection has occurred in an item view. \value SoundPlayed A sound has been played by an object - \value StateChanged The QAccessible::State of an object has changed. + \omitvalue StateChanged The QAccessible::State of an object has changed. + This value is used internally for the QAccessibleStateChangeEvent. \value TableCaptionChanged A table caption has been changed. \value TableColumnDescriptionChanged The description of a table column, typically found in the column's header, has been changed. diff --git a/src/gui/accessible/qaccessible.h b/src/gui/accessible/qaccessible.h index 8c962ffb53..e8a5cf8bad 100644 --- a/src/gui/accessible/qaccessible.h +++ b/src/gui/accessible/qaccessible.h @@ -452,6 +452,21 @@ private: int m_child; }; +class Q_GUI_EXPORT QAccessibleStateChangeEvent :public QAccessibleEvent +{ +public: + inline QAccessibleStateChangeEvent(QAccessible::State state, QObject *obj, int chld = -1) + : QAccessibleEvent(QAccessible::StateChanged, obj, chld), m_changedStates(state) + {} + + QAccessible::State changedStates() const { + return m_changedStates; + } + +private: + QAccessible::State m_changedStates; +}; + #define QAccessibleInterface_iid "org.qt-project.Qt.QAccessibleInterface" Q_DECLARE_INTERFACE(QAccessibleInterface, QAccessibleInterface_iid) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 03ada1ac7a..1493f61972 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8245,12 +8245,15 @@ bool QWidget::event(QEvent *event) void QWidget::changeEvent(QEvent * event) { switch(event->type()) { - case QEvent::EnabledChange: + case QEvent::EnabledChange: { update(); #ifndef QT_NO_ACCESSIBILITY - QAccessible::updateAccessibility(QAccessibleEvent(QAccessible::StateChanged, this, 0)); + QAccessible::State s; + s.disabled = true; + QAccessible::updateAccessibility(QAccessibleStateChangeEvent(s, this)); #endif break; + } case QEvent::FontChange: case QEvent::StyleChange: { @@ -10515,13 +10518,6 @@ void QWidget::updateMicroFocus() { // updating everything since this is currently called for any kind of state change qApp->inputMethod()->update(Qt::ImQueryAll); - -#ifndef QT_NO_ACCESSIBILITY - if (isVisible()) { - // ##### is this correct - QAccessible::updateAccessibility(QAccessibleEvent(QAccessible::StateChanged, this, 0)); - } -#endif } /*! diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index f7c8ad7773..aebef8ddc9 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -504,9 +504,6 @@ void QAbstractButtonPrivate::refresh() if (blockRefresh) return; q->update(); -#ifndef QT_NO_ACCESSIBILITY - QAccessible::updateAccessibility(QAccessibleEvent(QAccessible::StateChanged, q, 0)); -#endif } void QAbstractButtonPrivate::click() @@ -767,6 +764,13 @@ void QAbstractButton::setChecked(bool checked) d->notifyChecked(); if (guard) emit toggled(checked); + + +#ifndef QT_NO_ACCESSIBILITY + QAccessible::State s; + s.checked = true; + QAccessible::updateAccessibility(QAccessibleStateChangeEvent(s, this)); +#endif } bool QAbstractButton::isChecked() const diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index 7ca5dcb486..059b0f801c 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -376,7 +376,9 @@ void QPushButton::setDefault(bool enable) } update(); #ifndef QT_NO_ACCESSIBILITY - QAccessible::updateAccessibility(QAccessibleEvent(QAccessible::StateChanged, this, 0)); + QAccessible::State s; + s.defaultButton = true; + QAccessible::updateAccessibility(QAccessibleStateChangeEvent(s, this)); #endif } diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 3e3fce2e1c..b8649a6443 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -419,8 +419,6 @@ void tst_QAccessibility::eventTest() button->setFocus(Qt::MouseFocusReason); QTestAccessibility::clearEvents(); QTest::mouseClick(button, Qt::LeftButton, 0); - QVERIFY_EVENT(button, 0, QAccessible::StateChanged); - QVERIFY_EVENT(button, 0, QAccessible::StateChanged); button->setAccessibleName("Olaf the second"); QVERIFY_EVENT(button, -1, QAccessible::NameChanged); -- cgit v1.2.3