summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtScaledAvatarCache.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/Swift/QtUI/QtScaledAvatarCache.cpp b/Swift/QtUI/QtScaledAvatarCache.cpp
index 6abff87..46ec2fc 100644
--- a/Swift/QtUI/QtScaledAvatarCache.cpp
+++ b/Swift/QtUI/QtScaledAvatarCache.cpp
@@ -14,6 +14,9 @@
#include <QPainter>
#include <QByteArray>
+#include <Swiften/Base/Log.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
namespace Swift {
QtScaledAvatarCache::QtScaledAvatarCache(int size) : size(size) {
@@ -31,18 +34,21 @@ QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) {
QString targetFile = targetDir.absoluteFilePath(avatarFile.baseName());
if (!QFileInfo(targetFile).exists()) {
QPixmap avatarPixmap;
- avatarPixmap.load(path);
- QPixmap maskedAvatar(avatarPixmap.size());
- maskedAvatar.fill(QColor(0, 0, 0, 0));
- QPainter maskPainter(&maskedAvatar);
- maskPainter.setBrush(Qt::black);
- maskPainter.drawRoundedRect(maskedAvatar.rect(), 25.0, 25.0, Qt::RelativeSize);
- maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
- maskPainter.drawPixmap(0, 0, avatarPixmap);
- maskPainter.end();
-
- if (!maskedAvatar.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(targetFile, "PNG")) {
- return path;
+ if (avatarPixmap.load(path)) {
+ QPixmap maskedAvatar(avatarPixmap.size());
+ maskedAvatar.fill(QColor(0, 0, 0, 0));
+ QPainter maskPainter(&maskedAvatar);
+ maskPainter.setBrush(Qt::black);
+ maskPainter.drawRoundedRect(maskedAvatar.rect(), 25.0, 25.0, Qt::RelativeSize);
+ maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ maskPainter.drawPixmap(0, 0, avatarPixmap);
+ maskPainter.end();
+
+ if (!maskedAvatar.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(targetFile, "PNG")) {
+ return path;
+ }
+ } else {
+ SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl;
}
}
return targetFile;