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