Changeset 63897 in vbox
- Timestamp:
- Sep 19, 2016 4:29:42 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r63896 r63897 55 55 56 56 57 /** QAccessibleObject extension used as an accessibility interface for Snapshot item. */ 58 class UIAccessibilityInterfaceForUISnapshotItem : public QAccessibleObject 59 { 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 57 105 /** QAccessibleWidget extension used as an accessibility interface for Snapshot tree. */ 58 106 class UIAccessibilityInterfaceForUISnapshotTree : public QAccessibleWidget … … 212 260 UISnapshotItem *childSnapshotItem(int iIndex) const; 213 261 }; 262 263 264 /********************************************************************************************************************************* 265 * Class UIAccessibilityInterfaceForUISnapshotItem implementation. * 266 *********************************************************************************************************************************/ 267 268 QAccessibleInterface *UIAccessibilityInterfaceForUISnapshotItem::parent() const 269 { 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() const 280 { 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) const 289 { 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) const 300 { 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() const 311 { 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) const 335 { 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() const 351 { 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() const 361 { 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 } 214 382 215 383 … … 585 753 /* Install Snapshot tree accessibility interface factory: */ 586 754 QAccessible::installFactory(UIAccessibilityInterfaceForUISnapshotTree::pFactory); 755 /* Install Snapshot item accessibility interface factory: */ 756 QAccessible::installFactory(UIAccessibilityInterfaceForUISnapshotItem::pFactory); 587 757 588 758 /* No header: */
Note:
See TracChangeset
for help on using the changeset viewer.