summaryrefslogtreecommitdiffstats
path: root/demos/declarative/calculator
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-04-22 04:47:24 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-04-22 04:47:24 (GMT)
commit2366667fc97eb6a56203b2dd7dac776ff4164abd (patch)
treeb2acb6cc6bfe475d7e619e4788973b61fff775e0 /demos/declarative/calculator
parent2c762f3b8b284a7c6dc0c499b7052013bad5b707 (diff)
downloadQt-2366667fc97eb6a56203b2dd7dac776ff4164abd.zip
Qt-2366667fc97eb6a56203b2dd7dac776ff4164abd.tar.gz
Qt-2366667fc97eb6a56203b2dd7dac776ff4164abd.tar.bz2
Initial import of kinetic-dui branch from the old kinetic
Diffstat (limited to 'demos/declarative/calculator')
-rw-r--r--demos/declarative/calculator/CalcButton.qml40
-rw-r--r--demos/declarative/calculator/calculator.js87
-rw-r--r--demos/declarative/calculator/calculator.qml83
-rw-r--r--demos/declarative/calculator/pics/button-pressed.pngbin0 -> 644 bytes
-rw-r--r--demos/declarative/calculator/pics/button-pressed.sci5
-rw-r--r--demos/declarative/calculator/pics/button.pngbin0 -> 635 bytes
-rw-r--r--demos/declarative/calculator/pics/button.sci5
-rw-r--r--demos/declarative/calculator/pics/clear.pngbin0 -> 611 bytes
8 files changed, 220 insertions, 0 deletions
diff --git a/demos/declarative/calculator/CalcButton.qml b/demos/declarative/calculator/CalcButton.qml
new file mode 100644
index 0000000..c925314
--- /dev/null
+++ b/demos/declarative/calculator/CalcButton.qml
@@ -0,0 +1,40 @@
+<Item id="Button" width="50" height="30">
+
+ <properties>
+ <Property name="operation" type="string"/>
+ <Property name="toggable" value="false"/>
+ <Property name="toggled" value="false"/>
+ </properties>
+
+ <Script>
+ function buttonClicked(operation) {
+ if (Button.toggable == true) {
+ if (Button.toggled == true) {
+ Button.toggled = false;
+ Button.state = 'Toggled';
+ } else {
+ Button.toggled = true;
+ Button.state = '';
+ }
+ }
+ else
+ doOp(operation);
+ }
+ </Script>
+
+ <Image id="Image" src="pics/button.sci" width="{Button.width}" height="{Button.height}"/>
+ <Image id="ImagePressed" src="pics/button-pressed.sci" width="{Button.width}" height="{Button.height}" opacity="0"/>
+ <Text anchors.centeredIn="{Image}" text="{Button.operation}" color="white" font.bold="true"/>
+ <MouseRegion id="MouseRegion" anchors.fill="{Button}" onClicked="buttonClicked(Button.operation)"/>
+
+ <states>
+ <State name="Pressed" when="{MouseRegion.pressed == true}">
+ <SetProperties target="{ImagePressed}" opacity="1"/>
+ </State>
+ <State name="Toggled" when="{Button.toggled == true}">
+ <SetProperties target="{ImagePressed}" opacity="1"/>
+ </State>
+ </states>
+
+</Item>
+
diff --git a/demos/declarative/calculator/calculator.js b/demos/declarative/calculator/calculator.js
new file mode 100644
index 0000000..774b232
--- /dev/null
+++ b/demos/declarative/calculator/calculator.js
@@ -0,0 +1,87 @@
+
+var curVal = 0;
+var memory = 0;
+var lastOp = "";
+var timer = 0;
+
+function disabled(op) {
+ if (op == "." && CurNum.text.toString().search(/\./) != -1) {
+ return true;
+ } else if (op == "Sqrt" && CurNum.text.toString().search(/-/) != -1) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function doOp(op) {
+ if (disabled(op)) {
+ return;
+ }
+
+ if (op.toString().length==1 && ((op >= "0" && op <= "9") || op==".") ) {
+ if (CurNum.text.toString().length >= 14)
+ return; // No arbitrary length numbers
+ if (lastOp.toString().length == 1 && ((lastOp >= "0" && lastOp <= "9") || lastOp==".") ) {
+ CurNum.text = CurNum.text + op.toString();
+ } else {
+ CurNum.text = op;
+ }
+ lastOp = op;
+ return;
+ }
+ lastOp = op;
+
+ // Pending operations
+ if (CurrentOperation.text == "+") {
+ CurNum.text = Number(CurNum.text.valueOf()) + Number(curVal.valueOf());
+ } else if (CurrentOperation.text == "-") {
+ CurNum.text = Number(curVal) - Number(CurNum.text.valueOf());
+ } else if (CurrentOperation.text == "x") {
+ CurNum.text = Number(curVal) * Number(CurNum.text.valueOf());
+ } else if (CurrentOperation.text == "/") {
+ CurNum.text = Number(Number(curVal) / Number(CurNum.text.valueOf())).toString();
+ } else if (CurrentOperation.text == "=") {
+ }
+
+ if (op == "+" || op == "-" || op == "x" || op == "/") {
+ CurrentOperation.text = op;
+ curVal = CurNum.text.valueOf();
+ return;
+ }
+ curVal = 0;
+ CurrentOperation.text = "";
+
+ // Immediate operations
+ if (op == "1/x") { // reciprocal
+ CurNum.text = (1 / CurNum.text.valueOf()).toString();
+ } else if (op == "^2") { // squared
+ CurNum.text = (CurNum.text.valueOf() * CurNum.text.valueOf()).toString();
+ } else if (op == "Abs") {
+ CurNum.text = (Math.abs(CurNum.text.valueOf())).toString();
+ } else if (op == "Int") {
+ CurNum.text = (Math.floor(CurNum.text.valueOf())).toString();
+ } else if (op == "+/-") { // plus/minus
+ CurNum.text = (CurNum.text.valueOf() * -1).toString();
+ } else if (op == "Sqrt") { // square root
+ CurNum.text = (Math.sqrt(CurNum.text.valueOf())).toString();
+ } else if (op == "MC") { // memory clear
+ memory = 0;
+ } else if (op == "M+") { // memory increment
+ memory += CurNum.text.valueOf();
+ } else if (op == "MR") { // memory recall
+ CurNum.text = memory.toString();
+ } else if (op == "MS") { // memory set
+ memory = CurNum.text.valueOf();
+ } else if (op == "Bksp") {
+ CurNum.text = CurNum.text.toString().slice(0, -1);
+ } else if (op == "C") {
+ CurNum.text = "0";
+ } else if (op == "AC") {
+ curVal = 0;
+ memory = 0;
+ lastOp = "";
+ CurNum.text ="0";
+ }
+}
+
diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml
new file mode 100644
index 0000000..4ada896
--- /dev/null
+++ b/demos/declarative/calculator/calculator.qml
@@ -0,0 +1,83 @@
+<Rect id="MainWindow" width="320" height="270" color="black">
+ <Script src="calculator.js"/>
+
+ <VerticalLayout spacing="2" margin="2">
+ <Rect id="Container" height="60" z="2" width="316" pen.color="white" color="#343434">
+ <Text id="CurNum" font.bold="true" color="white" font.size="16" anchors.right="{Container.right}" anchors.rightMargin="5"
+ anchors.verticalCenter="{Container.verticalCenter}"/>
+ <Text id="CurrentOperation" color="white" font.bold="true" font.size="16" anchors.left="{Container.left}" anchors.leftMargin="5"
+ anchors.verticalCenter="{Container.verticalCenter}"/>
+ </Rect>
+
+ <Item width="320" height="30">
+ <CalcButton id="AdvancedCheckBox" x="55" width="206" operation="Advanced Mode" toggable="true"/>
+ </Item>
+
+ <Item width="320">
+ <Item id="BasicButtons" x="55" width="160" height="160">
+ <CalcButton operation="Bksp" id="Bksp" width="67" opacity="0"/>
+ <CalcButton operation="C" id="C" width="76"/>
+ <CalcButton operation="AC" id="AC" x="78" width="76"/>
+
+ <GridLayout id="NumKeypad" y="32" spacing="2" columns="3">
+ <CalcButton operation="7"/>
+ <CalcButton operation="8"/>
+ <CalcButton operation="9"/>
+ <CalcButton operation="4"/>
+ <CalcButton operation="5"/>
+ <CalcButton operation="6"/>
+ <CalcButton operation="1"/>
+ <CalcButton operation="2"/>
+ <CalcButton operation="3"/>
+ </GridLayout>
+
+ <HorizontalLayout y="128" spacing="2">
+ <CalcButton operation="0" width="50"/>
+ <CalcButton operation="." x="77" width="50"/>
+ <CalcButton operation="=" id="Equals" x="77" width="102"/>
+ </HorizontalLayout>
+
+ <VerticalLayout id="SimpleOperations" x="156" y="0" spacing="2">
+ <CalcButton operation="x"/>
+ <CalcButton operation="/"/>
+ <CalcButton operation="-"/>
+ <CalcButton operation="+"/>
+ </VerticalLayout>
+ </Item>
+
+ <GridLayout id="AdvancedButtons" x="350" spacing="2" columns="2" opacity="0">
+ <CalcButton operation="Abs"/>
+ <CalcButton operation="Int"/>
+ <CalcButton operation="MC"/>
+ <CalcButton operation="Sqrt"/>
+ <CalcButton operation="MR"/>
+ <CalcButton operation="^2"/>
+ <CalcButton operation="MS"/>
+ <CalcButton operation="1/x"/>
+ <CalcButton operation="M+"/>
+ <CalcButton operation="+/-"/>
+ </GridLayout>
+ </Item>
+ </VerticalLayout>
+
+ <states>
+ <State name="Advanced" when="{AdvancedCheckBox.toggled == true}">
+ <SetProperties target="{BasicButtons}" x="0"/>
+ <SetProperties target="{SimpleOperations}" y="32"/>
+ <SetProperties target="{Bksp}" opacity="1"/>
+ <SetProperties target="{C}" x="69" width="67"/>
+ <SetProperties target="{AC}" x="138" width="67"/>
+ <SetProperties target="{Equals}" width="50"/>
+ <SetProperties target="{AdvancedButtons}" x="210" opacity="1"/>
+ </State>
+ </states>
+
+ <transitions>
+ <Transition>
+ <NumericAnimation properties="x,y,width" easing="easeOutBounce" duration="500"/>
+ <NumericAnimation properties="opacity" easing="easeInOutQuad" duration="500"/>
+ </Transition>
+ </transitions>
+
+</Rect>
+
diff --git a/demos/declarative/calculator/pics/button-pressed.png b/demos/declarative/calculator/pics/button-pressed.png
new file mode 100644
index 0000000..1a24cee
--- /dev/null
+++ b/demos/declarative/calculator/pics/button-pressed.png
Binary files differ
diff --git a/demos/declarative/calculator/pics/button-pressed.sci b/demos/declarative/calculator/pics/button-pressed.sci
new file mode 100644
index 0000000..f3bc860
--- /dev/null
+++ b/demos/declarative/calculator/pics/button-pressed.sci
@@ -0,0 +1,5 @@
+gridLeft: 5
+gridTop: 5
+gridBottom: 5
+gridRight: 5
+imageFile: button-pressed.png
diff --git a/demos/declarative/calculator/pics/button.png b/demos/declarative/calculator/pics/button.png
new file mode 100644
index 0000000..88c8bf8
--- /dev/null
+++ b/demos/declarative/calculator/pics/button.png
Binary files differ
diff --git a/demos/declarative/calculator/pics/button.sci b/demos/declarative/calculator/pics/button.sci
new file mode 100644
index 0000000..b1c7929
--- /dev/null
+++ b/demos/declarative/calculator/pics/button.sci
@@ -0,0 +1,5 @@
+gridLeft: 5
+gridTop: 5
+gridBottom: 5
+gridRight: 5
+imageFile: button.png
diff --git a/demos/declarative/calculator/pics/clear.png b/demos/declarative/calculator/pics/clear.png
new file mode 100644
index 0000000..fb07a27c
--- /dev/null
+++ b/demos/declarative/calculator/pics/clear.png
Binary files differ