-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.qml
237 lines (211 loc) · 5.73 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
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
import QtMultimedia 5.5
import Qt.labs.settings 1.0
import "qrc:/thymio-ar" as AR
import "qrc:/thymio-vpl2" as VPL2
ApplicationWindow {
id: window
title: qsTr("Thymio Adventure")
visible: true
width: 960
height: 600
property var vision: loader.item.vision !== undefined ? loader.item.vision : null
property var vplEditor: loader.item.vplEditor !== undefined ? loader.item.vplEditor : null
header: ToolBar {
RowLayout {
anchors.fill: parent
ToolButton {
contentItem: Image {
anchors.centerIn: parent
source: "images/ic_menu_white_24px.svg"
}
onClicked: drawer.open()
}
ToolButton {
contentItem: Image {
anchors.centerIn: parent
source: !!thymio.node ? "images/ic_connection_on1_white_24px.svg" : "images/ic_connection_off_white_24px.svg"
}
onClicked: dashelTargetSelector.open()
}
Repeater {
model: (camera.cameraStatus === Camera.ActiveStatus && vision) ? vision.landmarks : 0
delegate: ToolButton {
contentItem: Item {
Image {
source: modelData.icon
height: parent.height * 0.8
width: parent.height * 0.8
}
ProgressBar {
width: parent.width
to: 0.5
value: modelData.confidence
anchors.bottom: parent.bottom
}
}
}
}
VPL2.CompilationLabel {
vplEditor: window.vplEditor
}
ToolButton {
visible: !!vplEditor
contentItem: Image {
anchors.centerIn: parent
source: !thymio.playing ? "images/ic_play_white_48px.svg" : "images/ic_stop_white_48px.svg"
}
enabled: !!vplEditor && (vplEditor.compiler.error === "") && (thymio.node !== undefined)
onClicked: thymio.playing = !thymio.playing
}
ToolButton {
visible: !!vplEditor
contentItem: Image {
anchors.centerIn: parent
source: (!!vplEditor && vplEditor.minimized) ? "images/ic_edit_mode_white_24px.svg" : "images/ic_ar_mode_white_24px.svg"
}
onClicked: vplEditor.minimized = !vplEditor.minimized;
}
}
}
Rectangle {
anchors.fill: parent
color: "#200032"
}
Camera {
id: camera
captureMode: Camera.CaptureViewfinder
cameraState: Camera.LoadedState
//deviceId: QtMultimedia.availableCameras[1].deviceId // hack to use second camera on laptop
}
property rect cameraRect
VideoOutput {
id: videoOutput
anchors.fill: parent
source: camera
filters: vision ? [ vision ] : []
fillMode: VideoOutput.PreserveAspectCrop
onContentRectChanged: cameraRect = mapNormalizedRectToItem(Qt.rect(0, 0, 1, 1));
}
Loader {
id: loader
source: "Mission1.qml"
anchors.fill: parent
Settings {
property alias source: loader.source
}
}
ListModel {
id: menuItems
ListElement { title: qsTr("world map"); source: "Map.qml"; icon: "images/ic_map_white_24px.svg"}
ListElement { title: qsTr("free play"); source: "ThymioVpl2Live.qml" ; icon: "images/ic_freeplay_white_24px.svg" }
ListElement { title: qsTr("load program"); save: false; icon: "images/ic_freeplay_white_24px.svg" }
ListElement { title: qsTr("save program"); save: true; icon: "images/ic_freeplay_white_24px.svg" }
ListElement { title: qsTr("new program"); newProgram: true; icon: "images/ic_freeplay_white_24px.svg" }
ListElement { title: qsTr("about"); source: "About.qml" ; icon: "images/ic_info_white_24px.svg" }
}
Drawer {
id: drawer
edge: Qt.LeftEdge
position: 0
width: 280
height: window.height
contentItem: Pane {
ListView {
id: listView
currentIndex: -1
anchors.fill: parent
model: menuItems
delegate: ItemDelegate {
contentItem: Row {
spacing: 24
VPL2.HDPIImage {
source: icon
width: 24
height: 24
opacity: enabled ? 1.0 : 0.5
}
Text {
text: model.title
font.pixelSize: 14
font.weight: Font.Medium
color: Material.primaryTextColor
opacity: enabled ? 1.0 : 0.5
}
}
text: model.title
highlighted: ListView.isCurrentItem
enabled: {
if (source === undefined) {
// load/save
return !!vplEditor;
} else {
// link to a QML file
return (loader.source.toString().indexOf(source) === -1);
}
}
onClicked: {
if (source === undefined) {
if (newProgram === true) {
// new program
vplEditor.clearProgram();
saveProgramDialog.programName = "";
} else {
// load/save dialog
saveProgramDialog.isSave = save;
saveProgramDialog.visible = true;
}
} else {
// link to a QML file, load this file
if (listView.currentIndex != index) {
listView.currentIndex = index;
loader.source = source;
}
}
drawer.close()
}
}
ScrollIndicator.vertical: ScrollIndicator { }
}
}
}
VPL2.DashelTargetDialog {
id: dashelTargetSelector
aseba: aseba
}
VPL2.LoadSaveDialog {
id: saveProgramDialog
vplEditor: window.vplEditor
}
VPL2.Aseba {
id: aseba
onTargetChanged: console.log("target", target)
onUserMessage: {
if (type !== 0) {
return;
}
if (vplEditor === undefined) {
return;
}
vplEditor.compiler.execTransition(data[0], data[1]);
}
}
Connections {
target: vplEditor ? vplEditor.compiler : null
onSourceChanged: thymio.playing = false
}
VPL2.Thymio {
id: thymio
property bool playing: false
events: vplEditor ? vplEditor.compiler.events : {}
source: playing ? vplEditor.compiler.source : ""
onNodeChanged: if (!playing) { playing = false; }
onPlayingChanged: if (vplEditor !== undefined) { vplEditor.compiler.execReset(playing); }
onErrorChanged: if (error !== "") { vplEditor.compiler.error = error; }
}
}