diff options
Diffstat (limited to 'qml')
| -rw-r--r-- | qml/harbour-unitmaster.qml | 40 | ||||
| -rw-r--r-- | qml/pages/LengthModel.qml | 92 | ||||
| -rw-r--r-- | qml/pages/MassModel.qml | 50 | ||||
| -rw-r--r-- | qml/pages/QuantityModel.qml | 33 | ||||
| -rw-r--r-- | qml/pages/QuantityPage.qml | 124 | ||||
| -rw-r--r-- | qml/pages/SelectQuantityPage.qml | 45 | ||||
| -rw-r--r-- | qml/pages/TemperatureModel.qml | 43 | ||||
| -rw-r--r-- | qml/pages/helpers.js | 5 |
8 files changed, 432 insertions, 0 deletions
diff --git a/qml/harbour-unitmaster.qml b/qml/harbour-unitmaster.qml new file mode 100644 index 0000000..7bef9ad --- /dev/null +++ b/qml/harbour-unitmaster.qml @@ -0,0 +1,40 @@ +/* + Copyright (C) 2013 Jolla Ltd. + Contact: Thomas Perl <thomas.perl@jollamobile.com> + All rights reserved. + + You may use this file under the terms of BSD license as follows: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Jolla Ltd nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "pages" + +ApplicationWindow +{ + initialPage: SelectQuantityPage { } +} + + diff --git a/qml/pages/LengthModel.qml b/qml/pages/LengthModel.qml new file mode 100644 index 0000000..a374be3 --- /dev/null +++ b/qml/pages/LengthModel.qml @@ -0,0 +1,92 @@ +import QtQuick 2.0 + +ListModel { + function from (title, value) { + var functions = { + "meter": function () { return value; }, + "kilometer": function () { return value*1000.0; }, + "decimeter": function () { return value/10.0; }, + "centimeter": function () { return value/100.0; }, + "millimeter": function () { return value/1000.0; }, + "thou": function () { return value*(25.4e-6); }, + "inch": function () { return value*0.0254; }, + "foot": function () { return value*0.3048; }, + "yard": function () { return value*0.9144; }, + "mile": function () { return value*1609.344; }, + "nautical mile": function () { return value*1852.0; } + } + return functions[title](); + } + + function to (title, value) { + var functions = { + "meter": function () { return value; }, + "kilometer": function () { return value/1000.0; }, + "decimeter": function () { return value*10.0; }, + "centimeter": function () { return value*100.0; }, + "millimeter": function () { return value*1000.0; }, + "thou": function () { return value/(25.4e-6); }, + "inch": function () { return value/0.0254; }, + "foot": function () { return value/0.3048; }, + "yard": function () { return value/0.9144; }, + "mile": function () { return value/1609.344; }, + "nautical mile": function () { return value/1852.0; } + }; + return functions[title](); + } + + ListElement { + title: "meter" + abbr: "m" + } + + ListElement { + title: "kilometer" + abbr: "km" + } + + ListElement { + title: "decimeter" + abbr: "dm" + } + + ListElement { + title: "centimeter" + abbr: "cm" + } + + ListElement { + title: "millimeter" + abbr: "mm" + } + + ListElement { + title: "thou" + abbr: "thou" + } + + ListElement { + title: "inch" + abbr: "inch" + } + + ListElement { + title: "foot" + abbr: "ft" + } + + ListElement { + title: "yard" + abbr: "yd" + } + + ListElement { + title: "mile" + abbr: "" + } + + ListElement { + title: "nautical mile" + abbr: "" + } +} diff --git a/qml/pages/MassModel.qml b/qml/pages/MassModel.qml new file mode 100644 index 0000000..cadcdf0 --- /dev/null +++ b/qml/pages/MassModel.qml @@ -0,0 +1,50 @@ +import QtQuick 2.0 + +ListModel { + function from(title, value) { + var functions = { + "kilogram": function () { return value; }, + "gram": function () { return value/1000.0; }, + "tonne": function () { return value*1000.0; }, + "pound": function () { return value*0.45359237; }, + "ounce": function () { return value*0.028349523125; } + }; + return functions[title](); + } + + function to(title, value) { + var functions = { + "kilogram": function () { return value; }, + "gram": function () { return value*1000.0; }, + "tonne": function () { return value/1000.0; }, + "pound": function () { return value/0.45359237; }, + "ounce": function () { return value/0.028349523125; } + }; + return functions[title](); + } + + ListElement { + title: "kilogram" + abbr: "kg" + } + + ListElement { + title: "gram" + abbr: "g" + } + + ListElement { + title: "tonne" + abbr: "t" + } + + ListElement { + title: "pound" + abbr: "lb" + } + + ListElement { + title: "ounce" + abbr: "oz" + } +} diff --git a/qml/pages/QuantityModel.qml b/qml/pages/QuantityModel.qml new file mode 100644 index 0000000..de0cf14 --- /dev/null +++ b/qml/pages/QuantityModel.qml @@ -0,0 +1,33 @@ +import QtQuick 2.0 + +ListModel { + ListElement { + title: "mass" + model: "MassModel.qml" + } + + ListElement { + title: "length" + model: "LengthModel.qml" + } + + ListElement { + title: "temperature" + model: "TemperatureModel.qml" + } + +// ListElement { +// title: "time" +// model: "TimeModel.qml" +// } + +// ListElement { +// title: "current" +// model: "CurrentModel.qml" +// } + +// ListElement { +// title: "area" +// model: "AreaModel.qml" +// } +} diff --git a/qml/pages/QuantityPage.qml b/qml/pages/QuantityPage.qml new file mode 100644 index 0000000..fd7e5ad --- /dev/null +++ b/qml/pages/QuantityPage.qml @@ -0,0 +1,124 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "helpers.js" as Helpers + +Page { + id: page + + property bool first: false + property string fromUnit: "" + property string modelFilename + property string quantityName + + function formatText(value, unit) { + return value.toPrecision(5) + " " + pluralize(unit, value); + } + + function updateResult() { + var f = parseFloat(fromField.text); + + if (fromField.text.length === 0) { + f = 0.0; + } + + if (fromCombo.value.length === 0 || toCombo.value.length === 0) + return; + + var model = modelLoader.item; + + var result = model.from(fromCombo.value, f); + result = model.to(toCombo.value, result); + + resultLabel.text = formatText(result, toCombo.value); + } + + function pluralize(s, n) { + if (n !== 1) { + if (s === "inch") { + return "inches"; + } else if (s === "foot") { + return "feet"; + } else if (s === "celcius") { + return s; + } + return s + "s"; + } + + return s; + } + + Component.onCompleted: { + modelLoader.setSource(modelFilename); + } + + Loader { + id: modelLoader + onLoaded: { + fromRepeater.model = modelLoader.item; + toRepeater.model = modelLoader.item; + } + } + + Column { + id: column + spacing: Theme.paddingLarge + anchors.fill: parent + + PageHeader { + title: Helpers.capitalize(page.quantityName) + } + + ComboBox { + id: fromCombo + width: parent.width + label: "From" + menu: ContextMenu { + Repeater { + id: fromRepeater + delegate: MenuItem { + text: title + } + } + } + onValueChanged: updateResult() + } + + TextField { + id: fromField + width: parent.width + placeholderText: "enter " + pluralize(fromCombo.value, 0) + inputMethodHints: Qt.ImhFormattedNumbersOnly + EnterKey.onClicked: { + parent.focus = true; + updateResult(); + } + } + + ComboBox { + id: toCombo + width: parent.width + label: "To" + menu: ContextMenu { + Repeater { + id: toRepeater + delegate: MenuItem { + text: title + } + } + } + onValueChanged: updateResult() + } + + SectionHeader { + text: "Result" + } + + Label { + id: resultLabel + height: Theme.itemSizeSmall + anchors.horizontalCenter: parent.horizontalCenter + } + } +} + + diff --git a/qml/pages/SelectQuantityPage.qml b/qml/pages/SelectQuantityPage.qml new file mode 100644 index 0000000..b39f08a --- /dev/null +++ b/qml/pages/SelectQuantityPage.qml @@ -0,0 +1,45 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "helpers.js" as H + +Page { + id: page + + QuantityModel { + id: quantityModel + } + + SilicaListView { + anchors.fill: parent + model: quantityModel + spacing: Theme.paddingLarge + delegate: BackgroundItem { + width: ListView.view.width + Label { + x: Theme.paddingLarge + text: H.capitalize(title) + anchors.verticalCenter: parent.verticalCenter + } + onClicked: { + var props = { + "first": true, + "modelFilename": model, + "quantityName": title + }; + pageStack.push(Qt.resolvedUrl("QuantityPage.qml"), props); + } + } + header: PageHeader { + title: "Quantity" + } + VerticalScrollDecorator {} + +// PullDownMenu { +// MenuItem { +// text: "About" +// } +// } + } +} + + diff --git a/qml/pages/TemperatureModel.qml b/qml/pages/TemperatureModel.qml new file mode 100644 index 0000000..74fc7d2 --- /dev/null +++ b/qml/pages/TemperatureModel.qml @@ -0,0 +1,43 @@ +import QtQuick 2.0 + +ListModel { + function from(title, value) { + var functions = { + "kelvin": function () { return value; }, + "celcius": function () { return value + 273.15; }, + "fahrenheit": function () { return (value + 459.67) * 5.0 / 9.0; }, + "rankine": function () { return value * 5.0 / 9.0; } + }; + return functions[title](); + } + + function to(title, value) { + var functions = { + "kelvin": function () { return value; }, + "celcius": function () { return value - 273.15; }, + "fahrenheit": function () { return value * 9.0 / 5.0 - 459.67; }, + "rankine": function () { return value * 9.0 / 5.0; } + }; + return functions[title](); + } + + ListElement { + title: "kelvin" + abbr: "K" + } + + ListElement { + title: "celcius" + abbr: "°C" + } + + ListElement { + title: "fahrenheit" + abbr: "F" + } + + ListElement { + title: "rankine" + abbr: "°R" + } +} diff --git a/qml/pages/helpers.js b/qml/pages/helpers.js new file mode 100644 index 0000000..dd7ad7c --- /dev/null +++ b/qml/pages/helpers.js @@ -0,0 +1,5 @@ +.pragma library + +function capitalize(str) { + return str.substr(0, 1).toUpperCase() + str.substr(1); +} |
