diff options
-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 |