mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-19 12:22:16 +03:00
Convert ImageProvider in an async image provider using an internal image response
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
88a2904651
commit
896e61ae04
2 changed files with 47 additions and 24 deletions
|
@ -1613,15 +1613,12 @@ int UserModel::findUserIdForAccount(AccountState *account) const
|
|||
}
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
|
||||
ImageProvider::ImageProvider()
|
||||
: QQuickImageProvider(QQuickImageProvider::Image)
|
||||
class ImageResponse : public QQuickImageResponse
|
||||
{
|
||||
}
|
||||
|
||||
QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
public:
|
||||
ImageResponse(const QString &id, const QSize &requestedSize, QThreadPool *pool)
|
||||
{
|
||||
Q_UNUSED(size)
|
||||
Q_UNUSED(requestedSize)
|
||||
Q_UNUSED(pool)
|
||||
|
||||
const auto makeIcon = [](const QString &path) {
|
||||
QImage image(128, 128, QImage::Format_ARGB32);
|
||||
|
@ -1633,15 +1630,36 @@ QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &
|
|||
};
|
||||
|
||||
if (id == QLatin1String("fallbackWhite")) {
|
||||
return makeIcon(QStringLiteral(":/client/theme/white/user.svg"));
|
||||
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("fallbackBlack")) {
|
||||
return makeIcon(QStringLiteral(":/client/theme/black/user.svg"));
|
||||
|
||||
handleDone(UserModel::instance()->avatarById(id.toInt()));
|
||||
}
|
||||
|
||||
const int uid = id.toInt();
|
||||
return UserModel::instance()->avatarById(uid);
|
||||
void handleDone(const QImage &image)
|
||||
{
|
||||
_image = image;
|
||||
emit finished();
|
||||
}
|
||||
|
||||
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<int, QByteArray> UserAppsModel::roleNames() const
|
|||
return roles;
|
||||
}
|
||||
}
|
||||
|
||||
#include "usermodel.moc"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue