99 lines
2.8 KiB
QML
99 lines
2.8 KiB
QML
import QtQuick 2.0
|
||
import Sailfish.Silica 1.0
|
||
import "../components"
|
||
|
||
// Un parametro in una card: titolo a sinistra, valore a destra, riga di
|
||
// dettaglio e barra opzionale. level: 0 = ok, 1 = attenzione, 2 = critico.
|
||
Rectangle {
|
||
id: card
|
||
|
||
property string title
|
||
property string value
|
||
property string detail
|
||
property real progress: -1
|
||
property int level: 0
|
||
// Una card toccabile mostra il chevron e porta a una pagina di dettaglio.
|
||
property bool interactive: false
|
||
|
||
signal clicked()
|
||
|
||
function levelColor() {
|
||
if (level === 2) return "#e53935"
|
||
if (level === 1) return "#ffb300"
|
||
return "#43a047"
|
||
}
|
||
|
||
width: parent ? parent.width : 0
|
||
height: content.height + 2 * Theme.paddingMedium
|
||
radius: Theme.paddingSmall
|
||
color: Theme.rgba(Theme.highlightBackgroundColor, 0.08)
|
||
|
||
Column {
|
||
id: content
|
||
x: Theme.paddingMedium
|
||
y: Theme.paddingMedium
|
||
width: parent.width - 2 * Theme.paddingMedium
|
||
spacing: Theme.paddingSmall / 2
|
||
|
||
Row {
|
||
width: parent.width
|
||
|
||
Label {
|
||
text: card.title
|
||
font.pixelSize: Theme.fontSizeSmall
|
||
color: Theme.secondaryColor
|
||
width: parent.width * (card.interactive ? 0.50 : 0.55)
|
||
truncationMode: TruncationMode.Fade
|
||
}
|
||
|
||
Label {
|
||
text: card.value
|
||
font.pixelSize: Theme.fontSizeMedium
|
||
color: card.level === 0 ? Theme.primaryColor : card.levelColor()
|
||
horizontalAlignment: Text.AlignRight
|
||
width: parent.width * (card.interactive ? 0.40 : 0.45)
|
||
truncationMode: TruncationMode.Fade
|
||
}
|
||
|
||
Label {
|
||
visible: card.interactive
|
||
text: "›"
|
||
width: parent.width * 0.10
|
||
horizontalAlignment: Text.AlignRight
|
||
font.pixelSize: Theme.fontSizeMedium
|
||
color: Theme.secondaryColor
|
||
}
|
||
}
|
||
|
||
Label {
|
||
text: card.detail
|
||
visible: card.detail !== ""
|
||
font.pixelSize: Theme.fontSizeExtraSmall
|
||
color: Theme.secondaryColor
|
||
width: parent.width
|
||
wrapMode: Text.WordWrap
|
||
}
|
||
|
||
Rectangle {
|
||
visible: card.progress >= 0
|
||
width: parent.width
|
||
height: 4
|
||
radius: 2
|
||
color: Theme.rgba(Theme.primaryColor, 0.15)
|
||
|
||
Rectangle {
|
||
width: parent.width * Math.max(0, Math.min(100, card.progress)) / 100
|
||
height: parent.height
|
||
radius: 2
|
||
color: card.levelColor()
|
||
}
|
||
}
|
||
}
|
||
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
enabled: card.interactive
|
||
onClicked: card.clicked()
|
||
}
|
||
}
|