summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Millán Soto <fid@gpul.org>2012-01-22 13:43:36 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-10 16:11:54 +0100
commitc03ceb203c65d9e3485fad848bfc0c4b6ee3e9aa (patch)
tree5bfca4ad98a6b21435d8fbde20701494499bd398
parent0aa20342693a954edabdbd8387d57610d931c3b5 (diff)
Added QAccessibleGroupBox
Added a new accessible interface for QGroupBox, as QAccessibleDisplay is not good enough when the QGroupBox is checkable. AccessibleFactory was modified to return a QAccessibleGroupBox when the accessible interface of a QGroupBox is requested. Created tst_QAccessibility::groupBoxTest Change-Id: I6c23dcf5562b3ea269b04102e78463b65827188a Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
-rw-r--r--src/gui/widgets/qgroupbox.cpp3
-rw-r--r--src/plugins/accessible/widgets/main.cpp4
-rw-r--r--src/plugins/accessible/widgets/simplewidgets.cpp129
-rw-r--r--src/plugins/accessible/widgets/simplewidgets.h29
-rw-r--r--tests/auto/qaccessibility/tst_qaccessibility.cpp45
5 files changed, 192 insertions, 18 deletions
diff --git a/src/gui/widgets/qgroupbox.cpp b/src/gui/widgets/qgroupbox.cpp
index 236f30889d..03275e7c4a 100644
--- a/src/gui/widgets/qgroupbox.cpp
+++ b/src/gui/widgets/qgroupbox.cpp
@@ -641,6 +641,9 @@ void QGroupBox::setChecked(bool b)
update();
d->checked = b;
d->_q_setChildrenEnabled(b);
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged);
+#endif
emit toggled(b);
}
}
diff --git a/src/plugins/accessible/widgets/main.cpp b/src/plugins/accessible/widgets/main.cpp
index aa0e0966fb..d947d088c7 100644
--- a/src/plugins/accessible/widgets/main.cpp
+++ b/src/plugins/accessible/widgets/main.cpp
@@ -233,8 +233,10 @@ QAccessibleInterface *AccessibleFactory::create(const QString &classname, QObjec
#endif
} else if (classname == QLatin1String("QLabel") || classname == QLatin1String("QLCDNumber")) {
iface = new QAccessibleDisplay(widget);
+#ifndef QT_NO_GROUPBOX
} else if (classname == QLatin1String("QGroupBox")) {
- iface = new QAccessibleDisplay(widget, Grouping);
+ iface = new QAccessibleGroupBox(widget);
+#endif
} else if (classname == QLatin1String("QStatusBar")) {
iface = new QAccessibleWidgetEx(widget, StatusBar);
#ifndef QT_NO_PROGRESSBAR
diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp
index 5f591331c3..e47cfad2df 100644
--- a/src/plugins/accessible/widgets/simplewidgets.cpp
+++ b/src/plugins/accessible/widgets/simplewidgets.cpp
@@ -537,10 +537,6 @@ QString QAccessibleDisplay::text(Text t, int child) const
if (str.isEmpty()) {
if (qobject_cast<QLabel*>(object())) {
str = qobject_cast<QLabel*>(object())->text();
-#ifndef QT_NO_GROUPBOX
- } else if (qobject_cast<QGroupBox*>(object())) {
- str = qobject_cast<QGroupBox*>(object())->title();
-#endif
#ifndef QT_NO_LCDNUMBER
} else if (qobject_cast<QLCDNumber*>(object())) {
QLCDNumber *l = qobject_cast<QLCDNumber*>(object());
@@ -581,13 +577,6 @@ QAccessible::Relation QAccessibleDisplay::relationTo(int child, const QAccessibl
if (o == label->buddy())
relation |= Label;
#endif
-#ifndef QT_NO_GROUPBOX
- } else {
- QGroupBox *groupbox = qobject_cast<QGroupBox*>(object());
- if (groupbox && !groupbox->title().isEmpty())
- if (groupbox->children().contains(o))
- relation |= Label;
-#endif
}
return relation;
}
@@ -604,12 +593,6 @@ int QAccessibleDisplay::navigate(RelationFlag rel, int entry, QAccessibleInterfa
if (entry == 1)
targetObject = label->buddy();
#endif
-#ifndef QT_NO_GROUPBOX
- } else {
- QGroupBox *groupbox = qobject_cast<QGroupBox*>(object());
- if (groupbox && !groupbox->title().isEmpty())
- rel = Child;
-#endif
}
*target = QAccessible::queryAccessibleInterface(targetObject);
if (*target)
@@ -660,6 +643,118 @@ QRect QAccessibleDisplay::imagePosition(QAccessible2::CoordinateType coordType)
return QRect();
}
+#ifndef QT_NO_GROUPBOX
+QAccessibleGroupBox::QAccessibleGroupBox(QWidget *w)
+ : QAccessibleWidgetEx(w, Grouping)
+{
+}
+
+QGroupBox* QAccessibleGroupBox::groupBox() const
+{
+ return static_cast<QGroupBox *>(widget());
+}
+
+QString QAccessibleGroupBox::text(QAccessible::Text t, int child) const
+{
+ QString txt = QAccessibleWidgetEx::text(t, child);
+
+ if (txt.isEmpty()) {
+ switch (t) {
+ case Name:
+ txt = qt_accStripAmp(groupBox()->title());
+ case Description:
+ txt = qt_accStripAmp(groupBox()->title());
+ default:
+ break;
+ }
+ }
+
+ return txt;
+}
+
+QAccessible::State QAccessibleGroupBox::state(int child) const
+{
+ QAccessible::State st = QAccessibleWidgetEx::state(child);
+
+ if (groupBox()->isChecked())
+ st |= QAccessible::Checked;
+
+ return st;
+}
+
+QAccessible::Role QAccessibleGroupBox::role(int child) const
+{
+ if (child)
+ return QAccessibleWidgetEx::role(child);
+
+ return groupBox()->isCheckable() ? QAccessible::CheckBox : QAccessible::Grouping;
+}
+
+int QAccessibleGroupBox::navigate(RelationFlag rel, int entry, QAccessibleInterface **target) const
+{
+ if ((rel == Labelled) && !groupBox()->title().isEmpty())
+ rel = Child;
+ return QAccessibleWidgetEx::navigate(rel, entry, target);
+}
+
+QAccessible::Relation QAccessibleGroupBox::relationTo(int child, const QAccessibleInterface* other, int otherChild) const
+{
+ QGroupBox *groupbox = this->groupBox();
+
+ QAccessible::Relation relation = QAccessibleWidgetEx::relationTo(child, other, otherChild);
+
+ if (!child && !otherChild && !groupbox->title().isEmpty()) {
+ QObject *o = other->object();
+ if (groupbox->children().contains(o))
+ relation |= Label;
+ }
+
+ return relation;
+}
+
+int QAccessibleGroupBox::actionCount()
+{
+ return groupBox()->isCheckable() ? 1 : 0;
+}
+
+void QAccessibleGroupBox::doAction(int actionIndex)
+{
+ if ((actionIndex == 0) && groupBox()->isCheckable()) {
+ groupBox()->setChecked(!groupBox()->isChecked());
+ }
+}
+
+QString QAccessibleGroupBox::description(int actionIndex)
+{
+ if ((actionIndex == 0) && (groupBox()->isCheckable())) {
+ return QLatin1String("Toggles the button.");
+ }
+ return QString();
+}
+
+QString QAccessibleGroupBox::name(int actionIndex)
+{
+ if (actionIndex || !groupBox()->isCheckable())
+ return QString();
+
+ return QLatin1String("Toggle");
+}
+
+QString QAccessibleGroupBox::localizedName(int actionIndex)
+{
+ if (actionIndex || !groupBox()->isCheckable())
+ return QString();
+
+ return QGroupBox::tr("Toggle");
+}
+
+QStringList QAccessibleGroupBox::keyBindings(int actionIndex)
+{
+ return QStringList();
+}
+
+#endif
+
#ifndef QT_NO_LINEEDIT
/*!
\class QAccessibleLineEdit
diff --git a/src/plugins/accessible/widgets/simplewidgets.h b/src/plugins/accessible/widgets/simplewidgets.h
index e1c99d2c03..32592bae18 100644
--- a/src/plugins/accessible/widgets/simplewidgets.h
+++ b/src/plugins/accessible/widgets/simplewidgets.h
@@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE
class QAbstractButton;
class QLineEdit;
class QToolButton;
+class QGroupBox;
class QProgressBar;
class QAccessibleButton : public QAccessibleWidgetEx, public QAccessibleActionInterface
@@ -129,6 +130,34 @@ public:
QRect imagePosition(QAccessible2::CoordinateType coordType);
};
+#ifndef QT_NO_GROUPBOX
+class QAccessibleGroupBox : public QAccessibleWidgetEx,
+ public QAccessibleActionInterface
+{
+ Q_ACCESSIBLE_OBJECT
+public:
+ explicit QAccessibleGroupBox(QWidget *w);
+
+ State state(int child) const;
+ Role role(int child) const;
+ QString text(Text t, int child) const;
+
+ Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
+ int navigate(RelationFlag rel, int entry, QAccessibleInterface** target) const;
+
+ //QAccessibleActionInterface
+ int actionCount();
+ QString description(int actionIndex);
+ void doAction(int actionIndex);
+ QString name(int actionIndex);
+ QString localizedName(int actionIndex);
+ QStringList keyBindings(int actionIndex);
+
+private:
+ QGroupBox *groupBox() const;
+};
+#endif
+
#ifndef QT_NO_LINEEDIT
class QAccessibleLineEdit : public QAccessibleWidgetEx, public QAccessibleTextInterface,
public QAccessibleSimpleEditableTextInterface
diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp
index d09e7965a1..b168e30cad 100644
--- a/tests/auto/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp
@@ -263,6 +263,7 @@ private slots:
void mdiAreaTest();
void mdiSubWindowTest();
void lineEditTest();
+ void groupBoxTest();
void workspaceTest();
void dialogButtonBoxTest();
void dialTest();
@@ -3145,6 +3146,50 @@ void tst_QAccessibility::lineEditTest()
QTestAccessibility::clearEvents();
}
+void tst_QAccessibility::groupBoxTest()
+{
+ QGroupBox *groupBox = new QGroupBox();
+ QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(groupBox);
+
+ groupBox->setTitle(QLatin1String("Test QGroupBox"));
+ groupBox->setToolTip(QLatin1String("This group box will be used to test accessibility"));
+ QVBoxLayout *layout = new QVBoxLayout();
+ QRadioButton *rbutton = new QRadioButton();
+ layout->addWidget(rbutton);
+ groupBox->setLayout(layout);
+ QAccessibleInterface *rButtonIface = QAccessible::queryAccessibleInterface(rbutton);
+
+ QCOMPARE(iface->childCount(), 1);
+ QCOMPARE(iface->role(0), QAccessible::Grouping);
+ QCOMPARE(iface->text(QAccessible::Name, 0), QLatin1String("Test QGroupBox"));
+ QCOMPARE(iface->text(QAccessible::Description, 0), QLatin1String("This group box will be used to test accessibility"));
+ QAccessible::Relation relation = iface->relationTo(0, rButtonIface, 0);
+ QVERIFY(relation & QAccessible::Label);
+
+ delete rButtonIface;
+ delete iface;
+ delete groupBox;
+
+ groupBox = new QGroupBox();
+ iface = QAccessible::queryAccessibleInterface(groupBox);
+
+ groupBox->setCheckable(true);
+ groupBox->setChecked(false);
+
+ QCOMPARE(iface->role(0), QAccessible::CheckBox);
+ QAccessibleActionInterface *actionIface = iface->actionInterface();
+ QVERIFY(actionIface);
+ QAccessible::State state = iface->state(0);
+ QVERIFY(!(state & QAccessible::Checked));
+ actionIface->doAction(0);
+ QVERIFY(groupBox->isChecked());
+ state = iface->state(0);
+ QVERIFY(state & QAccessible::Checked);
+
+ delete iface;
+ delete groupBox;
+}
+
void tst_QAccessibility::workspaceTest()
{
{