summaryrefslogtreecommitdiffstats
path: root/src/plugins/accessible
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2011-09-07 16:36:51 (GMT)
committerFrederik Gladhorn <frederik.gladhorn@nokia.com>2011-09-08 08:51:24 (GMT)
commitc6d8800c4d3167e8d672f5fbed8bf1e8831ebc6a (patch)
tree2bd94e09c089b9eb0804c2acba675ce6f03ead83 /src/plugins/accessible
parent04d36837ecc66f81f363f2c4b8238a40017fd4fb (diff)
downloadQt-c6d8800c4d3167e8d672f5fbed8bf1e8831ebc6a.zip
Qt-c6d8800c4d3167e8d672f5fbed8bf1e8831ebc6a.tar.gz
Qt-c6d8800c4d3167e8d672f5fbed8bf1e8831ebc6a.tar.bz2
Implement QAccessibleActionInterface for menu actions.
This allows to open and trigger menu items via actions using the dedicated action interface. Reviewed-by: Jan-Arve
Diffstat (limited to 'src/plugins/accessible')
-rw-r--r--src/plugins/accessible/widgets/qaccessiblemenu.cpp77
-rw-r--r--src/plugins/accessible/widgets/qaccessiblemenu.h14
2 files changed, 83 insertions, 8 deletions
diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.cpp b/src/plugins/accessible/widgets/qaccessiblemenu.cpp
index 1454c7c..4ae1d15 100644
--- a/src/plugins/accessible/widgets/qaccessiblemenu.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblemenu.cpp
@@ -433,6 +433,8 @@ QString QAccessibleMenuItem::actionText(int action, Text text, int child ) const
switch (action) {
case Press:
case DefaultAction:
+ if (m_action->menu())
+ return QMenu::tr("Open");
return QMenu::tr("Execute");
break;
default:
@@ -444,11 +446,41 @@ QString QAccessibleMenuItem::actionText(int action, Text text, int child ) const
bool QAccessibleMenuItem::doAction(int action, int child, const QVariantList & /*params = QVariantList()*/ )
{
- if ((action == Press || action == DefaultAction) && child == 0) {
- m_action->trigger();
- return true;
+ if ((child) || ((action != DefaultAction) && (action != Press)))
+ return false;
+
+ // if the action has a menu, expand/hide it
+ if (m_action->menu()) {
+ if (m_action->menu()->isVisible()) {
+ m_action->menu()->hide();
+ return true;
+ } else {
+ if (QMenuBar *bar = qobject_cast<QMenuBar*>(owner())) {
+ bar->setActiveAction(m_action);
+ return true;
+ } else if (QMenu *menu = qobject_cast<QMenu*>(owner())){
+ menu->setActiveAction(m_action);
+ return true;
+ }
+ }
}
- return false;
+ // no menu
+ m_action->trigger();
+ return true;
+}
+
+// action interface
+int QAccessibleMenuItem::actionCount()
+{
+ return 1;
+}
+
+void QAccessibleMenuItem::doAction(int actionIndex)
+{
+ if (actionIndex)
+ return;
+
+ doAction(DefaultAction, 0);
}
int QAccessibleMenuItem::indexOfChild( const QAccessibleInterface * child ) const
@@ -618,7 +650,7 @@ QAccessible::State QAccessibleMenuItem::state(int child ) const
delete iface;
}
}
- return s;
+ return s | HasInvokeExtension;;
}
QString QAccessibleMenuItem::text ( Text t, int child ) const
@@ -654,17 +686,50 @@ QString QAccessibleMenuItem::text ( Text t, int child ) const
return str;
}
+// action interface
int QAccessibleMenuItem::userActionCount ( int /*child*/ ) const
{
return 0;
}
-
QAction *QAccessibleMenuItem::action() const
{
return m_action;
}
+QString QAccessibleMenuItem::description(int)
+{
+ return text(QAccessible::Description, 0);
+}
+
+QString QAccessibleMenuItem::name(int)
+{
+ return actionText(DefaultAction, QAccessible::Name, 0);
+}
+
+QString QAccessibleMenuItem::localizedName(int)
+{
+ return text(QAccessible::Name, 0);
+}
+
+QStringList QAccessibleMenuItem::keyBindings(int)
+{
+ QStringList keys;
+#ifndef QT_NO_SHORTCUT
+ QKeySequence key = m_action->shortcut();
+ if (!key.isEmpty()) {
+ keys.append(key.toString());
+ }
+#endif
+ return keys;
+}
+
+
+QVariant QAccessibleMenuItem::invokeMethodEx(Method, int, const QVariantList &)
+{
+ return QVariant();
+}
+
QWidget *QAccessibleMenuItem::owner() const
{
return m_owner;
diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.h b/src/plugins/accessible/widgets/qaccessiblemenu.h
index 680594d..47f42cb 100644
--- a/src/plugins/accessible/widgets/qaccessiblemenu.h
+++ b/src/plugins/accessible/widgets/qaccessiblemenu.h
@@ -43,6 +43,7 @@
#define QACCESSIBLEMENU_H
#include <QtGui/qaccessiblewidget.h>
+#include <QtGui/qaccessible2.h>
QT_BEGIN_NAMESPACE
@@ -101,8 +102,9 @@ protected:
-class QAccessibleMenuItem : public QAccessibleInterface
+class QAccessibleMenuItem : public QAccessibleActionInterface, public QAccessibleInterfaceEx
{
+ Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleMenuItem(QWidget *owner, QAction *w);
@@ -123,9 +125,17 @@ public:
virtual QString text ( Text t, int child ) const;
virtual int userActionCount ( int child ) const;
- QWidget *owner() const;
+ // action interface
+ virtual int actionCount();
+ virtual void doAction(int actionIndex);
+ virtual QString description(int);
+ virtual QString name(int);
+ virtual QString localizedName(int);
+ virtual QStringList keyBindings(int);
+ virtual QVariant invokeMethodEx(Method, int, const QVariantList &);
+ QWidget *owner() const;
protected:
QAction *action() const;
private: