diff options
author | Kevin Smith <git@kismith.co.uk> | 2013-11-25 10:54:03 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2013-11-25 10:54:03 (GMT) |
commit | 78df31e45cf9f6c90a82c2a9265b2e3bb509570d (patch) | |
tree | 1a6311d09f90e6674533028de6f3c6cd401a7478 /Swift | |
parent | 58da4ae2358b90a9a178ecebf7f33b7e9e0636ee (diff) | |
download | swift-contrib-78df31e45cf9f6c90a82c2a9265b2e3bb509570d.zip swift-contrib-78df31e45cf9f6c90a82c2a9265b2e3bb509570d.tar.bz2 |
When in screen-reader mode, change the text used in rosters to include more information.
Change-Id: I8807b2ce6d36dbce510a185f0e4e2c549c623225
Diffstat (limited to 'Swift')
-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 @@ -35,5 +35,5 @@ QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* setting 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)); 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 @@ -19,4 +19,5 @@ #include <Swift/Controllers/Roster/ContactRosterItem.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> +#include <Swift/Controllers/StatusUtil.h> #include <Swift/QtUI/Roster/QtTreeWidget.h> @@ -27,5 +28,5 @@ 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); @@ -93,9 +94,9 @@ QVariant RosterModel::data(const QModelIndex& index, int role) const { 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); @@ -106,4 +107,19 @@ 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); 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,4 +1,4 @@ /* - * 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. @@ -29,5 +29,5 @@ namespace Swift { Q_OBJECT public: - RosterModel(QtTreeWidget* view); + RosterModel(QtTreeWidget* view, bool screenReaderMode); ~RosterModel(); void setRoster(Roster* swiftRoster); @@ -57,7 +57,11 @@ namespace Swift { 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_; }; } |