VirtualBox

Changeset 63732 in vbox


Ignore:
Timestamp:
Sep 5, 2016 4:52:40 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110508
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp

    r62493 r63732  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleObject>
    2324# include <QApplication>
    2425# include <QPainter>
     
    3132# include "UIGDetailsElement.h"
    3233# include "UIGDetailsModel.h"
     34# include "UIGDetailsView.h"
     35# include "UIGDetails.h"
    3336
    3437#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     38
     39
     40/** QAccessibleObject extension used as an accessibility interface for Details-view items. */
     41class UIAccessibilityInterfaceForUIGDetailsItem : public QAccessibleObject
     42{
     43public:
     44
     45    /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
     46    static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
     47    {
     48        /* Creating Details-view accessibility interface: */
     49        if (pObject && strClassname == QLatin1String("UIGDetailsItem"))
     50            return new UIAccessibilityInterfaceForUIGDetailsItem(pObject);
     51
     52        /* Null by default: */
     53        return 0;
     54    }
     55
     56    /** Constructs an accessibility interface passing @a pObject to the base-class. */
     57    UIAccessibilityInterfaceForUIGDetailsItem(QObject *pObject)
     58        : QAccessibleObject(pObject)
     59    {}
     60
     61    /** Returns the parent. */
     62    virtual QAccessibleInterface *parent() const /* override */
     63    {
     64        /* Make sure item still alive: */
     65        AssertPtrReturn(item(), 0);
     66
     67        /* Return the parent: */
     68        switch (item()->type())
     69        {
     70            /* For a set: */
     71            case UIGDetailsItemType_Set:
     72            {
     73                /* Always return parent view: */
     74                return QAccessible::queryAccessibleInterface(item()->model()->details()->view());
     75            }
     76            /* For an element: */
     77            case UIGDetailsItemType_Element:
     78            {
     79                /* What amount of children root has? */
     80                const int cChildCount = item()->model()->root()->items().size();
     81
     82                /* Return our parent (if root has many of children): */
     83                if (cChildCount > 1)
     84                    return QAccessible::queryAccessibleInterface(item()->parentItem());
     85
     86                /* Return parent view (otherwise): */
     87                return QAccessible::queryAccessibleInterface(item()->model()->details()->view());
     88            }
     89            default:
     90                break;
     91        }
     92
     93        /* Null by default: */
     94        return 0;
     95    }
     96
     97    /** Returns the number of children. */
     98    virtual int childCount() const /* override */
     99    {
     100        /* Make sure item still alive: */
     101        AssertPtrReturn(item(), 0);
     102
     103        /* Return the number of set children: */
     104        if (item()->type() == UIGDetailsItemType_Set)
     105            return item()->items().size();
     106
     107        /* Zero by default: */
     108        return 0;
     109    }
     110
     111    /** Returns the child with the passed @a iIndex. */
     112    virtual QAccessibleInterface *child(int iIndex) const /* override */
     113    {
     114        /* Make sure item still alive: */
     115        AssertPtrReturn(item(), 0);
     116        /* Make sure index is valid: */
     117        AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
     118
     119        /* Return the child with the passed iIndex: */
     120        return QAccessible::queryAccessibleInterface(item()->items().at(iIndex));
     121    }
     122
     123    /** Returns the index of the passed @a pChild. */
     124    virtual int indexOfChild(const QAccessibleInterface *pChild) const /* override */
     125    {
     126        /* Search for corresponding child: */
     127        for (int i = 0; i < childCount(); ++i)
     128            if (child(i) == pChild)
     129                return i;
     130
     131        /* -1 by default: */
     132        return -1;
     133    }
     134
     135    /** Returns the rect. */
     136    virtual QRect rect() const /* override */
     137    {
     138        /* Now goes the mapping: */
     139        const QSize   itemSize         = item()->size().toSize();
     140        const QPointF itemPosInScene   = item()->mapToScene(QPointF(0, 0));
     141        const QPoint  itemPosInView    = item()->model()->details()->view()->mapFromScene(itemPosInScene);
     142        const QPoint  itemPosInScreen  = item()->model()->details()->view()->mapToGlobal(itemPosInView);
     143        const QRect   itemRectInScreen = QRect(itemPosInScreen, itemSize);
     144        return itemRectInScreen;
     145    }
     146
     147    /** Returns a text for the passed @a enmTextRole. */
     148    virtual QString text(QAccessible::Text enmTextRole) const /* override */
     149    {
     150        /* Make sure item still alive: */
     151        AssertPtrReturn(item(), QString());
     152
     153        switch (enmTextRole)
     154        {
     155            case QAccessible::Name:        return item()->name();
     156            case QAccessible::Description: return item()->description();
     157            default: break;
     158        }
     159
     160        /* Null-string by default: */
     161        return QString();
     162    }
     163
     164    /** Returns the role. */
     165    virtual QAccessible::Role role() const /* override */
     166    {
     167        /* Make sure item still alive: */
     168        AssertPtrReturn(item(), QAccessible::NoRole);
     169
     170        /* Return the role of set: */
     171        if (item()->type() == UIGDetailsItemType_Set)
     172            return QAccessible::List;
     173
     174        /* ListItem by default: */
     175        return QAccessible::ListItem;
     176    }
     177
     178    /** Returns the state. */
     179    virtual QAccessible::State state() const /* override */
     180    {
     181        /* Return the default state: */
     182        QAccessible::State state;
     183        return state;
     184    }
     185
     186private:
     187
     188    /** Returns corresponding Details-view item. */
     189    UIGDetailsItem *item() const { return qobject_cast<UIGDetailsItem*>(object()); }
     190};
    35191
    36192
     
    39195    , m_pParent(pParent)
    40196{
     197    /* Install Details-view item accessibility interface factory: */
     198    QAccessible::installFactory(UIAccessibilityInterfaceForUIGDetailsItem::pFactory);
     199
    41200    /* Basic item setup: */
    42201    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