warehouse for ces2019
[apps/onscreenapp.git] / app / pages / ListPage.qml
1 /*
2  * Copyright (C) 2018 The Qt Company Ltd.
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.Layouts 1.1
19 import QtQuick.Controls 2.0
20
21 Page {
22     id: root
23     property alias model: listView.model
24     
25     property int appSize: 0
26     property int pageSize: 0
27     property int currentPageIndex: 0
28
29     property int nPullHeight: 100
30     
31     BusyIndicator {
32         id: prevBusyIndicator
33         anchors.horizontalCenter: parent.horizontalCenter
34         implicitWidth: 60
35         implicitHeight: 60
36         running: false
37     }
38
39     StackView {
40         id: stack
41         initialItem: listView
42         anchors.fill: parent
43         anchors.margins: root.width * 0.075
44     }
45
46     ListView {
47         id: listView
48         //anchors.fill: parent
49         //anchors.margins: root.width * 0.075
50         clip: true
51         
52         delegate: MouseArea {
53             id: delegate
54             width: listView.width
55             height: width / 6
56                         
57             RowLayout {
58                 anchors.fill: parent
59                                 
60                 Item {
61                     Layout.preferredWidth: 100
62                     Layout.preferredHeight: 100
63                                         
64                                         MouseArea{
65                                                 anchors.fill: parent    
66                                                 z: 2
67                                         onClicked: {
68                                                     stack.push("qrc:/pages/DetailPage.qml", {stack: stack, model: model}, StackView.Immediate)
69                                                 }
70                                         }
71                     Image {
72                         anchors.fill: parent
73                         source: model.icon
74                     }
75                 }
76                 ColumnLayout {
77                     Label {
78                         Layout.fillWidth: true
79                         text: model.name.toUpperCase()
80                         color: '#00ADDC'
81                     }
82                     Label {
83                         text: 'Version: ' + model.version
84                         font.pixelSize: 16
85                         font.italic: true
86                     }
87                     Label {
88                         text: 'Description: ' + model.description
89                         font.pixelSize: 16
90                         wrapMode: Text.Wrap
91                         elide: Text.ElideRight
92                         Layout.preferredWidth: 400
93                         Layout.preferredHeight: 40
94                     }                                   
95                 }
96                 ColumnLayout {
97                     spacing: 5
98                     Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
99
100                     Button {
101                                                 x: x - 6
102                                                 text: model.statetext
103                         onClicked: {
104                             if (model.statetext === 'Install' || model.statetext === 'Update') {
105                                 listView.model.install(model.index)
106                             } else if (model.statetext === 'Launch') {
107                                 if (listView.model.launch(model.id) > 1) {
108                                     homescreenHandler.tapShortcut(model.name)
109                                 } else {
110                                     console.warn('app cannot be launched')
111                                 }
112                             }
113                         }
114                         implicitWidth: 140
115                         implicitHeight: 40
116                                                 //Layout.rightMargin: 5
117                     }
118                 }
119                                 
120             }
121             DownloadBar {
122                 anchors.fill: parent
123                 progress: model.progress
124             }            
125             Image {
126                 source: 'qrc:/images/DividingLine.svg'
127                 anchors.horizontalCenter: parent.horizontalCenter
128                 anchors.top: parent.top
129                 visible: model.index > 0
130             }
131
132             
133         }
134
135         states: [
136             State {
137                 name: "prevPageState"; when: listView.contentY < -nPullHeight
138                 StateChangeScript {
139                     name: "prevPageScript"
140                     script: getPrevPage()
141                 }
142             }
143         ]
144     }
145
146     function getPrevPage() {
147         listView.y = nPullHeight;
148
149         currentPageIndex = currentPageIndex > 0 ? currentPageIndex-1 : 0;
150         prevBusyIndicator.running = true
151         prevPageTimer.start();
152     }
153
154     Timer {
155         id: prevPageTimer
156         interval: 1000
157         repeat: false
158         running: false
159         onTriggered: {
160             listView.model.getPrevPage(currentPageIndex)
161             prevPageAnimation.start();
162         }
163     }
164
165     NumberAnimation {
166         id: prevPageAnimation
167         target: listView
168         property: "y"
169         duration: 100
170         from: nPullHeight
171         to: 0
172         onStopped: {
173             prevBusyIndicator.running = false
174             listView.y = 0;
175         }
176     }
177
178     Connections {
179         target: listView.model
180         onRequestCompleted: {
181             appSize = appsize
182             pageSize = pagesize
183             console.log("request completed!", appSize, pageSize)
184         }
185     }
186 }