| 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 |
import "components" |
| 23 |
import "components/calculator.js" as Calculator |
| 24 |
|
| 25 |
/*! |
| 26 |
\brief MainView with a Label and Button elements. |
| 27 |
*/ |
| 28 |
|
| 29 |
MainView { |
| 30 |
id: mainView |
| 31 |
// objectName for functional testing purposes (autopilot-qt5) |
| 32 |
objectName: "mainView" |
| 33 |
|
| 34 |
// Note! applicationName needs to match the .desktop filename |
| 35 |
applicationName: "calculator" |
| 36 |
|
| 37 |
/* |
| 38 |
This property enables the application to change orientation |
| 39 |
when the device is rotated. The default is false. |
| 40 |
*/ |
| 41 |
automaticOrientation: true |
| 42 |
|
| 43 |
width: units.gu(40) |
| 44 |
height: units.gu(71) |
| 45 |
|
| 46 |
property var calculator: new Calculator.Calculator(numericInput, memoryIndicator); |
| 47 |
|
| 48 |
// default portrait layout |
| 49 |
Page { |
| 50 |
id: page |
| 51 |
title: i18n.tr("Calculator") |
| 52 |
anchors.fill: parent |
| 53 |
|
| 54 |
Flickable { |
| 55 |
anchors.fill: parent |
| 56 |
contentWidth: column.width |
| 57 |
contentHeight: column.height |
| 58 |
Column { |
| 59 |
id: column |
| 60 |
width: page.width |
| 61 |
height: childrenRect.height |
| 62 |
spacing: units.gu(0.5) |
| 63 |
TextField { |
| 64 |
id: numericInput |
| 65 |
anchors { |
| 66 |
left: parent.left |
| 67 |
right: parent.right |
| 68 |
} |
| 69 |
readOnly: true |
| 70 |
font.pixelSize: FontUtils.sizeToPixels("x-large") |
| 71 |
font.bold: true |
| 72 |
horizontalAlignment: Text.AlignRight |
| 73 |
height: layout.currentLayout === "landscape" ? |
| 74 |
units.gu(5) : units.gu(7) |
| 75 |
primaryItem: Label { |
| 76 |
id: memoryIndicator |
| 77 |
width: units.gu(3) |
| 78 |
height: parent.height |
| 79 |
text: "M" |
| 80 |
textSize: Label.Large |
| 81 |
font.bold: true |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
Layouts { |
| 86 |
id: layout |
| 87 |
anchors { |
| 88 |
left: parent.left |
| 89 |
right: parent.right |
| 90 |
} |
| 91 |
height: page.height - numericInput.height - mainView.header.height |
| 92 |
|
| 93 |
layouts: [ |
| 94 |
ConditionalLayout { |
| 95 |
name: "landscape" |
| 96 |
when: mainView.width > mainView.height |
| 97 |
Item { |
| 98 |
anchors.fill: parent |
| 99 |
Functions { |
| 100 |
operations: calculator |
| 101 |
anchors.fill: parent |
| 102 |
anchors.rightMargin: parent.width / 2 + units.gu(0.25) |
| 103 |
spacing: units.gu(0.4) |
| 104 |
} |
| 105 |
|
| 106 |
ItemLayout { |
| 107 |
item: "buttons" |
| 108 |
anchors.fill: parent |
| 109 |
|
| 110 |
anchors.leftMargin: parent.width / 2 + units.gu(0.25) |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
] |
| 116 |
DefaultLayout { |
| 117 |
anchors.fill: parent |
| 118 |
anchors.margins: units.gu(0.5) |
| 119 |
operations: calculator |
| 120 |
spacing: (layout.currentLayout === "landscape") ? units.gu(0.4) : units.gu(2) |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |