From 78df31e45cf9f6c90a82c2a9265b2e3bb509570d Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 25 Nov 2013 10:54:03 +0000 Subject: When in screen-reader mode, change the text used in rosters to include more information. Change-Id: I8807b2ce6d36dbce510a185f0e4e2c549c623225 diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index f9d3dd0..91e9a33 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -34,7 +34,7 @@ namespace Swift { QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent), tooltipShown_(false) { eventStream_ = eventStream; settings_ = settings; - model_ = new RosterModel(this); + model_ = new RosterModel(this, settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)); setModel(model_); delegate_ = new RosterDelegate(this, settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); setItemDelegate(delegate_); diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp index 16c6d7e..a5341fe 100644 --- a/Swift/QtUI/Roster/RosterModel.cpp +++ b/Swift/QtUI/Roster/RosterModel.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -26,7 +27,7 @@ namespace Swift { -RosterModel::RosterModel(QtTreeWidget* view) : roster_(NULL), view_(view) { +RosterModel::RosterModel(QtTreeWidget* view, bool screenReaderMode) : roster_(NULL), view_(view), screenReader_(screenReaderMode) { const int tooltipAvatarSize = 96; // maximal suggested size according to XEP-0153 cachedImageScaler_ = new QtScaledAvatarCache(tooltipAvatarSize); } @@ -92,11 +93,11 @@ QVariant RosterModel::data(const QModelIndex& index, int role) const { if (!item) return QVariant(); switch (role) { - case Qt::DisplayRole: return P2QSTRING(item->getDisplayName()); + case Qt::DisplayRole: return getScreenReaderTextOr(item, P2QSTRING(item->getDisplayName())); case Qt::TextColorRole: return getTextColor(item); case Qt::BackgroundColorRole: return getBackgroundColor(item); case Qt::ToolTipRole: return getToolTip(item); - case StatusTextRole: return getStatusText(item); + case StatusTextRole: return getScreenReaderTextOr(item, getStatusText(item)); case AvatarRole: return getAvatar(item); case PresenceIconRole: return getPresenceIcon(item); case ChildCountRole: return getChildCount(item); @@ -105,6 +106,21 @@ QVariant RosterModel::data(const QModelIndex& index, int role) const { } } +QString RosterModel::getScreenReaderTextOr(RosterItem* item, const QString& alternative) const { + QString name = P2QSTRING(item->getDisplayName()); + ContactRosterItem* contact = dynamic_cast(item); + if (contact && screenReader_) { + name += ": " + P2QSTRING(statusShowTypeToFriendlyName(contact->getStatusShow())); + if (!contact->getStatusText().empty()) { + name += " (" + P2QSTRING(contact->getStatusText()) + ")"; + } + return name; + } + else { + return alternative; + } +} + int RosterModel::getChildCount(RosterItem* item) const { GroupRosterItem* group = dynamic_cast(item); return group ? group->getDisplayedChildren().size() : 0; diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h index 5397054..7f6cdd2 100644 --- a/Swift/QtUI/Roster/RosterModel.h +++ b/Swift/QtUI/Roster/RosterModel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2013 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -28,7 +28,7 @@ namespace Swift { class RosterModel : public QAbstractItemModel { Q_OBJECT public: - RosterModel(QtTreeWidget* view); + RosterModel(QtTreeWidget* view, bool screenReaderMode); ~RosterModel(); void setRoster(Roster* swiftRoster); Qt::ItemFlags flags(const QModelIndex& index) const; @@ -56,8 +56,12 @@ namespace Swift { int getChildCount(RosterItem* item) const; bool getIsIdle(RosterItem* item) const; void reLayout(); + /** calculates screenreader-friendly text if in screenreader mode, otherwise uses alternative text */ + QString getScreenReaderTextOr(RosterItem* item, const QString& alternative) const; + private: Roster* roster_; QtTreeWidget* view_; QtScaledAvatarCache* cachedImageScaler_; + bool screenReader_; }; } -- cgit v0.10.2-6-g49f6