VirtualBox

Changeset 64522 in vbox for trunk


Ignore:
Timestamp:
Nov 2, 2016 3:54:12 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 124): Basic QIComboBox accessibility interface.

File:
1 edited

Legend:

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

    r64521 r64522  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleWidget>
    2324# include <QHBoxLayout>
    2425# include <QLineEdit>
     
    3233#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3334
     35
     36/** QAccessibleWidget extension used as an accessibility interface for QIComboBox. */
     37class QIAccessibilityInterfaceForQIComboBox : 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 QIComboBox accessibility interface: */
     45        if (pObject && strClassname == QLatin1String("QIComboBox"))
     46            return new QIAccessibilityInterfaceForQIComboBox(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    QIAccessibilityInterfaceForQIComboBox(QWidget *pWidget)
     54        : QAccessibleWidget(pWidget, QAccessible::ToolBar)
     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 QIComboBox. */
     70    QIComboBox *combo() const { return qobject_cast<QIComboBox*>(widget()); }
     71};
     72
     73
     74/*********************************************************************************************************************************
     75*   Class QIAccessibilityInterfaceForQIComboBox implementation.                                                                  *
     76*********************************************************************************************************************************/
     77
     78int QIAccessibilityInterfaceForQIComboBox::childCount() const
     79{
     80    /* Make sure combo still alive: */
     81    AssertPtrReturn(combo(), 0);
     82
     83    /* Return the number of children: */
     84    return combo()->subElementCount();
     85}
     86
     87QAccessibleInterface *QIAccessibilityInterfaceForQIComboBox::child(int iIndex) const
     88{
     89    /* Make sure combo still alive: */
     90    AssertPtrReturn(combo(), 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(combo()->subElement(iIndex));
     96}
     97
     98int QIAccessibilityInterfaceForQIComboBox::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 QIAccessibilityInterfaceForQIComboBox::text(QAccessible::Text /* enmTextRole */) const
     110{
     111    /* Return empty string: */
     112    return QString();
     113}
     114
     115
     116/*********************************************************************************************************************************
     117*   Class QIComboBox implementation.                                                                                             *
     118*********************************************************************************************************************************/
    34119
    35120QIComboBox::QIComboBox(QWidget *pParent /* = 0 */)
     
    204289void QIComboBox::prepare()
    205290{
     291    /* Install QIComboBox accessibility interface factory: */
     292    QAccessible::installFactory(QIAccessibilityInterfaceForQIComboBox::pFactory);
     293
    206294    /* Create layout: */
    207295    QHBoxLayout *pLayout = new QHBoxLayout(this);
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