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

View File

@ -2,36 +2,47 @@ import QtQuick 2.10
import QtQuick.Controls 2.3
import QtGraphicalEffects 1.0
Image {
Item {
property bool statusIndicator
id: avatar
mipmap: true
layer.enabled: true
fillMode: Image.PreserveAspectCrop
layer.effect: OpacityMask {
maskSource: Item {
width: avatar.width
height: avatar.width
Rectangle {
anchors.centerIn: parent
width: avatar.width
height: avatar.width
radius: avatar.width / 2
}
}
}
property alias source: avatar.source
Rectangle {
id: circle
width: avatar.width
height: avatar.width
radius: avatar.width / 2
color: "transparent"
border.color: "#4caf50"
border.width: 4
visible: statusIndicator
width: parent.width
height: parent.width
radius: parent.width / 2
color: "white"
}
Image {
id: avatar
width: parent.width
height: parent.width
mipmap: true
layer.enabled: true
fillMode: Image.PreserveAspectCrop
layer.effect: OpacityMask {
maskSource: Item {
width: avatar.width
height: avatar.width
Rectangle {
anchors.centerIn: parent
width: avatar.width
height: avatar.width
radius: avatar.width / 2
}
}
}
Rectangle {
width: parent.width
height: parent.width
radius: parent.width / 2
color: "transparent"
border.color: "#4caf50"
border.width: 4
visible: statusIndicator
}
}
}