aboutsummaryrefslogtreecommitdiff
path: root/user.cpp
diff options
context:
space:
mode:
authorFelix Rohrbach <fxrh@gmx.de>2016-10-14 16:58:06 +0200
committerGitHub <noreply@github.com>2016-10-14 16:58:06 +0200
commit6536124821c1df791a69a58de21a71322d9363f6 (patch)
tree712be9dc1f146105c5569dfac65367381f260793 /user.cpp
parent45f38a1d6687d1ceaca87a6d6d94ac2515debb02 (diff)
parent24deeda0fe95fd352b823b48a3bc2e660f6a261d (diff)
downloadlibquotient-6536124821c1df791a69a58de21a71322d9363f6.tar.gz
libquotient-6536124821c1df791a69a58de21a71322d9363f6.zip
Merge pull request #42 from Fxrh/kitsune-use-qsize
MediaThumbnailJob: Use QSize instead of two separate int's for size
Diffstat (limited to 'user.cpp')
-rw-r--r--user.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/user.cpp b/user.cpp
index 60140e5b..7d4f0d1a 100644
--- a/user.cpp
+++ b/user.cpp
@@ -24,7 +24,6 @@
#include "jobs/mediathumbnailjob.h"
#include <QtCore/QTimer>
-#include <QtCore/QPair>
#include <QtCore/QDebug>
using namespace QMatrixClient;
@@ -39,11 +38,10 @@ class User::Private
Connection* connection;
QPixmap avatar;
- int requestedWidth;
- int requestedHeight;
+ QSize requestedSize;
bool avatarValid;
bool avatarOngoingRequest;
- QHash<QPair<int,int>,QPixmap> scaledMap;
+ QVector<QPixmap> scaledAvatars;
void requestAvatar();
};
@@ -51,11 +49,11 @@ class User::Private
User::User(QString userId, Connection* connection)
: QObject(connection), d(new Private)
{
- d->q = this;
d->connection = connection;
d->userId = userId;
d->avatarValid = false;
d->avatarOngoingRequest = false;
+ d->q = this;
}
User::~User()
@@ -82,15 +80,16 @@ QString User::displayname() const
QPixmap User::avatar(int width, int height)
{
+ QSize size(width, height);
+
if( !d->avatarValid
- || width > d->requestedWidth
- || height > d->requestedHeight )
+ || width > d->requestedSize.width()
+ || height > d->requestedSize.height() )
{
if( !d->avatarOngoingRequest && d->avatarUrl.isValid() )
{
qDebug() << "Getting avatar for" << id();
- d->requestedWidth = width;
- d->requestedHeight = height;
+ d->requestedSize = size;
d->avatarOngoingRequest = true;
QTimer::singleShot(0, this, SLOT(requestAvatar()));
}
@@ -98,12 +97,15 @@ QPixmap User::avatar(int width, int height)
if( d->avatar.isNull() )
return d->avatar;
- QPair<int,int> size(width, height);
- if( !d->scaledMap.contains(size) )
+ for (const QPixmap& p: d->scaledAvatars)
{
- d->scaledMap.insert(size, d->avatar.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ if (p.size() == size)
+ return p;
}
- return d->scaledMap.value(size);
+ QPixmap newlyScaled =
+ d->avatar.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ d->scaledAvatars.push_back(newlyScaled);
+ return newlyScaled;
}
void User::processEvent(Event* event)
@@ -132,14 +134,13 @@ void User::requestAvatar()
void User::Private::requestAvatar()
{
- MediaThumbnailJob* job =
- connection->getThumbnail(avatarUrl, requestedWidth, requestedHeight);
+ MediaThumbnailJob* job = connection->getThumbnail(avatarUrl, requestedSize);
connect( job, &MediaThumbnailJob::success, [=]() {
avatarOngoingRequest = false;
avatarValid = true;
- avatar = job->thumbnail().scaled(requestedWidth, requestedHeight,
+ avatar = job->thumbnail().scaled(requestedSize,
Qt::KeepAspectRatio, Qt::SmoothTransformation);
- scaledMap.clear();
+ scaledAvatars.clear();
emit q->avatarChanged(q);
});
}