diff options
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterModel.cpp | 22 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterModel.h | 8 |
3 files changed, 26 insertions, 6 deletions
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 <Swift/Controllers/Roster/ContactRosterItem.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> +#include <Swift/Controllers/StatusUtil.h> #include <Swift/QtUI/Roster/QtTreeWidget.h> #include <Swift/QtUI/Roster/RosterTooltip.h> @@ -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<ContactRosterItem*>(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<GroupRosterItem*>(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_; }; } |