-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathTalkItemAudio.qml
165 lines (150 loc) · 5.6 KB
/
TalkItemAudio.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
import QtQuick 2.12
import QtMultimedia 5.12
import TalkModel 1.0
//音频信息delegate
//龚建波 2021-3-29
TalkItemBase {
id: control
//ColumnLayout在拉伸时计算有问题,暂时用Column+Row
Row{
width: control.contentWidth
layoutDirection: control.isUser?Qt.RightToLeft:Qt.LeftToRight
height: 50
spacing: 12
Rectangle{
radius: 4
width: 80+Math.min(210,Math.pow(model.audio_duration/1000,0.5)*20)
height: control.messageHeight
color: control.messageBgColor
//指向发言人小三角
Rectangle{
width: 10
height: 10
y: control.messageHeight/2-10
anchors.horizontalCenter: control.isUser?parent.right:parent.left
rotation: 45
color: control.messageBgColor
}
Row{
anchors{
verticalCenter: parent.verticalCenter
margins: 14
//left和right这样互斥写,属性绑定会有问题
//但是layoutDirection切换后会刷新
left: control.isUser?undefined:parent.left
right: control.isUser?parent.right:parent.undefined
}
layoutDirection: control.isUser?Qt.RightToLeft:Qt.LeftToRight
spacing: 0
AnimatedImage{
anchors.verticalCenter: parent.verticalCenter
source: (audioPlayer.playbackState===MediaPlayer.PlayingState&&
audioPlayer.currentId===index)
?"qrc:/Image/audio_playing.gif"
:"qrc:/Image/audio_20_play.png"
rotation: control.isUser?180:0
//切换source后不会自动播放
onSourceChanged: playing=true
}
TalkLabel{
anchors.verticalCenter: parent.verticalCenter
text: model.audio_durationStr
}
}
//点击播放
MouseArea{
anchors.fill: parent
onClicked: {
if(audioPlayer.playbackState===MediaPlayer.PlayingState){
audioPlayer.stop();
}else{
//source没变不能再次播放?
audioPlayer.source="";
audioPlayer.source=model.audio_path;
audioPlayer.currentId=index;
audioPlayer.play();
}
}
}
}
//转换按钮
Rectangle{
visible: (model.status!==TalkData.ParseSuccess)
anchors.verticalCenter: parent.verticalCenter
//之前放在消息rect内部了,现在作为兄弟
//anchors{
// verticalCenter: parent.verticalCenter
// margins: control.isUser?-width-12:12
// left: control.isUser?parent.left:parent.right
// //right: control.isUser?parent.left:parent.undefined
//}
height: control.messageHeight-16
width: label_item.width+24
radius: height/2
color: "#A4ACC6"
TalkLabel{
id: label_item
anchors.centerIn: parent
color: "white"
text: {
switch(model.status)
{
case TalkData.DataError: return "无效数据";
case TalkData.DataReady: return "转文字";
case TalkData.ParseOn: return " ";
case TalkData.ParseSuccess: return "转换成功";
case TalkData.ParseError: return "转换失败";
}
return " ";
}
}
AnimatedImage{
anchors.centerIn: parent
visible: (model.status===TalkData.ParseOn)
source: "qrc:/Image/audio_loading.gif"
}
MouseArea{
anchors.fill: parent
onClicked: {
//直接通过id访问外部对象
//需要处理当前是否可以点击
talkModel.parseRow(index);
}
}
}//end 转换按钮
}
Row{
width: control.contentWidth
layoutDirection: control.isUser?Qt.RightToLeft:Qt.LeftToRight
TalkLabel{
text: model.datetime
padding: 0
}
}
Row{
visible: (model.status===TalkData.ParseSuccess)
width: control.contentWidth
layoutDirection: control.isUser?Qt.RightToLeft:Qt.LeftToRight
Rectangle{
id: wrap_item
radius: 4
width: text_item.width
height: text_item.height
color: control.messageBgColor
//无文本时的警告图片
Image {
visible: model.audio_text.length<=0
x: 14
//有些情况下图片显示异常,设置透明度0.9解决了
opacity: 0.999
anchors.verticalCenter: parent.verticalCenter
source: "qrc:/Image/warn_20_red.png"
}
TalkLabel{
id: text_item
text: model.audio_text.length>0?model.audio_text:" 未识别到文字"
width: Math.min(control.contentWidth,textWidth)
}
}
}
}