Init rewritten avatar.

This commit is contained in:
Black Hat
2018-11-04 19:14:02 +08:00
parent c19f49a898
commit 5a46810016
24 changed files with 167 additions and 101 deletions

View File

@@ -1,6 +1,7 @@
#ifndef SpectralUser_H
#define SpectralUser_H
#include "paintable.h"
#include "room.h"
#include "user.h"
@@ -8,18 +9,34 @@
using namespace QMatrixClient;
class UserPaintable : public Paintable {
Q_OBJECT
public:
UserPaintable(User* parent) : Paintable(parent), m_user(parent) {
connect(m_user, &User::avatarChanged, [=] { emit paintableChanged(); });
}
QImage image(int dimension) override {
if (!m_user) return QImage();
return m_user->avatar(dimension);
}
QImage image(int width, int height) override {
if (!m_user) return QImage();
return m_user->avatar(width, height);
}
private:
User* m_user;
};
class SpectralUser : public User {
Q_OBJECT
Q_PROPERTY(QImage avatar READ getAvatar NOTIFY inheritedAvatarChanged)
Q_PROPERTY(Paintable* paintable READ paintable CONSTANT)
public:
SpectralUser(QString userId, Connection* connection);
SpectralUser(QString userId, Connection* connection)
: User(userId, connection) {}
QImage getAvatar() { return avatar(128); }
signals:
void inheritedAvatarChanged(
User* user,
const Room* roomContext); // https://bugreports.qt.io/browse/QTBUG-7684
Paintable* paintable() { return new UserPaintable(this); }
};
#endif // SpectralUser_H