f5233397285cdc5feccc115084fb853333be012c
[apps/homescreen.git] / homescreen / qml / main.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 import QtQuick 2.2
19 import QtQuick.Window 2.1
20 import QtQuick.Layouts 1.1
21 import HomeScreen 1.0
22
23 Window {
24     visible: true
25     flags: Qt.FramelessWindowHint
26     width: container.width * container.scale
27     height: container.height * container.scale
28     title: 'HomeScreen'
29     color: "#00000000"
30
31     Image {
32         id: container
33         anchors.centerIn: parent
34         width: 1920
35         height: 720
36         scale: 1.0
37         source: './images/menubar_background.png'
38
39         ColumnLayout {
40             id: menuBar
41             anchors.fill: parent
42             spacing: 0
43             TopArea {
44                 id: topArea
45                 anchors.horizontalCenter: parent.horizontalCenter
46                 Layout.preferredHeight: 80
47                 x: 640
48             }
49
50             Item {
51                 id: applicationArea
52                 Layout.fillWidth: true
53                 Layout.fillHeight: true
54                 Layout.preferredHeight: 510
55
56                 visible: true
57                 MouseArea {
58                     enabled: true
59                 }
60             }
61
62             ShortcutArea {
63                 id: shortcutArea
64                 anchors.horizontalCenter: parent.horizontalCenter
65                 Layout.fillHeight: true
66                 Layout.preferredHeight: 130
67             }
68         }
69         states: [
70             State {
71                 name: "normal"
72                 PropertyChanges {
73                     target: container
74                     y: 0
75                 }
76                 PropertyChanges {
77                     target: topArea
78                     y: 0
79                 }
80                 PropertyChanges {
81                     target: applicationArea
82                     y: 80
83                 }
84                 PropertyChanges {
85                     target: shortcutArea
86                     y: 590
87                 }
88             },
89             State {
90                 name: "fullscreen"
91                 PropertyChanges {
92                     target: container
93                     y: -720
94                 }
95                 PropertyChanges {
96                     target: topArea
97                     y: -80
98                 }
99                 PropertyChanges {
100                     target: applicationArea
101                     y: -510
102                 }
103                 PropertyChanges {
104                     target: shortcutArea
105                     y: 720
106                 }
107             }
108         ]
109         transitions: Transition {
110             NumberAnimation {
111                 target: topArea
112                 property: "y"
113                 easing.type: "OutQuad"
114                 duration: 250
115             }
116             NumberAnimation {
117                 target: applicationArea
118                 property: "y"
119                 easing.type: "OutQuad"
120                 duration: 250
121             }
122             NumberAnimation {
123                 target: shortcutArea
124                 property: "y"
125                 easing.type: "OutQuad"
126                 duration: 250
127             }
128         }
129     }
130
131     Item {
132         id: switchBtn
133         width: 61
134         height: 61
135         anchors.right: parent.right
136         anchors.rightMargin: 17
137         anchors.top: parent.top
138         anchors.topMargin: 2
139         z: 1
140         Image {
141             id: image
142             width: 55
143             height: 55
144             anchors.centerIn: parent
145             source: './images/normal.png'
146         }
147
148         MouseArea {
149             anchors.fill: parent
150             property string btnState: 'normal'
151             onClicked: {
152                 if (container.state === 'normal') {
153                     turnToFullscreen()
154                 } else {
155                     turnToNormal()
156                 }
157             }
158         }
159     }
160
161     Item {
162         id: splitSwitchBtn
163         width: 61
164         height: 61
165         anchors.right: switchBtn.left
166         anchors.top: parent.top
167         anchors.topMargin: 2
168         z: 1
169         property bool enableSplitSwitchBtn: false
170         Image {
171             id: splitSwitchImage
172             width: 55
173             height: 55
174             anchors.centerIn: parent
175             source: './images/split_switch_disable.png'
176         }
177
178         MouseArea {
179             property bool changed : false
180             anchors.fill: parent
181             onClicked: {
182                 if (splitSwitchBtn.enableSplitSwitchBtn) {
183                     if(changed) {
184                         switchSplitArea(0)
185                         changed = false
186                     }
187                     else {
188                         switchSplitArea(1)
189                         changed = true
190                     }
191                 }
192             }
193         }
194     }
195
196
197     function turnToFullscreen() {
198         image.source = './images/fullscreen.png'
199         container.state = 'fullscreen'
200         container.opacity = 0.0
201         touchArea.switchArea(1)
202     }
203
204     function turnToNormal() {
205         image.source = './images/normal.png'
206         container.state = 'normal'
207         container.opacity = 1.0
208         touchArea.switchArea(0)
209     }
210
211     function enableSplitSwitchBtn() {
212         splitSwitchImage.source = './images/split_switch.png'
213         splitSwitchBtn.enableSplitSwitchBtn = true
214     }
215
216     function disableSplitSwitchBtn() {
217         splitSwitchImage.source = './images/split_switch_disable.png'
218         splitSwitchBtn.enableSplitSwitchBtn = false;
219     }
220
221     function switchSplitArea(val) {
222         homescreenHandler.changeLayout(val);
223     }
224 }