VirtualBox

Changeset 64477 in vbox for trunk/src/VBox/Frontends


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

FE/Qt: bugref:6899: Accessibility support (step 106): Basic QITreeView accessibility interface.

File:
1 edited

Legend:

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

    r64473 r64477  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleWidget>
    2324# include <QMouseEvent>
    2425# include <QPainter>
     
    2728# include "QITreeView.h"
    2829
     30/* Other VBox includes: */
     31# include "iprt/assert.h"
     32
    2933#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     34
     35
     36/** QAccessibleWidget extension used as an accessibility interface for QITreeView. */
     37class QIAccessibilityInterfaceForQITreeView : public QAccessibleWidget
     38{
     39public:
     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 QITreeView accessibility interface: */
     45        if (pObject && strClassname == QLatin1String("QITreeView"))
     46            return new QIAccessibilityInterfaceForQITreeView(qobject_cast<QWidget*>(pObject));
     47
     48        /* Null by default: */
     49        return 0;
     50    }
     51
     52    /** Constructs an accessibility interface passing @a pWidget to the base-class. */
     53    QIAccessibilityInterfaceForQITreeView(QWidget *pWidget)
     54        : QAccessibleWidget(pWidget, QAccessible::List)
     55    {}
     56
     57    /** Returns the number of children. */
     58    virtual int childCount() const /* override */;
     59    /** Returns the child with the passed @a iIndex. */
     60    virtual QAccessibleInterface *child(int iIndex) const /* override */;
     61    /** Returns the index of the passed @a pChild. */
     62    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */;
     63
     64    /** Returns a text for the passed @a enmTextRole. */
     65    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     66
     67private:
     68
     69    /** Returns corresponding QITreeView. */
     70    QITreeView *tree() const { return qobject_cast<QITreeView*>(widget()); }
     71};
     72
     73
     74/*********************************************************************************************************************************
     75*   Class QIAccessibilityInterfaceForQITreeView implementation.                                                                  *
     76*********************************************************************************************************************************/
     77
     78int QIAccessibilityInterfaceForQITreeView::childCount() const
     79{
     80    /* Make sure tree still alive: */
     81    AssertPtrReturn(tree(), 0);
     82
     83    /* Return the number of children: */
     84    return tree()->childCount();
     85}
     86
     87QAccessibleInterface *QIAccessibilityInterfaceForQITreeView::child(int iIndex) const
     88{
     89    /* Make sure tree still alive: */
     90    AssertPtrReturn(tree(), 0);
     91    /* Make sure index is valid: */
     92    AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
     93
     94    /* Return the child with the passed iIndex: */
     95    return QAccessible::queryAccessibleInterface(tree()->childItem(iIndex));
     96}
     97
     98int QIAccessibilityInterfaceForQITreeView::indexOfChild(const QAccessibleInterface *pChild) const
     99{
     100    /* Search for corresponding child: */
     101    for (int i = 0; i < childCount(); ++i)
     102        if (child(i) == pChild)
     103            return i;
     104
     105    /* -1 by default: */
     106    return -1;
     107}
     108
     109QString QIAccessibilityInterfaceForQITreeView::text(QAccessible::Text /* enmTextRole */) const
     110{
     111    /* Make sure tree still alive: */
     112    AssertPtrReturn(tree(), QString());
     113
     114    /* Return tree whats-this: */
     115    return tree()->whatsThis();
     116}
    30117
    31118
     
    140227void QITreeView::prepare()
    141228{
     229    /* Install QITreeView accessibility interface factory: */
     230    QAccessible::installFactory(QIAccessibilityInterfaceForQITreeView::pFactory);
     231
    142232    /* Mark header hidden: */
    143233    setHeaderHidden(true);
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