status-desktop/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml

66 lines
1.8 KiB
QML
Raw Normal View History

2020-05-28 22:22:51 +00:00
import QtQuick 2.14
import QtQuick.Controls 2.3
2020-05-28 22:22:51 +00:00
import QtQuick.Controls 2.14 as QQC2
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.1
import "../../../../shared"
import "../../../../imports"
2020-05-28 17:34:54 +00:00
import "./samples/"
2020-05-28 22:22:51 +00:00
ScrollView {
2020-05-28 17:34:54 +00:00
property var messageList: MessagesData {}
2020-05-28 22:22:51 +00:00
anchors.fill: parent
Layout.fillWidth: true
Layout.fillHeight: true
2020-05-28 22:22:51 +00:00
ScrollBar.vertical.policy: chatLogView.contentHeight > chatLogView.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
2020-06-04 19:07:07 +00:00
SortFilterModel {
id: messageListDelegate
lessThan: function(left, right) {
return left.clock < right.clock;
}
2020-05-28 22:22:51 +00:00
model: messageList
delegate: Message {
userName: model.userName
message: model.message
identicon: model.identicon
isCurrentUser: model.isCurrentUser
repeatMessageInfo: model.repeatMessageInfo
timestamp: model.timestamp
sticker: model.sticker
contentType: model.contentType
}
2020-06-04 19:07:07 +00:00
}
2020-05-28 22:22:51 +00:00
2020-06-04 19:07:07 +00:00
ListView {
anchors.fill: parent
spacing: 4
id: chatLogView
model: messageListDelegate
Layout.fillWidth: true
Layout.fillHeight: true
highlightFollowsCurrentItem: true
2020-05-28 22:22:51 +00:00
onCountChanged: {
if (!this.atYEnd) {
// User has scrolled up, we don't want to scroll back
return
}
2020-05-28 22:22:51 +00:00
// positionViewAtEnd doesn't work well. Instead, we use highlightFollowsCurrentItem
// and set the current Item/Index to the latest item
while (this.currentIndex < this.count - 1) {
this.incrementCurrentIndex()
}
}
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/