diff --git a/src/gui/tray/usermodel.cpp b/src/gui/tray/usermodel.cpp index 9c9f3cf81..4c8a7eb49 100644 --- a/src/gui/tray/usermodel.cpp +++ b/src/gui/tray/usermodel.cpp @@ -1613,35 +1613,53 @@ int UserModel::findUserIdForAccount(AccountState *account) const } /*-------------------------------------------------------------------------------------*/ -ImageProvider::ImageProvider() - : QQuickImageProvider(QQuickImageProvider::Image) +class ImageResponse : public QQuickImageResponse { -} +public: + ImageResponse(const QString &id, const QSize &requestedSize, QThreadPool *pool) + { + Q_UNUSED(pool) -QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) -{ - Q_UNUSED(size) - Q_UNUSED(requestedSize) + const auto makeIcon = [](const QString &path) { + QImage image(128, 128, QImage::Format_ARGB32); + image.fill(Qt::GlobalColor::transparent); + QPainter painter(&image); + QSvgRenderer renderer(path); + renderer.render(&painter); + return image; + }; - const auto makeIcon = [](const QString &path) { - QImage image(128, 128, QImage::Format_ARGB32); - image.fill(Qt::GlobalColor::transparent); - QPainter painter(&image); - QSvgRenderer renderer(path); - renderer.render(&painter); - return image; - }; + if (id == QLatin1String("fallbackWhite")) { + handleDone(makeIcon(QStringLiteral(":/client/theme/white/user.svg"))); + return; + } else if (id == QLatin1String("fallbackBlack")) { + handleDone(makeIcon(QStringLiteral(":/client/theme/black/user.svg"))); + return; + } - if (id == QLatin1String("fallbackWhite")) { - return makeIcon(QStringLiteral(":/client/theme/white/user.svg")); + + handleDone(UserModel::instance()->avatarById(id.toInt())); } - if (id == QLatin1String("fallbackBlack")) { - return makeIcon(QStringLiteral(":/client/theme/black/user.svg")); + void handleDone(const QImage &image) + { + _image = image; + emit finished(); } - const int uid = id.toInt(); - return UserModel::instance()->avatarById(uid); + QQuickTextureFactory *textureFactory() const override + { + return QQuickTextureFactory::textureFactoryForImage(_image); + } + +private: + QImage _image; +}; + +QQuickImageResponse *ImageProvider::requestImageResponse(const QString &id, const QSize &requestedSize) +{ + const auto response = new class ImageResponse(id, requestedSize, &pool); + return response; } /*-------------------------------------------------------------------------------------*/ @@ -1720,3 +1738,6 @@ QHash UserAppsModel::roleNames() const return roles; } } + +#include "usermodel.moc" + diff --git a/src/gui/tray/usermodel.h b/src/gui/tray/usermodel.h index 33c3ae455..b73a1541b 100644 --- a/src/gui/tray/usermodel.h +++ b/src/gui/tray/usermodel.h @@ -276,11 +276,13 @@ private: void buildUserList(); }; -class ImageProvider : public QQuickImageProvider +class ImageProvider : public QQuickAsyncImageProvider { + Q_OBJECT + public: - ImageProvider(); - QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override; + ImageProvider() = default; + QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override; }; class UserAppsModel : public QAbstractListModel