diff options
Diffstat (limited to 'src/widgets/accessible/simplewidgets.cpp')
-rw-r--r-- | src/widgets/accessible/simplewidgets.cpp | 151 |
1 files changed, 81 insertions, 70 deletions
diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index ca74ee4b12..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" @@ -76,6 +40,12 @@ #include <qlineedit.h> #include <private/qlineedit_p.h> #endif +#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> @@ -90,9 +60,11 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ACCESSIBILITY +using namespace Qt::StringLiterals; -extern QList<QWidget*> childWidgets(const QWidget *widget); +#if QT_CONFIG(accessibility) + +QWidgetList _q_ac_childWidgets(const QWidget *widget); QString qt_accStripAmp(const QString &text); QString qt_accHotKey(const QString &text); @@ -117,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. */ @@ -244,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; } } @@ -362,9 +332,9 @@ QAccessibleInterface *QAccessibleToolButton::child(int index) const return QAccessible::queryAccessibleInterface(toolButton()->menu()); } #else - Q_UNUSED(index) + Q_UNUSED(index); #endif - return 0; + return nullptr; } /* @@ -431,10 +401,10 @@ QAccessible::Role QAccessibleDisplay::role() const #if QT_CONFIG(label) QLabel *l = qobject_cast<QLabel*>(object()); if (l) { - if (l->pixmap()) + if (!l->pixmap().isNull()) return QAccessible::Graphic; #ifndef QT_NO_PICTURE - if (l->picture()) + if (!l->picture().isNull()) return QAccessible::Graphic; #endif #if QT_CONFIG(movie) @@ -516,11 +486,12 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const } /*! \reimp */ -QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > +QList<QPair<QAccessibleInterface *, QAccessible::Relation>> QAccessibleDisplay::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const { - QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match); -#if QT_CONFIG(shortcut) && QT_CONFIG(label) + QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels = + QAccessibleWidget::relations(match); +# if QT_CONFIG(shortcut) && QT_CONFIG(label) if (match & QAccessible::Labelled) { if (QLabel *label = qobject_cast<QLabel*>(object())) { const QAccessible::Relation rel = QAccessible::Labelled; @@ -542,7 +513,7 @@ void *QAccessibleDisplay::interface_cast(QAccessible::InterfaceType t) /*! \internal */ QString QAccessibleDisplay::imageDescription() const { -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) return widget()->toolTip(); #else return QString(); @@ -558,10 +529,7 @@ QSize QAccessibleDisplay::imageSize() const #endif return QSize(); #if QT_CONFIG(label) - const QPixmap *pixmap = label->pixmap(); - if (!pixmap) - return QSize(); - return pixmap->size(); + return label->pixmap().size(); #endif } @@ -574,8 +542,7 @@ QPoint QAccessibleDisplay::imagePosition() const #endif return QPoint(); #if QT_CONFIG(label) - const QPixmap *pixmap = label->pixmap(); - if (!pixmap) + if (label->pixmap().isNull()) return QPoint(); return QPoint(label->mapToGlobal(label->pos())); @@ -631,13 +598,14 @@ QAccessible::Role QAccessibleGroupBox::role() const return groupBox()->isCheckable() ? QAccessible::CheckBox : QAccessible::Grouping; } -QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > +QList<QPair<QAccessibleInterface *, QAccessible::Relation>> QAccessibleGroupBox::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const { - QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match); + QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels = + 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) @@ -686,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. */ @@ -704,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; @@ -810,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 @@ -883,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) @@ -976,7 +944,7 @@ QAccessibleInterface *QAccessibleWindowContainer::child(int i) const { if (i == 0) return QAccessible::queryAccessibleInterface(container()->containedWindow()); - return 0; + return nullptr; } QWindowContainer *QAccessibleWindowContainer::container() const @@ -984,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 |