-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.qml
412 lines (380 loc) · 10.4 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
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtGraphicalEffects 1.0
import Qt.labs.settings 1.0
import QtQml 2.2
import "qrc:/thymio-vpl2"
ApplicationWindow {
id: window
title: qsTr("Thymio VPL Mobile Preview")
visible: true
width: 960
height: 600
Material.primary: Material.theme === Material.Dark ? "#200032" : Material.background // "#a3d9db"
property string linkRichTextStyle: Material.theme === Material.Dark ?
"<style>a:link { text-decoration: none; color: \"#90CAF9\" }</style>" :
"<style>a:link { text-decoration: none; color: \"#3F51B5\" }</style>"
Material.accent: Material.theme === Material.Dark ? "#9478aa" : "#B290CC" // "#59cbc8"
Material.background: Material.theme === Material.Dark ? "#ff44285a" : "white"
header: vplEditor.blockEditorVisible ? blockEditorTitleBar : vplEditorTitleBar
readonly property string autosaveName: qsTr("autosave");
EditorTitleBar {
id: vplEditorTitleBar
visible: !vplEditor.blockEditorVisible
vplEditor: vplEditor
isThymioConnected: !!thymio.node
onOpenDrawer: drawer.open()
onOpenDashelTargetSelector: dashelTargetSelector.open()
}
BlockEditorTitleBar {
id: blockEditorTitleBar
visible: vplEditor.blockEditorVisible
onCancel: vplEditor.blockEditor.close()
onAccept: vplEditor.blockEditor.accept()
okEnabled: vplEditor.blockEditorDefinition
}
Editor {
id: vplEditor
anchors.fill: parent
// Text {
// text: "developer preview pre-alpha, no feature or design is final"
// anchors.left: parent.left
// anchors.leftMargin: 106
// anchors.top: parent.top
// anchors.topMargin: 10
// color: Material.primaryTextColor
// }
}
// improve using: https://appbus.wordpress.com/2016/05/20/one-page-sample-app/
FloatingActionButton {
property int distToBorders: isMini ? 16 : 24
anchors.right: parent.right
anchors.rightMargin: (isMini ? 64 : 96) + distToBorders
anchors.bottom: parent.bottom
anchors.bottomMargin: distToBorders
isMini: window.width <= 460
/*anchors.top: parent.top
anchors.topMargin: -height/2
z: 2*/
imageSource: !thymio.playing ? "qrc:/thymio-vpl2/icons/ic_play_arrow_white_24px.svg" : "qrc:/thymio-vpl2/icons/ic_stop_white_24px.svg"
visible: !vplEditor.blockEditorVisible
onClicked: thymio.playing = !thymio.playing
enabled: (vplEditor.compiler.output.error === undefined) && (thymio.node !== undefined)
//opacity: enabled ? 1.0 : 0.38
}
Connections {
target: vplEditor.compiler
onOutputChanged: thymio.playing = false
}
ListModel {
id: menuItems
ListElement {
title: QT_TR_NOOP("load program");
callback: "load";
whiteIcon: "qrc:/thymio-vpl2/icons/ic_open_white_24px.svg";
blackIcon: "qrc:/thymio-vpl2/icons/ic_open_black_24px.svg";
}
function load() {
saveProgramDialog.isSave = false;
saveProgramDialog.visible = true;
}
ListElement {
title: QT_TR_NOOP("save program");
callback: "save";
whiteIcon: "qrc:/thymio-vpl2/icons/ic_save_white_24px.svg";
blackIcon: "qrc:/thymio-vpl2/icons/ic_save_black_24px.svg";
}
function save() {
saveProgramDialog.isSave = true;
saveProgramDialog.visible = true;
}
ListElement {
title: QT_TR_NOOP("new program");
callback: "newProgram";
whiteIcon: "qrc:/thymio-vpl2/icons/ic_new_white_24px.svg";
blackIcon: "qrc:/thymio-vpl2/icons/ic_new_black_24px.svg";
}
function newProgram() {
vplEditor.clearProgram();
saveProgramDialog.programName = "";
}
ListElement {
title: QT_TR_NOOP("switch color theme");
callback: "switchColorTheme";
whiteIcon: "qrc:/thymio-vpl2/icons/ic_invert_colors_white_24px.svg";
blackIcon: "qrc:/thymio-vpl2/icons/ic_invert_colors_black_24px.svg";
}
function switchColorTheme() {
if (window.Material.theme === Material.Dark) {
window.Material.theme = Material.Light;
} else {
window.Material.theme = Material.Dark;
}
}
/*ListElement {
title: QT_TR_NOOP("switch editor mode");
callback: "switchEditorMode";
whiteIcon: "";
blackIcon: "";
}
function switchEditorMode() {
vplEditor.switchMode();
}*/
ListElement {
title: QT_TR_NOOP("about");
callback: "showAboutBox";
whiteIcon: "qrc:/thymio-vpl2/icons/ic_info_white_24px.svg";
blackIcon: "qrc:/thymio-vpl2/icons/ic_info_black_24px.svg";
}
function showAboutBox() {
aboutDialog.visible = true;
}
ListElement {
title: "dev: show aesl";
callback: "showAeslSource";
whiteIcon: "";
blackIcon: "";
visible: false;
}
function showAeslSource() {
aeslSourceDialog.visible = true;
}
}
Drawer {
id: drawer
edge: Qt.LeftEdge
position: 0
width: 300
height: window.height
contentItem: Pane {
ListView {
id: listView
currentIndex: -1
anchors.fill: parent
model: menuItems
delegate: ItemDelegate {
contentItem: Row {
spacing: 24
HDPIImage {
source: Material.theme === Material.Dark ? whiteIcon : blackIcon
width: 24
height: 24
opacity: enabled ? 1.0 : 0.5
}
Text {
text: qsTr(model.title);
font.pixelSize: 14
font.weight: Font.Medium
color: Material.primaryTextColor
opacity: enabled ? 1.0 : 0.5
visible: ((model.title.substring(0, 4) !== "dev:") || (Qt.application.arguments.indexOf("--developer") !== -1))
}
}
onClicked: {
ListView.view.model[callback]();
drawer.close()
}
}
}
}
}
DashelTargetDialog {
id: dashelTargetSelector
aseba: aseba
}
LoadSaveDialog {
id: saveProgramDialog
vplEditor: vplEditor
}
Popup {
id: aboutDialog
x: (parent.width - width) / 2
y: (parent.height - height) / 2
modal: true
padding: 24
Column {
spacing: 20
padding: 0
Label {
text: qsTr("Thymio VPL Mobile Preview")
font.pixelSize: 20
font.weight: Font.Medium
}
Label {
textFormat: Text.RichText;
text:
linkRichTextStyle +
qsTr("<p><a href=\"http://stephane.magnenat.net\">Stéphane Magnenat</a>, <a href=\"http://sampla.ch\">Martin Voelkle</a>,<br/><a href=\"http://mariamari-a.com\">Maria Beltran</a> and contributors.</p>") +
qsTr("<p>© 2015–2017 EPFL, ETH Zürich and Mobsya</p>") +
qsTr("<p>This project is open source under <a href=\"https://github.com/aseba-community/thymio-vpl2/blob/master/LICENSE.txt\">LGPL</a>.<br/>") +
qsTr("See file <a href=\"https://github.com/aseba-community/thymio-vpl2/blob/master/AUTHORS.md\">AUTHORS.md</a> in the <a href=\"https://github.com/aseba-community/thymio-vpl2\">source code</a><br/>") +
qsTr("for a detailed list of contributions.")
font.pixelSize: 14
font.weight: Font.Normal
lineHeight: 20
lineHeightMode: Text.FixedHeight
onLinkActivated: Qt.openUrlExternally(link)
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
Rectangle {
width: 100
height: 50
color: "white"
anchors.verticalCenter: parent.verticalCenter
HDPIImage {
width: 80
height: width * 0.5
fillMode: Image.PreserveAspectFit
source: "qrc:/thymio-vpl2/images/logoEPFL.svg"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: { Qt.openUrlExternally("http://mobots.epfl.ch"); }
}
}
Rectangle {
width: 100
height: 50
color: "white"
anchors.verticalCenter: parent.verticalCenter
HDPIImage {
width: 80
height: width * 0.48 // 0.38753
fillMode: Image.PreserveAspectFit
source: "qrc:/thymio-vpl2/images/logoETHGTC.svg"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: { Qt.openUrlExternally("http://www.gtc.inf.ethz.ch"); }
}
}
Rectangle {
width: 100
height: 50
color: "white"
anchors.verticalCenter: parent.verticalCenter
HDPIImage {
width: 80
height: width * 0.27348
fillMode: Image.PreserveAspectFit
source: "qrc:/thymio-vpl2/images/logoMobsya.svg"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: { Qt.openUrlExternally("http://www.mobsya.org"); }
}
}
}
}
}
// developer options for debugging
Popup {
id: aeslSourceDialog
x: (parent.width - width) / 2
y: (parent.height - height) / 2
width: 0.8 * parent.width
height: 0.8 * parent.height
modal: true
focus: true
Flickable {
anchors.fill: parent
clip: true
TextEdit {
id: aeslSourceText
text: prettyPrintGeneratedAesl(vplEditor.compiler.output.script)
color: Material.primaryTextColor
font.family: "Monospace"
readOnly: true
// TODO: move this somewhere
function prettyPrintGeneratedAesl(source) {
var level = 0;
var output = "";
var splitted = source.split("\n");
for (var i = 0; i < splitted.length; i++) {
var line = splitted[i].trim();
if ((line.indexOf("sub ") === 0) || (line.indexOf("onevent ") === 0)) {
output += "\n" + line + "\n";
level = 1;
} else {
if (line.indexOf("end") === 0) {
level -= 1;
}
for (var j = 0; j < level; j++)
output += " ";
output += line + "\n";
if (line.indexOf("if ") === 0) {
level += 1;
}
}
}
return output;
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.selectAll()
parent.copy()
parent.deselect()
}
}
}
contentWidth: aeslSourceText.paintedWidth
contentHeight: aeslSourceText.paintedHeight
ScrollBar.vertical: ScrollBar { }
ScrollBar.horizontal: ScrollBar { }
}
}
Aseba {
id: aseba
onUserMessage: {
if (type !== 0) {
return;
}
if (vplEditor === undefined) {
return;
}
vplEditor.compiler.execTransition(data[0]);
}
}
Thymio {
id: thymio
property bool playingOld : false
property bool playing: false
onNodeChanged: playing = false
onPlayingChanged: {
if (playing && !playingOld) {
start();
} else if (!playing && playingOld) {
stop();
}
playingOld = playing;
}
function start() {
vplEditor.saveProgram(autosaveName);
vplEditor.compiler.execReset(true);
var output = vplEditor.compiler.output;
program = {
events: output.events,
source: output.script,
};
}
function stop() {
vplEditor.compiler.execReset(false);
program = {
events: {},
source: "",
};
}
onErrorChanged: if (error !== "") { vplEditor.compiler.output.error = error; }
}
Component.onCompleted: {
vplEditor.loadProgram(autosaveName);
}
}