-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathChatBox.qml
More file actions
75 lines (65 loc) · 2.03 KB
/
Copy pathChatBox.qml
File metadata and controls
75 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Item {
id: chatBox
width: 400
height: 300
ColumnLayout {
anchors.fill: parent
spacing: 6
ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
TextArea {
id: chatArea
Layout.fillWidth: true
Layout.fillHeight: true
readOnly: true
wrapMode: TextEdit.Wrap
textFormat: TextEdit.RichText // Enable HTML rendering
text: _chatBox.chatHistory
font.pixelSize: 12
// Add padding for better text display
leftPadding: 10
rightPadding: 10
topPadding: 10
bottomPadding: 10
// Auto-scroll to bottom when new messages arrive
onTextChanged: {
cursorPosition = length
if (length > 0) {
// ensure cursor is visible
chatArea.flickableItem.contentY = chatArea.flickableItem.contentHeight - chatArea.flickableItem.height
}
}
}
}
RowLayout {
Layout.fillWidth: true
spacing: 4
TextField {
id: chatInput
Layout.fillWidth: true
placeholderText: qsTr("Type a message…")
onAccepted: {
_chatBox.sendMessage(text)
text = ""
}
}
Button {
text: qsTr("Send")
onClicked: {
_chatBox.sendMessage(chatInput.text)
chatInput.text = ""
}
}
}
Button {
text: qsTr("Clear Chat")
onClicked: {
_chatBox.clearChat()
}
}
}
}