Add onscreenapp
[apps/onscreenapp.git] / app / main.qml
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  
17 import QtQuick 2.6
18 import QtQuick.Window 2.2
19 import QtQuick.Layouts 1.1
20 import QtQuick.Controls 2.0
21 import AGL.Demo.Controls 1.0
22 import OnScreenModel 1.0
23
24 Window {
25     id: root
26     flags: Qt.FramelessWindowHint
27     visible: true
28     x: 0
29     y:  218
30     width: 1080
31     height: 1488
32     color: '#00000000'
33
34     Onscreen {
35         id: ons
36         anchors.centerIn: parent
37         visible: true
38         scale: 0
39
40         property string dsp_sts: "hide"
41         property string dsp_title: ""
42         property string dsp_icon: ""
43         property string dsp_contents: ""
44         property int btnNum: 0
45         property string btn1Name: ""
46         property string btn2Name: ""
47         property string btn3Name: ""
48
49         states: [
50             State {
51                 name: 'active'
52                 when: ons.dsp_sts == "show"
53                 PropertyChanges {
54                     target: ons
55                     scale: 1
56                     z: 1
57                 }
58             },
59             State {
60                 name: 'inactive'
61                 when: ons.dsp_sts == "hide"
62                 PropertyChanges {
63                     target: ons
64                     scale: 0
65                     z: -1
66                 }
67             }
68         ]
69         transitions: Transition {
70             NumberAnimation {
71                 properties: 'scale';
72                 duration: 300;
73                 easing.type: Easing.Linear
74                 alwaysRunToEnd: true
75             }
76         }
77     }
78
79     OnScreenModel {
80         id: onscreenModel
81     }
82
83     Timer {
84         id: ons_timer
85         interval: 3000
86         onTriggered: {
87             hideOnScreen();
88             clearOnScreenModel();
89         }
90     }
91
92     Connections {
93         target: ons
94         onScaleChanged : {
95             if(ons.scale == 0) {
96                 console.log(qsTr('hide animation finished'));
97                 eventHandler.deactivateWindow();
98             }
99         }
100     }
101
102     function showOnScreen() {
103         console.log(qsTr('show onscreenapp'));
104         ons.dsp_title = onscreenModel.getTitle()
105         ons.dsp_icon = "../images/" + onscreenModel.getType() + ".svg"
106         ons.dsp_contents = onscreenModel.getContents()
107         ons.btnNum = onscreenModel.buttonNum()
108         ons.btn1Name = onscreenModel.buttonName(0)
109         ons.btn2Name = onscreenModel.buttonName(1)
110         ons.btn3Name = onscreenModel.buttonName(2)
111         ons_timer.running =  ons.btnNum > 0 ? false : true
112         ons.dsp_sts = "show"
113     }
114
115     function hideOnScreen() {
116         console.log(qsTr('hide onscreenapp'));
117         ons.dsp_sts = "hide"
118         ons_timer.running = false
119     }
120
121     function setOnScreenModel(data) {
122         console.log(qsTr('onscreenapp >>> setModel status: ' + data));
123         onscreenModel.setModel(data)
124     }
125 }