1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #ifndef ACCESSIBILITYSCENEMANAGER_H
30 #define ACCESSIBILITYSCENEMANAGER_H
31 
32 #include <QtGui>
33 
34 #include "optionswidget.h"
35 
36 QString translateRole(QAccessible::Role role);
37 class AccessibilitySceneManager : public QObject
38 {
39 Q_OBJECT
40 public:
41     AccessibilitySceneManager();
setRootWindow(QWindow * window)42     void setRootWindow(QWindow * window) { m_window = window; }
setView(QGraphicsView * view)43     void setView(QGraphicsView *view) { m_view = view; }
setScene(QGraphicsScene * scene)44     void setScene(QGraphicsScene *scene) { m_scene = scene; }
setTreeView(QGraphicsView * treeView)45     void setTreeView(QGraphicsView *treeView) { m_treeView = treeView; }
setTreeScene(QGraphicsScene * treeScene)46     void setTreeScene(QGraphicsScene *treeScene) { m_treeScene = treeScene; }
47 
setOptionsWidget(OptionsWidget * optionsWidget)48     void setOptionsWidget(OptionsWidget *optionsWidget) { m_optionsWidget = optionsWidget; }
49 public slots:
50     void populateAccessibilityScene();
51     void updateAccessibilitySceneItemFlags();
52     void populateAccessibilityTreeScene();
53     void handleUpdate(QAccessibleEvent *event);
54     void setSelected(QObject *object);
55 
56     void changeScale(int scale);
57 private:
58     void updateItems(QObject *root);
59     void updateItem(QObject *object);
60     void updateItem(QGraphicsRectItem *item, QAccessibleInterface *interface);
61     void updateItemFlags(QGraphicsRectItem *item, QAccessibleInterface *interface);
62 
63     void populateAccessibilityScene(QAccessibleInterface * interface, QGraphicsScene *scene);
64     QGraphicsRectItem * processInterface(QAccessibleInterface * interface, QGraphicsScene *scene);
65 
66     struct TreeItem;
67     TreeItem computeLevels(QAccessibleInterface * interface, int level);
68     void populateAccessibilityTreeScene(QAccessibleInterface * interface);
69     void addGraphicsItems(TreeItem item, int row, int xPos);
70 
71     bool isHidden(QAccessibleInterface *interface);
72 
73     QWindow *m_window;
74     QGraphicsView *m_view;
75     QGraphicsScene *m_scene;
76     QGraphicsView *m_treeView;
77     QGraphicsScene *m_treeScene;
78     QGraphicsItem *m_rootItem;
79     OptionsWidget *m_optionsWidget;
80     QObject *m_selectedObject;
81 
82     QHash<QObject *, QGraphicsRectItem*> m_graphicsItems;
83     QSet<QObject *> m_animatedObjects;
84 
85     struct TreeItem {
86         QList<TreeItem> children;
87         int width;
88         QString name;
89         QString role;
90         QString description;
91         QRect rect;
92         QAccessible::State state;
93         QObject *object;
TreeItemTreeItem94         TreeItem() : width(0) {}
95     };
96 
97     TreeItem m_rootTreeItem;
98     int m_treeItemWidth;
99     int m_treeItemHorizontalPadding;
100     int m_treeItemHeight;
101     int m_treeItemVerticalPadding;
102 };
103 
104 #endif // ACCESSIBILITYSCENEMANAGER_H
105