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 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 https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://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 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef ACCESSIBLE_ITEMVIEWS_H 41 #define ACCESSIBLE_ITEMVIEWS_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <QtWidgets/private/qtwidgetsglobal_p.h> 55 #include "QtCore/qpointer.h" 56 #include <QtGui/qaccessible.h> 57 #include <QtWidgets/qaccessiblewidget.h> 58 #include <QtWidgets/qabstractitemview.h> 59 #include <QtWidgets/qheaderview.h> 60 61 QT_REQUIRE_CONFIG(itemviews); 62 63 QT_BEGIN_NAMESPACE 64 65 #ifndef QT_NO_ACCESSIBILITY 66 67 class QAccessibleTableCell; 68 class QAccessibleTableHeaderCell; 69 70 class QAccessibleTable :public QAccessibleTableInterface, public QAccessibleObject 71 { 72 public: 73 explicit QAccessibleTable(QWidget *w); 74 bool isValid() const override; 75 76 QAccessible::Role role() const override; 77 QAccessible::State state() const override; 78 QString text(QAccessible::Text t) const override; 79 QRect rect() const override; 80 81 QAccessibleInterface *childAt(int x, int y) const override; 82 int childCount() const override; 83 int indexOfChild(const QAccessibleInterface *) const override; 84 85 QAccessibleInterface *parent() const override; 86 QAccessibleInterface *child(int index) const override; 87 88 void *interface_cast(QAccessible::InterfaceType t) override; 89 90 // table interface 91 virtual QAccessibleInterface *cellAt(int row, int column) const override; 92 virtual QAccessibleInterface *caption() const override; 93 virtual QAccessibleInterface *summary() const override; 94 virtual QString columnDescription(int column) const override; 95 virtual QString rowDescription(int row) const override; 96 virtual int columnCount() const override; 97 virtual int rowCount() const override; 98 99 // selection 100 virtual int selectedCellCount() const override; 101 virtual int selectedColumnCount() const override; 102 virtual int selectedRowCount() const override; 103 virtual QList<QAccessibleInterface*> selectedCells() const override; 104 virtual QList<int> selectedColumns() const override; 105 virtual QList<int> selectedRows() const override; 106 virtual bool isColumnSelected(int column) const override; 107 virtual bool isRowSelected(int row) const override; 108 virtual bool selectRow(int row) override; 109 virtual bool selectColumn(int column) override; 110 virtual bool unselectRow(int row) override; 111 virtual bool unselectColumn(int column) override; 112 113 QAbstractItemView *view() const; 114 115 void modelChange(QAccessibleTableModelChangeEvent *event) override; 116 117 protected: cellRole()118 inline QAccessible::Role cellRole() const { 119 switch (m_role) { 120 case QAccessible::List: 121 return QAccessible::ListItem; 122 case QAccessible::Table: 123 return QAccessible::Cell; 124 case QAccessible::Tree: 125 return QAccessible::TreeItem; 126 default: 127 Q_ASSERT(0); 128 } 129 return QAccessible::NoRole; 130 } 131 132 QHeaderView *horizontalHeader() const; 133 QHeaderView *verticalHeader() const; 134 135 // maybe vector 136 typedef QHash<int, QAccessible::Id> ChildCache; 137 mutable ChildCache childToId; 138 139 virtual ~QAccessibleTable(); 140 141 private: 142 // the child index for a model index 143 inline int logicalIndex(const QModelIndex &index) const; 144 QAccessible::Role m_role; 145 }; 146 147 #if QT_CONFIG(treeview) 148 class QAccessibleTree :public QAccessibleTable 149 { 150 public: QAccessibleTree(QWidget * w)151 explicit QAccessibleTree(QWidget *w) 152 : QAccessibleTable(w) 153 {} 154 155 156 QAccessibleInterface *childAt(int x, int y) const override; 157 int childCount() const override; 158 QAccessibleInterface *child(int index) const override; 159 160 int indexOfChild(const QAccessibleInterface *) const override; 161 162 int rowCount() const override; 163 164 // table interface 165 QAccessibleInterface *cellAt(int row, int column) const override; 166 QString rowDescription(int row) const override; 167 bool isRowSelected(int row) const override; 168 bool selectRow(int row) override; 169 170 private: 171 QModelIndex indexFromLogical(int row, int column = 0) const; 172 173 inline int logicalIndex(const QModelIndex &index) const; 174 }; 175 #endif 176 177 class QAccessibleTableCell: public QAccessibleInterface, public QAccessibleTableCellInterface, public QAccessibleActionInterface 178 { 179 public: 180 QAccessibleTableCell(QAbstractItemView *view, const QModelIndex &m_index, QAccessible::Role role); 181 182 void *interface_cast(QAccessible::InterfaceType t) override; object()183 QObject *object() const override { return nullptr; } 184 QAccessible::Role role() const override; 185 QAccessible::State state() const override; 186 QRect rect() const override; 187 bool isValid() const override; 188 childAt(int,int)189 QAccessibleInterface *childAt(int, int) const override { return nullptr; } childCount()190 int childCount() const override { return 0; } indexOfChild(const QAccessibleInterface *)191 int indexOfChild(const QAccessibleInterface *) const override { return -1; } 192 193 QString text(QAccessible::Text t) const override; 194 void setText(QAccessible::Text t, const QString &text) override; 195 196 QAccessibleInterface *parent() const override; 197 QAccessibleInterface *child(int) const override; 198 199 // cell interface 200 virtual int columnExtent() const override; 201 virtual QList<QAccessibleInterface*> columnHeaderCells() const override; 202 virtual int columnIndex() const override; 203 virtual int rowExtent() const override; 204 virtual QList<QAccessibleInterface*> rowHeaderCells() const override; 205 virtual int rowIndex() const override; 206 virtual bool isSelected() const override; 207 virtual QAccessibleInterface* table() const override; 208 209 //action interface 210 virtual QStringList actionNames() const override; 211 virtual void doAction(const QString &actionName) override; 212 virtual QStringList keyBindingsForAction(const QString &actionName) const override; 213 214 private: 215 QHeaderView *verticalHeader() const; 216 QHeaderView *horizontalHeader() const; 217 QPointer<QAbstractItemView > view; 218 QPersistentModelIndex m_index; 219 QAccessible::Role m_role; 220 221 void selectCell(); 222 void unselectCell(); 223 224 friend class QAccessibleTable; 225 #if QT_CONFIG(treeview) 226 friend class QAccessibleTree; 227 #endif 228 }; 229 230 231 class QAccessibleTableHeaderCell: public QAccessibleInterface 232 { 233 public: 234 // For header cells, pass the header view in addition 235 QAccessibleTableHeaderCell(QAbstractItemView *view, int index, Qt::Orientation orientation); 236 object()237 QObject *object() const override { return nullptr; } 238 QAccessible::Role role() const override; 239 QAccessible::State state() const override; 240 QRect rect() const override; 241 bool isValid() const override; 242 childAt(int,int)243 QAccessibleInterface *childAt(int, int) const override { return nullptr; } childCount()244 int childCount() const override { return 0; } indexOfChild(const QAccessibleInterface *)245 int indexOfChild(const QAccessibleInterface *) const override { return -1; } 246 247 QString text(QAccessible::Text t) const override; 248 void setText(QAccessible::Text t, const QString &text) override; 249 250 QAccessibleInterface *parent() const override; 251 QAccessibleInterface *child(int index) const override; 252 253 private: 254 QHeaderView *headerView() const; 255 256 QPointer<QAbstractItemView> view; 257 int index; 258 Qt::Orientation orientation; 259 260 friend class QAccessibleTable; 261 #if QT_CONFIG(treeview) 262 friend class QAccessibleTree; 263 #endif 264 }; 265 266 // This is the corner button on the top left of a table. 267 // It can be used to select all cells or it is not active at all. 268 // For now it is ignored. 269 class QAccessibleTableCornerButton: public QAccessibleInterface 270 { 271 public: QAccessibleTableCornerButton(QAbstractItemView * view_)272 QAccessibleTableCornerButton(QAbstractItemView *view_) 273 :view(view_) 274 {} 275 object()276 QObject *object() const override { return nullptr; } role()277 QAccessible::Role role() const override { return QAccessible::Pane; } state()278 QAccessible::State state() const override { return QAccessible::State(); } rect()279 QRect rect() const override { return QRect(); } isValid()280 bool isValid() const override { return true; } 281 childAt(int,int)282 QAccessibleInterface *childAt(int, int) const override { return nullptr; } childCount()283 int childCount() const override { return 0; } indexOfChild(const QAccessibleInterface *)284 int indexOfChild(const QAccessibleInterface *) const override { return -1; } 285 text(QAccessible::Text)286 QString text(QAccessible::Text) const override { return QString(); } setText(QAccessible::Text,const QString &)287 void setText(QAccessible::Text, const QString &) override {} 288 parent()289 QAccessibleInterface *parent() const override { 290 return QAccessible::queryAccessibleInterface(view); 291 } child(int)292 QAccessibleInterface *child(int) const override { 293 return nullptr; 294 } 295 296 private: 297 QPointer<QAbstractItemView> view; 298 }; 299 300 301 #endif // QT_NO_ACCESSIBILITY 302 303 QT_END_NAMESPACE 304 305 #endif // ACCESSIBLE_ITEMVIEWS_H 306