/usr/lib/ubuntu-ui-toolkit/examples/unit-converter/unit-converter.qml is in ubuntu-ui-toolkit-examples 0.1.46+14.04.20140408.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /*
* Copyright 2012 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import Ubuntu.Components 0.1
import "conversion.js" as Converter
/*!
\brief Example unit converter application.
The application demonstrates the usage of
- i18n
- units
- Label
- Tabs
- Tab
- Page
- ToolbarActions
- Action
- TextField and
- Button components
The application converts length and weight units between several metrics.
Related units are grouped in the same page (Tab) and conversion happens when
pressing Enter/Return after entering a number in one of the input fields (i.e.
accepting the entered text), or by pressing the "Convert" button.
The navigation between converter pages is provided by the Tabs component.
*/
MainView {
id: root
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the .desktop filename
applicationName: "unit-converter"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
automaticOrientation: true
width: units.gu(100)
height: units.gu(75)
property real margins: units.gu(2)
property real labelWidth: units.gu(12)
// Length conversion model; the unit is Mile
property var lengthModel: [
{"unit": "Inch", "rate": 63360.0},
{"unit": "Meter", "rate": 1609.344},
{"unit": "Miles", "rate": 1.0},
{"unit": "Feets", "rate": 5280.0},
{"unit": "Yards", "rate": 1760.0},
{"unit": "Kilometers", "rate": 1.609344},
]
// Weight conversion model; the base unit is Pound
property var weightModel: [
{"unit": "Pounds", "rate": 1.0},
{"unit": "Kilograms", "rate": 0.45359237},
{"unit": "Ounces", "rate": 16},
{"unit": "Stones", "rate": 0.0714285714},
{"unit": "US Tons", "rate": 0.0005},
{"unit": "UK Tons", "rate": 0.000446428571},
]
// converter page template
Component {
id: pageContent
Page {
// expose Repeater's model for reusability, so we can set it from
// outside, when we build the tabs
property alias model: converter.model
// remove the input panel when pressed outside of any text input
MouseArea {
anchors.fill: parent
onPressed: Qt.inputMethod.hide();
}
Flickable {
id: flickable
anchors {
fill: parent
margins: root.margins
}
flickableDirection: Flickable.VerticalFlick
contentWidth: pageLayout.width
contentHeight: pageLayout.height
Column {
id: pageLayout
width: flickable.width
height: childrenRect.height
spacing: units.gu(1.2)
// show as many lines as many units we have in the model
// it is assumed that the model has "unit" and "rate" roles
Repeater {
id: converter
Row {
spacing: units.gu(1)
Label {
text: i18n.tr(modelData.unit)
fontSize: "large"
width: root.labelWidth
height: input.height
verticalAlignment: Text.AlignVCenter
}
// input field performing conversion
TextField {
id: input
//errorHighlight: false
validator: DoubleValidator {notation: DoubleValidator.StandardNotation}
width: pageLayout.width - root.labelWidth - spacing
text: "0.0"
font.pixelSize: FontUtils.sizeToPixels("large")
height: units.gu(4)
// on-the-fly conversion
onTextChanged: if (activeFocus) Converter.convert(input, converter, index)
onAccepted: Qt.inputMethod.hide()
}
}
}
}
}
tools: ToolbarActions {
Action {
objectName: "action"
iconSource: Qt.resolvedUrl("toolbarIcon.png")
text: i18n.tr("Clear")
onTriggered: Converter.clear(converter)
}
}
}
}
Tabs {
id: tabs
// First tab begins here
Tab {
objectName: "Tab1"
title: i18n.tr("Lengths")
// Tab content begins here
page: Loader {
sourceComponent: pageContent
onStatusChanged: {
if (status === Loader.Ready && item) {
item.parent = parent;
item.model = lengthModel;
}
}
}
}
// Second tab begins here
Tab {
objectName: "Tab2"
title: i18n.tr("Weights")
page: Loader {
sourceComponent: pageContent
onStatusChanged: {
if (status === Loader.Ready && item) {
item.parent = parent;
item.model = weightModel;
}
}
}
}
}
}
|