082cc803b178469adfd1556a931e4d942a39e162
[ubi] / qml / ubi / DownloadProgressBar.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "UIConstants.js" as Const
3
4 Rectangle {
5     id: root
6     height: 20
7     width: 200
8     state: "invisible"
9     color: Const.TRANSPARENT
10     border.width: 1
11     radius: 5
12     border.color: Const.DEFAULT_FOREGROUND_COLOR
13
14     Rectangle {
15         id: bar
16         height: parent.height
17         width: root.width/2
18         x:0
19         radius: 5
20         color: Const.DEFAULT_FOREGROUND_COLOR
21         state: "right"
22
23         states: [
24             State {
25                 name: "right"
26             },
27             State {
28                 name: "left"
29             },
30             State {
31                 name: "progress"
32             }
33         ]
34     }
35
36     function setProgres(progress) {
37         //console.log("proggress = "+progress);
38         if(bar.state!="progress") {
39             time.stop();
40             bar.state = "progress"
41             bar.x=0;
42         }
43         bar.width = root.width*progress;
44         if(progress==1)
45             stopDownload();
46     }
47     function startDownload() {
48         //console.log("start download");
49         bar.width=root.width/2;
50         bar.x=0;
51         state = "visible";
52         time.restart();
53     }
54     function stopDownload() {
55         //console.log("stop download");
56         state = "invisible";
57     }
58
59     Timer {
60         id: time
61         interval: 10
62         repeat: true
63         onTriggered: {
64             if(bar.x+bar.width>=root.width)
65                 bar.state = "left";
66             if(bar.x<=0)
67                 bar.state = "right";
68
69             if(bar.state=="right")
70                 bar.x += 6;
71             else if(bar.state=="left")
72                 bar.x -= 6;
73         }
74     }
75
76     states: [
77         State {
78             name: "visible"
79             PropertyChanges { target: root; opacity: 1 }
80         },
81         State {
82             name: "invisible"
83             PropertyChanges { target: root; opacity: 0 }
84         }
85     ]
86
87     transitions: Transition {
88         NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
89     }
90 }