Changeset 64129 in vbox
- Timestamp:
- Oct 3, 2016 3:51:07 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 111086
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITreeWidget.cpp
r64128 r64129 34 34 35 35 36 /** QAccessibleObject extension used as an accessibility interface for QITreeWidgetItem. */ 37 class QIAccessibilityInterfaceForQITreeWidgetItem : public QAccessibleObject 38 { 39 public: 40 41 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */ 42 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject) 43 { 44 /* Creating QITreeWidgetItem accessibility interface: */ 45 if (pObject && strClassname == QLatin1String("QITreeWidgetItem")) 46 return new QIAccessibilityInterfaceForQITreeWidgetItem(pObject); 47 48 /* Null by default: */ 49 return 0; 50 } 51 52 /** Constructs an accessibility interface passing @a pObject to the base-class. */ 53 QIAccessibilityInterfaceForQITreeWidgetItem(QObject *pObject) 54 : QAccessibleObject(pObject) 55 {} 56 57 /** Returns the parent. */ 58 virtual QAccessibleInterface *parent() const /* override */; 59 60 /** Returns the number of children. */ 61 virtual int childCount() const /* override */; 62 /** Returns the child with the passed @a iIndex. */ 63 virtual QAccessibleInterface *child(int iIndex) const /* override */; 64 /** Returns the index of the passed @a pChild. */ 65 virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */; 66 67 /** Returns the rect. */ 68 virtual QRect rect() const /* override */; 69 /** Returns a text for the passed @a enmTextRole. */ 70 virtual QString text(QAccessible::Text enmTextRole) const /* override */; 71 72 /** Returns the role. */ 73 virtual QAccessible::Role role() const /* override */; 74 /** Returns the state. */ 75 virtual QAccessible::State state() const /* override */; 76 77 private: 78 79 /** Returns corresponding QITreeWidgetItem. */ 80 QITreeWidgetItem *item() const { return qobject_cast<QITreeWidgetItem*>(object()); } 81 }; 82 83 36 84 /** QAccessibleWidget extension used as an accessibility interface for QITreeWidget. */ 37 85 class QIAccessibilityInterfaceForQITreeWidget : public QAccessibleWidget … … 68 116 QITreeWidget *tree() const { return qobject_cast<QITreeWidget*>(widget()); } 69 117 }; 118 119 120 /********************************************************************************************************************************* 121 * Class QIAccessibilityInterfaceForQITreeWidgetItem implementation. * 122 *********************************************************************************************************************************/ 123 124 QAccessibleInterface *QIAccessibilityInterfaceForQITreeWidgetItem::parent() const 125 { 126 /* Make sure item still alive: */ 127 AssertPtrReturn(item(), 0); 128 129 /* Return the parent: */ 130 return item()->parentItem() ? 131 QAccessible::queryAccessibleInterface(item()->parentItem()) : 132 QAccessible::queryAccessibleInterface(item()->parentTree()); 133 } 134 135 int QIAccessibilityInterfaceForQITreeWidgetItem::childCount() const 136 { 137 /* Make sure item still alive: */ 138 AssertPtrReturn(item(), 0); 139 140 /* Return the number of children: */ 141 return item()->childCount(); 142 } 143 144 QAccessibleInterface *QIAccessibilityInterfaceForQITreeWidgetItem::child(int iIndex) const 145 { 146 /* Make sure item still alive: */ 147 AssertPtrReturn(item(), 0); 148 /* Make sure index is valid: */ 149 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0); 150 151 /* Return the child with the passed iIndex: */ 152 return QAccessible::queryAccessibleInterface(item()->childItem(iIndex)); 153 } 154 155 int QIAccessibilityInterfaceForQITreeWidgetItem::indexOfChild(const QAccessibleInterface *pChild) const 156 { 157 /* Search for corresponding child: */ 158 for (int i = 0; i < childCount(); ++i) 159 if (child(i) == pChild) 160 return i; 161 162 /* -1 by default: */ 163 return -1; 164 } 165 166 QRect QIAccessibilityInterfaceForQITreeWidgetItem::rect() const 167 { 168 /* Make sure item still alive: */ 169 AssertPtrReturn(item(), QRect()); 170 171 /* Compose common region: */ 172 QRegion region; 173 174 /* Append item rectangle: */ 175 const QRect itemRectInViewport = item()->parentTree()->visualItemRect(item()); 176 const QSize itemSize = itemRectInViewport.size(); 177 const QPoint itemPosInViewport = itemRectInViewport.topLeft(); 178 const QPoint itemPosInScreen = item()->parentTree()->viewport()->mapToGlobal(itemPosInViewport); 179 const QRect itemRectInScreen = QRect(itemPosInScreen, itemSize); 180 region += itemRectInScreen; 181 182 /* Append children rectangles: */ 183 for (int i = 0; i < childCount(); ++i) 184 region += child(i)->rect(); 185 186 /* Return common region bounding rectangle: */ 187 return region.boundingRect(); 188 } 189 190 QString QIAccessibilityInterfaceForQITreeWidgetItem::text(QAccessible::Text enmTextRole) const 191 { 192 /* Make sure item still alive: */ 193 AssertPtrReturn(item(), QString()); 194 195 /* Return a text for the passed enmTextRole: */ 196 switch (enmTextRole) 197 { 198 case QAccessible::Name: return item()->text(0); 199 default: break; 200 } 201 202 /* Null-string by default: */ 203 return QString(); 204 } 205 206 QAccessible::Role QIAccessibilityInterfaceForQITreeWidgetItem::role() const 207 { 208 /* Return the role of item with children: */ 209 if (childCount() > 0) 210 return QAccessible::List; 211 212 /* TreeItem by default: */ 213 return QAccessible::ListItem; 214 } 215 216 QAccessible::State QIAccessibilityInterfaceForQITreeWidgetItem::state() const 217 { 218 /* Make sure item still alive: */ 219 AssertPtrReturn(item(), QAccessible::State()); 220 221 /* Compose the state: */ 222 QAccessible::State state; 223 state.focusable = true; 224 state.selectable = true; 225 226 /* Compose the state of current item: */ 227 if ( item() 228 && item() == QITreeWidgetItem::toItem(item()->treeWidget()->currentItem())) 229 { 230 state.active = true; 231 state.focused = true; 232 state.selected = true; 233 } 234 235 /* Return the state: */ 236 return state; 237 } 70 238 71 239 … … 207 375 /* Install QITreeWidget accessibility interface factory: */ 208 376 QAccessible::installFactory(QIAccessibilityInterfaceForQITreeWidget::pFactory); 377 /* Install QITreeWidgetItem accessibility interface factory: */ 378 QAccessible::installFactory(QIAccessibilityInterfaceForQITreeWidgetItem::pFactory); 209 379 210 380 // WORKAROUND:
Note:
See TracChangeset
for help on using the changeset viewer.