diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-10-21 14:53:16 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-25 12:29:43 +0200 |
commit | 9a369a25ddfac9352cabde65c8476c7433dc6c3a (patch) | |
tree | dfe305c1d8b46002a3265ead430ec8deef45e7a1 /src/gui | |
parent | 8fd9fe209934ac92210ed3b81723ad5e21a98a30 (diff) |
Accessibility: Make it possible to send events with no QObject
Change-Id: Icbb9d15ec52ff5f7718eaf3600cab140971274aa
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/accessible/qaccessible.cpp | 41 | ||||
-rw-r--r-- | src/gui/accessible/qaccessible.h | 72 |
2 files changed, 107 insertions, 6 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index b8771ec583..5d28512697 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -1270,8 +1270,16 @@ QAccessibleInterface::~QAccessibleInterface() /*! \fn QAccessibleEvent::QAccessibleEvent(QObject *object, QAccessible::Event type) Constructs a QAccessibleEvent to notify that \a object has changed. - The event \a type explains what changed. - */ + The event \a type describes what changed. +*/ + +/*! \fn QAccessibleEvent::QAccessibleEvent(QAccessibleInterface *interface, QAccessible::Event type) + + Constructs a QAccessibleEvent to notify that \a interface has changed. + The event \a type describes what changed. + Use this function if you already have a QAccessibleInterface or no QObject, otherwise consider + the overload taking a \l QObject parameter as it might be cheaper. +*/ /*! \fn QAccessibleEvent::~QAccessibleEvent() Destroys the event. @@ -1293,6 +1301,22 @@ QAccessibleInterface::~QAccessibleInterface() Returns the child index. */ +/*! + \internal + Returns the uniqueId of the QAccessibleInterface represented by this event. + + In case the object() function returns 0 this is the only way to access the + interface. +*/ +QAccessible::Id QAccessibleEvent::uniqueId() const +{ + if (!m_object) + return m_uniqueId; + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object); + if (m_child != -1) + iface = iface->child(m_child); + return QAccessible::uniqueId(iface); +} /*! \class QAccessibleValueChangeEvent @@ -1530,6 +1554,9 @@ QAccessibleInterface::~QAccessibleInterface() */ QAccessibleInterface *QAccessibleEvent::accessibleInterface() const { + if (m_object == 0) + return QAccessible::accessibleInterface(m_uniqueId); + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object); if (!iface || !iface->isValid()) { static bool hasWarned = false; @@ -1681,9 +1708,13 @@ QDebug operator<<(QDebug d, const QAccessibleEvent &ev) d << "QAccessibleEvent(null)"; return d; } - d.nospace() << "QAccessibleEvent(object=" << hex << ev.object(); - d.nospace() << dec; - d.nospace() << "child=" << ev.child(); + d.nospace() << "QAccessibleEvent("; + if (ev.object()) { + d.nospace() << "object=" << hex << ev.object() << dec; + d.nospace() << "child=" << ev.child(); + } else { + d.nospace() << "no object, uniqueId=" << ev.uniqueId(); + } d << " event=" << qAccessibleEventString(ev.type()); if (ev.type() == QAccessible::StateChanged) { QAccessible::State changed = static_cast<const QAccessibleStateChangeEvent*>(&ev)->changedStates(); diff --git a/src/gui/accessible/qaccessible.h b/src/gui/accessible/qaccessible.h index d5b0af550e..25ce161940 100644 --- a/src/gui/accessible/qaccessible.h +++ b/src/gui/accessible/qaccessible.h @@ -597,6 +597,7 @@ class Q_GUI_EXPORT QAccessibleEvent { Q_DISABLE_COPY(QAccessibleEvent) public: + inline QAccessibleEvent(QObject *obj, QAccessible::Event typ) : m_type(typ), m_object(obj), m_child(-1) { @@ -613,11 +614,27 @@ public: Q_ASSERT(m_type != QAccessible::TableModelChanged); } + inline QAccessibleEvent(QAccessibleInterface *iface, QAccessible::Event typ) + : m_type(typ), m_object(0) + { + Q_ASSERT(iface); + Q_ASSERT(m_type != QAccessible::ValueChanged); + Q_ASSERT(m_type != QAccessible::StateChanged); + Q_ASSERT(m_type != QAccessible::TextCaretMoved); + Q_ASSERT(m_type != QAccessible::TextSelectionChanged); + Q_ASSERT(m_type != QAccessible::TextInserted); + Q_ASSERT(m_type != QAccessible::TextRemoved); + Q_ASSERT(m_type != QAccessible::TextUpdated); + Q_ASSERT(m_type != QAccessible::TableModelChanged); + m_uniqueId = QAccessible::uniqueId(iface); + } + virtual ~QAccessibleEvent() {} QAccessible::Event type() const { return m_type; } QObject *object() const { return m_object; } + QAccessible::Id uniqueId() const; void setChild(int chld) { m_child = chld; } int child() const { return m_child; } @@ -627,7 +644,11 @@ public: protected: QAccessible::Event m_type; QObject *m_object; - int m_child; + union { + int m_child; + QAccessible::Id m_uniqueId; + }; + }; class Q_GUI_EXPORT QAccessibleStateChangeEvent :public QAccessibleEvent @@ -638,6 +659,11 @@ public: { m_type = QAccessible::StateChanged; } + inline QAccessibleStateChangeEvent(QAccessibleInterface *iface, QAccessible::State state) + : QAccessibleEvent(iface, QAccessible::InvalidEvent), m_changedStates(state) + { + m_type = QAccessible::StateChanged; + } QAccessible::State changedStates() const { return m_changedStates; @@ -657,6 +683,12 @@ public: { m_type = QAccessible::TextCaretMoved; } + inline QAccessibleTextCursorEvent(QAccessibleInterface *iface, int cursorPos) + : QAccessibleEvent(iface, QAccessible::InvalidEvent) + , m_cursorPosition(cursorPos) + { + m_type = QAccessible::TextCaretMoved; + } void setCursorPosition(int position) { m_cursorPosition = position; } int cursorPosition() const { return m_cursorPosition; } @@ -675,6 +707,12 @@ public: { m_type = QAccessible::TextSelectionChanged; } + inline QAccessibleTextSelectionEvent(QAccessibleInterface *iface, int start, int end) + : QAccessibleTextCursorEvent(iface, (start == -1) ? 0 : end) + , m_selectionStart(start), m_selectionEnd(end) + { + m_type = QAccessible::TextSelectionChanged; + } void setSelection(int start, int end) { m_selectionStart = start; @@ -698,6 +736,12 @@ public: { m_type = QAccessible::TextInserted; } + inline QAccessibleTextInsertEvent(QAccessibleInterface *iface, int position, const QString &text) + : QAccessibleTextCursorEvent(iface, position + text.length()) + , m_position(position), m_text(text) + { + m_type = QAccessible::TextInserted; + } QString textInserted() const { return m_text; @@ -720,6 +764,12 @@ public: { m_type = QAccessible::TextRemoved; } + inline QAccessibleTextRemoveEvent(QAccessibleInterface *iface, int position, const QString &text) + : QAccessibleTextCursorEvent(iface, position) + , m_position(position), m_text(text) + { + m_type = QAccessible::TextRemoved; + } QString textRemoved() const { return m_text; @@ -742,6 +792,12 @@ public: { m_type = QAccessible::TextUpdated; } + inline QAccessibleTextUpdateEvent(QAccessibleInterface *iface, int position, const QString &oldText, const QString &text) + : QAccessibleTextCursorEvent(iface, position + text.length()) + , m_position(position), m_oldText(oldText), m_text(text) + { + m_type = QAccessible::TextUpdated; + } QString textRemoved() const { return m_oldText; } @@ -767,6 +823,12 @@ public: { m_type = QAccessible::ValueChanged; } + inline QAccessibleValueChangeEvent(QAccessibleInterface *iface, const QVariant &val) + : QAccessibleEvent(iface, QAccessible::InvalidEvent) + , m_value(val) + { + m_type = QAccessible::ValueChanged; + } void setValue(const QVariant & val) { m_value= val; } QVariant value() const { return m_value; } @@ -794,6 +856,14 @@ public: { m_type = QAccessible::TableModelChanged; } + inline QAccessibleTableModelChangeEvent(QAccessibleInterface *iface, ModelChangeType changeType) + : QAccessibleEvent(iface, QAccessible::InvalidEvent) + , m_modelChangeType(changeType) + , m_firstRow(-1), m_firstColumn(-1), m_lastRow(-1), m_lastColumn(-1) + { + m_type = QAccessible::TableModelChanged; + } + void setModelChangeType(ModelChangeType changeType) { m_modelChangeType = changeType; } ModelChangeType modelChangeType() const { return m_modelChangeType; } |