- Timestamp:
- Oct 31, 2016 3:18:41 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 111629
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r63961 r64493 55 55 56 56 57 /** QAccessibleObject extension used as an accessibility interface for Snapshot item. */58 class UIAccessibilityInterfaceForUISnapshotItem : public QAccessibleObject59 {60 public:61 62 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */63 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)64 {65 /* Creating Snapshot item accessibility interface: */66 if (pObject && strClassname == QLatin1String("UISnapshotItem"))67 return new UIAccessibilityInterfaceForUISnapshotItem(pObject);68 69 /* Null by default: */70 return 0;71 }72 73 /** Constructs an accessibility interface passing @a pObject to the base-class. */74 UIAccessibilityInterfaceForUISnapshotItem(QObject *pObject)75 : QAccessibleObject(pObject)76 {}77 78 /** Returns the parent. */79 virtual QAccessibleInterface *parent() const /* override */;80 81 /** Returns the number of children. */82 virtual int childCount() const /* override */;83 /** Returns the child with the passed @a iIndex. */84 virtual QAccessibleInterface *child(int iIndex) const /* override */;85 /** Returns the index of the passed @a pChild. */86 virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */;87 88 /** Returns the rect. */89 virtual QRect rect() const /* override */;90 /** Returns a text for the passed @a enmTextRole. */91 virtual QString text(QAccessible::Text enmTextRole) const /* override */;92 93 /** Returns the role. */94 virtual QAccessible::Role role() const /* override */;95 /** Returns the state. */96 virtual QAccessible::State state() const /* override */;97 98 private:99 100 /** Returns corresponding Snapshot item. */101 UISnapshotItem *item() const { return qobject_cast<UISnapshotItem*>(object()); }102 };103 104 105 /** QAccessibleWidget extension used as an accessibility interface for Snapshot tree. */106 class UIAccessibilityInterfaceForUISnapshotTree : public QAccessibleWidget107 {108 public:109 110 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */111 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)112 {113 /* Creating Snapshot tree accessibility interface: */114 if (pObject && strClassname == QLatin1String("UISnapshotTree"))115 return new UIAccessibilityInterfaceForUISnapshotTree(qobject_cast<QWidget*>(pObject));116 117 /* Null by default: */118 return 0;119 }120 121 /** Constructs an accessibility interface passing @a pWidget to the base-class. */122 UIAccessibilityInterfaceForUISnapshotTree(QWidget *pWidget)123 : QAccessibleWidget(pWidget, QAccessible::List)124 {}125 126 /** Returns the number of children. */127 virtual int childCount() const /* override */;128 /** Returns the child with the passed @a iIndex. */129 virtual QAccessibleInterface *child(int iIndex) const /* override */;130 131 /** Returns a text for the passed @a enmTextRole. */132 virtual QString text(QAccessible::Text enmTextRole) const /* override */;133 134 private:135 136 /** Returns corresponding Snapshot tree. */137 UISnapshotTree *tree() const { return qobject_cast<UISnapshotTree*>(widget()); }138 };139 140 141 57 /** QTreeWidgetItem subclass for snapshots items. */ 142 58 class UISnapshotItem : public QObject, public QTreeWidgetItem … … 260 176 UISnapshotItem *childSnapshotItem(int iIndex) const; 261 177 }; 262 263 264 /*********************************************************************************************************************************265 * Class UIAccessibilityInterfaceForUISnapshotItem implementation. *266 *********************************************************************************************************************************/267 268 QAccessibleInterface *UIAccessibilityInterfaceForUISnapshotItem::parent() const269 {270 /* Make sure item still alive: */271 AssertPtrReturn(item(), 0);272 273 /* Return the parent: */274 return item()->parentSnapshotItem() ?275 QAccessible::queryAccessibleInterface(item()->parentSnapshotItem()) :276 QAccessible::queryAccessibleInterface(item()->parentSnapshotTree());277 }278 279 int UIAccessibilityInterfaceForUISnapshotItem::childCount() const280 {281 /* Make sure item still alive: */282 AssertPtrReturn(item(), 0);283 284 /* Return the number of children: */285 return item()->childCount();286 }287 288 QAccessibleInterface *UIAccessibilityInterfaceForUISnapshotItem::child(int iIndex) const289 {290 /* Make sure item still alive: */291 AssertPtrReturn(item(), 0);292 /* Make sure index is valid: */293 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);294 295 /* Return the child with the passed iIndex: */296 return QAccessible::queryAccessibleInterface(item()->childSnapshotItem(iIndex));297 }298 299 int UIAccessibilityInterfaceForUISnapshotItem::indexOfChild(const QAccessibleInterface *pChild) const300 {301 /* Search for corresponding child: */302 for (int i = 0; i < childCount(); ++i)303 if (child(i) == pChild)304 return i;305 306 /* -1 by default: */307 return -1;308 }309 310 QRect UIAccessibilityInterfaceForUISnapshotItem::rect() const311 {312 /* Make sure item still alive: */313 AssertPtrReturn(item(), QRect());314 315 /* Compose common region: */316 QRegion region;317 318 /* Append item rectangle: */319 const QRect itemRectInViewport = item()->parentSnapshotTree()->visualItemRect(item());320 const QSize itemSize = itemRectInViewport.size();321 const QPoint itemPosInViewport = itemRectInViewport.topLeft();322 const QPoint itemPosInScreen = item()->parentSnapshotTree()->viewport()->mapToGlobal(itemPosInViewport);323 const QRect itemRectInScreen = QRect(itemPosInScreen, itemSize);324 region += itemRectInScreen;325 326 /* Append children rectangles: */327 for (int i = 0; i < childCount(); ++i)328 region += child(i)->rect();329 330 /* Return common region bounding rectangle: */331 return region.boundingRect();332 }333 334 QString UIAccessibilityInterfaceForUISnapshotItem::text(QAccessible::Text enmTextRole) const335 {336 /* Make sure item still alive: */337 AssertPtrReturn(item(), QString());338 339 /* Return a text for the passed enmTextRole: */340 switch (enmTextRole)341 {342 case QAccessible::Name: return item()->text(0);343 default: break;344 }345 346 /* Null-string by default: */347 return QString();348 }349 350 QAccessible::Role UIAccessibilityInterfaceForUISnapshotItem::role() const351 {352 /* Return the role of item with children: */353 if (childCount() > 0)354 return QAccessible::List;355 356 /* TreeItem by default: */357 return QAccessible::ListItem;358 }359 360 QAccessible::State UIAccessibilityInterfaceForUISnapshotItem::state() const361 {362 /* Make sure item still alive: */363 AssertPtrReturn(item(), QAccessible::State());364 365 /* Compose the state: */366 QAccessible::State state;367 state.focusable = true;368 state.selectable = true;369 370 /* Compose the state of current item: */371 if ( item()372 && item() == UISnapshotPane::toSnapshotItem(item()->treeWidget()->currentItem()))373 {374 state.active = true;375 state.focused = true;376 state.selected = true;377 }378 379 /* Return the state: */380 return state;381 }382 383 384 /*********************************************************************************************************************************385 * Class UIAccessibilityInterfaceForUISnapshotTree implementation. *386 *********************************************************************************************************************************/387 388 int UIAccessibilityInterfaceForUISnapshotTree::childCount() const389 {390 /* Make sure tree still alive: */391 AssertPtrReturn(tree(), 0);392 393 /* Return the number of children: */394 return tree()->childCount();395 }396 397 QAccessibleInterface *UIAccessibilityInterfaceForUISnapshotTree::child(int iIndex) const398 {399 /* Make sure tree still alive: */400 AssertPtrReturn(tree(), 0);401 /* Make sure index is valid: */402 AssertReturn(iIndex >= 0, 0);403 if (iIndex >= childCount())404 {405 // WORKAROUND:406 // Normally I would assert here, but Qt5 accessibility code has407 // a hard-coded architecture for a tree-views which we do not like408 // but have to live with and this architecture enumerates children409 // of all levels as children of level 0, so Qt5 can try to address410 // our interface with index which surely out of bounds by our laws.411 // So let's assume that's exactly such case and try to enumerate412 // visible children like they are a part of the list, not tree.413 // printf("Invalid index: %d\n", iIndex);414 415 // Visible children indexes starts with 1, not 0,416 // don't ask me why, it's some stupid Qt5 idea:417 const int iRequiredIndex = iIndex - 1;418 419 // Do some sanity check as well, enough?420 AssertReturn(iRequiredIndex >= 0, 0);421 422 // Try to find a visible child with required index:423 int iCurrentIndex = 0;424 QTreeWidgetItem *pItem = tree()->topLevelItem(0);425 while (pItem && iCurrentIndex < iRequiredIndex)426 {427 ++iCurrentIndex;428 pItem = tree()->itemBelow(pItem);429 }430 431 // Return what we found:432 // if (pItem)433 // printf("Item found: [%s]\n", pItem->text(0).toUtf8().constData());434 return pItem ? QAccessible::queryAccessibleInterface(UISnapshotPane::toSnapshotItem(pItem)) : 0;435 }436 437 /* Return the child with the passed iIndex: */438 return QAccessible::queryAccessibleInterface(tree()->childSnapshotItem(iIndex));439 }440 441 QString UIAccessibilityInterfaceForUISnapshotTree::text(QAccessible::Text /* enmTextRole */) const442 {443 /* Make sure tree still alive: */444 AssertPtrReturn(tree(), QString());445 446 /* Return tree tool-tip: */447 return tree()->toolTip();448 }449 178 450 179 … … 777 506 : QTreeWidget(pParent) 778 507 { 779 /* Install Snapshot tree accessibility interface factory: */780 QAccessible::installFactory(UIAccessibilityInterfaceForUISnapshotTree::pFactory);781 /* Install Snapshot item accessibility interface factory: */782 QAccessible::installFactory(UIAccessibilityInterfaceForUISnapshotItem::pFactory);783 784 508 /* No header: */ 785 509 header()->hide();
Note:
See TracChangeset
for help on using the changeset viewer.