From f5395975cd6a319f670782cd97e31d69de16f4b3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 5 Oct 2020 10:22:44 +0200 Subject: [PATCH 1/3] toggle morseing through pull down menu instead of tapping --- qml/pages/FirstPage.qml | 62 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 236bcdd..5e169e1 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -136,40 +136,44 @@ Page { torchRectangle.color = "white"; } - Rectangle{ - id: torchRectangle + SilicaFlickable { anchors.fill: parent - color: "white" - MouseArea { + PullDownMenu{ + MenuItem { + text: qsTr("Toggle morseing SOS") + onClicked: toggleTimer() + } + } + + Rectangle{ + id: torchRectangle anchors.fill: parent - onClicked: { -// console.debug("tapped..."); - toggleTimer(); + color: "white" + + BusyIndicator { + id: torchBusyIndicator + anchors.centerIn: parent + size: BusyIndicatorSize.Large + running: false + } + Label { + id: torchAboutToStartText + visible: false + anchors.bottom: torchBusyIndicator.top + anchors.bottomMargin: Theme.paddingLarge + anchors.left: parent.left + anchors.right: parent.right + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + color: Theme.highlightColor + font.family: Theme.fontFamilyHeading + font.pixelSize: Theme.fontSizeExtraLarge + text: "SOS blinking starts\nin " + morseGapLetter/1000 + "s" } } - BusyIndicator { - id: torchBusyIndicator - anchors.centerIn: parent - size: BusyIndicatorSize.Large - running: false - } - Label { - id: torchAboutToStartText - visible: false - anchors.bottom: torchBusyIndicator.top - anchors.bottomMargin: Theme.paddingLarge - anchors.left: parent.left - anchors.right: parent.right - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.WordWrap - color: Theme.highlightColor - font.family: Theme.fontFamilyHeading - font.pixelSize: Theme.fontSizeExtraLarge - text: "SOS blinking starts\nin " + morseGapLetter/1000 + "s" + SimpleTorchScreenBlank{ + activated: Qt.application.active } } - SimpleTorchScreenBlank{ - activated: Qt.application.active - } } From 399b673875aced5cfcae378938c5a94018e6f5f1 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 5 Oct 2020 15:23:09 +0200 Subject: [PATCH 2/3] allow to choose a different torch color --- qml/pages/FirstPage.qml | 102 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 5 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 5e169e1..33c7d2c 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -38,6 +38,7 @@ import QtQuick 2.2 import Sailfish.Silica 1.0 +import QtQuick.LocalStorage 2.0 Page { id: page @@ -50,6 +51,31 @@ Page { property int morseGapWord: 7 * morseUnit property int startInterval: 50 property bool morseSOS: false + property color torchColor: "white" + + readonly property var torch_color_palette: [ + // real world light colors, mostly from http://planetpixelemporium.com/tutorialpages/light.html + // sorted by lightness, https://www.hashbangcode.com/article/color-sorting-php + '#ffffff', // white aka direct sunlight + '#fffffb', // high noon sun + '#f4fffa', // standard fluorescent + + '#f2fcff', // metal halide + '#fff1e0', // halogen + '#d8f7ff', // mercury vapor + + '#ffd1b2', // sodium vapor + '#fffaf4', // carbon arc + '#ffd6aa', // tungsten 100w + + '#ffc58f', // tungsten 40w + '#fd5e53', // sunset orange, https://www.colorhexa.com/fd5e53 + '#ffb74c', // high pressure sodium + + '#ff9329', // candle + '#F31431', // red alert, https://www.colourlovers.com/color/F31431/Red_Alert + '#a700ff', // black light fluorescent + ] Timer { id: torchTimer @@ -62,10 +88,10 @@ Page { if (morseSOS) { morseCounter++; // console.debug("morseCounter:" + morseCounter); - if (torchRectangle.color == "#ffffff") { + if (torchRectangle.color != "#000000") { torchRectangle.color = "black"; } else if (torchRectangle.color == "#000000"){ - torchRectangle.color = "white"; + torchRectangle.color = torchColor } switch(morseCounter) { @@ -133,13 +159,75 @@ Page { torchAboutToStartText.visible = true; torchTimer.start(); } - torchRectangle.color = "white"; + torchRectangle.color = torchColor + } + + function _dbInit(db) + { + try { + db.transaction(function (tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS settings (key text, value text, PRIMARY KEY(key))') + }) + db.changeVersion("", "1.0"); + } catch (err) { + console.log("Error creating table in database: " + err) + }; + } + + function _dbGetHandle() + { + try { + var db = LocalStorage.openDatabaseSync("SimpleTorch", "1.0", "App settings", 32, _dbInit) + } catch (err) { + console.log("Error opening database: " + err) + } + return db + } + + function applyColor() { + var db = _dbGetHandle(); + return db.readTransaction(function(tx) { + var results = tx.executeSql('SELECT value FROM settings WHERE key = "color"') + + if(results.rows.length === 0) { + torchColor = '#ffffff' + return + } + torchColor = results.rows.item(0).value + }) + } + + function saveColor() { + var db = _dbGetHandle(); + db.transaction(function(tx) { + try { + var result = tx.executeSql('UPDATE settings SET value = ? WHERE key = "color"', [torchColor]) + if (result.rowsAffected === 0) { + tx.executeSql('INSERT INTO settings VALUES (?, ?)', ["color", torchColor]) + } + } catch (e) { + console.error(e) + } + }) } SilicaFlickable { anchors.fill: parent - PullDownMenu{ + PullDownMenu { + MenuItem { + text: qsTr("Change color") + onClicked: { + var dialog = pageStack.push("Sailfish.Silica.ColorPickerDialog") + dialog.colors = torch_color_palette + dialog.accepted.connect(function() { + torchColor = dialog.color + torchRectangle.color = torchColor + saveColor() + }) + } + } + MenuItem { text: qsTr("Toggle morseing SOS") onClicked: toggleTimer() @@ -149,7 +237,7 @@ Page { Rectangle{ id: torchRectangle anchors.fill: parent - color: "white" + color: torchColor BusyIndicator { id: torchBusyIndicator @@ -176,4 +264,8 @@ Page { activated: Qt.application.active } } + + Component.onCompleted: { + applyColor() + } } From e7229b5dbb42fdf96ad2ae9456c2f4b2640120ae Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 9 Oct 2020 23:20:48 +0200 Subject: [PATCH 3/3] always morse in white --- qml/pages/FirstPage.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 33c7d2c..734ca25 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -91,7 +91,7 @@ Page { if (torchRectangle.color != "#000000") { torchRectangle.color = "black"; } else if (torchRectangle.color == "#000000"){ - torchRectangle.color = torchColor + torchRectangle.color = "white" } switch(morseCounter) {