Changeset 64478 in vbox
- Timestamp:
- Oct 28, 2016 3:59:13 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITreeView.cpp
r64477 r64478 34 34 35 35 36 /** QAccessible Widget extension used as an accessibility interface for QITreeView. */37 class QIAccessibilityInterfaceForQITreeView : public QAccessibleWidget36 /** QAccessibleObject extension used as an accessibility interface for QITreeViewItem. */ 37 class QIAccessibilityInterfaceForQITreeViewItem : public QAccessibleObject 38 38 { 39 39 public: … … 42 42 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject) 43 43 { 44 /* Creating QITreeView accessibility interface: */45 if (pObject && strClassname == QLatin1String("QITreeView "))46 return new QIAccessibilityInterfaceForQITreeView (qobject_cast<QWidget*>(pObject));44 /* Creating QITreeViewItem accessibility interface: */ 45 if (pObject && strClassname == QLatin1String("QITreeViewItem")) 46 return new QIAccessibilityInterfaceForQITreeViewItem(pObject); 47 47 48 48 /* Null by default: */ … … 50 50 } 51 51 52 /** Constructs an accessibility interface passing @a p Widget to the base-class. */53 QIAccessibilityInterfaceForQITreeView (QWidget *pWidget)54 : QAccessible Widget(pWidget, QAccessible::List)52 /** Constructs an accessibility interface passing @a pObject to the base-class. */ 53 QIAccessibilityInterfaceForQITreeViewItem(QObject *pObject) 54 : QAccessibleObject(pObject) 55 55 {} 56 57 /** Returns the parent. */ 58 virtual QAccessibleInterface *parent() const /* override */; 56 59 57 60 /** Returns the number of children. */ … … 62 65 virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */; 63 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 QITreeViewItem. */ 80 QITreeViewItem *item() const { return qobject_cast<QITreeViewItem*>(object()); } 81 }; 82 83 84 /** QAccessibleWidget extension used as an accessibility interface for QITreeView. */ 85 class QIAccessibilityInterfaceForQITreeView : public QAccessibleWidget 86 { 87 public: 88 89 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */ 90 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject) 91 { 92 /* Creating QITreeView accessibility interface: */ 93 if (pObject && strClassname == QLatin1String("QITreeView")) 94 return new QIAccessibilityInterfaceForQITreeView(qobject_cast<QWidget*>(pObject)); 95 96 /* Null by default: */ 97 return 0; 98 } 99 100 /** Constructs an accessibility interface passing @a pWidget to the base-class. */ 101 QIAccessibilityInterfaceForQITreeView(QWidget *pWidget) 102 : QAccessibleWidget(pWidget, QAccessible::List) 103 {} 104 105 /** Returns the number of children. */ 106 virtual int childCount() const /* override */; 107 /** Returns the child with the passed @a iIndex. */ 108 virtual QAccessibleInterface *child(int iIndex) const /* override */; 109 /** Returns the index of the passed @a pChild. */ 110 virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */; 111 64 112 /** Returns a text for the passed @a enmTextRole. */ 65 113 virtual QString text(QAccessible::Text enmTextRole) const /* override */; … … 70 118 QITreeView *tree() const { return qobject_cast<QITreeView*>(widget()); } 71 119 }; 120 121 122 /********************************************************************************************************************************* 123 * Class QIAccessibilityInterfaceForQITreeViewItem implementation. * 124 *********************************************************************************************************************************/ 125 126 QAccessibleInterface *QIAccessibilityInterfaceForQITreeViewItem::parent() const 127 { 128 /* Make sure item still alive: */ 129 AssertPtrReturn(item(), 0); 130 131 /* Return the parent: */ 132 return item()->parentItem() ? 133 QAccessible::queryAccessibleInterface(item()->parentItem()) : 134 QAccessible::queryAccessibleInterface(item()->parentTree()); 135 } 136 137 int QIAccessibilityInterfaceForQITreeViewItem::childCount() const 138 { 139 /* Make sure item still alive: */ 140 AssertPtrReturn(item(), 0); 141 142 /* Return the number of children: */ 143 return item()->childCount(); 144 } 145 146 QAccessibleInterface *QIAccessibilityInterfaceForQITreeViewItem::child(int iIndex) const /* override */ 147 { 148 /* Make sure item still alive: */ 149 AssertPtrReturn(item(), 0); 150 /* Make sure index is valid: */ 151 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0); 152 153 /* Return the child with the passed iIndex: */ 154 return QAccessible::queryAccessibleInterface(item()->childItem(iIndex)); 155 } 156 157 int QIAccessibilityInterfaceForQITreeViewItem::indexOfChild(const QAccessibleInterface *pChild) const /* override */ 158 { 159 /* Search for corresponding child: */ 160 for (int i = 0; i < childCount(); ++i) 161 if (child(i) == pChild) 162 return i; 163 164 /* -1 by default: */ 165 return -1; 166 } 167 168 QRect QIAccessibilityInterfaceForQITreeViewItem::rect() const 169 { 170 /* Make sure item still alive: */ 171 AssertPtrReturn(item(), QRect()); 172 AssertPtrReturn(item()->parentTree(), QRect()); 173 AssertPtrReturn(item()->parentTree()->viewport(), QRect()); 174 175 /* Get the local rect: */ 176 const QRect itemRectInViewport = item()->rect(); 177 const QSize itemSize = itemRectInViewport.size(); 178 const QPoint itemPosInViewport = itemRectInViewport.topLeft(); 179 const QPoint itemPosInScreen = item()->parentTree()->viewport()->mapToGlobal(itemPosInViewport); 180 const QRect itemRectInScreen = QRect(itemPosInScreen, itemSize); 181 182 /* Return the rect: */ 183 return itemRectInScreen; 184 } 185 186 QString QIAccessibilityInterfaceForQITreeViewItem::text(QAccessible::Text enmTextRole) const 187 { 188 /* Make sure row still alive: */ 189 AssertPtrReturn(item(), QString()); 190 191 /* Return a text for the passed enmTextRole: */ 192 switch (enmTextRole) 193 { 194 case QAccessible::Name: return item()->text(); 195 default: break; 196 } 197 198 /* Null-string by default: */ 199 return QString(); 200 } 201 202 QAccessible::Role QIAccessibilityInterfaceForQITreeViewItem::role() const 203 { 204 /* List if there are children, ListItem by default: */ 205 return childCount() ? QAccessible::List : QAccessible::ListItem; 206 } 207 208 QAccessible::State QIAccessibilityInterfaceForQITreeViewItem::state() const 209 { 210 /* Empty state by default: */ 211 return QAccessible::State(); 212 } 72 213 73 214 … … 227 368 void QITreeView::prepare() 228 369 { 370 /* Install QITreeViewItem accessibility interface factory: */ 371 QAccessible::installFactory(QIAccessibilityInterfaceForQITreeViewItem::pFactory); 229 372 /* Install QITreeView accessibility interface factory: */ 230 373 QAccessible::installFactory(QIAccessibilityInterfaceForQITreeView::pFactory);
Note:
See TracChangeset
for help on using the changeset viewer.