summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-03-08 22:00:09 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-03-08 22:00:09 (GMT)
commit87ff1525f682105fa4e5a9a75dc7d844b19cfdbb (patch)
tree54dabebb45f639fcd597b9a75d6084230fffd82e /Swift/QtUI/QtRosterHeader.cpp
parent27d21b371f24272466a2d6a5bf2e2b717ee2d9fc (diff)
downloadswift-87ff1525f682105fa4e5a9a75dc7d844b19cfdbb.zip
swift-87ff1525f682105fa4e5a9a75dc7d844b19cfdbb.tar.bz2
Cache rounded avatars.
Resolves: #770
Diffstat (limited to 'Swift/QtUI/QtRosterHeader.cpp')
-rw-r--r--Swift/QtUI/QtRosterHeader.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index 18bb980..5fb4d1a 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -8,6 +8,7 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
+#include <QFileInfo>
#include <QIcon>
#include <QSizePolicy>
#include <qdebug.h>
@@ -19,6 +20,7 @@
#include <Swift/QtUI/QtElidingLabel.h>
#include <Swift/QtUI/QtClickableLabel.h>
#include <Swift/QtUI/QtNameWidget.h>
+#include "QtScaledAvatarCache.h"
namespace Swift {
QtRosterHeader::QtRosterHeader(QtSettingsProvider* settings, QWidget* parent) : QWidget(parent) {
@@ -71,28 +73,15 @@ void QtRosterHeader::setConnecting() {
}
void QtRosterHeader::setAvatar(const QString& path) {
- QIcon avatar(path);
- if (avatar.isNull()) {
- //qDebug() << "Setting null avatar";
- avatar = QIcon(":/icons/avatar.png");
- }
-
- // Apply a rounded rectangle mask
- // FIXME:
- // - We shouldn't go via a 128x128 pixmap
- // - Something tells me we can do this with clever composition mode +
- // 1 drawRectangle on the avatarPixmap, but i haven't figured it out yet.
- QPixmap avatarPixmap = avatar.pixmap(128, 128);
- QPixmap maskedAvatar(avatarPixmap.size());
- maskedAvatar.fill(QColor(0, 0, 0, 0));
- QPainter maskPainter(&maskedAvatar);
- maskPainter.setBrush(Qt::black);
- maskPainter.drawRoundedRect(maskedAvatar.rect(), 13, 13);
- maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
- maskPainter.drawPixmap(0, 0, avatarPixmap);
- maskPainter.end();
-
- avatarLabel_->setPixmap(maskedAvatar.scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ QString scaledAvatarPath = QtScaledAvatarCache(avatarSize_).getScaledAvatarPath(path);
+ QPixmap avatar;
+ if (QFileInfo(scaledAvatarPath).exists()) {
+ avatar.load(scaledAvatarPath);
+ }
+ else {
+ avatar = QPixmap(":/icons/avatar.png").scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
+ avatarLabel_->setPixmap(avatar);
}
void QtRosterHeader::setNick(const QString& nick) {