Merge lp:~f-riccardo87/ubuntu-calculator-app/new-design into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Ferrazzo
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
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

To post a comment you must log in.
Revision history for this message
Dalius (dalius-sandbox) wrote :

Could you resolve conflicts? I guess you need to pull from trunk.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
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

Revision history for this message
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>

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Dalius (dalius-sandbox) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed file 'KeyboardButton.qml'
--- KeyboardButton.qml 2013-02-27 08:59:52 +0000
+++ KeyboardButton.qml 1970-01-01 00:00:00 +0000
@@ -1,29 +0,0 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Rectangle {
5 id: buttonRect
6 width: units.gu(9)
7 height: units.gu(6)
8 radius: units.gu(1)
9 color: buttonMA.pressed ? "#c0c0c0" : "white"
10
11 property alias text: buttonText.text
12
13 signal clicked()
14 signal pressAndHold()
15
16 Text {
17 id: buttonText
18 anchors.centerIn: parent
19 color: "#dd4814"
20 font.pixelSize: units.gu(3)
21 }
22
23 MouseArea {
24 id: buttonMA
25 anchors.fill: parent
26 onClicked: buttonRect.clicked()
27 onPressAndHold: buttonRect.pressAndHold();
28 }
29}
300
=== removed file 'KeyboardsView.qml'
--- KeyboardsView.qml 2013-02-25 10:57:31 +0000
+++ KeyboardsView.qml 1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
1import QtQuick 2.0
2
3Flickable {
4 id: keyboardsView
5 width: parent.width
6 clip: true
7
8 contentWidth: stdKeyboard.width
9 contentHeight: stdKeyboard.height
10
11 property double buttonRowHeight: units.gu(8);
12 property double targetPosition
13
14 onMovementEnded: {
15 var stopPositionInRow = contentY % buttonRowHeight;
16 if( Math.abs(stopPositionInRow) > (buttonRowHeight/2)) {
17 targetPosition = contentY+(buttonRowHeight - stopPositionInRow)
18 }
19 else {
20 targetPosition = contentY -stopPositionInRow
21 }
22 snap.start();
23 }
24
25 NumberAnimation {id: snap; target: keyboardsView; property: "contentY"; to: targetPosition }
26
27 StdKeyboard {
28 id: stdKeyboard
29 width: keyboardsView.width
30 }
31}
320
=== removed file 'Memory.qml'
--- Memory.qml 2013-02-25 20:13:21 +0000
+++ Memory.qml 1970-01-01 00:00:00 +0000
@@ -1,12 +0,0 @@
1import QtQuick 2.0
2
3ListModel {
4 id: memory
5
6 ListElement {
7 isLastItem: true
8 formula: ''
9 answer: ''
10 formula_data: ''
11 }
12}
130
=== added directory 'Scientific'
=== added file 'Scientific/KeyboardButton.qml'
--- Scientific/KeyboardButton.qml 1970-01-01 00:00:00 +0000
+++ Scientific/KeyboardButton.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,29 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Rectangle {
5 id: buttonRect
6 width: units.gu(9)
7 height: units.gu(6)
8 radius: units.gu(1)
9 color: buttonMA.pressed ? "#c0c0c0" : "white"
10
11 property alias text: buttonText.text
12
13 signal clicked()
14 signal pressAndHold()
15
16 Text {
17 id: buttonText
18 anchors.centerIn: parent
19 color: "#dd4814"
20 font.pixelSize: units.gu(3)
21 }
22
23 MouseArea {
24 id: buttonMA
25 anchors.fill: parent
26 onClicked: buttonRect.clicked()
27 onPressAndHold: buttonRect.pressAndHold();
28 }
29}
030
=== added file 'Scientific/KeyboardsView.qml'
--- Scientific/KeyboardsView.qml 1970-01-01 00:00:00 +0000
+++ Scientific/KeyboardsView.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,31 @@
1import QtQuick 2.0
2
3Flickable {
4 id: keyboardsView
5 width: parent.width
6 clip: true
7
8 contentWidth: stdKeyboard.width
9 contentHeight: stdKeyboard.height
10
11 property double buttonRowHeight: units.gu(8);
12 property double targetPosition
13
14 onMovementEnded: {
15 var stopPositionInRow = contentY % buttonRowHeight;
16 if( Math.abs(stopPositionInRow) > (buttonRowHeight/2)) {
17 targetPosition = contentY+(buttonRowHeight - stopPositionInRow)
18 }
19 else {
20 targetPosition = contentY -stopPositionInRow
21 }
22 snap.start();
23 }
24
25 NumberAnimation {id: snap; target: keyboardsView; property: "contentY"; to: targetPosition }
26
27 StdKeyboard {
28 id: stdKeyboard
29 width: keyboardsView.width
30 }
31}
032
=== added file 'Scientific/Memory.qml'
--- Scientific/Memory.qml 1970-01-01 00:00:00 +0000
+++ Scientific/Memory.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,12 @@
1import QtQuick 2.0
2
3ListModel {
4 id: memory
5
6 ListElement {
7 isLastItem: true
8 formula: ''
9 answer: ''
10 formula_data: ''
11 }
12}
013
=== added file 'Scientific/ScientificPage.qml'
--- Scientific/ScientificPage.qml 1970-01-01 00:00:00 +0000
+++ Scientific/ScientificPage.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,188 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import "../engine.js" as CALC
4
5Page {
6
7 property string formula_text: '';
8 property string brackets_added: '';
9 property string formula_text_for_engine: '';
10 property var formula: [];
11 property string answer: '';
12 property string angularUnit: 'RAD';
13
14 function formulaPush(visual, engine, type) {
15 var prev = null;
16 if (formula.length > 0)
17 prev = formula[formula.length-1];
18
19 var result = CALC.getFormulaTexts(prev, visual, engine, type, brackets_added.length/2)
20
21 var visual_text = result[0];
22 var engine_text = result[1];
23 var fixed_type = result[2];
24 var brackets_count = result[3];
25
26 brackets_added = brackets_added.substr(0, brackets_count*2);
27
28 if (visual_text !== null && engine_text !== null) {
29 formula_text += visual_text;
30 formula_text_for_engine += engine_text;
31 formula.push({'visual': visual_text, 'engine': engine_text, 'type': fixed_type});
32
33 answer = calculate()
34 }
35 else {
36 formulaView.showError();
37 }
38 }
39
40 function formulaPop() {
41 if (formula.length > 0) {
42 var prev = formula[formula.length-1];
43 formula_text = formula_text.substring(0, formula_text.length - prev.visual.length);
44 formula_text_for_engine = formula_text_for_engine.substring(0, formula_text_for_engine.length - prev.engine.length);
45 if (prev.type === 'function' || (prev.type === 'group' && prev.engine === '(' || prev.engine === '*('))
46 brackets_added = brackets_added.substring(0, brackets_added.length-2)
47 else if (prev.type === 'group' && prev.engine === ')')
48 brackets_added += " )"
49 formula.pop();
50
51 answer = calculate()
52 }
53 }
54
55 function formulaReset() {
56 formula_text = '';
57 formula_text_for_engine = '';
58 formula = [];
59 answer = "";
60 brackets_added = '';
61 }
62
63 function calculate() {
64
65 console.debug('Formula for engine: ' + formula_text_for_engine)
66
67 var result = 0;
68 try {
69 result = CALC.parse(angularUnit + formula_text_for_engine + brackets_added);
70 if (result === Number.POSITIVE_INFINITY)
71 result = '∞';
72 else if (result === Number.NEGATIVE_INFINITY)
73 result = '-∞';
74 } catch(exception) {
75 if(exception instanceof CALC.DivisionByZeroError){
76 result = "division by zero error";
77 } else if(exception instanceof SyntaxError){
78 result = "";
79 } else if(exception instanceof CALC.ParenthesisError){
80 if(exception.missing === '(')
81 brackets_added = brackets_added.substr(0, brackets_added.length-2);
82 else
83 brackets_added+=(' '+exception.missing);
84 result = calculate();
85 }
86 }
87 return result;
88 }
89
90 function addFromMemory(answerToAdd, formulaData) {
91 if (answerToAdd !== '' && answerToAdd.indexOf('error') === -1 && answerToAdd.indexOf('∞') === -1) {
92 for (var i = 0; i < answerToAdd.length; i++)
93 formulaPush(answerToAdd[i], answerToAdd[i], answerToAdd[i] === '.' ? 'real' : 'number')
94 }
95 else {
96 var fd = JSON.parse(formulaData);
97
98 var prev = null;
99 if (formula.length > 0)
100 prev = formula[formula.length-1];
101
102 var result = CALC.getFormulaTexts(prev, fd[0].engine, fd[0].engine, fd[0].type, brackets_added.length/2)
103
104 if (result[0] !== null && result[1] !== null) {
105 for (var idx = 0; idx < fd.length; idx++) {
106 formula_text += fd[idx].visual;
107 formula_text_for_engine += fd[idx].engine;
108 formula.push({'visual': fd[idx].visual, 'engine': fd[idx].engine, 'type': fd[idx].type});
109 }
110 answer = calculate()
111 }
112 }
113 }
114
115 Item {
116 anchors.fill: parent
117
118 ListView {
119 id: formulaView
120 anchors.fill: parent
121 snapMode: ListView.SnapOneItem
122 clip: true
123
124 property string currentFormula: '%1<font color="lightgray">%2</font>'.arg(formula_text).arg(brackets_added)
125 property string currentAnswer: answer
126 property color color: "#FFFFFF";
127 property bool positionedAtEnd: true;
128
129 function addCurrentToMemory() {
130 if (formula_text !== '') {
131 memory.get(memory.count-1).isLastItem = false
132 memory.get(memory.count-1).formula_data = JSON.stringify(formula)
133 memory.append({'formula': memory.get(memory.count-1).formula, 'answer': memory.get(count-1).answer, 'formula_data': '', 'isLastItem': true})
134 positionViewAtEnd();
135 }
136 }
137
138 function showError() {
139 animateError.start()
140 }
141
142 PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100}
143
144 add: Transition{
145 SequentialAnimation {
146 NumberAnimation {property: "y"; from: formulaView.footerItem.y; to: formulaView.contentY; duration: 200; }
147 ParallelAnimation{
148 NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 200 }
149 NumberAnimation { property: "y"; from: formulaView.contentY; duration: 0 }
150 }
151 }
152 }
153
154 onCurrentFormulaChanged: {
155 memory.get(memory.count-1).formula = currentFormula
156 positionViewAtEnd();
157 }
158
159 onCurrentAnswerChanged: {
160 memory.get(memory.count-1).answer = currentAnswer
161 }
162
163 onContentYChanged: {
164 positionedAtEnd = formulaView.indexAt(0, contentY+0) == formulaView.model.count-1
165 }
166
167 model: Memory{
168 id: memory
169 }
170
171 delegate: Screen {
172 id: screen
173 width: formulaView.width
174
175 onUseAnswer: addFromMemory(answerToUse, formulaData)
176 }
177
178 footer: KeyboardsView {
179 height: formulaView.height - units.gu(24)
180 }
181
182 Scrollbar {
183 flickableItem: formulaView
184 align: Qt.AlignTrailing
185 }
186 }
187 }
188}
0189
=== added file 'Scientific/Screen.qml'
--- Scientific/Screen.qml 1970-01-01 00:00:00 +0000
+++ Scientific/Screen.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,68 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1
4
5Rectangle{
6 id: root
7 height: columnA.height + units.gu(4)
8 color: screenMA.pressed && !isLastItem ? "#FFDB88" : formulaView.color
9 transformOrigin: Item.Bottom
10
11 signal useAnswer(string answerToUse, string formulaData)
12
13 Text {
14 width: parent.width
15 visible: isLastItem && index && formulaView.positionedAtEnd > 0
16 clip: true
17 text: "^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^"
18 color: "#C0C0C0"
19 }
20
21
22 Column {
23 id: columnA
24 spacing: units.gu(2)
25 width: parent.width - units.gu(8)
26 anchors.centerIn: parent
27
28 Label {
29 id: formulaLabel
30 width: parent.width
31 height: units.gu(13)
32 font.pixelSize: units.gu(4)
33 fontSizeMode: Text.Fit
34 wrapMode: Text.WordWrap
35 text: formula
36 }
37
38 Label {
39 id: answerLabel
40 width: parent.width
41 height: units.gu(5)
42 clip: true
43 font.pixelSize: units.gu(4)
44 fontSizeMode: Text.Fit
45 color: "#dd4814"
46 text: '= ' + answer
47 }
48 }
49
50 Divider {
51 visible: !isLastItem
52 width: parent.width
53 anchors {
54 left: parent.left
55 right: parent.right
56 bottom: parent.bottom
57 }
58 }
59
60 MouseArea {
61 id: screenMA
62 anchors.fill: parent
63 onClicked: {
64 if (answer.indexOf('error') === -1)
65 root.useAnswer(answer, formula_data)
66 }
67 }
68}
069
=== added file 'Scientific/StdKeyboard.qml'
--- Scientific/StdKeyboard.qml 1970-01-01 00:00:00 +0000
+++ Scientific/StdKeyboard.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,222 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Item {
5 width: parent.width
6 height: grid.height+units.gu(4)
7
8 Grid {
9 id: grid
10 columns: Math.floor(parent.width / units.gu(46))
11
12 anchors{
13 top: parent.top
14 topMargin: units.gu(2)
15 horizontalCenter: parent.horizontalCenter
16 }
17 spacing: units.gu(2)
18 Grid{
19 columns:4
20 spacing: units.gu(2)
21
22 KeyboardButton {
23 text: "("
24 onClicked: formulaPush('(', '(', 'group')
25 }
26
27 KeyboardButton {
28 text: ")"
29 onClicked: formulaPush(')', ')', 'group')
30 }
31
32 KeyboardButton {
33 text: "C"
34 onClicked: {
35 formulaView.addCurrentToMemory();
36 formulaReset();
37 }
38 }
39
40 KeyboardButton {
41 text: "M"
42 onClicked: {
43 formulaView.addCurrentToMemory();
44 }
45 }
46
47 KeyboardButton {
48 text: "7"
49 onClicked: formulaPush('7', '7', 'number')
50 }
51
52 KeyboardButton {
53 text: "8"
54 onClicked: formulaPush('8', '8', 'number')
55 }
56
57 KeyboardButton {
58 text: "9"
59 onClicked: formulaPush('9', '9', 'number')
60 }
61
62 KeyboardButton {
63 text: "÷"
64 onClicked: formulaPush('÷', '/', 'operation')
65 }
66
67 KeyboardButton {
68 text: "4"
69 onClicked: formulaPush('4', '4', 'number')
70 }
71
72 KeyboardButton {
73 text: "5"
74 onClicked: formulaPush('5', '5', 'number')
75 }
76
77 KeyboardButton {
78 text: "6"
79 onClicked: formulaPush('6', '6', 'number')
80 }
81
82 KeyboardButton {
83 text: "×"
84 onClicked: formulaPush('×', '*', 'operation')
85 }
86
87 KeyboardButton {
88 text: "1"
89 onClicked: formulaPush('1', '1', 'number')
90 }
91
92 KeyboardButton {
93 text: "2"
94 onClicked: formulaPush('2', '2', 'number')
95 }
96
97 KeyboardButton {
98 text: "3"
99 onClicked: formulaPush('3', '3', 'number')
100 }
101
102 KeyboardButton {
103 text: "+"
104 onClicked: formulaPush('+', '+', 'operation')
105 }
106
107 KeyboardButton {
108 text: "0"
109 onClicked: formulaPush('0', '0', 'number')
110 }
111
112 KeyboardButton {
113 text: "."
114 onClicked: formulaPush('.', '.', 'real')
115 }
116
117 KeyboardButton {
118 text: "←"
119 onClicked: formulaPop()
120 onPressAndHold: formulaReset()
121 }
122
123 KeyboardButton {
124 text: "−"
125 onClicked: formulaPush('−', '-', 'operation')
126 }
127
128 }
129
130 Grid{
131 spacing: units.gu(2)
132
133 KeyboardButton {
134 text: "sin"
135 onClicked: formulaPush('sin', 'sin', 'function')
136 }
137
138 KeyboardButton {
139 text: "cos"
140 onClicked: formulaPush('cos', 'cos', 'function')
141 }
142
143 KeyboardButton {
144 text: "tan"
145 onClicked: formulaPush('tan', 'tan', 'function')
146 }
147
148 KeyboardButton {
149 text: angularUnit
150 onClicked: {
151 if (angularUnit === 'RAD') {
152 angularUnit = 'DEG';
153 }
154 else if (angularUnit === 'DEG') {
155 angularUnit = 'GRAD';
156 }
157 else if (angularUnit === 'GRAD') {
158 angularUnit = 'RAD'
159 }
160 calculate();
161 }
162 }
163
164 KeyboardButton {
165 text: "asin"
166 onClicked: formulaPush('asin', 'asin', 'function')
167 }
168
169 KeyboardButton {
170 text: "acos"
171 onClicked: formulaPush('acos', 'acos', 'function')
172 }
173
174 KeyboardButton {
175 text: "atan"
176 onClicked: formulaPush('atan', 'atan', 'function')
177 }
178
179
180 KeyboardButton {
181 text: "ln"
182 onClicked: formulaPush('ln', 'ln', 'function')
183 }
184
185 KeyboardButton {
186 text: "√"
187 onClicked: formulaPush('√', '√', 'function')
188 }
189
190 KeyboardButton {
191 text: "π"
192 onClicked: formulaPush('π', 'π', 'const')
193 }
194
195 KeyboardButton {
196 text: "e"
197 onClicked: formulaPush('e', 'E', 'const')
198 }
199
200 KeyboardButton {
201 text: "log"
202 onClicked: formulaPush('log', 'log', 'function')
203 }
204
205 KeyboardButton {
206 text: "%"
207 onClicked: formulaPush('%', '%', 'operation')
208 }
209
210 KeyboardButton {
211 text: "!"
212 onClicked: formulaPush('!', '!', 'operation')
213 }
214
215 KeyboardButton {
216 text: "^"
217 onClicked: formulaPush('^', '^', 'operation')
218 }
219 }
220
221 }
222}
0223
=== removed file 'Screen.qml'
--- Screen.qml 2013-03-02 09:26:56 +0000
+++ Screen.qml 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1
4
5Rectangle{
6 id: root
7 height: columnA.height + units.gu(4)
8 color: screenMA.pressed && !isLastItem ? "#FFDB88" : formulaView.color
9 transformOrigin: Item.Bottom
10
11 signal useAnswer(string answerToUse, string formulaData)
12
13 Text {
14 width: parent.width
15 visible: isLastItem && index && formulaView.positionedAtEnd > 0
16 clip: true
17 text: "^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^"
18 color: "#C0C0C0"
19 }
20
21
22 Column {
23 id: columnA
24 spacing: units.gu(2)
25 width: parent.width - units.gu(8)
26 anchors.centerIn: parent
27
28 Label {
29 id: formulaLabel
30 width: parent.width
31 height: units.gu(13)
32 font.pixelSize: units.gu(4)
33 fontSizeMode: Text.Fit
34 wrapMode: Text.WordWrap
35 text: formula
36 }
37
38 Label {
39 id: answerLabel
40 width: parent.width
41 height: units.gu(5)
42 clip: true
43 font.pixelSize: units.gu(4)
44 fontSizeMode: Text.Fit
45 color: "#dd4814"
46 text: '= ' + answer
47 }
48 }
49
50 Divider {
51 visible: !isLastItem
52 width: parent.width
53 anchors {
54 left: parent.left
55 right: parent.right
56 bottom: parent.bottom
57 }
58 }
59
60 MouseArea {
61 id: screenMA
62 anchors.fill: parent
63 onClicked: {
64 if (answer.indexOf('error') === -1)
65 root.useAnswer(answer, formula_data)
66 }
67 }
68}
690
=== added directory 'Simple'
=== added file 'Simple/CalcKeyboard.qml'
--- Simple/CalcKeyboard.qml 1970-01-01 00:00:00 +0000
+++ Simple/CalcKeyboard.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,102 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Item {
5 width: parent.width
6 height: grid.height+units.gu(4)
7
8 Grid {
9 id: grid
10 columns: 4
11 anchors{
12 top: parent.top
13 topMargin: units.gu(2)
14 horizontalCenter: parent.horizontalCenter
15 }
16 spacing: units.gu(2)
17
18 KeyboardButton {
19 text: "7"
20 onClicked: formulaPush('7', '7')
21 }
22
23 KeyboardButton {
24 text: "8"
25 onClicked: formulaPush('8', '8')
26 }
27
28 KeyboardButton {
29 text: "9"
30 onClicked: formulaPush('9', '9')
31 }
32
33 KeyboardButton {
34 text: "÷"
35 onClicked: formulaPush('÷', '/')
36 }
37
38 KeyboardButton {
39 text: "4"
40 onClicked: formulaPush('4', '4')
41 }
42
43 KeyboardButton {
44 text: "5"
45 onClicked: formulaPush('5', '5')
46 }
47
48 KeyboardButton {
49 text: "6"
50 onClicked: formulaPush('6', '6')
51 }
52
53 KeyboardButton {
54 text: "×"
55 onClicked: formulaPush('×', '*')
56 }
57
58 KeyboardButton {
59 text: "1"
60 onClicked: formulaPush('1', '1')
61 }
62
63 KeyboardButton {
64 text: "2"
65 onClicked: formulaPush('2', '2')
66 }
67
68 KeyboardButton {
69 text: "3"
70 onClicked: formulaPush('3', '3')
71 }
72
73 KeyboardButton {
74 text: "+"
75 onClicked: formulaPush('+', '+')
76 }
77
78 KeyboardButton {
79 text: "0"
80 onClicked: formulaPush('0', '0')
81 }
82
83 KeyboardButton {
84 text: "."
85 onClicked: formulaPush('.', '.')
86 }
87
88 KeyboardButton {
89 text: "C"
90 onClicked: {
91 formulaView.addCurrentToMemory();
92 clear();
93 }
94 }
95
96 KeyboardButton {
97 text: "−"
98 onClicked: formulaPush('−', '-')
99 }
100
101 }
102}
0103
=== added file 'Simple/CalcLabel.qml'
--- Simple/CalcLabel.qml 1970-01-01 00:00:00 +0000
+++ Simple/CalcLabel.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,51 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Rectangle {
5 id: root
6 width: parent.width
7 height: row.height
8 color: "white"
9
10 property int operationsWidth: operatorLabel.width+formulaLabel.width
11 property string operation: ""
12 property string numbers: ""
13 property bool labelReadOnly: false
14 property string labelText: ""
15 property int numbersHeight: units.gu(4)
16 property string numbersColor: '#757373'
17
18 Row{
19 id: row
20 height: numbersHeight
21 width: parent.width
22 TextField{
23 id: numberName
24 width: row.width-operatorLabel.width-formulaLabel.width
25 anchors.bottom: parent.bottom
26 ItemStyle.delegate: Item{} // removes ubuntu shape
27 readOnly: labelReadOnly
28 text: labelText
29 onTextChanged: { labelText = numberName.text }
30 hasClearButton: false
31 }
32 Label {
33 id: operatorLabel
34 width: units.gu(4)
35 font.pixelSize: units.gu(4)
36 text: root.operation
37 font.family: "Ubuntu"
38 }
39 Label {
40 id: formulaLabel
41 width: units.gu(25)
42 color: numbersColor
43 anchors.bottom: parent.bottom
44 font.pixelSize: numbersHeight
45 fontSizeMode: Text.Fit
46 horizontalAlignment: Text.AlignRight
47 text: root.numbers
48 font.family: "Ubuntu"
49 }
50 }
51}
052
=== added file 'Simple/KeyboardButton.qml'
--- Simple/KeyboardButton.qml 1970-01-01 00:00:00 +0000
+++ Simple/KeyboardButton.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,29 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Rectangle {
5 id: buttonRect
6 width: units.gu(9)
7 height: units.gu(6)
8 radius: units.gu(1)
9 color: buttonMA.pressed ? "#c0c0c0" : "white"
10
11 property alias text: buttonText.text
12
13 signal clicked()
14 signal pressAndHold()
15
16 Text {
17 id: buttonText
18 anchors.centerIn: parent
19 color: "#dd4814"
20 font.pixelSize: units.gu(3)
21 }
22
23 MouseArea {
24 id: buttonMA
25 anchors.fill: parent
26 onClicked: buttonRect.clicked()
27 onPressAndHold: buttonRect.pressAndHold();
28 }
29}
030
=== added file 'Simple/Memory.qml'
--- Simple/Memory.qml 1970-01-01 00:00:00 +0000
+++ Simple/Memory.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,12 @@
1import QtQuick 2.0
2
3ListModel {
4 id: memory
5
6 ListElement {
7 dbId: -1
8 isLastItem: true
9 answer: ''
10 operators: []
11 }
12}
013
=== added file 'Simple/Screen.qml'
--- Simple/Screen.qml 1970-01-01 00:00:00 +0000
+++ Simple/Screen.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,79 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1
4
5Item{
6 id: root
7 height: _content.height + divider.height
8 transformOrigin: Item.Bottom
9
10 property var ops
11 signal useAnswer(string answerToUse, string formulaData)
12 signal labelTextUpdated(int idx, string newText)
13
14 Rectangle{
15 id: _content
16 width: parent.width
17 height: inputs.height+units.gu(2)
18 Column {
19 id: inputs
20 anchors.top: parent.top
21 anchors.topMargin: units.gu(2)
22 spacing: units.gu(0.5)
23 width: parent.width - units.gu(4)
24 anchors.centerIn: parent
25
26 Repeater{
27 id: repeater
28 model: ops
29 CalcLabel{
30 id: formulaLabel
31 labelText: _text
32 numbers: _number
33 operation: _operation
34
35 onLabelTextChanged: {
36 root.labelTextUpdated(index, labelText)
37 }
38 }
39 }
40
41 Rectangle{
42 height: units.gu(0.1)
43 width: answerLabel.operationsWidth
44 anchors.right: parent.right
45 color: '#757373'
46 }
47
48 CalcLabel {
49 id: answerLabel
50 numbers: answer
51 labelReadOnly: true
52 labelText: i18n.tr("Total")
53 numbersColor: "#dd4814"
54 numbersHeight: units.gu(7)
55
56 MouseArea {
57 id: screenMA
58 enabled: !isLastItem
59 anchors.fill: parent
60 onClicked: {
61 if (answer.indexOf('error') === -1)
62 root.useAnswer(answer, formula_data)
63 }
64 }
65 }
66 }
67 }
68
69 Divider {
70 id: divider
71 visible: !isLastItem
72 width: parent.width
73 anchors {
74 left: parent.left
75 right: parent.right
76 bottom: parent.bottom
77 }
78 }
79}
080
=== added file 'Simple/SimplePage.qml'
--- Simple/SimplePage.qml 1970-01-01 00:00:00 +0000
+++ Simple/SimplePage.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,175 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import "../engine.js" as CALC
4
5Page {
6
7 property var context: new CALC.Context;
8 property var scanner;
9 property string answer: ''
10 property var screenFormula: [{_text:'', _operation:'', _number:''}]
11 property var engineFormula: ['']
12
13 function formulaPush(visual, engine) {
14 try{
15 scanner = new CALC.Scanner(engineFormula.join('') + engine, context);
16 } catch(exception) {
17 console.log(exception)
18 return;
19 }
20 switch(scanner.tokens.last().type){
21 case CALC.T_PLUS:
22 case CALC.T_MINUS:
23 case CALC.T_DIV:
24 case CALC.T_TIMES:
25 case CALC.T_UNARY_PLUS:
26 case CALC.T_UNARY_MINUS:
27 if(scanner.tokens.length > 1 && (scanner.tokens[scanner.tokens.length-2].type & CALC.T_OPERATOR)) return;
28 screenFormula.push({_text:'', _operation: '', _number:''});
29 screenFormula[screenFormula.length-1]._operation = visual;
30 engineFormula[engineFormula.length-1] += engine;
31 engineFormula.push('');
32 break;
33 default:
34 screenFormula[screenFormula.length-1]._number += visual;
35 engineFormula[engineFormula.length-1] += engine;
36 break;
37 }
38 formulaView.currentOperatorsChanged()
39 calculate();
40 }
41
42 function calculate() {
43 var result = 0;
44 try{
45 result = new CALC.Parser(scanner).reduce(context);
46 if (result === Number.POSITIVE_INFINITY)
47 result = '∞';
48 else if (result === Number.NEGATIVE_INFINITY)
49 result = '-∞';
50 } catch(exception) {
51 if(exception instanceof CALC.DivisionByZeroError){
52 result = "division by zero error";
53 } else if(exception instanceof SyntaxError){
54 result = "";
55 }
56 }
57 answer = result;
58 }
59
60 function remove(index){
61 screenFormula.splice(index, 1);
62 engineFormula.splice(index, 1);
63 }
64
65 function clear(){
66 answer = '';
67 screenFormula = [{_text:'', _operation:'', _number:''}];
68 engineFormula = [''];
69 }
70
71 function addFromMemory(answerToAdd, formulaData) {
72 if (answerToAdd !== '' && answerToAdd.indexOf('error') === -1 && answerToAdd.indexOf('∞') === -1) {
73 for (var i = 0; i < answerToAdd.length; i++)
74 formulaPush(answerToAdd[i], answerToAdd[i], answerToAdd[i] === '.' ? 'real' : 'number')
75 }
76 }
77
78 Item {
79 anchors.fill: parent
80
81 ListView {
82 id: formulaView
83 anchors.fill: parent
84 verticalLayoutDirection: ListView.BottomToTop
85 clip: true
86
87 signal currentOperatorsChanged()
88 property string currentAnswer: answer
89
90 function addCurrentToMemory() {
91 if (screenFormula.length > 1) {
92 memory.get(0).isLastItem = false
93 storage.saveCalculation(memory.get(0));
94 memory.insert(0,{'answer': '', 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true})
95 positionViewAtBeginning();
96 }
97 }
98
99 function showError() {
100 animateError.start()
101 }
102
103 PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100}
104
105 displaced: Transition{
106 SequentialAnimation{
107 NumberAnimation {property: "scale"; to: 0.9; duration: 50 }
108 NumberAnimation {property: "y"; duration: 300 }
109 NumberAnimation {property: "scale"; to: 1; duration: 50 }
110 }
111 }
112
113 onCurrentOperatorsChanged: {
114 memory.get(0).operators = screenFormula
115 positionViewAtBeginning();
116 }
117
118 onCurrentAnswerChanged: {
119 memory.get(0).answer = currentAnswer
120 }
121
122 model: Memory{
123 id: memory
124 Component.onCompleted: {
125 storage.getCalculations(function(calc){
126 memory.append(calc);
127 });
128 }
129 }
130
131 delegate: Screen {
132 id: screen
133 width: formulaView.width
134 ops: operators
135
136 onUseAnswer: addFromMemory(answerToUse, formulaData)
137 onLabelTextUpdated: {
138 if(index === 0){
139 screenFormula[idx]._text = newText;
140 return;
141 }
142 memory.get(index).operators.get(idx)._text = newText;
143 }
144 }
145
146 header: CalcKeyboard {
147 }
148
149 Scrollbar {
150 flickableItem: formulaView
151 align: Qt.AlignTrailing
152 }
153
154 Component.onCompleted: {
155 currentOperatorsChanged();
156 }
157
158 Component.onDestruction: {
159 //update the storage
160 for(var i=0; i<memory.count; i++){
161 var operators = memory.get(i).operators;
162 var newop = [];
163 for(var j=0; j< operators.count; j++){
164 newop.push(operators.get(j))
165 }
166 var newElement = {'dbId': memory.get(i).dbId,
167 'isLastItem': false,
168 'answer': memory.get(i).answer,
169 'operators': newop};
170 storage.updateCalculation(newElement);
171 }
172 }
173 }
174 }
175}
0176
=== removed file 'StdKeyboard.qml'
--- StdKeyboard.qml 2013-02-27 14:20:40 +0000
+++ StdKeyboard.qml 1970-01-01 00:00:00 +0000
@@ -1,222 +0,0 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3
4Item {
5 width: parent.width
6 height: grid.height+units.gu(4)
7
8 Grid {
9 id: grid
10 columns: Math.floor(parent.width / units.gu(46))
11
12 anchors{
13 top: parent.top
14 topMargin: units.gu(2)
15 horizontalCenter: parent.horizontalCenter
16 }
17 spacing: units.gu(2)
18 Grid{
19 columns:4
20 spacing: units.gu(2)
21
22 KeyboardButton {
23 text: "("
24 onClicked: formulaPush('(', '(', 'group')
25 }
26
27 KeyboardButton {
28 text: ")"
29 onClicked: formulaPush(')', ')', 'group')
30 }
31
32 KeyboardButton {
33 text: "C"
34 onClicked: {
35 formulaView.addCurrentToMemory();
36 formulaReset();
37 }
38 }
39
40 KeyboardButton {
41 text: "M"
42 onClicked: {
43 formulaView.addCurrentToMemory();
44 }
45 }
46
47 KeyboardButton {
48 text: "7"
49 onClicked: formulaPush('7', '7', 'number')
50 }
51
52 KeyboardButton {
53 text: "8"
54 onClicked: formulaPush('8', '8', 'number')
55 }
56
57 KeyboardButton {
58 text: "9"
59 onClicked: formulaPush('9', '9', 'number')
60 }
61
62 KeyboardButton {
63 text: "÷"
64 onClicked: formulaPush('÷', '/', 'operation')
65 }
66
67 KeyboardButton {
68 text: "4"
69 onClicked: formulaPush('4', '4', 'number')
70 }
71
72 KeyboardButton {
73 text: "5"
74 onClicked: formulaPush('5', '5', 'number')
75 }
76
77 KeyboardButton {
78 text: "6"
79 onClicked: formulaPush('6', '6', 'number')
80 }
81
82 KeyboardButton {
83 text: "×"
84 onClicked: formulaPush('×', '*', 'operation')
85 }
86
87 KeyboardButton {
88 text: "1"
89 onClicked: formulaPush('1', '1', 'number')
90 }
91
92 KeyboardButton {
93 text: "2"
94 onClicked: formulaPush('2', '2', 'number')
95 }
96
97 KeyboardButton {
98 text: "3"
99 onClicked: formulaPush('3', '3', 'number')
100 }
101
102 KeyboardButton {
103 text: "+"
104 onClicked: formulaPush('+', '+', 'operation')
105 }
106
107 KeyboardButton {
108 text: "0"
109 onClicked: formulaPush('0', '0', 'number')
110 }
111
112 KeyboardButton {
113 text: "."
114 onClicked: formulaPush('.', '.', 'real')
115 }
116
117 KeyboardButton {
118 text: "←"
119 onClicked: formulaPop()
120 onPressAndHold: formulaReset()
121 }
122
123 KeyboardButton {
124 text: "−"
125 onClicked: formulaPush('−', '-', 'operation')
126 }
127
128 }
129
130 Grid{
131 spacing: units.gu(2)
132
133 KeyboardButton {
134 text: "sin"
135 onClicked: formulaPush('sin', 'sin', 'function')
136 }
137
138 KeyboardButton {
139 text: "cos"
140 onClicked: formulaPush('cos', 'cos', 'function')
141 }
142
143 KeyboardButton {
144 text: "tan"
145 onClicked: formulaPush('tan', 'tan', 'function')
146 }
147
148 KeyboardButton {
149 text: angularUnit
150 onClicked: {
151 if (angularUnit === 'RAD') {
152 angularUnit = 'DEG';
153 }
154 else if (angularUnit === 'DEG') {
155 angularUnit = 'GRAD';
156 }
157 else if (angularUnit === 'GRAD') {
158 angularUnit = 'RAD'
159 }
160 calculate();
161 }
162 }
163
164 KeyboardButton {
165 text: "asin"
166 onClicked: formulaPush('asin', 'asin', 'function')
167 }
168
169 KeyboardButton {
170 text: "acos"
171 onClicked: formulaPush('acos', 'acos', 'function')
172 }
173
174 KeyboardButton {
175 text: "atan"
176 onClicked: formulaPush('atan', 'atan', 'function')
177 }
178
179
180 KeyboardButton {
181 text: "ln"
182 onClicked: formulaPush('ln', 'ln', 'function')
183 }
184
185 KeyboardButton {
186 text: "√"
187 onClicked: formulaPush('√', '√', 'function')
188 }
189
190 KeyboardButton {
191 text: "π"
192 onClicked: formulaPush('π', 'π', 'const')
193 }
194
195 KeyboardButton {
196 text: "e"
197 onClicked: formulaPush('e', 'E', 'const')
198 }
199
200 KeyboardButton {
201 text: "log"
202 onClicked: formulaPush('log', 'log', 'function')
203 }
204
205 KeyboardButton {
206 text: "%"
207 onClicked: formulaPush('%', '%', 'operation')
208 }
209
210 KeyboardButton {
211 text: "!"
212 onClicked: formulaPush('!', '!', 'operation')
213 }
214
215 KeyboardButton {
216 text: "^"
217 onClicked: formulaPush('^', '^', 'operation')
218 }
219 }
220
221 }
222}
2230
=== added file 'Storage.qml'
--- Storage.qml 1970-01-01 00:00:00 +0000
+++ Storage.qml 2013-03-08 10:04:20 +0000
@@ -0,0 +1,56 @@
1//TODO: modify saved calculations text
2import QtQuick 2.0
3import QtQuick.LocalStorage 2.0
4
5Item {
6
7 property var db: null
8
9 function openDB() {
10 if(db !== null) return;
11
12 db = LocalStorage.openDatabaseSync("ubuntu-calculator-app", "0.1", "Default Ubuntu touch calculator", 100000);
13
14 db.transaction(function(tx){
15 tx.executeSql('CREATE TABLE IF NOT EXISTS Calculations(id INTEGER PRIMARY KEY, calc TEXT)');
16 });
17 }
18
19 function getCalculations(callback){
20 openDB();
21 db.transaction(
22 function(tx){
23 var res = tx.executeSql('SELECT * FROM Calculations');
24 for(var i=res.rows.length - 1; i >= 0; i--){
25 var obj = JSON.parse(res.rows.item(i).calc);
26 obj.dbId = res.rows.item(i).id;
27 callback(obj);
28 }
29 }
30 );
31 }
32
33 function saveCalculation(calc){
34 openDB();
35 var res;
36 db.transaction( function(tx){
37 res = tx.executeSql('INSERT INTO Calculations(calc) VALUES(?)', [JSON.stringify(calc)]);
38 });
39 return res.insertId
40 }
41
42 function updateCalculation(calc){
43 openDB();
44 var index = calc.dbId
45 db.transaction(function(tx){
46 tx.executeSql('UPDATE Calculations SET calc = ? WHERE id = ?', [JSON.stringify(calc), index])
47 });
48 }
49
50 function removeCalculation(calc){
51 openDb();
52 db.transaction(function(tx){
53 tx.executeSql('DELETE FROM Calculations WHERE id = ?', [calc.dbId]);
54 });
55 }
56}
057
=== modified file 'calculator.qml'
--- calculator.qml 2013-03-02 09:26:56 +0000
+++ calculator.qml 2013-03-08 10:04:20 +0000
@@ -1,6 +1,7 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import "engine.js" as CALC3import "Simple"
4import "Scientific"
45
5/*!6/*!
6 \brief MainView with Tabs element.7 \brief MainView with Tabs element.
@@ -9,118 +10,15 @@
9*/10*/
1011
11MainView {12MainView {
13 id: mainView
12 // objectName for functional testing purposes (autopilot-qt5)14 // objectName for functional testing purposes (autopilot-qt5)
13 objectName: "calculator"15 objectName: "calculator"
1416
15 width: units.gu(50)17 width: units.gu(50)
16 height: units.gu(75)18 height: units.gu(75)
1719
18 property string formula_text: '';20 Storage{
19 property string brackets_added: '';21 id: storage
20 property string formula_text_for_engine: '';
21 property var formula: [];
22 property string answer: '';
23 property string angularUnit: 'RAD';
24
25 function formulaPush(visual, engine, type) {
26 var prev = null;
27 if (formula.length > 0)
28 prev = formula[formula.length-1];
29
30 var result = CALC.getFormulaTexts(prev, visual, engine, type, brackets_added.length/2)
31
32 var visual_text = result[0];
33 var engine_text = result[1];
34 var fixed_type = result[2];
35 var brackets_count = result[3];
36
37 brackets_added = brackets_added.substr(0, brackets_count*2);
38
39 if (visual_text !== null && engine_text !== null) {
40 formula_text += visual_text;
41 formula_text_for_engine += engine_text;
42 formula.push({'visual': visual_text, 'engine': engine_text, 'type': fixed_type});
43
44 answer = calculate()
45 }
46 else {
47 formulaView.showError();
48 }
49 }
50
51 function formulaPop() {
52 if (formula.length > 0) {
53 var prev = formula[formula.length-1];
54 formula_text = formula_text.substring(0, formula_text.length - prev.visual.length);
55 formula_text_for_engine = formula_text_for_engine.substring(0, formula_text_for_engine.length - prev.engine.length);
56 if (prev.type === 'function' || (prev.type === 'group' && prev.engine === '(' || prev.engine === '*('))
57 brackets_added = brackets_added.substring(0, brackets_added.length-2)
58 else if (prev.type === 'group' && prev.engine === ')')
59 brackets_added += " )"
60 formula.pop();
61
62 answer = calculate()
63 }
64 }
65
66 function formulaReset() {
67 formula_text = '';
68 formula_text_for_engine = '';
69 formula = [];
70 answer = "";
71 brackets_added = '';
72 }
73
74 function calculate() {
75
76 console.debug('Formula for engine: ' + formula_text_for_engine)
77
78 var result = 0;
79 try {
80 result = CALC.parse(angularUnit + formula_text_for_engine + brackets_added);
81 if (result === Number.POSITIVE_INFINITY)
82 result = '∞';
83 else if (result === Number.NEGATIVE_INFINITY)
84 result = '-∞';
85 } catch(exception) {
86 if(exception instanceof CALC.DivisionByZeroError){
87 result = "division by zero error";
88 } else if(exception instanceof SyntaxError){
89 result = "";
90 } else if(exception instanceof CALC.ParenthesisError){
91 if(exception.missing === '(')
92 brackets_added = brackets_added.substr(0, brackets_added.length-2);
93 else
94 brackets_added+=(' '+exception.missing);
95 result = calculate();
96 }
97 }
98 return result;
99 }
100
101 function addFromMemory(answerToAdd, formulaData) {
102 if (answerToAdd !== '' && answerToAdd.indexOf('error') === -1 && answerToAdd.indexOf('∞') === -1) {
103 for (var i = 0; i < answerToAdd.length; i++)
104 formulaPush(answerToAdd[i], answerToAdd[i], answerToAdd[i] === '.' ? 'real' : 'number')
105 }
106 else {
107 var fd = JSON.parse(formulaData);
108
109 var prev = null;
110 if (formula.length > 0)
111 prev = formula[formula.length-1];
112
113 var result = CALC.getFormulaTexts(prev, fd[0].engine, fd[0].engine, fd[0].type, brackets_added.length/2)
114
115 if (result[0] !== null && result[1] !== null) {
116 for (var idx = 0; idx < fd.length; idx++) {
117 formula_text += fd[idx].visual;
118 formula_text_for_engine += fd[idx].engine;
119 formula.push({'visual': fd[idx].visual, 'engine': fd[idx].engine, 'type': fd[idx].type});
120 }
121 answer = calculate()
122 }
123 }
124 }22 }
12523
126 Tabs {24 Tabs {
@@ -134,82 +32,7 @@
134 title: i18n.tr("Calculator")32 title: i18n.tr("Calculator")
135 33
136 // Tab content begins here34 // Tab content begins here
137 page: Page {35 page: SimplePage{} //ScientificPage{} for a better calculator
138
139 Item {
140 anchors.fill: parent
141
142 ListView {
143 id: formulaView
144 anchors.fill: parent
145 snapMode: ListView.SnapOneItem
146 clip: true
147
148 property string currentFormula: '%1<font color="lightgray">%2</font>'.arg(formula_text).arg(brackets_added)
149 property string currentAnswer: answer
150 property color color: "#FFFFFF";
151 property bool positionedAtEnd: true;
152
153 function addCurrentToMemory() {
154 if (formula_text !== '') {
155 memory.get(memory.count-1).isLastItem = false
156 memory.get(memory.count-1).formula_data = JSON.stringify(formula)
157 memory.append({'formula': memory.get(memory.count-1).formula, 'answer': memory.get(count-1).answer, 'formula_data': '', 'isLastItem': true})
158 positionViewAtEnd();
159 }
160 }
161
162 function showError() {
163 animateError.start()
164 }
165
166 PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100}
167
168 add: Transition{
169 SequentialAnimation {
170 NumberAnimation {property: "y"; from: formulaView.footerItem.y; to: formulaView.contentY; duration: 200; }
171 ParallelAnimation{
172 NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 200 }
173 NumberAnimation { property: "y"; from: formulaView.contentY; duration: 0 }
174 }
175 }
176 }
177
178 onCurrentFormulaChanged: {
179 memory.get(memory.count-1).formula = currentFormula
180 positionViewAtEnd();
181 }
182
183 onCurrentAnswerChanged: {
184 memory.get(memory.count-1).answer = currentAnswer
185 }
186
187 onContentYChanged: {
188 positionedAtEnd = formulaView.indexAt(0, contentY+0) == formulaView.model.count-1
189 }
190
191 model: Memory{
192 id: memory
193 }
194
195 delegate: Screen {
196 id: screen
197 width: formulaView.width
198
199 onUseAnswer: addFromMemory(answerToUse, formulaData)
200 }
201
202 footer: KeyboardsView {
203 height: formulaView.height - units.gu(24)
204 }
205
206 Scrollbar {
207 flickableItem: formulaView
208 align: Qt.AlignTrailing
209 }
210 }
211 }
212 }
213 }36 }
21437
215 Tab {38 Tab {

Subscribers

People subscribed via source and target branches