From ef5baad9ff47cfe32bb4f97368e0b3148765caa6 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Sat, 7 Dec 2013 17:33:25 +0200 Subject: shuffle stuff around and add directory for tests --- harbour-unitmaster.desktop | 6 -- harbour-unitmaster.png | Bin 4971 -> 0 bytes harbour-unitmaster.pro | 52 +------------- qml/harbour-unitmaster.qml | 15 ---- qml/pages/AboutPage.qml | 31 -------- qml/pages/AngleModel.qml | 50 ------------- qml/pages/LengthModel.qml | 92 ------------------------ qml/pages/MassModel.qml | 50 ------------- qml/pages/PressureModel.qml | 71 ------------------ qml/pages/QuantityModel.qml | 43 ----------- qml/pages/QuantityPage.qml | 136 ----------------------------------- qml/pages/SelectQuantityPage.qml | 46 ------------ qml/pages/TemperatureModel.qml | 43 ----------- qml/pages/helpers.js | 5 -- rpm/harbour-unitmaster.yaml | 23 +++--- src/harbour-unitmaster.desktop | 6 ++ src/harbour-unitmaster.png | Bin 0 -> 4971 bytes src/main.cpp | 51 +++++++++++++ src/qml/harbour-unitmaster.qml | 15 ++++ src/qml/pages/AboutPage.qml | 31 ++++++++ src/qml/pages/AngleModel.qml | 50 +++++++++++++ src/qml/pages/LengthModel.qml | 92 ++++++++++++++++++++++++ src/qml/pages/MassModel.qml | 50 +++++++++++++ src/qml/pages/PressureModel.qml | 71 ++++++++++++++++++ src/qml/pages/QuantityModel.qml | 43 +++++++++++ src/qml/pages/QuantityPage.qml | 136 +++++++++++++++++++++++++++++++++++ src/qml/pages/SelectQuantityPage.qml | 46 ++++++++++++ src/qml/pages/TemperatureModel.qml | 43 +++++++++++ src/qml/pages/helpers.js | 5 ++ src/src.pro | 47 ++++++++++++ src/unitmaster.cpp | 51 ------------- tests/main.cpp | 3 + 32 files changed, 707 insertions(+), 696 deletions(-) delete mode 100644 harbour-unitmaster.desktop delete mode 100644 harbour-unitmaster.png delete mode 100644 qml/harbour-unitmaster.qml delete mode 100644 qml/pages/AboutPage.qml delete mode 100644 qml/pages/AngleModel.qml delete mode 100644 qml/pages/LengthModel.qml delete mode 100644 qml/pages/MassModel.qml delete mode 100644 qml/pages/PressureModel.qml delete mode 100644 qml/pages/QuantityModel.qml delete mode 100644 qml/pages/QuantityPage.qml delete mode 100644 qml/pages/SelectQuantityPage.qml delete mode 100644 qml/pages/TemperatureModel.qml delete mode 100644 qml/pages/helpers.js create mode 100644 src/harbour-unitmaster.desktop create mode 100644 src/harbour-unitmaster.png create mode 100644 src/main.cpp create mode 100644 src/qml/harbour-unitmaster.qml create mode 100644 src/qml/pages/AboutPage.qml create mode 100644 src/qml/pages/AngleModel.qml create mode 100644 src/qml/pages/LengthModel.qml create mode 100644 src/qml/pages/MassModel.qml create mode 100644 src/qml/pages/PressureModel.qml create mode 100644 src/qml/pages/QuantityModel.qml create mode 100644 src/qml/pages/QuantityPage.qml create mode 100644 src/qml/pages/SelectQuantityPage.qml create mode 100644 src/qml/pages/TemperatureModel.qml create mode 100644 src/qml/pages/helpers.js create mode 100644 src/src.pro delete mode 100644 src/unitmaster.cpp create mode 100644 tests/main.cpp diff --git a/harbour-unitmaster.desktop b/harbour-unitmaster.desktop deleted file mode 100644 index 27dd6d4..0000000 --- a/harbour-unitmaster.desktop +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Type=Application -X-Nemo-Application-Type=silica-qt5 -Name=Unit Master -Icon=harbour-unitmaster -Exec=harbour-unitmaster diff --git a/harbour-unitmaster.png b/harbour-unitmaster.png deleted file mode 100644 index e54207a..0000000 Binary files a/harbour-unitmaster.png and /dev/null differ diff --git a/harbour-unitmaster.pro b/harbour-unitmaster.pro index a7024f6..26d5720 100644 --- a/harbour-unitmaster.pro +++ b/harbour-unitmaster.pro @@ -1,49 +1,3 @@ -# 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 - -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 += link_pkgconfig -PKGCONFIG += sailfishapp -INCLUDEPATH += /usr/include/sailfishapp - -OTHER_FILES += $$files(rpm/*) \ - qml/pages/AboutPage.qml - -#CONFIG += sailfishapp - -SOURCES += src/unitmaster.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 \ - harbour-unitmaster.desktop \ - qml/harbour-unitmaster.qml \ - rpm/harbour-unitmaster.yaml \ - rpm/harbour-unitmaster.spec - +TEMPLATE = subdirs +SUBDIRS = src tests +CONFIG += ordered diff --git a/qml/harbour-unitmaster.qml b/qml/harbour-unitmaster.qml deleted file mode 100644 index 5d3cf21..0000000 --- a/qml/harbour-unitmaster.qml +++ /dev/null @@ -1,15 +0,0 @@ -import QtQuick 2.0 -import Sailfish.Silica 1.0 -import "pages" - -ApplicationWindow -{ - initialPage: SelectQuantityPage { } - cover: CoverBackground { - CoverPlaceholder { - text: "Unit Master" - } - } -} - - diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml deleted file mode 100644 index 0810846..0000000 --- a/qml/pages/AboutPage.qml +++ /dev/null @@ -1,31 +0,0 @@ -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/qml/pages/AngleModel.qml b/qml/pages/AngleModel.qml deleted file mode 100644 index a81adb4..0000000 --- a/qml/pages/AngleModel.qml +++ /dev/null @@ -1,50 +0,0 @@ -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/qml/pages/LengthModel.qml b/qml/pages/LengthModel.qml deleted file mode 100644 index a374be3..0000000 --- a/qml/pages/LengthModel.qml +++ /dev/null @@ -1,92 +0,0 @@ -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 deleted file mode 100644 index cadcdf0..0000000 --- a/qml/pages/MassModel.qml +++ /dev/null @@ -1,50 +0,0 @@ -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/PressureModel.qml b/qml/pages/PressureModel.qml deleted file mode 100644 index 2196f8a..0000000 --- a/qml/pages/PressureModel.qml +++ /dev/null @@ -1,71 +0,0 @@ -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/qml/pages/QuantityModel.qml b/qml/pages/QuantityModel.qml deleted file mode 100644 index f7e3844..0000000 --- a/qml/pages/QuantityModel.qml +++ /dev/null @@ -1,43 +0,0 @@ -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/qml/pages/QuantityPage.qml b/qml/pages/QuantityPage.qml deleted file mode 100644 index 0d5c4de..0000000 --- a/qml/pages/QuantityPage.qml +++ /dev/null @@ -1,136 +0,0 @@ -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/qml/pages/SelectQuantityPage.qml b/qml/pages/SelectQuantityPage.qml deleted file mode 100644 index 4e1456d..0000000 --- a/qml/pages/SelectQuantityPage.qml +++ /dev/null @@ -1,46 +0,0 @@ -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/qml/pages/TemperatureModel.qml b/qml/pages/TemperatureModel.qml deleted file mode 100644 index 74fc7d2..0000000 --- a/qml/pages/TemperatureModel.qml +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index dd7ad7c..0000000 --- a/qml/pages/helpers.js +++ /dev/null @@ -1,5 +0,0 @@ -.pragma library - -function capitalize(str) { - return str.substr(0, 1).toUpperCase() + str.substr(1); -} diff --git a/rpm/harbour-unitmaster.yaml b/rpm/harbour-unitmaster.yaml index 662aefc..e9ed7c6 100644 --- a/rpm/harbour-unitmaster.yaml +++ b/rpm/harbour-unitmaster.yaml @@ -18,15 +18,22 @@ PkgConfigBR: Requires: - sailfishsilica-qt5 Files: -- '%{_datadir}/applications' -- '%{_datadir}/%{name}' - '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png' - '%{_datadir}/applications/%{name}.desktop' - '%{_datadir}/%{name}/qml' -- '%{_bindir}' -- '%{_datadir}/icons/hicolor/86x86/apps' -- /usr/bin -- /usr/share/harbour-unitmaster -- /usr/share/applications -- /usr/share/icons/hicolor/86x86/apps +- '%{_bindir}/%{name}' PkgBR: [] + +SubPackages: + - Name: test + Summary: 'Tests for %{name}' + Group: Qt/Qt + AutoDepend: true + PkgConfigBR: + - Qt5QuickTest + Requires: + - qt5-qtdeclarative-import-qttest + Files: + - '%{_bindir}/tst-harbour-unitmaster' + - '%{_datadir}/tst-harbour-unitmaster/*.qml' + - '%{_datadir}/tst-harbour-unitmaster/*.sh' 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 new file mode 100644 index 0000000..e54207a Binary files /dev/null and b/src/harbour-unitmaster.png differ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..dfbb6d6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,51 @@ +/* + Copyright (C) 2013 Jolla Ltd. + Contact: Thomas Perl + 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. +*/ + +#ifdef QT_QML_DEBUG +#include +#endif + +#include + + +int main(int argc, char *argv[]) +{ + // SailfishApp::main() will display "qml/template.qml", if you need more + // control over initialization, you can use: + // + // - SailfishApp::application(int, char *[]) to get the QGuiApplication * + // - SailfishApp::createView() to get a new QQuickView * instance + // - SailfishApp::pathTo(QString) to get a QUrl to a resource file + // + // To display the view, call "show()" (will show fullscreen on device). + + return SailfishApp::main(argc, argv); +} + 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 diff --git a/src/unitmaster.cpp b/src/unitmaster.cpp deleted file mode 100644 index dfbb6d6..0000000 --- a/src/unitmaster.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright (C) 2013 Jolla Ltd. - Contact: Thomas Perl - 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. -*/ - -#ifdef QT_QML_DEBUG -#include -#endif - -#include - - -int main(int argc, char *argv[]) -{ - // SailfishApp::main() will display "qml/template.qml", if you need more - // control over initialization, you can use: - // - // - SailfishApp::application(int, char *[]) to get the QGuiApplication * - // - SailfishApp::createView() to get a new QQuickView * instance - // - SailfishApp::pathTo(QString) to get a QUrl to a resource file - // - // To display the view, call "show()" (will show fullscreen on device). - - return SailfishApp::main(argc, argv); -} - diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..0c5d40e --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,3 @@ +#include + +QUICK_TEST_MAIN(UnitMasterTestSet) -- cgit v1.2.3