diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-02-22 18:41:22 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-02-22 18:41:22 (GMT) |
commit | 66105a538fca090f9d251a7173ad79ae2f5727e5 (patch) | |
tree | 9907e7d2f6318d8884d40276e6e8e35c2bfe2c2a /Swift/QtUI/Roster | |
parent | 59939976a98b6b45582490be9ce568e9fd051da5 (diff) | |
download | swift-contrib-66105a538fca090f9d251a7173ad79ae2f5727e5.zip swift-contrib-66105a538fca090f9d251a7173ad79ae2f5727e5.tar.bz2 |
Round corners of avatars in roster.
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r-- | Swift/QtUI/Roster/RosterDelegate.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
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 <QPainterPath> #include <QPolygon> #include <qdebug.h> +#include <QBitmap> #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<QIcon>().isNull() ? index.data(AvatarRole).value<QIcon>() : 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<QIcon>().isNull() |