11420
|
1 |
import QtQuick 2.0
|
|
2 |
import Hedgewars.Engine 1.0
|
|
3 |
|
|
4 |
Rectangle {
|
|
5 |
color: "#15193a"
|
|
6 |
radius: 8
|
|
7 |
border.width: 4
|
|
8 |
border.color: "#ea761d"
|
|
9 |
|
|
10 |
ListView {
|
|
11 |
id: chatLines
|
|
12 |
x: 0
|
|
13 |
width: parent.width - clientsList.width
|
11429
|
14 |
anchors.top: parent.top
|
|
15 |
anchors.bottom: input.top
|
11420
|
16 |
focus: true
|
|
17 |
clip: true
|
|
18 |
highlightFollowsCurrentItem: true
|
|
19 |
|
|
20 |
model: ListModel {
|
|
21 |
id: chatLinesModel
|
|
22 |
}
|
|
23 |
|
|
24 |
delegate: Rectangle {
|
|
25 |
id: chatLinesDelegate
|
|
26 |
height: 24
|
|
27 |
width: parent.width
|
|
28 |
color: "transparent"
|
|
29 |
|
|
30 |
Row {
|
|
31 |
spacing: 8;
|
|
32 |
Text {
|
|
33 |
color: "#ffffa0"
|
|
34 |
text: nick
|
|
35 |
|
|
36 |
MouseArea {
|
|
37 |
z: 1
|
|
38 |
anchors.fill: parent
|
|
39 |
onClicked: ;
|
|
40 |
}
|
|
41 |
}
|
|
42 |
Text {
|
|
43 |
color: "#ffffff"
|
11428
|
44 |
text: line
|
11420
|
45 |
|
|
46 |
MouseArea {
|
|
47 |
z: 1
|
|
48 |
anchors.fill: parent
|
|
49 |
onClicked: ;
|
|
50 |
}
|
|
51 |
}
|
|
52 |
}
|
|
53 |
|
|
54 |
}
|
|
55 |
|
11421
|
56 |
function addLine(nickname, line) {
|
11428
|
57 |
chatLinesModel.append({"nick" : nickname, "line": line})
|
11421
|
58 |
if(chatLinesModel.count > 200)
|
|
59 |
chatLinesModel.remove(0)
|
|
60 |
chatLines.currentIndex = chatLinesModel.count - 1
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
TextInput {
|
|
65 |
id: input
|
|
66 |
x: 0
|
|
67 |
width: chatLines.width
|
|
68 |
height: 24
|
11429
|
69 |
anchors.bottom: parent.bottom
|
11421
|
70 |
color: "#eccd2f"
|
|
71 |
|
|
72 |
onAccepted: {
|
|
73 |
HWEngine.sendChatMessage(text)
|
|
74 |
chatLines.addLine("me", text)
|
|
75 |
text = ""
|
11420
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
ListView {
|
|
80 |
id: clientsList
|
|
81 |
x: parent.width - width
|
|
82 |
width: 100
|
|
83 |
height: parent.height
|
|
84 |
focus: true
|
|
85 |
clip: true
|
|
86 |
|
|
87 |
model: ListModel {
|
|
88 |
id: chatClientsModel
|
|
89 |
}
|
|
90 |
|
|
91 |
delegate: Rectangle {
|
|
92 |
id: chatClientDelegate
|
|
93 |
height: 24
|
|
94 |
width: parent.width
|
|
95 |
color: "transparent"
|
|
96 |
|
|
97 |
Row {
|
|
98 |
Text {
|
|
99 |
color: "#ffffff"
|
|
100 |
text: name
|
|
101 |
|
|
102 |
MouseArea {
|
|
103 |
z: 1
|
|
104 |
anchors.fill: parent
|
|
105 |
onClicked: ;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
}
|
11429
|
111 |
}
|
11420
|
112 |
|
11429
|
113 |
function addChatLine(nickname, line) {
|
|
114 |
chatLines.addLine(nickname, line)
|
|
115 |
}
|
11420
|
116 |
|
11429
|
117 |
function addClient(clientName) {
|
|
118 |
chatClientsModel.append({"isAdmin": false, "name": clientName})
|
|
119 |
chatLines.addLine("***", qsTr("%1 joined").arg(clientName))
|
|
120 |
}
|
|
121 |
|
|
122 |
function removeClient(clientName, reason) {
|
|
123 |
var i = chatClientsModel.count - 1;
|
|
124 |
while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
|
|
125 |
|
|
126 |
if(i >= 0) {
|
|
127 |
chatClientsModel.remove(i, 1);
|
|
128 |
chatLines.addLine("***", qsTr("%1 quit (%2)").arg(clientName).arg(reason))
|
11420
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
|