-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
525 lines (458 loc) · 18.9 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Window 2.11
import QtQuick.Controls 2.4
import QtQuick.Controls.Styles 1.4
import UdpSender 0.0
Window {
property real mm: (Screen.pixelDensity)
property int win_width : Qt.platform.os === "android" ? Screen.width : Qt.platform.os === "ios" ? Screen.width : Screen.width*0.5
property int win_height : Qt.platform.os === "android" ? Screen.height : Qt.platform.os === "ios" ? Screen.height : Screen.height*0.75
id:root
visible: true
width: win_width
height: win_height
title: qsTr("Packet Sender")
color: "#FFFFFF"
UdpPacketSender{
id:udpSender
onCurrentDatagramChanged: {
viewMessageArea.color = "red"
console.log("################################## RECEIVED: " + currentDatagram)
viewMessageArea.text = viewMessageArea.text + currentDatagram + "\n"
}
}
Rectangle{
id: firstView
width: root.width
height: root.height
color: "#201d41"
//[FIRST COMPONENT]
GroupBox {
id:groupBoxIp
x: win_width*0.1
y: win_height*0.075
antialiasing: true
title: qsTr("Ip Address")
clip: false
Column {
spacing: 10
Rectangle{
width: win_width*0.8
height:win_height*0.08
color: "#DC143C"
radius: win_height*0.02
transformOrigin: Item.Center
TextInput {
anchors.centerIn: groupBoxIp
id: ip_label
color: "#F0F0F0"
width: win_width*0.8
height: win_height*0.08
font.italic: true
cursorVisible: false
opacity: 0.7
transformOrigin: Item.Bottom
font.pixelSize: win_height*0.04
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
validator: RegExpValidator{regExp: /^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$/} // /[0-9]+[.]+/
onEditingFinished: {
//controllo se tutto corretto, se okay mostro una spunta verde altrimenti x rossa
if(!(udpSender.analizeIp(getText(0,15))))
{
imageCorrectDestIp.visible = true
imageErrorDestIp.visible = false
}
else
{
imageCorrectDestIp.visible = false
imageErrorDestIp.visible = true
}
}
}
}
}
}
//[END FIRST COMPONENT]
//[SECOND COMPONENT]
GroupBox {
id:groupBoxPort
title: "Ip Dest Port"
x: win_width*0.1
y: win_height*0.275
clip: false
Column {
spacing: 10
Rectangle{
width: win_width*0.8
height:win_height*0.08
color: "#800000"
radius: win_height*0.02
transformOrigin: Item.Center
TextInput {
anchors.centerIn: groupBoxPort
id: port_label
color: "#F0F0F0"
width: win_width*0.8
height:win_height*0.08
font.italic: true
cursorVisible: false
opacity: 0.7
transformOrigin: Item.Bottom
font.pixelSize: win_height*0.04
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
inputMethodHints: Qt.ImhDigitsOnly
/*
^ # anchor match at start-of-line, followed by
0* # zero or more leading zeros
([1-9]) # 1 - 9
| ([1-9][0-9]) # 10 - 99
| ([1-9][0-9][0-9]) # 100 - 999
| ([1-9][0-9][0-9][0-9]) # 1000 - 9999
| ([1-5][0-9][0-9][0-9][0-9]) # 10,000 - 59,999
| (6[0-4][0-9][0-9][0-9]) # 60,000 - 64,999
| (65[0-4][0-9][0-9]) # 65,000 - 65,499
| (655[0-2][0-9]) # 65,500 - 65,529
| (6553[0-5]) # 65,530 - 65,535
$
*/
validator: RegExpValidator {regExp:/^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/} //regExp: /^([1-9]) | ([1-9][0-9]) | ([1-9][0-9][0-9]) | ([1-9][0-9][0-9][0-9]) | ([1-5][0-9][0-9][0-9][0-9]) | (6[0-4][0-9][0-9][0-9]) | (65[0-4][0-9][0-9]) | (655[0-2][0-9]) | (6553[0-5]) $ /}
onEditingFinished: {
imageCorrectPortDest.visible = true
imageErrorPortDest.visible = false
}
}
}
}
}
//[END SECOND COMPONENT]
//[THREE COMPONENT]
GroupBox {
id:groupBoxListenPort
title: "Listen Port"
x: win_width*0.1
y: win_height*0.475
clip: false
Column {
spacing: 10
Rectangle{
width: win_width*0.8
height:win_height*0.08
color: "#800000"
radius: win_height*0.02
transformOrigin: Item.Center
TextInput {
anchors.centerIn: groupBoxListenPort
id: listen_port_label
color: "#F0F0F0"
width: win_width*0.8
height:win_height*0.08
font.italic: true
cursorVisible: false
opacity: 0.7
transformOrigin: Item.Bottom
font.pixelSize: win_height*0.04
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
/*
^ # anchor match at start-of-line, followed by
0* # zero or more leading zeros
([1-9]) # 1 - 9
| ([1-9][0-9]) # 10 - 99
| ([1-9][0-9][0-9]) # 100 - 999
| ([1-9][0-9][0-9][0-9]) # 1000 - 9999
| ([1-5][0-9][0-9][0-9][0-9]) # 10,000 - 59,999
| (6[0-4][0-9][0-9][0-9]) # 60,000 - 64,999
| (65[0-4][0-9][0-9]) # 65,000 - 65,499
| (655[0-2][0-9]) # 65,500 - 65,529
| (6553[0-5]) # 65,530 - 65,535
$
*/
validator: RegExpValidator {regExp:/^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/} //regExp: /^([1-9]) | ([1-9][0-9]) | ([1-9][0-9][0-9]) | ([1-9][0-9][0-9][0-9]) | ([1-5][0-9][0-9][0-9][0-9]) | (6[0-4][0-9][0-9][0-9]) | (65[0-4][0-9][0-9]) | (655[0-2][0-9]) | (6553[0-5]) $ /}
inputMethodHints: Qt.ImhDigitsOnly
onEditingFinished: {
imageCorrectPortSrc.visible = true
imageErrorPortSrc.visible = false
}
}
}
}
}
//[END THREE COMPONENT]
//[FOUR COMPONENT]
GroupBox {
id:groupBoxMyIp
x: win_width*0.1
y: win_height*0.675
antialiasing: true
title: qsTr("My Ip Address")
clip: false
Column {
spacing: 10
Rectangle{
width: win_width*0.8
height:win_height*0.08
color: "#FFFF00"
radius: win_height*0.02
border.color: "#FFFF00"
clip: false
transformOrigin: Item.Center
Text {
id: myIp
text: udpSender.viewAllAddress()
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
padding: 0
font.capitalization: Font.SmallCaps
font.italic: true
transformOrigin: Item.Center
anchors.fill: parent
font.pixelSize:win_height*0.04
anchors.centerIn: groupBoxMyIp
}
}
}
}
//[END FOUR COMPONENT]
//[FIVE COMPONENT]
Rectangle {
id: startButton
x: win_width*0.115
y: win_height*0.875
width: win_width*0.8
height:win_height*0.08
color: "#00FF00"
radius: win_height*0.02
Text {
text: qsTr("Start")
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors.fill:parent
}
MouseArea{
anchors.fill:parent
onClicked: {
//CLICK MOUSE
if(listen_port_label.text != "")
{
if(port_label.text != "")
{
if(!(udpSender.analizeIp(ip_label.getText(0,15))))
{
//METTERE CHE QUANDO PREMO START SCORRESCHERMATA FUORI E COMPARE UNA NUOVAS CON SOLO MESSAGE E SENDER
firstViewFadeOut.start()
secondViewFadeIn.start()
secondView.visible = true
udpSender.initPacket(ip_label.getText(0,15),myIp.text,port_label.getText(0,5),listen_port_label.getText(0,15))
}
else
{
imageCorrectDestIp.visible = false
imageErrorDestIp.visible = true
}
}
else
{
imageCorrectPortDest.visible = false
imageErrorPortDest.visible = true
//aggiungere immagine errore
}
}
else
{
imageCorrectPortSrc.visible = false
imageErrorPortSrc.visible = true
//aggiungere immagine errore
}
}
}
}
//[END FIVE COMPONENT]
transformOrigin: Item.TopLeft
NumberAnimation on x {
id: firstViewFadeOut
easing.type: Easing.OutBack
to: - firstView.width
from: 0
duration: 1500
}
NumberAnimation on x {
id: firstViewFadeIn
easing.type: Easing.OutBack
to: 0
from: - firstView.width
duration: 1500
}
Component.onCompleted: {
firstViewFadeIn.stop()
firstViewFadeOut.stop()
secondViewFadeIn.stop()
secondViewFadeOut.stop()
}
Image {
id: imageCorrectDestIp
source: encodeURIComponent("/pics/GreenArrow.png")
width: groupBoxIp.height
height:groupBoxIp.height
anchors.left: groupBoxIp.left
anchors.leftMargin: win_width*0.03
visible: false
anchors.top: groupBoxIp.top
anchors.topMargin: groupBoxIp.height/7
}
Image {
id: imageErrorDestIp
source: encodeURIComponent("/pics/Error_3.png")
width: groupBoxIp.height
height:groupBoxIp.height
anchors.left: groupBoxIp.left
anchors.leftMargin: win_width*0.03
visible: false
anchors.top: groupBoxIp.top
anchors.topMargin: groupBoxIp.height/7
}
Image {
id: imageCorrectPortDest
source: encodeURIComponent("/pics/GreenArrow.png")
width: groupBoxPort.height
height:groupBoxPort.height
anchors.left: groupBoxPort.left
anchors.leftMargin: win_width*0.03
visible: false
anchors.top: groupBoxPort.top
anchors.topMargin: groupBoxPort.height/7
}
Image {
id: imageErrorPortDest
source: encodeURIComponent("/pics/Error_3.png")
width: groupBoxPort.height
height:groupBoxPort.height
anchors.left: groupBoxPort.left
anchors.leftMargin: win_width*0.03
visible: false
anchors.top: groupBoxPort.top
anchors.topMargin: groupBoxPort.height/7
}
Image {
id: imageCorrectPortSrc
source: encodeURIComponent("/pics/GreenArrow.png")
width: groupBoxListenPort.height
height:groupBoxListenPort.height
anchors.left: groupBoxListenPort.left
anchors.leftMargin: win_width*0.03
visible: false
anchors.top: groupBoxListenPort.top
anchors.topMargin: groupBoxListenPort.height/7
}
Image {
id: imageErrorPortSrc
width: groupBoxListenPort.height
height:groupBoxListenPort.height
anchors.left: groupBoxListenPort.left
anchors.leftMargin: win_width*0.03
visible: false
anchors.top: groupBoxListenPort.top
anchors.topMargin: groupBoxListenPort.height/7
}
}//[END OF FIRST VIEW]
//[START OF SECOND VIEW]
Rectangle {
id: secondView
width: root.width
height: root.height
color: "#201d41"
visible: false
TextArea{
id: viewMessageArea
width: secondView.width - (win_width*0.01)
anchors.top: parent.top
anchors.topMargin: win_height*0.005
anchors.left: parent.left
anchors.leftMargin: win_height*0.005
height: (win_height*0.75)
readOnly: true
placeholderText: qsTr("Message...")
background: Rectangle {
border.color:"#21be2b"
color: "#083045"
}
}
TextArea{
id: messageArea
width: root.width - (win_width*0.025)
anchors.top: viewMessageArea.bottom
anchors.left: secondView.left
anchors.leftMargin:win_width*0.05
anchors.bottomMargin:win_height*0.05
height:win_height*0.15
wrapMode: TextEdit.WrapAnywhere
placeholderText: qsTr(" !! Write Here !!")
}
Image {
id: imageSend
source: encodeURIComponent("/pics/send.png")
width: win_width*0.15
height: win_width*0.15
transformOrigin: Item.TopLeft
visible: true
y:messageArea.y + win_width*0.02
x: messageArea.x + messageArea.width - win_width*0.17
MouseArea{
anchors.fill: imageSend
onClicked: {
//SEND PACKET AND SEND TO VIEWMESSAGEAREA
viewMessageArea.color = "#fff44f"
messageArea.insert(messageArea.cursorPosition, " ")
messageArea.cursorPosition
console.log("################ LUNGHEZZA : " + messageArea.text.length)
udpSender.sendPacket(messageArea.getText(0,messageArea.text.length))
viewMessageArea.text = viewMessageArea.text + messageArea.getText(0,messageArea.text.length + "\n") //("<p style='color: " + "#fff44f" + ";'>" + messageArea.getText(0,messageArea.text.length) + "</p>")
console.log(viewMessageArea.text)
messageArea.remove(0,messageArea.text.length)
}
}
}
NumberAnimation on x {
id: secondViewFadeOut
easing.type: Easing.OutBack
from:0
to: secondView.width
duration: 1500
}
NumberAnimation on x {
id: secondViewFadeIn
easing.type: Easing.OutBack
from:secondView.width
to: 0
duration: 1500
}
Component.onCompleted: {
firstViewFadeIn.stop()
firstViewFadeOut.stop()
secondViewFadeIn.stop()
secondViewFadeOut.stop()
secondView.visible = false
darkModeON()
}
}//[END OF SECOND VIEW]
function darkModeON()
{
groupBoxIp.title = "<font color=\"white\">Ip Address</font>";
groupBoxPort.title = "<font color=\"white\">Ip Dest Port</font>";
groupBoxListenPort.title = "<font color=\"white\">Listen Port</font>";
groupBoxMyIp.title = "<font color=\"white\">My Ip Address</font>";
firstView.color = "#0a0a0a"
secondView.color = "#0a0a0a"
}
function darkModeOFF()
{
groupBoxIp.title = "<font color=\"black\">Ip Address</font>";
groupBoxPort.title = "<font color=\"black\">Ip Dest Port</font>";
groupBoxListenPort.title = "<font color=\"black\">Listen Port</font>";
groupBoxMyIp.title = "<font color=\"black\">My Ip Address</font>";
firstView.color = "#FFFFF0"
secondView.color = "#FFFFF0"
}
}