| 1 |
/* |
| 2 |
* Copyright 2013 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
* |
| 16 |
* Author: Zsombor Egri <[email protected]> |
| 17 |
*/ |
| 18 |
|
| 19 |
import QtQuick 2.0 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import Lomiri.Layouts 1.0 |
| 22 |
|
| 23 |
Item { |
| 24 |
id: buttonGrid |
| 25 |
Layouts.item: "buttons" |
| 26 |
|
| 27 |
property real spacing: units.gu(0.5) |
| 28 |
property real buttonHeight: (buttonGrid.height - 5 * buttonGrid.spacing) / 6 |
| 29 |
property real buttonWidth: (buttonGrid.width - 3 * buttonGrid.spacing) / 4 |
| 30 |
|
| 31 |
property var operations |
| 32 |
|
| 33 |
property var __model: [ |
| 34 |
{"label": "mc", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, |
| 35 |
{"label": "m+", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, |
| 36 |
{"label": "m-", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, |
| 37 |
{"label": "mr", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, |
| 38 |
|
| 39 |
{"label": "c", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, |
| 40 |
{"label": "+/-", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, |
| 41 |
{"label": "/", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, |
| 42 |
{"label": "*", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, |
| 43 |
|
| 44 |
{"label": "7", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 45 |
{"label": "8", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 46 |
{"label": "9", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 47 |
{"label": "-", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, |
| 48 |
|
| 49 |
{"label": "4", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 50 |
{"label": "5", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 51 |
{"label": "6", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 52 |
{"label": "+", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, |
| 53 |
|
| 54 |
{"label": "1", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 55 |
{"label": "2", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 56 |
{"label": "3", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 57 |
{"label": "=", "color": "orange", "width" : buttonWidth, "height": buttonHeight * 2 + spacing}, |
| 58 |
] |
| 59 |
property var __lastRow: [ |
| 60 |
{"label": "0", "color": "#5f5f5f", "width" : 2 * buttonWidth + spacing, "height": buttonHeight}, |
| 61 |
{"label": ".", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, |
| 62 |
] |
| 63 |
Grid { |
| 64 |
id: grid |
| 65 |
spacing: buttonGrid.spacing |
| 66 |
anchors.fill: parent |
| 67 |
|
| 68 |
// memory |
| 69 |
Repeater { |
| 70 |
model: __model |
| 71 |
delegate: Button { |
| 72 |
text: modelData.label |
| 73 |
color: modelData.color |
| 74 |
width: modelData.width |
| 75 |
height: modelData.height |
| 76 |
onClicked: operations.execute(modelData.label) |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
Row { |
| 81 |
anchors{ |
| 82 |
top: grid.bottom |
| 83 |
topMargin: -buttonHeight |
| 84 |
} |
| 85 |
|
| 86 |
spacing: buttonGrid.spacing |
| 87 |
|
| 88 |
// memory |
| 89 |
Repeater { |
| 90 |
model: __lastRow |
| 91 |
delegate: Button { |
| 92 |
text: modelData.label |
| 93 |
color: modelData.color |
| 94 |
width: modelData.width |
| 95 |
height: modelData.height |
| 96 |
onClicked: operations.execute(modelData.label) |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
} |