status-desktop/ui/shared/status/StatusChatInfo.qml

135 lines
4.2 KiB
QML
Raw Normal View History

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtGraphicalEffects 1.13
import "../../imports"
import "../../shared"
import "../../shared/status"
Item {
id: root
property string chatId
property string chatName
property int chatType
property string identicon
property int identiconSize: 40
property bool isCompact: false
property bool muted: false
property string profileImage: chatType === Constants.chatTypeOneToOne ? appMain.getProfileImage(chatId) || "" : ""
2020-11-30 17:03:52 +00:00
height: 48
width: nameAndInfo.width + chatIdenticon.width + Style.current.smallPadding
2020-11-30 17:03:52 +00:00
Connections {
enabled: chatType === Constants.chatTypeOneToOne
target: profileModel.contacts.list
onContactChanged: {
if (pubkey === root.chatId) {
root.profileImage = appMain.getProfileImage(root.chatId)
2020-11-30 17:03:52 +00:00
}
}
}
StatusIdenticon {
id: chatIdenticon
chatType: root.chatType
chatName: root.chatName
2020-11-30 17:03:52 +00:00
identicon: root.profileImage || root.identicon
width: root.isCompact ? 20 : root.identiconSize
height: root.isCompact ? 20 : root.identiconSize
anchors.verticalCenter: parent.verticalCenter
}
Item {
id: nameAndInfo
height: chatName.height + chatInfo.height
width: childrenRect.width
anchors.verticalCenter: parent.verticalCenter
anchors.left: chatIdenticon.right
anchors.leftMargin: Style.current.smallPadding
StyledText {
id: chatName
text: {
switch(root.chatType) {
case Constants.chatTypePublic: return "#" + root.chatName;
case Constants.chatTypeOneToOne: return Utils.removeStatusEns(root.chatName)
default: return root.chatName
}
}
font.weight: Font.Medium
font.pixelSize: 15
}
SVGImage {
property bool hovered: false
id: bellImg
visible: root.muted
source: "../../app/img/bell-disabled.svg"
anchors.verticalCenter: chatName.verticalCenter
anchors.left: chatName.right
anchors.leftMargin: 4
width: 12.5
height: 12.5
ColorOverlay {
anchors.fill: parent
source: parent
color: bellImg.hovered ? Style.current.textColor : Style.current.darkGrey
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onEntered: bellImg.hovered = true
onExited: bellImg.hovered = false
onClicked: {
chatsModel.unmuteCurrentChannel()
}
}
}
Connections {
2020-12-06 22:15:51 +00:00
target: profileModel.contacts
onContactChanged: {
if(root.chatId === publicKey){
// Hack warning: Triggering reload to avoid changing the current text binding
var tmp = chatId;
chatId = "";
chatId = tmp;
}
}
}
StyledText {
id: chatInfo
color: Style.current.darkGrey
text: {
switch(root.chatType){
//% "Public chat"
case Constants.chatTypePublic: return qsTrId("public-chat")
2020-12-06 22:15:51 +00:00
case Constants.chatTypeOneToOne: return (profileModel.contacts.isAdded(root.chatId) ?
//% "Contact"
qsTrId("chat-is-a-contact") :
//% "Not a contact"
qsTrId("chat-is-not-a-contact"))
case Constants.chatTypePrivateGroupChat:
let cnt = chatsModel.activeChannel.members.rowCount();
//% "%1 members"
if(cnt > 1) return qsTrId("%1-members").arg(cnt);
//% "1 member"
return qsTrId("1-member");
default: return "...";
}
}
font.pixelSize: 12
anchors.top: chatName.bottom
}
}
}