Skip to content

Commit

Permalink
FIX(a11y): Make global shortcut settings more accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jan 10, 2024
1 parent 158f141 commit 9935fe3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 20 deletions.
79 changes: 61 additions & 18 deletions src/mumble/GlobalShortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <cassert>

#include <QDebug>

const QString GlobalShortcutConfig::name = QLatin1String("GlobalShortcutConfig");

/**
Expand All @@ -43,43 +45,67 @@ static ConfigRegistrar registrarGlobalShortcut(1200, GlobalShortcutConfigDialogN

static const QString UPARROW = QString::fromUtf8("\xE2\x86\x91 ");

ShortcutActionWidget::ShortcutActionWidget(QWidget *p) : MUComboBox(p) {
ShortcutActionWidget::ShortcutActionWidget(QWidget *p) : QWidget(p), m_comboBox(new MUComboBox()) {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_comboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

//QHBoxLayout *layout = new QHBoxLayout();
//layout->setSpacing(0);
//layout->setContentsMargins(0, 0, 0, 0);
//layout->setSizeConstraint(QLayout::SetNoConstraint);
//layout->addWidget(m_comboBox);
//setLayout(layout);
m_comboBox->setParent(this);

int idx = 0;

insertItem(idx, tr("Unassigned"));
setItemData(idx, -1);
m_comboBox->insertItem(idx, tr("Unassigned"));
m_comboBox->setItemData(idx, -1);
#ifndef Q_OS_MAC
setSizeAdjustPolicy(AdjustToContents);
m_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
#endif

idx++;

foreach (GlobalShortcut *gs, GlobalShortcutEngine::engine->qmShortcuts) {
insertItem(idx, gs->name);
setItemData(idx, gs->idx);
if (!gs->qsToolTip.isEmpty())
setItemData(idx, gs->qsToolTip, Qt::ToolTipRole);
if (!gs->qsWhatsThis.isEmpty())
setItemData(idx, gs->qsWhatsThis, Qt::WhatsThisRole);
m_comboBox->insertItem(idx, gs->name);
m_comboBox->setItemData(idx, gs->idx);
if (!gs->qsToolTip.isEmpty()) {
m_comboBox->setItemData(idx, gs->qsToolTip, Qt::ToolTipRole);
}
if (!gs->qsWhatsThis.isEmpty()) {
m_comboBox->setItemData(idx, gs->qsWhatsThis, Qt::WhatsThisRole);
}
idx++;
}

// Sort the ShortcutActionWidget items
QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
proxy->setSourceModel(model());
proxy->setSourceModel(m_comboBox->model());

model()->setParent(proxy);
setModel(proxy);
m_comboBox->model()->setParent(proxy);
m_comboBox->setModel(proxy);

model()->sort(0);
m_comboBox->model()->sort(0);

m_comboBox->setFocusPolicy(Qt::NoFocus);
m_comboBox->adjustSize();
adjustSize();

qDebug() << p->parentWidget();
QTreeWidget *treeWidget = qobject_cast< QTreeWidget *>(p->parentWidget());
if (treeWidget) {
qDebug() << "resize";
treeWidget->resizeColumnToContents(0);
}
}

void ShortcutActionWidget::setIndex(unsigned int idx) {
setCurrentIndex(findData(idx));
m_comboBox->setCurrentIndex(m_comboBox->findData(idx));
}

unsigned int ShortcutActionWidget::index() const {
return itemData(currentIndex()).toUInt();
return m_comboBox->itemData(m_comboBox->currentIndex()).toUInt();
}

ShortcutToggleWidget::ShortcutToggleWidget(QWidget *p) : MUComboBox(p) {
Expand Down Expand Up @@ -347,14 +373,16 @@ ShortcutTargetWidget::ShortcutTargetWidget(QWidget *p) : QFrame(p) {

qtbEdit = new QToolButton();
qtbEdit->setText(tr("..."));
qtbEdit->setFocusPolicy(Qt::ClickFocus);
qtbEdit->setFocusPolicy(Qt::TabFocus);
qtbEdit->setObjectName(QLatin1String("qtbEdit"));

QHBoxLayout *l = new QHBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->addWidget(qleTarget, 1);
l->addWidget(qtbEdit);

setFocusProxy(qtbEdit);

QMetaObject::connectSlotsByName(this);
}

Expand Down Expand Up @@ -556,11 +584,16 @@ GlobalShortcutConfig::GlobalShortcutConfig(Settings &st) : ConfigWidget(st) {
qtwShortcuts->setColumnCount(canSuppress ? 4 : 3);
qtwShortcuts->setItemDelegate(new ShortcutDelegate(qtwShortcuts));

qtwShortcuts->headerItem()->setData(0, Qt::AccessibleTextRole, tr("Shortcut action"));
qtwShortcuts->headerItem()->setData(1, Qt::AccessibleTextRole, tr("Shortcut data"));
qtwShortcuts->headerItem()->setData(2, Qt::AccessibleTextRole, tr("Shortcut input combinations"));

qtwShortcuts->header()->setSectionResizeMode(0, QHeaderView::Fixed);
qtwShortcuts->header()->resizeSection(0, 150);
qtwShortcuts->header()->setSectionResizeMode(2, QHeaderView::Stretch);
if (canSuppress)
if (canSuppress) {
qtwShortcuts->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
}

qcbEnableGlobalShortcuts->setVisible(canDisable);

Expand Down Expand Up @@ -705,6 +738,15 @@ void GlobalShortcutConfig::on_qtwShortcuts_itemChanged(QTreeWidgetItem *item, in
if (gs && sc.qvData.userType() != gs->qvDefault.userType()) {
item->setData(1, Qt::DisplayRole, gs->qvDefault);
}

if (gs) {
item->setData(0, Qt::AccessibleTextRole, gs->name);
} else {
item->setData(0, Qt::AccessibleTextRole, tr("Unassigned"));
}
item->setData(1, Qt::AccessibleTextRole, sc.qvData);
item->setData(3, Qt::AccessibleDescriptionRole,
item->checkState(3) == Qt::Checked ? tr("checked") : tr("unchecked"));
}

QString GlobalShortcutConfig::title() const {
Expand Down Expand Up @@ -811,6 +853,7 @@ void GlobalShortcutConfig::reload() {
foreach (const Shortcut &sc, qlShortcuts) {
QTreeWidgetItem *item = itemForShortcut(sc);
qtwShortcuts->addTopLevelItem(item);
on_qtwShortcuts_itemChanged(item, 0);
}
#ifdef Q_OS_MAC
if (!Global::get().s.bSuppressMacEventTapWarning) {
Expand Down
5 changes: 4 additions & 1 deletion src/mumble/GlobalShortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class GlobalShortcut : public QObject {
*
* @see GlobalShortcutEngine
*/
class ShortcutActionWidget : public MUComboBox {
class ShortcutActionWidget : public QWidget {
private:
Q_OBJECT
Q_DISABLE_COPY(ShortcutActionWidget)
Q_PROPERTY(unsigned int index READ index WRITE setIndex USER true)

MUComboBox *m_comboBox;

public:
ShortcutActionWidget(QWidget *p = nullptr);
unsigned int index() const;
Expand Down
12 changes: 11 additions & 1 deletion src/mumble/GlobalShortcut.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@
</widget>
</item>
<item>
<widget class="QTreeWidget" name="qtwShortcuts">
<widget class="MultiColumnTreeWidget" name="qtwShortcuts">
<property name="toolTip">
<string>List of configured shortcuts</string>
</property>
<property name="accessibleName">
<string>Configured shortcuts</string>
</property>
<property name="accessibleDescription">
<string>Use up and down keys to navigate through your added shortcuts. Use left and right keys to navigate between actions and options for a single shortcut.</string>
</property>
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
Expand Down Expand Up @@ -271,6 +274,13 @@ Without this option enabled, using Mumble's global shortcuts in privileged appli
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MultiColumnTreeWidget</class>
<extends>QTreeWidget</extends>
<header>widgets/MultiColumnTreeWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 9935fe3

Please sign in to comment.