From 666ad146312a1c8abdefe8bba5582fd9ac042700 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 18 Aug 2009 07:50:09 +0100 Subject: Include a (dummy) presence icon in roster entries. diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp index 7b4d83a..e49c87f 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp @@ -139,10 +139,15 @@ QVariant QtTreeWidgetItem::data(int role) { case Qt::BackgroundColorRole: return backgroundColor_; case StatusTextRole: return statusText_; case AvatarRole: return avatar_; + case PresenceIconRole: return getPresenceIcon(); default: return QVariant(); } } +QIcon QtTreeWidgetItem::getPresenceIcon() { + return QIcon(":/icons/online.png"); +} + bool QtTreeWidgetItem::isContact() { return children_.size() == 0; } diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h index 1b898b0..9c3b0ad 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.h +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h @@ -17,7 +17,8 @@ namespace Swift { enum RosterRoles { StatusTextRole = Qt::UserRole, - AvatarRole = Qt::UserRole + 1 + AvatarRole = Qt::UserRole + 1, + PresenceIconRole = Qt::UserRole + 2 }; class QtTreeWidget; @@ -33,6 +34,7 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem { int row(); QtTreeWidgetItem* getItem(int row); QVariant data(int role); + QIcon getPresenceIcon(); QtTreeWidgetItem(QtTreeWidgetItem* parentItem); void setText(const String& text); void setAvatarPath(const String& path); diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index b05bbb1..f3f07ee 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -35,17 +35,24 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option painter->fillRect(fullRegion, option.palette.highlight()); painter->setPen(option.palette.highlightedText().color()); } - QRect avatarRegion(QPoint(margin_, fullRegion.top() + margin_), QSize(avatarSize_, avatarSize_)); - QIcon icon = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value().isNull() + + QRect presenceIconRegion(QPoint(margin_, fullRegion.top()), QSize(presenceIconSize_, fullRegion.height())); + QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value().isNull() + ? index.data(PresenceIconRole).value() + : QIcon(":/icons/offline.png"); + presenceIcon.paint(painter, presenceIconRegion, Qt::AlignVCenter | Qt::AlignHCenter); + + QRect avatarRegion(QPoint(presenceIconRegion.right() + margin_, fullRegion.top()), QSize(avatarSize_, fullRegion.height())); + QIcon avatar = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value().isNull() ? index.data(AvatarRole).value() : QIcon(":/icons/avatar.png"); - icon.paint(painter, avatarRegion, Qt::AlignVCenter | Qt::AlignHCenter); + avatar.paint(painter, avatarRegion, Qt::AlignVCenter | Qt::AlignHCenter); QFont nameFont = painter->font(); QFont statusFont = painter->font(); painter->setFont(nameFont); - QRect textRegion(fullRegion.adjusted(avatarSize_ + margin_ * 2, 0, 0, 0)); + QRect textRegion(fullRegion.adjusted(avatarRegion.right() + margin_ * 2, 0, 0, 0)); QFontMetrics nameMetrics(nameFont); int nameHeight = nameMetrics.height() + margin_; diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h index 9ec800f..0d923ac 100644 --- a/Swift/QtUI/Roster/RosterDelegate.h +++ b/Swift/QtUI/Roster/RosterDelegate.h @@ -9,6 +9,7 @@ namespace Swift { void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; private: static const int avatarSize_ = 28; + static const int presenceIconSize_ = 16; static const int margin_ = 4; }; } -- cgit v0.10.2-6-g49f6