diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2013-12-07 17:33:25 +0200 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2013-12-07 17:33:25 +0200 |
| commit | ef5baad9ff47cfe32bb4f97368e0b3148765caa6 (patch) | |
| tree | 87d59ecc69e7981489e16aeed62115b4a4927223 /src | |
| parent | 3aeb00f43988ae607082cdabe124b9d5e123e33c (diff) | |
| download | unitmaster-ef5baad9ff47cfe32bb4f97368e0b3148765caa6.tar.gz unitmaster-ef5baad9ff47cfe32bb4f97368e0b3148765caa6.zip | |
shuffle stuff around and add directory for tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/harbour-unitmaster.desktop | 6 | ||||
| -rw-r--r-- | src/harbour-unitmaster.png | bin | 0 -> 4971 bytes | |||
| -rw-r--r-- | src/main.cpp (renamed from src/unitmaster.cpp) | 0 | ||||
| -rw-r--r-- | src/qml/harbour-unitmaster.qml | 15 | ||||
| -rw-r--r-- | src/qml/pages/AboutPage.qml | 31 | ||||
| -rw-r--r-- | src/qml/pages/AngleModel.qml | 50 | ||||
| -rw-r--r-- | src/qml/pages/LengthModel.qml | 92 | ||||
| -rw-r--r-- | src/qml/pages/MassModel.qml | 50 | ||||
| -rw-r--r-- | src/qml/pages/PressureModel.qml | 71 | ||||
| -rw-r--r-- | src/qml/pages/QuantityModel.qml | 43 | ||||
| -rw-r--r-- | src/qml/pages/QuantityPage.qml | 136 | ||||
| -rw-r--r-- | src/qml/pages/SelectQuantityPage.qml | 46 | ||||
| -rw-r--r-- | src/qml/pages/TemperatureModel.qml | 43 | ||||
| -rw-r--r-- | src/qml/pages/helpers.js | 5 | ||||
| -rw-r--r-- | src/src.pro | 47 |
15 files changed, 635 insertions, 0 deletions
diff --git a/src/harbour-unitmaster.desktop b/src/harbour-unitmaster.desktop new file mode 100644 index 0000000..27dd6d4 --- /dev/null +++ b/src/harbour-unitmaster.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Application +X-Nemo-Application-Type=silica-qt5 +Name=Unit Master +Icon=harbour-unitmaster +Exec=harbour-unitmaster diff --git a/src/harbour-unitmaster.png b/src/harbour-unitmaster.png Binary files differnew file mode 100644 index 0000000..e54207a --- /dev/null +++ b/src/harbour-unitmaster.png diff --git a/src/unitmaster.cpp b/src/main.cpp index dfbb6d6..dfbb6d6 100644 --- a/src/unitmaster.cpp +++ b/src/main.cpp diff --git a/src/qml/harbour-unitmaster.qml b/src/qml/harbour-unitmaster.qml new file mode 100644 index 0000000..5d3cf21 --- /dev/null +++ b/src/qml/harbour-unitmaster.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "pages" + +ApplicationWindow +{ + initialPage: SelectQuantityPage { } + cover: CoverBackground { + CoverPlaceholder { + text: "Unit Master" + } + } +} + + diff --git a/src/qml/pages/AboutPage.qml b/src/qml/pages/AboutPage.qml new file mode 100644 index 0000000..0810846 --- /dev/null +++ b/src/qml/pages/AboutPage.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "helpers.js" as H + +Page { + id: page + + SilicaFlickable { + anchors.fill: parent + + Column { + width: parent.width + spacing: Theme.paddingLarge + + PageHeader { + title: "About" + } + + TextArea { + readOnly: true + width: parent.width + horizontalAlignment: TextEdit.AlignHCenter + text: "Unit Master\nCopyright 2013 Oskari Timperi\n\nThe +application icon is derived from the Meanicons Icon Set\n(http://www.meanicons.com/)." + } + } + + } +} + + diff --git a/src/qml/pages/AngleModel.qml b/src/qml/pages/AngleModel.qml new file mode 100644 index 0000000..a81adb4 --- /dev/null +++ b/src/qml/pages/AngleModel.qml @@ -0,0 +1,50 @@ +import QtQuick 2.0 + +ListModel { + function from(title, value) { + var functions = { + "radian": function () { return value; }, + "degree": function () { return value*Math.PI/180.0; }, + "gon": function () { return value*Math.PI/200.0; }, + "arcminute": function () { return value*Math.PI/10800; }, + "arcsecond": function () { return value*Math.PI/648000; } + }; + return functions[title](); + } + + function to(title, value) { + var functions = { + "radian": function () { return value; }, + "degree": function () { return value*180.0/Math.PI; }, + "gon": function () { return value*200.0/Math.PI; }, + "arcminute": function () { return value*10800/Math.PI; }, + "arcsecond": function () { return value*648000/Math.PI; } + }; + return functions[title](); + } + + ListElement { + title: "radian" + abbr: "rad" + } + + ListElement { + title: "degree" + abbr: "deg" + } + + ListElement { + title: "gon" + abbr: "" + } + + ListElement { + title: "arcminute" + abbr: "" + } + + ListElement { + title: "arcsecond" + abbr: "" + } +} diff --git a/src/qml/pages/LengthModel.qml b/src/qml/pages/LengthModel.qml new file mode 100644 index 0000000..a374be3 --- /dev/null +++ b/src/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/src/qml/pages/MassModel.qml b/src/qml/pages/MassModel.qml new file mode 100644 index 0000000..cadcdf0 --- /dev/null +++ b/src/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/src/qml/pages/PressureModel.qml b/src/qml/pages/PressureModel.qml new file mode 100644 index 0000000..2196f8a --- /dev/null +++ b/src/qml/pages/PressureModel.qml @@ -0,0 +1,71 @@ +import QtQuick 2.0 + +ListModel { + function from(title, value) { + var functions = { + "pascal": function () { return value; }, + "kilopascal": function () { return value*1000; }, + "bar": function () { return value*1e5; }, + "millibar": function () { return value*100.0; }, + "pounds per square inch": function () { return value*(6.8948e3); }, + "technical atmosphere": function () { return value*0.980665e5; }, + "standard atmosphere": function () { return value*1.01325e5; }, + "torr": function () { return value*133.3224; } + }; + return functions[title](); + } + + function to(title, value) { + var functions = { + "pascal": function () { return value; }, + "kilopascal": function () { return value/1000; }, + "bar": function () { return value/1e5; }, + "millibar": function () { return value/100.0; }, + "pounds per square inch": function () { return value/(6.8948e3); }, + "technical atmosphere": function () { return value/(0.980665e5); }, + "standard atmosphere": function () { return value/(1.01325e5); }, + "torr": function () { return value/133.3224; } + }; + return functions[title](); + } + + ListElement { + title: "pascal" + abbr: "Pa" + } + + ListElement { + title: "kilopascal" + abbr: "kPa" + } + + ListElement { + title: "bar" + abbr: "" + } + + ListElement { + title: "millibar" + abbr: "mbar" + } + + ListElement { + title: "pounds per square inch" + abbr: "psi" + } + + ListElement { + title: "technical atmosphere" + abbr: "at" + } + + ListElement { + title: "standard atmosphere" + abbr: "atm" + } + + ListElement { + title: "torr" + abbr: "" + } +} diff --git a/src/qml/pages/QuantityModel.qml b/src/qml/pages/QuantityModel.qml new file mode 100644 index 0000000..f7e3844 --- /dev/null +++ b/src/qml/pages/QuantityModel.qml @@ -0,0 +1,43 @@ +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" +// } + + ListElement { + title: "angle" + model: "AngleModel.qml" + } + + ListElement { + title: "pressure" + model: "PressureModel.qml" + } +} diff --git a/src/qml/pages/QuantityPage.qml b/src/qml/pages/QuantityPage.qml new file mode 100644 index 0000000..0d5c4de --- /dev/null +++ b/src/qml/pages/QuantityPage.qml @@ -0,0 +1,136 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "helpers.js" as Helpers + +Page { + id: page + + property string modelFilename + property string quantityName + + function formatText(value, unit) { + return "%1 %2".arg(value.toPrecision(5)).arg(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 fromUnit = model.get(fromCombo.currentIndex).title; + var toUnit = model.get(toCombo.currentIndex).title; + + var result = model.from(fromUnit, f); + result = model.to(toUnit, result); + + resultLabel.text = formatText(result, toUnit); + } + + 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; + } + + function makeTitle(title, abbr) { + if (abbr.length > 0) { + return "%1 (%2)".arg(title).arg(abbr); + } + + return title; + } + + 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: makeTitle(title, abbr) + } + } + } + onValueChanged: updateResult() + } + + TextField { + id: fromField + width: parent.width + placeholderText: "enter " + pluralize(fromRepeater.model.get(fromCombo.currentIndex).title, 0) + inputMethodHints: Qt.ImhFormattedNumbersOnly + EnterKey.onClicked: { + parent.focus = true; + updateResult(); + } + onTextChanged: { + updateResult(); + } + } + + ComboBox { + id: toCombo + width: parent.width + label: "To" + menu: ContextMenu { + Repeater { + id: toRepeater + delegate: MenuItem { + text: makeTitle(title, abbr) + } + } + } + onValueChanged: updateResult() + } + + SectionHeader { + text: "Result" + } + + Label { + id: resultLabel + height: Theme.itemSizeSmall + anchors.horizontalCenter: parent.horizontalCenter + } + } +} + + diff --git a/src/qml/pages/SelectQuantityPage.qml b/src/qml/pages/SelectQuantityPage.qml new file mode 100644 index 0000000..4e1456d --- /dev/null +++ b/src/qml/pages/SelectQuantityPage.qml @@ -0,0 +1,46 @@ +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" + onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml")) + } + } + } +} + + diff --git a/src/qml/pages/TemperatureModel.qml b/src/qml/pages/TemperatureModel.qml new file mode 100644 index 0000000..74fc7d2 --- /dev/null +++ b/src/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/src/qml/pages/helpers.js b/src/qml/pages/helpers.js new file mode 100644 index 0000000..dd7ad7c --- /dev/null +++ b/src/qml/pages/helpers.js @@ -0,0 +1,5 @@ +.pragma library + +function capitalize(str) { + return str.substr(0, 1).toUpperCase() + str.substr(1); +} diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..82aa2df --- /dev/null +++ b/src/src.pro @@ -0,0 +1,47 @@ +TEMPLATE=app + +# The name of your app. +# NOTICE: name defined in TARGET has a corresponding QML filename. +# If name defined in TARGET is changed, following needs to be +# done to match new name: +# - corresponding QML filename must be changed +# - desktop icon filename must be changed +# - desktop filename must be changed +# - icon definition filename in desktop file must be changed +TARGET = harbour-unitmaster + +QT += quick qml + +CONFIG += link_pkgconfig +PKGCONFIG += sailfishapp +INCLUDEPATH += /usr/include/sailfishapp + +target.path = /usr/bin + +qml.files = qml +qml.path = /usr/share/$${TARGET} + +desktop.files = $${TARGET}.desktop +desktop.path = /usr/share/applications + +icon.files = $${TARGET}.png +icon.path = /usr/share/icons/hicolor/86x86/apps + +INSTALLS += target qml desktop icon + +#CONFIG += sailfishapp + +SOURCES += main.cpp + +OTHER_FILES += \ + qml/pages/QuantityModel.qml \ + qml/pages/MassModel.qml \ + qml/pages/SelectQuantityPage.qml \ + qml/pages/QuantityPage.qml \ + qml/pages/helpers.js \ + qml/pages/LengthModel.qml \ + qml/pages/TemperatureModel.qml \ + qml/pages/AboutPage.qml \ + harbour-unitmaster.desktop \ + qml/harbour-unitmaster.qml \ + ../rpm/$${TARGET}.spec |
