VirtualBox

Changeset 63770 in vbox


Ignore:
Timestamp:
Sep 8, 2016 4:18:21 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110585
Message:

FE/Qt: bugref:6899: Accessibility support (step 20): Selector UI: Basic UITextTableLine accessibility interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsTextPane.cpp

    r63767 r63770  
    2121
    2222/* Qt includes: */
     23# include <QAccessibleObject>
    2324# include <QPainter>
    2425# include <QTextLayout>
     
    3132# include "UIRichTextString.h"
    3233
     34/* Other VBox includes: */
     35# include <iprt/assert.h>
     36
    3337#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     38
     39
     40/** QAccessibleObject extension used as an accessibility interface for UITextTableLine. */
     41class UIAccessibilityInterfaceForUITextTableLine : 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("UITextTableLine"))
     50            return new UIAccessibilityInterfaceForUITextTableLine(pObject);
     51
     52        /* Null by default: */
     53        return 0;
     54    }
     55
     56    /** Constructs an accessibility interface passing @a pObject to the base-class. */
     57    UIAccessibilityInterfaceForUITextTableLine(QObject *pObject)
     58        : QAccessibleObject(pObject)
     59    {}
     60
     61    /** Returns the parent. */
     62    virtual QAccessibleInterface *parent() const /* override */
     63    {
     64        /* Make sure line still alive: */
     65        AssertPtrReturn(line(), 0);
     66
     67        /* Return the parent: */
     68        return QAccessible::queryAccessibleInterface(line()->parent());
     69    }
     70
     71    /** Returns the number of children. */
     72    virtual int childCount() const /* override */ { return 0; }
     73    /** Returns the child with the passed @a iIndex. */
     74    virtual QAccessibleInterface *child(int /* iIndex */) const /* override */ { return 0; }
     75    /** Returns the index of the passed @a pChild. */
     76    virtual int indexOfChild(const QAccessibleInterface * /* pChild */) const /* override */ { return -1; }
     77
     78    /** Returns the rect. */
     79    virtual QRect rect() const /* override */
     80    {
     81        /* Make sure parent still alive: */
     82        AssertPtrReturn(parent(), QRect());
     83
     84        /* Return the parent's rect for now: */
     85        // TODO: Return sub-rect.
     86        return parent()->rect();
     87    }
     88
     89    /** Returns a text for the passed @a enmTextRole. */
     90    virtual QString text(QAccessible::Text enmTextRole) const /* override */
     91    {
     92        /* Make sure line still alive: */
     93        AssertPtrReturn(line(), QString());
     94
     95        /* Return the description: */
     96        if (enmTextRole == QAccessible::Description)
     97            return UIGraphicsTextPane::tr("%1: %2", "'key: value', like 'Name: MyVM'").arg(line()->string1(), line()->string2());
     98
     99        /* Null-string by default: */
     100        return QString();
     101    }
     102
     103    /** Returns the role. */
     104    virtual QAccessible::Role role() const /* override */ { return QAccessible::StaticText; }
     105    /** Returns the state. */
     106    virtual QAccessible::State state() const /* override */ { return QAccessible::State(); }
     107
     108private:
     109
     110    /** Returns corresponding text-table line. */
     111    UITextTableLine *line() const { return qobject_cast<UITextTableLine*>(object()); }
     112};
     113
    34114
    35115UIGraphicsTextPane::UIGraphicsTextPane(QIGraphicsWidget *pParent, QPaintDevice *pPaintDevice)
     
    44124    , m_fAnchorCanBeHovered(true)
    45125{
     126    /* Install text-table line accessibility interface factory: */
     127    QAccessible::installFactory(UIAccessibilityInterfaceForUITextTableLine::pFactory);
     128
    46129    /* We do support hover-events: */
    47130    setAcceptHoverEvents(true);
     
    71154        {
    72155            /* Take both lines 'as is': */
    73             m_text << UITextTableLine(strLeftLine, strRightLine, parent());
     156            m_text << UITextTableLine(strLeftLine, strRightLine, parentWidget());
    74157        }
    75158        /* If 2nd line is empty: */
     
    79162            QStringList subLines = strLeftLine.split(QRegExp("\\n"));
    80163            foreach (const QString &strSubLine, subLines)
    81                 m_text << UITextTableLine(strSubLine, QString(), parent());
     164                m_text << UITextTableLine(strSubLine, QString(), parentWidget());
    82165        }
    83166    }
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