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