Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable torch color and SOS from pulley #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 127 additions & 31 deletions qml/pages/FirstPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import QtQuick 2.2
import Sailfish.Silica 1.0
import QtQuick.LocalStorage 2.0

Page {
id: page
Expand All @@ -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
Expand All @@ -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 = "white"
}
switch(morseCounter)
{
Expand Down Expand Up @@ -133,43 +159,113 @@ 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)
};
}

Rectangle{
id: torchRectangle
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
color: "white"

MouseArea {
anchors.fill: parent
onClicked: {
// console.debug("tapped...");
toggleTimer();
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()
}
}
BusyIndicator {
id: torchBusyIndicator
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: false

Rectangle{
id: torchRectangle
anchors.fill: parent
color: torchColor

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"
}
}
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

Component.onCompleted: {
applyColor()
}
}