diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-25 09:13:25 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-25 09:13:25 +0900 |
commit | 7b65cec153970c3e7525f24e0d167e0aa7ba4de4 (patch) | |
tree | 650fa11ac7faec373ee65dca43c9ef0ff8155dad | |
parent | 00a3b28c8e561c35ad33499819d5aaced49b50da (diff) | |
download | libquotient-7b65cec153970c3e7525f24e0d167e0aa7ba4de4.tar.gz libquotient-7b65cec153970c3e7525f24e0d167e0aa7ba4de4.zip |
Use pimpl for Avatars
-rw-r--r-- | avatar.cpp | 39 | ||||
-rw-r--r-- | avatar.h | 20 |
2 files changed, 41 insertions, 18 deletions
@@ -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; } + @@ -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 |