1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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: 480; height: 360
|
---|
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 | width: parent.width; height: parent.height; anchors.centerIn: parent
|
---|
67 |
|
---|
68 | Column {
|
---|
69 | id: box; spacing: 8
|
---|
70 |
|
---|
71 | anchors { fill: parent; topMargin: 6; bottomMargin: 6; leftMargin: 6; rightMargin: 6 }
|
---|
72 |
|
---|
73 | Display {
|
---|
74 | id: display
|
---|
75 | width: box.width-3
|
---|
76 | height: 64
|
---|
77 | }
|
---|
78 |
|
---|
79 | Column {
|
---|
80 | id: column; spacing: 6
|
---|
81 |
|
---|
82 | property real h: ((box.height - 72) / 6) - ((spacing * (6 - 1)) / 6)
|
---|
83 | property real w: (box.width / 4) - ((spacing * (4 - 1)) / 4)
|
---|
84 |
|
---|
85 | Row {
|
---|
86 | spacing: 6
|
---|
87 | Button { width: column.w; height: column.h; color: 'purple'; operation: "Off" }
|
---|
88 | Button { width: column.w; height: column.h; color: 'purple'; operation: leftArrow }
|
---|
89 | Button { width: column.w; height: column.h; color: 'purple'; operation: "C" }
|
---|
90 | Button { width: column.w; height: column.h; color: 'purple'; operation: "AC" }
|
---|
91 | }
|
---|
92 |
|
---|
93 | Row {
|
---|
94 | spacing: 6
|
---|
95 | property real w: (box.width / 4) - ((spacing * (4 - 1)) / 4)
|
---|
96 |
|
---|
97 | Button { width: column.w; height: column.h; color: 'green'; operation: "mc" }
|
---|
98 | Button { width: column.w; height: column.h; color: 'green'; operation: "m+" }
|
---|
99 | Button { width: column.w; height: column.h; color: 'green'; operation: "m-" }
|
---|
100 | Button { width: column.w; height: column.h; color: 'green'; operation: "mr" }
|
---|
101 | }
|
---|
102 |
|
---|
103 | Grid {
|
---|
104 | id: grid; rows: 5; columns: 5; spacing: 6
|
---|
105 |
|
---|
106 | property real w: (box.width / columns) - ((spacing * (columns - 1)) / columns)
|
---|
107 |
|
---|
108 | Button { width: grid.w; height: column.h; operation: "7"; color: 'blue' }
|
---|
109 | Button { width: grid.w; height: column.h; operation: "8"; color: 'blue' }
|
---|
110 | Button { width: grid.w; height: column.h; operation: "9"; color: 'blue' }
|
---|
111 | Button { width: grid.w; height: column.h; operation: division }
|
---|
112 | Button { width: grid.w; height: column.h; operation: squareRoot }
|
---|
113 | Button { width: grid.w; height: column.h; operation: "4"; color: 'blue' }
|
---|
114 | Button { width: grid.w; height: column.h; operation: "5"; color: 'blue' }
|
---|
115 | Button { width: grid.w; height: column.h; operation: "6"; color: 'blue' }
|
---|
116 | Button { width: grid.w; height: column.h; operation: multiplication }
|
---|
117 | Button { width: grid.w; height: column.h; operation: "x^2" }
|
---|
118 | Button { width: grid.w; height: column.h; operation: "1"; color: 'blue' }
|
---|
119 | Button { width: grid.w; height: column.h; operation: "2"; color: 'blue' }
|
---|
120 | Button { width: grid.w; height: column.h; operation: "3"; color: 'blue' }
|
---|
121 | Button { width: grid.w; height: column.h; operation: "-" }
|
---|
122 | Button { width: grid.w; height: column.h; operation: "1/x" }
|
---|
123 | Button { width: grid.w; height: column.h; operation: "0"; color: 'blue' }
|
---|
124 | Button { width: grid.w; height: column.h; operation: "." }
|
---|
125 | Button { width: grid.w; height: column.h; operation: plusminus }
|
---|
126 | Button { width: grid.w; height: column.h; operation: "+" }
|
---|
127 | Button { width: grid.w; height: column.h; operation: "="; color: 'red' }
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | states: [
|
---|
133 | State {
|
---|
134 | name: "orientation " + Orientation.Landscape
|
---|
135 | PropertyChanges { target: main; rotation: 90; width: window.height; height: window.width }
|
---|
136 | PropertyChanges { target: rotateButton; operation: rotateLeft }
|
---|
137 | },
|
---|
138 | State {
|
---|
139 | name: "orientation " + Orientation.PortraitInverted
|
---|
140 | PropertyChanges { target: main; rotation: 180; }
|
---|
141 | PropertyChanges { target: rotateButton; operation: rotateRight }
|
---|
142 | },
|
---|
143 | State {
|
---|
144 | name: "orientation " + Orientation.LandscapeInverted
|
---|
145 | PropertyChanges { target: main; rotation: 270; width: window.height; height: window.width }
|
---|
146 | PropertyChanges { target: rotateButton; operation: rotateLeft }
|
---|
147 | }
|
---|
148 | ]
|
---|
149 |
|
---|
150 | transitions: Transition {
|
---|
151 | SequentialAnimation {
|
---|
152 | PropertyAction { target: rotateButton; property: "operation" }
|
---|
153 | RotationAnimation { direction: RotationAnimation.Shortest; duration: 300; easing.type: Easing.InOutQuint }
|
---|
154 | NumberAnimation { properties: "x,y,width,height"; duration: 300; easing.type: Easing.InOutQuint }
|
---|
155 | }
|
---|
156 | }
|
---|
157 | }
|
---|
158 | }
|
---|