0b072748065ea955ea8074cf038edf7228397807
[ubi] / qml / ubi / components / Bar.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "../UIConstants.js" as Const
3
4 Item {
5     id: root
6
7     property string label
8     property bool isDownload: false
9     property bool isUpload: false
10     height: 32
11
12     Image {
13         id: icon
14         width: root.height
15         height: root.height
16         source: isDownload? "../"+Const.ICON_DOWN : (isUpload? "../"+Const.ICON_UP : "")
17         sourceSize.width: width
18         sourceSize.height: height
19         visible: isDownload || isUpload
20     }
21
22     Rectangle {
23         id: bbar
24
25         color: Const.TRANSPARENT
26         border.width: 2
27         radius: 5
28         border.color: Const.DEFAULT_FOREGROUND_COLOR
29         height: root.height
30         width: icon.visible? root.width-icon.width-5 : root.width
31         x: icon.visible? icon.width+5 : 0
32
33         Rectangle {
34             id: bar
35             height: parent.height
36             width: 0
37             x:0
38             radius: 5
39             color: Const.DEFAULT_FOREGROUND_COLOR
40             state: "right"
41
42             states: [
43                 State {
44                     name: "right"
45                 },
46                 State {
47                     name: "left"
48                 },
49                 State {
50                     name: "progress"
51                 }
52             ]
53         }
54
55         Text {
56             id: caption
57             font.pixelSize: 25
58             anchors.centerIn: parent
59             //color: Const.DEFAULT_FOREGROUND_COLOR
60             text: root.label.length>28 ? root.label.substring(0,25)+"..." : root.label
61             color: "black"
62         }
63
64     }
65
66     function setProgres(progress) {
67         console.log("proggress = "+progress);
68         if(bar.state!="progress") {
69             time.stop();
70             bar.state = "progress"
71             bar.x=0;
72         }
73         bar.width = bbar.width*progress;
74         if(progress==1)
75             stop();
76     }
77
78     function start() {
79         bar.width=bbar.width/2;
80         bar.x=0;
81         time.restart();
82     }
83
84     function stop() {
85         //console.log("stop!");
86     }
87
88     Timer {
89         id: time
90         interval: 10
91         repeat: true
92         onTriggered: {
93             if(bar.x+bar.width>=bbar.width)
94                 bar.state = "left";
95             if(bar.x<=0)
96                 bar.state = "right";
97
98             if(bar.state=="right")
99                 bar.x += 6;
100             else if(bar.state=="left")
101                 bar.x -= 6;
102         }
103     }
104 }
105