From e3908964948892633f09cec0df8c5b4d149c9ac7 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 16 Sep 2018 18:54:12 +0800 Subject: Remove default avatar. --- lib/avatar.cpp | 24 +++++++----------------- lib/avatar.h | 4 ++-- lib/user.cpp | 4 +--- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/avatar.cpp b/lib/avatar.cpp index be9b6a78..438268b6 100644 --- a/lib/avatar.cpp +++ b/lib/avatar.cpp @@ -33,16 +33,14 @@ using std::move; class Avatar::Private { public: - explicit Private(QIcon di, QUrl url = {}) - : _defaultIcon(move(di)), _url(move(url)) - { } + explicit Private(QUrl url = {}) : _url(move(url)) { } + QImage get(Connection* connection, QSize size, get_callback_t callback) const; bool upload(UploadContentJob* job, upload_callback_t callback); bool checkUrl(QUrl url) const; - const QIcon _defaultIcon; QUrl _url; // The below are related to image caching, hence mutable @@ -56,12 +54,12 @@ class Avatar::Private mutable std::vector callbacks; }; -Avatar::Avatar(QIcon defaultIcon) - : d(std::make_unique(std::move(defaultIcon))) +Avatar::Avatar() + : d(std::make_unique()) { } -Avatar::Avatar(QUrl url, QIcon defaultIcon) - : d(std::make_unique(std::move(defaultIcon), std::move(url))) +Avatar::Avatar(QUrl url) + : d(std::make_unique(std::move(url))) { } Avatar::Avatar(Avatar&&) = default; @@ -126,14 +124,6 @@ QImage Avatar::Private::get(Connection* connection, QSize size, if (callback) callbacks.emplace_back(move(callback)); _thumbnailRequest = connection->getThumbnail(_url, size); - if (_originalImage.isNull() && !_defaultIcon.isNull()) - { - _originalImage = QImage(_defaultIcon.actualSize(size), - QImage::Format_ARGB32_Premultiplied); - _originalImage.fill(Qt::transparent); - QPainter p { &_originalImage }; - _defaultIcon.paint(&p, { QPoint(), _defaultIcon.actualSize(size) }); - } QObject::connect( _thumbnailRequest, &MediaThumbnailJob::success, _thumbnailRequest, [this] { _fetched = true; @@ -149,7 +139,7 @@ QImage Avatar::Private::get(Connection* connection, QSize size, for (const auto& p: _scaledImages) if (p.first == size) return p.second; - auto result = _originalImage.scaled(size, + auto result = _originalImage.isNull() ? QImage() : _originalImage.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); _scaledImages.emplace_back(size, result); return result; diff --git a/lib/avatar.h b/lib/avatar.h index 0166ae9e..c86345e3 100644 --- a/lib/avatar.h +++ b/lib/avatar.h @@ -31,8 +31,8 @@ namespace QMatrixClient class Avatar { public: - explicit Avatar(QIcon defaultIcon = {}); - explicit Avatar(QUrl url, QIcon defaultIcon = {}); + explicit Avatar(); + explicit Avatar(QUrl url); Avatar(Avatar&&); ~Avatar(); Avatar& operator=(Avatar&&); diff --git a/lib/user.cpp b/lib/user.cpp index b9f493c5..eec08ad9 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -44,9 +44,7 @@ class User::Private public: static Avatar makeAvatar(QUrl url) { - static const QIcon icon - { QIcon::fromTheme(QStringLiteral("user-available")) }; - return Avatar(move(url), icon); + return Avatar(move(url)); } Private(QString userId, Connection* connection) -- cgit v1.2.3