Add HUserAvatar and HRoomAvatar components

This commit is contained in:
miruka 2019-07-07 00:24:23 -04:00
parent 064fb6e9a2
commit 683ee3e1cf
14 changed files with 55 additions and 59 deletions

View File

@ -3,7 +3,7 @@ import "../Base"
import "../utils.js" as Utils import "../utils.js" as Utils
Rectangle { Rectangle {
property var name: null property string name: ""
property var imageUrl: null property var imageUrl: null
property int dimension: theme.avatar.size property int dimension: theme.avatar.size
property bool hidden: false property bool hidden: false

View File

@ -0,0 +1,10 @@
import QtQuick 2.7
HAvatar {
property string roomId: ""
readonly property var roomInfo: rooms.getWhere({"roomId": roomId}, 1)[0]
readonly property var dname: roomInfo.displayName
name: dname[0] == "#" && dname.length > 1 ? dname.substring(1) : dname
imageUrl: roomInfo.avatarUrl
}

View File

@ -1,11 +0,0 @@
import QtQuick 2.7
HAvatar {
HImage {
id: status
anchors.right: parent.right
anchors.bottom: parent.bottom
source: "../../icons/status.svg"
sourceSize.width: 12
}
}

View File

@ -0,0 +1,17 @@
import QtQuick 2.7
HAvatar {
property string userId: ""
readonly property var userInfo: userId ? users.getUser(userId) : ({})
name: userInfo.displayName || userId.substring(1) // no leading @
imageUrl: userInfo.avatarUrl
//HImage {
//id: status
//anchors.right: parent.right
//anchors.bottom: parent.bottom
//source: "../../icons/status.svg"
//sourceSize.width: 12
//}
}

View File

@ -17,7 +17,7 @@ HRectangle {
id: bannerRow id: bannerRow
anchors.fill: parent anchors.fill: parent
HAvatar { HUserAvatar {
id: bannerAvatar id: bannerAvatar
dimension: banner.Layout.preferredHeight dimension: banner.Layout.preferredHeight
} }

View File

@ -10,9 +10,7 @@ Banner {
color: theme.chat.inviteBanner.background color: theme.chat.inviteBanner.background
avatar.name: inviterId ? (inviterInfo.displayName || avatar.userId: inviterId
Utils.stripUserId(inviterId)) : ""
avatar.imageUrl: inviterId ? inviterInfo.avatarUrl : ""
labelText: qsTr("%1 invited you to join the room.").arg( labelText: qsTr("%1 invited you to join the room.").arg(
inviterId ? inviterId ?

View File

@ -1,6 +1,5 @@
import QtQuick 2.7 import QtQuick 2.7
import "../../Base" import "../../Base"
import "../../utils.js" as Utils
Banner { Banner {
property string userId: "" property string userId: ""
@ -9,7 +8,7 @@ Banner {
color: theme.chat.leftBanner.background color: theme.chat.leftBanner.background
// TODO: avatar func auto // TODO: avatar func auto
avatar.name: userInfo.displayName || Utils.stripUserId(userId) avatar.userId: userId
avatar.imageUrl: users.getUser(userId).avatarUrl avatar.imageUrl: users.getUser(userId).avatarUrl
labelText: qsTr("You are not part of this room anymore.") labelText: qsTr("You are not part of this room anymore.")

View File

@ -1,7 +1,6 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import "../Base" import "../Base"
import "../utils.js" as Utils
HRectangle { HRectangle {
property string displayName: "" property string displayName: ""
@ -21,9 +20,9 @@ HRectangle {
spacing: 8 spacing: 8
anchors.fill: parent anchors.fill: parent
HAvatar { HRoomAvatar {
id: avatar id: avatar
name: Utils.stripRoomName(displayName) roomId: chatPage.roomId
dimension: roomHeader.height dimension: roomHeader.height
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
} }

View File

@ -1,32 +1,31 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import "../../Base" import "../../Base"
import "../utils.js" as Utils
MouseArea { MouseArea {
id: memberDelegate id: memberDelegate
width: memberList.width width: memberList.width
height: childrenRect.height height: childrenRect.height
property var member: Backend.users.get(userId) property var memberInfo: Backend.users.get(model.userId)
HRowLayout { HRowLayout {
width: parent.width width: parent.width
spacing: memberList.spacing spacing: memberList.spacing
HAvatar { HUserAvatar {
id: memberAvatar id: avatar
name: member.displayName || Utils.stripUserId(member.userId) userId: memberInfo.userId
} }
HColumnLayout { HColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumWidth: Layout.maximumWidth:
parent.width - parent.totalSpacing - memberAvatar.width parent.width - parent.totalSpacing - avatar.width
HLabel { HLabel {
id: memberName id: memberName
text: member.displayName.value text: memberInfo.displayName || model.userId
elide: Text.ElideRight elide: Text.ElideRight
maximumLineCount: 1 maximumLineCount: 1
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter

View File

@ -1,7 +1,6 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import "../Base" import "../Base"
import "../utils.js" as Utils
HRectangle { HRectangle {
function setFocus() { textArea.forceActiveFocus() } function setFocus() { textArea.forceActiveFocus() }
@ -17,10 +16,9 @@ HRectangle {
HRowLayout { HRowLayout {
anchors.fill: parent anchors.fill: parent
HAvatar { HUserAvatar {
id: avatar id: avatar
name: chatPage.senderInfo.displayName || userId: chatPage.userId
Utils.stripUserId(chatPage.userId)
dimension: sendBox.Layout.minimumHeight dimension: sendBox.Layout.minimumHeight
} }

View File

@ -8,10 +8,10 @@ Row {
spacing: standardSpacing / 2 spacing: standardSpacing / 2
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
HAvatar { HUserAvatar {
id: avatar id: avatar
hidden: combine hidden: combine
name: senderInfo.displayName || Utils.stripUserId(model.senderId) userId: model.senderId
dimension: model.showNameLine ? 48 : 28 dimension: model.showNameLine ? 48 : 28
visible: ! isOwn visible: ! isOwn
} }

View File

@ -1,17 +1,15 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import "../Base" import "../Base"
import "../utils.js" as Utils
Column { Column {
id: accountDelegate id: accountDelegate
width: parent.width width: parent.width
// Avoid binding loop by using Component.onCompleted // Avoid binding loop by using Component.onCompleted
property var user: null property var userInfo: null
Component.onCompleted: user = users.getUser(userId) Component.onCompleted: userInfo = users.getUser(model.userId)
property string roomCategoriesListUserId: userId
property bool expanded: true property bool expanded: true
HRowLayout { HRowLayout {
@ -19,9 +17,9 @@ Column {
height: childrenRect.height height: childrenRect.height
id: row id: row
HAvatar { HUserAvatar {
id: avatar id: avatar
name: user.displayName || Utils.stripUserId(user.userId) Component.onCompleted: userId = model.userId
} }
HColumnLayout { HColumnLayout {
@ -30,7 +28,7 @@ Column {
HLabel { HLabel {
id: accountLabel id: accountLabel
text: user.displayName || user.userId text: userInfo.displayName || model.userId
elide: HLabel.ElideRight elide: HLabel.ElideRight
maximumLineCount: 1 maximumLineCount: 1
Layout.fillWidth: true Layout.fillWidth: true
@ -40,7 +38,7 @@ Column {
HTextField { HTextField {
id: statusEdit id: statusEdit
text: user.statusMessage text: userInfo.statusMessage
placeholderText: qsTr("Set status message") placeholderText: qsTr("Set status message")
font.pixelSize: theme.fontSize.small font.pixelSize: theme.fontSize.small
background: null background: null
@ -51,7 +49,7 @@ Column {
Layout.fillWidth: true Layout.fillWidth: true
onEditingFinished: { onEditingFinished: {
//Backend.setStatusMessage(userId, text) //Backend.setStatusMessage(model.userId, text) TODO
pageStack.forceActiveFocus() pageStack.forceActiveFocus()
} }
} }
@ -71,7 +69,7 @@ Column {
height: childrenRect.height * (accountDelegate.expanded ? 1 : 0) height: childrenRect.height * (accountDelegate.expanded ? 1 : 0)
clip: heightAnimation.running clip: heightAnimation.running
userId: roomCategoriesListUserId userId: userInfo.userId
Behavior on height { Behavior on height {
HNumberAnimation { id: heightAnimation } HNumberAnimation { id: heightAnimation }

View File

@ -15,9 +15,9 @@ MouseArea {
width: parent.width width: parent.width
spacing: sidePane.collapsed ? 0 : sidePane.normalSpacing spacing: sidePane.collapsed ? 0 : sidePane.normalSpacing
HAvatar { HRoomAvatar {
id: roomAvatar id: roomAvatar
name: Utils.stripRoomName(model.displayName) roomId: model.roomId
} }
HColumnLayout { HColumnLayout {

View File

@ -12,18 +12,6 @@ function arrayToModelItem(keys_name, array) {
} }
function stripUserId(user_id) {
// Remove leading @
return user_id.substring(1)
}
function stripRoomName(name) {
// Remove leading # (aliases)
return name[0] == "#" && name.length > 1 ? name.substring(1) : name
}
function hueFrom(string) { function hueFrom(string) {
// Calculate and return a unique hue between 0 and 1 for the string // Calculate and return a unique hue between 0 and 1 for the string
var hue = 0 var hue = 0
@ -55,7 +43,8 @@ function nameColor(name) {
function coloredNameHtml(name, alt_id) { function coloredNameHtml(name, alt_id) {
return "<font color='" + nameColor(name || stripUserId(alt_id)) + "'>" + // substring: remove leading @
return "<font color='" + nameColor(name || alt_id.substring(1)) + "'>" +
escapeHtml(name || alt_id) + escapeHtml(name || alt_id) +
"</font>" "</font>"
} }