enum RelationFlag {
Unrelated = 0x00000000,
Self = 0x00000001,
- Ancestor = 0x00000002,
- Child = 0x00000004,
- Descendent = 0x00000008,
- Sibling = 0x00000010,
- HierarchyMask = 0x000000ff,
Up = 0x00000100,
Down = 0x00000200,
return 0;
}
break;
- case QAccessible::Ancestor:
- *target = parent();
- return 0;
default:
break;
}
QAccessibleInterface *child(int) const { return 0; }
int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
{
- if (relation == QAccessible::Ancestor && index == 1) {
- *iface = parent();
- return 0;
- }
+ Q_UNUSED(relation);
+ Q_UNUSED(index);
+ Q_UNUSED(iface);
return -1;
}
- QAccessible::Relation relationTo(const QAccessibleInterface *) const
- {
- return QAccessible::Unrelated;
- }
-
// action interface
QStringList actionNames() const
{
return qobject_cast<QTabBar*>(object());
}
-int QAccessibleTabBar::navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const
-{
- if (rel == QAccessible::Child) {
- *target = child(entry - 1);
- if (*target) {
- return 0;
- }
- return -1;
- }
- return QAccessibleWidget::navigate(rel, entry, target);
-}
-
QAccessibleInterface* QAccessibleTabBar::child(int index) const
{
// first the tabs, then 2 buttons
QWidget *targetWidget = 0;
QWidget *entryWidget = 0;
- if (relation == QAccessible::Child ||
- relation == QAccessible::Left || relation == QAccessible::Up || relation == QAccessible::Right || relation == QAccessible::Down) {
+ if (relation == QAccessible::Left || relation == QAccessible::Up || relation == QAccessible::Right || relation == QAccessible::Down) {
QWidgetList children = accessibleChildren();
if (entry < 0 || entry > children.count())
return -1;
// It might be possible to make it more general, but I'll leave that as an exercise
// to the reader. :-)
switch (relation) {
- case QAccessible::Child:
- if (entry > 0) {
- *target = child(entry - 1);
- return *target ? 0 : -1;
- }
case QAccessible::Left:
if (entry < 1)
break;
QAccessibleInterface* child(int index) const;
int indexOfChild(const QAccessibleInterface *child) const;
- int navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const;
protected:
QTabBar *tabBar() const;
int QAccessibleTable::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
{
+ Q_UNUSED(relation);
+ Q_UNUSED(index);
*iface = 0;
- switch (relation) {
- case QAccessible::Ancestor: {
- *iface = parent();
- return *iface ? 0 : -1;
- }
- case QAccessible::Child: {
- Q_ASSERT(index > 0);
- *iface = child(index - 1);
- if (*iface) {
- return 0;
- }
- break;
- }
- default:
- break;
- }
return -1;
}
return (treeView->d_func()->viewItems.count() + hHeader)* view->model()->columnCount();
}
+
+QAccessibleInterface *QAccessibleTree::child(int index) const
+{
+ Q_ASSERT(index >= 0);
+ int hHeader = horizontalHeader() ? 1 : 0;
+
+ if (hHeader) {
+ if (index < view->model()->columnCount()) {
+ return new QAccessibleTableHeaderCell(view, index, Qt::Horizontal);
+ } else {
+ index -= view->model()->columnCount();
+ }
+ }
+
+ int row = index / view->model()->columnCount();
+ int column = index % view->model()->columnCount();
+ QModelIndex modelIndex = indexFromLogical(row, column);
+ if (modelIndex.isValid()) {
+ return cell(modelIndex);
+ }
+ return 0;
+}
+
int QAccessibleTree::rowCount() const
{
const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
return -1;
}
-int QAccessibleTree::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
-{
- switch (relation) {
- case QAccessible::Child: {
- Q_ASSERT(index > 0);
- --index;
- int hHeader = horizontalHeader() ? 1 : 0;
-
- if (hHeader) {
- if (index < view->model()->columnCount()) {
- *iface = new QAccessibleTableHeaderCell(view, index, Qt::Horizontal);
- return 0;
- } else {
- index -= view->model()->columnCount();
- }
- }
-
- int row = index / view->model()->columnCount();
- int column = index % view->model()->columnCount();
- QModelIndex modelIndex = indexFromLogical(row, column);
- if (modelIndex.isValid()) {
- *iface = cell(modelIndex);
- return 0;
- }
- return -1;
- }
- default:
- break;
- }
- return QAccessibleTable::navigate(relation, index, iface);
-}
-
QAccessible::Relation QAccessibleTree::relationTo(const QAccessibleInterface *) const
{
return QAccessible::Unrelated;
int QAccessibleTableCell::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
{
- if (relation == QAccessible::Ancestor && index == 1) {
- *iface = parent();
- return 0;
- }
-
- *iface = 0;
- if (!view)
- return -1;
-
- switch (relation) {
-
- case QAccessible::Child: {
- return -1;
- }
- case QAccessible::Sibling:
- if (index > 0) {
- QAccessibleInterface *parent = QAccessible::queryAccessibleInterface(view);
- *iface = parent->child(index - 1);
- delete parent;
- return *iface ? 0 : -1;
- }
- return -1;
+ Q_UNUSED(index);
+ Q_UNUSED(relation);
+// switch (relation) {
// From table1 implementation:
// case Up:
// case Down:
// if (idx.parent() != row.parent() || idx.row() != row.row())
// *iface = cell(idx);
// return index ? kids.indexOf(idx) + 1 : 0; }
- default:
- break;
- }
-
+// }
+ *iface = 0;
return -1;
}
-QAccessible::Relation QAccessibleTableCell::relationTo(const QAccessibleInterface *other) const
-{
- // we only check for parent-child relationships in trees
- if (m_role == QAccessible::TreeItem && other->role() == QAccessible::TreeItem) {
- QModelIndex otherIndex = static_cast<const QAccessibleTableCell*>(other)->m_index;
- // is the other our parent?
- if (otherIndex.parent() == m_index)
- return QAccessible::Ancestor;
- // are we the other's child?
- if (m_index.parent() == otherIndex)
- return QAccessible::Child;
- }
- return QAccessible::Unrelated;
-}
-
QAccessibleTableHeaderCell::QAccessibleTableHeaderCell(QAbstractItemView *view_, int index_, Qt::Orientation orientation_)
: view(view_), index(index_), orientation(orientation_)
{
int QAccessibleTableHeaderCell::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
{
- if (relation == QAccessible::Ancestor && index == 1) {
- *iface = parent();
- return *iface ? 0 : -1;
- }
- *iface = 0;
+ Q_UNUSED(relation);
+ Q_UNUSED(index);
+ Q_UNUSED(iface);
+
return -1;
}
QAccessibleInterface *childAt(int x, int y) const;
int childCount() const;
+ QAccessibleInterface *child(int index) const;
+
int indexOfChild(const QAccessibleInterface *) const;
int rowCount() const;
- int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const;
QAccessible::Relation relationTo(const QAccessibleInterface *other) const;
// table interface
QAccessibleInterface *parent() const;
QAccessibleInterface *child(int) const;
int navigate(QAccessible::RelationFlag relation, int m_index, QAccessibleInterface **iface) const;
- QAccessible::Relation relationTo(const QAccessibleInterface *other) const;
// cell interface
virtual int columnExtent() const;
}
int navigate(QAccessible::RelationFlag relation, int, QAccessibleInterface **iface) const
{
- if (relation == QAccessible::Ancestor) {
- *iface = parent();
- return *iface ? 0 : -1;
- }
+ Q_UNUSED(relation);
+ Q_UNUSED(iface);
return -1;
}
+
QAccessible::Relation relationTo(const QAccessibleInterface *) const
{
return QAccessible::Unrelated;
return QAccessibleWidget::parent();
}
-int QAccessibleMenu::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const
-{
- Q_ASSERT(entry >= 0);
- switch (relation) {
- case QAccessible::Child:
- *target = child(entry - 1);
- return *target ? 0 : -1;
- case QAccessible::Ancestor:
- *target = parent();
- return *target ? 0 : -1;
- default:
- return QAccessibleWidget::navigate(relation, entry, target);
- }
-}
-
int QAccessibleMenu::indexOfChild( const QAccessibleInterface *child) const
{
int index = -1;
return 0;
}
-int QAccessibleMenuBar::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const
-{
- if (relation == QAccessible::Child) {
- *target = child(entry - 1);
- return *target ? 0 : -1;
- }
- return QAccessibleWidget::navigate(relation, entry, target);
-}
-
int QAccessibleMenuBar::indexOfChild(const QAccessibleInterface *child) const
{
int index = -1;
}
switch (relation) {
- case QAccessible::Child:
- *target = child(entry - 1);
- break;
- case QAccessible::Ancestor:
- *target = parent();
- break;
case QAccessible::Up:
case QAccessible::Down:{
QAccessibleInterface *parentIface = parent();
delete parentIface;
break;
}
- case QAccessible::Sibling: {
- QAccessibleInterface *parentIface = parent();
- if (parentIface)
- *target = parentIface->child(entry - 1);
- delete parentIface;
- break;
- }
default:
break;
return rect;
}
-QAccessible::Relation QAccessibleMenuItem::relationTo(const QAccessibleInterface *other) const
-{
- if (other->object() == owner()) {
- return QAccessible::Child;
- }
- Q_UNUSED(other)
- // ###
- return QAccessible::Unrelated;
-}
-
QAccessible::Role QAccessibleMenuItem::role() const
{
return m_action->isSeparator() ? QAccessible::Separator : QAccessible::MenuItem;
QAccessible::Role role() const;
QAccessibleInterface *child(int index) const;
QAccessibleInterface *parent() const;
- int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const;
int indexOfChild( const QAccessibleInterface *child ) const;
protected:
QAccessibleInterface *child(int index) const;
int childCount() const;
- int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const;
int indexOfChild(const QAccessibleInterface *child) const;
protected:
int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface ** target) const;
QObject * object() const;
QRect rect() const;
- QAccessible::Relation relationTo(const QAccessibleInterface *other) const;
QAccessible::Role role() const;
void setText(QAccessible::Text t, const QString & text);
QAccessible::State state() const;
QVariant QAccessibleStackedWidget::invokeMethod(QAccessible::Method, const QVariantList ¶ms)
{
+ Q_UNUSED(params);
return QVariant();
}
return QAccessible::queryAccessibleInterface(stackedWidget()->widget(index));
}
-int QAccessibleStackedWidget::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const
-{
- switch (relation) {
- case QAccessible::Child:
- *target = child(entry - 1);
- return *target ? 0 : -1;
- default:
- return QAccessibleWidget::navigate(relation, entry, target);
- }
-}
-
QStackedWidget *QAccessibleStackedWidget::stackedWidget() const
{
return static_cast<QStackedWidget *>(object());
return mdiArea()->subWindowList().count();
}
+QAccessibleInterface *QAccessibleMdiArea::child(int index) const
+{
+ QList<QMdiSubWindow *> subWindows = mdiArea()->subWindowList();
+ QWidget *targetObject = subWindows.value(index);
+ if (!targetObject)
+ return 0;
+ return QAccessible::queryAccessibleInterface(targetObject);
+}
+
+
int QAccessibleMdiArea::indexOfChild(const QAccessibleInterface *child) const
{
if (!child || !child->object() || mdiArea()->subWindowList().isEmpty())
{
*target = 0;
QWidget *targetObject = 0;
- QList<QMdiSubWindow *> subWindows = mdiArea()->subWindowList();
switch (relation) {
- case QAccessible::Child:
- if (entry < 1 || subWindows.isEmpty() || entry > subWindows.count())
- return -1;
- targetObject = subWindows.at(entry - 1);
- break;
case QAccessible::Up:
case QAccessible::Down:
case QAccessible::Left:
return 0;
}
+QAccessibleInterface *QAccessibleMdiSubWindow::child(int index) const
+{
+ QMdiSubWindow *source = mdiSubWindow();
+ if (index != 0 || !source->widget())
+ return 0;
+
+ return QAccessible::queryAccessibleInterface(source->widget());
+}
+
int QAccessibleMdiSubWindow::indexOfChild(const QAccessibleInterface *child) const
{
if (child && child->object() && child->object() == mdiSubWindow()->widget())
QWidget *targetObject = 0;
QMdiSubWindow *source = mdiSubWindow();
switch (relation) {
- case QAccessible::Child:
- if (entry != 1 || !source->widget())
- return -1;
- targetObject = source->widget();
- break;
case QAccessible::Up:
case QAccessible::Down:
case QAccessible::Left:
return workspace()->windowList().count();
}
+QAccessibleInterface *QAccessibleWorkspace::child(int index) const
+{
+ QWidgetList subWindows = workspace()->windowList();
+ if (index < 0 || subWindows.isEmpty() || index >= subWindows.count())
+ return 0;
+ QObject *targetObject = subWindows.at(index);
+ return QAccessible::queryAccessibleInterface(targetObject);
+}
+
int QAccessibleWorkspace::indexOfChild(const QAccessibleInterface *child) const
{
if (!child || !child->object() || workspace()->windowList().isEmpty())
{
*target = 0;
QWidget *targetObject = 0;
- QWidgetList subWindows = workspace()->windowList();
switch (relation) {
- case QAccessible::Child:
- if (entry < 1 || subWindows.isEmpty() || entry > subWindows.count())
- return -1;
- targetObject = subWindows.at(entry - 1);
- break;
case QAccessible::Up:
case QAccessible::Down:
case QAccessible::Left:
return QAccessibleWidget::navigate(relation, entry, target);
QWidget *targetWidget = 0;
switch (relation) {
- case QAccessible::Child:
- *target = child(entry - 1);
- return *target ? 0 : -1;
case QAccessible::Up:
if (entry == 2)
targetWidget = navigationBar();
int QAccessibleTitleBar::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **iface) const
{
switch (relation) {
- case QAccessible::Child:
- *iface = child(entry - 1);
- return *iface ? 0 : -1;
case QAccessible::FocusChild:
// ###
if (entry >= 1) {
return role > QDockWidgetLayout::FloatButton ? -1 : index;
}
break;
- case QAccessible::Ancestor:
- *iface = parent();
- return iface ? 0 : -1;
default:
break;
}
int childCount() const;
int indexOfChild(const QAccessibleInterface *child) const;
QAccessibleInterface *child(int index) const;
- int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const;
protected:
QStackedWidget *stackedWidget() const;
explicit QAccessibleMdiArea(QWidget *widget);
int childCount() const;
+ QAccessibleInterface *child(int index) const;
int indexOfChild(const QAccessibleInterface *child) const;
int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const;
void setText(QAccessible::Text textType, const QString &text);
QAccessible::State state() const;
int childCount() const;
+ QAccessibleInterface *child(int index) const;
int indexOfChild(const QAccessibleInterface *child) const;
int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const;
QRect rect() const;
explicit QAccessibleWorkspace(QWidget *widget);
int childCount() const;
+ QAccessibleInterface *child(int index) const;
int indexOfChild(const QAccessibleInterface *child) const;
int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const;
} else {
QGroupBox *groupbox = qobject_cast<QGroupBox*>(object());
if (groupbox && !groupbox->title().isEmpty())
- rel = QAccessible::Child;
+ *target = child(entry - 1);
#endif
}
- *target = QAccessible::queryAccessibleInterface(targetObject);
+ if (targetObject)
+ *target = QAccessible::queryAccessibleInterface(targetObject);
if (*target)
return 0;
}
return E_FAIL;
QAccessibleInterface *acc = 0;
- int control = -1;
switch (navDir) {
case NAVDIR_FIRSTCHILD:
- control = accessible->navigate(QAccessible::Child, 1, &acc);
+ acc = accessible->child(0);
break;
case NAVDIR_LASTCHILD:
- control = accessible->navigate(QAccessible::Child, accessible->childCount(), &acc);
+ acc = accessible->child(accessible->childCount() - 1);
break;
case NAVDIR_NEXT:
case NAVDIR_PREVIOUS:
int index = parent->indexOfChild(accessible);
index += (navDir == NAVDIR_NEXT) ? 1 : -1;
if (index > 0 && index <= parent->childCount())
- control = parent->navigate(QAccessible::Child, index, &acc);
+ acc = parent->child(index - 1);
delete parent;
}
} else {
int index = varStart.lVal;
index += (navDir == NAVDIR_NEXT) ? 1 : -1;
if (index > 0 && index <= accessible->childCount())
- control = accessible->navigate(QAccessible::Child, index, &acc);
+ acc = accessible->child(index - 1);
}
break;
+
+ // Geometrical
case NAVDIR_UP:
- control = accessible->navigate(QAccessible::Up, varStart.lVal, &acc);
- break;
case NAVDIR_DOWN:
- control = accessible->navigate(QAccessible::Down, varStart.lVal, &acc);
- break;
case NAVDIR_LEFT:
- control = accessible->navigate(QAccessible::Left, varStart.lVal, &acc);
- break;
case NAVDIR_RIGHT:
- control = accessible->navigate(QAccessible::Right, varStart.lVal, &acc);
+ if (QAccessibleInterface *pIface = accessible->parent()) {
+
+ QRect startg = accessible->rect();
+ QPoint startc = startg.center();
+ QAccessibleInterface *candidate = 0;
+ unsigned mindist = UINT_MAX; // will work on screen sizes at least up to 46340x46340
+ const int sibCount = pIface->childCount();
+ for (int i = 0; i < sibCount; ++i) {
+ QAccessibleInterface *sibling = 0;
+ sibling = pIface->child(i);
+ Q_ASSERT(sibling);
+ if ((accessible->relationTo(sibling) & QAccessible::Self) || (sibling->state() & QAccessible::Invisible)) {
+ //ignore ourself and invisible siblings
+ delete sibling;
+ continue;
+ }
+
+ QRect sibg = sibling->rect();
+ QPoint sibc = sibg.center();
+ QPoint sibp;
+ QPoint startp;
+ QPoint distp;
+ switch (navDir) {
+ case NAVDIR_LEFT:
+ startp = QPoint(startg.left(), startg.top() + startg.height() / 2);
+ sibp = QPoint(sibg.right(), sibg.top() + sibg.height() / 2);
+ if (QPoint(sibc - startc).x() >= 0) {
+ delete sibling;
+ continue;
+ }
+ distp = sibp - startp;
+ break;
+ case NAVDIR_RIGHT:
+ startp = QPoint(startg.right(), startg.top() + startg.height() / 2);
+ sibp = QPoint(sibg.left(), sibg.top() + sibg.height() / 2);
+ if (QPoint(sibc - startc).x() <= 0) {
+ delete sibling;
+ continue;
+ }
+ distp = sibp - startp;
+ break;
+ case NAVDIR_UP:
+ startp = QPoint(startg.left() + startg.width() / 2, startg.top());
+ sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.bottom());
+ if (QPoint(sibc - startc).y() >= 0) {
+ delete sibling;
+ continue;
+ }
+ distp = sibp - startp;
+ break;
+ case NAVDIR_DOWN:
+ startp = QPoint(startg.left() + startg.width() / 2, startg.bottom());
+ sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.top());
+ if (QPoint(sibc - startc).y() <= 0) {
+ delete sibling;
+ continue;
+ }
+ distp = sibp - startp;
+ break;
+ default:
+ break;
+ }
+
+ // Since we're *comparing* (and not measuring) distances, we can compare the
+ // squared distance, (thus, no need to take the sqrt()).
+ unsigned dist = distp.x() * distp.x() + distp.y() * distp.y();
+ if (dist < mindist) {
+ delete candidate;
+ candidate = sibling;
+ mindist = dist;
+ } else {
+ delete sibling;
+ }
+ }
+ delete pIface;
+ acc = candidate;
+ }
break;
default:
break;
}
- if (control == -1) {
+ if (!acc) {
(*pvarEnd).vt = VT_EMPTY;
return S_FALSE;
}
- if (!acc) {
- (*pvarEnd).vt = VT_I4;
- (*pvarEnd).lVal = control;
- return S_OK;
- }
-
QWindowsAccessible* wacc = new QWindowsAccessible(acc);
IDispatch *iface = 0;
acc = QAccessible::queryAccessibleInterface(ref.first);
if (acc && ref.second) {
if (ref.second) {
- QAccessibleInterface *res;
- int index = acc->navigate(QAccessible::Child, ref.second, &res);
+ QAccessibleInterface *res = acc->child(ref.second - 1);
delete acc;
- if (index == -1)
+ if (!res)
return E_INVALIDARG;
acc = res;
}
}
}
} else {
- QAccessible::RelationFlag rel = childIndex ? QAccessible::Child : QAccessible::Self;
- accessible->navigate(rel, childIndex, &acc);
+ if (childIndex) {
+ acc = accessible->child(childIndex - 1);
+ } else {
+ // FIXME
+ Q_ASSERT(0);
+ }
}
if (acc) {
}
QObject *parent = object()->parent();
- if (o == parent)
- return relation | QAccessible::Child;
-
if (o->parent() == parent) {
- relation |= QAccessible::Sibling;
QAccessibleInterface *sibIface = QAccessible::queryAccessibleInterface(o);
Q_ASSERT(sibIface);
QRect wg = rect();
relation |= QAccessible::Covered;
}
delete pIface;
- } else {
- QPoint wc = wg.center();
- QPoint sc = sg.center();
- if (wc.x() < sc.x())
- relation |= QAccessible::Left;
- else if(wc.x() > sc.x())
- relation |= QAccessible::Right;
- if (wc.y() < sc.y())
- relation |= QAccessible::Up;
- else if (wc.y() > sc.y())
- relation |= QAccessible::Down;
}
delete sibIface;
return relation;
}
- if (isAncestor(o, object()))
- return relation | QAccessible::Descendent;
- if (isAncestor(object(), o))
- return relation | QAccessible::Ancestor;
-
return relation;
}
QObject *targetObject = 0;
switch (relation) {
- // Hierarchical
- case QAccessible::Self:
- targetObject = object();
- break;
- case QAccessible::Child:
- qWarning() << "QAccessibleWidget::navigate is deprecated for QAccessible::Child in:" << object()->metaObject()->className();
- *target = child(entry - 1);
- return *target ? 0 : -1;
- case QAccessible::Ancestor:
- qWarning() << "QAccessibleWidget::navigate is deprecated for QAccessible::Ancestor in:" << object()->metaObject()->className();
- *target = parent();
- return *target ? 0 : -1;
- case QAccessible::Sibling:
- {
- QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(parentObject());
- if (!iface)
- return -1;
-
- *target = iface->child(entry - 1);
- delete iface;
- if (*target)
- return 0;
- }
- break;
-
- // Geometrical
- case QAccessible::Left:
- // fall through
- case QAccessible::Right:
- // fall through
- case QAccessible::Up:
- // fall through
- case QAccessible::Down:
- {
- QAccessibleInterface *pIface = parent();
- if (!pIface)
- return -1;
-
- QRect startg = rect();
- QPoint startc = startg.center();
- QAccessibleInterface *candidate = 0;
- int mindist = 100000;
- int sibCount = pIface->childCount();
- for (int i = 0; i < sibCount; ++i) {
- QAccessibleInterface *sibling = 0;
- sibling = pIface->child(i);
- Q_ASSERT(sibling);
- if ((relationTo(sibling) & QAccessible::Self) || (sibling->state() & QAccessible::Invisible)) {
- //ignore ourself and invisible siblings
- delete sibling;
- continue;
- }
-
- QRect sibg = sibling->rect();
- QPoint sibc = sibg.center();
- QPoint sibp;
- QPoint startp;
- QPoint distp;
- switch (relation) {
- case QAccessible::Left:
- startp = QPoint(startg.left(), startg.top() + startg.height() / 2);
- sibp = QPoint(sibg.right(), sibg.top() + sibg.height() / 2);
- if (QPoint(sibc - startc).x() >= 0) {
- delete sibling;
- continue;
- }
- distp = sibp - startp;
- break;
- case QAccessible::Right:
- startp = QPoint(startg.right(), startg.top() + startg.height() / 2);
- sibp = QPoint(sibg.left(), sibg.top() + sibg.height() / 2);
- if (QPoint(sibc - startc).x() <= 0) {
- delete sibling;
- continue;
- }
- distp = sibp - startp;
- break;
- case QAccessible::Up:
- startp = QPoint(startg.left() + startg.width() / 2, startg.top());
- sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.bottom());
- if (QPoint(sibc - startc).y() >= 0) {
- delete sibling;
- continue;
- }
- distp = sibp - startp;
- break;
- case QAccessible::Down:
- startp = QPoint(startg.left() + startg.width() / 2, startg.bottom());
- sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.top());
- if (QPoint(sibc - startc).y() <= 0) {
- delete sibling;
- continue;
- }
- distp = sibp - startp;
- break;
- default:
- break;
- }
-
- int dist = (int)qSqrt((qreal)distp.x() * distp.x() + distp.y() * distp.y());
- if (dist < mindist) {
- delete candidate;
- candidate = sibling;
- mindist = dist;
- } else {
- delete sibling;
- }
- }
- delete pIface;
- *target = candidate;
- if (*target)
- return 0;
- }
- break;
case QAccessible::Covers:
if (entry > 0) {
QAccessibleInterface *pIface = QAccessible::queryAccessibleInterface(parentObject());
void customWidget();
void deletedWidget();
- void navigateGeometric();
void navigateHierarchy();
void sliderTest();
void navigateCovered();
delete iface;
}
-void tst_QAccessibility::navigateGeometric()
-{
- {
- static const int skip = 20; //speed the test up significantly
- static const double step = Q_PI / 180;
- QWidget *w = new QWidget(0);
- w->setObjectName(QString("Josef"));
- w->setFixedSize(400, 400);
-
- // center widget
- QtTestAccessibleWidget *center = new QtTestAccessibleWidget(w, "Sol");
- center->move(200, 200);
-
- // arrange 360 widgets around it in a circle
- QtTestAccessibleWidget *aw = 0;
- for (int i = 0; i < 360; i += skip) {
- aw = new QtTestAccessibleWidget(w, QString::number(i).toLatin1());
- aw->move( int(200.0 + 100.0 * sin(step * (double)i)), int(200.0 + 100.0 * cos(step * (double)i)) );
- }
-
- aw = new QtTestAccessibleWidget(w, "Earth");
- QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(center);
- QAccessibleInterface *target = 0;
- QVERIFY(iface != 0);
- QVERIFY(iface->isValid());
-
- w->show();
- QCoreApplication::processEvents();
- QTest::qWait(100);
-
- // let one widget rotate around center
- for (int i = 0; i < 360; i+=skip) {
- aw->move( int(200.0 + 75.0 * sin(step * (double)i)), int(200.0 + 75.0 * cos(step * (double)i)) );
-
- if (i < 45 || i > 315) {
- QCOMPARE(iface->navigate(QAccessible::Down, 0, &target), 0);
- } else if ( i < 135 ) {
- QCOMPARE(iface->navigate(QAccessible::Right, 0, &target), 0);
- } else if ( i < 225 ) {
- QCOMPARE(iface->navigate(QAccessible::Up, 0, &target), 0);
- } else {
- QCOMPARE(iface->navigate(QAccessible::Left, 0, &target), 0);
- }
-
- QVERIFY(target);
- QVERIFY(target->isValid());
- QVERIFY(target->object());
- QCOMPARE(target->object()->objectName(), aw->objectName());
- delete target; target = 0;
- }
-
- // test invisible widget
- target = QAccessible::queryAccessibleInterface(aw);
- QVERIFY(!(target->state() & QAccessible::Invisible));
- aw->hide();
- QVERIFY(target->state() & QAccessible::Invisible);
- delete target; target = 0;
-
- aw->move(center->x() + 10, center->y());
- QCOMPARE(iface->navigate(QAccessible::Right, 0, &target), 0);
- QVERIFY(target);
- QVERIFY(target->isValid());
- QVERIFY(target->object());
- QVERIFY(QString(target->object()->objectName()) != "Earth");
- delete target; target = 0;
-
- aw->move(center->x() - 10, center->y());
- QCOMPARE(iface->navigate(QAccessible::Left, 0, &target), 0);
- QVERIFY(target);
- QVERIFY(target->isValid());
- QVERIFY(target->object());
- QVERIFY(QString(target->object()->objectName()) != "Earth");
- delete target; target = 0;
-
- aw->move(center->x(), center->y() + 10);
- QCOMPARE(iface->navigate(QAccessible::Down, 0, &target), 0);
- QVERIFY(target);
- QVERIFY(target->isValid());
- QVERIFY(target->object());
- QVERIFY(QString(target->object()->objectName()) != "Earth");
- delete target; target = 0;
-
- aw->move(center->x(), center->y() - 10);
- QCOMPARE(iface->navigate(QAccessible::Up, 0, &target), 0);
- QVERIFY(target);
- QVERIFY(target->isValid());
- QVERIFY(target->object());
- QVERIFY(QString(target->object()->objectName()) != "Earth");
- delete target; target = 0;
-
- delete iface;
- delete w;
- }
- QTestAccessibility::clearEvents();
-}
-
void tst_QAccessibility::sliderTest()
{
{
QVERIFY(iface != 0);
QVERIFY(iface->isValid());
- QCOMPARE(iface->navigate(QAccessible::Sibling, -42, &target), -1);
- QVERIFY(target == 0);
- QCOMPARE(iface->navigate(QAccessible::Sibling, 42, &target), -1);
- QVERIFY(target == 0);
-
target = iface->child(14);
QVERIFY(target == 0);
target = iface->child(-1);
delete interfaceW1;
delete iface; iface = 0;
- QCOMPARE(target->navigate(QAccessible::Sibling, 0, &iface), -1);
- QVERIFY(iface == 0);
- QCOMPARE(target->navigate(QAccessible::Sibling, 42, &iface), -1);
- QVERIFY(iface == 0);
- QCOMPARE(target->navigate(QAccessible::Sibling, -42, &iface), -1);
- QVERIFY(iface == 0);
- QCOMPARE(target->navigate(QAccessible::Sibling, 2, &iface), 0);
- QVERIFY(iface != 0);
- QVERIFY(iface->isValid());
- QCOMPARE(iface->object(), (QObject*)w2);
- delete target; target = 0;
- QCOMPARE(iface->navigate(QAccessible::Sibling, 3, &target), 0);
+ iface = QAccessible::queryAccessibleInterface(w);
+ target = iface->child(2);
QVERIFY(target != 0);
QVERIFY(target->isValid());
QCOMPARE(target->object(), (QObject*)w3);
delete iface; iface = 0;
+
+ iface = target->child(1);
+ QCOMPARE(iface, (QAccessibleInterface*)0);
iface = target->child(0);
QVERIFY(iface != 0);
QVERIFY(iface->isValid());
QCOMPARE(iface->object(), (QObject*)w31);
- delete target; target = 0;
- QCOMPARE(iface->navigate(QAccessible::Sibling, -1, &target), -1);
- QVERIFY(target == 0);
- QCOMPARE(iface->navigate(QAccessible::Sibling, 0, &target), -1);
- QVERIFY(target == 0);
- QCOMPARE(iface->navigate(QAccessible::Sibling, 1, &target), 0);
- QVERIFY(target != 0);
- QVERIFY(target->isValid());
+ iface = QAccessible::queryAccessibleInterface(w);
+ QAccessibleInterface *acc3 = iface->child(2);
+ target = acc3->child(0);
+ delete acc3;
+ delete iface;
QCOMPARE(target->object(), (QObject*)w31);
- delete iface; iface = 0;
iface = target->parent();
QVERIFY(iface != 0);
QAccessible::MenuItem
};
for (int child = 0; child < 5; ++child) {
- entry = iface->navigate(QAccessible::Sibling, child + 1, &iface2);
- QCOMPARE(entry, 0);
+ iface2 = interface->child(child);
QVERIFY(iface2);
QCOMPARE(iface2->role(), fileRoles[child]);
delete iface2;
QTestAccessibility::clearEvents();
}
+bool accessibleInterfaceLeftOf(const QAccessibleInterface *a1, const QAccessibleInterface *a2)
+{
+ return a1->rect().x() < a2->rect().x();
+}
+
+bool accessibleInterfaceAbove(const QAccessibleInterface *a1, const QAccessibleInterface *a2)
+{
+ return a1->rect().y() < a2->rect().y();
+}
+
void tst_QAccessibility::dialogButtonBoxTest()
{
{
QCOMPARE(iface->role(), QAccessible::Grouping);
QStringList actualOrder;
QAccessibleInterface *child;
- QAccessibleInterface *leftmost;
child = iface->child(0);
QCOMPARE(child->role(), QAccessible::PushButton);
- // first find the leftmost button
- while (child->navigate(QAccessible::Left, 1, &leftmost) != -1) {
- delete child;
- child = leftmost;
- }
- leftmost = child;
-
- // then traverse from left to right to find the correct order of the buttons
- int right = 0;
- while (right != -1) {
- actualOrder << leftmost->text(QAccessible::Name);
- right = leftmost->navigate(QAccessible::Right, 1, &child);
- delete leftmost;
- leftmost = child;
- }
+ QVector<QAccessibleInterface *> buttons;
+ for (int i = 0; i < iface->childCount(); ++i)
+ buttons << iface->child(i);
+
+ qSort(buttons.begin(), buttons.end(), accessibleInterfaceLeftOf);
+
+ for (int i = 0; i < buttons.count(); ++i)
+ actualOrder << buttons.at(i)->text(QAccessible::Name);
QStringList expectedOrder;
QDialogButtonBox::ButtonLayout btnlout =
#endif
QApplication::processEvents();
- QAccessibleInterface *child;
QStringList actualOrder;
- child = iface->child(0);
- // first find the topmost button
- QAccessibleInterface *other;
- while (child->navigate(QAccessible::Up, 1, &other) != -1) {
- delete child;
- child = other;
- }
- other = child;
-
- // then traverse from top to bottom to find the correct order of the buttons
- actualOrder.clear();
- int right = 0;
- while (right != -1) {
- actualOrder << other->text(QAccessible::Name);
- right = other->navigate(QAccessible::Down, 1, &child);
- delete other;
- other = child;
- }
+
+ QVector<QAccessibleInterface *> buttons;
+ for (int i = 0; i < iface->childCount(); ++i)
+ buttons << iface->child(i);
+
+ qSort(buttons.begin(), buttons.end(), accessibleInterfaceAbove);
+
+ for (int i = 0; i < buttons.count(); ++i)
+ actualOrder << buttons.at(i)->text(QAccessible::Name);
QStringList expectedOrder;
expectedOrder << QDialogButtonBox::tr("OK")