diff options
Diffstat (limited to 'src/widgets/accessible/qaccessiblewidget.cpp')
-rw-r--r-- | src/widgets/accessible/qaccessiblewidget.cpp | 140 |
1 files changed, 40 insertions, 100 deletions
diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index c96d213e7b..b0bb12ea86 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -1,47 +1,10 @@ -/**************************************************************************** -** -** 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 "qaction.h" #include "qapplication.h" #if QT_CONFIG(groupbox) #include "qgroupbox.h" @@ -49,7 +12,9 @@ #if QT_CONFIG(label) #include "qlabel.h" #endif +#if QT_CONFIG(tooltip) #include "qtooltip.h" +#endif #if QT_CONFIG(whatsthis) #include "qwhatsthis.h" #endif @@ -67,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) { @@ -111,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; @@ -143,21 +95,21 @@ 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 - Q_UNUSED(text) + Q_UNUSED(text); #endif return QString(); @@ -273,22 +225,6 @@ QRect QAccessibleWidget::rect() const return QRect(wpos.x(), wpos.y(), w->width(), w->height()); } -QT_BEGIN_INCLUDE_NAMESPACE -#include <private/qobject_p.h> -QT_END_INCLUDE_NAMESPACE - -class QACConnectionObject : public QObject -{ - Q_DECLARE_PRIVATE(QObject) -public: - inline bool isSender(const QObject *receiver, const char *signal) const - { return d_func()->isSender(receiver, signal); } - inline QObjectList receiverList(const char *signal) const - { return d_func()->receiverList(signal); } - inline QObjectList senderList() const - { return d_func()->senderList(); } -}; - /*! Registers \a signal as a controlling signal. @@ -300,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) @@ -314,10 +250,10 @@ static inline bool isAncestor(const QObject *obj, const QObject *child) } /*! \reimp */ -QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > +QList<QPair<QAccessibleInterface *, QAccessible::Relation>> QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRelations*/) const { - QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels; + QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels; if (match & QAccessible::Label) { const QAccessible::Relation rel = QAccessible::Label; if (QWidget *parent = widget()->parentWidget()) { @@ -325,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()) { @@ -347,15 +283,15 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel if (match & QAccessible::Controlled) { QObjectList allReceivers; - QACConnectionObject *connectionObject = (QACConnectionObject*)object(); - for (int sig = 0; sig < d->primarySignals.count(); ++sig) { - const QObjectList receivers = connectionObject->receiverList(d->primarySignals.at(sig).toLatin1()); + QObject *connectionObject = object(); + 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) @@ -376,10 +312,10 @@ 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 0; + return nullptr; } /*! \reimp */ @@ -390,17 +326,21 @@ QAccessibleInterface *QAccessibleWidget::focusChild() const QWidget *fw = widget()->focusWidget(); if (!fw) - return 0; + return nullptr; - if (isAncestor(widget(), fw) || fw == widget()) - return QAccessible::queryAccessibleInterface(fw); - return 0; + if (isAncestor(widget(), fw)) { + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(fw); + if (!iface || iface == this || !iface->focusChild()) + return iface; + return iface->focusChild(); + } + return nullptr; } /*! \reimp */ int QAccessibleWidget::childCount() const { - QWidgetList cl = childWidgets(widget()); + QWidgetList cl = _q_ac_childWidgets(widget()); return cl.size(); } @@ -409,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())); } @@ -438,7 +378,7 @@ QString QAccessibleWidget::text(QAccessible::Text t) const break; case QAccessible::Description: str = widget()->accessibleDescription(); -#ifndef QT_NO_TOOLTIP +#if QT_CONFIG(tooltip) if (str.isEmpty()) str = widget()->toolTip(); #endif @@ -538,9 +478,9 @@ void *QAccessibleWidget::interface_cast(QAccessible::InterfaceType t) { if (t == QAccessible::ActionInterface) return static_cast<QAccessibleActionInterface*>(this); - return 0; + return nullptr; } QT_END_NAMESPACE -#endif //QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) |