Initial Release
[marketstoday] / src / qml / StockQuotesComponent.qml
1 /*
2 @version: 0.1
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 import Qt 4.7
8 import "Library" as Library
9 import "Library/js/ISODate.js" as DateLib
10
11 Rectangle {
12     id: stockQuotesComponent
13     clip: true
14     color: "#343434"
15
16     signal updateStarted
17     signal updateCompleted
18
19     property XmlListModel stockQuotesListModel
20     property XmlListModel lastUpdatedModel
21     property int componentWidth
22     property int componentHeight
23     property int itemHeight: 50
24
25     Component {
26         id: stockQuotesDelegate
27
28         Item {
29             id: wrapper; width: componentWidth; height: itemHeight
30             Item {
31                 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1 }
32                 Row {
33                     x: 30;y: 15;
34                     width: componentWidth - 40;
35                     spacing: 5
36
37                     Text { text: if (width >= 250) {stockName;} else {symbol;} width: parent.width * 35/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
38                     Text { text: lastTradedPrice; width: parent.width * 25/100; font.pixelSize: 18; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
39                     Text { text: change; width: parent.width * 20/100; font.pixelSize: 18; elide: Text.ElideRight
40                         color: if(change >= 0){"green";} else {"red";}
41                             style: Text.Raised; styleColor: "black" }
42                     Text { text: changePercentage; width: parent.width * 20/100; font.pixelSize: 18; elide: Text.ElideRight;
43                         color: if(change >= 0){"green";} else {"red";}
44                             style: Text.Raised; styleColor: "black" }
45                 }
46             }
47         }
48     }
49
50     Rectangle{
51         id: pathViewWrapper
52         width: parent.width
53         anchors.top: parent.top
54         anchors.bottom: footerText.top
55         color: "#343434"
56
57         PathView{
58             id: stockQuotesView
59             flickDeceleration: 500
60             //preferredHighlightBegin: 1/stockQuotesView.count
61             //preferredHighlightEnd: 1/stockQuotesView.count
62             //pathItemCount: count
63             focus: true
64             interactive: true
65             model: stockQuotesListModel
66             delegate:  stockQuotesDelegate
67             path: Path {
68                 startX: width / 2
69                 startY: itemHeight/2
70                 PathLine {
71                     x: width / 2
72                     y: stockQuotesView.count * itemHeight  + itemHeight/2
73                 }
74             }
75             Keys.onDownPressed: if (!moving && interactive) {
76                                     console.log(stockQuotesView.height);
77                                     incrementCurrentIndex();
78                                 }
79             Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
80         }
81     }
82
83     Rectangle{
84         id: footerText
85         width: parent.width
86         height: 25
87         color: "#343434"
88         anchors.bottom: toolBar.top
89         ListView {
90             anchors.fill: parent
91             model: lastUpdatedModel
92             delegate:
93                 Text {
94                     text: "Updated: "+DateLib.ISODate.format(timestamp)
95                     horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
96                     width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
97                     color: "#cccccc"
98                     style: Text.Raised; styleColor: "black"
99                 }
100         }
101     }
102
103     Library.ToolBar {
104         id:toolBar
105         width: parent.width; height: 40
106         anchors.bottom: parent.bottom
107         opacity: 0.9
108         onReloadButtonClicked: reloadQuotes();
109         onDownButtonClicked: if (!stockQuotesView.moving && stockQuotesView.interactive) stockQuotesView.currentIndex = stockQuotesView.currentIndex + 1
110         onUpButtonClicked: if (!stockQuotesView.moving && stockQuotesView.interactive) stockQuotesView.currentIndex = stockQuotesView.currentIndex - 1
111         onNewsButtonClicked: Qt.openUrlExternally("http://finance.yahoo.com");
112         Connections {
113             target: stockQuotesComponent
114             onUpdateStarted:{
115                 if (!toolBar.updatePending) toolBar.updatePending = true;
116             }
117             onUpdateCompleted:{
118                 toolBar.updatePending = false;
119             }
120         }
121     }
122 }