From 55a29d850469e8aec3caf8c30de703e58b981faf Mon Sep 17 00:00:00 2001 From: bbedward Date: Sat, 20 Sep 2025 20:44:50 -0400 Subject: [PATCH] minimum width for system monitoring topbar widgets --- Modules/TopBar/CpuMonitor.qml | 18 ++++++++++++++++ Modules/TopBar/CpuTemperature.qml | 18 ++++++++++++++++ Modules/TopBar/GpuTemperature.qml | 18 ++++++++++++++++ Modules/TopBar/NetworkMonitor.qml | 36 +++++++++++++++++++++++++++++++ Modules/TopBar/RamMonitor.qml | 18 ++++++++++++++++ Widgets/StyledTextMetrics.qml | 24 +++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 Widgets/StyledTextMetrics.qml diff --git a/Modules/TopBar/CpuMonitor.qml b/Modules/TopBar/CpuMonitor.qml index e8543333..96d8d2c4 100644 --- a/Modules/TopBar/CpuMonitor.qml +++ b/Modules/TopBar/CpuMonitor.qml @@ -92,6 +92,24 @@ Rectangle { font.weight: Font.Medium color: Theme.surfaceText anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideNone + + StyledTextMetrics { + id: cpuBaseline + font.pixelSize: Theme.fontSizeSmall + font.weight: Font.Medium + text: "100%" + } + + width: Math.max(cpuBaseline.width, paintedWidth) + + Behavior on width { + NumberAnimation { + duration: 120 + easing.type: Easing.OutCubic + } + } } } diff --git a/Modules/TopBar/CpuTemperature.qml b/Modules/TopBar/CpuTemperature.qml index 19a0beb8..95ba0e01 100644 --- a/Modules/TopBar/CpuTemperature.qml +++ b/Modules/TopBar/CpuTemperature.qml @@ -92,6 +92,24 @@ Rectangle { font.weight: Font.Medium color: Theme.surfaceText anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideNone + + StyledTextMetrics { + id: tempBaseline + font.pixelSize: Theme.fontSizeSmall + font.weight: Font.Medium + text: "100°" + } + + width: Math.max(tempBaseline.width, paintedWidth) + + Behavior on width { + NumberAnimation { + duration: 120 + easing.type: Easing.OutCubic + } + } } } diff --git a/Modules/TopBar/GpuTemperature.qml b/Modules/TopBar/GpuTemperature.qml index 0c00322a..52e65c32 100644 --- a/Modules/TopBar/GpuTemperature.qml +++ b/Modules/TopBar/GpuTemperature.qml @@ -166,6 +166,24 @@ Rectangle { font.weight: Font.Medium color: Theme.surfaceText anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideNone + + StyledTextMetrics { + id: gpuTempBaseline + font.pixelSize: Theme.fontSizeSmall + font.weight: Font.Medium + text: "100°" + } + + width: Math.max(gpuTempBaseline.width, paintedWidth) + + Behavior on width { + NumberAnimation { + duration: 120 + easing.type: Easing.OutCubic + } + } } } diff --git a/Modules/TopBar/NetworkMonitor.qml b/Modules/TopBar/NetworkMonitor.qml index a10b9bec..5ae4993e 100644 --- a/Modules/TopBar/NetworkMonitor.qml +++ b/Modules/TopBar/NetworkMonitor.qml @@ -80,6 +80,24 @@ Rectangle { font.weight: Font.Medium color: Theme.surfaceText anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideNone + + StyledTextMetrics { + id: rxBaseline + font.pixelSize: Theme.fontSizeSmall + font.weight: Font.Medium + text: "88.8 MB/s" + } + + width: Math.max(rxBaseline.width, paintedWidth) + + Behavior on width { + NumberAnimation { + duration: 120 + easing.type: Easing.OutCubic + } + } } } @@ -100,6 +118,24 @@ Rectangle { font.weight: Font.Medium color: Theme.surfaceText anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideNone + + StyledTextMetrics { + id: txBaseline + font.pixelSize: Theme.fontSizeSmall + font.weight: Font.Medium + text: "88.8 MB/s" + } + + width: Math.max(txBaseline.width, paintedWidth) + + Behavior on width { + NumberAnimation { + duration: 120 + easing.type: Easing.OutCubic + } + } } } diff --git a/Modules/TopBar/RamMonitor.qml b/Modules/TopBar/RamMonitor.qml index 89bf7ae5..0a20674a 100644 --- a/Modules/TopBar/RamMonitor.qml +++ b/Modules/TopBar/RamMonitor.qml @@ -92,6 +92,24 @@ Rectangle { font.weight: Font.Medium color: Theme.surfaceText anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideNone + + StyledTextMetrics { + id: ramBaseline + font.pixelSize: Theme.fontSizeSmall + font.weight: Font.Medium + text: "100%" + } + + width: Math.max(ramBaseline.width, paintedWidth) + + Behavior on width { + NumberAnimation { + duration: 120 + easing.type: Easing.OutCubic + } + } } } diff --git a/Widgets/StyledTextMetrics.qml b/Widgets/StyledTextMetrics.qml new file mode 100644 index 00000000..de1146b9 --- /dev/null +++ b/Widgets/StyledTextMetrics.qml @@ -0,0 +1,24 @@ +import QtQuick +import qs.Common +import qs.Services + +TextMetrics { + property bool isMonospace: false + + readonly property string resolvedFontFamily: { + const requestedFont = isMonospace ? SettingsData.monoFontFamily : SettingsData.fontFamily + const defaultFont = isMonospace ? SettingsData.defaultMonoFontFamily : SettingsData.defaultFontFamily + + if (requestedFont === defaultFont) { + const availableFonts = Qt.fontFamilies() + if (!availableFonts.includes(requestedFont)) { + return isMonospace ? "Monospace" : "DejaVu Sans" + } + } + return requestedFont + } + + font.pixelSize: Appearance.fontSize.normal + font.family: resolvedFontFamily + font.weight: SettingsData.fontWeight +} \ No newline at end of file