diff options
Diffstat (limited to 'src/widgets/accessible')
-rw-r--r-- | src/widgets/accessible/complexwidgets.cpp | 255 | ||||
-rw-r--r-- | src/widgets/accessible/complexwidgets_p.h | 61 | ||||
-rw-r--r-- | src/widgets/accessible/itemviews.cpp | 404 | ||||
-rw-r--r-- | src/widgets/accessible/itemviews_p.h | 59 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblemenu.cpp | 50 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblemenu_p.h | 44 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblewidget.cpp | 93 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblewidget.h | 44 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblewidgetfactory.cpp | 147 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblewidgetfactory_p.h | 45 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblewidgets.cpp | 102 | ||||
-rw-r--r-- | src/widgets/accessible/qaccessiblewidgets_p.h | 45 | ||||
-rw-r--r-- | src/widgets/accessible/rangecontrols.cpp | 56 | ||||
-rw-r--r-- | src/widgets/accessible/rangecontrols_p.h | 44 | ||||
-rw-r--r-- | src/widgets/accessible/simplewidgets.cpp | 124 | ||||
-rw-r--r-- | src/widgets/accessible/simplewidgets_p.h | 57 |
16 files changed, 714 insertions, 916 deletions
diff --git a/src/widgets/accessible/complexwidgets.cpp b/src/widgets/accessible/complexwidgets.cpp index ab543a79df..77bf8504fa 100644 --- a/src/widgets/accessible/complexwidgets.cpp +++ b/src/widgets/accessible/complexwidgets.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "complexwidgets_p.h" @@ -72,10 +36,12 @@ #endif #include <QDebug> -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QString qt_accStripAmp(const QString &text); QString qt_accHotKey(const QString &text); @@ -112,7 +78,9 @@ public: } QAccessible::State s = parent()->state(); + s.selectable = true; s.focused = (m_index == m_parent->currentIndex()); + s.selected = s.focused; return s; } QRect rect() const override { @@ -211,10 +179,18 @@ QAccessibleTabBar::QAccessibleTabBar(QWidget *w) QAccessibleTabBar::~QAccessibleTabBar() { - for (QAccessible::Id id : qAsConst(m_childInterfaces)) + for (QAccessible::Id id : std::as_const(m_childInterfaces)) QAccessible::deleteAccessibleInterface(id); } +void *QAccessibleTabBar::interface_cast(QAccessible::InterfaceType t) +{ + if (t == QAccessible::SelectionInterface) { + return static_cast<QAccessibleSelectionInterface*>(this); + } + return QAccessibleWidget::interface_cast(t); +} + /*! Returns the QTabBar. */ QTabBar *QAccessibleTabBar::tabBar() const { @@ -292,6 +268,60 @@ QString QAccessibleTabBar::text(QAccessible::Text t) const return QString(); } +int QAccessibleTabBar::selectedItemCount() const +{ + if (tabBar()->currentIndex() >= 0) + return 1; + return 0; +} + +QList<QAccessibleInterface*> QAccessibleTabBar::selectedItems() const +{ + QList<QAccessibleInterface*> items; + QAccessibleInterface *selected = selectedItem(0); + if (selected) + items.push_back(selected); + return items; +} + +QAccessibleInterface* QAccessibleTabBar::selectedItem(int selectionIndex) const +{ + const int currentIndex = tabBar()->currentIndex(); + if (selectionIndex != 0 || currentIndex < 0) + return nullptr; + return child(currentIndex); +} + +bool QAccessibleTabBar::isSelected(QAccessibleInterface *childItem) const +{ + return childItem && selectedItem(0) == childItem; +} + +bool QAccessibleTabBar::select(QAccessibleInterface *childItem) +{ + const int childIndex = indexOfChild(childItem); + if (childIndex >= 0) { + tabBar()->setCurrentIndex(childIndex); + return true; + } + return false; +} + +bool QAccessibleTabBar::unselect(QAccessibleInterface *) +{ + return false; +} + +bool QAccessibleTabBar::selectAll() +{ + return false; +} + +bool QAccessibleTabBar::clear() +{ + return false; +} + #endif // QT_CONFIG(tabbar) #if QT_CONFIG(combobox) @@ -317,17 +347,19 @@ QAccessibleComboBox::QAccessibleComboBox(QWidget *w) */ QComboBox *QAccessibleComboBox::comboBox() const { - return qobject_cast<QComboBox*>(object()); + return qobject_cast<QComboBox *>(object()); } QAccessibleInterface *QAccessibleComboBox::child(int index) const { - if (index == 0) { - QAbstractItemView *view = comboBox()->view(); - //QWidget *parent = view ? view->parentWidget() : 0; - return QAccessible::queryAccessibleInterface(view); - } else if (index == 1 && comboBox()->isEditable()) { - return QAccessible::queryAccessibleInterface(comboBox()->lineEdit()); + if (QComboBox *cBox = comboBox()) { + if (index == 0) { + QAbstractItemView *view = cBox->view(); + //QWidget *parent = view ? view->parentWidget() : 0; + return QAccessible::queryAccessibleInterface(view); + } else if (index == 1 && cBox->isEditable()) { + return QAccessible::queryAccessibleInterface(cBox->lineEdit()); + } } return nullptr; } @@ -335,55 +367,86 @@ QAccessibleInterface *QAccessibleComboBox::child(int index) const int QAccessibleComboBox::childCount() const { // list and text edit - return comboBox()->isEditable() ? 2 : 1; + if (QComboBox *cBox = comboBox()) + return (cBox->isEditable()) ? 2 : 1; + return 0; } QAccessibleInterface *QAccessibleComboBox::childAt(int x, int y) const { - if (comboBox()->isEditable() && comboBox()->lineEdit()->rect().contains(x, y)) - return child(1); + if (QComboBox *cBox = comboBox()) { + if (cBox->isEditable() && cBox->lineEdit()->rect().contains(x, y)) + return child(1); + } return nullptr; } int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const { - if (comboBox()->view() == child->object()) - return 0; - if (comboBox()->isEditable() && comboBox()->lineEdit() == child->object()) - return 1; + if (QComboBox *cBox = comboBox()) { + if (cBox->view() == child->object()) + return 0; + if (cBox->isEditable() && cBox->lineEdit() == child->object()) + return 1; + } return -1; } +QAccessibleInterface *QAccessibleComboBox::focusChild() const +{ + // The editable combobox is the focus proxy of its lineedit, so the + // lineedit itself never gets focus. But it is the accessible focus + // child of an editable combobox. + if (QComboBox *cBox = comboBox()) { + if (cBox->isEditable()) + return child(1); + } + return nullptr; +} + /*! \reimp */ QString QAccessibleComboBox::text(QAccessible::Text t) const { QString str; - - switch (t) { - case QAccessible::Name: + if (QComboBox *cBox = comboBox()) { + switch (t) { + case QAccessible::Name: #ifndef Q_OS_UNIX // on Linux we use relations for this, name is text (fall through to Value) str = QAccessibleWidget::text(t); break; #endif - case QAccessible::Value: - if (comboBox()->isEditable()) - str = comboBox()->lineEdit()->text(); - else - str = comboBox()->currentText(); - break; + case QAccessible::Value: + if (cBox->isEditable()) + str = cBox->lineEdit()->text(); + else + str = cBox->currentText(); + break; #ifndef QT_NO_SHORTCUT - case QAccessible::Accelerator: - str = QKeySequence(Qt::Key_Down).toString(QKeySequence::NativeText); - break; + case QAccessible::Accelerator: + str = QKeySequence(Qt::Key_Down).toString(QKeySequence::NativeText); + break; #endif - default: - break; + default: + break; + } + if (str.isEmpty()) + str = QAccessibleWidget::text(t); } - if (str.isEmpty()) - str = QAccessibleWidget::text(t); return str; } +QAccessible::State QAccessibleComboBox::state() const +{ + QAccessible::State s = QAccessibleWidget::state(); + + if (QComboBox *cBox = comboBox()) { + s.expandable = true; + s.expanded = isValid() && cBox->view()->isVisible(); + s.editable = cBox->isEditable(); + } + return s; +} + QStringList QAccessibleComboBox::actionNames() const { return QStringList() << showMenuAction() << pressAction(); @@ -398,26 +461,28 @@ QString QAccessibleComboBox::localizedActionDescription(const QString &actionNam void QAccessibleComboBox::doAction(const QString &actionName) { - if (actionName == showMenuAction() || actionName == pressAction()) { - if (comboBox()->view()->isVisible()) { + if (QComboBox *cBox = comboBox()) { + if (actionName == showMenuAction() || actionName == pressAction()) { + if (cBox->view()->isVisible()) { #if defined(Q_OS_ANDROID) - const auto list = child(0)->tableInterface(); - if (list && list->selectedRowCount() > 0) { - comboBox()->setCurrentIndex(list->selectedRows().at(0)); - } - comboBox()->setFocus(); + const auto list = child(0)->tableInterface(); + if (list && list->selectedRowCount() > 0) { + cBox->setCurrentIndex(list->selectedRows().at(0)); + } + cBox->setFocus(); #endif - comboBox()->hidePopup(); - } else { - comboBox()->showPopup(); + cBox->hidePopup(); + } else { + cBox->showPopup(); #if defined(Q_OS_ANDROID) - const auto list = child(0)->tableInterface(); - if (list && list->selectedRowCount() > 0) { - auto selectedCells = list->selectedCells(); - QAccessibleEvent ev(selectedCells.at(0),QAccessible::Focus); - QAccessible::updateAccessibility(&ev); - } + const auto list = child(0)->tableInterface(); + if (list && list->selectedRowCount() > 0) { + auto selectedCells = list->selectedCells(); + QAccessibleEvent ev(selectedCells.at(0),QAccessible::Focus); + QAccessible::updateAccessibility(&ev); + } #endif + } } } } @@ -444,7 +509,7 @@ QAccessibleInterface *QAccessibleAbstractScrollArea::child(int index) const int QAccessibleAbstractScrollArea::childCount() const { - return accessibleChildren().count(); + return accessibleChildren().size(); } int QAccessibleAbstractScrollArea::indexOfChild(const QAccessibleInterface *child) const @@ -490,13 +555,19 @@ QWidgetList QAccessibleAbstractScrollArea::accessibleChildren() const // Horizontal scrollBar container. QScrollBar *horizontalScrollBar = abstractScrollArea()->horizontalScrollBar(); if (horizontalScrollBar && horizontalScrollBar->isVisible()) { - children.append(horizontalScrollBar->parentWidget()); + QWidget *scrollBarParent = horizontalScrollBar->parentWidget(); + // Add container only if scroll bar is in the container + if (elementType(scrollBarParent) == HorizontalContainer) + children.append(scrollBarParent); } // Vertical scrollBar container. QScrollBar *verticalScrollBar = abstractScrollArea()->verticalScrollBar(); if (verticalScrollBar && verticalScrollBar->isVisible()) { - children.append(verticalScrollBar->parentWidget()); + QWidget *scrollBarParent = verticalScrollBar->parentWidget(); + // Add container only if scroll bar is in the container + if (elementType(scrollBarParent) == VerticalContainer) + children.append(scrollBarParent); } // CornerWidget. @@ -517,9 +588,9 @@ QAccessibleAbstractScrollArea::elementType(QWidget *widget) const return Self; if (widget == abstractScrollArea()->viewport()) return Viewport; - if (widget->objectName() == QLatin1String("qt_scrollarea_hcontainer")) + if (widget->objectName() == "qt_scrollarea_hcontainer"_L1) return HorizontalContainer; - if (widget->objectName() == QLatin1String("qt_scrollarea_vcontainer")) + if (widget->objectName() == "qt_scrollarea_vcontainer"_L1) return VerticalContainer; if (widget == abstractScrollArea()->cornerWidget()) return CornerWidget; @@ -542,4 +613,4 @@ QAccessibleScrollArea::QAccessibleScrollArea(QWidget *widget) QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) diff --git a/src/widgets/accessible/complexwidgets_p.h b/src/widgets/accessible/complexwidgets_p.h index 335e257476..5169aa8243 100644 --- a/src/widgets/accessible/complexwidgets_p.h +++ b/src/widgets/accessible/complexwidgets_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef COMPLEXWIDGETS_H #define COMPLEXWIDGETS_H @@ -60,7 +24,7 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) class QAbstractButton; class QHeaderView; @@ -106,12 +70,14 @@ public: #endif // QT_CONFIG(scrollarea) #if QT_CONFIG(tabbar) -class QAccessibleTabBar : public QAccessibleWidget +class QAccessibleTabBar : public QAccessibleWidget, public QAccessibleSelectionInterface { public: explicit QAccessibleTabBar(QWidget *w); ~QAccessibleTabBar(); + void *interface_cast(QAccessible::InterfaceType t) override; + QAccessibleInterface *focusChild() const override; int childCount() const override; QString text(QAccessible::Text t) const override; @@ -119,6 +85,16 @@ public: QAccessibleInterface* child(int index) const override; int indexOfChild(const QAccessibleInterface *child) const override; + // QAccessibleSelectionInterface + int selectedItemCount() const override; + QList<QAccessibleInterface*> selectedItems() const override; + QAccessibleInterface* selectedItem(int selectionIndex) const override; + bool isSelected(QAccessibleInterface *childItem) const override; + bool select(QAccessibleInterface *childItem) override; + bool unselect(QAccessibleInterface *childItem) override; + bool selectAll() override; + bool clear() override; + protected: QTabBar *tabBar() const; mutable QHash<int, QAccessible::Id> m_childInterfaces; @@ -135,9 +111,12 @@ public: QAccessibleInterface *childAt(int x, int y) const override; int indexOfChild(const QAccessibleInterface *child) const override; QAccessibleInterface* child(int index) const override; + QAccessibleInterface* focusChild() const override; QString text(QAccessible::Text t) const override; + QAccessible::State state() const override; + // QAccessibleActionInterface QStringList actionNames() const override; QString localizedActionDescription(const QString &actionName) const override; @@ -149,7 +128,7 @@ protected: }; #endif // QT_CONFIG(combobox) -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index a7b536ae54..aa5f729820 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "itemviews_p.h" @@ -52,7 +16,7 @@ #endif #include <private/qwidget_p.h> -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QT_BEGIN_NAMESPACE @@ -75,11 +39,16 @@ QAbstractItemView *QAccessibleTable::view() const int QAccessibleTable::logicalIndex(const QModelIndex &index) const { - if (!view()->model() || !index.isValid()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = index.model(); + if (!theModel || !index.isValid()) return -1; - int vHeader = verticalHeader() ? 1 : 0; - int hHeader = horizontalHeader() ? 1 : 0; - return (index.row() + hHeader)*(index.model()->columnCount() + vHeader) + (index.column() + vHeader); + + const QModelIndex rootIndex = theView->rootIndex(); + const int vHeader = verticalHeader() ? 1 : 0; + const int hHeader = horizontalHeader() ? 1 : 0; + return (index.row() + hHeader) * (theModel->columnCount(rootIndex) + vHeader) + + (index.column() + vHeader); } QAccessibleTable::QAccessibleTable(QWidget *w) @@ -115,7 +84,7 @@ bool QAccessibleTable::isValid() const QAccessibleTable::~QAccessibleTable() { - for (QAccessible::Id id : qAsConst(childToId)) + for (QAccessible::Id id : std::as_const(childToId)) QAccessible::deleteAccessibleInterface(id); } @@ -149,12 +118,14 @@ QHeaderView *QAccessibleTable::verticalHeader() const QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return nullptr; Q_ASSERT(role() != QAccessible::Tree); - QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); + QModelIndex index = theModel->index(row, column, theView->rootIndex()); if (Q_UNLIKELY(!index.isValid())) { - qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << view(); + qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << theView; return nullptr; } return child(logicalIndex(index)); @@ -167,51 +138,59 @@ QAccessibleInterface *QAccessibleTable::caption() const QString QAccessibleTable::columnDescription(int column) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return QString(); - return view()->model()->headerData(column, Qt::Horizontal).toString(); + return theModel->headerData(column, Qt::Horizontal).toString(); } int QAccessibleTable::columnCount() const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return 0; - return view()->model()->columnCount(); + return theModel->columnCount(theView->rootIndex()); } int QAccessibleTable::rowCount() const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return 0; - return view()->model()->rowCount(); + return theModel->rowCount(theView->rootIndex()); } int QAccessibleTable::selectedCellCount() const { if (!view()->selectionModel()) return 0; - return view()->selectionModel()->selectedIndexes().count(); + return view()->selectionModel()->selectedIndexes().size(); } int QAccessibleTable::selectedColumnCount() const { if (!view()->selectionModel()) return 0; - return view()->selectionModel()->selectedColumns().count(); + return view()->selectionModel()->selectedColumns().size(); } int QAccessibleTable::selectedRowCount() const { if (!view()->selectionModel()) return 0; - return view()->selectionModel()->selectedRows().count(); + return view()->selectionModel()->selectedRows().size(); } QString QAccessibleTable::rowDescription(int row) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return QString(); - return view()->model()->headerData(row, Qt::Vertical).toString(); + return theModel->headerData(row, Qt::Vertical).toString(); } QList<QAccessibleInterface *> QAccessibleTable::selectedCells() const @@ -273,9 +252,13 @@ bool QAccessibleTable::isRowSelected(int row) const bool QAccessibleTable::selectRow(int row) { - if (!view()->model() || !view()->selectionModel()) + QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel || !view()->selectionModel()) return false; - QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); + + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = theModel->index(row, 0, rootIndex); if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) return false; @@ -289,9 +272,10 @@ bool QAccessibleTable::selectRow(int row) view()->clearSelection(); break; case QAbstractItemView::ContiguousSelection: - if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) - && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) - view()->clearSelection(); + if ((!row || !theView->selectionModel()->isRowSelected(row - 1, rootIndex)) + && !theView->selectionModel()->isRowSelected(row + 1, rootIndex)) { + theView->clearSelection(); + } break; default: break; @@ -303,45 +287,55 @@ bool QAccessibleTable::selectRow(int row) bool QAccessibleTable::selectColumn(int column) { - if (!view()->model() || !view()->selectionModel()) + QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + auto *selectionModel = theView->selectionModel(); + if (!theModel || !selectionModel) return false; - QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); + + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = theModel->index(0, column, rootIndex); if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectRows) return false; - switch (view()->selectionMode()) { + switch (theView->selectionMode()) { case QAbstractItemView::NoSelection: return false; case QAbstractItemView::SingleSelection: - if (view()->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) + if (theView->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) return false; Q_FALLTHROUGH(); case QAbstractItemView::ContiguousSelection: - if ((!column || !view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) - && !view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) - view()->clearSelection(); + if ((!column || !selectionModel->isColumnSelected(column - 1, rootIndex)) + && !selectionModel->isColumnSelected(column + 1, rootIndex)) { + theView->clearSelection(); + } break; default: break; } - view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns); + selectionModel->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns); return true; } bool QAccessibleTable::unselectRow(int row) { - if (!view()->model() || !view()->selectionModel()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + auto *selectionModel = theView->selectionModel(); + if (!theModel || !selectionModel) return false; - QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = view()->model()->index(row, 0, rootIndex); if (!index.isValid()) return false; QItemSelection selection(index, index); - switch (view()->selectionMode()) { + switch (theView->selectionMode()) { case QAbstractItemView::SingleSelection: //In SingleSelection and ContiguousSelection once an item //is selected, there's no way for the user to unselect all items @@ -352,26 +346,31 @@ bool QAccessibleTable::unselectRow(int row) if (selectedRowCount() == 1) return false; - if ((!row || view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) - && view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) { + if ((!row || selectionModel->isRowSelected(row - 1, rootIndex)) + && selectionModel->isRowSelected(row + 1, rootIndex)) { //If there are rows selected both up the current row and down the current rown, //the ones which are down the current row will be deselected - selection = QItemSelection(index, view()->model()->index(rowCount() - 1, 0, view()->rootIndex())); + selection = QItemSelection(index, theModel->index(rowCount() - 1, 0, rootIndex)); } + break; default: break; } - view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); + selectionModel->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); return true; } bool QAccessibleTable::unselectColumn(int column) { - if (!view()->model() || !view()->selectionModel()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + auto *selectionModel = theView->selectionModel(); + if (!theModel || !selectionModel) return false; - QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = view()->model()->index(0, column, rootIndex); if (!index.isValid()) return false; @@ -388,20 +387,100 @@ bool QAccessibleTable::unselectColumn(int column) if (selectedColumnCount() == 1) return false; - if ((!column || view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) - && view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) { + if ((!column || selectionModel->isColumnSelected(column - 1, rootIndex)) + && selectionModel->isColumnSelected(column + 1, rootIndex)) { //If there are columns selected both at the left of the current row and at the right //of the current rown, the ones which are at the right will be deselected - selection = QItemSelection(index, view()->model()->index(0, columnCount() - 1, view()->rootIndex())); + selection = QItemSelection(index, theModel->index(0, columnCount() - 1, rootIndex)); } + break; default: break; } - view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns); + selectionModel->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns); return true; } +int QAccessibleTable::selectedItemCount() const +{ + return selectedCellCount(); +} + +QList<QAccessibleInterface*> QAccessibleTable::selectedItems() const +{ + return selectedCells(); +} + +bool QAccessibleTable::isSelected(QAccessibleInterface *childCell) const +{ + if (!childCell || childCell->parent() != this) { + qWarning() << "QAccessibleTable::isSelected: Accessible interface must be a direct child of the table interface."; + return false; + } + + const QAccessibleTableCellInterface *cell = childCell->tableCellInterface(); + if (cell) + return cell->isSelected(); + + return false; +} + +bool QAccessibleTable::select(QAccessibleInterface *childCell) +{ + if (!childCell || childCell->parent() != this) { + qWarning() << "QAccessibleTable::select: Accessible interface must be a direct child of the table interface."; + return false; + } + + if (!childCell->tableCellInterface()) { + qWarning() << "QAccessibleTable::select: Accessible interface doesn't implement table cell interface."; + return false; + } + + if (childCell->role() == QAccessible::Cell || childCell->role() == QAccessible::ListItem || childCell->role() == QAccessible::TreeItem) { + QAccessibleTableCell* cell = static_cast<QAccessibleTableCell*>(childCell); + cell->selectCell(); + return true; + } + + return false; +} + +bool QAccessibleTable::unselect(QAccessibleInterface *childCell) +{ + if (!childCell || childCell->parent() != this) { + qWarning() << "QAccessibleTable::select: Accessible interface must be a direct child of the table interface."; + return false; + } + + if (!childCell->tableCellInterface()) { + qWarning() << "QAccessibleTable::unselect: Accessible interface doesn't implement table cell interface."; + return false; + } + + if (childCell->role() == QAccessible::Cell || childCell->role() == QAccessible::ListItem || childCell->role() == QAccessible::TreeItem) { + QAccessibleTableCell* cell = static_cast<QAccessibleTableCell*>(childCell); + cell->unselectCell(); + return true; + } + + return false; +} + +bool QAccessibleTable::selectAll() +{ + view()->selectAll(); + return true; +} + +bool QAccessibleTable::clear() +{ + view()->selectionModel()->clearSelection(); + return true; +} + + QAccessible::Role QAccessibleTable::role() const { return m_role; @@ -409,7 +488,27 @@ QAccessible::Role QAccessibleTable::role() const QAccessible::State QAccessibleTable::state() const { - return QAccessible::State(); + QAccessible::State state; + const auto *w = view(); + + if (w->testAttribute(Qt::WA_WState_Visible) == false) + state.invisible = true; + if (w->focusPolicy() != Qt::NoFocus) + state.focusable = true; + if (w->hasFocus()) + state.focused = true; + if (!w->isEnabled()) + state.disabled = true; + if (w->isWindow()) { + if (w->windowFlags() & Qt::WindowSystemMenuHint) + state.movable = true; + if (w->minimumSize() != w->maximumSize()) + state.sizeable = true; + if (w->isActiveWindow()) + state.active = true; + } + + return state; } QAccessibleInterface *QAccessibleTable::childAt(int x, int y) const @@ -418,30 +517,44 @@ QAccessibleInterface *QAccessibleTable::childAt(int x, int y) const QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset); // FIXME: if indexPosition < 0 in one coordinate, return header - QModelIndex index = view()->indexAt(indexPosition); - if (index.isValid()) { + const QModelIndex index = view()->indexAt(indexPosition); + if (index.isValid()) return child(logicalIndex(index)); - } return nullptr; } +QAccessibleInterface *QAccessibleTable::focusChild() const +{ + QModelIndex index = view()->currentIndex(); + if (!index.isValid()) + return nullptr; + + return child(logicalIndex(index)); +} + int QAccessibleTable::childCount() const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return 0; + const QModelIndex rootIndex = theView->rootIndex(); int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; - return (view()->model()->rowCount()+hHeader) * (view()->model()->columnCount()+vHeader); + return (theModel->rowCount(rootIndex) + hHeader) * (theModel->columnCount(rootIndex) + vHeader); } int QAccessibleTable::indexOfChild(const QAccessibleInterface *iface) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return -1; QAccessibleInterface *parent = iface->parent(); - if (parent->object() != view()) + if (parent->object() != theView) return -1; + const QModelIndex rootIndex = theView->rootIndex(); Q_ASSERT(iface->role() != QAccessible::TreeItem); // should be handled by tree class if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) { const QAccessibleTableCell* cell = static_cast<const QAccessibleTableCell*>(iface); @@ -451,7 +564,7 @@ int QAccessibleTable::indexOfChild(const QAccessibleInterface *iface) const return cell->index + (verticalHeader() ? 1 : 0); } else if (iface->role() == QAccessible::RowHeader){ const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); - return (cell->index + 1) * (view()->model()->columnCount() + 1); + return (cell->index + 1) * (theModel->columnCount(rootIndex) + 1); } else if (iface->role() == QAccessible::Pane) { return 0; // corner button } else { @@ -485,14 +598,17 @@ QAccessibleInterface *QAccessibleTable::parent() const } return QAccessible::queryAccessibleInterface(view()->parent()); } - return nullptr; + return QAccessible::queryAccessibleInterface(qApp); } QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const { - if (!view()->model()) + QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return nullptr; + const QModelIndex rootIndex = theView->rootIndex(); auto id = childToId.constFind(logicalIndex); if (id != childToId.constEnd()) return QAccessible::accessibleInterface(id.value()); @@ -500,7 +616,7 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; - int columns = view()->model()->columnCount() + vHeader; + int columns = theModel->columnCount(rootIndex) + vHeader; int row = logicalIndex / columns; int column = logicalIndex % columns; @@ -510,27 +626,27 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const if (vHeader) { if (column == 0) { if (hHeader && row == 0) { - iface = new QAccessibleTableCornerButton(view()); + iface = new QAccessibleTableCornerButton(theView); } else { - iface = new QAccessibleTableHeaderCell(view(), row - hHeader, Qt::Vertical); + iface = new QAccessibleTableHeaderCell(theView, row - hHeader, Qt::Vertical); } } --column; } if (!iface && hHeader) { if (row == 0) { - iface = new QAccessibleTableHeaderCell(view(), column, Qt::Horizontal); + iface = new QAccessibleTableHeaderCell(theView, column, Qt::Horizontal); } --row; } if (!iface) { - QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); + QModelIndex index = theModel->index(row, column, rootIndex); if (Q_UNLIKELY(!index.isValid())) { qWarning("QAccessibleTable::child: Invalid index at: %d %d", row, column); return nullptr; } - iface = new QAccessibleTableCell(view(), index, cellRole()); + iface = new QAccessibleTableCell(theView, index, cellRole()); } QAccessible::registerAccessibleInterface(iface); @@ -540,6 +656,8 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const void *QAccessibleTable::interface_cast(QAccessible::InterfaceType t) { + if (t == QAccessible::SelectionInterface) + return static_cast<QAccessibleSelectionInterface*>(this); if (t == QAccessible::TableInterface) return static_cast<QAccessibleTableInterface*>(this); return nullptr; @@ -553,7 +671,7 @@ void QAccessibleTable::modelChange(QAccessibleTableModelChangeEvent *event) switch (event->modelChangeType()) { case QAccessibleTableModelChangeEvent::ModelReset: - for (QAccessible::Id id : qAsConst(childToId)) + for (QAccessible::Id id : std::as_const(childToId)) QAccessible::deleteAccessibleInterface(id); childToId.clear(); break; @@ -661,7 +779,7 @@ QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const return QModelIndex(); const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); - if (Q_UNLIKELY(row < 0 || column < 0 || treeView->d_func()->viewItems.count() <= row)) { + if (Q_UNLIKELY(row < 0 || column < 0 || treeView->d_func()->viewItems.size() <= row)) { qWarning() << "QAccessibleTree::indexFromLogical: invalid index: " << row << column << " for " << treeView; return QModelIndex(); } @@ -675,20 +793,39 @@ QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const QAccessibleInterface *QAccessibleTree::childAt(int x, int y) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return nullptr; - QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0)); - QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset); - QModelIndex index = view()->indexAt(indexPosition); + const QPoint viewportOffset = theView->viewport()->mapTo(view(), QPoint(0, 0)); + const QPoint indexPosition = theView->mapFromGlobal(QPoint(x, y) - viewportOffset); + + const QModelIndex index = theView->indexAt(indexPosition); if (!index.isValid()) return nullptr; - const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); + const QTreeView *treeView = qobject_cast<const QTreeView *>(theView); int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0); int column = index.column(); - int i = row * view()->model()->columnCount() + column; + int i = row * theModel->columnCount(theView->rootIndex()) + column; + return child(i); +} + +QAccessibleInterface *QAccessibleTree::focusChild() const +{ + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + const QModelIndex index = theView->currentIndex(); + if (!index.isValid()) + return nullptr; + + const QTreeView *treeView = qobject_cast<const QTreeView *>(theView); + const int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0); + const int column = index.column(); + + int i = row * theModel->columnCount(theView->rootIndex()) + column; return child(i); } @@ -696,33 +833,37 @@ int QAccessibleTree::childCount() const { const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); Q_ASSERT(treeView); - if (!view()->model()) + const QAbstractItemModel *theModel = treeView->model(); + if (!theModel) return 0; int hHeader = horizontalHeader() ? 1 : 0; - return (treeView->d_func()->viewItems.count() + hHeader)* view()->model()->columnCount(); + return (treeView->d_func()->viewItems.size() + hHeader) + * theModel->columnCount(treeView->rootIndex()); } QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const { - if (logicalIndex < 0 || !view()->model() || !view()->model()->columnCount()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + const QModelIndex rootIndex = theView->rootIndex(); + if (logicalIndex < 0 || !theModel || !theModel->columnCount(rootIndex)) return nullptr; QAccessibleInterface *iface = nullptr; int index = logicalIndex; if (horizontalHeader()) { - if (index < view()->model()->columnCount()) { + if (index < theModel->columnCount(rootIndex)) iface = new QAccessibleTableHeaderCell(view(), index, Qt::Horizontal); - } else { - index -= view()->model()->columnCount(); - } + else + index -= theModel->columnCount(rootIndex); } if (!iface) { - int row = index / view()->model()->columnCount(); - int column = index % view()->model()->columnCount(); - QModelIndex modelIndex = indexFromLogical(row, column); + const int row = index / theModel->columnCount(rootIndex); + const int column = index % theModel->columnCount(rootIndex); + const QModelIndex modelIndex = indexFromLogical(row, column); if (!modelIndex.isValid()) return nullptr; iface = new QAccessibleTableCell(view(), modelIndex, cellRole()); @@ -736,12 +877,14 @@ int QAccessibleTree::rowCount() const { const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); Q_ASSERT(treeView); - return treeView->d_func()->viewItems.count(); + return treeView->d_func()->viewItems.size(); } int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return -1; QAccessibleInterface *parent = iface->parent(); if (parent->object() != view()) @@ -749,12 +892,12 @@ int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const if (iface->role() == QAccessible::TreeItem) { const QAccessibleTableCell* cell = static_cast<const QAccessibleTableCell*>(iface); - const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); + const QTreeView *treeView = qobject_cast<const QTreeView *>(theView); Q_ASSERT(treeView); int row = treeView->d_func()->viewIndex(cell->m_index) + (horizontalHeader() ? 1 : 0); int column = cell->m_index.column(); - int index = row * view()->model()->columnCount() + column; + int index = row * theModel->columnCount(theView->rootIndex()) + column; return index; } else if (iface->role() == QAccessible::ColumnHeader){ const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); @@ -1017,7 +1160,7 @@ void QAccessibleTableCell::unselectCell() //one cell is selected it cannot be unselected by the user if ((selectionMode != QAbstractItemView::MultiSelection) && (selectionMode != QAbstractItemView::ExtendedSelection) - && (view->selectionModel()->selectedIndexes().count() <= 1)) + && (view->selectionModel()->selectedIndexes().size() <= 1)) return; view->selectionModel()->select(m_index, QItemSelectionModel::Deselect); @@ -1211,9 +1354,14 @@ void QAccessibleTableHeaderCell::setText(QAccessible::Text, const QString &) bool QAccessibleTableHeaderCell::isValid() const { - return view && !qt_widget_private(view)->data.in_destructor - && view->model() && (index >= 0) - && ((orientation == Qt::Horizontal) ? (index < view->model()->columnCount()) : (index < view->model()->rowCount())); + const QAbstractItemModel *theModel = view && !qt_widget_private(view)->data.in_destructor + ? view->model() : nullptr; + if (!theModel) + return false; + const QModelIndex rootIndex = view->rootIndex(); + return (index >= 0) && ((orientation == Qt::Horizontal) + ? (index < theModel->columnCount(rootIndex)) + : (index < theModel->rowCount(rootIndex))); } QAccessibleInterface *QAccessibleTableHeaderCell::parent() const @@ -1248,4 +1396,4 @@ QHeaderView *QAccessibleTableHeaderCell::headerView() const QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) diff --git a/src/widgets/accessible/itemviews_p.h b/src/widgets/accessible/itemviews_p.h index 683ae9c948..077f14de1d 100644 --- a/src/widgets/accessible/itemviews_p.h +++ b/src/widgets/accessible/itemviews_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef ACCESSIBLE_ITEMVIEWS_H #define ACCESSIBLE_ITEMVIEWS_H @@ -62,12 +26,12 @@ QT_REQUIRE_CONFIG(itemviews); QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) class QAccessibleTableCell; class QAccessibleTableHeaderCell; -class QAccessibleTable :public QAccessibleTableInterface, public QAccessibleObject +class QAccessibleTable :public QAccessibleTableInterface, public QAccessibleSelectionInterface, public QAccessibleObject { public: explicit QAccessibleTable(QWidget *w); @@ -79,6 +43,7 @@ public: QRect rect() const override; QAccessibleInterface *childAt(int x, int y) const override; + QAccessibleInterface *focusChild() const override; int childCount() const override; int indexOfChild(const QAccessibleInterface *) const override; @@ -110,6 +75,15 @@ public: virtual bool unselectRow(int row) override; virtual bool unselectColumn(int column) override; + // QAccessibleSelectionInterface + virtual int selectedItemCount() const override; + virtual QList<QAccessibleInterface*> selectedItems() const override; + virtual bool isSelected(QAccessibleInterface *childCell) const override; + virtual bool select(QAccessibleInterface *childCell) override; + virtual bool unselect(QAccessibleInterface *childCell) override; + virtual bool selectAll() override; + virtual bool clear() override; + QAbstractItemView *view() const; void modelChange(QAccessibleTableModelChangeEvent *event) override; @@ -154,6 +128,7 @@ public: QAccessibleInterface *childAt(int x, int y) const override; + QAccessibleInterface *focusChild() const override; int childCount() const override; QAccessibleInterface *child(int index) const override; @@ -169,8 +144,6 @@ public: private: QModelIndex indexFromLogical(int row, int column = 0) const; - - inline int logicalIndex(const QModelIndex &index) const; }; #endif @@ -298,7 +271,7 @@ private: }; -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/qaccessiblemenu.cpp b/src/widgets/accessible/qaccessiblemenu.cpp index 962a56170a..1d72a82456 100644 --- a/src/widgets/accessible/qaccessiblemenu.cpp +++ b/src/widgets/accessible/qaccessiblemenu.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qaccessiblemenu_p.h" @@ -48,7 +12,7 @@ #include <qstyle.h> #include <private/qwidget_p.h> -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QT_BEGIN_NAMESPACE @@ -80,7 +44,7 @@ QMenu *QAccessibleMenu::menu() const int QAccessibleMenu::childCount() const { - return menu()->actions().count(); + return menu()->actions().size(); } QAccessibleInterface *QAccessibleMenu::childAt(int x, int y) const @@ -121,7 +85,7 @@ QAccessibleInterface *QAccessibleMenu::parent() const const QList<QObject *> associatedObjects = menuAction->associatedObjects(); parentCandidates.reserve(associatedObjects.size() + 1); parentCandidates << menu()->parentWidget() << associatedObjects; - for (QObject *object : qAsConst(parentCandidates)) { + for (QObject *object : std::as_const(parentCandidates)) { if (qobject_cast<QMenu*>(object) #if QT_CONFIG(menubar) || qobject_cast<QMenuBar*>(object) @@ -159,7 +123,7 @@ QMenuBar *QAccessibleMenuBar::menuBar() const int QAccessibleMenuBar::childCount() const { - return menuBar()->actions().count(); + return menuBar()->actions().size(); } QAccessibleInterface *QAccessibleMenuBar::child(int index) const @@ -393,5 +357,5 @@ QWidget *QAccessibleMenuItem::owner() const QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) diff --git a/src/widgets/accessible/qaccessiblemenu_p.h b/src/widgets/accessible/qaccessiblemenu_p.h index 9acd2a42f9..8eb9a37e2d 100644 --- a/src/widgets/accessible/qaccessiblemenu_p.h +++ b/src/widgets/accessible/qaccessiblemenu_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QACCESSIBLEMENU_H #define QACCESSIBLEMENU_H @@ -57,7 +21,7 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) #if QT_CONFIG(menu) class QMenu; @@ -139,5 +103,5 @@ private: #endif // QT_CONFIG(menu) QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) #endif // QACCESSIBLEMENU_H diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index ae545a5ce2..b0bb12ea86 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -1,45 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qaccessiblewidget.h" -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) #include "qapplication.h" #if QT_CONFIG(groupbox) @@ -68,22 +32,9 @@ QT_BEGIN_NAMESPACE -static QList<QWidget*> childWidgets(const QWidget *widget) -{ - QList<QWidget*> widgets; - for (QObject *o : widget->children()) { - QWidget *w = qobject_cast<QWidget *>(o); - if (w && !w->isWindow() - && !qobject_cast<QFocusFrame*>(w) -#if QT_CONFIG(menu) - && !qobject_cast<QMenu*>(w) -#endif - && w->objectName() != QLatin1String("qt_rubberband") - && w->objectName() != QLatin1String("qt_spinbox_lineedit")) - widgets.append(w); - } - return widgets; -} +using namespace Qt::StringLiterals; + +QWidgetList _q_ac_childWidgets(const QWidget *widget); static QString buddyString(const QWidget *widget) { @@ -112,18 +63,18 @@ static QString buddyString(const QWidget *widget) /* This function will return the offset of the '&' in the text that would be preceding the accelerator character. If this text does not have an accelerator, -1 will be returned. */ -static int qt_accAmpIndex(const QString &text) +static qsizetype qt_accAmpIndex(const QString &text) { #ifndef QT_NO_SHORTCUT if (text.isEmpty()) return -1; - int fa = 0; - while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) { + qsizetype fa = 0; + while ((fa = text.indexOf(u'&', fa)) != -1) { ++fa; - if (fa < text.length()) { + if (fa < text.size()) { // ignore "&&" - if (text.at(fa) == QLatin1Char('&')) { + if (text.at(fa) == u'&') { ++fa; continue; @@ -144,17 +95,17 @@ static int qt_accAmpIndex(const QString &text) QString qt_accStripAmp(const QString &text) { QString newText(text); - int ampIndex = qt_accAmpIndex(newText); + qsizetype ampIndex = qt_accAmpIndex(newText); if (ampIndex != -1) newText.remove(ampIndex, 1); - return newText.replace(QLatin1String("&&"), QLatin1String("&")); + return newText.replace("&&"_L1, "&"_L1); } QString qt_accHotKey(const QString &text) { #ifndef QT_NO_SHORTCUT - int ampIndex = qt_accAmpIndex(text); + qsizetype ampIndex = qt_accAmpIndex(text); if (ampIndex != -1) return QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + text.at(ampIndex + 1); #else @@ -285,7 +236,7 @@ void QAccessibleWidget::addControllingSignal(const QString &signal) QByteArray s = QMetaObject::normalizedSignature(signal.toLatin1()); if (Q_UNLIKELY(object()->metaObject()->indexOfSignal(s) < 0)) qWarning("Signal %s unknown in %s", s.constData(), object()->metaObject()->className()); - d->primarySignals << QLatin1String(s); + d->primarySignals << QLatin1StringView(s); } static inline bool isAncestor(const QObject *obj, const QObject *child) @@ -310,7 +261,7 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel // first check for all siblings that are labels to us // ideally we would go through all objects and check, but that // will be too expensive - const QList<QWidget*> kids = childWidgets(parent); + const QList<QWidget*> kids = _q_ac_childWidgets(parent); for (QWidget *kid : kids) { if (QLabel *labelSibling = qobject_cast<QLabel*>(kid)) { if (labelSibling->buddy() == widget()) { @@ -333,14 +284,14 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel if (match & QAccessible::Controlled) { QObjectList allReceivers; QObject *connectionObject = object(); - for (int sig = 0; sig < d->primarySignals.count(); ++sig) { + for (int sig = 0; sig < d->primarySignals.size(); ++sig) { const QObjectList receivers = connectionObject->d_func()->receiverList(d->primarySignals.at(sig).toLatin1()); allReceivers += receivers; } allReceivers.removeAll(object()); //### The object might connect to itself internally - for (int i = 0; i < allReceivers.count(); ++i) { + for (int i = 0; i < allReceivers.size(); ++i) { const QAccessible::Relation rel = QAccessible::Controlled; QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(allReceivers.at(i)); if (iface) @@ -361,7 +312,7 @@ QAccessibleInterface *QAccessibleWidget::parent() const QAccessibleInterface *QAccessibleWidget::child(int index) const { Q_ASSERT(widget()); - QWidgetList childList = childWidgets(widget()); + QWidgetList childList = _q_ac_childWidgets(widget()); if (index >= 0 && index < childList.size()) return QAccessible::queryAccessibleInterface(childList.at(index)); return nullptr; @@ -389,7 +340,7 @@ QAccessibleInterface *QAccessibleWidget::focusChild() const /*! \reimp */ int QAccessibleWidget::childCount() const { - QWidgetList cl = childWidgets(widget()); + QWidgetList cl = _q_ac_childWidgets(widget()); return cl.size(); } @@ -398,7 +349,7 @@ int QAccessibleWidget::indexOfChild(const QAccessibleInterface *child) const { if (!child) return -1; - QWidgetList cl = childWidgets(widget()); + QWidgetList cl = _q_ac_childWidgets(widget()); return cl.indexOf(qobject_cast<QWidget *>(child->object())); } @@ -532,4 +483,4 @@ void *QAccessibleWidget::interface_cast(QAccessible::InterfaceType t) QT_END_NAMESPACE -#endif //QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) diff --git a/src/widgets/accessible/qaccessiblewidget.h b/src/widgets/accessible/qaccessiblewidget.h index 7b915a99ac..c237e25d4a 100644 --- a/src/widgets/accessible/qaccessiblewidget.h +++ b/src/widgets/accessible/qaccessiblewidget.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QACCESSIBLEWIDGET_H #define QACCESSIBLEWIDGET_H @@ -46,7 +10,7 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) class QAccessibleWidgetPrivate; @@ -94,7 +58,7 @@ private: }; -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/qaccessiblewidgetfactory.cpp b/src/widgets/accessible/qaccessiblewidgetfactory.cpp index 4c6a6fdecb..664e35a6e7 100644 --- a/src/widgets/accessible/qaccessiblewidgetfactory.cpp +++ b/src/widgets/accessible/qaccessiblewidgetfactory.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qaccessiblewidgets_p.h" #include "qaccessiblemenu_p.h" @@ -56,10 +20,12 @@ #include <qvariant.h> #include <qaccessible.h> -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *object) { QAccessibleInterface *iface = nullptr; @@ -77,154 +43,155 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje if (false) { #if QT_CONFIG(lineedit) - } else if (classname == QLatin1String("QLineEdit")) { - if (widget->objectName() == QLatin1String("qt_spinbox_lineedit")) + } else if (classname == "QLineEdit"_L1) { + if (widget->objectName() == "qt_spinbox_lineedit"_L1) iface = nullptr; else iface = new QAccessibleLineEdit(widget); #endif #if QT_CONFIG(combobox) - } else if (classname == QLatin1String("QComboBox")) { + } else if (classname == "QComboBox"_L1) { iface = new QAccessibleComboBox(widget); #endif #if QT_CONFIG(spinbox) - } else if (classname == QLatin1String("QAbstractSpinBox")) { + } else if (classname == "QAbstractSpinBox"_L1) { iface = new QAccessibleAbstractSpinBox(widget); - } else if (classname == QLatin1String("QSpinBox")) { + } else if (classname == "QSpinBox"_L1) { iface = new QAccessibleSpinBox(widget); - } else if (classname == QLatin1String("QDoubleSpinBox")) { + } else if (classname == "QDoubleSpinBox"_L1) { iface = new QAccessibleDoubleSpinBox(widget); #endif #if QT_CONFIG(scrollbar) - } else if (classname == QLatin1String("QScrollBar")) { + } else if (classname == "QScrollBar"_L1) { iface = new QAccessibleScrollBar(widget); #endif #if QT_CONFIG(slider) - } else if (classname == QLatin1String("QAbstractSlider")) { + } else if (classname == "QAbstractSlider"_L1) { iface = new QAccessibleAbstractSlider(widget); - } else if (classname == QLatin1String("QSlider")) { + } else if (classname == "QSlider"_L1) { iface = new QAccessibleSlider(widget); #endif #if QT_CONFIG(toolbutton) - } else if (classname == QLatin1String("QToolButton")) { + } else if (classname == "QToolButton"_L1) { iface = new QAccessibleToolButton(widget); #endif // QT_CONFIG(toolbutton) #if QT_CONFIG(abstractbutton) - } else if (classname == QLatin1String("QCheckBox") - || classname == QLatin1String("QRadioButton") - || classname == QLatin1String("QPushButton") - || classname == QLatin1String("QAbstractButton")) { + } else if (classname == "QCheckBox"_L1 + || classname == "QRadioButton"_L1 + || classname == "QPushButton"_L1 + || classname == "QAbstractButton"_L1) { iface = new QAccessibleButton(widget); #endif - } else if (classname == QLatin1String("QDialog")) { + } else if (classname == "QDialog"_L1) { iface = new QAccessibleWidget(widget, QAccessible::Dialog); - } else if (classname == QLatin1String("QMessageBox")) { - iface = new QAccessibleWidget(widget, QAccessible::AlertMessage); +#if QT_CONFIG(messagebox) + } else if (classname == "QMessageBox"_L1) { + iface = new QAccessibleMessageBox(widget); +#endif #if QT_CONFIG(mainwindow) - } else if (classname == QLatin1String("QMainWindow")) { + } else if (classname == "QMainWindow"_L1) { iface = new QAccessibleMainWindow(widget); #endif - } else if (classname == QLatin1String("QLabel") || classname == QLatin1String("QLCDNumber")) { + } else if (classname == "QLabel"_L1 || classname == "QLCDNumber"_L1) { iface = new QAccessibleDisplay(widget); #if QT_CONFIG(groupbox) - } else if (classname == QLatin1String("QGroupBox")) { + } else if (classname == "QGroupBox"_L1) { iface = new QAccessibleGroupBox(widget); #endif - } else if (classname == QLatin1String("QStatusBar")) { + } else if (classname == "QStatusBar"_L1) { iface = new QAccessibleDisplay(widget); #if QT_CONFIG(progressbar) - } else if (classname == QLatin1String("QProgressBar")) { + } else if (classname == "QProgressBar"_L1) { iface = new QAccessibleProgressBar(widget); #endif - } else if (classname == QLatin1String("QToolBar")) { + } else if (classname == "QToolBar"_L1) { iface = new QAccessibleWidget(widget, QAccessible::ToolBar, widget->windowTitle()); #if QT_CONFIG(menubar) - } else if (classname == QLatin1String("QMenuBar")) { + } else if (classname == "QMenuBar"_L1) { iface = new QAccessibleMenuBar(widget); #endif #if QT_CONFIG(menu) - } else if (classname == QLatin1String("QMenu")) { + } else if (classname == "QMenu"_L1) { iface = new QAccessibleMenu(widget); #endif #if QT_CONFIG(treeview) - } else if (classname == QLatin1String("QTreeView")) { + } else if (classname == "QTreeView"_L1) { iface = new QAccessibleTree(widget); #endif // QT_CONFIG(treeview) #if QT_CONFIG(itemviews) - } else if (classname == QLatin1String("QTableView") || classname == QLatin1String("QListView")) { + } else if (classname == "QTableView"_L1 || classname == "QListView"_L1) { iface = new QAccessibleTable(widget); - // ### This should be cleaned up. We return the parent for the scrollarea to hide it. #endif // QT_CONFIG(itemviews) #if QT_CONFIG(tabbar) - } else if (classname == QLatin1String("QTabBar")) { + } else if (classname == "QTabBar"_L1) { iface = new QAccessibleTabBar(widget); #endif - } else if (classname == QLatin1String("QSizeGrip")) { + } else if (classname == "QSizeGrip"_L1) { iface = new QAccessibleWidget(widget, QAccessible::Grip); #if QT_CONFIG(splitter) - } else if (classname == QLatin1String("QSplitter")) { + } else if (classname == "QSplitter"_L1) { iface = new QAccessibleWidget(widget, QAccessible::Splitter); - } else if (classname == QLatin1String("QSplitterHandle")) { + } else if (classname == "QSplitterHandle"_L1) { iface = new QAccessibleWidget(widget, QAccessible::Grip); #endif #if QT_CONFIG(textedit) && !defined(QT_NO_CURSOR) - } else if (classname == QLatin1String("QTextEdit")) { + } else if (classname == "QTextEdit"_L1) { iface = new QAccessibleTextEdit(widget); - } else if (classname == QLatin1String("QPlainTextEdit")) { + } else if (classname == "QPlainTextEdit"_L1) { iface = new QAccessiblePlainTextEdit(widget); #endif - } else if (classname == QLatin1String("QTipLabel")) { + } else if (classname == "QTipLabel"_L1) { iface = new QAccessibleDisplay(widget, QAccessible::ToolTip); - } else if (classname == QLatin1String("QFrame")) { + } else if (classname == "QFrame"_L1) { iface = new QAccessibleWidget(widget, QAccessible::Border); #if QT_CONFIG(stackedwidget) - } else if (classname == QLatin1String("QStackedWidget")) { + } else if (classname == "QStackedWidget"_L1) { iface = new QAccessibleStackedWidget(widget); #endif #if QT_CONFIG(toolbox) - } else if (classname == QLatin1String("QToolBox")) { + } else if (classname == "QToolBox"_L1) { iface = new QAccessibleToolBox(widget); #endif #if QT_CONFIG(mdiarea) - } else if (classname == QLatin1String("QMdiArea")) { + } else if (classname == "QMdiArea"_L1) { iface = new QAccessibleMdiArea(widget); - } else if (classname == QLatin1String("QMdiSubWindow")) { + } else if (classname == "QMdiSubWindow"_L1) { iface = new QAccessibleMdiSubWindow(widget); #endif #if QT_CONFIG(dialogbuttonbox) - } else if (classname == QLatin1String("QDialogButtonBox")) { + } else if (classname == "QDialogButtonBox"_L1) { iface = new QAccessibleDialogButtonBox(widget); #endif #if QT_CONFIG(dial) - } else if (classname == QLatin1String("QDial")) { + } else if (classname == "QDial"_L1) { iface = new QAccessibleDial(widget); #endif #if QT_CONFIG(rubberband) - } else if (classname == QLatin1String("QRubberBand")) { + } else if (classname == "QRubberBand"_L1) { iface = new QAccessibleWidget(widget, QAccessible::Border); #endif #if QT_CONFIG(textbrowser) && !defined(QT_NO_CURSOR) - } else if (classname == QLatin1String("QTextBrowser")) { + } else if (classname == "QTextBrowser"_L1) { iface = new QAccessibleTextBrowser(widget); #endif #if QT_CONFIG(scrollarea) - } else if (classname == QLatin1String("QAbstractScrollArea")) { + } else if (classname == "QAbstractScrollArea"_L1) { iface = new QAccessibleAbstractScrollArea(widget); - } else if (classname == QLatin1String("QScrollArea")) { + } else if (classname == "QScrollArea"_L1) { iface = new QAccessibleScrollArea(widget); #endif #if QT_CONFIG(calendarwidget) - } else if (classname == QLatin1String("QCalendarWidget")) { + } else if (classname == "QCalendarWidget"_L1) { iface = new QAccessibleCalendarWidget(widget); #endif #if QT_CONFIG(dockwidget) - } else if (classname == QLatin1String("QDockWidget")) { + } else if (classname == "QDockWidget"_L1) { iface = new QAccessibleDockWidget(widget); #endif - } else if (classname == QLatin1String("QWidget")) { + } else if (classname == "QWidget"_L1) { iface = new QAccessibleWidget(widget); - } else if (classname == QLatin1String("QWindowContainer")) { + } else if (classname == "QWindowContainer"_L1) { iface = new QAccessibleWindowContainer(widget); } @@ -233,4 +200,4 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) diff --git a/src/widgets/accessible/qaccessiblewidgetfactory_p.h b/src/widgets/accessible/qaccessiblewidgetfactory_p.h index 5da609ddca..eb37b33ff7 100644 --- a/src/widgets/accessible/qaccessiblewidgetfactory_p.h +++ b/src/widgets/accessible/qaccessiblewidgetfactory_p.h @@ -1,44 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <QtWidgets/private/qtwidgetsglobal_p.h> -#include <QtGui/qaccessible.h> #ifndef QACCESSIBLEWIDGETFACTORY_H #define QACCESSIBLEWIDGETFACTORY_H @@ -56,6 +19,10 @@ QT_BEGIN_NAMESPACE +class QObject; +class QAccessibleInterface; +class QString; + QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *object); QT_END_NAMESPACE diff --git a/src/widgets/accessible/qaccessiblewidgets.cpp b/src/widgets/accessible/qaccessiblewidgets.cpp index d9ba34c145..5c2a3bd02b 100644 --- a/src/widgets/accessible/qaccessiblewidgets.cpp +++ b/src/widgets/accessible/qaccessiblewidgets.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qaccessiblewidgets_p.h" #include "qabstracttextdocumentlayout.h" @@ -92,14 +56,16 @@ #include <QMenu> #endif -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QString qt_accStripAmp(const QString &text); QString qt_accHotKey(const QString &text); -QList<QWidget*> childWidgets(const QWidget *widget) +QWidgetList _q_ac_childWidgets(const QWidget *widget) { QList<QWidget*> widgets; if (!widget) @@ -114,8 +80,10 @@ QList<QWidget*> childWidgets(const QWidget *widget) #if QT_CONFIG(menu) && !qobject_cast<QMenu*>(w) #endif - && objectName != QLatin1String("qt_rubberband") - && objectName != QLatin1String("qt_qmainwindow_extended_splitter")) { + // Exclude widgets used as implementation details + && objectName != "qt_rubberband"_L1 + && objectName != "qt_qmainwindow_extended_splitter"_L1 + && objectName != "qt_spinbox_lineedit"_L1) { widgets.append(w); } } @@ -127,7 +95,7 @@ QList<QWidget*> childWidgets(const QWidget *widget) QAccessiblePlainTextEdit::QAccessiblePlainTextEdit(QWidget* o) :QAccessibleTextWidget(o) { - Q_ASSERT(widget()->inherits("QPlainTextEdit")); + Q_ASSERT(qobject_cast<QPlainTextEdit *>(widget())); } QPlainTextEdit* QAccessiblePlainTextEdit::plainTextEdit() const @@ -224,7 +192,7 @@ void QAccessiblePlainTextEdit::scrollToSubstring(int startIndex, int endIndex) QAccessibleTextEdit::QAccessibleTextEdit(QWidget *o) : QAccessibleTextWidget(o, QAccessible::EditableText) { - Q_ASSERT(widget()->inherits("QTextEdit")); + Q_ASSERT(qobject_cast<QTextEdit *>(widget())); } /*! Returns the text edit. */ @@ -393,7 +361,7 @@ QAccessibleMdiArea::QAccessibleMdiArea(QWidget *widget) int QAccessibleMdiArea::childCount() const { - return mdiArea()->subWindowList().count(); + return mdiArea()->subWindowList().size(); } QAccessibleInterface *QAccessibleMdiArea::child(int index) const @@ -432,7 +400,7 @@ QString QAccessibleMdiSubWindow::text(QAccessible::Text textType) const { if (textType == QAccessible::Name) { QString title = mdiSubWindow()->windowTitle(); - title.replace(QLatin1String("[*]"), QLatin1String("")); + title.remove("[*]"_L1); return title; } return QAccessibleWidget::text(textType); @@ -570,7 +538,7 @@ QCalendarWidget *QAccessibleCalendarWidget::calendarWidget() const QAbstractItemView *QAccessibleCalendarWidget::calendarView() const { for (QObject *child : calendarWidget()->children()) { - if (child->objectName() == QLatin1String("qt_calendar_calendarview")) + if (child->objectName() == "qt_calendar_calendarview"_L1) return static_cast<QAbstractItemView *>(child); } return nullptr; @@ -579,7 +547,7 @@ QAbstractItemView *QAccessibleCalendarWidget::calendarView() const QWidget *QAccessibleCalendarWidget::navigationBar() const { for (QObject *child : calendarWidget()->children()) { - if (child->objectName() == QLatin1String("qt_calendar_navigationbar")) + if (child->objectName() == "qt_calendar_navigationbar"_L1) return static_cast<QWidget *>(child); } return nullptr; @@ -761,7 +729,7 @@ class AttributeFormatterRef { public: template <typename RHS> void operator=(RHS &&rhs) - { string += QLatin1String(key) + QLatin1Char(':') + std::forward<RHS>(rhs) + QLatin1Char(';'); } + { string += QLatin1StringView(key) + u':' + std::forward<RHS>(rhs) + u';'; } }; /*! @@ -769,7 +737,7 @@ public: \brief Small string-builder class that supports a map-like API to serialize key-value pairs. \code AttributeFormatter attrs; - attrs["foo"] = QLatinString("hello") + world + QLatin1Char('!'); + attrs["foo"] = QLatinString("hello") + world + u'!'; \endcode The key type is always \c{const char*}, and the right-hand-side can be any QStringBuilder expression. @@ -852,13 +820,13 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end AttributeFormatter attrs; QString family = charFormatFont.families().value(0, QString()); if (!family.isEmpty()) { - family = family.replace(u'\\', QLatin1String("\\\\")); - family = family.replace(u':', QLatin1String("\\:")); - family = family.replace(u',', QLatin1String("\\,")); - family = family.replace(u'=', QLatin1String("\\=")); - family = family.replace(u';', QLatin1String("\\;")); - family = family.replace(u'\"', QLatin1String("\\\"")); - attrs["font-family"] = QLatin1Char('"') + family + QLatin1Char('"'); + family = family.replace(u'\\', "\\\\"_L1); + family = family.replace(u':', "\\:"_L1); + family = family.replace(u',', "\\,"_L1); + family = family.replace(u'=', "\\="_L1); + family = family.replace(u';', "\\;"_L1); + family = family.replace(u'\"', "\\\""_L1); + attrs["font-family"] = u'"' + family + u'"'; } int fontSize = int(charFormatFont.pointSize()); @@ -871,6 +839,8 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end QFont::Style style = charFormatFont.style(); attrs["font-style"] = QString::fromLatin1((style == QFont::StyleItalic) ? "italic" : ((style == QFont::StyleOblique) ? "oblique": "normal")); + attrs["text-line-through-type"] = charFormatFont.strikeOut() ? "single"_L1 : "none"_L1; + QTextCharFormat::UnderlineStyle underlineStyle = charFormat.underlineStyle(); if (underlineStyle == QTextCharFormat::NoUnderline && charFormatFont.underline()) // underline could still be set in the default font underlineStyle = QTextCharFormat::SingleUnderline; @@ -900,7 +870,7 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end underlineStyleValue = QStringLiteral("wave"); // this is not correct, but provides good approximation at least break; default: - qWarning() << "Unknown QTextCharFormat::​UnderlineStyle value " << underlineStyle << " could not be translated to IAccessible2 value"; + qWarning() << "Unknown QTextCharFormat::UnderlineStyle value " << underlineStyle << " could not be translated to IAccessible2 value"; break; } if (!underlineStyleValue.isNull()) { @@ -966,7 +936,7 @@ QString QAccessibleTextWidget::text(int startOffset, int endOffset) const cursor.setPosition(startOffset, QTextCursor::MoveAnchor); cursor.setPosition(endOffset, QTextCursor::KeepAnchor); - return cursor.selectedText().replace(QChar(QChar::ParagraphSeparator), QLatin1Char('\n')); + return cursor.selectedText().replace(QChar(QChar::ParagraphSeparator), u'\n'); } QPoint QAccessibleTextWidget::scrollBarPosition() const @@ -1105,8 +1075,8 @@ QAccessibleMainWindow::QAccessibleMainWindow(QWidget *widget) QAccessibleInterface *QAccessibleMainWindow::child(int index) const { - QList<QWidget*> kids = childWidgets(mainWindow()); - if (index >= 0 && index < kids.count()) { + QList<QWidget*> kids = _q_ac_childWidgets(mainWindow()); + if (index >= 0 && index < kids.size()) { return QAccessible::queryAccessibleInterface(kids.at(index)); } return nullptr; @@ -1114,13 +1084,13 @@ QAccessibleInterface *QAccessibleMainWindow::child(int index) const int QAccessibleMainWindow::childCount() const { - QList<QWidget*> kids = childWidgets(mainWindow()); - return kids.count(); + QList<QWidget*> kids = _q_ac_childWidgets(mainWindow()); + return kids.size(); } int QAccessibleMainWindow::indexOfChild(const QAccessibleInterface *iface) const { - QList<QWidget*> kids = childWidgets(mainWindow()); + QList<QWidget*> kids = _q_ac_childWidgets(mainWindow()); return kids.indexOf(static_cast<QWidget*>(iface->object())); } @@ -1133,7 +1103,7 @@ QAccessibleInterface *QAccessibleMainWindow::childAt(int x, int y) const if (!QRect(gp.x(), gp.y(), w->width(), w->height()).contains(x, y)) return nullptr; - const QWidgetList kids = childWidgets(mainWindow()); + const QWidgetList kids = _q_ac_childWidgets(mainWindow()); QPoint rp = mainWindow()->mapFromGlobal(QPoint(x, y)); for (QWidget *child : kids) { if (!child->isWindow() && !child->isHidden() && child->geometry().contains(rp)) { @@ -1152,4 +1122,4 @@ QMainWindow *QAccessibleMainWindow::mainWindow() const QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) diff --git a/src/widgets/accessible/qaccessiblewidgets_p.h b/src/widgets/accessible/qaccessiblewidgets_p.h index 87f0b888a0..6d06f294e8 100644 --- a/src/widgets/accessible/qaccessiblewidgets_p.h +++ b/src/widgets/accessible/qaccessiblewidgets_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QACCESSIBLEWIDGETS_H #define QACCESSIBLEWIDGETS_H @@ -54,10 +18,9 @@ #include <QtWidgets/private/qtwidgetsglobal_p.h> #include <QtWidgets/qaccessiblewidget.h> -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) #include <QtCore/QPointer> -#include <QtCore/QPair> QT_BEGIN_NAMESPACE @@ -319,7 +282,7 @@ public: }; #endif // QT_CONFIG(mainwindow) -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/rangecontrols.cpp b/src/widgets/accessible/rangecontrols.cpp index 6c12b553b4..b172c10044 100644 --- a/src/widgets/accessible/rangecontrols.cpp +++ b/src/widgets/accessible/rangecontrols.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "rangecontrols_p.h" @@ -65,7 +29,9 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +using namespace Qt::StringLiterals; + +#if QT_CONFIG(accessibility) #if QT_CONFIG(spinbox) QAccessibleAbstractSpinBox::QAccessibleAbstractSpinBox(QWidget *w) @@ -253,7 +219,7 @@ QAccessibleSpinBox::QAccessibleSpinBox(QWidget *w) : QAccessibleAbstractSpinBox(w) { Q_ASSERT(spinBox()); - addControllingSignal(QLatin1String("valueChanged(int)")); + addControllingSignal("valueChanged(int)"_L1); } /*! @@ -270,7 +236,7 @@ QAccessibleDoubleSpinBox::QAccessibleDoubleSpinBox(QWidget *widget) : QAccessibleAbstractSpinBox(widget) { Q_ASSERT(qobject_cast<QDoubleSpinBox *>(widget)); - addControllingSignal(QLatin1String("valueChanged(double)")); + addControllingSignal("valueChanged(double)"_L1); } /*! @@ -307,7 +273,7 @@ QAccessibleScrollBar::QAccessibleScrollBar(QWidget *w) : QAccessibleAbstractSlider(w, QAccessible::ScrollBar) { Q_ASSERT(scrollBar()); - addControllingSignal(QLatin1String("valueChanged(int)")); + addControllingSignal("valueChanged(int)"_L1); } /*! Returns the scroll bar. */ @@ -342,7 +308,7 @@ QAccessibleSlider::QAccessibleSlider(QWidget *w) : QAccessibleAbstractSlider(w) { Q_ASSERT(slider()); - addControllingSignal(QLatin1String("valueChanged(int)")); + addControllingSignal("valueChanged(int)"_L1); } /*! Returns the slider. */ @@ -410,7 +376,7 @@ QAccessibleDial::QAccessibleDial(QWidget *widget) : QAccessibleAbstractSlider(widget, QAccessible::Dial) { Q_ASSERT(qobject_cast<QDial *>(widget)); - addControllingSignal(QLatin1String("valueChanged(int)")); + addControllingSignal("valueChanged(int)"_L1); } QString QAccessibleDial::text(QAccessible::Text textType) const @@ -427,6 +393,6 @@ QDial *QAccessibleDial::dial() const } #endif // QT_CONFIG(dial) -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/rangecontrols_p.h b/src/widgets/accessible/rangecontrols_p.h index 1eada8e456..162cbbdb34 100644 --- a/src/widgets/accessible/rangecontrols_p.h +++ b/src/widgets/accessible/rangecontrols_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef RANGECONTROLS_H #define RANGECONTROLS_H @@ -56,7 +20,7 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) class QAbstractSpinBox; class QAbstractSlider; @@ -199,7 +163,7 @@ protected: }; #endif // QT_CONFIG(dial) -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index 3ecd938039..fbbbab857d 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "simplewidgets_p.h" @@ -79,6 +43,9 @@ #ifndef QT_NO_PICTURE #include <QtGui/qpicture.h> #endif +#if QT_CONFIG(messagebox) +#include <qmessagebox.h> +#endif #include <qstyle.h> #include <qstyleoption.h> #include <qtextdocument.h> @@ -93,9 +60,11 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +using namespace Qt::StringLiterals; + +#if QT_CONFIG(accessibility) -extern QList<QWidget*> childWidgets(const QWidget *widget); +QWidgetList _q_ac_childWidgets(const QWidget *widget); QString qt_accStripAmp(const QString &text); QString qt_accHotKey(const QString &text); @@ -120,9 +89,9 @@ QAccessibleButton::QAccessibleButton(QWidget *w) // FIXME: The checkable state of the button is dynamic, // while we only update the controlling signal once :( if (button()->isCheckable()) - addControllingSignal(QLatin1String("toggled(bool)")); + addControllingSignal("toggled(bool)"_L1); else - addControllingSignal(QLatin1String("clicked()")); + addControllingSignal("clicked()"_L1); } /*! Returns the button. */ @@ -247,11 +216,9 @@ QStringList QAccessibleButton::actionNames() const names << toggleAction(); break; default: - if (button()->isCheckable()) { + if (button()->isCheckable()) names << toggleAction(); - } else { - names << pressAction(); - } + names << pressAction(); break; } } @@ -434,10 +401,10 @@ QAccessible::Role QAccessibleDisplay::role() const #if QT_CONFIG(label) QLabel *l = qobject_cast<QLabel*>(object()); if (l) { - if (!l->pixmap(Qt::ReturnByValue).isNull()) + if (!l->pixmap().isNull()) return QAccessible::Graphic; #ifndef QT_NO_PICTURE - if (!l->picture(Qt::ReturnByValue).isNull()) + if (!l->picture().isNull()) return QAccessible::Graphic; #endif #if QT_CONFIG(movie) @@ -562,7 +529,7 @@ QSize QAccessibleDisplay::imageSize() const #endif return QSize(); #if QT_CONFIG(label) - return label->pixmap(Qt::ReturnByValue).size(); + return label->pixmap().size(); #endif } @@ -575,7 +542,7 @@ QPoint QAccessibleDisplay::imagePosition() const #endif return QPoint(); #if QT_CONFIG(label) - if (label->pixmap(Qt::ReturnByValue).isNull()) + if (label->pixmap().isNull()) return QPoint(); return QPoint(label->mapToGlobal(label->pos())); @@ -638,7 +605,7 @@ QAccessibleGroupBox::relations(QAccessible::Relation match /* = QAccessible::All QAccessibleWidget::relations(match); if ((match & QAccessible::Labelled) && (!groupBox()->title().isEmpty())) { - const QList<QWidget*> kids = childWidgets(widget()); + const QList<QWidget*> kids = _q_ac_childWidgets(widget()); for (QWidget *kid : kids) { QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(kid); if (iface) @@ -687,8 +654,8 @@ QStringList QAccessibleGroupBox::keyBindingsForAction(const QString &) const QAccessibleLineEdit::QAccessibleLineEdit(QWidget *w, const QString &name) : QAccessibleWidget(w, QAccessible::EditableText, name) { - addControllingSignal(QLatin1String("textChanged(const QString&)")); - addControllingSignal(QLatin1String("returnPressed()")); + addControllingSignal("textChanged(const QString&)"_L1); + addControllingSignal("returnPressed()"_L1); } /*! Returns the line edit. */ @@ -705,7 +672,7 @@ QString QAccessibleLineEdit::text(QAccessible::Text t) const if (lineEdit()->echoMode() == QLineEdit::Normal) str = lineEdit()->text(); else if (lineEdit()->echoMode() != QLineEdit::NoEcho) - str = QString(lineEdit()->text().length(), QChar::fromLatin1('*')); + str = QString(lineEdit()->text().size(), QChar::fromLatin1('*')); break; default: break; @@ -811,7 +778,7 @@ void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *e return; *startOffset = lineEdit()->selectionStart(); - *endOffset = *startOffset + lineEdit()->selectedText().count(); + *endOffset = *startOffset + lineEdit()->selectedText().size(); } QString QAccessibleLineEdit::text(int startOffset, int endOffset) const @@ -884,7 +851,7 @@ void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int int QAccessibleLineEdit::characterCount() const { - return lineEdit()->text().count(); + return lineEdit()->text().size(); } void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex) @@ -985,6 +952,49 @@ QWindowContainer *QAccessibleWindowContainer::container() const return static_cast<QWindowContainer *>(widget()); } -#endif // QT_NO_ACCESSIBILITY +#if QT_CONFIG(messagebox) +/*! + \internal + Implements QAccessibleWidget for QMessageBox +*/ +QAccessibleMessageBox::QAccessibleMessageBox(QWidget *widget) + : QAccessibleWidget(widget, QAccessible::AlertMessage) +{ + Q_ASSERT(qobject_cast<QMessageBox *>(widget)); +} + +QMessageBox *QAccessibleMessageBox::messageBox() const +{ + return static_cast<QMessageBox *>(widget()); +} + +QString QAccessibleMessageBox::text(QAccessible::Text t) const +{ + QString str; + + switch (t) { + case QAccessible::Name: + str = QAccessibleWidget::text(t); + if (str.isEmpty()) // implies no title text is set + str = messageBox()->text(); + break; + case QAccessible::Description: + str = widget()->accessibleDescription(); + break; + case QAccessible::Value: + str = messageBox()->text(); + break; + case QAccessible::Help: + str = messageBox()->informativeText(); + break; + default: + break; + } + + return str; +} +#endif + +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE diff --git a/src/widgets/accessible/simplewidgets_p.h b/src/widgets/accessible/simplewidgets_p.h index dd1631d6a5..c9c03b00d8 100644 --- a/src/widgets/accessible/simplewidgets_p.h +++ b/src/widgets/accessible/simplewidgets_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef SIMPLEWIDGETS_H #define SIMPLEWIDGETS_H @@ -57,12 +21,13 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) class QAbstractButton; class QLineEdit; class QToolButton; class QGroupBox; +class QMessageBox; class QProgressBar; #if QT_CONFIG(abstractbutton) @@ -225,7 +190,19 @@ private: QWindowContainer *container() const; }; -#endif // QT_NO_ACCESSIBILITY +#if QT_CONFIG(messagebox) +class QAccessibleMessageBox : public QAccessibleWidget +{ +public: + explicit QAccessibleMessageBox(QWidget *widget); + + QString text(QAccessible::Text t) const override; + + QMessageBox *messageBox() const; +}; +#endif + +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE |