update WWW
[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: button.height
11     //width: parent.width
12
13     width: mainWindow.width-3*Const.DEFAULT_MARGIN
14
15     signal cancel(string file);
16
17     Row {
18         spacing: Const.DEFAULT_MARGIN
19         anchors.verticalCenter: parent.verticalCenter
20
21         Image {
22             id: icon
23             source: isDownload? "../images/download.png" :
24                     isUpload? "../images/upload.png" : ""
25             visible: isDownload || isUpload
26             anchors.verticalCenter: parent.verticalCenter
27         }
28
29         Rectangle {
30             id: bbar
31             anchors.verticalCenter: parent.verticalCenter
32             color: Const.TRANSPARENT
33             border.width: 2
34             //radius: 5
35             border.color: Const.DEFAULT_FOREGROUND_COLOR
36             height: 40
37             width: icon.visible?
38                        root.width-icon.width-button.width-2*Const.DEFAULT_MARGIN :
39                        root.width-button.width-1*Const.DEFAULT_MARGIN
40             //x: icon.visible? icon.width+5 : 0
41
42             Rectangle {
43                 id: bar
44                 height: parent.height
45                 width: 0
46                 x:0
47                 color: Const.DEFAULT_FOREGROUND_COLOR
48                 state: "right"
49
50                 states: [
51                     State {
52                         name: "right"
53                     },
54                     State {
55                         name: "left"
56                     },
57                     State {
58                         name: "progress"
59                     }
60                 ]
61             }
62
63             Text {
64                 id: caption
65                 font.pixelSize: 25
66                 anchors.centerIn: parent
67                 //color: Const.DEFAULT_FOREGROUND_COLOR
68                 text: root.label
69                 width: bbar.width
70                 elide: Text.ElideRight
71                 horizontalAlignment: Text.AlignHCenter
72                 color: "black"
73             }
74         }
75
76         Button {
77             id: button
78             anchors.verticalCenter: parent.verticalCenter
79             iconSource: "images/close.png"
80             onButtonClicked: root.cancel(root.label)
81         }
82     }
83
84     function setProgres(progress) {
85         //console.log("proggress = "+progress);
86         if(bar.state!="progress") {
87             time.stop();
88             bar.state = "progress"
89             bar.x=0;
90         }
91         bar.width = bbar.width*progress;
92         if(progress==1)
93             stop();
94     }
95
96     function start() {
97         bar.width=bbar.width/2;
98         bar.x=0;
99         time.restart();
100     }
101
102     function stop() {
103         //console.log("stop!");
104     }
105
106     Timer {
107         id: time
108         interval: 10
109         repeat: true
110         onTriggered: {
111             if(bar.x+bar.width>=bbar.width)
112                 bar.state = "left";
113             if(bar.x<=0)
114                 bar.state = "right";
115
116             if(bar.state=="right")
117                 bar.x += 6;
118             else if(bar.state=="left")
119                 bar.x -= 6;
120         }
121     }
122 }
123