Add avatar for user.

This commit is contained in:
Black Hat 2018-03-04 20:05:09 +08:00
parent b6d94382a9
commit 854a1c3855
2 changed files with 46 additions and 30 deletions

View File

@ -2,8 +2,8 @@
#include <QtGui/QColor> #include <QtGui/QColor>
#include "roomlistmodel.h" #include "roomlistmodel.h"
#include "controller.h" #include "controller.h"
#include "user.h"
RoomListModel::RoomListModel() { RoomListModel::RoomListModel() {
@ -59,7 +59,12 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
return room->topic(); return room->topic();
} }
if(role == AvatarRole) { if(role == AvatarRole) {
if(room->avatarUrl().toString() != "") {
return room->avatarUrl(); return room->avatarUrl();
} else if(room->users().length() == 2) {
QMatrixClient::User* user = room->users().at(0);
return user->avatarUrl();
}
} }
return QVariant(); return QVariant();
} }

View File

@ -2,10 +2,21 @@ import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
Image { Item {
property bool statusIndicator property bool statusIndicator
property alias source: avatar.source
Rectangle {
width: parent.width
height: parent.width
radius: parent.width / 2
color: "white"
}
Image {
id: avatar id: avatar
width: parent.width
height: parent.width
mipmap: true mipmap: true
layer.enabled: true layer.enabled: true
@ -25,13 +36,13 @@ Image {
} }
Rectangle { Rectangle {
id: circle width: parent.width
width: avatar.width height: parent.width
height: avatar.width radius: parent.width / 2
radius: avatar.width / 2
color: "transparent" color: "transparent"
border.color: "#4caf50" border.color: "#4caf50"
border.width: 4 border.width: 4
visible: statusIndicator visible: statusIndicator
} }
} }
}