1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef ACCESSIBLE_ITEMVIEWS_H
43 #define ACCESSIBLE_ITEMVIEWS_H
44 
45 #include "QtCore/qpointer.h"
46 
47 #include <QtGui/qabstractitemview.h>
48 #include <QtGui/qheaderview.h>
49 #include <QtGui/qaccessible.h>
50 #include <QtGui/qaccessible2.h>
51 #include <QtGui/qaccessiblewidget.h>
52 
53 
54 QT_BEGIN_NAMESPACE
55 
56 #ifndef QT_NO_ACCESSIBILITY
57 
58 #ifndef QT_NO_ITEMVIEWS
59 
60 class QAccessibleTable2Cell;
61 class QAccessibleTable2HeaderCell;
62 
63 class QAccessibleTable2: public QAccessibleTable2Interface, public QAccessibleObjectEx
64 {
65     Q_ACCESSIBLE_OBJECT
66 public:
67     explicit QAccessibleTable2(QWidget *w);
68 
69     virtual ~QAccessibleTable2();
70 
71     Role role(int child) const;
72     State state(int child) const;
73     QString text(Text t, int child) const;
74     QRect rect(int child) const;
75 
76     int childAt(int x, int y) const;
77     int childCount() const;
78     int indexOfChild(const QAccessibleInterface *) const;
79 
80     int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const;
81     Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
82 
83 #ifndef QT_NO_ACTION
84     int userActionCount(int child) const;
85     QString actionText(int action, Text t, int child) const;
86     bool doAction(int action, int child, const QVariantList &params);
87 #endif
invokeMethodEx(Method,int,const QVariantList &)88     QVariant invokeMethodEx(Method, int, const QVariantList &) { return QVariant(); }
89 
90     // table2 interface
91     virtual QAccessibleTable2CellInterface *cellAt(int row, int column) const;
92     virtual QAccessibleInterface *caption() const;
93     virtual QAccessibleInterface *summary() const;
94     virtual QString columnDescription(int column) const;
95     virtual QString rowDescription(int row) const;
96     virtual int columnCount() const;
97     virtual int rowCount() const;
98     virtual QAccessible2::TableModelChange modelChange() const;
99 
100     // selection
101     virtual int selectedCellCount() const;
102     virtual int selectedColumnCount() const;
103     virtual int selectedRowCount() const;
104     virtual QList<QAccessibleTable2CellInterface*> selectedCells() const;
105     virtual QList<int> selectedColumns() const;
106     virtual QList<int> selectedRows() const;
107     virtual bool isColumnSelected(int column) const;
108     virtual bool isRowSelected(int row) const;
109     virtual bool selectRow(int row);
110     virtual bool selectColumn(int column);
111     virtual bool unselectRow(int row);
112     virtual bool unselectColumn(int column);
113 
114     QAbstractItemView *view() const;
115 
116 protected:
117     virtual void modelReset();
118     virtual void rowsInserted(const QModelIndex &parent, int first, int last);
119     virtual void rowsRemoved(const QModelIndex &parent, int first, int last);
120     virtual void columnsInserted(const QModelIndex &parent, int first, int last);
121     virtual void columnsRemoved(const QModelIndex &parent, int first, int last);
122     virtual void rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
123     virtual void columnsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column);
124 
125 protected:
126     QAccessible2::TableModelChange lastChange;
127     inline QAccessibleTable2Cell *cell(const QModelIndex &index) const;
cellRole()128     inline QAccessible::Role cellRole() const {
129         switch (m_role) {
130         case QAccessible::List:
131             return QAccessible::ListItem;
132         case QAccessible::Table:
133             return QAccessible::Cell;
134         case QAccessible::Tree:
135             return QAccessible::TreeItem;
136         default:
137             Q_ASSERT(0);
138         }
139         return QAccessible::NoRole;
140     }
141 
142     QHeaderView *horizontalHeader() const;
143     QHeaderView *verticalHeader() const;
144 private:
145     // the child index for a model index
146     inline int logicalIndex(const QModelIndex &index) const;
147     // the model index from the child index
148     QAccessibleInterface *childFromLogical(int logicalIndex) const;
149     QAccessible::Role m_role;
150 };
151 
152 class QAccessibleTree :public QAccessibleTable2
153 {
154 public:
QAccessibleTree(QWidget * w)155     explicit QAccessibleTree(QWidget *w)
156         : QAccessibleTable2(w)
157     {}
158 
~QAccessibleTree()159     virtual ~QAccessibleTree() {}
160 
161     int childAt(int x, int y) const;
162     int childCount() const;
163     int indexOfChild(const QAccessibleInterface *) const;
164 
165     int rowCount() const;
166 
167     int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const;
168     Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
169 
170     // table2 interface
171     QAccessibleTable2CellInterface *cellAt(int row, int column) const;
172     QString rowDescription(int row) const;
173     bool isRowSelected(int row) const;
174     bool selectRow(int row);
175 
176 private:
177     QModelIndex indexFromLogical(int row, int column = 0) const;
178 };
179 
180 class QAccessibleTable2Cell: public QAccessibleTable2CellInterface /*), public QAccessibleTextInterface, public QAccessibleSimpleEditableTextInterface*/
181 {
182 public:
183     QAccessibleTable2Cell(QAbstractItemView *view, const QModelIndex &m_index, QAccessible::Role role);
184 
object()185     QObject *object() const { return 0; }
186     Role role(int child) const;
187     State state(int child) const;
188     QRect rect(int child) const;
189     bool isValid() const;
190 
childAt(int,int)191     int childAt(int, int) const { return 0; }
childCount()192     int childCount() const { return 0; }
indexOfChild(const QAccessibleInterface *)193     int indexOfChild(const QAccessibleInterface *) const  { return -1; }
194 
195     QString text(Text t, int child) const;
196     void setText(Text t, int child, const QString &text);
197 
198     int navigate(RelationFlag relation, int m_index, QAccessibleInterface **iface) const;
199     Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
200 
201     bool isExpandable() const;
202 
203 #ifndef QT_NO_ACTION
204     int userActionCount(int child) const;
205     QString actionText(int action, Text t, int child) const;
206     bool doAction(int action, int child, const QVariantList &params);
207 #endif
208 
209     // cell interface
210     virtual int columnExtent() const;
211     virtual QList<QAccessibleInterface*> columnHeaderCells() const;
212     virtual int columnIndex() const;
213     virtual int rowExtent() const;
214     virtual QList<QAccessibleInterface*> rowHeaderCells() const;
215     virtual int rowIndex() const;
216     virtual bool isSelected() const;
217     virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const;
218     virtual QAccessibleTable2Interface* table() const;
219 
220 private:
221     QHeaderView *verticalHeader() const;
222     QHeaderView *horizontalHeader() const;
223     QPointer<QAbstractItemView > view;
224     QModelIndex m_index;
225     QAccessible::Role m_role;
226 
227 friend class QAccessibleTable2;
228 friend class QAccessibleTree;
229 };
230 
231 
232 class QAccessibleTable2HeaderCell: public QAccessibleInterface /*), public QAccessibleTextInterface, public QAccessibleSimpleEditableTextInterface*/
233 {
234 public:
235     // For header cells, pass the header view in addition
236     QAccessibleTable2HeaderCell(QAbstractItemView *view, int index, Qt::Orientation orientation);
237 
object()238     QObject *object() const { return 0; }
239     Role role(int child) const;
240     State state(int child) const;
241     QRect rect(int child) const;
242     bool isValid() const;
243 
childAt(int,int)244     int childAt(int, int) const { return 0; }
childCount()245     int childCount() const { return 0; }
indexOfChild(const QAccessibleInterface *)246     int indexOfChild(const QAccessibleInterface *) const  { return -1; }
247 
248     QString text(Text t, int child) const;
249     void setText(Text t, int child, const QString &text);
250 
251     int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const;
252     Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
253 
254 #ifndef QT_NO_ACTION
255     int userActionCount(int child) const;
256     QString actionText(int action, Text t, int child) const;
257     bool doAction(int action, int child, const QVariantList &params);
258 #endif
259 
260 private:
261     QAbstractItemView *view;
262     int index;
263     Qt::Orientation orientation;
264 
265 friend class QAccessibleTable2;
266 friend class QAccessibleTree;
267 };
268 
269 // This is the corner button on the top left of a table.
270 // It can be used to select all cells or it is not active at all.
271 // For now it is ignored.
272 class QAccessibleTable2CornerButton: public QAccessibleInterface
273 {
274 public:
QAccessibleTable2CornerButton(QAbstractItemView * view_)275     QAccessibleTable2CornerButton(QAbstractItemView *view_)
276         :view(view_)
277     {}
278 
object()279     QObject *object() const { return 0; }
role(int child)280     Role role(int child) const { Q_ASSERT(child == 0); return QAccessible::Pane; }
state(int child)281     State state(int child) const { Q_ASSERT(child == 0); return QAccessible::Normal; }
rect(int child)282     QRect rect(int child) const { Q_ASSERT(child == 0); return QRect(); }
isValid()283     bool isValid() const { return true; }
284 
childAt(int,int)285     int childAt(int, int) const { return 0; }
childCount()286     int childCount() const { return 0; }
indexOfChild(const QAccessibleInterface *)287     int indexOfChild(const QAccessibleInterface *) const  { return -1; }
288 
text(Text,int)289     QString text(Text, int) const { return QString(); }
setText(Text,int,const QString &)290     void setText(Text, int, const QString &) {}
291 
navigate(RelationFlag relation,int index,QAccessibleInterface ** iface)292     int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
293     {
294         if (relation == QAccessible::Ancestor && index == 1) {
295             *iface = QAccessible::queryAccessibleInterface(view);
296             return 0;
297         }
298         return -1;
299     }
relationTo(int,const QAccessibleInterface *,int)300     Relation relationTo(int, const QAccessibleInterface *, int) const
301     {
302         return QAccessible::Unrelated;
303     }
304 
305 #ifndef QT_NO_ACTION
userActionCount(int)306     int userActionCount(int) const { return 0; }
actionText(int,Text,int)307     QString actionText(int, Text, int) const { return QString(); }
doAction(int,int,const QVariantList &)308     bool doAction(int, int, const QVariantList &) { return false; }
309 #endif
310 private:
311     QAbstractItemView *view;
312 };
313 
314 
315 #endif
316 
317 #endif // QT_NO_ACCESSIBILITY
318 
319 QT_END_NAMESPACE
320 
321 #endif // ACCESSIBLE_ITEMVIEWS_H
322