VirtualBox

Changeset 64478 in vbox


Ignore:
Timestamp:
Oct 28, 2016 3:59:13 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 107): Basic QITreeViewItem accessibility interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITreeView.cpp

    r64477 r64478  
    3434
    3535
    36 /** QAccessibleWidget extension used as an accessibility interface for QITreeView. */
    37 class QIAccessibilityInterfaceForQITreeView : public QAccessibleWidget
     36/** QAccessibleObject extension used as an accessibility interface for QITreeViewItem. */
     37class QIAccessibilityInterfaceForQITreeViewItem : public QAccessibleObject
    3838{
    3939public:
     
    4242    static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
    4343    {
    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);
    4747
    4848        /* Null by default: */
     
    5050    }
    5151
    52     /** Constructs an accessibility interface passing @a pWidget to the base-class. */
    53     QIAccessibilityInterfaceForQITreeView(QWidget *pWidget)
    54         : QAccessibleWidget(pWidget, QAccessible::List)
     52    /** Constructs an accessibility interface passing @a pObject to the base-class. */
     53    QIAccessibilityInterfaceForQITreeViewItem(QObject *pObject)
     54        : QAccessibleObject(pObject)
    5555    {}
     56
     57    /** Returns the parent. */
     58    virtual QAccessibleInterface *parent() const /* override */;
    5659
    5760    /** Returns the number of children. */
     
    6265    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */;
    6366
     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
     77private:
     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. */
     85class QIAccessibilityInterfaceForQITreeView : public QAccessibleWidget
     86{
     87public:
     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
    64112    /** Returns a text for the passed @a enmTextRole. */
    65113    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     
    70118    QITreeView *tree() const { return qobject_cast<QITreeView*>(widget()); }
    71119};
     120
     121
     122/*********************************************************************************************************************************
     123*   Class QIAccessibilityInterfaceForQITreeViewItem implementation.                                                              *
     124*********************************************************************************************************************************/
     125
     126QAccessibleInterface *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
     137int 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
     146QAccessibleInterface *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
     157int 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
     168QRect 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
     186QString 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
     202QAccessible::Role QIAccessibilityInterfaceForQITreeViewItem::role() const
     203{
     204    /* List if there are children, ListItem by default: */
     205    return childCount() ? QAccessible::List : QAccessible::ListItem;
     206}
     207
     208QAccessible::State QIAccessibilityInterfaceForQITreeViewItem::state() const
     209{
     210    /* Empty state by default: */
     211    return QAccessible::State();
     212}
    72213
    73214
     
    227368void QITreeView::prepare()
    228369{
     370    /* Install QITreeViewItem accessibility interface factory: */
     371    QAccessible::installFactory(QIAccessibilityInterfaceForQITreeViewItem::pFactory);
    229372    /* Install QITreeView accessibility interface factory: */
    230373    QAccessible::installFactory(QIAccessibilityInterfaceForQITreeView::pFactory);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette