Harmattan font changes completed
[marketstoday] / src / qml / ConfigTickersComponent.qml
1 /*
2 @version: 0.5
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 import Qt 4.7
8 import "Library/js/DBUtility.js" as DBUtility
9
10 Item {
11     id: tickerTab
12     property int componentWidth
13     property int itemHeight
14     signal logRequest(string strMessage)
15
16     Component.onCompleted: {
17             DBUtility.initialize();
18             loadSymbols();
19     }
20
21     function loadSymbols(){
22         var symbolsArray = DBUtility.getAllSymbols();
23         if (symbolsArray && symbolsArray.length > 0){
24             var i = 0;
25             for (i = 0; i< symbolsArray.length; i++) {
26                 logRequest("Appending "+symbolsArray[i]+ " to ListModel");
27                 symbolsListModel.append({"symbol": symbolsArray[i]});
28             }
29             logRequest("ListModel count is  "+symbolsListModel.count);
30         }
31     }
32
33     function removeSymbol(symbol,index){
34         logRequest("Removing symbol "+symbol+" at index "+index);
35
36         var result = DBUtility.removeSymbol(symbol);
37         if (result !== "Error"){
38             symbolsListModel.remove(index);
39         }
40         else{
41             logRequest("Error: DB error while removing "+symbol+" at index "+index);
42         }
43
44     }
45
46     function addSymbol(symbol){
47         if (symbol && symbol.length > 0){
48             symbol = symbol.toUpperCase();
49             logRequest("Adding symbol "+symbol);
50             var result = DBUtility.addSymbol(symbol);
51             logRequest("Result is "+result);
52
53             if (result !== "Error"){
54                 symbolsListModel.append({"symbol": symbol});
55             }
56             else{
57                 logRequest("Error: DB error while adding "+symbol);
58             }
59         }
60         else{
61             logRequest("Error: Invalid symbol "+symbol);
62         }                
63     }
64
65     ListModel {
66         id: symbolsListModel
67     }
68
69     Component {
70         id: tickersListDelegate
71
72         Item {
73             id: wrapper; width: componentWidth; height: itemHeight
74             Rectangle { id: listRecord;
75                 color: "black";
76                 opacity: index % 2 ? 0.2 : 0.4;
77                 height: parent.height - 2;
78                 width: parent.width; y: 1 }
79
80             Text {
81                 text: symbol;
82                 anchors.left: parent.left
83                 anchors.leftMargin: 30
84                 anchors.verticalCenter: parent.verticalCenter
85                 verticalAlignment: Text.AlignVCenter
86                 width: parent.width - 120;
87                 height: parent.height
88                 font.pixelSize: 24;
89                 font.bold: true;
90                 elide: Text.ElideRight;
91                 color: "white";
92                 style: Text.Raised;
93                 styleColor: "black"
94             }
95
96             Rectangle {
97                 id: removeButtonArea
98                 width: 120
99                 height: parent.height
100                 anchors.right: parent.right
101                 color: "#00000000";
102
103                 Image {
104                     source: "Library/images/remove.png"
105                     anchors.centerIn: parent
106                     width: 32; height: 32
107                 }
108
109                 MouseArea{
110                     id:removeButtonMouseArea
111                     anchors.fill: parent
112                     onClicked: {
113                         removeSymbol(symbol,index)
114                     }
115                 }
116
117                 states: State {
118                          name: "pressed"; when: removeButtonMouseArea.pressed
119                          PropertyChanges { target: removeButtonArea; color: "#9a9a9a"}
120                 }
121             }
122         }
123     }
124
125     Rectangle {
126         id: newSymbolRow
127         //width: parent.width
128         width: componentWidth
129         height: itemHeight;
130         anchors.top: parent.top
131         color: "#343434"
132
133         Item {
134             id: lineEditItem
135             width: parent.width - 120
136             height: parent.height
137             anchors.verticalCenter: parent.verticalCenter
138             anchors.left: parent.left
139             BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
140             TextInput{
141                 id: newSymbol
142                 width: parent.width
143                 height: parent.height
144                 anchors.left: parent.left
145                 anchors.leftMargin: 5
146                 anchors.verticalCenter: parent.verticalCenter
147                 maximumLength:25
148                 font.pixelSize: 24
149                 font.bold: true
150                 font.capitalization: Font.AllUppercase                
151                 inputMethodHints: Qt.ImhNoPredictiveText
152                 color: "#151515"; selectionColor: "green"
153                 KeyNavigation.tab: addButton
154                 Keys.onReturnPressed: {
155                     logRequest("Return pressed");
156                     addSymbol(newSymbol.text.trim());
157                     newSymbol.text = "";
158                     newSymbol.closeSoftwareInputPanel();
159                 }
160                 Keys.onEnterPressed: {
161                     logRequest("Enter pressed");
162                     addSymbol(newSymbol.text.trim());
163                     newSymbol.text = "";
164                     newSymbol.closeSoftwareInputPanel();
165                 }
166                 focus: true
167             }
168         }
169
170         Rectangle {
171             id: addButtonArea
172             anchors.verticalCenter: parent.verticalCenter
173             anchors.right: parent.right
174             width: 120
175             height: parent.height
176             color:"#343434"
177             Image {
178                 id: addButton
179                 source: "Library/images/add.png"
180                 width: 32; height: 32
181                 anchors.centerIn: parent
182             }
183             MouseArea{
184                 id:addButtonMouseArea
185                 anchors.fill: parent
186                 onClicked: {
187                      addSymbol(newSymbol.text.trim());
188                      newSymbol.text = "";
189                      newSymbol.closeSoftwareInputPanel();
190                 }
191             }
192             states: State {
193                      name: "pressed"; when: addButtonMouseArea.pressed
194                      PropertyChanges { target: addButtonArea; color: "#9a9a9a"}
195             }
196         }
197     }
198     Rectangle{
199         anchors.top: newSymbolRow.bottom
200         anchors.bottom: footerTextArea.top
201         width: parent.width;
202
203         color:"#343434"
204         ListView{
205             id: symbolsListView
206             anchors.fill: parent
207             model: symbolsListModel
208             delegate: tickersListDelegate
209         }
210
211     }
212
213     Rectangle{
214         id: footerTextArea
215         width: parent.width
216         height: 25
217         //z: 5
218         color: "#343434"
219         anchors.bottom: parent.bottom
220         Text {
221             id: footerMessage
222             anchors.fill: parent
223             text: "Only Yahoo! Finance ticker symbols are supported."
224             horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
225             width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
226             color: "#cccccc"
227             style: Text.Raised; styleColor: "black"
228         }
229
230         Timer {
231             id: footerMessageTimer
232             interval: 10000
233             repeat: false
234             onTriggered: {
235                 footerMessage.text = "";
236             }
237         }
238
239         Component.onCompleted: {
240             footerMessageTimer.start();
241         }
242     }
243 }