-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPost.qml
49 lines (42 loc) · 942 Bytes
/
Post.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
import QtQuick 2.0
Item {
id: root
width: 200
height: 0
opacity: 0
property int seed: Math.random()*1700 + 1
//http://xkcd.com/1750/
Image {
id: img
anchors.fill: parent
asynchronous: true
onSourceSizeChanged: {
root.height = sourceSize.height*root.width/sourceSize.width
root.opacity = 1
}
}
Behavior on opacity {
NumberAnimation {
duration: 400
}
}
Component.onCompleted: {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
var t = xhr.responseText
var p = t.search("<div id=\"comic\">")
t = t.slice(p)
p = t.search("src=")
t = t.slice(p+5)
p = t.search('"')
t = t.slice(0, p)
img.source = "http:"+t
console.log("http://xkcd.com/%1/".arg(root.seed))
console.log("->" + img.source)
}
}
xhr.open("GET", "http://xkcd.com/%1/".arg(root.seed))
xhr.send()
}
}