c844c710aa6c8e2f86cd2aded51f7246f1fa194c
[profile/ivi/qtdeclarative.git] / examples / declarative / calculator / calculator.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 1.0
43 import "Core"
44 import "Core/calculator.js" as CalcEngine
45
46 Rectangle {
47     id: window
48
49     width: 360; height: 480
50     color: "#282828"
51
52     property string rotateLeft: "\u2939"
53     property string rotateRight: "\u2935"
54     property string leftArrow: "\u2190"
55     property string division : "\u00f7"
56     property string multiplication : "\u00d7"
57     property string squareRoot : "\u221a"
58     property string plusminus : "\u00b1"
59
60     function doOp(operation) { CalcEngine.doOperation(operation) }
61
62     Item {
63         id: main
64         state: "orientation " + runtime.orientation
65
66         property bool landscapeWindow: window.width > window.height 
67         property real baseWidth: landscapeWindow ? window.height : window.width
68         property real baseHeight: landscapeWindow ? window.width : window.height
69         property real rotationDelta: landscapeWindow ? -90 : 0
70
71         rotation: rotationDelta
72         width: main.baseWidth
73         height: main.baseHeight
74         anchors.centerIn: parent
75
76         Column {
77             id: box; spacing: 8
78
79             anchors { fill: parent; topMargin: 6; bottomMargin: 6; leftMargin: 6; rightMargin: 6 }
80
81             Display {
82                 id: display
83                 width: box.width-3
84                 height: 64
85             }
86
87             Column {
88                 id: column; spacing: 6
89
90                 property real h: ((box.height - 72) / 6) - ((spacing * (6 - 1)) / 6)
91                 property real w: (box.width / 4) - ((spacing * (4 - 1)) / 4)
92
93                 Row {
94                     spacing: 6
95                     Button { width: column.w; height: column.h; color: 'purple'; operation: "Off" }
96                     Button { width: column.w; height: column.h; color: 'purple'; operation: leftArrow }
97                     Button { width: column.w; height: column.h; color: 'purple'; operation: "C" }
98                     Button { width: column.w; height: column.h; color: 'purple'; operation: "AC" }
99                 }
100
101                 Row {
102                     spacing: 6
103                     property real w: (box.width / 4) - ((spacing * (4 - 1)) / 4)
104
105                     Button { width: column.w; height: column.h; color: 'green'; operation: "mc" }
106                     Button { width: column.w; height: column.h; color: 'green'; operation: "m+" }
107                     Button { width: column.w; height: column.h; color: 'green'; operation: "m-" }
108                     Button { width: column.w; height: column.h; color: 'green'; operation: "mr" }
109                 }
110
111                 Grid {
112                     id: grid; rows: 5; columns: 5; spacing: 6
113
114                     property real w: (box.width / columns) - ((spacing * (columns - 1)) / columns)
115
116                     Button { width: grid.w; height: column.h; operation: "7"; color: 'blue' }
117                     Button { width: grid.w; height: column.h; operation: "8"; color: 'blue' }
118                     Button { width: grid.w; height: column.h; operation: "9"; color: 'blue' }
119                     Button { width: grid.w; height: column.h; operation: division }
120                     Button { width: grid.w; height: column.h; operation: squareRoot }
121                     Button { width: grid.w; height: column.h; operation: "4"; color: 'blue' }
122                     Button { width: grid.w; height: column.h; operation: "5"; color: 'blue' }
123                     Button { width: grid.w; height: column.h; operation: "6"; color: 'blue' }
124                     Button { width: grid.w; height: column.h; operation: multiplication }
125                     Button { width: grid.w; height: column.h; operation: "x^2" }
126                     Button { width: grid.w; height: column.h; operation: "1"; color: 'blue' }
127                     Button { width: grid.w; height: column.h; operation: "2"; color: 'blue' }
128                     Button { width: grid.w; height: column.h; operation: "3"; color: 'blue' }
129                     Button { width: grid.w; height: column.h; operation: "-" }
130                     Button { width: grid.w; height: column.h; operation: "1/x" }
131                     Button { width: grid.w; height: column.h; operation: "0"; color: 'blue' }
132                     Button { width: grid.w; height: column.h; operation: "." }
133                     Button { width: grid.w; height: column.h; operation: plusminus }
134                     Button { width: grid.w; height: column.h; operation: "+" }
135                     Button { width: grid.w; height: column.h; operation: "="; color: 'red' }
136                 }
137             }
138         }
139
140         states: [
141             State {
142                 name: "orientation " + Orientation.Landscape
143                 PropertyChanges { target: main; rotation: 90 + rotationDelta; width: main.baseHeight; height: main.baseWidth }
144             },
145             State {
146                 name: "orientation " + Orientation.PortraitInverted
147                 PropertyChanges { target: main; rotation: 180 + rotationDelta; }
148             },
149             State {
150                 name: "orientation " + Orientation.LandscapeInverted
151                 PropertyChanges { target: main; rotation: 270 + rotationDelta; width: main.baseHeight; height: main.baseWidth }
152             }
153         ]
154
155         transitions: Transition {
156             SequentialAnimation {
157                 RotationAnimation { direction: RotationAnimation.Shortest; duration: 300; easing.type: Easing.InOutQuint  }
158                 NumberAnimation { properties: "x,y,width,height"; duration: 300; easing.type: Easing.InOutQuint }
159             }
160         }
161     }
162 }