summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.cpp5
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.h4
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp15
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.h1
4 files changed, 20 insertions, 5 deletions
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<QIcon>().isNull()
+
+ QRect presenceIconRegion(QPoint(margin_, fullRegion.top()), QSize(presenceIconSize_, fullRegion.height()));
+ QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value<QIcon>().isNull()
+ ? index.data(PresenceIconRole).value<QIcon>()
+ : 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<QIcon>().isNull()
? index.data(AvatarRole).value<QIcon>()
: 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;
};
}