From 66105a538fca090f9d251a7173ad79ae2f5727e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 22 Feb 2011 19:41:22 +0100 Subject: Round corners of avatars in roster. diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index 57e7af1..1dc513b 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "QtStatusWidget.h" #include @@ -74,7 +76,19 @@ void QtRosterHeader::setAvatar(const QString& path) { //qDebug() << "Setting null avatar"; avatar = QIcon(":/icons/avatar.png"); } - avatarLabel_->setPixmap(avatar.pixmap(avatarSize_, avatarSize_)); + + // Apply a rounded rectangle mask + // FIXME: We shouldn't go via a 128x128 pixmap + QPixmap avatarPixmap = avatar.pixmap(128, 128); + QPixmap mask(avatarPixmap.size()); + QPainter maskPainter(&mask); + maskPainter.fillRect(mask.rect(), Qt::white); + maskPainter.setBrush(Qt::black); + maskPainter.drawRoundedRect(mask.rect(), 13, 13); + avatarPixmap.setMask(mask.createMaskFromColor(Qt::white)); + avatarPixmap = avatarPixmap.scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation); + + avatarLabel_->setPixmap(avatarPixmap); } void QtRosterHeader::setNick(const QString& nick) { diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index 7dbf3cb..5f6e778 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "Swift/Controllers/Roster/ContactRosterItem.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" @@ -88,7 +89,19 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& QIcon avatar = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value().isNull() ? index.data(AvatarRole).value() : QIcon(":/icons/avatar.png"); - avatar.paint(painter, avatarRegion, Qt::AlignVCenter | Qt::AlignHCenter); + + // Apply a rounded rectangle mask + // FIXME: We shouldn't go via a 128x128 pixmap + QPixmap avatarPixmap = avatar.pixmap(128, 128); + QPixmap mask(avatarPixmap.size()); + QPainter maskPainter(&mask); + maskPainter.fillRect(mask.rect(), Qt::white); + maskPainter.setBrush(Qt::black); + maskPainter.drawRoundedRect(mask.rect(), 13, 13); + avatarPixmap.setMask(mask.createMaskFromColor(Qt::white)); + avatarPixmap = avatarPixmap.scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + + painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap); //Paint the presence icon over the top of the avatar QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value().isNull() -- cgit v0.10.2-6-g49f6