VirtualBox

Changeset 64230 in vbox


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

FE/Qt: bugref:6899: Accessibility support (step 83): Basic QITableViewRow accessibility interface.

File:
1 edited

Legend:

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

    r64229 r64230  
    3333
    3434
    35 /** QAccessibleWidget extension used as an accessibility interface for QITableView. */
    36 class QIAccessibilityInterfaceForQITableView : public QAccessibleWidget
     35/** QAccessibleObject extension used as an accessibility interface for QITableViewRow. */
     36class QIAccessibilityInterfaceForQITableViewRow : public QAccessibleObject
    3737{
    3838public:
     
    4141    static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
    4242    {
    43         /* Creating QITableView accessibility interface: */
    44         if (pObject && strClassname == QLatin1String("QITableView"))
    45             return new QIAccessibilityInterfaceForQITableView(qobject_cast<QWidget*>(pObject));
     43        /* Creating QITableViewRow accessibility interface: */
     44        if (pObject && strClassname == QLatin1String("QITableViewRow"))
     45            return new QIAccessibilityInterfaceForQITableViewRow(pObject);
    4646
    4747        /* Null by default: */
     
    4949    }
    5050
    51     /** Constructs an accessibility interface passing @a pWidget to the base-class. */
    52     QIAccessibilityInterfaceForQITableView(QWidget *pWidget)
    53         : QAccessibleWidget(pWidget, QAccessible::List)
     51    /** Constructs an accessibility interface passing @a pObject to the base-class. */
     52    QIAccessibilityInterfaceForQITableViewRow(QObject *pObject)
     53        : QAccessibleObject(pObject)
    5454    {}
     55
     56    /** Returns the parent. */
     57    virtual QAccessibleInterface *parent() const /* override */;
    5558
    5659    /** Returns the number of children. */
     
    6164    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */;
    6265
     66    /** Returns the rect. */
     67    virtual QRect rect() const /* override */;
     68    /** Returns a text for the passed @a enmTextRole. */
     69    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     70
     71    /** Returns the role. */
     72    virtual QAccessible::Role role() const /* override */;
     73    /** Returns the state. */
     74    virtual QAccessible::State state() const /* override */;
     75
     76private:
     77
     78    /** Returns corresponding QITableViewRow. */
     79    QITableViewRow *row() const { return qobject_cast<QITableViewRow*>(object()); }
     80};
     81
     82
     83/** QAccessibleWidget extension used as an accessibility interface for QITableView. */
     84class QIAccessibilityInterfaceForQITableView : public QAccessibleWidget
     85{
     86public:
     87
     88    /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
     89    static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
     90    {
     91        /* Creating QITableView accessibility interface: */
     92        if (pObject && strClassname == QLatin1String("QITableView"))
     93            return new QIAccessibilityInterfaceForQITableView(qobject_cast<QWidget*>(pObject));
     94
     95        /* Null by default: */
     96        return 0;
     97    }
     98
     99    /** Constructs an accessibility interface passing @a pWidget to the base-class. */
     100    QIAccessibilityInterfaceForQITableView(QWidget *pWidget)
     101        : QAccessibleWidget(pWidget, QAccessible::List)
     102    {}
     103
     104    /** Returns the number of children. */
     105    virtual int childCount() const /* override */;
     106    /** Returns the child with the passed @a iIndex. */
     107    virtual QAccessibleInterface *child(int iIndex) const /* override */;
     108    /** Returns the index of the passed @a pChild. */
     109    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */;
     110
    63111    /** Returns a text for the passed @a enmTextRole. */
    64112    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     
    69117    QITableView *table() const { return qobject_cast<QITableView*>(widget()); }
    70118};
     119
     120
     121/*********************************************************************************************************************************
     122*   Class QIAccessibilityInterfaceForQITableViewRow implementation.                                                              *
     123*********************************************************************************************************************************/
     124
     125QAccessibleInterface *QIAccessibilityInterfaceForQITableViewRow::parent() const
     126{
     127    /* Make sure row still alive: */
     128    AssertPtrReturn(row(), 0);
     129
     130    /* Return the parent: */
     131    return QAccessible::queryAccessibleInterface(row()->table());
     132}
     133
     134int QIAccessibilityInterfaceForQITableViewRow::childCount() const
     135{
     136    /* Make sure row still alive: */
     137    AssertPtrReturn(row(), 0);
     138
     139    /* Return the number of children: */
     140    return row()->childCount();
     141}
     142
     143QAccessibleInterface *QIAccessibilityInterfaceForQITableViewRow::child(int iIndex) const /* override */
     144{
     145    /* Make sure row still alive: */
     146    AssertPtrReturn(row(), 0);
     147    /* Make sure index is valid: */
     148    AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
     149
     150    /* Return the child with the passed iIndex: */
     151    return QAccessible::queryAccessibleInterface(row()->childItem(iIndex));
     152}
     153
     154int QIAccessibilityInterfaceForQITableViewRow::indexOfChild(const QAccessibleInterface *pChild) const /* override */
     155{
     156    /* Search for corresponding child: */
     157    for (int i = 0; i < childCount(); ++i)
     158        if (child(i) == pChild)
     159            return i;
     160
     161    /* -1 by default: */
     162    return -1;
     163}
     164
     165QRect QIAccessibilityInterfaceForQITableViewRow::rect() const
     166{
     167    /* Make sure row still alive: */
     168    AssertPtrReturn(row(), QRect());
     169    AssertPtrReturn(row()->table(), QRect());
     170
     171    /* Calculate local item coordinates: */
     172    const int iIndexInParent = parent()->indexOfChild(this);
     173    const int iX = row()->table()->columnViewportPosition(0);
     174    const int iY = row()->table()->rowViewportPosition(iIndexInParent);
     175    int iWidth = 0;
     176    int iHeight = 0;
     177    for (int i = 0; i < childCount(); ++i)
     178        iWidth += row()->table()->columnWidth(i);
     179    iHeight += row()->table()->rowHeight(iIndexInParent);
     180
     181    /* Map local item coordinates to global: */
     182    const QPoint itemPosInScreen = row()->table()->viewport()->mapToGlobal(QPoint(iX, iY));
     183
     184    /* Return item rectangle: */
     185    return QRect(itemPosInScreen, QSize(iWidth, iHeight));
     186}
     187
     188QString QIAccessibilityInterfaceForQITableViewRow::text(QAccessible::Text enmTextRole) const
     189{
     190    /* Make sure row still alive: */
     191    AssertPtrReturn(row(), QString());
     192
     193    /* Return a text for the passed enmTextRole: */
     194    switch (enmTextRole)
     195    {
     196        case QAccessible::Name: return childCount() > 0 && child(0) ? child(0)->text(enmTextRole) : QString();
     197        default: break;
     198    }
     199
     200    /* Null-string by default: */
     201    return QString();
     202}
     203
     204QAccessible::Role QIAccessibilityInterfaceForQITableViewRow::role() const
     205{
     206    /* Row by default: */
     207    return QAccessible::Row;
     208}
     209
     210QAccessible::State QIAccessibilityInterfaceForQITableViewRow::state() const
     211{
     212    /* Make sure row still alive: */
     213    AssertPtrReturn(row(), QAccessible::State());
     214
     215    /* Empty state by default: */
     216    return QAccessible::State();
     217}
    71218
    72219
     
    169316void QITableView::prepare()
    170317{
     318    /* Install QITableViewRow accessibility interface factory: */
     319    QAccessible::installFactory(QIAccessibilityInterfaceForQITableViewRow::pFactory);
    171320    /* Install QITableView accessibility interface factory: */
    172321    QAccessible::installFactory(QIAccessibilityInterfaceForQITableView::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