VirtualBox

Changeset 64229 in vbox


Ignore:
Timestamp:
Oct 12, 2016 5:56:18 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 82): Basic QITableView accessibility interface.

File:
1 edited

Legend:

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

    r64178 r64229  
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
     22/* Qt includes: */
     23# include <QAccessibleWidget>
     24
    2225/* GUI includes: */
    2326# include "QITableView.h"
     
    2932#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3033
     34
     35/** QAccessibleWidget extension used as an accessibility interface for QITableView. */
     36class QIAccessibilityInterfaceForQITableView : public QAccessibleWidget
     37{
     38public:
     39
     40    /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
     41    static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
     42    {
     43        /* Creating QITableView accessibility interface: */
     44        if (pObject && strClassname == QLatin1String("QITableView"))
     45            return new QIAccessibilityInterfaceForQITableView(qobject_cast<QWidget*>(pObject));
     46
     47        /* Null by default: */
     48        return 0;
     49    }
     50
     51    /** Constructs an accessibility interface passing @a pWidget to the base-class. */
     52    QIAccessibilityInterfaceForQITableView(QWidget *pWidget)
     53        : QAccessibleWidget(pWidget, QAccessible::List)
     54    {}
     55
     56    /** Returns the number of children. */
     57    virtual int childCount() const /* override */;
     58    /** Returns the child with the passed @a iIndex. */
     59    virtual QAccessibleInterface *child(int iIndex) const /* override */;
     60    /** Returns the index of the passed @a pChild. */
     61    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */;
     62
     63    /** Returns a text for the passed @a enmTextRole. */
     64    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     65
     66private:
     67
     68    /** Returns corresponding QITableView. */
     69    QITableView *table() const { return qobject_cast<QITableView*>(widget()); }
     70};
     71
     72
     73/*********************************************************************************************************************************
     74*   Class QIAccessibilityInterfaceForQITableView implementation.                                                                 *
     75*********************************************************************************************************************************/
     76
     77int QIAccessibilityInterfaceForQITableView::childCount() const
     78{
     79    /* Make sure table still alive: */
     80    AssertPtrReturn(table(), 0);
     81
     82    /* Return the number of children: */
     83    return table()->childCount();
     84}
     85
     86QAccessibleInterface *QIAccessibilityInterfaceForQITableView::child(int iIndex) const
     87{
     88    /* Make sure table still alive: */
     89    AssertPtrReturn(table(), 0);
     90    /* Make sure index is valid: */
     91    AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
     92
     93    /* Return the child with the passed iIndex: */
     94    return QAccessible::queryAccessibleInterface(table()->childItem(iIndex));
     95}
     96
     97int QIAccessibilityInterfaceForQITableView::indexOfChild(const QAccessibleInterface *pChild) const
     98{
     99    /* Search for corresponding child: */
     100    for (int i = 0; i < childCount(); ++i)
     101        if (child(i) == pChild)
     102            return i;
     103
     104    /* -1 by default: */
     105    return -1;
     106}
     107
     108QString QIAccessibilityInterfaceForQITableView::text(QAccessible::Text /* enmTextRole */) const
     109{
     110    /* Make sure table still alive: */
     111    AssertPtrReturn(table(), QString());
     112
     113    /* Return tree whats-this: */
     114    return table()->whatsThis();
     115}
     116
     117
     118/*********************************************************************************************************************************
     119*   Class QITableView implementation.                                                                                            *
     120*********************************************************************************************************************************/
    31121
    32122QITableView::QITableView(QWidget *pParent)
     
    79169void QITableView::prepare()
    80170{
     171    /* Install QITableView accessibility interface factory: */
     172    QAccessible::installFactory(QIAccessibilityInterfaceForQITableView::pFactory);
     173
    81174    /* Delete old delegate: */
    82175    delete itemDelegate();
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