VirtualBox

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


Ignore:
Timestamp:
Oct 3, 2016 3:48:38 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
111085
Message:

FE/Qt: bugref:6899: Accessibility support (step 69): Basic QITreeWidget accessibility interface.

File:
1 edited

Legend:

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

    r64126 r64128  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleWidget>
    2324# include <QPainter>
    2425# include <QResizeEvent>
     
    2728# include "QITreeWidget.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 QITreeWidget. */
     37class QIAccessibilityInterfaceForQITreeWidget : 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 QITreeWidget accessibility interface: */
     45        if (pObject && strClassname == QLatin1String("QITreeWidget"))
     46            return new QIAccessibilityInterfaceForQITreeWidget(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    QIAccessibilityInterfaceForQITreeWidget(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
     62    /** Returns a text for the passed @a enmTextRole. */
     63    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     64
     65private:
     66
     67    /** Returns corresponding QITreeWidget. */
     68    QITreeWidget *tree() const { return qobject_cast<QITreeWidget*>(widget()); }
     69};
     70
     71
     72/*********************************************************************************************************************************
     73*   Class QIAccessibilityInterfaceForQITreeWidget implementation.                                                                *
     74*********************************************************************************************************************************/
     75
     76int QIAccessibilityInterfaceForQITreeWidget::childCount() const
     77{
     78    /* Make sure tree still alive: */
     79    AssertPtrReturn(tree(), 0);
     80
     81    /* Return the number of children: */
     82    return tree()->childCount();
     83}
     84
     85QAccessibleInterface *QIAccessibilityInterfaceForQITreeWidget::child(int iIndex) const
     86{
     87    /* Make sure tree still alive: */
     88    AssertPtrReturn(tree(), 0);
     89    /* Make sure index is valid: */
     90    AssertReturn(iIndex >= 0, 0);
     91    if (iIndex >= childCount())
     92    {
     93        // WORKAROUND:
     94        // Normally I would assert here, but Qt5 accessibility code has
     95        // a hard-coded architecture for a tree-views which we do not like
     96        // but have to live with and this architecture enumerates children
     97        // of all levels as children of level 0, so Qt5 can try to address
     98        // our interface with index which surely out of bounds by our laws.
     99        // So let's assume that's exactly such case and try to enumerate
     100        // visible children like they are a part of the list, not tree.
     101        // printf("Invalid index: %d\n", iIndex);
     102
     103        // Do some sanity check as well, enough?
     104        AssertReturn(iIndex >= tree()->columnCount(), 0);
     105
     106        // The enumeration step is column count:
     107        int iCurrentIndex = tree()->columnCount();
     108        QTreeWidgetItem *pItem = tree()->topLevelItem(0);
     109        while (pItem && iCurrentIndex < iIndex)
     110        {
     111            iCurrentIndex += tree()->columnCount();
     112            pItem = tree()->itemBelow(pItem);
     113        }
     114
     115        // Return what we found:
     116        // if (pItem)
     117        //     printf("Item found: [%s]\n", pItem->text(0).toUtf8().constData());
     118        return pItem ? QAccessible::queryAccessibleInterface(QITreeWidgetItem::toItem(pItem)) : 0;
     119    }
     120
     121    /* Return the child with the passed iIndex: */
     122    return QAccessible::queryAccessibleInterface(tree()->childItem(iIndex));
     123}
     124
     125QString QIAccessibilityInterfaceForQITreeWidget::text(QAccessible::Text /* enmTextRole */) const
     126{
     127    /* Make sure tree still alive: */
     128    AssertPtrReturn(tree(), QString());
     129
     130    /* Return tree whats-this: */
     131    return tree()->whatsThis();
     132}
    30133
    31134
     
    102205    : QTreeWidget(pParent)
    103206{
     207    /* Install QITreeWidget accessibility interface factory: */
     208    QAccessible::installFactory(QIAccessibilityInterfaceForQITreeWidget::pFactory);
     209
     210    // WORKAROUND:
     211    // Ok, what do we have here..
     212    // There is a bug in QAccessible framework which might be just treated like
     213    // a functionality flaw. It consist in fact that if an accessibility client
     214    // is enabled, base-class can request an accessibility interface in own
     215    // constructor before the sub-class registers own factory, so we have to
     216    // recreate interface after we finished with our own initialization.
     217    QAccessibleInterface *pInterface = QAccessible::queryAccessibleInterface(this);
     218    if (pInterface)
     219    {
     220        QAccessible::deleteAccessibleInterface(QAccessible::uniqueId(pInterface));
     221        QAccessible::queryAccessibleInterface(this); // <= new one, proper..
     222    }
    104223}
    105224
Note: See TracChangeset for help on using the changeset viewer.

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