Finished Font Size Changes for Harmattan, Fremantle
[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: 75
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         z: 5
132         color: "#343434"
133
134         Item {
135             id: lineEditItem
136             width: parent.width - 120
137             height: parent.height
138             anchors.verticalCenter: parent.verticalCenter
139             anchors.left: parent.left
140             BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
141             TextInput{
142                 id: newSymbol
143                 width: parent.width
144                 height: parent.height
145                 anchors.left: parent.left
146                 anchors.leftMargin: 5
147                 anchors.verticalCenter: parent.verticalCenter
148                 maximumLength:25
149                 font.pixelSize: 24
150                 font.bold: true
151                 font.capitalization: Font.AllUppercase                
152                 inputMethodHints: Qt.ImhNoPredictiveText
153                 color: "#151515"; selectionColor: "green"
154                 KeyNavigation.tab: addButton
155                 Keys.onReturnPressed: {
156                     logRequest("Return pressed");
157                     addSymbol(newSymbol.text.trim());
158                     newSymbol.text = "";
159                     newSymbol.closeSoftwareInputPanel();
160                 }
161                 Keys.onEnterPressed: {
162                     logRequest("Enter pressed");
163                     addSymbol(newSymbol.text.trim());
164                     newSymbol.text = "";
165                     newSymbol.closeSoftwareInputPanel();
166                 }
167                 focus: true
168             }
169         }
170
171         Rectangle {
172             id: addButtonArea
173             anchors.verticalCenter: parent.verticalCenter
174             anchors.right: parent.right
175             width: 120
176             height: parent.height
177             color:"#343434"
178             Image {
179                 id: addButton
180                 source: "Library/images/add.png"
181                 width: 32; height: 32
182                 anchors.centerIn: parent
183             }
184             MouseArea{
185                 id:addButtonMouseArea
186                 anchors.fill: parent
187                 onClicked: {
188                      addSymbol(newSymbol.text.trim());
189                      newSymbol.text = "";
190                      newSymbol.closeSoftwareInputPanel();
191                 }
192             }
193             states: State {
194                      name: "pressed"; when: addButtonMouseArea.pressed
195                      PropertyChanges { target: addButtonArea; color: "#9a9a9a"}
196             }
197         }
198     }
199     Rectangle{
200         anchors.top: newSymbolRow.bottom
201         anchors.bottom: footerTextArea.top
202         width: parent.width;
203
204         color:"#343434"
205         ListView{
206             id: symbolsListView
207             anchors.fill: parent
208             model: symbolsListModel
209             delegate: tickersListDelegate
210         }
211
212     }
213
214     Rectangle{
215         id: footerTextArea
216         width: parent.width
217         height: 25
218         //z: 5
219         color: "#343434"
220         anchors.bottom: parent.bottom
221         Text {
222             id: footerMessage
223             anchors.fill: parent
224             text: "Only Yahoo! Finance ticker symbols are supported."
225             horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
226             width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
227             color: "#cccccc"
228             style: Text.Raised; styleColor: "black"
229         }
230
231         Timer {
232             id: footerMessageTimer
233             interval: 10000
234             repeat: false
235             onTriggered: {
236                 footerMessage.text = "";
237             }
238         }
239
240         Component.onCompleted: {
241             footerMessageTimer.start();
242         }
243     }
244 }