VirtualBox

Changeset 63896 in vbox


Ignore:
Timestamp:
Sep 19, 2016 4:26:16 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110770
Message:

FE/Qt: bugref:6899: Accessibility support (step 38): Selector UI: Basic Snapshot tree accessibility interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r63895 r63896  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleWidget>
    2324# include <QApplication>
    2425# include <QDateTime>
     
    5455
    5556
     57/** QAccessibleWidget extension used as an accessibility interface for Snapshot tree. */
     58class UIAccessibilityInterfaceForUISnapshotTree : public QAccessibleWidget
     59{
     60public:
     61
     62    /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
     63    static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
     64    {
     65        /* Creating Snapshot tree accessibility interface: */
     66        if (pObject && strClassname == QLatin1String("UISnapshotTree"))
     67            return new UIAccessibilityInterfaceForUISnapshotTree(qobject_cast<QWidget*>(pObject));
     68
     69        /* Null by default: */
     70        return 0;
     71    }
     72
     73    /** Constructs an accessibility interface passing @a pWidget to the base-class. */
     74    UIAccessibilityInterfaceForUISnapshotTree(QWidget *pWidget)
     75        : QAccessibleWidget(pWidget, QAccessible::List)
     76    {}
     77
     78    /** Returns the number of children. */
     79    virtual int childCount() const /* override */;
     80    /** Returns the child with the passed @a iIndex. */
     81    virtual QAccessibleInterface *child(int iIndex) const /* override */;
     82
     83    /** Returns a text for the passed @a enmTextRole. */
     84    virtual QString text(QAccessible::Text enmTextRole) const /* override */;
     85
     86private:
     87
     88    /** Returns corresponding Snapshot tree. */
     89    UISnapshotTree *tree() const { return qobject_cast<UISnapshotTree*>(widget()); }
     90};
     91
     92
    5693/** QTreeWidgetItem subclass for snapshots items. */
    5794class UISnapshotItem : public QObject, public QTreeWidgetItem
     
    175212    UISnapshotItem *childSnapshotItem(int iIndex) const;
    176213};
     214
     215
     216/*********************************************************************************************************************************
     217*   Class UIAccessibilityInterfaceForUISnapshotTree implementation.                                                              *
     218*********************************************************************************************************************************/
     219
     220int UIAccessibilityInterfaceForUISnapshotTree::childCount() const
     221{
     222    /* Make sure tree still alive: */
     223    AssertPtrReturn(tree(), 0);
     224
     225    /* Return the number of children: */
     226    return tree()->childCount();
     227}
     228
     229QAccessibleInterface *UIAccessibilityInterfaceForUISnapshotTree::child(int iIndex) const
     230{
     231    /* Make sure tree still alive: */
     232    AssertPtrReturn(tree(), 0);
     233    /* Make sure index is valid: */
     234    // WORKAROUND:
     235    // Usually I would assert here, but Qt5 accessibility code has
     236    // a hard-coded architecture for a tree-views which we do not like
     237    // but have to live with and this architecture enumerates children
     238    // of all levels as children of level 0, so Qt5 can try to address
     239    // our interface with index which surely out of bounds by our laws.
     240    if (iIndex < 0 || iIndex >= childCount())
     241        return 0;
     242
     243    /* Return the child with the passed iIndex: */
     244    return QAccessible::queryAccessibleInterface(tree()->childSnapshotItem(iIndex));
     245}
     246
     247QString UIAccessibilityInterfaceForUISnapshotTree::text(QAccessible::Text /* enmTextRole */) const
     248{
     249    /* Make sure tree still alive: */
     250    AssertPtrReturn(tree(), QString());
     251
     252    /* Return tree tool-tip: */
     253    return tree()->toolTip();
     254}
    177255
    178256
     
    505583    : QTreeWidget(pParent)
    506584{
     585    /* Install Snapshot tree accessibility interface factory: */
     586    QAccessible::installFactory(UIAccessibilityInterfaceForUISnapshotTree::pFactory);
     587
    507588    /* No header: */
    508589    header()->hide();
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