25
25
property var formula: new F.Formula()
26
26
property var screenFormula: [{_text:'', _operation: '', _number:''}]
27
property bool calcKeyboardVisible: true
28
27
property bool labelVisible: false
29
28
property bool saveLabel: true
59
58
if (last.type === CALC.T_NUMBER || last.type === CALC.T_UNARY_MINUS) {
60
59
screenFormula[screenFormula.length - 1]._number += last.value.toString();
62
} else if (hasToBePushedOnSameLine(last)){
63
/* If is not a number is an operator
64
* Plus and minus can stay in number position,
66
* This is check by hasToBePushedOnSameLine()
61
} else if (last.type === CALC.T_MINUS && screenFormula[screenFormula.length - 1]._number === ''){
62
/*If it's a minus and there aren't numbers on same line yet*/
68
63
screenFormula[screenFormula.length - 1]._number += last.value.toString(); // Push on the same line
70
65
} else if (last.type === CALC.T_OPERATOR) { // This is if the first thing is an operator
73
68
else { // In all other cases operator is on an new line
74
69
if (last.value !== undefined) { // To avoid errors on console
70
screenFormula.push({_text:'', _operation: last.value.toString(), _number: ''});
76
screenFormula.push({_text:'', _operation: last.value.toString(), _number: ''});
79
74
formulaView.currentOperatorsChanged();
80
75
formulaView.forceActiveFocus();
86
// Check if an element has to be pushed on same line of calc
87
function hasToBePushedOnSameLine(element) {
88
if (element.type === CALC.T_MINUS // Is it a minus?
89
&& screenFormula[screenFormula.length - 1]._number === '' // There aren't numbers on same line yet?
96
80
function changeSign(){
214
198
Keys.onPressed: {
215
199
// No label focused
216
if (calcKeyboardVisible) {
217
201
if (event.key === Qt.Key_Escape || event.key === Qt.Key_Delete || event.key === Qt.Key_Backspace )
218
202
formulaView.atYEnd ? buttonClicked('clear') : formulaView.positionViewAtBeginning();
219
203
else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Equal)
227
211
event.text === "=") &&
228
212
event.text !== "")
229
213
buttonClicked(event.text)
231
event.accepted = true;
234
216
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Escape) {
235
217
if (event.key === Qt.Key_Escape)
236
218
saveLabel = false;
237
219
labelVisible = false;
238
calcKeyboardVisible = true;
239
220
// Remove the cursor from the label
240
221
storage.forceActiveFocus();
242
event.accepted = true;
246
226
Keys.onReleased: {
247
227
// No label focused
248
if (calcKeyboardVisible) {
249
229
if (event.key === Qt.Key_Escape || event.key === Qt.Key_Delete || event.key === Qt.Key_Backspace )
250
230
buttonReleased('clear');
251
231
else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Equal)
366
345
function saveMainLabel(newText) {
367
if (index !== 0 && saveLabel) {
368
var calculation = [];
369
var calc = storage.getCalculation(memory.get(index).dbId);
370
calc.mainLabel = newText
371
calculation.push({"calc": calc});
372
storage.updateCalculation(calculation, memory.get(index).dbId);
376
var oldLabel = storage.getCalculation(memory.get(index).dbId);
377
memory.get(index).mainLabel = oldLabel.mainLabel;
348
var calculation = [];
349
var calc = storage.getCalculation(memory.get(index).dbId);
350
calc.mainLabel = newText
351
calculation.push({"calc": calc});
352
storage.updateCalculation(calculation, memory.get(index).dbId);
356
var oldLabel = storage.getCalculation(memory.get(index).dbId);
357
memory.get(index).mainLabel = oldLabel.mainLabel;
381
362
function saveCalcLabel(idx, newText) {
382
if (index !== 0 && saveLabel) {
383
var calculation = [];
384
var calc = storage.getCalculation(memory.get(index).dbId);
385
calc.operators[idx]._text = newText;
386
calculation.push({"calc": calc});
387
storage.updateCalculation(calculation, memory.get(index).dbId);
391
var oldLabel = storage.getCalculation(memory.get(index).dbId);
392
newText = oldLabel.operators[idx]._text;
365
var calculation = [];
366
var calc = storage.getCalculation(memory.get(index).dbId);
367
calc.operators[idx]._text = newText;
368
calculation.push({"calc": calc});
369
storage.updateCalculation(calculation, memory.get(index).dbId);
373
var oldLabel = storage.getCalculation(memory.get(index).dbId);
374
newText = oldLabel.operators[idx]._text;