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

131 lines
4.4 KiB
QML

import QtQuick 2.0
import Sailfish.Silica 1.0
// Copertina: legge api.summary (context property C++), quindi non dipende
// dallo scope delle property della pagina principale.
//
// Due righe con l'etichetta davanti: "attuale / impostata" per la casa e per
// l'acqua. Prima erano frasi lunghe ("casa · obiettivo 19,0 °C", "ACS 53,4 °C ·
// obiettivo 55 °C") e sulla cover, che e' stretta, venivano tagliate a meta':
// il numero vero spariva proprio dove serve di sfuggita.
CoverBackground {
id: cover
function t(key) {
var v = api.summary[key]
return api.formatValue(v)
}
// "22,9 / 19,0 °C": attuale e impostata, con l'unita' una volta sola.
function coppia(attuale, impostata) {
return cover.t(attuale) + " / " + cover.t(impostata) + " °C"
}
// Colore del pallino: gli stessi criteri della Home (vedi MainPage.qml).
// Un dato vecchio e' ambra come un modo attivo: un dato vecchio non e' un
// dato buono, e la copertina e' il posto dove si guarda di sfuggita.
// Rosso solo per un allarme che ferma la macchina (livello 3): un avviso
// (livello 2) e' ambra.
function statusColor() {
if (!api.hasData || api.stale)
return "orange"
var livello = api.statusLevel()
if (livello === 3)
return Theme.errorColor
if (livello === 2)
return "#ffb300"
if (livello === 1)
return Theme.highlightColor
return "#4caf50"
}
Row {
id: intestazione
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: Theme.paddingLarge
spacing: Theme.paddingSmall
Rectangle {
anchors.verticalCenter: parent.verticalCenter
width: Theme.paddingSmall
height: width
radius: width / 2
color: cover.statusColor()
}
Label {
text: "Aira"
color: Theme.primaryColor
font.pixelSize: Theme.fontSizeLarge
}
}
Column {
anchors.centerIn: parent
width: parent.width - 2 * Theme.paddingMedium
spacing: Theme.paddingMedium
Row {
width: parent.width
spacing: Theme.paddingSmall
Label {
text: qsTr("House")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
width: parent.width * 0.32
anchors.verticalCenter: parent.verticalCenter
}
Label {
text: cover.coppia("zone1_temperature", "zone1_setpoint")
// Spenta quando i numeri sono vecchi: non deve sembrare fresca.
color: api.stale ? Theme.secondaryColor : Theme.primaryColor
font.pixelSize: Theme.fontSizeSmall
font.bold: true
elide: Text.ElideRight
width: parent.width - parent.width * 0.32 - parent.spacing
anchors.verticalCenter: parent.verticalCenter
}
}
Row {
width: parent.width
spacing: Theme.paddingSmall
Label {
text: qsTr("Water")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
width: parent.width * 0.32
anchors.verticalCenter: parent.verticalCenter
}
Label {
text: cover.coppia("dhw_current", "dhw_target")
color: api.stale ? Theme.secondaryColor : Theme.primaryColor
font.pixelSize: Theme.fontSizeSmall
font.bold: true
elide: Text.ElideRight
width: parent.width - parent.width * 0.32 - parent.spacing
anchors.verticalCenter: parent.verticalCenter
}
}
}
Label {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.paddingMedium
// Qui c'e' posto per dire che i numeri non sono freschi.
text: api.stale
? qsTr("Not updated · last %1").arg(api.lastUpdate)
: qsTr("outside %1 °C").arg(cover.t("outdoor_temperature"))
color: api.stale ? "orange" : Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
truncationMode: TruncationMode.Fade
width: parent.width - 2 * Theme.paddingMedium
}
}