summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/code/doc_src_qt4-accessibility.qdoc
blob: 8bed0a9201bf89a32ee1a2fc6e52fd0fb2e0a275 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! [environment]
export QT_ACCESSIBILITY=1
//! [environment]

//! [0]
class MyWidgetInterface : public QAccessibleWidget
{
public:
    MyWidgetInterface(QWidget *widget, Role role);

    QString text(Text text, int child) const;
    State state(int child) const;
    QString actionText(int action, Text text, int child) const;
    bool doAction(int action, int child, const QVariantList &params);
    ...
};
//! [0]


//! [1]
bool MyWidgetInterface::doAction(int action, int child,
                                 const QVariantList &params)
{
    if (child || !widget()->isEnabled())
        return false;

    switch (action) {
    case DefaultAction:
    case Press:
        {
            MyWidget *widget = qobject_cast<MyWidget *>(object());
            if (widget)
                widget->click();
        }
        return true;
    }
    return QAccessibleWidget::doAction(action, child, params);
}
//! [1]


//! [2]
QStringList MyFactory::keys() const
{
    return QStringList() << "MyWidget" << "MyOtherWidget";
}

QAccessibleInterface *MyFactory::create(const QString &className,
                                        QObject *object)
{
    if (classname == "MyWidget")
        return new MyWidgetInterface(object);
    if (classname == "MyOtherWidget")
        return new MyOtherWidgetInterface(object);
    return 0;
}

Q_EXPORT_PLUGIN2(myfactory, MyFactory)
//! [2]