forked from penk/qml-livereload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playgrounds.qml
67 lines (59 loc) · 1.85 KB
/
playgrounds.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
import QtQuick 2.0
import QtQuick.Window 2.0
// from https://github.com/rschroll/qhttpserver
import HttpServer 1.0
Item {
id: root
width: Screen.width
height: Screen.height
HttpServer {
id: server
Component.onCompleted: listen("127.0.0.1", 5000)
onNewRequest: {
var route = /^\/\?/;
if ( route.test(request.url) ) {
response.writeHead(200)
response.write(editor.text)
response.end()
}
else {
response.writeHead(404)
response.end()
}
}
}
Timer {
id: timer
interval: 500; running: true; repeat: false
onTriggered: viewLoader.setSource('http://localhost:5000/?'+Math.random()) // workaround for cache
}
Rectangle {
id: background
width: root.width/2
height: root.height
anchors { top: parent.top; left: parent.left; bottom: parent.bottom }
color: '#1d1f21'
TextEdit {
id: editor
anchors { fill: parent; margins: 20 }
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere;
onTextChanged: timer.restart();
// style from Atom dark theme:
// https://github.com/atom/atom-dark-syntax/blob/master/stylesheets/syntax-variables.less
color: '#c5c8c6'
selectionColor: '#444444'
selectByMouse: true
font { pointSize: 16; family: 'Monaco' }
text: "import QtQuick 2.0\n" + "Rectangle { anchors.fill: parent; color: '#ff0000' }"
}
}
Item {
width: root.width/2
height: root.height
anchors { top: parent.top; left: background.right; bottom: parent.bottom }
Loader {
id: viewLoader
anchors.fill: parent
}
}
}