Something went wrong. Try again.
A KDE Plasma panel widget showing how much Claude Max quota is left, at a glance.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129/* * What shows in the panel: the widget's mark, the percentage of the * constraint that will be hit first, and a five-dot level of the SAME figure. * * The level used to show the second window, and that was wrong: a number and * a bar side by side reporting different values read as incoherent, not as * two pieces of information. The second window lives in the tooltip and the * popup. * * Which one is "first" has already been decided by the daemon. Nothing is * chosen here: at panel height, this only draws. */pragma ComponentBehavior: Bound
import QtQuickimport QtQuick.Layoutsimport org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.components as PlasmaComponentsimport org.kde.plasma.plasmoidimport org.kde.kirigami as Kirigami
MouseArea { id: compact
readonly property var compactState: root.quotaState ? root.quotaState.compact : null readonly property bool hasData: compactState !== null && compactState !== undefined readonly property int primaryPercent: hasData ? compactState.primary.percent : 0 // A vertical panel is too narrow for the mark and the number side by // side: there the level goes under the number and the mark goes. readonly property bool vertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical
readonly property real u: look.u readonly property color tone: hasData ? look.severityColor(compactState.primary.severity, look.ink) : look.muted
Look { id: look }
Layout.minimumWidth: layout.implicitWidth + (vertical ? 0 : 2 * pill.padding) Layout.preferredWidth: Layout.minimumWidth Layout.minimumHeight: layout.implicitHeight
acceptedButtons: Qt.LeftButton hoverEnabled: true onClicked: root.expanded = !root.expanded
// Reachable and readable without a mouse: the same toggle from the // keyboard, and the tooltip's words for a screen reader. activeFocusOnTab: true Keys.onPressed: event => { if (event.key === Qt.Key_Space || event.key === Qt.Key_Enter || event.key === Qt.Key_Return || event.key === Qt.Key_Select) { root.expanded = !root.expanded event.accepted = true } } Accessible.role: Accessible.Button Accessible.name: root.toolTipMainText Accessible.description: root.toolTipSubText Accessible.onPressAction: root.expanded = !root.expanded
// The open popup's anchor: the widget stays marked while its detail is // on screen. Rectangle { id: pill readonly property real padding: Math.round(10 * compact.u) anchors.centerIn: parent width: compact.vertical ? parent.width : layout.implicitWidth + 2 * padding height: compact.vertical ? layout.implicitHeight + padding : Math.round(26 * compact.u) radius: Math.min(width, height) / 2 color: look.tile visible: root.expanded }
GridLayout { id: layout anchors.centerIn: parent flow: compact.vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight rowSpacing: Math.round(4 * compact.u) columnSpacing: Math.round(6 * compact.u)
Kirigami.Icon { Layout.alignment: Qt.AlignVCenter visible: !compact.vertical implicitWidth: Math.round(16 * compact.u) implicitHeight: implicitWidth // Drawn as a mask in the theme's colour, like the popup's: one // file for light panels and dark ones. source: Qt.resolvedUrl("../icons/dipstick.svg") isMask: true Accessible.ignored: true color: root.expanded || compact.containsMouse ? look.ink : look.muted }
PlasmaComponents.Label { Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter // A dash when there is no data, not a zero: a zero would be a // reassuring lie at exactly the moment we know nothing. text: compact.hasData ? i18nc("percentage of quota used", "%1%", compact.primaryPercent) : "—" color: compact.tone font.family: look.monoFamily font.pixelSize: Math.round(12 * compact.u) }
// Five dots: the number made readable out of the corner of an eye. // Same data, other shape. Row { Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter visible: compact.hasData spacing: Math.round(3 * compact.u) Accessible.ignored: true
Repeater { model: 5 delegate: Rectangle { required property int index width: Math.round(4 * compact.u) height: width radius: width / 2 color: index < Math.round(compact.primaryPercent / 20) ? compact.tone : look.grooveBare } } } }}