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 ++++++++++++++++++++++++++++++++++++--- avatar.h | 20 +++++--------------- 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,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; } + 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; 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> _scaledPixmaps; - - QSize _requestedSize; - bool _valid = false; - Connection* _connection; - MediaThumbnailJob* _ongoingRequest = nullptr; - std::vector notifiers; + class Private; + QScopedPointer d; }; } // namespace QMatrixClient -- cgit v1.2.3