moment/harmonyqml/components/Chat/Chat.qml

108 lines
2.7 KiB
QML
Raw Normal View History

2019-03-22 14:28:14 +11:00
import QtQuick 2.7
import QtQuick.Layouts 1.3
import "../Base"
import "Banners"
import "RoomEventList"
2019-05-13 03:17:42 +10:00
import "RoomSidePane"
2019-03-22 14:28:14 +11:00
2019-05-13 03:17:42 +10:00
HColumnLayout {
2019-04-22 00:44:04 +10:00
property string userId: ""
property string category: ""
2019-04-22 00:44:04 +10:00
property string roomId: ""
2019-03-22 14:28:14 +11:00
2019-04-22 00:44:04 +10:00
readonly property var roomInfo:
Backend.accounts.get(userId)
.roomCategories.get(category)
.rooms.get(roomId)
2019-04-15 06:12:07 +10:00
readonly property var sender: Backend.users.get(userId)
readonly property bool hasUnknownDevices:
category == "Rooms" ?
Backend.clients.get(userId).roomHasUnknownDevices(roomId) : false
id: chatPage
2019-03-22 14:28:14 +11:00
onFocusChanged: sendBox.setFocus()
Component.onCompleted: Backend.signals.roomCategoryChanged.connect(
function(forUserId, forRoomId, previous, now) {
if (chatPage && forUserId == userId && forRoomId == roomId) {
chatPage.category = now
}
}
)
2019-05-13 03:17:42 +10:00
RoomHeader {
id: roomHeader
displayName: roomInfo.displayName
topic: roomInfo.topic || ""
Layout.fillWidth: true
Layout.preferredHeight: HStyle.avatar.size
2019-05-13 03:17:42 +10:00
}
2019-04-22 00:44:04 +10:00
2019-05-13 03:17:42 +10:00
HSplitView {
id: chatSplitView
2019-05-13 03:17:42 +10:00
Layout.fillWidth: true
Layout.fillHeight: true
HColumnLayout {
Layout.fillWidth: true
2019-04-22 00:44:04 +10:00
2019-05-13 03:17:42 +10:00
RoomEventList {
Layout.fillWidth: true
Layout.fillHeight: true
}
2019-05-13 03:17:42 +10:00
TypingMembersBar {}
2019-05-13 03:17:42 +10:00
InviteBanner {
visible: category === "Invites"
inviter: roomInfo.inviter
}
2019-05-13 03:17:42 +10:00
UnknownDevicesBanner {
visible: category == "Rooms" && hasUnknownDevices
}
SendBox {
id: sendBox
visible: category == "Rooms" && ! hasUnknownDevices
}
2019-05-13 03:17:42 +10:00
LeftBanner {
visible: category === "Left"
leftEvent: roomInfo.leftEvent
}
}
2019-05-13 03:17:42 +10:00
RoomSidePane {
id: roomSidePane
collapsed: width < Layout.minimumWidth + 8
property int parentWidth: parent.width
property int collapseBelow: 120
function set_width() {
width = parent.width * 0.3 < collapseBelow ?
Layout.minimumWidth : Math.min(parent.width * 0.3, 300)
}
onParentWidthChanged:
if (chatSplitView.canAutoSize) { set_width() }
2019-05-13 03:17:42 +10:00
width: set_width() // Initial width
Layout.minimumWidth: HStyle.avatar.size
2019-05-13 03:17:42 +10:00
Layout.maximumWidth: parent.width
Behavior on width {
NumberAnimation {
duration: chatSplitView.canAutoSize ? 120 : 0
}
}
2019-05-13 03:17:42 +10:00
}
2019-04-22 00:44:04 +10:00
}
2019-03-22 14:28:14 +11:00
}