aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-12-25 09:13:25 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-12-25 09:13:25 +0900
commit7b65cec153970c3e7525f24e0d167e0aa7ba4de4 (patch)
tree650fa11ac7faec373ee65dca43c9ef0ff8155dad
parent00a3b28c8e561c35ad33499819d5aaced49b50da (diff)
downloadlibquotient-7b65cec153970c3e7525f24e0d167e0aa7ba4de4.tar.gz
libquotient-7b65cec153970c3e7525f24e0d167e0aa7ba4de4.zip
Use pimpl for Avatars
-rw-r--r--avatar.cpp39
-rw-r--r--avatar.h20
2 files changed, 41 insertions, 18 deletions
diff --git a/avatar.cpp b/avatar.cpp
index f5101ddb..b2f50a67 100644
--- a/avatar.cpp
+++ b/avatar.cpp
@@ -24,8 +24,38 @@
using namespace QMatrixClient;
+class Avatar::Private
+{
+ public:
+ Private(Connection* c, QIcon di) : _connection(c), _defaultIcon(di) { }
+ QPixmap get(int width, int height, Avatar::notifier_t notifier);
+
+ Connection* _connection;
+ const QIcon _defaultIcon;
+ QUrl _url;
+ QPixmap _originalPixmap;
+
+ std::vector<QPair<QSize, QPixmap>> _scaledPixmaps;
+
+ QSize _requestedSize;
+ bool _valid = false;
+ MediaThumbnailJob* _ongoingRequest = nullptr;
+ std::vector<notifier_t> notifiers;
+};
+
+Avatar::Avatar(Connection* connection, QIcon defaultIcon)
+ : d(new Private { connection, std::move(defaultIcon) })
+{ }
+
+Avatar::~Avatar() = default;
+
QPixmap Avatar::get(int width, int height, Avatar::notifier_t notifier)
{
+ return d->get(width, height, notifier);
+}
+
+QPixmap Avatar::Private::get(int width, int height, Avatar::notifier_t notifier)
+{
QSize size(width, height);
// FIXME: Alternating between longer-width and longer-height requests
@@ -73,12 +103,15 @@ QPixmap Avatar::get(int width, int height, Avatar::notifier_t notifier)
return pixmap;
}
+QUrl Avatar::url() const { return d->_url; }
+
bool Avatar::updateUrl(const QUrl& newUrl)
{
- if (newUrl == _url)
+ if (newUrl == d->_url)
return false;
- _url = newUrl;
- _valid = false;
+ d->_url = newUrl;
+ d->_valid = false;
return true;
}
+
diff --git a/avatar.h b/avatar.h
index 60cf3779..e71fecd7 100644
--- a/avatar.h
+++ b/avatar.h
@@ -31,28 +31,18 @@ namespace QMatrixClient
class Avatar
{
public:
- explicit Avatar(Connection* connection, QIcon defaultIcon = {})
- : _defaultIcon(std::move(defaultIcon)), _connection(connection)
- { }
+ explicit Avatar(Connection* connection, QIcon defaultIcon = {});
+ ~Avatar();
using notifier_t = std::function<void()>;
QPixmap get(int w, int h, notifier_t notifier);
- QUrl url() const { return _url; }
+ QUrl url() const;
bool updateUrl(const QUrl& newUrl);
private:
- QUrl _url;
- QPixmap _originalPixmap;
- QIcon _defaultIcon;
-
- std::vector<QPair<QSize, QPixmap>> _scaledPixmaps;
-
- QSize _requestedSize;
- bool _valid = false;
- Connection* _connection;
- MediaThumbnailJob* _ongoingRequest = nullptr;
- std::vector<notifier_t> notifiers;
+ class Private;
+ QScopedPointer<Private> d;
};
} // namespace QMatrixClient