File indexing completed on 2024-04-28 15:28:39
0001 #!/usr/bin/env kjscmd5 0002 0003 0004 function Calculator(ui) 0005 { 0006 // Setup entry functions 0007 var display = ui.findChild('display'); 0008 this.display = display; 0009 0010 this.one = function() { display.intValue = display.intValue*10+1; } 0011 this.two = function() { display.intValue = display.intValue*10+2; } 0012 this.three = function() { display.intValue = display.intValue*10+3; } 0013 this.four = function() { display.intValue = display.intValue*10+4; } 0014 this.five = function() { display.intValue = display.intValue*10+5; } 0015 this.six = function() { display.intValue = display.intValue*10+6; } 0016 this.seven = function() { display.intValue = display.intValue*10+7; } 0017 this.eight = function() { display.intValue = display.intValue*10+8; } 0018 this.nine = function() { display.intValue = display.intValue*10+9; } 0019 this.zero = function() { display.intValue = display.intValue*10+0; } 0020 0021 ui.connect( ui.findChild('one'), 'clicked()', this, 'one()' ); 0022 ui.connect( ui.findChild('two'), 'clicked()', this, 'two()' ); 0023 ui.connect( ui.findChild('three'), 'clicked()', this, 'three()' ); 0024 ui.connect( ui.findChild('four'), 'clicked()', this, 'four()' ); 0025 ui.connect( ui.findChild('five'), 'clicked()', this, 'five()' ); 0026 ui.connect( ui.findChild('six'), 'clicked()', this, 'six()' ); 0027 ui.connect( ui.findChild('seven'), 'clicked()', this, 'seven()' ); 0028 ui.connect( ui.findChild('eight'), 'clicked()', this, 'eight()' ); 0029 ui.connect( ui.findChild('nine'), 'clicked()', this, 'nine()' ); 0030 ui.connect( ui.findChild('zero'), 'clicked()', this, 'zero()' ); 0031 0032 this.val = 0; 0033 this.display.intValue = 0; 0034 this.lastop = function() {} 0035 0036 this.plus = function() 0037 { 0038 this.val = display.intValue+this.val; 0039 display.intValue = 0; 0040 this.lastop=this.plus 0041 } 0042 0043 this.minus = function() 0044 { 0045 this.val = display.intValue-this.val; 0046 display.intValue = 0; 0047 this.lastop=this.minus; 0048 } 0049 0050 0051 ui.connect( ui.findChild('plus'), 'clicked()', this, 'plus()' ); 0052 ui.connect( ui.findChild('minus'), 'clicked()', this, 'minus()' ); 0053 0054 this.equals = function() { this.lastop(); display.intValue = this.val; } 0055 this.clear = function() { this.lastop=function(){}; display.intValue = 0; this.val = 0; } 0056 0057 ui.connect( ui.findChild('equals'), 'clicked()', this, 'equals()' ); 0058 ui.connect( ui.findChild('clear'), 'clicked()', this, 'clear()' ); 0059 } 0060 0061 var loader = new QUiLoader(); 0062 var ui = loader.load('calc.ui', this); 0063 var calc = new Calculator(ui); 0064 0065 ui.show(); 0066 exec(); 0067