📄 qaccessiblewidget.cpp
字号:
{ while (child) { if (child == obj) return true; child = child->parent(); } return false;}/*! \reimp */QAccessible::Relation QAccessibleWidget::relationTo(int child, const QAccessibleInterface *other, int otherChild) const{ Relation relation = Unrelated; if (d->asking == this) // recursive call return relation; QObject *o = other ? other->object() : 0; if (!o) return relation; QWidget *focus = widget()->focusWidget(); if (object() == focus && isAncestor(o, focus)) relation |= FocusChild; QACConnectionObject *connectionObject = (QACConnectionObject*)object(); for (int sig = 0; sig < d->primarySignals.count(); ++sig) { if (connectionObject->isSender(o, d->primarySignals.at(sig).toAscii())) { relation |= Controller; break; } } // test for passive relationships. // d->asking protects from endless recursion. d->asking = this; int inverse = other->relationTo(otherChild, this, child); d->asking = 0; if (inverse & Controller) relation |= Controlled; if (inverse & Label) relation |= Labelled; if(o == object()) { if (child && !otherChild) return relation | Child; if (!child && otherChild) return relation | Ancestor; if (!child && !otherChild) return relation | Self; } QObject *parent = object()->parent(); if (o == parent) return relation | Child; if (o->parent() == parent) { relation |= Sibling; QAccessibleInterface *sibIface = QAccessible::queryAccessibleInterface(o); Q_ASSERT(sibIface); QRect wg = rect(0); QRect sg = sibIface->rect(0); if (wg.intersects(sg)) { QAccessibleInterface *pIface = 0; sibIface->navigate(Ancestor, 1, &pIface); if (pIface && !((sibIface->state(0) | state(0)) & Invisible)) { int wi = pIface->indexOfChild(this); int si = pIface->indexOfChild(sibIface); if (wi > si) relation |= QAccessible::Covers; else 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 | Descendent; if (isAncestor(object(), o)) return relation | Ancestor; return relation;}/*! \reimp */int QAccessibleWidget::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const{ if (!target) return -1; *target = 0; QObject *targetObject = 0; QWidgetList childList = childWidgets(widget()); bool complexWidget = childList.size() < childCount(); switch (relation) { // Hierarchical case Self: targetObject = object(); break; case Child: if (complexWidget) { if (entry > 0 && entry <= childCount()) return entry; return -1; }else { if (entry > 0 && childList.size() >= entry) targetObject = childList.at(entry - 1); } break; case Ancestor: { if (entry <= 0) return -1; targetObject = widget()->parentWidget(); int i; for (i = entry; i > 1 && targetObject; --i) targetObject = targetObject->parent(); if (!targetObject && i == 1) targetObject = qApp; } break; case Sibling: { QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(parentObject()); if (!iface) return -1; iface->navigate(Child, entry, target); delete iface; if (*target) return 0; } break; // Geometrical case QAccessible::Left: if (complexWidget && entry) { if (entry < 2 || widget()->height() > widget()->width() + 20) // looks vertical return -1; return entry - 1; } // fall through case QAccessible::Right: if (complexWidget && entry) { if (entry >= childCount() || widget()->height() > widget()->width() + 20) // looks vertical return -1; return entry + 1; } // fall through case QAccessible::Up: if (complexWidget && entry) { if (entry < 2 || widget()->width() > widget()->height() + 20) // looks horizontal return - 1; return entry - 1; } // fall through case QAccessible::Down: if (complexWidget && entry) { if (entry >= childCount() || widget()->width() > widget()->height() + 20) // looks horizontal return - 1; return entry + 1; } else { QAccessibleInterface *pIface = QAccessible::queryAccessibleInterface(parentObject()); if (!pIface) return -1; QRect startg = rect(0); QPoint startc = startg.center(); QAccessibleInterface *candidate = 0; int mindist = 100000; int sibCount = pIface->childCount(); for (int i = 0; i < sibCount; ++i) { QAccessibleInterface *sibling = 0; pIface->navigate(Child, i+1, &sibling); Q_ASSERT(sibling); if ((relationTo(0, sibling, 0) & Self) || (sibling->state(0) & QAccessible::Invisible)) { //ignore ourself and invisible siblings delete sibling; continue; } QRect sibg = sibling->rect(0); 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 Covers: if (entry > 0) { QAccessibleInterface *pIface = QAccessible::queryAccessibleInterface(parentObject()); if (!pIface) return -1; QRect r = rect(0); int sibCount = pIface->childCount(); QAccessibleInterface *sibling = 0; for (int i = pIface->indexOfChild(this) + 1; i <= sibCount && entry; ++i) { pIface->navigate(Child, i, &sibling); if (!sibling || (sibling->state(0) & Invisible)) { delete sibling; sibling = 0; continue; } if (sibling->rect(0).intersects(r)) --entry; if (!entry) break; delete sibling; sibling = 0; } delete pIface; *target = sibling; if (*target) return 0; } break; case Covered: if (entry > 0) { QAccessibleInterface *pIface = QAccessible::queryAccessibleInterface(parentObject()); if (!pIface) return -1; QRect r = rect(0); int index = pIface->indexOfChild(this); QAccessibleInterface *sibling = 0; for (int i = 1; i < index && entry; ++i) { pIface->navigate(Child, i, &sibling); Q_ASSERT(sibling); if (!sibling || (sibling->state(0) & Invisible)) { delete sibling; sibling = 0; continue; } if (sibling->rect(0).intersects(r)) --entry; if (!entry) break; delete sibling; sibling = 0; } delete pIface; *target = sibling; if (*target) return 0; } break; // Logical case FocusChild: { if (widget()->hasFocus()) { targetObject = object(); break; } QWidget *fw = widget()->focusWidget(); if (!fw) return -1; if (isAncestor(widget(), fw) || fw == widget()) targetObject = fw; /* ### QWidget *parent = fw; while (parent && !targetObject) { parent = parent->parentWidget(); if (parent == widget()) targetObject = fw;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -