From dc01e88c01bf5eab7ed71ac721fa94519aa12e4f Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Thu, 29 Jun 2023 09:48:53 +0000 Subject: [PATCH] FIX(a11y): Improve accessibility of configuration dialog --- src/mumble/ConfigDialog.cpp | 135 ++++++++++++++++++++++++++++++++++++ src/mumble/ConfigDialog.h | 2 + 2 files changed, 137 insertions(+) diff --git a/src/mumble/ConfigDialog.cpp b/src/mumble/ConfigDialog.cpp index 9572cd36756..7c336aea992 100644 --- a/src/mumble/ConfigDialog.cpp +++ b/src/mumble/ConfigDialog.cpp @@ -13,9 +13,12 @@ #include #include #include +#include #include #include +#include + // init static member fields QMutex ConfigDialog::s_existingWidgetsMutex; @@ -77,6 +80,7 @@ ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) { QPushButton *restoreAllButton = pageButtonBox->addButton(tr("Defaults (All)"), QDialogButtonBox::ResetRole); restoreAllButton->setToolTip(tr("Restore all defaults")); restoreAllButton->setWhatsThis(tr("This button will restore the defaults for all settings.")); + restoreAllButton->setFocusPolicy(Qt::NoFocus); if (!Global::get().s.qbaConfigGeometry.isEmpty()) { #ifdef USE_OVERLAY @@ -84,6 +88,9 @@ ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) { #endif restoreGeometry(Global::get().s.qbaConfigGeometry); } + + updateTabOrder(); + qlwIcons->setFocus(); } void ConfigDialog::addPage(ConfigWidget *cw, unsigned int idx) { @@ -109,6 +116,7 @@ void ConfigDialog::addPage(ConfigWidget *cw, unsigned int idx) { qsa->setFrameShape(QFrame::NoFrame); qsa->setWidgetResizable(true); qsa->setWidget(cw); + qsa->setFocusPolicy(Qt::NoFocus); qhPages.insert(cw, qsa); qswPages->addWidget(qsa); } else { @@ -196,7 +204,134 @@ void ConfigDialog::on_qlwIcons_currentItemChanged(QListWidgetItem *current, QLis QWidget *w = qhPages.value(qmIconWidgets.value(current)); if (w) qswPages->setCurrentWidget(w); + + updateTabOrder(); + } +} + +void ConfigDialog::updateTabOrder() { + QPushButton *okButton = dialogButtonBox->button(QDialogButtonBox::Ok); + QPushButton *cancelButton = dialogButtonBox->button(QDialogButtonBox::Cancel); + QPushButton *applyButton = dialogButtonBox->button(QDialogButtonBox::Apply); + QPushButton *resetButton = pageButtonBox->button(QDialogButtonBox::Reset); + QPushButton *restoreButton = pageButtonBox->button(QDialogButtonBox::RestoreDefaults); + + QWidget *contentFocusWidget = qswPages; + + ConfigWidget *page; + QScrollArea *qsa = qobject_cast< QScrollArea * >(qswPages->currentWidget()); + if (qsa) { + page = qobject_cast< ConfigWidget * >(qsa->widget()); + } else { + page = qobject_cast< ConfigWidget * >(qswPages->currentWidget()); + } + + if (page) { + contentFocusWidget = page; + /* + if (contentFocusWidget->nextInFocusChain()) { + contentFocusWidget = contentFocusWidget->nextInFocusChain(); + } + while (contentFocusWidget + && (qobject_cast< QGroupBox * >(contentFocusWidget) || contentFocusWidget->focusPolicy() == Qt::NoFocus) + && contentFocusWidget->nextInFocusChain()) { + contentFocusWidget = contentFocusWidget->nextInFocusChain(); + }*/ + } + + if (contentFocusWidget) { + qDebug() << contentFocusWidget->accessibleName() << " " << contentFocusWidget->metaObject()->className(); + } else { + qDebug() << "No contentFocusWidget"; + } + + qDebug() << "page is: " << qswPages->currentWidget()->accessibleName() << " " + << qswPages->currentWidget()->metaObject()->className(); + + setTabOrder(cancelButton, okButton); + setTabOrder(okButton, qlwIcons); + setTabOrder(qlwIcons, contentFocusWidget); + setTabOrder(qswPages->currentWidget(), resetButton); + if (restoreButton) { + setTabOrder(resetButton, restoreButton); + setTabOrder(restoreButton, applyButton); + } else { + setTabOrder(resetButton, applyButton); + } + setTabOrder(applyButton, cancelButton); + + if (resetButton && resetButton->previousInFocusChain()) { + qDebug() << "previous reset is: " << resetButton->previousInFocusChain()->accessibleName() << " " + << resetButton->previousInFocusChain()->metaObject()->className(); + + QAbstractButton *button = qobject_cast< QAbstractButton * >(resetButton->previousInFocusChain()); + if(button){ + qDebug() << button->text(); + } + } else { + qDebug() << "previous reset is nullptr"; + } + + if (resetButton && resetButton->nextInFocusChain()) { + qDebug() << "after reset is: " << resetButton->nextInFocusChain()->accessibleName() << " " + << resetButton->nextInFocusChain()->metaObject()->className(); + + QAbstractButton *button = qobject_cast< QAbstractButton * >(resetButton->nextInFocusChain()); + if(button){ + qDebug() << button->text(); + } + } else { + qDebug() << "After reset is nullptr"; } + + if (restoreButton && restoreButton->previousInFocusChain()) { + qDebug() << "previous restore is: " << restoreButton->previousInFocusChain()->accessibleName() << " " + << restoreButton->previousInFocusChain()->metaObject()->className(); + + QAbstractButton *button = qobject_cast< QAbstractButton * >(restoreButton->previousInFocusChain()); + if(button){ + qDebug() << button->text(); + } + } else { + qDebug() << "previous restore is nullptr"; + } + + if (restoreButton && restoreButton->nextInFocusChain()) { + qDebug() << "after defaults is: " << restoreButton->nextInFocusChain()->accessibleName() << " " + << restoreButton->nextInFocusChain()->metaObject()->className(); + + QAbstractButton *button = qobject_cast< QAbstractButton * >(restoreButton->nextInFocusChain()); + if(button){ + qDebug() << button->text(); + } + } else { + qDebug() << "After restore is nullptr"; + } + + if (applyButton && applyButton->previousInFocusChain()) { + qDebug() << "previous apply is: " << applyButton->previousInFocusChain()->accessibleName() << " " + << applyButton->previousInFocusChain()->metaObject()->className(); + + QAbstractButton *button = qobject_cast< QAbstractButton * >(applyButton->previousInFocusChain()); + if(button){ + qDebug() << button->text(); + } + } else { + qDebug() << "previous apply is nullptr"; + } + + if (applyButton && applyButton->nextInFocusChain()) { + qDebug() << "after apply is: " << applyButton->nextInFocusChain()->accessibleName() << " " + << applyButton->nextInFocusChain()->metaObject()->className(); + + QAbstractButton *button = qobject_cast< QAbstractButton * >(applyButton->nextInFocusChain()); + if(button){ + qDebug() << button->text(); + } + } else { + qDebug() << "After apply is nullptr"; + } + } void ConfigDialog::updateListView() { diff --git a/src/mumble/ConfigDialog.h b/src/mumble/ConfigDialog.h index 4fdd7202731..b0196e48367 100644 --- a/src/mumble/ConfigDialog.h +++ b/src/mumble/ConfigDialog.h @@ -17,6 +17,8 @@ class ConfigDialog : public QDialog, public Ui::ConfigDialog { private: Q_OBJECT Q_DISABLE_COPY(ConfigDialog) + + void updateTabOrder(); protected: static QMutex s_existingWidgetsMutex; static QHash< QString, ConfigWidget * > s_existingWidgets;