use new web view for each iteration; move main screen from HTML to QML
[YOB2RHWY.git] / main.qml
blob2689f107f4700337dbb29107d49aecd414bdc369
1 import QtQuick 2.0
2 import QtWebEngine 1.3
4 Rectangle {
5         id: rootItem
6         property WebEngineView webView
8         anchors.fill: parent
9         color: "#C9F8FE"
11         Text {
12                 anchors.centerIn: parent
13                 text: "bitte würfeln"
14                 font.pixelSize: 100
15                 color: "#333333"
16                 focus: false
17         }
19         function loadURL(u) {
20                 if (rootItem.webView) rootItem.webView.destroy()
21                 rootItem.webView = webComponent.createObject(rootItem)
22                 rootItem.webView.url = u
23         }
25         Component.onCompleted: rootItem.forceActiveFocus()
27         Keys.onPressed: {
28                 if (event.modifiers & Qt.ControlModifier) {
29                         switch (event.key) {
30                                 case Qt.Key_0: if (rootItem.webView) {
31                                         rootItem.webView.destroy()
32                                         rootItem.forceActiveFocus()
33                                 }
34                                 break;
35                                 case Qt.Key_1: rootItem.loadURL("http://quiz.zeit.de/#/quiz/1239")
36                                 break;
37                                 case Qt.Key_2: rootItem.loadURL("http://quiz.zeit.de/#/quiz/1246")
38                                 break;
39                                 case Qt.Key_3: rootItem.loadURL("http://quiz.zeit.de/#/quiz/1248")
40                                 break;
41                                 case Qt.Key_4: rootItem.loadURL("http://quiz.zeit.de/#/quiz/1258")
42                                 break;
43                                 case Qt.Key_5: rootItem.loadURL("http://quiz.zeit.de/#/quiz/1269")
44                                 break;
45                                 case Qt.Key_6: rootItem.loadURL("http://quiz.zeit.de/#/quiz/1280")
46                                 break;
47                         }
48                 }
49                 event.accepted = true
50         }
52         property Component webComponent: WebEngineView {
53                 anchors.fill: parent
54                 profile: WebEngineProfile {
55                         offTheRecord: true
56                 }
57         }