add workground funcation
[apps/homescreen.git] / homescreen / qml / StatusArea.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
4  * Copyright (c) 2017, 2018 TOYOTA MOTOR CORPORATION
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import QtQuick 2.2
20 import QtQuick.Layouts 1.1
21 import HomeScreen 1.0
22
23 Item {
24     id: root
25     width: 295
26     height: 218
27
28     property date now: new Date
29     Timer {
30         interval: 100; running: true; repeat: true;
31         onTriggered: root.now = new Date
32     }
33
34     Connections {
35         target: weather
36
37         onConditionChanged: {
38             var icon = ''
39
40             if (condition.indexOf("clouds") != -1) {
41                 icon = "WeatherIcons_Cloudy-01.png"
42             } else if (condition.indexOf("thunderstorm") != -1) {
43                 icon = "WeatherIcons_Thunderstorm-01.png"
44             } else if (condition.indexOf("snow") != -1) {
45                 icon = "WeatherIcons_Snow-01.png"
46             } else if (condition.indexOf("rain") != -1) {
47                 icon = "WeatherIcons_Rain-01.png"
48             }
49
50             condition_item.source = icon ? './images/Weather/' + icon : ''
51         }
52
53         onTemperatureChanged: {
54             temperature_item.text = temperature.split(".")[0] + '°F'
55         }
56     }
57
58     RowLayout {
59         anchors.fill: parent
60         spacing: 0
61         Item {
62             Layout.fillWidth: true
63             Layout.fillHeight: true
64             Layout.preferredWidth: 295 - 76
65             ColumnLayout {
66                 anchors.fill: parent
67                 anchors.margins: 40
68                 spacing: 0
69                 Text {
70                     Layout.fillWidth: true
71                     Layout.fillHeight: true
72                     text: Qt.formatDate(now, 'dddd').toUpperCase()
73                     font.family: 'Roboto'
74                     font.pixelSize: 13
75                     color: 'white'
76                     verticalAlignment:  Text.AlignVCenter
77 //                    Rectangle {
78 //                        anchors.fill: parent
79 //                        anchors.margins: 5
80 //                        color: 'red'
81 //                        border.color: 'blue'
82 //                        border.width: 1
83 //                        z: -1
84 //                    }
85                 }
86                 Text {
87                     Layout.fillWidth: true
88                     Layout.fillHeight: true
89                     text: Qt.formatTime(now, 'h:mm ap').toUpperCase()
90                     font.family: 'Roboto'
91                     font.pixelSize: 40
92                     color: 'white'
93                     horizontalAlignment:  Text.AlignHCenter
94                     verticalAlignment:  Text.AlignVCenter
95                 }
96                 RowLayout {
97                     Layout.fillWidth: true
98                     Layout.fillHeight: true
99                     Layout.preferredHeight: 20
100                     Image {
101                         id: condition_item
102                         source: './images/Weather/WeatherIcons_Rain-01.png'
103                     }
104                     Text {
105                         id: temperature_item
106                         text: '64°F'
107                         color: 'white'
108                         font.family: 'Helvetica'
109                         font.pixelSize: 32
110                     }
111                 }
112                 MouseArea {
113                     anchors.fill: parent
114                     onClicked: {
115                         homescreenHandler.killRunningApplications()
116                     }
117                 }
118             }
119         }
120         ColumnLayout {
121             id: icons
122             Layout.fillWidth: true
123             Layout.fillHeight: true
124             Layout.preferredWidth: 76
125             spacing: -10
126             Rectangle {
127                 Layout.preferredWidth: 77
128                 Layout.preferredHeight: 55
129                 opacity: 0
130             }
131             Image {
132                 id: bt_icon
133                 Layout.preferredWidth: 77
134                 Layout.preferredHeight: 55
135                 source: connStatus ? './images/Status/HMI_Status_Bluetooth_On-01.png' : './images/Status/HMI_Status_Bluetooth_Inactive-01.png'
136                 fillMode: Image.PreserveAspectFit
137                 property string deviceName: "none"
138                 property bool connStatus: false
139                 Connections {
140                     target: bluetooth
141                     onConnectionEvent: {
142                         console.log("onConnectionEvent", data.Status)
143                         if (data.Status === "connected") {
144                             bt_icon.connStatus = true
145                         } else if (data.Status === "disconnected") {
146                             bt_icon.connStatus = false
147                         }
148                     }
149                     onDeviceUpdateEvent: {
150                         console.log("onConnectionEvent", data.Paired)
151                         if (data.Paired === "True" && data.Connected === "True") {
152                             bt_icon.deviceName = data.name
153                             bt_icon.connStatus = true
154                         } else {
155                             if(bt_icon.deviceName === data.Name)
156                             {
157                                 bt_icon.connStatus = false
158                             }
159                         }
160                     }
161                 }
162             }
163
164             Repeater {
165                 model: StatusBarModel { objectName: "statusBar" }
166                 delegate: Image {
167                     Layout.preferredWidth: 77
168                     Layout.preferredHeight: 55
169                     source: model.modelData
170                     fillMode: Image.PreserveAspectFit
171                 }
172             }
173         }
174     }
175 }