Files
harbour-tide/qml/cover/CoverPage.qml
T

71 lines
2.4 KiB
QML

import QtQuick 2.0
import Sailfish.Silica 1.0
import "../js/tides.js" as Tides
CoverBackground {
id: cover
Column {
anchors.centerIn: parent
spacing: Theme.paddingSmall
width: parent.width
Label {
text: "🌊 Tide"
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Theme.fontSizeLarge
color: Theme.primaryColor
}
Label {
id: portLabel
anchors.horizontalCenter: parent.horizontalCenter
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
text: qsTr("No port selected")
}
Label {
id: nextLabel
anchors.horizontalCenter: parent.horizontalCenter
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}
}
onStatusChanged: {
if (status === Cover.Active) refresh()
}
Component.onCompleted: refresh()
function refresh() {
var pref = appSettings.preferredPort
console.log("[tide] cover refresh, pref:", pref)
if (pref === "") {
portLabel.text = qsTr("No port selected")
nextLabel.text = ""
return
}
var p = null
for (var i = 0; i < Tides.PORTS.length; i++) {
if (Tides.PORTS[i][0] === pref) { p = Tides.PORTS[i]; break }
}
// preferito custom (comune): ricostruisci le costanti da lat/lon
if (!p && appSettings.preferredLat >= 0) {
var np = Tides.nearestPort(appSettings.preferredLat, appSettings.preferredLon)
var cost = np.km < 222 ? np.port[4].slice()
: Tides.synthConst(appSettings.preferredLat, appSettings.preferredLon)
p = [pref, "", appSettings.preferredLat, appSettings.preferredLon, cost, "pref"]
}
if (!p) { portLabel.text = qsTr("No port selected"); nextLabel.text = ""; return }
portLabel.text = p[0]
var ex = Tides.extrema(p, new Date(), 1)
if (ex.length > 0) {
var e = ex[0]
var kind = e.kind === "high" ? qsTr("High") : qsTr("Low")
nextLabel.text = kind + " " + Tides.fmtHM(e.t) + " · " + Tides.fmtH(e.h, appSettings.unit)
}
}
}