Merge lp:~f-riccardo87/ubuntu-calculator-app/new-design into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
- new-design
- Merge into old_trunk
Status: | Merged |
---|---|
Approved by: | Dalius |
Approved revision: | 30 |
Merged at revision: | 20 |
Proposed branch: | lp:~f-riccardo87/ubuntu-calculator-app/new-design |
Merge into: | lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk |
Diff against target: |
1726 lines (+1060/-545) 19 files modified
KeyboardButton.qml (+0/-29) KeyboardsView.qml (+0/-31) Memory.qml (+0/-12) Scientific/KeyboardButton.qml (+29/-0) Scientific/KeyboardsView.qml (+31/-0) Scientific/Memory.qml (+12/-0) Scientific/ScientificPage.qml (+188/-0) Scientific/Screen.qml (+68/-0) Scientific/StdKeyboard.qml (+222/-0) Screen.qml (+0/-68) Simple/CalcKeyboard.qml (+102/-0) Simple/CalcLabel.qml (+51/-0) Simple/KeyboardButton.qml (+29/-0) Simple/Memory.qml (+12/-0) Simple/Screen.qml (+79/-0) Simple/SimplePage.qml (+175/-0) StdKeyboard.qml (+0/-222) Storage.qml (+56/-0) calculator.qml (+6/-183) |
To merge this branch: | bzr merge lp:~f-riccardo87/ubuntu-calculator-app/new-design |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dalius (community) | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Review via email: mp+152352@code.launchpad.net |
Commit message
added simple view
Description of the change
Simple view creaed and merged with existent scientific view
Dalius (dalius-sandbox) wrote : | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:28
http://
Executed test runs:
FAILURE: http://
Click here to trigger a rebuild:
http://
Riccardo Ferrazzo (f-riccardo87) wrote : | # |
I'm trying now
In data venerdì 8 marzo 2013 09:47:28, hai scritto:
> Could you resolve conflicts? I guess you need to pull from trunk.
--
Riccardo Ferrazzo <email address hidden>
- 29. By Riccardo Ferrazzo
-
conflicts resolved
- 30. By Riccardo Ferrazzo
-
added some files
Riccardo Ferrazzo (f-riccardo87) wrote : | # |
Conflicts resolved, also i've seen that some files are missing in the previous
review :)
In data venerdì 8 marzo 2013 09:47:28, hai scritto:
> Could you resolve conflicts? I guess you need to pull from trunk.
--
Riccardo Ferrazzo <email address hidden>
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:29
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
Dalius (dalius-sandbox) : | # |
Preview Diff
1 | === removed file 'KeyboardButton.qml' | |||
2 | --- KeyboardButton.qml 2013-02-27 08:59:52 +0000 | |||
3 | +++ KeyboardButton.qml 1970-01-01 00:00:00 +0000 | |||
4 | @@ -1,29 +0,0 @@ | |||
5 | 1 | import QtQuick 2.0 | ||
6 | 2 | import Ubuntu.Components 0.1 | ||
7 | 3 | |||
8 | 4 | Rectangle { | ||
9 | 5 | id: buttonRect | ||
10 | 6 | width: units.gu(9) | ||
11 | 7 | height: units.gu(6) | ||
12 | 8 | radius: units.gu(1) | ||
13 | 9 | color: buttonMA.pressed ? "#c0c0c0" : "white" | ||
14 | 10 | |||
15 | 11 | property alias text: buttonText.text | ||
16 | 12 | |||
17 | 13 | signal clicked() | ||
18 | 14 | signal pressAndHold() | ||
19 | 15 | |||
20 | 16 | Text { | ||
21 | 17 | id: buttonText | ||
22 | 18 | anchors.centerIn: parent | ||
23 | 19 | color: "#dd4814" | ||
24 | 20 | font.pixelSize: units.gu(3) | ||
25 | 21 | } | ||
26 | 22 | |||
27 | 23 | MouseArea { | ||
28 | 24 | id: buttonMA | ||
29 | 25 | anchors.fill: parent | ||
30 | 26 | onClicked: buttonRect.clicked() | ||
31 | 27 | onPressAndHold: buttonRect.pressAndHold(); | ||
32 | 28 | } | ||
33 | 29 | } | ||
34 | 30 | 0 | ||
35 | === removed file 'KeyboardsView.qml' | |||
36 | --- KeyboardsView.qml 2013-02-25 10:57:31 +0000 | |||
37 | +++ KeyboardsView.qml 1970-01-01 00:00:00 +0000 | |||
38 | @@ -1,31 +0,0 @@ | |||
39 | 1 | import QtQuick 2.0 | ||
40 | 2 | |||
41 | 3 | Flickable { | ||
42 | 4 | id: keyboardsView | ||
43 | 5 | width: parent.width | ||
44 | 6 | clip: true | ||
45 | 7 | |||
46 | 8 | contentWidth: stdKeyboard.width | ||
47 | 9 | contentHeight: stdKeyboard.height | ||
48 | 10 | |||
49 | 11 | property double buttonRowHeight: units.gu(8); | ||
50 | 12 | property double targetPosition | ||
51 | 13 | |||
52 | 14 | onMovementEnded: { | ||
53 | 15 | var stopPositionInRow = contentY % buttonRowHeight; | ||
54 | 16 | if( Math.abs(stopPositionInRow) > (buttonRowHeight/2)) { | ||
55 | 17 | targetPosition = contentY+(buttonRowHeight - stopPositionInRow) | ||
56 | 18 | } | ||
57 | 19 | else { | ||
58 | 20 | targetPosition = contentY -stopPositionInRow | ||
59 | 21 | } | ||
60 | 22 | snap.start(); | ||
61 | 23 | } | ||
62 | 24 | |||
63 | 25 | NumberAnimation {id: snap; target: keyboardsView; property: "contentY"; to: targetPosition } | ||
64 | 26 | |||
65 | 27 | StdKeyboard { | ||
66 | 28 | id: stdKeyboard | ||
67 | 29 | width: keyboardsView.width | ||
68 | 30 | } | ||
69 | 31 | } | ||
70 | 32 | 0 | ||
71 | === removed file 'Memory.qml' | |||
72 | --- Memory.qml 2013-02-25 20:13:21 +0000 | |||
73 | +++ Memory.qml 1970-01-01 00:00:00 +0000 | |||
74 | @@ -1,12 +0,0 @@ | |||
75 | 1 | import QtQuick 2.0 | ||
76 | 2 | |||
77 | 3 | ListModel { | ||
78 | 4 | id: memory | ||
79 | 5 | |||
80 | 6 | ListElement { | ||
81 | 7 | isLastItem: true | ||
82 | 8 | formula: '' | ||
83 | 9 | answer: '' | ||
84 | 10 | formula_data: '' | ||
85 | 11 | } | ||
86 | 12 | } | ||
87 | 13 | 0 | ||
88 | === added directory 'Scientific' | |||
89 | === added file 'Scientific/KeyboardButton.qml' | |||
90 | --- Scientific/KeyboardButton.qml 1970-01-01 00:00:00 +0000 | |||
91 | +++ Scientific/KeyboardButton.qml 2013-03-08 10:04:20 +0000 | |||
92 | @@ -0,0 +1,29 @@ | |||
93 | 1 | import QtQuick 2.0 | ||
94 | 2 | import Ubuntu.Components 0.1 | ||
95 | 3 | |||
96 | 4 | Rectangle { | ||
97 | 5 | id: buttonRect | ||
98 | 6 | width: units.gu(9) | ||
99 | 7 | height: units.gu(6) | ||
100 | 8 | radius: units.gu(1) | ||
101 | 9 | color: buttonMA.pressed ? "#c0c0c0" : "white" | ||
102 | 10 | |||
103 | 11 | property alias text: buttonText.text | ||
104 | 12 | |||
105 | 13 | signal clicked() | ||
106 | 14 | signal pressAndHold() | ||
107 | 15 | |||
108 | 16 | Text { | ||
109 | 17 | id: buttonText | ||
110 | 18 | anchors.centerIn: parent | ||
111 | 19 | color: "#dd4814" | ||
112 | 20 | font.pixelSize: units.gu(3) | ||
113 | 21 | } | ||
114 | 22 | |||
115 | 23 | MouseArea { | ||
116 | 24 | id: buttonMA | ||
117 | 25 | anchors.fill: parent | ||
118 | 26 | onClicked: buttonRect.clicked() | ||
119 | 27 | onPressAndHold: buttonRect.pressAndHold(); | ||
120 | 28 | } | ||
121 | 29 | } | ||
122 | 0 | 30 | ||
123 | === added file 'Scientific/KeyboardsView.qml' | |||
124 | --- Scientific/KeyboardsView.qml 1970-01-01 00:00:00 +0000 | |||
125 | +++ Scientific/KeyboardsView.qml 2013-03-08 10:04:20 +0000 | |||
126 | @@ -0,0 +1,31 @@ | |||
127 | 1 | import QtQuick 2.0 | ||
128 | 2 | |||
129 | 3 | Flickable { | ||
130 | 4 | id: keyboardsView | ||
131 | 5 | width: parent.width | ||
132 | 6 | clip: true | ||
133 | 7 | |||
134 | 8 | contentWidth: stdKeyboard.width | ||
135 | 9 | contentHeight: stdKeyboard.height | ||
136 | 10 | |||
137 | 11 | property double buttonRowHeight: units.gu(8); | ||
138 | 12 | property double targetPosition | ||
139 | 13 | |||
140 | 14 | onMovementEnded: { | ||
141 | 15 | var stopPositionInRow = contentY % buttonRowHeight; | ||
142 | 16 | if( Math.abs(stopPositionInRow) > (buttonRowHeight/2)) { | ||
143 | 17 | targetPosition = contentY+(buttonRowHeight - stopPositionInRow) | ||
144 | 18 | } | ||
145 | 19 | else { | ||
146 | 20 | targetPosition = contentY -stopPositionInRow | ||
147 | 21 | } | ||
148 | 22 | snap.start(); | ||
149 | 23 | } | ||
150 | 24 | |||
151 | 25 | NumberAnimation {id: snap; target: keyboardsView; property: "contentY"; to: targetPosition } | ||
152 | 26 | |||
153 | 27 | StdKeyboard { | ||
154 | 28 | id: stdKeyboard | ||
155 | 29 | width: keyboardsView.width | ||
156 | 30 | } | ||
157 | 31 | } | ||
158 | 0 | 32 | ||
159 | === added file 'Scientific/Memory.qml' | |||
160 | --- Scientific/Memory.qml 1970-01-01 00:00:00 +0000 | |||
161 | +++ Scientific/Memory.qml 2013-03-08 10:04:20 +0000 | |||
162 | @@ -0,0 +1,12 @@ | |||
163 | 1 | import QtQuick 2.0 | ||
164 | 2 | |||
165 | 3 | ListModel { | ||
166 | 4 | id: memory | ||
167 | 5 | |||
168 | 6 | ListElement { | ||
169 | 7 | isLastItem: true | ||
170 | 8 | formula: '' | ||
171 | 9 | answer: '' | ||
172 | 10 | formula_data: '' | ||
173 | 11 | } | ||
174 | 12 | } | ||
175 | 0 | 13 | ||
176 | === added file 'Scientific/ScientificPage.qml' | |||
177 | --- Scientific/ScientificPage.qml 1970-01-01 00:00:00 +0000 | |||
178 | +++ Scientific/ScientificPage.qml 2013-03-08 10:04:20 +0000 | |||
179 | @@ -0,0 +1,188 @@ | |||
180 | 1 | import QtQuick 2.0 | ||
181 | 2 | import Ubuntu.Components 0.1 | ||
182 | 3 | import "../engine.js" as CALC | ||
183 | 4 | |||
184 | 5 | Page { | ||
185 | 6 | |||
186 | 7 | property string formula_text: ''; | ||
187 | 8 | property string brackets_added: ''; | ||
188 | 9 | property string formula_text_for_engine: ''; | ||
189 | 10 | property var formula: []; | ||
190 | 11 | property string answer: ''; | ||
191 | 12 | property string angularUnit: 'RAD'; | ||
192 | 13 | |||
193 | 14 | function formulaPush(visual, engine, type) { | ||
194 | 15 | var prev = null; | ||
195 | 16 | if (formula.length > 0) | ||
196 | 17 | prev = formula[formula.length-1]; | ||
197 | 18 | |||
198 | 19 | var result = CALC.getFormulaTexts(prev, visual, engine, type, brackets_added.length/2) | ||
199 | 20 | |||
200 | 21 | var visual_text = result[0]; | ||
201 | 22 | var engine_text = result[1]; | ||
202 | 23 | var fixed_type = result[2]; | ||
203 | 24 | var brackets_count = result[3]; | ||
204 | 25 | |||
205 | 26 | brackets_added = brackets_added.substr(0, brackets_count*2); | ||
206 | 27 | |||
207 | 28 | if (visual_text !== null && engine_text !== null) { | ||
208 | 29 | formula_text += visual_text; | ||
209 | 30 | formula_text_for_engine += engine_text; | ||
210 | 31 | formula.push({'visual': visual_text, 'engine': engine_text, 'type': fixed_type}); | ||
211 | 32 | |||
212 | 33 | answer = calculate() | ||
213 | 34 | } | ||
214 | 35 | else { | ||
215 | 36 | formulaView.showError(); | ||
216 | 37 | } | ||
217 | 38 | } | ||
218 | 39 | |||
219 | 40 | function formulaPop() { | ||
220 | 41 | if (formula.length > 0) { | ||
221 | 42 | var prev = formula[formula.length-1]; | ||
222 | 43 | formula_text = formula_text.substring(0, formula_text.length - prev.visual.length); | ||
223 | 44 | formula_text_for_engine = formula_text_for_engine.substring(0, formula_text_for_engine.length - prev.engine.length); | ||
224 | 45 | if (prev.type === 'function' || (prev.type === 'group' && prev.engine === '(' || prev.engine === '*(')) | ||
225 | 46 | brackets_added = brackets_added.substring(0, brackets_added.length-2) | ||
226 | 47 | else if (prev.type === 'group' && prev.engine === ')') | ||
227 | 48 | brackets_added += " )" | ||
228 | 49 | formula.pop(); | ||
229 | 50 | |||
230 | 51 | answer = calculate() | ||
231 | 52 | } | ||
232 | 53 | } | ||
233 | 54 | |||
234 | 55 | function formulaReset() { | ||
235 | 56 | formula_text = ''; | ||
236 | 57 | formula_text_for_engine = ''; | ||
237 | 58 | formula = []; | ||
238 | 59 | answer = ""; | ||
239 | 60 | brackets_added = ''; | ||
240 | 61 | } | ||
241 | 62 | |||
242 | 63 | function calculate() { | ||
243 | 64 | |||
244 | 65 | console.debug('Formula for engine: ' + formula_text_for_engine) | ||
245 | 66 | |||
246 | 67 | var result = 0; | ||
247 | 68 | try { | ||
248 | 69 | result = CALC.parse(angularUnit + formula_text_for_engine + brackets_added); | ||
249 | 70 | if (result === Number.POSITIVE_INFINITY) | ||
250 | 71 | result = '∞'; | ||
251 | 72 | else if (result === Number.NEGATIVE_INFINITY) | ||
252 | 73 | result = '-∞'; | ||
253 | 74 | } catch(exception) { | ||
254 | 75 | if(exception instanceof CALC.DivisionByZeroError){ | ||
255 | 76 | result = "division by zero error"; | ||
256 | 77 | } else if(exception instanceof SyntaxError){ | ||
257 | 78 | result = ""; | ||
258 | 79 | } else if(exception instanceof CALC.ParenthesisError){ | ||
259 | 80 | if(exception.missing === '(') | ||
260 | 81 | brackets_added = brackets_added.substr(0, brackets_added.length-2); | ||
261 | 82 | else | ||
262 | 83 | brackets_added+=(' '+exception.missing); | ||
263 | 84 | result = calculate(); | ||
264 | 85 | } | ||
265 | 86 | } | ||
266 | 87 | return result; | ||
267 | 88 | } | ||
268 | 89 | |||
269 | 90 | function addFromMemory(answerToAdd, formulaData) { | ||
270 | 91 | if (answerToAdd !== '' && answerToAdd.indexOf('error') === -1 && answerToAdd.indexOf('∞') === -1) { | ||
271 | 92 | for (var i = 0; i < answerToAdd.length; i++) | ||
272 | 93 | formulaPush(answerToAdd[i], answerToAdd[i], answerToAdd[i] === '.' ? 'real' : 'number') | ||
273 | 94 | } | ||
274 | 95 | else { | ||
275 | 96 | var fd = JSON.parse(formulaData); | ||
276 | 97 | |||
277 | 98 | var prev = null; | ||
278 | 99 | if (formula.length > 0) | ||
279 | 100 | prev = formula[formula.length-1]; | ||
280 | 101 | |||
281 | 102 | var result = CALC.getFormulaTexts(prev, fd[0].engine, fd[0].engine, fd[0].type, brackets_added.length/2) | ||
282 | 103 | |||
283 | 104 | if (result[0] !== null && result[1] !== null) { | ||
284 | 105 | for (var idx = 0; idx < fd.length; idx++) { | ||
285 | 106 | formula_text += fd[idx].visual; | ||
286 | 107 | formula_text_for_engine += fd[idx].engine; | ||
287 | 108 | formula.push({'visual': fd[idx].visual, 'engine': fd[idx].engine, 'type': fd[idx].type}); | ||
288 | 109 | } | ||
289 | 110 | answer = calculate() | ||
290 | 111 | } | ||
291 | 112 | } | ||
292 | 113 | } | ||
293 | 114 | |||
294 | 115 | Item { | ||
295 | 116 | anchors.fill: parent | ||
296 | 117 | |||
297 | 118 | ListView { | ||
298 | 119 | id: formulaView | ||
299 | 120 | anchors.fill: parent | ||
300 | 121 | snapMode: ListView.SnapOneItem | ||
301 | 122 | clip: true | ||
302 | 123 | |||
303 | 124 | property string currentFormula: '%1<font color="lightgray">%2</font>'.arg(formula_text).arg(brackets_added) | ||
304 | 125 | property string currentAnswer: answer | ||
305 | 126 | property color color: "#FFFFFF"; | ||
306 | 127 | property bool positionedAtEnd: true; | ||
307 | 128 | |||
308 | 129 | function addCurrentToMemory() { | ||
309 | 130 | if (formula_text !== '') { | ||
310 | 131 | memory.get(memory.count-1).isLastItem = false | ||
311 | 132 | memory.get(memory.count-1).formula_data = JSON.stringify(formula) | ||
312 | 133 | memory.append({'formula': memory.get(memory.count-1).formula, 'answer': memory.get(count-1).answer, 'formula_data': '', 'isLastItem': true}) | ||
313 | 134 | positionViewAtEnd(); | ||
314 | 135 | } | ||
315 | 136 | } | ||
316 | 137 | |||
317 | 138 | function showError() { | ||
318 | 139 | animateError.start() | ||
319 | 140 | } | ||
320 | 141 | |||
321 | 142 | PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100} | ||
322 | 143 | |||
323 | 144 | add: Transition{ | ||
324 | 145 | SequentialAnimation { | ||
325 | 146 | NumberAnimation {property: "y"; from: formulaView.footerItem.y; to: formulaView.contentY; duration: 200; } | ||
326 | 147 | ParallelAnimation{ | ||
327 | 148 | NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 200 } | ||
328 | 149 | NumberAnimation { property: "y"; from: formulaView.contentY; duration: 0 } | ||
329 | 150 | } | ||
330 | 151 | } | ||
331 | 152 | } | ||
332 | 153 | |||
333 | 154 | onCurrentFormulaChanged: { | ||
334 | 155 | memory.get(memory.count-1).formula = currentFormula | ||
335 | 156 | positionViewAtEnd(); | ||
336 | 157 | } | ||
337 | 158 | |||
338 | 159 | onCurrentAnswerChanged: { | ||
339 | 160 | memory.get(memory.count-1).answer = currentAnswer | ||
340 | 161 | } | ||
341 | 162 | |||
342 | 163 | onContentYChanged: { | ||
343 | 164 | positionedAtEnd = formulaView.indexAt(0, contentY+0) == formulaView.model.count-1 | ||
344 | 165 | } | ||
345 | 166 | |||
346 | 167 | model: Memory{ | ||
347 | 168 | id: memory | ||
348 | 169 | } | ||
349 | 170 | |||
350 | 171 | delegate: Screen { | ||
351 | 172 | id: screen | ||
352 | 173 | width: formulaView.width | ||
353 | 174 | |||
354 | 175 | onUseAnswer: addFromMemory(answerToUse, formulaData) | ||
355 | 176 | } | ||
356 | 177 | |||
357 | 178 | footer: KeyboardsView { | ||
358 | 179 | height: formulaView.height - units.gu(24) | ||
359 | 180 | } | ||
360 | 181 | |||
361 | 182 | Scrollbar { | ||
362 | 183 | flickableItem: formulaView | ||
363 | 184 | align: Qt.AlignTrailing | ||
364 | 185 | } | ||
365 | 186 | } | ||
366 | 187 | } | ||
367 | 188 | } | ||
368 | 0 | 189 | ||
369 | === added file 'Scientific/Screen.qml' | |||
370 | --- Scientific/Screen.qml 1970-01-01 00:00:00 +0000 | |||
371 | +++ Scientific/Screen.qml 2013-03-08 10:04:20 +0000 | |||
372 | @@ -0,0 +1,68 @@ | |||
373 | 1 | import QtQuick 2.0 | ||
374 | 2 | import Ubuntu.Components 0.1 | ||
375 | 3 | import Ubuntu.Components.ListItems 0.1 | ||
376 | 4 | |||
377 | 5 | Rectangle{ | ||
378 | 6 | id: root | ||
379 | 7 | height: columnA.height + units.gu(4) | ||
380 | 8 | color: screenMA.pressed && !isLastItem ? "#FFDB88" : formulaView.color | ||
381 | 9 | transformOrigin: Item.Bottom | ||
382 | 10 | |||
383 | 11 | signal useAnswer(string answerToUse, string formulaData) | ||
384 | 12 | |||
385 | 13 | Text { | ||
386 | 14 | width: parent.width | ||
387 | 15 | visible: isLastItem && index && formulaView.positionedAtEnd > 0 | ||
388 | 16 | clip: true | ||
389 | 17 | text: "^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^" | ||
390 | 18 | color: "#C0C0C0" | ||
391 | 19 | } | ||
392 | 20 | |||
393 | 21 | |||
394 | 22 | Column { | ||
395 | 23 | id: columnA | ||
396 | 24 | spacing: units.gu(2) | ||
397 | 25 | width: parent.width - units.gu(8) | ||
398 | 26 | anchors.centerIn: parent | ||
399 | 27 | |||
400 | 28 | Label { | ||
401 | 29 | id: formulaLabel | ||
402 | 30 | width: parent.width | ||
403 | 31 | height: units.gu(13) | ||
404 | 32 | font.pixelSize: units.gu(4) | ||
405 | 33 | fontSizeMode: Text.Fit | ||
406 | 34 | wrapMode: Text.WordWrap | ||
407 | 35 | text: formula | ||
408 | 36 | } | ||
409 | 37 | |||
410 | 38 | Label { | ||
411 | 39 | id: answerLabel | ||
412 | 40 | width: parent.width | ||
413 | 41 | height: units.gu(5) | ||
414 | 42 | clip: true | ||
415 | 43 | font.pixelSize: units.gu(4) | ||
416 | 44 | fontSizeMode: Text.Fit | ||
417 | 45 | color: "#dd4814" | ||
418 | 46 | text: '= ' + answer | ||
419 | 47 | } | ||
420 | 48 | } | ||
421 | 49 | |||
422 | 50 | Divider { | ||
423 | 51 | visible: !isLastItem | ||
424 | 52 | width: parent.width | ||
425 | 53 | anchors { | ||
426 | 54 | left: parent.left | ||
427 | 55 | right: parent.right | ||
428 | 56 | bottom: parent.bottom | ||
429 | 57 | } | ||
430 | 58 | } | ||
431 | 59 | |||
432 | 60 | MouseArea { | ||
433 | 61 | id: screenMA | ||
434 | 62 | anchors.fill: parent | ||
435 | 63 | onClicked: { | ||
436 | 64 | if (answer.indexOf('error') === -1) | ||
437 | 65 | root.useAnswer(answer, formula_data) | ||
438 | 66 | } | ||
439 | 67 | } | ||
440 | 68 | } | ||
441 | 0 | 69 | ||
442 | === added file 'Scientific/StdKeyboard.qml' | |||
443 | --- Scientific/StdKeyboard.qml 1970-01-01 00:00:00 +0000 | |||
444 | +++ Scientific/StdKeyboard.qml 2013-03-08 10:04:20 +0000 | |||
445 | @@ -0,0 +1,222 @@ | |||
446 | 1 | import QtQuick 2.0 | ||
447 | 2 | import Ubuntu.Components 0.1 | ||
448 | 3 | |||
449 | 4 | Item { | ||
450 | 5 | width: parent.width | ||
451 | 6 | height: grid.height+units.gu(4) | ||
452 | 7 | |||
453 | 8 | Grid { | ||
454 | 9 | id: grid | ||
455 | 10 | columns: Math.floor(parent.width / units.gu(46)) | ||
456 | 11 | |||
457 | 12 | anchors{ | ||
458 | 13 | top: parent.top | ||
459 | 14 | topMargin: units.gu(2) | ||
460 | 15 | horizontalCenter: parent.horizontalCenter | ||
461 | 16 | } | ||
462 | 17 | spacing: units.gu(2) | ||
463 | 18 | Grid{ | ||
464 | 19 | columns:4 | ||
465 | 20 | spacing: units.gu(2) | ||
466 | 21 | |||
467 | 22 | KeyboardButton { | ||
468 | 23 | text: "(" | ||
469 | 24 | onClicked: formulaPush('(', '(', 'group') | ||
470 | 25 | } | ||
471 | 26 | |||
472 | 27 | KeyboardButton { | ||
473 | 28 | text: ")" | ||
474 | 29 | onClicked: formulaPush(')', ')', 'group') | ||
475 | 30 | } | ||
476 | 31 | |||
477 | 32 | KeyboardButton { | ||
478 | 33 | text: "C" | ||
479 | 34 | onClicked: { | ||
480 | 35 | formulaView.addCurrentToMemory(); | ||
481 | 36 | formulaReset(); | ||
482 | 37 | } | ||
483 | 38 | } | ||
484 | 39 | |||
485 | 40 | KeyboardButton { | ||
486 | 41 | text: "M" | ||
487 | 42 | onClicked: { | ||
488 | 43 | formulaView.addCurrentToMemory(); | ||
489 | 44 | } | ||
490 | 45 | } | ||
491 | 46 | |||
492 | 47 | KeyboardButton { | ||
493 | 48 | text: "7" | ||
494 | 49 | onClicked: formulaPush('7', '7', 'number') | ||
495 | 50 | } | ||
496 | 51 | |||
497 | 52 | KeyboardButton { | ||
498 | 53 | text: "8" | ||
499 | 54 | onClicked: formulaPush('8', '8', 'number') | ||
500 | 55 | } | ||
501 | 56 | |||
502 | 57 | KeyboardButton { | ||
503 | 58 | text: "9" | ||
504 | 59 | onClicked: formulaPush('9', '9', 'number') | ||
505 | 60 | } | ||
506 | 61 | |||
507 | 62 | KeyboardButton { | ||
508 | 63 | text: "÷" | ||
509 | 64 | onClicked: formulaPush('÷', '/', 'operation') | ||
510 | 65 | } | ||
511 | 66 | |||
512 | 67 | KeyboardButton { | ||
513 | 68 | text: "4" | ||
514 | 69 | onClicked: formulaPush('4', '4', 'number') | ||
515 | 70 | } | ||
516 | 71 | |||
517 | 72 | KeyboardButton { | ||
518 | 73 | text: "5" | ||
519 | 74 | onClicked: formulaPush('5', '5', 'number') | ||
520 | 75 | } | ||
521 | 76 | |||
522 | 77 | KeyboardButton { | ||
523 | 78 | text: "6" | ||
524 | 79 | onClicked: formulaPush('6', '6', 'number') | ||
525 | 80 | } | ||
526 | 81 | |||
527 | 82 | KeyboardButton { | ||
528 | 83 | text: "×" | ||
529 | 84 | onClicked: formulaPush('×', '*', 'operation') | ||
530 | 85 | } | ||
531 | 86 | |||
532 | 87 | KeyboardButton { | ||
533 | 88 | text: "1" | ||
534 | 89 | onClicked: formulaPush('1', '1', 'number') | ||
535 | 90 | } | ||
536 | 91 | |||
537 | 92 | KeyboardButton { | ||
538 | 93 | text: "2" | ||
539 | 94 | onClicked: formulaPush('2', '2', 'number') | ||
540 | 95 | } | ||
541 | 96 | |||
542 | 97 | KeyboardButton { | ||
543 | 98 | text: "3" | ||
544 | 99 | onClicked: formulaPush('3', '3', 'number') | ||
545 | 100 | } | ||
546 | 101 | |||
547 | 102 | KeyboardButton { | ||
548 | 103 | text: "+" | ||
549 | 104 | onClicked: formulaPush('+', '+', 'operation') | ||
550 | 105 | } | ||
551 | 106 | |||
552 | 107 | KeyboardButton { | ||
553 | 108 | text: "0" | ||
554 | 109 | onClicked: formulaPush('0', '0', 'number') | ||
555 | 110 | } | ||
556 | 111 | |||
557 | 112 | KeyboardButton { | ||
558 | 113 | text: "." | ||
559 | 114 | onClicked: formulaPush('.', '.', 'real') | ||
560 | 115 | } | ||
561 | 116 | |||
562 | 117 | KeyboardButton { | ||
563 | 118 | text: "←" | ||
564 | 119 | onClicked: formulaPop() | ||
565 | 120 | onPressAndHold: formulaReset() | ||
566 | 121 | } | ||
567 | 122 | |||
568 | 123 | KeyboardButton { | ||
569 | 124 | text: "−" | ||
570 | 125 | onClicked: formulaPush('−', '-', 'operation') | ||
571 | 126 | } | ||
572 | 127 | |||
573 | 128 | } | ||
574 | 129 | |||
575 | 130 | Grid{ | ||
576 | 131 | spacing: units.gu(2) | ||
577 | 132 | |||
578 | 133 | KeyboardButton { | ||
579 | 134 | text: "sin" | ||
580 | 135 | onClicked: formulaPush('sin', 'sin', 'function') | ||
581 | 136 | } | ||
582 | 137 | |||
583 | 138 | KeyboardButton { | ||
584 | 139 | text: "cos" | ||
585 | 140 | onClicked: formulaPush('cos', 'cos', 'function') | ||
586 | 141 | } | ||
587 | 142 | |||
588 | 143 | KeyboardButton { | ||
589 | 144 | text: "tan" | ||
590 | 145 | onClicked: formulaPush('tan', 'tan', 'function') | ||
591 | 146 | } | ||
592 | 147 | |||
593 | 148 | KeyboardButton { | ||
594 | 149 | text: angularUnit | ||
595 | 150 | onClicked: { | ||
596 | 151 | if (angularUnit === 'RAD') { | ||
597 | 152 | angularUnit = 'DEG'; | ||
598 | 153 | } | ||
599 | 154 | else if (angularUnit === 'DEG') { | ||
600 | 155 | angularUnit = 'GRAD'; | ||
601 | 156 | } | ||
602 | 157 | else if (angularUnit === 'GRAD') { | ||
603 | 158 | angularUnit = 'RAD' | ||
604 | 159 | } | ||
605 | 160 | calculate(); | ||
606 | 161 | } | ||
607 | 162 | } | ||
608 | 163 | |||
609 | 164 | KeyboardButton { | ||
610 | 165 | text: "asin" | ||
611 | 166 | onClicked: formulaPush('asin', 'asin', 'function') | ||
612 | 167 | } | ||
613 | 168 | |||
614 | 169 | KeyboardButton { | ||
615 | 170 | text: "acos" | ||
616 | 171 | onClicked: formulaPush('acos', 'acos', 'function') | ||
617 | 172 | } | ||
618 | 173 | |||
619 | 174 | KeyboardButton { | ||
620 | 175 | text: "atan" | ||
621 | 176 | onClicked: formulaPush('atan', 'atan', 'function') | ||
622 | 177 | } | ||
623 | 178 | |||
624 | 179 | |||
625 | 180 | KeyboardButton { | ||
626 | 181 | text: "ln" | ||
627 | 182 | onClicked: formulaPush('ln', 'ln', 'function') | ||
628 | 183 | } | ||
629 | 184 | |||
630 | 185 | KeyboardButton { | ||
631 | 186 | text: "√" | ||
632 | 187 | onClicked: formulaPush('√', '√', 'function') | ||
633 | 188 | } | ||
634 | 189 | |||
635 | 190 | KeyboardButton { | ||
636 | 191 | text: "π" | ||
637 | 192 | onClicked: formulaPush('π', 'π', 'const') | ||
638 | 193 | } | ||
639 | 194 | |||
640 | 195 | KeyboardButton { | ||
641 | 196 | text: "e" | ||
642 | 197 | onClicked: formulaPush('e', 'E', 'const') | ||
643 | 198 | } | ||
644 | 199 | |||
645 | 200 | KeyboardButton { | ||
646 | 201 | text: "log" | ||
647 | 202 | onClicked: formulaPush('log', 'log', 'function') | ||
648 | 203 | } | ||
649 | 204 | |||
650 | 205 | KeyboardButton { | ||
651 | 206 | text: "%" | ||
652 | 207 | onClicked: formulaPush('%', '%', 'operation') | ||
653 | 208 | } | ||
654 | 209 | |||
655 | 210 | KeyboardButton { | ||
656 | 211 | text: "!" | ||
657 | 212 | onClicked: formulaPush('!', '!', 'operation') | ||
658 | 213 | } | ||
659 | 214 | |||
660 | 215 | KeyboardButton { | ||
661 | 216 | text: "^" | ||
662 | 217 | onClicked: formulaPush('^', '^', 'operation') | ||
663 | 218 | } | ||
664 | 219 | } | ||
665 | 220 | |||
666 | 221 | } | ||
667 | 222 | } | ||
668 | 0 | 223 | ||
669 | === removed file 'Screen.qml' | |||
670 | --- Screen.qml 2013-03-02 09:26:56 +0000 | |||
671 | +++ Screen.qml 1970-01-01 00:00:00 +0000 | |||
672 | @@ -1,68 +0,0 @@ | |||
673 | 1 | import QtQuick 2.0 | ||
674 | 2 | import Ubuntu.Components 0.1 | ||
675 | 3 | import Ubuntu.Components.ListItems 0.1 | ||
676 | 4 | |||
677 | 5 | Rectangle{ | ||
678 | 6 | id: root | ||
679 | 7 | height: columnA.height + units.gu(4) | ||
680 | 8 | color: screenMA.pressed && !isLastItem ? "#FFDB88" : formulaView.color | ||
681 | 9 | transformOrigin: Item.Bottom | ||
682 | 10 | |||
683 | 11 | signal useAnswer(string answerToUse, string formulaData) | ||
684 | 12 | |||
685 | 13 | Text { | ||
686 | 14 | width: parent.width | ||
687 | 15 | visible: isLastItem && index && formulaView.positionedAtEnd > 0 | ||
688 | 16 | clip: true | ||
689 | 17 | text: "^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^" | ||
690 | 18 | color: "#C0C0C0" | ||
691 | 19 | } | ||
692 | 20 | |||
693 | 21 | |||
694 | 22 | Column { | ||
695 | 23 | id: columnA | ||
696 | 24 | spacing: units.gu(2) | ||
697 | 25 | width: parent.width - units.gu(8) | ||
698 | 26 | anchors.centerIn: parent | ||
699 | 27 | |||
700 | 28 | Label { | ||
701 | 29 | id: formulaLabel | ||
702 | 30 | width: parent.width | ||
703 | 31 | height: units.gu(13) | ||
704 | 32 | font.pixelSize: units.gu(4) | ||
705 | 33 | fontSizeMode: Text.Fit | ||
706 | 34 | wrapMode: Text.WordWrap | ||
707 | 35 | text: formula | ||
708 | 36 | } | ||
709 | 37 | |||
710 | 38 | Label { | ||
711 | 39 | id: answerLabel | ||
712 | 40 | width: parent.width | ||
713 | 41 | height: units.gu(5) | ||
714 | 42 | clip: true | ||
715 | 43 | font.pixelSize: units.gu(4) | ||
716 | 44 | fontSizeMode: Text.Fit | ||
717 | 45 | color: "#dd4814" | ||
718 | 46 | text: '= ' + answer | ||
719 | 47 | } | ||
720 | 48 | } | ||
721 | 49 | |||
722 | 50 | Divider { | ||
723 | 51 | visible: !isLastItem | ||
724 | 52 | width: parent.width | ||
725 | 53 | anchors { | ||
726 | 54 | left: parent.left | ||
727 | 55 | right: parent.right | ||
728 | 56 | bottom: parent.bottom | ||
729 | 57 | } | ||
730 | 58 | } | ||
731 | 59 | |||
732 | 60 | MouseArea { | ||
733 | 61 | id: screenMA | ||
734 | 62 | anchors.fill: parent | ||
735 | 63 | onClicked: { | ||
736 | 64 | if (answer.indexOf('error') === -1) | ||
737 | 65 | root.useAnswer(answer, formula_data) | ||
738 | 66 | } | ||
739 | 67 | } | ||
740 | 68 | } | ||
741 | 69 | 0 | ||
742 | === added directory 'Simple' | |||
743 | === added file 'Simple/CalcKeyboard.qml' | |||
744 | --- Simple/CalcKeyboard.qml 1970-01-01 00:00:00 +0000 | |||
745 | +++ Simple/CalcKeyboard.qml 2013-03-08 10:04:20 +0000 | |||
746 | @@ -0,0 +1,102 @@ | |||
747 | 1 | import QtQuick 2.0 | ||
748 | 2 | import Ubuntu.Components 0.1 | ||
749 | 3 | |||
750 | 4 | Item { | ||
751 | 5 | width: parent.width | ||
752 | 6 | height: grid.height+units.gu(4) | ||
753 | 7 | |||
754 | 8 | Grid { | ||
755 | 9 | id: grid | ||
756 | 10 | columns: 4 | ||
757 | 11 | anchors{ | ||
758 | 12 | top: parent.top | ||
759 | 13 | topMargin: units.gu(2) | ||
760 | 14 | horizontalCenter: parent.horizontalCenter | ||
761 | 15 | } | ||
762 | 16 | spacing: units.gu(2) | ||
763 | 17 | |||
764 | 18 | KeyboardButton { | ||
765 | 19 | text: "7" | ||
766 | 20 | onClicked: formulaPush('7', '7') | ||
767 | 21 | } | ||
768 | 22 | |||
769 | 23 | KeyboardButton { | ||
770 | 24 | text: "8" | ||
771 | 25 | onClicked: formulaPush('8', '8') | ||
772 | 26 | } | ||
773 | 27 | |||
774 | 28 | KeyboardButton { | ||
775 | 29 | text: "9" | ||
776 | 30 | onClicked: formulaPush('9', '9') | ||
777 | 31 | } | ||
778 | 32 | |||
779 | 33 | KeyboardButton { | ||
780 | 34 | text: "÷" | ||
781 | 35 | onClicked: formulaPush('÷', '/') | ||
782 | 36 | } | ||
783 | 37 | |||
784 | 38 | KeyboardButton { | ||
785 | 39 | text: "4" | ||
786 | 40 | onClicked: formulaPush('4', '4') | ||
787 | 41 | } | ||
788 | 42 | |||
789 | 43 | KeyboardButton { | ||
790 | 44 | text: "5" | ||
791 | 45 | onClicked: formulaPush('5', '5') | ||
792 | 46 | } | ||
793 | 47 | |||
794 | 48 | KeyboardButton { | ||
795 | 49 | text: "6" | ||
796 | 50 | onClicked: formulaPush('6', '6') | ||
797 | 51 | } | ||
798 | 52 | |||
799 | 53 | KeyboardButton { | ||
800 | 54 | text: "×" | ||
801 | 55 | onClicked: formulaPush('×', '*') | ||
802 | 56 | } | ||
803 | 57 | |||
804 | 58 | KeyboardButton { | ||
805 | 59 | text: "1" | ||
806 | 60 | onClicked: formulaPush('1', '1') | ||
807 | 61 | } | ||
808 | 62 | |||
809 | 63 | KeyboardButton { | ||
810 | 64 | text: "2" | ||
811 | 65 | onClicked: formulaPush('2', '2') | ||
812 | 66 | } | ||
813 | 67 | |||
814 | 68 | KeyboardButton { | ||
815 | 69 | text: "3" | ||
816 | 70 | onClicked: formulaPush('3', '3') | ||
817 | 71 | } | ||
818 | 72 | |||
819 | 73 | KeyboardButton { | ||
820 | 74 | text: "+" | ||
821 | 75 | onClicked: formulaPush('+', '+') | ||
822 | 76 | } | ||
823 | 77 | |||
824 | 78 | KeyboardButton { | ||
825 | 79 | text: "0" | ||
826 | 80 | onClicked: formulaPush('0', '0') | ||
827 | 81 | } | ||
828 | 82 | |||
829 | 83 | KeyboardButton { | ||
830 | 84 | text: "." | ||
831 | 85 | onClicked: formulaPush('.', '.') | ||
832 | 86 | } | ||
833 | 87 | |||
834 | 88 | KeyboardButton { | ||
835 | 89 | text: "C" | ||
836 | 90 | onClicked: { | ||
837 | 91 | formulaView.addCurrentToMemory(); | ||
838 | 92 | clear(); | ||
839 | 93 | } | ||
840 | 94 | } | ||
841 | 95 | |||
842 | 96 | KeyboardButton { | ||
843 | 97 | text: "−" | ||
844 | 98 | onClicked: formulaPush('−', '-') | ||
845 | 99 | } | ||
846 | 100 | |||
847 | 101 | } | ||
848 | 102 | } | ||
849 | 0 | 103 | ||
850 | === added file 'Simple/CalcLabel.qml' | |||
851 | --- Simple/CalcLabel.qml 1970-01-01 00:00:00 +0000 | |||
852 | +++ Simple/CalcLabel.qml 2013-03-08 10:04:20 +0000 | |||
853 | @@ -0,0 +1,51 @@ | |||
854 | 1 | import QtQuick 2.0 | ||
855 | 2 | import Ubuntu.Components 0.1 | ||
856 | 3 | |||
857 | 4 | Rectangle { | ||
858 | 5 | id: root | ||
859 | 6 | width: parent.width | ||
860 | 7 | height: row.height | ||
861 | 8 | color: "white" | ||
862 | 9 | |||
863 | 10 | property int operationsWidth: operatorLabel.width+formulaLabel.width | ||
864 | 11 | property string operation: "" | ||
865 | 12 | property string numbers: "" | ||
866 | 13 | property bool labelReadOnly: false | ||
867 | 14 | property string labelText: "" | ||
868 | 15 | property int numbersHeight: units.gu(4) | ||
869 | 16 | property string numbersColor: '#757373' | ||
870 | 17 | |||
871 | 18 | Row{ | ||
872 | 19 | id: row | ||
873 | 20 | height: numbersHeight | ||
874 | 21 | width: parent.width | ||
875 | 22 | TextField{ | ||
876 | 23 | id: numberName | ||
877 | 24 | width: row.width-operatorLabel.width-formulaLabel.width | ||
878 | 25 | anchors.bottom: parent.bottom | ||
879 | 26 | ItemStyle.delegate: Item{} // removes ubuntu shape | ||
880 | 27 | readOnly: labelReadOnly | ||
881 | 28 | text: labelText | ||
882 | 29 | onTextChanged: { labelText = numberName.text } | ||
883 | 30 | hasClearButton: false | ||
884 | 31 | } | ||
885 | 32 | Label { | ||
886 | 33 | id: operatorLabel | ||
887 | 34 | width: units.gu(4) | ||
888 | 35 | font.pixelSize: units.gu(4) | ||
889 | 36 | text: root.operation | ||
890 | 37 | font.family: "Ubuntu" | ||
891 | 38 | } | ||
892 | 39 | Label { | ||
893 | 40 | id: formulaLabel | ||
894 | 41 | width: units.gu(25) | ||
895 | 42 | color: numbersColor | ||
896 | 43 | anchors.bottom: parent.bottom | ||
897 | 44 | font.pixelSize: numbersHeight | ||
898 | 45 | fontSizeMode: Text.Fit | ||
899 | 46 | horizontalAlignment: Text.AlignRight | ||
900 | 47 | text: root.numbers | ||
901 | 48 | font.family: "Ubuntu" | ||
902 | 49 | } | ||
903 | 50 | } | ||
904 | 51 | } | ||
905 | 0 | 52 | ||
906 | === added file 'Simple/KeyboardButton.qml' | |||
907 | --- Simple/KeyboardButton.qml 1970-01-01 00:00:00 +0000 | |||
908 | +++ Simple/KeyboardButton.qml 2013-03-08 10:04:20 +0000 | |||
909 | @@ -0,0 +1,29 @@ | |||
910 | 1 | import QtQuick 2.0 | ||
911 | 2 | import Ubuntu.Components 0.1 | ||
912 | 3 | |||
913 | 4 | Rectangle { | ||
914 | 5 | id: buttonRect | ||
915 | 6 | width: units.gu(9) | ||
916 | 7 | height: units.gu(6) | ||
917 | 8 | radius: units.gu(1) | ||
918 | 9 | color: buttonMA.pressed ? "#c0c0c0" : "white" | ||
919 | 10 | |||
920 | 11 | property alias text: buttonText.text | ||
921 | 12 | |||
922 | 13 | signal clicked() | ||
923 | 14 | signal pressAndHold() | ||
924 | 15 | |||
925 | 16 | Text { | ||
926 | 17 | id: buttonText | ||
927 | 18 | anchors.centerIn: parent | ||
928 | 19 | color: "#dd4814" | ||
929 | 20 | font.pixelSize: units.gu(3) | ||
930 | 21 | } | ||
931 | 22 | |||
932 | 23 | MouseArea { | ||
933 | 24 | id: buttonMA | ||
934 | 25 | anchors.fill: parent | ||
935 | 26 | onClicked: buttonRect.clicked() | ||
936 | 27 | onPressAndHold: buttonRect.pressAndHold(); | ||
937 | 28 | } | ||
938 | 29 | } | ||
939 | 0 | 30 | ||
940 | === added file 'Simple/Memory.qml' | |||
941 | --- Simple/Memory.qml 1970-01-01 00:00:00 +0000 | |||
942 | +++ Simple/Memory.qml 2013-03-08 10:04:20 +0000 | |||
943 | @@ -0,0 +1,12 @@ | |||
944 | 1 | import QtQuick 2.0 | ||
945 | 2 | |||
946 | 3 | ListModel { | ||
947 | 4 | id: memory | ||
948 | 5 | |||
949 | 6 | ListElement { | ||
950 | 7 | dbId: -1 | ||
951 | 8 | isLastItem: true | ||
952 | 9 | answer: '' | ||
953 | 10 | operators: [] | ||
954 | 11 | } | ||
955 | 12 | } | ||
956 | 0 | 13 | ||
957 | === added file 'Simple/Screen.qml' | |||
958 | --- Simple/Screen.qml 1970-01-01 00:00:00 +0000 | |||
959 | +++ Simple/Screen.qml 2013-03-08 10:04:20 +0000 | |||
960 | @@ -0,0 +1,79 @@ | |||
961 | 1 | import QtQuick 2.0 | ||
962 | 2 | import Ubuntu.Components 0.1 | ||
963 | 3 | import Ubuntu.Components.ListItems 0.1 | ||
964 | 4 | |||
965 | 5 | Item{ | ||
966 | 6 | id: root | ||
967 | 7 | height: _content.height + divider.height | ||
968 | 8 | transformOrigin: Item.Bottom | ||
969 | 9 | |||
970 | 10 | property var ops | ||
971 | 11 | signal useAnswer(string answerToUse, string formulaData) | ||
972 | 12 | signal labelTextUpdated(int idx, string newText) | ||
973 | 13 | |||
974 | 14 | Rectangle{ | ||
975 | 15 | id: _content | ||
976 | 16 | width: parent.width | ||
977 | 17 | height: inputs.height+units.gu(2) | ||
978 | 18 | Column { | ||
979 | 19 | id: inputs | ||
980 | 20 | anchors.top: parent.top | ||
981 | 21 | anchors.topMargin: units.gu(2) | ||
982 | 22 | spacing: units.gu(0.5) | ||
983 | 23 | width: parent.width - units.gu(4) | ||
984 | 24 | anchors.centerIn: parent | ||
985 | 25 | |||
986 | 26 | Repeater{ | ||
987 | 27 | id: repeater | ||
988 | 28 | model: ops | ||
989 | 29 | CalcLabel{ | ||
990 | 30 | id: formulaLabel | ||
991 | 31 | labelText: _text | ||
992 | 32 | numbers: _number | ||
993 | 33 | operation: _operation | ||
994 | 34 | |||
995 | 35 | onLabelTextChanged: { | ||
996 | 36 | root.labelTextUpdated(index, labelText) | ||
997 | 37 | } | ||
998 | 38 | } | ||
999 | 39 | } | ||
1000 | 40 | |||
1001 | 41 | Rectangle{ | ||
1002 | 42 | height: units.gu(0.1) | ||
1003 | 43 | width: answerLabel.operationsWidth | ||
1004 | 44 | anchors.right: parent.right | ||
1005 | 45 | color: '#757373' | ||
1006 | 46 | } | ||
1007 | 47 | |||
1008 | 48 | CalcLabel { | ||
1009 | 49 | id: answerLabel | ||
1010 | 50 | numbers: answer | ||
1011 | 51 | labelReadOnly: true | ||
1012 | 52 | labelText: i18n.tr("Total") | ||
1013 | 53 | numbersColor: "#dd4814" | ||
1014 | 54 | numbersHeight: units.gu(7) | ||
1015 | 55 | |||
1016 | 56 | MouseArea { | ||
1017 | 57 | id: screenMA | ||
1018 | 58 | enabled: !isLastItem | ||
1019 | 59 | anchors.fill: parent | ||
1020 | 60 | onClicked: { | ||
1021 | 61 | if (answer.indexOf('error') === -1) | ||
1022 | 62 | root.useAnswer(answer, formula_data) | ||
1023 | 63 | } | ||
1024 | 64 | } | ||
1025 | 65 | } | ||
1026 | 66 | } | ||
1027 | 67 | } | ||
1028 | 68 | |||
1029 | 69 | Divider { | ||
1030 | 70 | id: divider | ||
1031 | 71 | visible: !isLastItem | ||
1032 | 72 | width: parent.width | ||
1033 | 73 | anchors { | ||
1034 | 74 | left: parent.left | ||
1035 | 75 | right: parent.right | ||
1036 | 76 | bottom: parent.bottom | ||
1037 | 77 | } | ||
1038 | 78 | } | ||
1039 | 79 | } | ||
1040 | 0 | 80 | ||
1041 | === added file 'Simple/SimplePage.qml' | |||
1042 | --- Simple/SimplePage.qml 1970-01-01 00:00:00 +0000 | |||
1043 | +++ Simple/SimplePage.qml 2013-03-08 10:04:20 +0000 | |||
1044 | @@ -0,0 +1,175 @@ | |||
1045 | 1 | import QtQuick 2.0 | ||
1046 | 2 | import Ubuntu.Components 0.1 | ||
1047 | 3 | import "../engine.js" as CALC | ||
1048 | 4 | |||
1049 | 5 | Page { | ||
1050 | 6 | |||
1051 | 7 | property var context: new CALC.Context; | ||
1052 | 8 | property var scanner; | ||
1053 | 9 | property string answer: '' | ||
1054 | 10 | property var screenFormula: [{_text:'', _operation:'', _number:''}] | ||
1055 | 11 | property var engineFormula: [''] | ||
1056 | 12 | |||
1057 | 13 | function formulaPush(visual, engine) { | ||
1058 | 14 | try{ | ||
1059 | 15 | scanner = new CALC.Scanner(engineFormula.join('') + engine, context); | ||
1060 | 16 | } catch(exception) { | ||
1061 | 17 | console.log(exception) | ||
1062 | 18 | return; | ||
1063 | 19 | } | ||
1064 | 20 | switch(scanner.tokens.last().type){ | ||
1065 | 21 | case CALC.T_PLUS: | ||
1066 | 22 | case CALC.T_MINUS: | ||
1067 | 23 | case CALC.T_DIV: | ||
1068 | 24 | case CALC.T_TIMES: | ||
1069 | 25 | case CALC.T_UNARY_PLUS: | ||
1070 | 26 | case CALC.T_UNARY_MINUS: | ||
1071 | 27 | if(scanner.tokens.length > 1 && (scanner.tokens[scanner.tokens.length-2].type & CALC.T_OPERATOR)) return; | ||
1072 | 28 | screenFormula.push({_text:'', _operation: '', _number:''}); | ||
1073 | 29 | screenFormula[screenFormula.length-1]._operation = visual; | ||
1074 | 30 | engineFormula[engineFormula.length-1] += engine; | ||
1075 | 31 | engineFormula.push(''); | ||
1076 | 32 | break; | ||
1077 | 33 | default: | ||
1078 | 34 | screenFormula[screenFormula.length-1]._number += visual; | ||
1079 | 35 | engineFormula[engineFormula.length-1] += engine; | ||
1080 | 36 | break; | ||
1081 | 37 | } | ||
1082 | 38 | formulaView.currentOperatorsChanged() | ||
1083 | 39 | calculate(); | ||
1084 | 40 | } | ||
1085 | 41 | |||
1086 | 42 | function calculate() { | ||
1087 | 43 | var result = 0; | ||
1088 | 44 | try{ | ||
1089 | 45 | result = new CALC.Parser(scanner).reduce(context); | ||
1090 | 46 | if (result === Number.POSITIVE_INFINITY) | ||
1091 | 47 | result = '∞'; | ||
1092 | 48 | else if (result === Number.NEGATIVE_INFINITY) | ||
1093 | 49 | result = '-∞'; | ||
1094 | 50 | } catch(exception) { | ||
1095 | 51 | if(exception instanceof CALC.DivisionByZeroError){ | ||
1096 | 52 | result = "division by zero error"; | ||
1097 | 53 | } else if(exception instanceof SyntaxError){ | ||
1098 | 54 | result = ""; | ||
1099 | 55 | } | ||
1100 | 56 | } | ||
1101 | 57 | answer = result; | ||
1102 | 58 | } | ||
1103 | 59 | |||
1104 | 60 | function remove(index){ | ||
1105 | 61 | screenFormula.splice(index, 1); | ||
1106 | 62 | engineFormula.splice(index, 1); | ||
1107 | 63 | } | ||
1108 | 64 | |||
1109 | 65 | function clear(){ | ||
1110 | 66 | answer = ''; | ||
1111 | 67 | screenFormula = [{_text:'', _operation:'', _number:''}]; | ||
1112 | 68 | engineFormula = ['']; | ||
1113 | 69 | } | ||
1114 | 70 | |||
1115 | 71 | function addFromMemory(answerToAdd, formulaData) { | ||
1116 | 72 | if (answerToAdd !== '' && answerToAdd.indexOf('error') === -1 && answerToAdd.indexOf('∞') === -1) { | ||
1117 | 73 | for (var i = 0; i < answerToAdd.length; i++) | ||
1118 | 74 | formulaPush(answerToAdd[i], answerToAdd[i], answerToAdd[i] === '.' ? 'real' : 'number') | ||
1119 | 75 | } | ||
1120 | 76 | } | ||
1121 | 77 | |||
1122 | 78 | Item { | ||
1123 | 79 | anchors.fill: parent | ||
1124 | 80 | |||
1125 | 81 | ListView { | ||
1126 | 82 | id: formulaView | ||
1127 | 83 | anchors.fill: parent | ||
1128 | 84 | verticalLayoutDirection: ListView.BottomToTop | ||
1129 | 85 | clip: true | ||
1130 | 86 | |||
1131 | 87 | signal currentOperatorsChanged() | ||
1132 | 88 | property string currentAnswer: answer | ||
1133 | 89 | |||
1134 | 90 | function addCurrentToMemory() { | ||
1135 | 91 | if (screenFormula.length > 1) { | ||
1136 | 92 | memory.get(0).isLastItem = false | ||
1137 | 93 | storage.saveCalculation(memory.get(0)); | ||
1138 | 94 | memory.insert(0,{'answer': '', 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true}) | ||
1139 | 95 | positionViewAtBeginning(); | ||
1140 | 96 | } | ||
1141 | 97 | } | ||
1142 | 98 | |||
1143 | 99 | function showError() { | ||
1144 | 100 | animateError.start() | ||
1145 | 101 | } | ||
1146 | 102 | |||
1147 | 103 | PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100} | ||
1148 | 104 | |||
1149 | 105 | displaced: Transition{ | ||
1150 | 106 | SequentialAnimation{ | ||
1151 | 107 | NumberAnimation {property: "scale"; to: 0.9; duration: 50 } | ||
1152 | 108 | NumberAnimation {property: "y"; duration: 300 } | ||
1153 | 109 | NumberAnimation {property: "scale"; to: 1; duration: 50 } | ||
1154 | 110 | } | ||
1155 | 111 | } | ||
1156 | 112 | |||
1157 | 113 | onCurrentOperatorsChanged: { | ||
1158 | 114 | memory.get(0).operators = screenFormula | ||
1159 | 115 | positionViewAtBeginning(); | ||
1160 | 116 | } | ||
1161 | 117 | |||
1162 | 118 | onCurrentAnswerChanged: { | ||
1163 | 119 | memory.get(0).answer = currentAnswer | ||
1164 | 120 | } | ||
1165 | 121 | |||
1166 | 122 | model: Memory{ | ||
1167 | 123 | id: memory | ||
1168 | 124 | Component.onCompleted: { | ||
1169 | 125 | storage.getCalculations(function(calc){ | ||
1170 | 126 | memory.append(calc); | ||
1171 | 127 | }); | ||
1172 | 128 | } | ||
1173 | 129 | } | ||
1174 | 130 | |||
1175 | 131 | delegate: Screen { | ||
1176 | 132 | id: screen | ||
1177 | 133 | width: formulaView.width | ||
1178 | 134 | ops: operators | ||
1179 | 135 | |||
1180 | 136 | onUseAnswer: addFromMemory(answerToUse, formulaData) | ||
1181 | 137 | onLabelTextUpdated: { | ||
1182 | 138 | if(index === 0){ | ||
1183 | 139 | screenFormula[idx]._text = newText; | ||
1184 | 140 | return; | ||
1185 | 141 | } | ||
1186 | 142 | memory.get(index).operators.get(idx)._text = newText; | ||
1187 | 143 | } | ||
1188 | 144 | } | ||
1189 | 145 | |||
1190 | 146 | header: CalcKeyboard { | ||
1191 | 147 | } | ||
1192 | 148 | |||
1193 | 149 | Scrollbar { | ||
1194 | 150 | flickableItem: formulaView | ||
1195 | 151 | align: Qt.AlignTrailing | ||
1196 | 152 | } | ||
1197 | 153 | |||
1198 | 154 | Component.onCompleted: { | ||
1199 | 155 | currentOperatorsChanged(); | ||
1200 | 156 | } | ||
1201 | 157 | |||
1202 | 158 | Component.onDestruction: { | ||
1203 | 159 | //update the storage | ||
1204 | 160 | for(var i=0; i<memory.count; i++){ | ||
1205 | 161 | var operators = memory.get(i).operators; | ||
1206 | 162 | var newop = []; | ||
1207 | 163 | for(var j=0; j< operators.count; j++){ | ||
1208 | 164 | newop.push(operators.get(j)) | ||
1209 | 165 | } | ||
1210 | 166 | var newElement = {'dbId': memory.get(i).dbId, | ||
1211 | 167 | 'isLastItem': false, | ||
1212 | 168 | 'answer': memory.get(i).answer, | ||
1213 | 169 | 'operators': newop}; | ||
1214 | 170 | storage.updateCalculation(newElement); | ||
1215 | 171 | } | ||
1216 | 172 | } | ||
1217 | 173 | } | ||
1218 | 174 | } | ||
1219 | 175 | } | ||
1220 | 0 | 176 | ||
1221 | === removed file 'StdKeyboard.qml' | |||
1222 | --- StdKeyboard.qml 2013-02-27 14:20:40 +0000 | |||
1223 | +++ StdKeyboard.qml 1970-01-01 00:00:00 +0000 | |||
1224 | @@ -1,222 +0,0 @@ | |||
1225 | 1 | import QtQuick 2.0 | ||
1226 | 2 | import Ubuntu.Components 0.1 | ||
1227 | 3 | |||
1228 | 4 | Item { | ||
1229 | 5 | width: parent.width | ||
1230 | 6 | height: grid.height+units.gu(4) | ||
1231 | 7 | |||
1232 | 8 | Grid { | ||
1233 | 9 | id: grid | ||
1234 | 10 | columns: Math.floor(parent.width / units.gu(46)) | ||
1235 | 11 | |||
1236 | 12 | anchors{ | ||
1237 | 13 | top: parent.top | ||
1238 | 14 | topMargin: units.gu(2) | ||
1239 | 15 | horizontalCenter: parent.horizontalCenter | ||
1240 | 16 | } | ||
1241 | 17 | spacing: units.gu(2) | ||
1242 | 18 | Grid{ | ||
1243 | 19 | columns:4 | ||
1244 | 20 | spacing: units.gu(2) | ||
1245 | 21 | |||
1246 | 22 | KeyboardButton { | ||
1247 | 23 | text: "(" | ||
1248 | 24 | onClicked: formulaPush('(', '(', 'group') | ||
1249 | 25 | } | ||
1250 | 26 | |||
1251 | 27 | KeyboardButton { | ||
1252 | 28 | text: ")" | ||
1253 | 29 | onClicked: formulaPush(')', ')', 'group') | ||
1254 | 30 | } | ||
1255 | 31 | |||
1256 | 32 | KeyboardButton { | ||
1257 | 33 | text: "C" | ||
1258 | 34 | onClicked: { | ||
1259 | 35 | formulaView.addCurrentToMemory(); | ||
1260 | 36 | formulaReset(); | ||
1261 | 37 | } | ||
1262 | 38 | } | ||
1263 | 39 | |||
1264 | 40 | KeyboardButton { | ||
1265 | 41 | text: "M" | ||
1266 | 42 | onClicked: { | ||
1267 | 43 | formulaView.addCurrentToMemory(); | ||
1268 | 44 | } | ||
1269 | 45 | } | ||
1270 | 46 | |||
1271 | 47 | KeyboardButton { | ||
1272 | 48 | text: "7" | ||
1273 | 49 | onClicked: formulaPush('7', '7', 'number') | ||
1274 | 50 | } | ||
1275 | 51 | |||
1276 | 52 | KeyboardButton { | ||
1277 | 53 | text: "8" | ||
1278 | 54 | onClicked: formulaPush('8', '8', 'number') | ||
1279 | 55 | } | ||
1280 | 56 | |||
1281 | 57 | KeyboardButton { | ||
1282 | 58 | text: "9" | ||
1283 | 59 | onClicked: formulaPush('9', '9', 'number') | ||
1284 | 60 | } | ||
1285 | 61 | |||
1286 | 62 | KeyboardButton { | ||
1287 | 63 | text: "÷" | ||
1288 | 64 | onClicked: formulaPush('÷', '/', 'operation') | ||
1289 | 65 | } | ||
1290 | 66 | |||
1291 | 67 | KeyboardButton { | ||
1292 | 68 | text: "4" | ||
1293 | 69 | onClicked: formulaPush('4', '4', 'number') | ||
1294 | 70 | } | ||
1295 | 71 | |||
1296 | 72 | KeyboardButton { | ||
1297 | 73 | text: "5" | ||
1298 | 74 | onClicked: formulaPush('5', '5', 'number') | ||
1299 | 75 | } | ||
1300 | 76 | |||
1301 | 77 | KeyboardButton { | ||
1302 | 78 | text: "6" | ||
1303 | 79 | onClicked: formulaPush('6', '6', 'number') | ||
1304 | 80 | } | ||
1305 | 81 | |||
1306 | 82 | KeyboardButton { | ||
1307 | 83 | text: "×" | ||
1308 | 84 | onClicked: formulaPush('×', '*', 'operation') | ||
1309 | 85 | } | ||
1310 | 86 | |||
1311 | 87 | KeyboardButton { | ||
1312 | 88 | text: "1" | ||
1313 | 89 | onClicked: formulaPush('1', '1', 'number') | ||
1314 | 90 | } | ||
1315 | 91 | |||
1316 | 92 | KeyboardButton { | ||
1317 | 93 | text: "2" | ||
1318 | 94 | onClicked: formulaPush('2', '2', 'number') | ||
1319 | 95 | } | ||
1320 | 96 | |||
1321 | 97 | KeyboardButton { | ||
1322 | 98 | text: "3" | ||
1323 | 99 | onClicked: formulaPush('3', '3', 'number') | ||
1324 | 100 | } | ||
1325 | 101 | |||
1326 | 102 | KeyboardButton { | ||
1327 | 103 | text: "+" | ||
1328 | 104 | onClicked: formulaPush('+', '+', 'operation') | ||
1329 | 105 | } | ||
1330 | 106 | |||
1331 | 107 | KeyboardButton { | ||
1332 | 108 | text: "0" | ||
1333 | 109 | onClicked: formulaPush('0', '0', 'number') | ||
1334 | 110 | } | ||
1335 | 111 | |||
1336 | 112 | KeyboardButton { | ||
1337 | 113 | text: "." | ||
1338 | 114 | onClicked: formulaPush('.', '.', 'real') | ||
1339 | 115 | } | ||
1340 | 116 | |||
1341 | 117 | KeyboardButton { | ||
1342 | 118 | text: "←" | ||
1343 | 119 | onClicked: formulaPop() | ||
1344 | 120 | onPressAndHold: formulaReset() | ||
1345 | 121 | } | ||
1346 | 122 | |||
1347 | 123 | KeyboardButton { | ||
1348 | 124 | text: "−" | ||
1349 | 125 | onClicked: formulaPush('−', '-', 'operation') | ||
1350 | 126 | } | ||
1351 | 127 | |||
1352 | 128 | } | ||
1353 | 129 | |||
1354 | 130 | Grid{ | ||
1355 | 131 | spacing: units.gu(2) | ||
1356 | 132 | |||
1357 | 133 | KeyboardButton { | ||
1358 | 134 | text: "sin" | ||
1359 | 135 | onClicked: formulaPush('sin', 'sin', 'function') | ||
1360 | 136 | } | ||
1361 | 137 | |||
1362 | 138 | KeyboardButton { | ||
1363 | 139 | text: "cos" | ||
1364 | 140 | onClicked: formulaPush('cos', 'cos', 'function') | ||
1365 | 141 | } | ||
1366 | 142 | |||
1367 | 143 | KeyboardButton { | ||
1368 | 144 | text: "tan" | ||
1369 | 145 | onClicked: formulaPush('tan', 'tan', 'function') | ||
1370 | 146 | } | ||
1371 | 147 | |||
1372 | 148 | KeyboardButton { | ||
1373 | 149 | text: angularUnit | ||
1374 | 150 | onClicked: { | ||
1375 | 151 | if (angularUnit === 'RAD') { | ||
1376 | 152 | angularUnit = 'DEG'; | ||
1377 | 153 | } | ||
1378 | 154 | else if (angularUnit === 'DEG') { | ||
1379 | 155 | angularUnit = 'GRAD'; | ||
1380 | 156 | } | ||
1381 | 157 | else if (angularUnit === 'GRAD') { | ||
1382 | 158 | angularUnit = 'RAD' | ||
1383 | 159 | } | ||
1384 | 160 | calculate(); | ||
1385 | 161 | } | ||
1386 | 162 | } | ||
1387 | 163 | |||
1388 | 164 | KeyboardButton { | ||
1389 | 165 | text: "asin" | ||
1390 | 166 | onClicked: formulaPush('asin', 'asin', 'function') | ||
1391 | 167 | } | ||
1392 | 168 | |||
1393 | 169 | KeyboardButton { | ||
1394 | 170 | text: "acos" | ||
1395 | 171 | onClicked: formulaPush('acos', 'acos', 'function') | ||
1396 | 172 | } | ||
1397 | 173 | |||
1398 | 174 | KeyboardButton { | ||
1399 | 175 | text: "atan" | ||
1400 | 176 | onClicked: formulaPush('atan', 'atan', 'function') | ||
1401 | 177 | } | ||
1402 | 178 | |||
1403 | 179 | |||
1404 | 180 | KeyboardButton { | ||
1405 | 181 | text: "ln" | ||
1406 | 182 | onClicked: formulaPush('ln', 'ln', 'function') | ||
1407 | 183 | } | ||
1408 | 184 | |||
1409 | 185 | KeyboardButton { | ||
1410 | 186 | text: "√" | ||
1411 | 187 | onClicked: formulaPush('√', '√', 'function') | ||
1412 | 188 | } | ||
1413 | 189 | |||
1414 | 190 | KeyboardButton { | ||
1415 | 191 | text: "π" | ||
1416 | 192 | onClicked: formulaPush('π', 'π', 'const') | ||
1417 | 193 | } | ||
1418 | 194 | |||
1419 | 195 | KeyboardButton { | ||
1420 | 196 | text: "e" | ||
1421 | 197 | onClicked: formulaPush('e', 'E', 'const') | ||
1422 | 198 | } | ||
1423 | 199 | |||
1424 | 200 | KeyboardButton { | ||
1425 | 201 | text: "log" | ||
1426 | 202 | onClicked: formulaPush('log', 'log', 'function') | ||
1427 | 203 | } | ||
1428 | 204 | |||
1429 | 205 | KeyboardButton { | ||
1430 | 206 | text: "%" | ||
1431 | 207 | onClicked: formulaPush('%', '%', 'operation') | ||
1432 | 208 | } | ||
1433 | 209 | |||
1434 | 210 | KeyboardButton { | ||
1435 | 211 | text: "!" | ||
1436 | 212 | onClicked: formulaPush('!', '!', 'operation') | ||
1437 | 213 | } | ||
1438 | 214 | |||
1439 | 215 | KeyboardButton { | ||
1440 | 216 | text: "^" | ||
1441 | 217 | onClicked: formulaPush('^', '^', 'operation') | ||
1442 | 218 | } | ||
1443 | 219 | } | ||
1444 | 220 | |||
1445 | 221 | } | ||
1446 | 222 | } | ||
1447 | 223 | 0 | ||
1448 | === added file 'Storage.qml' | |||
1449 | --- Storage.qml 1970-01-01 00:00:00 +0000 | |||
1450 | +++ Storage.qml 2013-03-08 10:04:20 +0000 | |||
1451 | @@ -0,0 +1,56 @@ | |||
1452 | 1 | //TODO: modify saved calculations text | ||
1453 | 2 | import QtQuick 2.0 | ||
1454 | 3 | import QtQuick.LocalStorage 2.0 | ||
1455 | 4 | |||
1456 | 5 | Item { | ||
1457 | 6 | |||
1458 | 7 | property var db: null | ||
1459 | 8 | |||
1460 | 9 | function openDB() { | ||
1461 | 10 | if(db !== null) return; | ||
1462 | 11 | |||
1463 | 12 | db = LocalStorage.openDatabaseSync("ubuntu-calculator-app", "0.1", "Default Ubuntu touch calculator", 100000); | ||
1464 | 13 | |||
1465 | 14 | db.transaction(function(tx){ | ||
1466 | 15 | tx.executeSql('CREATE TABLE IF NOT EXISTS Calculations(id INTEGER PRIMARY KEY, calc TEXT)'); | ||
1467 | 16 | }); | ||
1468 | 17 | } | ||
1469 | 18 | |||
1470 | 19 | function getCalculations(callback){ | ||
1471 | 20 | openDB(); | ||
1472 | 21 | db.transaction( | ||
1473 | 22 | function(tx){ | ||
1474 | 23 | var res = tx.executeSql('SELECT * FROM Calculations'); | ||
1475 | 24 | for(var i=res.rows.length - 1; i >= 0; i--){ | ||
1476 | 25 | var obj = JSON.parse(res.rows.item(i).calc); | ||
1477 | 26 | obj.dbId = res.rows.item(i).id; | ||
1478 | 27 | callback(obj); | ||
1479 | 28 | } | ||
1480 | 29 | } | ||
1481 | 30 | ); | ||
1482 | 31 | } | ||
1483 | 32 | |||
1484 | 33 | function saveCalculation(calc){ | ||
1485 | 34 | openDB(); | ||
1486 | 35 | var res; | ||
1487 | 36 | db.transaction( function(tx){ | ||
1488 | 37 | res = tx.executeSql('INSERT INTO Calculations(calc) VALUES(?)', [JSON.stringify(calc)]); | ||
1489 | 38 | }); | ||
1490 | 39 | return res.insertId | ||
1491 | 40 | } | ||
1492 | 41 | |||
1493 | 42 | function updateCalculation(calc){ | ||
1494 | 43 | openDB(); | ||
1495 | 44 | var index = calc.dbId | ||
1496 | 45 | db.transaction(function(tx){ | ||
1497 | 46 | tx.executeSql('UPDATE Calculations SET calc = ? WHERE id = ?', [JSON.stringify(calc), index]) | ||
1498 | 47 | }); | ||
1499 | 48 | } | ||
1500 | 49 | |||
1501 | 50 | function removeCalculation(calc){ | ||
1502 | 51 | openDb(); | ||
1503 | 52 | db.transaction(function(tx){ | ||
1504 | 53 | tx.executeSql('DELETE FROM Calculations WHERE id = ?', [calc.dbId]); | ||
1505 | 54 | }); | ||
1506 | 55 | } | ||
1507 | 56 | } | ||
1508 | 0 | 57 | ||
1509 | === modified file 'calculator.qml' | |||
1510 | --- calculator.qml 2013-03-02 09:26:56 +0000 | |||
1511 | +++ calculator.qml 2013-03-08 10:04:20 +0000 | |||
1512 | @@ -1,6 +1,7 @@ | |||
1513 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
1514 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
1516 | 3 | import "engine.js" as CALC | 3 | import "Simple" |
1517 | 4 | import "Scientific" | ||
1518 | 4 | 5 | ||
1519 | 5 | /*! | 6 | /*! |
1520 | 6 | \brief MainView with Tabs element. | 7 | \brief MainView with Tabs element. |
1521 | @@ -9,118 +10,15 @@ | |||
1522 | 9 | */ | 10 | */ |
1523 | 10 | 11 | ||
1524 | 11 | MainView { | 12 | MainView { |
1525 | 13 | id: mainView | ||
1526 | 12 | // objectName for functional testing purposes (autopilot-qt5) | 14 | // objectName for functional testing purposes (autopilot-qt5) |
1527 | 13 | objectName: "calculator" | 15 | objectName: "calculator" |
1528 | 14 | 16 | ||
1529 | 15 | width: units.gu(50) | 17 | width: units.gu(50) |
1530 | 16 | height: units.gu(75) | 18 | height: units.gu(75) |
1531 | 17 | 19 | ||
1638 | 18 | property string formula_text: ''; | 20 | Storage{ |
1639 | 19 | property string brackets_added: ''; | 21 | id: storage |
1534 | 20 | property string formula_text_for_engine: ''; | ||
1535 | 21 | property var formula: []; | ||
1536 | 22 | property string answer: ''; | ||
1537 | 23 | property string angularUnit: 'RAD'; | ||
1538 | 24 | |||
1539 | 25 | function formulaPush(visual, engine, type) { | ||
1540 | 26 | var prev = null; | ||
1541 | 27 | if (formula.length > 0) | ||
1542 | 28 | prev = formula[formula.length-1]; | ||
1543 | 29 | |||
1544 | 30 | var result = CALC.getFormulaTexts(prev, visual, engine, type, brackets_added.length/2) | ||
1545 | 31 | |||
1546 | 32 | var visual_text = result[0]; | ||
1547 | 33 | var engine_text = result[1]; | ||
1548 | 34 | var fixed_type = result[2]; | ||
1549 | 35 | var brackets_count = result[3]; | ||
1550 | 36 | |||
1551 | 37 | brackets_added = brackets_added.substr(0, brackets_count*2); | ||
1552 | 38 | |||
1553 | 39 | if (visual_text !== null && engine_text !== null) { | ||
1554 | 40 | formula_text += visual_text; | ||
1555 | 41 | formula_text_for_engine += engine_text; | ||
1556 | 42 | formula.push({'visual': visual_text, 'engine': engine_text, 'type': fixed_type}); | ||
1557 | 43 | |||
1558 | 44 | answer = calculate() | ||
1559 | 45 | } | ||
1560 | 46 | else { | ||
1561 | 47 | formulaView.showError(); | ||
1562 | 48 | } | ||
1563 | 49 | } | ||
1564 | 50 | |||
1565 | 51 | function formulaPop() { | ||
1566 | 52 | if (formula.length > 0) { | ||
1567 | 53 | var prev = formula[formula.length-1]; | ||
1568 | 54 | formula_text = formula_text.substring(0, formula_text.length - prev.visual.length); | ||
1569 | 55 | formula_text_for_engine = formula_text_for_engine.substring(0, formula_text_for_engine.length - prev.engine.length); | ||
1570 | 56 | if (prev.type === 'function' || (prev.type === 'group' && prev.engine === '(' || prev.engine === '*(')) | ||
1571 | 57 | brackets_added = brackets_added.substring(0, brackets_added.length-2) | ||
1572 | 58 | else if (prev.type === 'group' && prev.engine === ')') | ||
1573 | 59 | brackets_added += " )" | ||
1574 | 60 | formula.pop(); | ||
1575 | 61 | |||
1576 | 62 | answer = calculate() | ||
1577 | 63 | } | ||
1578 | 64 | } | ||
1579 | 65 | |||
1580 | 66 | function formulaReset() { | ||
1581 | 67 | formula_text = ''; | ||
1582 | 68 | formula_text_for_engine = ''; | ||
1583 | 69 | formula = []; | ||
1584 | 70 | answer = ""; | ||
1585 | 71 | brackets_added = ''; | ||
1586 | 72 | } | ||
1587 | 73 | |||
1588 | 74 | function calculate() { | ||
1589 | 75 | |||
1590 | 76 | console.debug('Formula for engine: ' + formula_text_for_engine) | ||
1591 | 77 | |||
1592 | 78 | var result = 0; | ||
1593 | 79 | try { | ||
1594 | 80 | result = CALC.parse(angularUnit + formula_text_for_engine + brackets_added); | ||
1595 | 81 | if (result === Number.POSITIVE_INFINITY) | ||
1596 | 82 | result = '∞'; | ||
1597 | 83 | else if (result === Number.NEGATIVE_INFINITY) | ||
1598 | 84 | result = '-∞'; | ||
1599 | 85 | } catch(exception) { | ||
1600 | 86 | if(exception instanceof CALC.DivisionByZeroError){ | ||
1601 | 87 | result = "division by zero error"; | ||
1602 | 88 | } else if(exception instanceof SyntaxError){ | ||
1603 | 89 | result = ""; | ||
1604 | 90 | } else if(exception instanceof CALC.ParenthesisError){ | ||
1605 | 91 | if(exception.missing === '(') | ||
1606 | 92 | brackets_added = brackets_added.substr(0, brackets_added.length-2); | ||
1607 | 93 | else | ||
1608 | 94 | brackets_added+=(' '+exception.missing); | ||
1609 | 95 | result = calculate(); | ||
1610 | 96 | } | ||
1611 | 97 | } | ||
1612 | 98 | return result; | ||
1613 | 99 | } | ||
1614 | 100 | |||
1615 | 101 | function addFromMemory(answerToAdd, formulaData) { | ||
1616 | 102 | if (answerToAdd !== '' && answerToAdd.indexOf('error') === -1 && answerToAdd.indexOf('∞') === -1) { | ||
1617 | 103 | for (var i = 0; i < answerToAdd.length; i++) | ||
1618 | 104 | formulaPush(answerToAdd[i], answerToAdd[i], answerToAdd[i] === '.' ? 'real' : 'number') | ||
1619 | 105 | } | ||
1620 | 106 | else { | ||
1621 | 107 | var fd = JSON.parse(formulaData); | ||
1622 | 108 | |||
1623 | 109 | var prev = null; | ||
1624 | 110 | if (formula.length > 0) | ||
1625 | 111 | prev = formula[formula.length-1]; | ||
1626 | 112 | |||
1627 | 113 | var result = CALC.getFormulaTexts(prev, fd[0].engine, fd[0].engine, fd[0].type, brackets_added.length/2) | ||
1628 | 114 | |||
1629 | 115 | if (result[0] !== null && result[1] !== null) { | ||
1630 | 116 | for (var idx = 0; idx < fd.length; idx++) { | ||
1631 | 117 | formula_text += fd[idx].visual; | ||
1632 | 118 | formula_text_for_engine += fd[idx].engine; | ||
1633 | 119 | formula.push({'visual': fd[idx].visual, 'engine': fd[idx].engine, 'type': fd[idx].type}); | ||
1634 | 120 | } | ||
1635 | 121 | answer = calculate() | ||
1636 | 122 | } | ||
1637 | 123 | } | ||
1640 | 124 | } | 22 | } |
1641 | 125 | 23 | ||
1642 | 126 | Tabs { | 24 | Tabs { |
1643 | @@ -134,82 +32,7 @@ | |||
1644 | 134 | title: i18n.tr("Calculator") | 32 | title: i18n.tr("Calculator") |
1645 | 135 | 33 | ||
1646 | 136 | // Tab content begins here | 34 | // Tab content begins here |
1723 | 137 | page: Page { | 35 | page: SimplePage{} //ScientificPage{} for a better calculator |
1648 | 138 | |||
1649 | 139 | Item { | ||
1650 | 140 | anchors.fill: parent | ||
1651 | 141 | |||
1652 | 142 | ListView { | ||
1653 | 143 | id: formulaView | ||
1654 | 144 | anchors.fill: parent | ||
1655 | 145 | snapMode: ListView.SnapOneItem | ||
1656 | 146 | clip: true | ||
1657 | 147 | |||
1658 | 148 | property string currentFormula: '%1<font color="lightgray">%2</font>'.arg(formula_text).arg(brackets_added) | ||
1659 | 149 | property string currentAnswer: answer | ||
1660 | 150 | property color color: "#FFFFFF"; | ||
1661 | 151 | property bool positionedAtEnd: true; | ||
1662 | 152 | |||
1663 | 153 | function addCurrentToMemory() { | ||
1664 | 154 | if (formula_text !== '') { | ||
1665 | 155 | memory.get(memory.count-1).isLastItem = false | ||
1666 | 156 | memory.get(memory.count-1).formula_data = JSON.stringify(formula) | ||
1667 | 157 | memory.append({'formula': memory.get(memory.count-1).formula, 'answer': memory.get(count-1).answer, 'formula_data': '', 'isLastItem': true}) | ||
1668 | 158 | positionViewAtEnd(); | ||
1669 | 159 | } | ||
1670 | 160 | } | ||
1671 | 161 | |||
1672 | 162 | function showError() { | ||
1673 | 163 | animateError.start() | ||
1674 | 164 | } | ||
1675 | 165 | |||
1676 | 166 | PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100} | ||
1677 | 167 | |||
1678 | 168 | add: Transition{ | ||
1679 | 169 | SequentialAnimation { | ||
1680 | 170 | NumberAnimation {property: "y"; from: formulaView.footerItem.y; to: formulaView.contentY; duration: 200; } | ||
1681 | 171 | ParallelAnimation{ | ||
1682 | 172 | NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 200 } | ||
1683 | 173 | NumberAnimation { property: "y"; from: formulaView.contentY; duration: 0 } | ||
1684 | 174 | } | ||
1685 | 175 | } | ||
1686 | 176 | } | ||
1687 | 177 | |||
1688 | 178 | onCurrentFormulaChanged: { | ||
1689 | 179 | memory.get(memory.count-1).formula = currentFormula | ||
1690 | 180 | positionViewAtEnd(); | ||
1691 | 181 | } | ||
1692 | 182 | |||
1693 | 183 | onCurrentAnswerChanged: { | ||
1694 | 184 | memory.get(memory.count-1).answer = currentAnswer | ||
1695 | 185 | } | ||
1696 | 186 | |||
1697 | 187 | onContentYChanged: { | ||
1698 | 188 | positionedAtEnd = formulaView.indexAt(0, contentY+0) == formulaView.model.count-1 | ||
1699 | 189 | } | ||
1700 | 190 | |||
1701 | 191 | model: Memory{ | ||
1702 | 192 | id: memory | ||
1703 | 193 | } | ||
1704 | 194 | |||
1705 | 195 | delegate: Screen { | ||
1706 | 196 | id: screen | ||
1707 | 197 | width: formulaView.width | ||
1708 | 198 | |||
1709 | 199 | onUseAnswer: addFromMemory(answerToUse, formulaData) | ||
1710 | 200 | } | ||
1711 | 201 | |||
1712 | 202 | footer: KeyboardsView { | ||
1713 | 203 | height: formulaView.height - units.gu(24) | ||
1714 | 204 | } | ||
1715 | 205 | |||
1716 | 206 | Scrollbar { | ||
1717 | 207 | flickableItem: formulaView | ||
1718 | 208 | align: Qt.AlignTrailing | ||
1719 | 209 | } | ||
1720 | 210 | } | ||
1721 | 211 | } | ||
1722 | 212 | } | ||
1724 | 213 | } | 36 | } |
1725 | 214 | 37 | ||
1726 | 215 | Tab { | 38 | Tab { |
Could you resolve conflicts? I guess you need to pull from trunk.