From 4ad6343be52b757fd354cd92874bca944d2ede49 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Fri, 6 Nov 2009 15:15:05 +0100 Subject: Add preliminary QAccessibleImage interface As requested by the Maemo team. --- src/gui/accessible/qaccessible.h | 7 ++++- src/gui/accessible/qaccessible2.cpp | 12 ++++++++ src/gui/accessible/qaccessible2.h | 13 ++++++++ src/plugins/accessible/widgets/simplewidgets.cpp | 38 ++++++++++++++++++++++++ src/plugins/accessible/widgets/simplewidgets.h | 7 ++++- tests/auto/qaccessibility/tst_qaccessibility.cpp | 21 +++++++++++++ 6 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/gui/accessible/qaccessible.h b/src/gui/accessible/qaccessible.h index 8f6d9d9..c493054 100644 --- a/src/gui/accessible/qaccessible.h +++ b/src/gui/accessible/qaccessible.h @@ -311,7 +311,8 @@ namespace QAccessible2 EditableTextInterface, ValueInterface, TableInterface, - ActionInterface + ActionInterface, + ImageInterface }; } @@ -321,6 +322,7 @@ class QAccessibleEditableTextInterface; class QAccessibleValueInterface; class QAccessibleTableInterface; class QAccessibleActionInterface; +class QAccessibleImageInterface; class Q_GUI_EXPORT QAccessibleInterface : public QAccessible { @@ -381,6 +383,9 @@ public: inline QAccessibleActionInterface *actionInterface() { return reinterpret_cast(cast_helper(QAccessible2::ActionInterface)); } + inline QAccessibleImageInterface *imageInterface() + { return reinterpret_cast(cast_helper(QAccessible2::ImageInterface)); } + private: QAccessible2Interface *cast_helper(QAccessible2::InterfaceType); }; diff --git a/src/gui/accessible/qaccessible2.cpp b/src/gui/accessible/qaccessible2.cpp index 0867368..b878cf1 100644 --- a/src/gui/accessible/qaccessible2.cpp +++ b/src/gui/accessible/qaccessible2.cpp @@ -120,6 +120,18 @@ QT_BEGIN_NAMESPACE \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink */ +/*! + \class QAccessibleImageInterface + \ingroup accessibility + \internal + \preliminary + + \brief The QAccessibleImageInterface class implements support for + the IAccessibleImage interface. + + \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink +*/ + QAccessibleSimpleEditableTextInterface::QAccessibleSimpleEditableTextInterface( QAccessibleInterface *accessibleInterface) : iface(accessibleInterface) diff --git a/src/gui/accessible/qaccessible2.h b/src/gui/accessible/qaccessible2.h index 435c640..ba12a7c 100644 --- a/src/gui/accessible/qaccessible2.h +++ b/src/gui/accessible/qaccessible2.h @@ -82,6 +82,7 @@ inline QAccessible2Interface *qAccessibleTextCastHelper() { return 0; } inline QAccessible2Interface *qAccessibleEditableTextCastHelper() { return 0; } inline QAccessible2Interface *qAccessibleTableCastHelper() { return 0; } inline QAccessible2Interface *qAccessibleActionCastHelper() { return 0; } +inline QAccessible2Interface *qAccessibleImageCastHelper() { return 0; } #define Q_ACCESSIBLE_OBJECT \ public: \ @@ -98,6 +99,8 @@ inline QAccessible2Interface *qAccessibleActionCastHelper() { return 0; } return qAccessibleTableCastHelper(); \ case QAccessible2::ActionInterface: \ return qAccessibleActionCastHelper(); \ + case QAccessible2::ImageInterface: \ + return qAccessibleImageCastHelper(); \ } \ return 0; \ } \ @@ -224,6 +227,16 @@ public: virtual QStringList keyBindings(int actionIndex) = 0; }; +class Q_GUI_EXPORT QAccessibleImageInterface : public QAccessible2Interface +{ +public: + inline QAccessible2Interface *qAccessibleImageCastHelper() { return this; } + + virtual QString imageDescription() = 0; + virtual QSize imageSize() = 0; + virtual QRect imagePosition(QAccessible2::CoordinateType coordType) = 0; +}; + #endif // QT_NO_ACCESSIBILITY QT_END_NAMESPACE diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index aa51759..1d801e4 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -602,6 +602,44 @@ int QAccessibleDisplay::navigate(RelationFlag rel, int entry, QAccessibleInterfa return QAccessibleWidgetEx::navigate(rel, entry, target); } +/*! \reimp */ +QString QAccessibleDisplay::imageDescription() +{ + return widget()->toolTip(); +} + +/*! \reimp */ +QSize QAccessibleDisplay::imageSize() +{ + QLabel *label = qobject_cast(widget()); + if (!label) + return QSize(); + const QPixmap *pixmap = label->pixmap(); + if (!pixmap) + return QSize(); + return pixmap->size(); +} + +/*! \reimp */ +QRect QAccessibleDisplay::imagePosition(QAccessible2::CoordinateType coordType) +{ + QLabel *label = qobject_cast(widget()); + if (!label) + return QRect(); + const QPixmap *pixmap = label->pixmap(); + if (!pixmap) + return QRect(); + + switch (coordType) { + case QAccessible2::RelativeToScreen: + return QRect(label->mapToGlobal(label->pos()), label->size()); + case QAccessible2::RelativeToParent: + return label->geometry(); + } + + return QRect(); +} + #ifndef QT_NO_LINEEDIT /*! \class QAccessibleLineEdit diff --git a/src/plugins/accessible/widgets/simplewidgets.h b/src/plugins/accessible/widgets/simplewidgets.h index 0c1cf5e..5182bdd 100644 --- a/src/plugins/accessible/widgets/simplewidgets.h +++ b/src/plugins/accessible/widgets/simplewidgets.h @@ -111,7 +111,7 @@ protected: }; #endif // QT_NO_TOOLBUTTON -class QAccessibleDisplay : public QAccessibleWidgetEx +class QAccessibleDisplay : public QAccessibleWidgetEx, public QAccessibleImageInterface { Q_ACCESSIBLE_OBJECT public: @@ -122,6 +122,11 @@ public: Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const; int navigate(RelationFlag, int entry, QAccessibleInterface **target) const; + + // QAccessibleImageInterface + QString imageDescription(); + QSize imageSize(); + QRect imagePosition(QAccessible2::CoordinateType coordType); }; #ifndef QT_NO_LINEEDIT diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 9f2e4e7..25c2649 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -4034,6 +4034,27 @@ void tst_QAccessibility::labelTest() delete acc_label; delete label; QTestAccessibility::clearEvents(); + + QPixmap testPixmap(50, 50); + testPixmap.fill(); + + QLabel imageLabel; + imageLabel.setPixmap(testPixmap); + imageLabel.setToolTip("Test Description"); + + acc_label = QAccessible::queryAccessibleInterface(&imageLabel); + QVERIFY(acc_label); + + QAccessibleImageInterface *imageInterface = acc_label->imageInterface(); + QVERIFY(imageInterface); + + QCOMPARE(imageInterface->imageSize(), testPixmap.size()); + QCOMPARE(imageInterface->imageDescription(), QString::fromLatin1("Test Description")); + QCOMPARE(imageInterface->imagePosition(QAccessible2::RelativeToParent), imageLabel.geometry()); + + delete acc_label; + + QTestAccessibility::clearEvents(); #else QSKIP("Test needs accessibility support.", SkipAll); #endif -- cgit v0.12