VirtualBox

Changeset 63699 in vbox


Ignore:
Timestamp:
Sep 2, 2016 1:15:58 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 5): Selector UI: Basic Chooser-view item accessibility interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp

    r62493 r63699  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleObject>
    2324# include <QApplication>
    2425# include <QStyle>
     
    3334
    3435/* GUI includes: */
     36# include "UIGChooser.h"
    3537# include "UIGChooserItem.h"
     38# include "UIGChooserView.h"
    3639# include "UIGChooserModel.h"
    3740# include "UIGChooserItemGroup.h"
     
    3942
    4043#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     44
     45
     46/** QAccessibleObject extension used as an accessibility interface for Chooser-view items. */
     47class UIAccessibilityInterfaceForUIGChooserItem : public QAccessibleObject
     48{
     49public:
     50
     51    /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
     52    static QAccessibleInterface* pFactory(const QString &strClassname, QObject *pObject)
     53    {
     54        /* Creating Chooser-view accessibility interface: */
     55        if (pObject && strClassname == QLatin1String("UIGChooserItem"))
     56            return new UIAccessibilityInterfaceForUIGChooserItem(pObject);
     57
     58        /* Null by default: */
     59        return 0;
     60    }
     61
     62    /** Constructs an accessibility interface passing @a pObject to the base-class. */
     63    UIAccessibilityInterfaceForUIGChooserItem(QObject *pObject)
     64        : QAccessibleObject(pObject)
     65    {}
     66
     67    /** Returns the parent. */
     68    virtual QAccessibleInterface* parent() const /* override */
     69    {
     70        /* Make sure item still alive: */
     71        AssertPtrReturn(item(), 0);
     72
     73        /* Return the parent: */
     74        return QAccessible::queryAccessibleInterface(item()->model()->chooser()->view());
     75    }
     76
     77    /** Returns the number of children. */
     78    virtual int childCount() const /* override */
     79    {
     80        /* Make sure item still alive: */
     81        AssertPtrReturn(item(), 0);
     82
     83        /* Return the number of group children: */
     84        if (item()->type() == UIGChooserItemType_Group)
     85            return item()->items().size();
     86
     87        /* Zero by default: */
     88        return 0;
     89    }
     90
     91    /** Returns the child with the passed @a iIndex. */
     92    virtual QAccessibleInterface *child(int iIndex) const /* override */
     93    {
     94        /* Make sure item still alive: */
     95        AssertPtrReturn(item(), 0);
     96
     97        /* Make sure index is valid: */
     98        if (iIndex < childCount())
     99            return QAccessible::queryAccessibleInterface(item()->items().at(iIndex));
     100
     101        /* Null by default: */
     102        return 0;
     103    }
     104
     105    /** Returns the index of the passed @a pChild. */
     106    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */
     107    {
     108        /* Search for corresponding child: */
     109        for (int i = 0; i < childCount(); ++i)
     110            if (child(i) == pChild)
     111                return i;
     112
     113        /* -1 by default: */
     114        return -1;
     115    }
     116
     117    /** Returns the rect. */
     118    virtual QRect rect() const /* override */
     119    {
     120        /* Now goes the mapping: */
     121        const QSize   itemSize         = item()->size().toSize();
     122        const QPointF itemPosInScene   = item()->mapToScene(QPointF(0, 0));
     123        const QPoint  itemPosInView    = item()->model()->chooser()->view()->mapFromScene(itemPosInScene);
     124        const QPoint  itemPosInScreen  = item()->model()->chooser()->view()->mapToGlobal(itemPosInView);
     125        const QRect   itemRectInScreen = QRect(itemPosInScreen, itemSize);
     126        return itemRectInScreen;
     127    }
     128
     129    /** Returns a text for the passed @a enmTextRole. */
     130    virtual QString text(QAccessible::Text enmTextRole) const /* override */
     131    {
     132        /* Make sure item still alive: */
     133        AssertPtrReturn(item(), QString());
     134
     135        switch (enmTextRole)
     136        {
     137            case QAccessible::Name:        return item()->name();
     138            case QAccessible::Description: return item()->description();
     139            default: break;
     140        }
     141
     142        /* Null-string by default: */
     143        return QString();
     144    }
     145
     146    /** Returns the role. */
     147    virtual QAccessible::Role role() const /* override */
     148    {
     149        /* Make sure item still alive: */
     150        AssertPtrReturn(item(), QAccessible::NoRole);
     151
     152        /* Return the number of group children: */
     153        if (item()->type() == UIGChooserItemType_Group)
     154            return QAccessible::List;
     155
     156        /* ListItem by default: */
     157        return QAccessible::ListItem;
     158    }
     159
     160    /** Returns the state. */
     161    virtual QAccessible::State state() const /* override */
     162    {
     163        /* Make sure item still alive: */
     164        AssertPtrReturn(item(), QAccessible::State());
     165
     166        /* Compose/return the state: */
     167        QAccessible::State state;
     168        state.focusable = true;
     169        state.selectable = true;
     170        if (item() && item() == item()->model()->currentItem())
     171        {
     172            state.active = true;
     173            state.focused = true;
     174            state.selected = true;
     175        }
     176        return state;
     177    }
     178
     179private:
     180
     181    /** Returns corresponding Chooser-view item. */
     182    UIGChooserItem* item() const { return qobject_cast<UIGChooserItem*>(object()); }
     183};
    41184
    42185
     
    58201    , m_iDragTokenDarkness(110)
    59202{
     203    /* Install Chooser-view item accessibility interface factory: */
     204    QAccessible::installFactory(UIAccessibilityInterfaceForUIGChooserItem::pFactory);
     205
    60206    /* Basic item setup: */
    61207    setOwnedByLayout(false);
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