Changeset 64230 in vbox
- Timestamp:
- Oct 12, 2016 5:59:53 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.cpp
r64229 r64230 33 33 34 34 35 /** QAccessible Widget extension used as an accessibility interface for QITableView. */36 class QIAccessibilityInterfaceForQITableView : public QAccessibleWidget35 /** QAccessibleObject extension used as an accessibility interface for QITableViewRow. */ 36 class QIAccessibilityInterfaceForQITableViewRow : public QAccessibleObject 37 37 { 38 38 public: … … 41 41 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject) 42 42 { 43 /* Creating QITableView accessibility interface: */44 if (pObject && strClassname == QLatin1String("QITableView "))45 return new QIAccessibilityInterfaceForQITableView (qobject_cast<QWidget*>(pObject));43 /* Creating QITableViewRow accessibility interface: */ 44 if (pObject && strClassname == QLatin1String("QITableViewRow")) 45 return new QIAccessibilityInterfaceForQITableViewRow(pObject); 46 46 47 47 /* Null by default: */ … … 49 49 } 50 50 51 /** Constructs an accessibility interface passing @a p Widget to the base-class. */52 QIAccessibilityInterfaceForQITableView (QWidget *pWidget)53 : QAccessible Widget(pWidget, QAccessible::List)51 /** Constructs an accessibility interface passing @a pObject to the base-class. */ 52 QIAccessibilityInterfaceForQITableViewRow(QObject *pObject) 53 : QAccessibleObject(pObject) 54 54 {} 55 56 /** Returns the parent. */ 57 virtual QAccessibleInterface *parent() const /* override */; 55 58 56 59 /** Returns the number of children. */ … … 61 64 virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */; 62 65 66 /** Returns the rect. */ 67 virtual QRect rect() const /* override */; 68 /** Returns a text for the passed @a enmTextRole. */ 69 virtual QString text(QAccessible::Text enmTextRole) const /* override */; 70 71 /** Returns the role. */ 72 virtual QAccessible::Role role() const /* override */; 73 /** Returns the state. */ 74 virtual QAccessible::State state() const /* override */; 75 76 private: 77 78 /** Returns corresponding QITableViewRow. */ 79 QITableViewRow *row() const { return qobject_cast<QITableViewRow*>(object()); } 80 }; 81 82 83 /** QAccessibleWidget extension used as an accessibility interface for QITableView. */ 84 class QIAccessibilityInterfaceForQITableView : public QAccessibleWidget 85 { 86 public: 87 88 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */ 89 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject) 90 { 91 /* Creating QITableView accessibility interface: */ 92 if (pObject && strClassname == QLatin1String("QITableView")) 93 return new QIAccessibilityInterfaceForQITableView(qobject_cast<QWidget*>(pObject)); 94 95 /* Null by default: */ 96 return 0; 97 } 98 99 /** Constructs an accessibility interface passing @a pWidget to the base-class. */ 100 QIAccessibilityInterfaceForQITableView(QWidget *pWidget) 101 : QAccessibleWidget(pWidget, QAccessible::List) 102 {} 103 104 /** Returns the number of children. */ 105 virtual int childCount() const /* override */; 106 /** Returns the child with the passed @a iIndex. */ 107 virtual QAccessibleInterface *child(int iIndex) const /* override */; 108 /** Returns the index of the passed @a pChild. */ 109 virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */; 110 63 111 /** Returns a text for the passed @a enmTextRole. */ 64 112 virtual QString text(QAccessible::Text enmTextRole) const /* override */; … … 69 117 QITableView *table() const { return qobject_cast<QITableView*>(widget()); } 70 118 }; 119 120 121 /********************************************************************************************************************************* 122 * Class QIAccessibilityInterfaceForQITableViewRow implementation. * 123 *********************************************************************************************************************************/ 124 125 QAccessibleInterface *QIAccessibilityInterfaceForQITableViewRow::parent() const 126 { 127 /* Make sure row still alive: */ 128 AssertPtrReturn(row(), 0); 129 130 /* Return the parent: */ 131 return QAccessible::queryAccessibleInterface(row()->table()); 132 } 133 134 int QIAccessibilityInterfaceForQITableViewRow::childCount() const 135 { 136 /* Make sure row still alive: */ 137 AssertPtrReturn(row(), 0); 138 139 /* Return the number of children: */ 140 return row()->childCount(); 141 } 142 143 QAccessibleInterface *QIAccessibilityInterfaceForQITableViewRow::child(int iIndex) const /* override */ 144 { 145 /* Make sure row still alive: */ 146 AssertPtrReturn(row(), 0); 147 /* Make sure index is valid: */ 148 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0); 149 150 /* Return the child with the passed iIndex: */ 151 return QAccessible::queryAccessibleInterface(row()->childItem(iIndex)); 152 } 153 154 int QIAccessibilityInterfaceForQITableViewRow::indexOfChild(const QAccessibleInterface *pChild) const /* override */ 155 { 156 /* Search for corresponding child: */ 157 for (int i = 0; i < childCount(); ++i) 158 if (child(i) == pChild) 159 return i; 160 161 /* -1 by default: */ 162 return -1; 163 } 164 165 QRect QIAccessibilityInterfaceForQITableViewRow::rect() const 166 { 167 /* Make sure row still alive: */ 168 AssertPtrReturn(row(), QRect()); 169 AssertPtrReturn(row()->table(), QRect()); 170 171 /* Calculate local item coordinates: */ 172 const int iIndexInParent = parent()->indexOfChild(this); 173 const int iX = row()->table()->columnViewportPosition(0); 174 const int iY = row()->table()->rowViewportPosition(iIndexInParent); 175 int iWidth = 0; 176 int iHeight = 0; 177 for (int i = 0; i < childCount(); ++i) 178 iWidth += row()->table()->columnWidth(i); 179 iHeight += row()->table()->rowHeight(iIndexInParent); 180 181 /* Map local item coordinates to global: */ 182 const QPoint itemPosInScreen = row()->table()->viewport()->mapToGlobal(QPoint(iX, iY)); 183 184 /* Return item rectangle: */ 185 return QRect(itemPosInScreen, QSize(iWidth, iHeight)); 186 } 187 188 QString QIAccessibilityInterfaceForQITableViewRow::text(QAccessible::Text enmTextRole) const 189 { 190 /* Make sure row still alive: */ 191 AssertPtrReturn(row(), QString()); 192 193 /* Return a text for the passed enmTextRole: */ 194 switch (enmTextRole) 195 { 196 case QAccessible::Name: return childCount() > 0 && child(0) ? child(0)->text(enmTextRole) : QString(); 197 default: break; 198 } 199 200 /* Null-string by default: */ 201 return QString(); 202 } 203 204 QAccessible::Role QIAccessibilityInterfaceForQITableViewRow::role() const 205 { 206 /* Row by default: */ 207 return QAccessible::Row; 208 } 209 210 QAccessible::State QIAccessibilityInterfaceForQITableViewRow::state() const 211 { 212 /* Make sure row still alive: */ 213 AssertPtrReturn(row(), QAccessible::State()); 214 215 /* Empty state by default: */ 216 return QAccessible::State(); 217 } 71 218 72 219 … … 169 316 void QITableView::prepare() 170 317 { 318 /* Install QITableViewRow accessibility interface factory: */ 319 QAccessible::installFactory(QIAccessibilityInterfaceForQITableViewRow::pFactory); 171 320 /* Install QITableView accessibility interface factory: */ 172 321 QAccessible::installFactory(QIAccessibilityInterfaceForQITableView::pFactory);
Note:
See TracChangeset
for help on using the changeset viewer.

