Merge master <-> api_changes
[profile/ivi/qtdeclarative.git] / examples / demos / calculator / calculator-desktop.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 QtQml 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 "CalculatorCore"
45 import "CalculatorCore/calculator.js" as CalcEngine
46
47 Rectangle {
48     id: window
49
50     width: 640; 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     focus: true
63     Keys.onPressed: doOp(event.text);
64
65     Item {
66         id: main
67         width: 640
68         height: 480
69         anchors.centerIn: parent
70
71         Column {
72             id: box; spacing: 8
73
74             anchors { fill: parent; topMargin: 6; bottomMargin: 6; leftMargin: 6; rightMargin: 6 }
75
76             Display {
77                 id: display
78                 width: box.width-3
79                 height: 64
80             }
81
82             Column {
83                 id: column; spacing: 6
84
85                 property real h: ((box.height - 72) / 6) - ((spacing * (6 - 1)) / 6)
86                 property real w: (box.width / 4) - ((spacing * (4 - 1)) / 4)
87
88                 Row {
89                     spacing: 6
90                     Button { width: column.w; height: column.h; color: 'purple'; operation: "Off" }
91                     Button { width: column.w; height: column.h; color: 'purple'; operation: leftArrow }
92                     Button { width: column.w; height: column.h; color: 'purple'; operation: "C" }
93                     Button { width: column.w; height: column.h; color: 'purple'; operation: "AC" }
94                 }
95
96                 Row {
97                     spacing: 6
98                     property real w: (box.width / 4) - ((spacing * (4 - 1)) / 4)
99
100                     Button { width: column.w; height: column.h; color: 'green'; operation: "mc" }
101                     Button { width: column.w; height: column.h; color: 'green'; operation: "m+" }
102                     Button { width: column.w; height: column.h; color: 'green'; operation: "m-" }
103                     Button { width: column.w; height: column.h; color: 'green'; operation: "mr" }
104                 }
105
106                 Grid {
107                     id: grid; rows: 5; columns: 5; spacing: 6
108
109                     property real w: (box.width / columns) - ((spacing * (columns - 1)) / columns)
110
111                     Button { width: grid.w; height: column.h; operation: "7"; color: 'blue' }
112                     Button { width: grid.w; height: column.h; operation: "8"; color: 'blue' }
113                     Button { width: grid.w; height: column.h; operation: "9"; color: 'blue' }
114                     Button { width: grid.w; height: column.h; operation: division }
115                     Button { width: grid.w; height: column.h; operation: squareRoot }
116                     Button { width: grid.w; height: column.h; operation: "4"; color: 'blue' }
117                     Button { width: grid.w; height: column.h; operation: "5"; color: 'blue' }
118                     Button { width: grid.w; height: column.h; operation: "6"; color: 'blue' }
119                     Button { width: grid.w; height: column.h; operation: multiplication }
120                     Button { width: grid.w; height: column.h; operation: "x^2" }
121                     Button { width: grid.w; height: column.h; operation: "1"; color: 'blue' }
122                     Button { width: grid.w; height: column.h; operation: "2"; color: 'blue' }
123                     Button { width: grid.w; height: column.h; operation: "3"; color: 'blue' }
124                     Button { width: grid.w; height: column.h; operation: "-" }
125                     Button { width: grid.w; height: column.h; operation: "1/x" }
126                     Button { width: grid.w; height: column.h; operation: "0"; color: 'blue' }
127                     Button { width: grid.w; height: column.h; operation: "." }
128                     Button { width: grid.w; height: column.h; operation: plusminus }
129                     Button { width: grid.w; height: column.h; operation: "+" }
130                     Button { width: grid.w; height: column.h; operation: "="; color: 'red' }
131                 }
132             }
133         }
134
135     }
136 }