-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.qml
115 lines (99 loc) · 3.12 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
// This code is released as public domain.
// -- Markus Goetz
import QtQuick 2.4
import QtQuick.Window 2.2
Window {
width: 800
height: 600
visible: true
Rectangle {
id: leftRect
ListView {
id: nodeView
model: nodeList
anchors.fill: parent
anchors.margins: 10
highlightFollowsCurrentItem: true
onCurrentItemChanged : {
chatField.text = nodeView.currentItem.log
}
focus: true
delegate: Text {
font.pointSize: 30
text: addr
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
property string log: model.log
property string addr: model.addr
height: 50
width: parent.width
MouseArea {
anchors.fill: parent
onClicked: nodeView.currentIndex = index
}
}
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
}
color: "white"
border.color: "grey"
radius:10
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: 250
}
Rectangle {
color: "white"
border.color: "grey"
radius:10
anchors.left: leftRect.right
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: inputRect.top
Text {
font.pointSize: 25
id: chatField
anchors.fill: parent
anchors.margins: 10
text: "Select a host on the left.<br>Then use the input below to send a message<br>"
}
}
Rectangle {
id: inputRect
TextInput {
id: input
font.pointSize: 25
anchors.fill: parent
anchors.margins: 10
Keys.onPressed: {
if (event.key == Qt.Key_Return) {
if (!nodeView.currentItem)
return;
var chatText = input.text;
input.text = "";
var addr = nodeView.currentItem.addr;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
nodeList.appendLog(addr, "You", chatText);
chatField.text = nodeView.currentItem.log;
}
}
var url = "http://" + addr + ":31337/chat";
request.open("POST", url);
var json = JSON.stringify({ "chat": {"message":chatText} });
console.log(json);
request.send(json);
}
}
}
color: "white"
border.color: "grey"
radius:10
anchors.left: leftRect.right
anchors.bottom: parent.bottom
anchors.right: parent.right
height: 60
focus: true
}
}