-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathmain.qml
170 lines (160 loc) · 4.84 KB
/
main.qml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 1.4 as Ctrl1
import QtMultimedia 5.12
import TalkModel 1.0
//聊天框练习
//龚建波 2021-3-29
Window {
visible: true
width: 720
height: 820
title: qsTr("聊天框练习 by:龚建波 1992")
TalkListModel{
id: talk_model
onModelReset: {
talk_player.stop();
update_timer.start();
}
onRowsInserted: {
talk_player.stop();
update_timer.start();
}
}
MediaPlayer{
id: talk_player
//只是标记下当前播放对象
property int currentId: -1
}
Timer{
id: update_timer
interval: 0
repeat: false
onTriggered: {
//对应版本Qt5.13.1
//positionViewAtEnd有问题,新增的大小受上次最后一项大小的影响
//如果上次更短就没法滑倒底部
//talk_view.positionViewAtEnd();
talk_view.currentIndex=talk_view.count-1;
}
}
Ctrl1.SplitView{
anchors.fill: parent
anchors.margins: 10
orientation: Qt.Vertical
handleDelegate: Rectangle{
height: 10
}
Rectangle{
Layout.fillHeight: true
Layout.fillWidth: true
radius: 4
border.color: "gray"
color: "#EEEEEE"
//消息列表
TalkListView{
id: talk_view
anchors.fill: parent
anchors.margins: 10
model: talk_model
talkModel: talk_model
audioPlayer: talk_player
}
}
Rectangle{
height: 220
Layout.fillWidth: true
radius: 4
border.color: "gray"
Row{
x: 10
y: 10
spacing: 10
//数据类型
ComboBox{
id: send_type
model: ["text","audio"]
currentIndex: 0
}
//清空
Button{
text: "Clear"
onClicked: {
text_area.clear();
talk_model.clearModel();
}
}
}
//文本编辑框
TextArea{
id: text_area
text: "龚建波 1992 测试!啊实打实打算"+
"asdasasd啊实打实大苏打啊实打实"+
"啊实打实大苏打按时大苏20210329"
anchors{
fill: parent
leftMargin: 10
rightMargin: 10
topMargin: 60
bottomMargin: 60
}
font{
family: "Microsoft YaHei"
pixelSize: 14
}
color: "#666666"
selectByMouse: true
selectionColor: "black"
selectedTextColor: "white"
wrapMode: TextInput.WrapAnywhere
background: Rectangle{
border.color: "gray"
}
}
//A发送
Button{
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: 10
text: "A Send"
onClicked: {
switch(send_type.currentText){
case "text":
if(true){ //M115
if(text_area.text.length<1)
return;
talk_model.appendText("B","A",text_area.text);
}break;
case "audio":
if(true){
talk_model.appendAudio("B","A");
}break;
}
}
}//end Button
//B发送
Button{
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 10
text: "B Send"
onClicked: {
switch(send_type.currentText){
case "text":
if(true){ //M115
if(text_area.text.length<1)
return;
talk_model.appendText("B","B",text_area.text);
}break;
case "audio":
if(true){
talk_model.appendAudio("B","B");
}break;
}
}
}//end Button
}
}
}