From 93cc57f06e68ce799ea8d0f66fde589bc360b69a Mon Sep 17 00:00:00 2001 From: Claudio Date: Thu, 27 Aug 2026 14:35:23 +0200 Subject: [PATCH] popup: altezza dinamica sul contenuto, senza scroll Il contenuto usciva dallo sfondo o il padding spariva: erano lo stesso errore. I margini erano ancorati, e quelli non entrano nell'implicitHeight del layout, quindi l'altezza andava indovinata a mano. Ora sono margini di layout, e contentItem e' un layout unico invece di un Item con dentro un layout ancorato: l'altezza si propaga da sola fino al popup. Il padding sul Control non serve: PlasmaExtras.Representation lo sovrascrive. --- plasmoid/contents/ui/FullRepresentation.qml | 435 ++++++++++---------- 1 file changed, 221 insertions(+), 214 deletions(-) diff --git a/plasmoid/contents/ui/FullRepresentation.qml b/plasmoid/contents/ui/FullRepresentation.qml index 2baf863..246843a 100644 --- a/plasmoid/contents/ui/FullRepresentation.qml +++ b/plasmoid/contents/ui/FullRepresentation.qml @@ -36,9 +36,18 @@ PlasmaExtras.Representation { onVisibleChanged: if (visible) now = Date.now() Layout.minimumWidth: Kirigami.Units.gridUnit * 20 - Layout.minimumHeight: Kirigami.Units.gridUnit * 12 + + // Altezza dinamica: il popup vale quanto il suo contenuto, senza scroll. + // + // Il padding sono margini di LAYOUT, non ancorati e non `padding` del + // Control: i primi entrano nell'implicitHeight del layout, gli ancorati no + // (e il contenuto traboccava), mentre `padding` qui viene sovrascritto - + // PlasmaExtras.Representation lo gestisce per conto suo. + Layout.preferredHeight: implicitHeight + header: PlasmaExtras.PlasmoidHeading { + id: headerItem visible: full.hasData // Senza, il titolo sta appiccicato ai bordi della barra. leftPadding: Kirigami.Units.largeSpacing @@ -66,253 +75,251 @@ PlasmaExtras.Representation { } } - contentItem: Item { - // Il popup si dimensiona sul contenuto: senza questo userebbe sempre - // l'altezza minima, lasciando un vuoto sotto le sezioni. - implicitHeight: sections.implicitHeight - - // Nessun dato: si spiega cosa fare, invece di mostrare un popup vuoto. - PlasmaExtras.PlaceholderMessage { - anchors.centerIn: parent - width: parent.width - Kirigami.Units.gridUnit * 4 - visible: !full.hasData - iconName: "speedometer" - text: { - if (root.stateProblem === "missing") { - return i18n("No data from the dipstick daemon") - } - if (root.stateProblem === "schema") { - return i18n("Daemon and widget versions do not match") - } - if (root.stateProblem === "malformed") { - return i18n("The state file is unreadable") - } - if (full.quota && full.quota.quota.needs_auth) { - return i18n("Not signed in") - } - return i18n("Quota unavailable") - } - explanation: { - if (root.stateProblem === "missing") { - return i18n("Start it with: systemctl --user start dipstick") - } - if (root.stateProblem === "schema") { - return i18n("Reinstall dipstick so both halves are on the same version.") + contentItem: ColumnLayout { + spacing: 0 + + PlasmaExtras.PlaceholderMessage { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.margins: Kirigami.Units.gridUnit + // Senza dato il popup non ha un contenuto che ne detti l'altezza: + // gliene serve una sensata di suo. + Layout.minimumHeight: Kirigami.Units.gridUnit * 14 + visible: !full.hasData + iconName: "speedometer" + text: { + if (root.stateProblem === "missing") { + return i18n("No data from the dipstick daemon") + } + if (root.stateProblem === "schema") { + return i18n("Daemon and widget versions do not match") + } + if (root.stateProblem === "malformed") { + return i18n("The state file is unreadable") + } + if (full.quota && full.quota.quota.needs_auth) { + return i18n("Not signed in") + } + return i18n("Quota unavailable") } - if (full.quota && full.quota.quota.needs_auth) { - return i18n("Sign in with: dipstick auth") + explanation: { + if (root.stateProblem === "missing") { + return i18n("Start it with: systemctl --user start dipstick") + } + if (root.stateProblem === "schema") { + return i18n("Reinstall dipstick so both halves are on the same version.") + } + if (full.quota && full.quota.quota.needs_auth) { + return i18n("Sign in with: dipstick auth") + } + if (full.quota && full.quota.quota.error) { + return full.quota.quota.error + } + return "" } - if (full.quota && full.quota.quota.error) { - return full.quota.quota.error + + // Quel che resta di vero quando la percentuale manca: i transcript sul + // disco. Non e' una quota - i token si sanno, i limiti no - e va detto. + ColumnLayout { + Layout.alignment: Qt.AlignHCenter + Layout.topMargin: Kirigami.Units.largeSpacing + visible: full.local !== null + spacing: 2 + + PlasmaComponents.Label { + Layout.alignment: Qt.AlignHCenter + opacity: 0.7 + font: Kirigami.Theme.smallFont + text: i18n("From local transcripts (tokens, not quota):") + } + PlasmaComponents.Label { + Layout.alignment: Qt.AlignHCenter + font: Kirigami.Theme.smallFont + text: full.local + ? i18n("%1 in the last 5h · %2 this week", + Format.humanTokens(full.local.session_tokens), + Format.humanTokens(full.local.week_tokens)) + : "" + } + PlasmaComponents.Label { + Layout.alignment: Qt.AlignHCenter + opacity: 0.7 + font: Kirigami.Theme.smallFont + visible: text !== "" + text: full.local + ? Format.sinceActivity(full.local.last_activity, full.now, i18n) + : "" + } } - return "" } - // Quel che resta di vero quando la percentuale manca: i transcript sul - // disco. Non e' una quota - i token si sanno, i limiti no - e va detto. ColumnLayout { - Layout.alignment: Qt.AlignHCenter - Layout.topMargin: Kirigami.Units.largeSpacing - visible: full.local !== null - spacing: 2 + id: sections + Layout.fillWidth: true + Layout.margins: Kirigami.Units.gridUnit + spacing: Math.round(Kirigami.Units.gridUnit * 0.75) + visible: full.hasData - PlasmaComponents.Label { - Layout.alignment: Qt.AlignHCenter - opacity: 0.7 - font: Kirigami.Theme.smallFont - text: i18n("From local transcripts (tokens, not quota):") - } - PlasmaComponents.Label { - Layout.alignment: Qt.AlignHCenter - font: Kirigami.Theme.smallFont - text: full.local - ? i18n("%1 in the last 5h · %2 this week", - Format.humanTokens(full.local.session_tokens), - Format.humanTokens(full.local.week_tokens)) - : "" + // La sezione: quale fonte sono queste percentuali. Il piano le + // qualifica, quindi la pastiglia sta qui e non nella testata. + RowLayout { + Layout.fillWidth: true + spacing: Kirigami.Units.smallSpacing + + PlasmaExtras.Heading { + Layout.fillWidth: true + level: 4 + elide: Text.ElideRight + text: i18n("Claude usage") + } + + Rectangle { + visible: full.account && full.account.plan + Layout.alignment: Qt.AlignVCenter + implicitWidth: planLabel.implicitWidth + Kirigami.Units.gridUnit + implicitHeight: planLabel.implicitHeight + Kirigami.Units.smallSpacing + radius: height / 2 + // Pastiglia piena con testo in contrasto. Prima era + // highlightColor su highlightColor trasparente: lo stesso + // colore su se' stesso, quindi illeggibile. + color: Kirigami.Theme.highlightColor + + PlasmaComponents.Label { + id: planLabel + anchors.centerIn: parent + // Nome di prodotto, non testo tradotto. + text: full.account ? full.account.plan : "" + color: Kirigami.Theme.highlightedTextColor + font.pointSize: Kirigami.Theme.smallFont.pointSize + font.weight: Font.Bold + } + } } + + // A quale account si riferiscono le percentuali qui sotto. PlasmaComponents.Label { - Layout.alignment: Qt.AlignHCenter - opacity: 0.7 - font: Kirigami.Theme.smallFont + Layout.fillWidth: true + // Annulla quasi tutto lo spazio di sezione: titolo e account + // sono un blocco solo, non due voci separate. + Layout.topMargin: -sections.spacing + 2 visible: text !== "" - text: full.local - ? Format.sinceActivity(full.local.last_activity, full.now, i18n) - : "" + elide: Text.ElideRight + opacity: 0.6 + font: Kirigami.Theme.smallFont + text: full.account ? (full.account.email || full.account.name || "") : "" } - } - } - ColumnLayout { - id: sections - anchors.fill: parent - // Senza margini i testi toccano il bordo del popup. - anchors.margins: Kirigami.Units.gridUnit - spacing: Math.round(Kirigami.Units.gridUnit * 0.75) - visible: full.hasData + // La riga sotto il titolo e' quel che lo rende una sezione invece di + // un testo qualsiasi: separa l'etichetta dai contatori che governa. + Kirigami.Separator { + Layout.fillWidth: true + Layout.topMargin: -Kirigami.Units.smallSpacing + Layout.bottomMargin: Kirigami.Units.smallSpacing + } - // La sezione: quale fonte sono queste percentuali. Il piano le - // qualifica, quindi la pastiglia sta qui e non nella testata. - RowLayout { - Layout.fillWidth: true - spacing: Kirigami.Units.smallSpacing + // Le righe hanno bisogno di piu' aria fra loro che al loro interno, + // o le tre barre sottili si leggono come un blocco solo. + Repeater { + model: full.windows + delegate: QuotaRow { + required property int index + required property var modelData + window: modelData + now: full.now + } + } + // Seconda sezione, stessa forma della prima: titolo, riga, contenuto. PlasmaExtras.Heading { Layout.fillWidth: true + visible: full.local !== null level: 4 elide: Text.ElideRight - text: i18n("Claude usage") + text: i18n("Tokens used") } - Rectangle { - visible: full.account && full.account.plan - Layout.alignment: Qt.AlignVCenter - implicitWidth: planLabel.implicitWidth + Kirigami.Units.gridUnit - implicitHeight: planLabel.implicitHeight + Kirigami.Units.smallSpacing - radius: height / 2 - // Pastiglia piena con testo in contrasto. Prima era - // highlightColor su highlightColor trasparente: lo stesso - // colore su se' stesso, quindi illeggibile. - color: Kirigami.Theme.highlightColor - - PlasmaComponents.Label { - id: planLabel - anchors.centerIn: parent - // Nome di prodotto, non testo tradotto. - text: full.account ? full.account.plan : "" - color: Kirigami.Theme.highlightedTextColor - font.pointSize: Kirigami.Theme.smallFont.pointSize - font.weight: Font.Bold - } - } - } - - // A quale account si riferiscono le percentuali qui sotto. - PlasmaComponents.Label { - Layout.fillWidth: true - // Annulla quasi tutto lo spazio di sezione: titolo e account - // sono un blocco solo, non due voci separate. - Layout.topMargin: -sections.spacing + 2 - visible: text !== "" - elide: Text.ElideRight - opacity: 0.6 - font: Kirigami.Theme.smallFont - text: full.account ? (full.account.email || full.account.name || "") : "" - } - - // La riga sotto il titolo e' quel che lo rende una sezione invece di - // un testo qualsiasi: separa l'etichetta dai contatori che governa. - Kirigami.Separator { - Layout.fillWidth: true - Layout.topMargin: -Kirigami.Units.smallSpacing - Layout.bottomMargin: Kirigami.Units.smallSpacing - } - - // Le righe hanno bisogno di piu' aria fra loro che al loro interno, - // o le tre barre sottili si leggono come un blocco solo. - Repeater { - model: full.windows - delegate: QuotaRow { - required property int index - required property var modelData - window: modelData - now: full.now + Kirigami.Separator { + Layout.fillWidth: true + Layout.topMargin: -sections.spacing + Kirigami.Units.smallSpacing + Layout.bottomMargin: Kirigami.Units.smallSpacing + visible: full.local !== null } - } - - // Seconda sezione, stessa forma della prima: titolo, riga, contenuto. - PlasmaExtras.Heading { - Layout.fillWidth: true - visible: full.local !== null - level: 4 - elide: Text.ElideRight - text: i18n("Tokens used") - } - Kirigami.Separator { - Layout.fillWidth: true - Layout.topMargin: -sections.spacing + Kirigami.Units.smallSpacing - Layout.bottomMargin: Kirigami.Units.smallSpacing - visible: full.local !== null - } - - // Il recap su una riga sua: sono i numeri che si guardano per primi - // qui dentro, quindi hanno il peso del testo normale e non quello - // delle note. Restano tre totali, non una serie storica. - RowLayout { - Layout.fillWidth: true - visible: full.local !== null - spacing: Kirigami.Units.gridUnit + // Il recap su una riga sua: sono i numeri che si guardano per primi + // qui dentro, quindi hanno il peso del testo normale e non quello + // delle note. Restano tre totali, non una serie storica. + RowLayout { + Layout.fillWidth: true + visible: full.local !== null + spacing: Kirigami.Units.gridUnit - Repeater { - model: full.local ? [ - { value: full.local.today_tokens, label: i18n("today") }, - { value: full.local.week_tokens, label: i18n("this week") }, - { value: full.local.month_tokens, label: i18n("this month") } - ] : [] + Repeater { + model: full.local ? [ + { value: full.local.today_tokens, label: i18n("today") }, + { value: full.local.week_tokens, label: i18n("this week") }, + { value: full.local.month_tokens, label: i18n("this month") } + ] : [] - delegate: RowLayout { - required property var modelData - spacing: Kirigami.Units.smallSpacing + delegate: RowLayout { + required property var modelData + spacing: Kirigami.Units.smallSpacing - PlasmaComponents.Label { - text: Format.humanTokens(modelData.value) - font.weight: Font.Bold - } - PlasmaComponents.Label { - text: modelData.label - opacity: 0.6 - font: Kirigami.Theme.smallFont + PlasmaComponents.Label { + text: Format.humanTokens(modelData.value) + font.weight: Font.Bold + } + PlasmaComponents.Label { + text: modelData.label + opacity: 0.6 + font: Kirigami.Theme.smallFont + } } } - } - Item { Layout.fillWidth: true } - } + Item { Layout.fillWidth: true } + } - // Il grafico sopra la legenda: la legenda spiega i colori che il - // grafico usa, quindi viene dopo. - DailyChart { - Layout.fillWidth: true - days: full.local && full.local.daily ? full.local.daily : [] - modelOrder: { - var out = [] - var models = full.local && full.local.models ? full.local.models : [] - for (var i = 0; i < models.length; i++) { - out.push(models[i].id) + // Il grafico sopra la legenda: la legenda spiega i colori che il + // grafico usa, quindi viene dopo. + DailyChart { + Layout.fillWidth: true + days: full.local && full.local.daily ? full.local.daily : [] + modelOrder: { + var out = [] + var models = full.local && full.local.models ? full.local.models : [] + for (var i = 0; i < models.length; i++) { + out.push(models[i].id) + } + return out } - return out } - } - ModelBreakdown { - Layout.fillWidth: true - models: full.local ? full.local.models : [] - } - - // La freschezza del dato e' parte del dato: un numero vecchio senza - // dirlo e' peggio di nessun numero. - PlasmaComponents.Label { - Layout.fillWidth: true - visible: full.quota && full.quota.quota.status !== "fresh" - wrapMode: Text.Wrap - color: Kirigami.Theme.neutralTextColor - font: Kirigami.Theme.smallFont - text: i18n("Quota data may be out of date.") - } + ModelBreakdown { + Layout.fillWidth: true + models: full.local ? full.local.models : [] + } - Item { Layout.fillHeight: true } + // La freschezza del dato e' parte del dato: un numero vecchio senza + // dirlo e' peggio di nessun numero. + PlasmaComponents.Label { + Layout.fillWidth: true + visible: full.quota && full.quota.quota.status !== "fresh" + wrapMode: Text.Wrap + color: Kirigami.Theme.neutralTextColor + font: Kirigami.Theme.smallFont + text: i18n("Quota data may be out of date.") + } - // Con i crediti attivi il 100% non blocca piu': mostrarlo come un muro - // sarebbe una bugia. - PlasmaComponents.Label { - Layout.fillWidth: true - visible: full.quota && full.quota.extra_usage_enabled - wrapMode: Text.Wrap - opacity: 0.7 - font: Kirigami.Theme.smallFont - text: i18n("Extra usage credits are enabled: reaching 100% will not block you.") + // Con i crediti attivi il 100% non blocca piu': mostrarlo come un muro + // sarebbe una bugia. + PlasmaComponents.Label { + Layout.fillWidth: true + visible: full.quota && full.quota.extra_usage_enabled + wrapMode: Text.Wrap + opacity: 0.7 + font: Kirigami.Theme.smallFont + text: i18n("Extra usage credits are enabled: reaching 100% will not block you.") + } } } - } } -- knotmirror 0.0.1