108 lines
2.5 KiB
QML
108 lines
2.5 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Controls 2.3
|
|
import QtQuick.Layouts 1.3
|
|
import Dcchat 1.0
|
|
import DCStyle 1.0
|
|
|
|
import "MessageArea.js" as MS
|
|
Rectangle {
|
|
|
|
// default property alias data: view.data
|
|
id: mess_area
|
|
required property int chat_id
|
|
signal loadMoreData();
|
|
property alias model: model
|
|
color: MessStyle.mess.background
|
|
Layout.fillWidth: true
|
|
ChatRoomModel {
|
|
id:model
|
|
chatid: chat_id
|
|
}
|
|
MessageModel {
|
|
id:mess
|
|
chatid: chat_id
|
|
}
|
|
ColumnLayout {
|
|
anchors.fill: parent
|
|
Rectangle {
|
|
Layout.fillWidth: true
|
|
height: 40
|
|
color: "green"
|
|
z:2
|
|
Text {
|
|
id: banner
|
|
anchors.fill: parent
|
|
color: "white"
|
|
verticalAlignment: Text.AlignVCenter
|
|
horizontalAlignment: Text.AlignHCenter
|
|
}
|
|
}
|
|
ListView {
|
|
id:view
|
|
Layout.fillHeight: true
|
|
Layout.fillWidth: true
|
|
model : model
|
|
spacing: 1
|
|
delegate: MessageItem {
|
|
width: mess_area.width
|
|
}
|
|
cacheBuffer:20
|
|
//for ScrollBar
|
|
ScrollBar.vertical: ScrollBar {
|
|
id: scroll_bar
|
|
parent: parent
|
|
}
|
|
|
|
}
|
|
Rectangle {
|
|
// send bare
|
|
z:2
|
|
Layout.fillWidth: true
|
|
height: 30
|
|
RowLayout {
|
|
anchors.fill: parent
|
|
TextArea {
|
|
id : local
|
|
height: parent.height
|
|
Layout.fillWidth: true
|
|
}
|
|
Button {
|
|
id : btn
|
|
text: "send"
|
|
onClicked: {
|
|
mess.sendText(local.text)
|
|
local.text = ""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// load more message when scroll at end
|
|
Connections {
|
|
target: view
|
|
function onMovementEnded(){
|
|
if(view.atYBeginning )
|
|
{
|
|
MS.loadMoreData()
|
|
}
|
|
|
|
}
|
|
}
|
|
// handle when have incomming mess
|
|
Connections {
|
|
target: model
|
|
function onUpdateData(){
|
|
if( view.atYEnd )
|
|
{
|
|
Qt.callLater(MS.viewChange)
|
|
}
|
|
|
|
}
|
|
}
|
|
Component.onCompleted:
|
|
{
|
|
// view.model = model
|
|
banner.text = model.chatName()
|
|
view.positionViewAtEnd()
|
|
}
|
|
}
|