From 854a1c3855de6cfe93b66d693e5d51b2a7469a90 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 4 Mar 2018 20:05:09 +0800 Subject: [PATCH] Add avatar for user. --- matrix/roomlistmodel.cpp | 9 +++-- qml/component/ImageStatus.qml | 67 ++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/matrix/roomlistmodel.cpp b/matrix/roomlistmodel.cpp index c4904cc..fb45a7d 100644 --- a/matrix/roomlistmodel.cpp +++ b/matrix/roomlistmodel.cpp @@ -2,8 +2,8 @@ #include #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(); } diff --git a/qml/component/ImageStatus.qml b/qml/component/ImageStatus.qml index 3619d9e..5bb3950 100644 --- a/qml/component/ImageStatus.qml +++ b/qml/component/ImageStatus.qml @@ -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 + } } }