Files
kde-antigravity-dashboard/contents/ui/GroupCard.qml
T

137 lines
4.1 KiB
QML

/* Card per gruppo di modelli Antigravity (Gemini, Claude, GPT-OSS) */
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.components 3.0 as PC3
import org.kde.kirigami as Kirigami
Rectangle {
id: root
property string tag: ""
property string title: ""
property string models: ""
property real remaining: 1.0
property real usedPercent: 0.0
property int resetAt: 0
property int clockTick: 0
property color accentColor: "#818cf8"
function formatResetMoment() {
if (!resetAt || resetAt <= 0) return "—"
const d = new Date(resetAt * 1000)
const now = new Date()
if (d.toDateString() === now.toDateString()) {
return d.toLocaleTimeString(Qt.locale(), "HH:mm")
}
return d.toLocaleDateString(Qt.locale(), "dd/MM") + " " + d.toLocaleTimeString(Qt.locale(), "HH:mm")
}
function countdown() {
const tick = root.clockTick
if (!resetAt || resetAt <= 0) return "—"
let mins = Math.max(0, Math.floor((resetAt * 1000 - Date.now()) / 60000))
if (mins === 0) return i18n("ora")
const days = Math.floor(mins / 1440)
mins -= days * 1440
const hours = Math.floor(mins / 60)
mins -= hours * 60
return days > 0 ? i18n("%1g %2h", days, hours) : i18n("%1h %2m", hours, mins)
}
Layout.fillWidth: true
Layout.preferredHeight: 46
radius: 5
color: Qt.rgba(0, 0, 0, 0.28)
border.width: 1
border.color: root.accentColor
ColumnLayout {
anchors.fill: parent
anchors.margins: 4
spacing: 2
// Riga 1: Tag + Titolo + Modelli + % Residuo
RowLayout {
Layout.fillWidth: true
spacing: 4
Rectangle {
Layout.preferredWidth: 38
Layout.preferredHeight: 14
radius: 7
color: root.accentColor
PC3.Label {
anchors.centerIn: parent
text: root.tag
color: "#101012"
font.bold: true
font.pointSize: Kirigami.Theme.defaultFont.pointSize - 3
}
}
PC3.Label {
text: root.title
font.bold: true
font.pointSize: Kirigami.Theme.defaultFont.pointSize - 1
}
PC3.Label {
text: "· " + root.models
color: Kirigami.Theme.disabledTextColor
font.pointSize: Kirigami.Theme.defaultFont.pointSize - 3
Layout.fillWidth: true
elide: Text.ElideRight
}
PC3.Label {
text: Math.round(root.remaining * 100) + "%"
color: root.accentColor
font.bold: true
font.pointSize: Kirigami.Theme.defaultFont.pointSize
}
}
// Riga 2: Barra di avanzamento
Item {
Layout.fillWidth: true
Layout.preferredHeight: 5
Rectangle {
id: track
anchors.fill: parent
radius: 2.5
color: Qt.rgba(0, 0, 0, 0.5)
}
Rectangle {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
width: track.width * Math.max(0, Math.min(1, root.remaining))
height: parent.height
radius: 2.5
color: root.accentColor
}
}
// Riga 3: Dettaglio usato + Orario esatto + Countdown
RowLayout {
Layout.fillWidth: true
spacing: 4
PC3.Label {
text: i18n("%1% usato", root.usedPercent.toFixed(1))
color: Kirigami.Theme.disabledTextColor
font.pointSize: Kirigami.Theme.defaultFont.pointSize - 3
}
Item { Layout.fillWidth: true }
PC3.Label {
text: i18n("reset %1 (%2)", root.formatResetMoment(), root.countdown())
color: root.accentColor
font.pointSize: Kirigami.Theme.defaultFont.pointSize - 3
}
}
}
}