Skip to content

Commit

Permalink
FIX(a11y): Make search result tree accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jan 8, 2024
1 parent a3f9ae5 commit 73eb7c5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/mumble/SearchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "SearchDialog.h"
#include "Accessibility.h"
#include "Channel.h"
#include "ClientUser.h"
#include "MainWindow.h"
Expand All @@ -26,6 +27,8 @@

#include <stack>

#include <QDebug>

namespace Search {

QString SearchDialog::toString(UserAction action) {
Expand Down Expand Up @@ -245,6 +248,31 @@ void SearchDialog::on_searchResultTree_itemActivated(QTreeWidgetItem *item, int)
}
}

void SearchDialog::on_searchResultTree_itemChanged(QTreeWidgetItem *c, int column) {
if (!c || column != 0 || Global::get().uiSession == 0) {
return;
}

SearchResultItem &item = static_cast< SearchResultItem & >(*c);
if (item.getResult().type == SearchType::User) {
const ClientUser *user = ClientUser::get(item.getID());

if (user) {
item.setData(1, Qt::AccessibleTextRole, Mumble::Accessibility::userToText(user));
item.setData(1, Qt::AccessibleDescriptionRole, Mumble::Accessibility::userToText(user));
qDebug() << Mumble::Accessibility::userToText(user);
}
} else {
const Channel *channel = Channel::get(static_cast< int >(item.getID()));

if (channel) {
item.setData(1, Qt::AccessibleTextRole, Mumble::Accessibility::channelToText(channel));
item.setData(1, Qt::AccessibleDescriptionRole, Mumble::Accessibility::channelToText(channel));
qDebug() << Mumble::Accessibility::channelToText(channel);
}
}
}

void SearchDialog::searchAgain() {
search(searchField->text());
}
Expand Down
1 change: 1 addition & 0 deletions src/mumble/SearchDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public slots:
void on_regexOption_clicked(bool checked);
void on_searchResultTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_searchResultTree_itemActivated(QTreeWidgetItem *item, int column);
void on_searchResultTree_itemChanged(QTreeWidgetItem *item, int column);
void searchAgain();
void clearSearchResults();
void search(const QString &searchTerm);
Expand Down
3 changes: 3 additions & 0 deletions src/mumble/SearchDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
</item>
<item row="2" column="0" colspan="2">
<widget class="SearchDialogTree" name="searchResultTree">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Search results</string>
</property>
Expand Down
13 changes: 13 additions & 0 deletions src/mumble/widgets/SearchDialogTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "SearchDialogTree.h"

#include <QResizeEvent>
#include <QDebug>

void SearchDialogTree::resizeEvent(QResizeEvent *event) {
// We have to update the layout on every resize since we have wrapping text that is displayed in the
Expand All @@ -17,3 +18,15 @@ void SearchDialogTree::resizeEvent(QResizeEvent *event) {

scheduleDelayedItemsLayout();
}

QModelIndex SearchDialogTree::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) {
QModelIndex mi = QTreeWidget::moveCursor(cursorAction, modifiers);

if (cursorAction == QAbstractItemView::MoveUp || cursorAction == QAbstractItemView::MoveDown) {
mi = model()->index(mi.row(), 1);
}

qDebug() << mi;

return mi;
}
4 changes: 4 additions & 0 deletions src/mumble/widgets/SearchDialogTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#define MUMBLE_MUMBLE_WIDGETS_SEARCHDIALOGTREE_H_

#include <QTreeWidget>
#include <QAbstractItemView>
#include <QModelIndex>

class QResizeEvent;

class SearchDialogTree : public QTreeWidget {
public:
using QTreeWidget::QTreeWidget;

QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;

protected:
void resizeEvent(QResizeEvent *event) override;
};
Expand Down

0 comments on commit 73eb7c5

Please sign in to comment.