Merge lp:~rpadovani/ubuntu-calculator-app/1267820 into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Padovani
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 220
Merged at revision: 208
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/1267820
Merge into: lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
Diff against target: 515 lines (+149/-95)
5 files modified
Simple/CalcKeyboard.qml (+36/-1)
Simple/CalcLabel.qml (+1/-3)
Simple/KeyboardButton.qml (+8/-2)
Simple/Screen.qml (+0/-1)
Simple/SimplePage.qml (+104/-88)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/1267820
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+201313@code.launchpad.net

Commit message

Fixed #1267820

Description of the change

Changed keyboard shortcut. Now if a label is selected:
- enter ends editing
- esc ends editing and restores previous value
If no label is selected:
- enter do the calc
- ctrl + enter tears off
- esc scrolls back

To post a comment you must log in.
208. By Riccardo Padovani

Added CTRL+ENTER shortcut

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
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Tested and found numeric keys work as do + and -, but * / = . (multiply, divide, equals, point) do not. I would expect we would support all of those too.

I also can't move from one field to another when entering labels, which we should probably assign to "tab"?

209. By Riccardo Padovani

Added supporto for * / =

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
210. By Riccardo Padovani

Restart Jenkins test

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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Escape key seems not to function.

211. By Riccardo Padovani

Added support for Escape key. Added a check to result var to avoid errors

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
212. By Riccardo Padovani

Fixed clear() function

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
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

CTRL+Enter still seems a bit glitchy.

http://imgur.com/ov9pWPd

I typed in a calculation, pressed "enter" to finish it, and then "ctrl+enter" to tear off.

213. By Riccardo Padovani

Updated listView behavior to avoid keyboard scroll

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
214. By Riccardo Padovani

Added two codes for delete

215. By Riccardo Padovani

Updated onMovementEnded to avoid crash

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
Gustavo Pichorim Boiko (boiko) wrote :

Can you please replace those hardcoded values by:

163 + if(event.key === 46){
--> Qt.Key_Period

167 + if (event.key === Qt.Key_Escape || event.key === 16777216 || event.key === 16777223 || event.key === 16777219 ) {
--> Qt.Key_Escape || Qt.Key_Delete || Qt.Key_Backspace

review: Needs Fixing
216. By Riccardo Padovani

Removed harcoded codes

217. By Riccardo Padovani

Added id of buttons in CalcKeyboard.qml

218. By Riccardo Padovani

Rewrited keyshortcut handler

219. By Riccardo Padovani

Added animations for keyboard shortcut

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
220. By Riccardo Padovani

Deleted hard-coded codes

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
Gustavo Pichorim Boiko (boiko) wrote :

Code looks good now and works as expected!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Simple/CalcKeyboard.qml'
--- Simple/CalcKeyboard.qml 2013-11-15 09:27:22 +0000
+++ Simple/CalcKeyboard.qml 2014-01-23 20:12:51 +0000
@@ -24,7 +24,23 @@
24 height: grid.height+units.gu(4)24 height: grid.height+units.gu(4)
2525
26 property int calcGridUnit: width / 5026 property int calcGridUnit: width / 50
2727 property variant keyboardButtons: {'0': zeroButton,
28 '1': oneButton,
29 '2': twoButton,
30 '3': threeButton,
31 '4': fourButton,
32 '5': fiveButton,
33 '6': sixButton,
34 '7': sevenButton,
35 '8': eightButton,
36 '9': nineButton,
37 '+': plusButton,
38 '-': minusButton,
39 '*': multiplyButton,
40 '/': divideButton,
41 '=': equalsButton,
42 '.': pointButton,
43 'clear': clearButton}
2844
29 Text {45 Text {
30 visible: formulaView.__wasAtYBegining && formulaView.__displaceDist > units.gu(2)46 visible: formulaView.__wasAtYBegining && formulaView.__displaceDist > units.gu(2)
@@ -73,6 +89,7 @@
7389
74 KeyboardButton {90 KeyboardButton {
75 objectName: "signButton"91 objectName: "signButton"
92 id: signButton
76 x: (calcGridUnit*11)93 x: (calcGridUnit*11)
77 y: 094 y: 0
78 text: "+/-"95 text: "+/-"
@@ -83,6 +100,7 @@
83100
84 KeyboardButton {101 KeyboardButton {
85 objectName: "divideButton"102 objectName: "divideButton"
103 id: divideButton
86 x: (calcGridUnit*11)*2104 x: (calcGridUnit*11)*2
87 y: 0105 y: 0
88 text: "Γ·"106 text: "Γ·"
@@ -94,6 +112,7 @@
94112
95 KeyboardButton {113 KeyboardButton {
96 objectName: "multiplyButton"114 objectName: "multiplyButton"
115 id: multiplyButton
97 x: (calcGridUnit*11)*3116 x: (calcGridUnit*11)*3
98 y: 0117 y: 0
99 text: "Γ—"118 text: "Γ—"
@@ -105,6 +124,7 @@
105124
106 KeyboardButton {125 KeyboardButton {
107 objectName: "sevenButton"126 objectName: "sevenButton"
127 id: sevenButton
108 x: 0128 x: 0
109 y: (calcGridUnit*8)129 y: (calcGridUnit*8)
110 text: Number(7).toLocaleString(Qt.locale(), "f", 0)130 text: Number(7).toLocaleString(Qt.locale(), "f", 0)
@@ -115,6 +135,7 @@
115135
116 KeyboardButton {136 KeyboardButton {
117 objectName: "eightButton"137 objectName: "eightButton"
138 id: eightButton
118 x: (calcGridUnit*11)139 x: (calcGridUnit*11)
119 y: (calcGridUnit*8)140 y: (calcGridUnit*8)
120 text: Number(8).toLocaleString(Qt.locale(), "f", 0)141 text: Number(8).toLocaleString(Qt.locale(), "f", 0)
@@ -125,6 +146,7 @@
125146
126 KeyboardButton {147 KeyboardButton {
127 objectName: "nineButton"148 objectName: "nineButton"
149 id: nineButton
128 x: (calcGridUnit*11)*2150 x: (calcGridUnit*11)*2
129 y: (calcGridUnit*8)151 y: (calcGridUnit*8)
130 text: Number(9).toLocaleString(Qt.locale(), "f", 0)152 text: Number(9).toLocaleString(Qt.locale(), "f", 0)
@@ -135,6 +157,7 @@
135157
136 KeyboardButton {158 KeyboardButton {
137 objectName: "minusButton"159 objectName: "minusButton"
160 id: minusButton
138 x: (calcGridUnit*11)*3161 x: (calcGridUnit*11)*3
139 y: (calcGridUnit*8)162 y: (calcGridUnit*8)
140 text: "βˆ’"163 text: "βˆ’"
@@ -146,6 +169,7 @@
146169
147 KeyboardButton {170 KeyboardButton {
148 objectName: "fourButton"171 objectName: "fourButton"
172 id: fourButton
149 x: 0173 x: 0
150 y: (calcGridUnit*8)*2174 y: (calcGridUnit*8)*2
151 text: Number(4).toLocaleString(Qt.locale(), "f", 0)175 text: Number(4).toLocaleString(Qt.locale(), "f", 0)
@@ -156,6 +180,7 @@
156180
157 KeyboardButton {181 KeyboardButton {
158 objectName: "fiveButton"182 objectName: "fiveButton"
183 id: fiveButton
159 x: (calcGridUnit*11)184 x: (calcGridUnit*11)
160 y: (calcGridUnit*8)*2185 y: (calcGridUnit*8)*2
161 text: Number(5).toLocaleString(Qt.locale(), "f", 0)186 text: Number(5).toLocaleString(Qt.locale(), "f", 0)
@@ -166,6 +191,7 @@
166191
167 KeyboardButton {192 KeyboardButton {
168 objectName: "sixButton"193 objectName: "sixButton"
194 id: sixButton
169 x: (calcGridUnit*11)*2195 x: (calcGridUnit*11)*2
170 y: (calcGridUnit*8)*2196 y: (calcGridUnit*8)*2
171 text: Number(6).toLocaleString(Qt.locale(), "f", 0)197 text: Number(6).toLocaleString(Qt.locale(), "f", 0)
@@ -176,6 +202,7 @@
176202
177 KeyboardButton {203 KeyboardButton {
178 objectName: "plusButton"204 objectName: "plusButton"
205 id: plusButton
179 x: (calcGridUnit*11)*3206 x: (calcGridUnit*11)*3
180 y: (calcGridUnit*8)*2207 y: (calcGridUnit*8)*2
181 text: "+"208 text: "+"
@@ -187,6 +214,7 @@
187214
188 KeyboardButton {215 KeyboardButton {
189 objectName: "oneButton"216 objectName: "oneButton"
217 id: oneButton
190 x: 0218 x: 0
191 y: (calcGridUnit*8)*3219 y: (calcGridUnit*8)*3
192 text: Number(1).toLocaleString(Qt.locale(), "f", 0)220 text: Number(1).toLocaleString(Qt.locale(), "f", 0)
@@ -197,6 +225,7 @@
197225
198 KeyboardButton {226 KeyboardButton {
199 objectName: "twoButton"227 objectName: "twoButton"
228 id: twoButton
200 x: (calcGridUnit*11)229 x: (calcGridUnit*11)
201 y: (calcGridUnit*8)*3230 y: (calcGridUnit*8)*3
202 text: Number(2).toLocaleString(Qt.locale(), "f", 0)231 text: Number(2).toLocaleString(Qt.locale(), "f", 0)
@@ -207,6 +236,7 @@
207236
208 KeyboardButton {237 KeyboardButton {
209 objectName: "threeButton"238 objectName: "threeButton"
239 id: threeButton
210 x: (calcGridUnit*11)*2240 x: (calcGridUnit*11)*2
211 y: (calcGridUnit*8)*3241 y: (calcGridUnit*8)*3
212 text: Number(3).toLocaleString(Qt.locale(), "f", 0)242 text: Number(3).toLocaleString(Qt.locale(), "f", 0)
@@ -217,6 +247,7 @@
217247
218 KeyboardButton {248 KeyboardButton {
219 objectName: "equalsButton"249 objectName: "equalsButton"
250 id: equalsButton
220 x: (calcGridUnit*11)*3251 x: (calcGridUnit*11)*3
221 y: (calcGridUnit*8)*3252 y: (calcGridUnit*8)*3
222 height: (calcGridUnit*14)253 height: (calcGridUnit*14)
@@ -232,6 +263,7 @@
232263
233 KeyboardButton {264 KeyboardButton {
234 objectName: "zeroButton"265 objectName: "zeroButton"
266 id: zeroButton
235 x: 0267 x: 0
236 y: (calcGridUnit*8)*4268 y: (calcGridUnit*8)*4
237 width: (calcGridUnit*20)269 width: (calcGridUnit*20)
@@ -243,6 +275,7 @@
243275
244 KeyboardButton {276 KeyboardButton {
245 objectName: "pointButton"277 objectName: "pointButton"
278 id: pointButton
246 x: (calcGridUnit*11)*2279 x: (calcGridUnit*11)*2
247 y: (calcGridUnit*8)*4280 y: (calcGridUnit*8)*4
248 text: "."281 text: "."
@@ -255,6 +288,8 @@
255 }288 }
256 }289 }
257290
291 Component.onCompleted: page.keyboardButtons = keyboardButtons
292
258 states: [293 states: [
259 State {294 State {
260 name: "calculationCompleted"295 name: "calculationCompleted"
261296
=== modified file 'Simple/CalcLabel.qml'
--- Simple/CalcLabel.qml 2013-09-13 20:46:03 +0000
+++ Simple/CalcLabel.qml 2014-01-23 20:12:51 +0000
@@ -64,9 +64,7 @@
64 calcKeyboardVisible = false64 calcKeyboardVisible = false
65 }65 }
66 else66 else
67 saveCalcLabel(index, labelText);67 labelText = saveCalcLabel(index, labelText);
68
69
70 }68 }
7169
72 readOnly: labelReadOnly70 readOnly: labelReadOnly
7371
=== modified file 'Simple/KeyboardButton.qml'
--- Simple/KeyboardButton.qml 2013-09-10 10:47:14 +0000
+++ Simple/KeyboardButton.qml 2014-01-23 20:12:51 +0000
@@ -33,13 +33,18 @@
3333
34 signal clicked()34 signal clicked()
35 signal pressAndHold()35 signal pressAndHold()
36 signal released()
37
38 onClicked: rectangle.color = pressedColor;
39 onReleased: rectangle.color = buttonColor;
3640
37 Rectangle {41 Rectangle {
42 id: rectangle
38 width: parent.width-243 width: parent.width-2
39 height: parent.height-244 height: parent.height-2
40 anchors.centerIn: parent45 anchors.centerIn: parent
41 radius: (calcGridUnit*1)46 radius: (calcGridUnit*1)
42 color: buttonMA.pressed ? pressedColor : buttonColor47 color: buttonColor
4348
44 Text {49 Text {
45 id: buttonText50 id: buttonText
@@ -52,7 +57,8 @@
52 MouseArea {57 MouseArea {
53 id: buttonMA58 id: buttonMA
54 anchors.fill: parent59 anchors.fill: parent
55 onClicked: buttonRect.clicked()60 onPressed: buttonRect.clicked()
61 onReleased: buttonRect.released()
56 onPressAndHold: buttonRect.pressAndHold();62 onPressAndHold: buttonRect.pressAndHold();
57 }63 }
58 }64 }
5965
=== modified file 'Simple/Screen.qml'
--- Simple/Screen.qml 2013-09-24 21:06:21 +0000
+++ Simple/Screen.qml 2014-01-23 20:12:51 +0000
@@ -28,7 +28,6 @@
2828
29 property var ops29 property var ops
30 property bool newCalculation: false30 property bool newCalculation: false
31 property bool labelVisible: false
32 signal useAnswer(string answerToUse, string formulaData)31 signal useAnswer(string answerToUse, string formulaData)
33 signal labelTextUpdated(int idx, string newText)32 signal labelTextUpdated(int idx, string newText)
34 signal mainLabelUpdated(int idx, string newText)33 signal mainLabelUpdated(int idx, string newText)
3534
=== modified file 'Simple/SimplePage.qml'
--- Simple/SimplePage.qml 2014-01-03 19:19:58 +0000
+++ Simple/SimplePage.qml 2014-01-23 20:12:51 +0000
@@ -22,10 +22,11 @@
22import "../formula.js" as F22import "../formula.js" as F
2323
24Page {24Page {
25
26 property var formula: new F.Formula()25 property var formula: new F.Formula()
27 property var screenFormula: [{_text:'', _operation: '', _number:''}]26 property var screenFormula: [{_text:'', _operation: '', _number:''}]
28 property bool calcKeyboardVisible: true27 property bool calcKeyboardVisible: true
28 property bool labelVisible: false
29 property bool saveLabel: true
29 /*30 /*
30 * hasToAddDot became true if dot is last pressed button.31 * hasToAddDot became true if dot is last pressed button.
31 * It is necessary only for +/-32 * It is necessary only for +/-
@@ -41,6 +42,10 @@
41 */42 */
42 property bool isFinished: true43 property bool isFinished: true
4344
45 property variant keyboardButtons: null
46
47 id: page
48
44 function formulaPush(visual) {49 function formulaPush(visual) {
45 var added = false;50 var added = false;
46 try{51 try{
@@ -104,8 +109,10 @@
104 // We modify result here to have max precision in the calc, but to have a limited number of decimal displayed109 // We modify result here to have max precision in the calc, but to have a limited number of decimal displayed
105 // .replace is to avoid to write final 0 in simple calc, because toPrecision add 0110 // .replace is to avoid to write final 0 in simple calc, because toPrecision add 0
106 // CALC.PRECISION is set in engine.js111 // CALC.PRECISION is set in engine.js
107 result = result.toPrecision(CALC.PRECISION).replace(/\.0+$/,"")112 if (result) {
108 screenFormula.push({_text:'', _operation: '=', _number: result.toString()});113 result = result.toPrecision(CALC.PRECISION).replace(/\.0+$/,"");
114 screenFormula.push({_text:'', _operation: '=', _number: result.toString()});
115 }
109 formulaView.currentOperatorsChanged();116 formulaView.currentOperatorsChanged();
110 }117 }
111118
@@ -182,73 +189,78 @@
182 clip: true189 clip: true
183 focus: true190 focus: true
184191
192 /* We need to override default behavior: when user click on up or down key
193 * screen has to go up or down of always the same size
194 * By default with up and down QT changes the focus and scrolls only if
195 * focused Item is not on screen
196 */
197 Keys.onUpPressed: {
198 if (!formulaView.atYBeginning)
199 scrollWithKeyboard(-100);
200 }
201 Keys.onDownPressed: {
202 if (!formulaView.atYEnd)
203 scrollWithKeyboard(100);
204 }
205
206 function buttonClicked(buttonName) {
207 keyboardButtons[buttonName].clicked();
208 }
209
210 function buttonReleased(buttonName) {
211 keyboardButtons[buttonName].released();
212 }
213
185 Keys.onPressed: {214 Keys.onPressed: {
186 if(event.key === Qt.Key_0){215 // No label focused
187 formulaPush(Number(0).toLocaleString(Qt.locale(), "f", 0))216 if (calcKeyboardVisible) {
188 }217 if (event.key === Qt.Key_Escape || event.key === Qt.Key_Delete || event.key === Qt.Key_Backspace )
189 if(event.key === Qt.Key_1){218 formulaView.atYEnd ? buttonClicked('clear') : formulaView.positionViewAtBeginning();
190 formulaPush(Number(1).toLocaleString(Qt.locale(), "f", 0))219 else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Equal)
191 }220 (event.modifiers & Qt.ControlModifier) ? tearedOff() : buttonClicked('=');
192 if(event.key === Qt.Key_2){221 else if ((!isNaN(event.text) ||
193 formulaPush(Number(2).toLocaleString(Qt.locale(), "f", 0))222 event.text === "+" ||
194 }223 event.text === "-" ||
195 if(event.key === Qt.Key_3){224 event.text === "*" ||
196 formulaPush(Number(3).toLocaleString(Qt.locale(), "f", 0))225 event.text === "/" ||
197 }226 event.text === "." ||
198 if(event.key === Qt.Key_4){227 event.text === "=") &&
199 formulaPush(Number(4).toLocaleString(Qt.locale(), "f", 0))228 event.text !== "")
200 }229 buttonClicked(event.text)
201 if(event.key === Qt.Key_5){230
202 formulaPush(Number(5).toLocaleString(Qt.locale(), "f", 0))231 event.accepted = true;
203 }232 }
204 if(event.key === Qt.Key_6){233 else {
205 formulaPush(Number(6).toLocaleString(Qt.locale(), "f", 0))234 if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Escape) {
206 }235 if (event.key === Qt.Key_Escape)
207 if(event.key === Qt.Key_7){236 saveLabel = false;
208 formulaPush(Number(7).toLocaleString(Qt.locale(), "f", 0))237 labelVisible = false;
209 }238 calcKeyboardVisible = true;
210 if(event.key === Qt.Key_8){239 // Remove the cursor from the label
211 formulaPush(Number(8).toLocaleString(Qt.locale(), "f", 0))240 storage.forceActiveFocus();
212 }
213 if(event.key === Qt.Key_9){
214 formulaPush(Number(9).toLocaleString(Qt.locale(), "f", 0))
215 }
216 if(event.key === 46){
217 if (!hasToAddDot) { // To avoid multiple dots
218 hasToAddDot = formulaPush(".");
219 }241 }
220 }242 event.accepted = true;
221 if(event.key === Qt.Key_Escape){243 }
222 clear();244 }
223 hasToAddDot = false;245
224 }246 Keys.onReleased: {
225 if(event.key === Qt.Key_Plus){247 // No label focused
226 formulaPush("+")248 if (calcKeyboardVisible) {
227 hasToAddDot = false;249 if (event.key === Qt.Key_Escape || event.key === Qt.Key_Delete || event.key === Qt.Key_Backspace )
228 }250 buttonReleased('clear');
229 if(event.key === Qt.Key_Minus){251 else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Equal)
230 formulaPush("-")252 buttonReleased('=');
231 hasToAddDot = false;253 else if ((!isNaN(event.text) ||
232 }254 event.text === "+" ||
233 if(event.key === Qt.Key_plusminus){255 event.text === "-" ||
234 changeSign()256 event.text === "*" ||
235 }257 event.text === "/" ||
236 if(event.key === Qt.Key_multiply){258 event.text === "." ||
237 formulaPush("*")259 event.text === "=") &&
238 hasToAddDot = false;260 event.text !== "")
239 }261 buttonReleased(event.text)
240 if(event.key === Qt.Key_division){262 }
241 formulaPush("/")263 event.accepted = true;
242 hasToAddDot = false;
243 }
244 if(event.key === Qt.Key_Enter){
245 calculate();
246 hasToAddDot = false;
247 }
248 if(event.key === 16777220){
249 calculate();
250 hasToAddDot = false;
251 }
252 }264 }
253265
254 /*266 /*
@@ -316,6 +328,8 @@
316 positionViewAtBeginning();328 positionViewAtBeginning();
317 }329 }
318330
331 currentIndex: -1;
332
319 model: Memory{333 model: Memory{
320 id: memory334 id: memory
321 Component.onCompleted: {335 Component.onCompleted: {
@@ -350,23 +364,35 @@
350 }364 }
351365
352 function saveMainLabel(newText) {366 function saveMainLabel(newText) {
353 if (index !== 0) {367 if (index !== 0 && saveLabel) {
354 var calculation = [];368 var calculation = [];
355 var calc = storage.getCalculation(memory.get(index).dbId);369 var calc = storage.getCalculation(memory.get(index).dbId);
356 calc.mainLabel = newText370 calc.mainLabel = newText
357 calculation.push({"calc": calc});371 calculation.push({"calc": calc});
358 storage.updateCalculation(calculation, memory.get(index).dbId);372 storage.updateCalculation(calculation, memory.get(index).dbId);
359 }373 }
374 else {
375 saveLabel = true;
376 var oldLabel = storage.getCalculation(memory.get(index).dbId);
377 memory.get(index).mainLabel = oldLabel.mainLabel;
378 }
360 }379 }
361380
362 function saveCalcLabel(idx, newText) {381 function saveCalcLabel(idx, newText) {
363 if (index !== 0) {382 if (index !== 0 && saveLabel) {
364 var calculation = [];383 var calculation = [];
365 var calc = storage.getCalculation(memory.get(index).dbId);384 var calc = storage.getCalculation(memory.get(index).dbId);
366 calc.operators[idx]._text = newText;385 calc.operators[idx]._text = newText;
367 calculation.push({"calc": calc});386 calculation.push({"calc": calc});
368 storage.updateCalculation(calculation, memory.get(index).dbId);387 storage.updateCalculation(calculation, memory.get(index).dbId);
369 }388 }
389 else {
390 saveLabel = true
391 var oldLabel = storage.getCalculation(memory.get(index).dbId);
392 newText = oldLabel.operators[idx]._text;
393 }
394
395 return newText;
370 }396 }
371397
372 onRemoveItem: {398 onRemoveItem: {
@@ -386,20 +412,6 @@
386 formulaView.forceActiveFocus();412 formulaView.forceActiveFocus();
387 }413 }
388414
389 /* We need to override default behavior: when user click on up or down key
390 * screen has to go up or down of always the same size
391 * By default with up and down QT changes the focus and scrolls only if
392 * focused Item is not on screen
393 */
394 Keys.onUpPressed: {
395 if (!formulaView.atYBeginning)
396 scrollWithKeyboard(-100);
397 }
398 Keys.onDownPressed: {
399 if (!formulaView.atYEnd)
400 scrollWithKeyboard(100);
401 }
402
403 onMovementStarted: {415 onMovementStarted: {
404 __wasAtYBegining = atYEnd416 __wasAtYBegining = atYEnd
405 __initialContentY = contentY417 __initialContentY = contentY
@@ -415,7 +427,14 @@
415 }427 }
416 }428 }
417 onMovementEnded: {429 onMovementEnded: {
418 if (__toBeRefresh && isFinished) {430 if (__toBeRefresh) {
431 tearedOff();
432 __toBeRefresh = false
433 }
434 }
435
436 function tearedOff(){
437 if (isFinished) {
419 isFinished = false;438 isFinished = false;
420439
421 if (formulaView.addCurrentToMemory()) {440 if (formulaView.addCurrentToMemory()) {
@@ -440,11 +459,8 @@
440459
441 storage.saveCalculations(calculations);460 storage.saveCalculations(calculations);
442 }461 }
443
444 clear();462 clear();
445 __toBeRefresh = false
446 hasToAddDot=false;463 hasToAddDot=false;
447
448 isFinished = true;464 isFinished = true;
449 }465 }
450 }466 }

Subscribers

People subscribed via source and target branches