From 7b65cec153970c3e7525f24e0d167e0aa7ba4de4 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 25 Dec 2017 09:13:25 +0900 Subject: Use pimpl for Avatars --- avatar.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'avatar.cpp') diff --git a/avatar.cpp b/avatar.cpp index f5101ddb..b2f50a67 100644 --- a/avatar.cpp +++ b/avatar.cpp @@ -24,7 +24,37 @@ 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> _scaledPixmaps; + + QSize _requestedSize; + bool _valid = false; + MediaThumbnailJob* _ongoingRequest = nullptr; + std::vector 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); @@ -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; } + -- cgit v1.2.3