-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
159 lines (124 loc) · 4.62 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
import EvoBotTest 1.0
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Window 2.3
ApplicationWindow {
readonly property string allActions: "LLLLRRRRFFFFBBBBUDOCSEEEEEEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
width: 1024
height: 768
visible: true
font.pointSize: 16
ColumnLayout {
Label {
text: {
var text = "%1 (service state: %2)".arg(_evobot.stateName(_evobot.state)).arg(_evobot.robotService.state);
if (_evobot.state == Controller.ErrorState)
text += " - " + _evobot.errorString;
return text;
}
}
Label {
text: "current sound: " + _evobot.robotService.currentSound
}
}
GridLayout {
anchors.centerIn: parent
enabled: _evobot.state === Controller.ConnectedState
opacity: enabled ? 1 : 0.5
Behavior on opacity { NumberAnimation {} }
Repeater {
model: allActions.length
Button {
readonly property string action: allActions.charAt(modelData)
readonly property int force: {
if (modelData < 16)
return modelData % 4;
if (action === "V")
return modelData - allActions.indexOf("V");
if (action === "E")
return modelData - allActions.indexOf("E");
return -1;
}
Layout.column: {
switch(action) {
case "L": return 3 - force;
case "R": return 5 + force;
case "F":
case "B":
case "S": return 4;
case "C": return 0;
case "U":
case "D": return 1;
case "O": return 2;
case "E": return force % 2 + 1
case "V": return force % 4 + 6
}
}
Layout.row: {
switch(action) {
case "F": return 4 - force;
case "B": return 6 + force;
case "L":
case "R":
case "S": return 5;
case "O":
case "C": return 2;
case "U": return 1;
case "D": return 3;
case "E": return force / 2 + 7;
case "V": return force / 4 + (force >= 16 ? 3 : 0)
}
}
Layout.fillWidth: true
checkable: action === "V"
checked: action === "V" && Math.max(0, _evobot.robotService.currentSound) === force
enabled: action !== "V" || force === 0 || _evobot.robotService.currentSound <= 0
font.pointSize: 20
text: action + (force >= 0 ? force : "")
onPressed: {
if (action !== "V" && action != "E")
_evobot.robotService.startAction(action, force);
}
onReleased: {
if (action !== "V" && action != "E")
_evobot.robotService.stopAction(action, force);
}
onClicked: {
if (action === "V" || action == "E")
_evobot.robotService.startAction(action, force);
}
onPressAndHold: {
if (action === "V")
_evobot.robotService.playLoop(force, true);
}
}
}
RowLayout {
Layout.column: 0
Layout.columnSpan: 10
Layout.row: 11
Repeater {
id: messageRepeater
model: 6
TextField {
Layout.fillWidth: true
//inputMask: "#dd9"
inputMethodHints: Qt.ImhPreferNumbers
text: _evobot.robotService.currentMessage[modelData]
validator: IntValidator { bottom: -128; top: 127 }
maximumLength: 3
}
}
Button {
text: "Send"
onClicked: {
var message = [];
for (var i = 0; i < messageRepeater.count; ++i)
message.push(parseInt(messageRepeater.itemAt(i).text));
_evobot.robotService.currentMessage = message;
}
}
}
}
}