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