1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-07 19:59:14 -04:00

feat(DiskUsage): updated dynamic width options for DiskUsage widget (#2517)

* feat(WidgetsTabSection.qml): added dynamic width and static padding for DiskUsage

* feat(DiskUsage.qml):added functionality for dynamic width and static padding, also changed spacing to work like in cpu and ram monitor. Now they look complete and same

* fix(DiskUsage): restore display modes & formatting

---------

Co-authored-by: purian23 <purian23@gmail.com>
This commit is contained in:
Bogdan
2026-05-30 08:02:15 +03:00
committed by GitHub
parent f2d5ee4692
commit f2961f9b6a
3 changed files with 59 additions and 31 deletions
@@ -12,6 +12,7 @@ BasePill {
property int diskUsageMode: (widgetData && widgetData.diskUsageMode !== undefined) ? widgetData.diskUsageMode : 0 property int diskUsageMode: (widgetData && widgetData.diskUsageMode !== undefined) ? widgetData.diskUsageMode : 0
property bool isHovered: mouseArea.containsMouse property bool isHovered: mouseArea.containsMouse
property bool isAutoHideBar: false property bool isAutoHideBar: false
property bool minimumWidth: (widgetData && widgetData.minimumWidth !== undefined) ? widgetData.minimumWidth : true
property var selectedMount: { property var selectedMount: {
if (!DgopService.diskMounts || DgopService.diskMounts.length === 0) { if (!DgopService.diskMounts || DgopService.diskMounts.length === 0) {
@@ -69,6 +70,8 @@ BasePill {
} }
Connections { Connections {
target: SettingsData
function onWidgetDataChanged() { function onWidgetDataChanged() {
root.mountPath = Qt.binding(() => { root.mountPath = Qt.binding(() => {
return (root.widgetData && root.widgetData.mountPath !== undefined) ? root.widgetData.mountPath : "/"; return (root.widgetData && root.widgetData.mountPath !== undefined) ? root.widgetData.mountPath : "/";
@@ -96,14 +99,12 @@ BasePill {
return DgopService.diskMounts[0] || null; return DgopService.diskMounts[0] || null;
}); });
} }
target: SettingsData
} }
content: Component { content: Component {
Item { Item {
implicitWidth: root.isVerticalOrientation ? (root.widgetThickness - root.horizontalPadding * 2) : diskContent.implicitWidth implicitWidth: root.isVerticalOrientation ? (root.widgetThickness - root.horizontalPadding * 2) : diskContent.implicitWidth
implicitHeight: root.isVerticalOrientation ? diskColumn.implicitHeight : (root.widgetThickness - root.horizontalPadding * 2) implicitHeight: root.isVerticalOrientation ? diskColumn.implicitHeight : diskContent.implicitHeight
Column { Column {
id: diskColumn id: diskColumn
@@ -118,10 +119,12 @@ BasePill {
if (root.diskUsagePercent > 90) { if (root.diskUsagePercent > 90) {
return Theme.tempDanger; return Theme.tempDanger;
} }
if (root.diskUsagePercent > 75) { if (root.diskUsagePercent > 75) {
return Theme.tempWarning; return Theme.tempWarning;
} }
return Theme.surfaceText;
return Theme.widgetIconColor;
} }
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
@@ -154,24 +157,28 @@ BasePill {
id: diskContent id: diskContent
visible: !root.isVerticalOrientation visible: !root.isVerticalOrientation
anchors.centerIn: parent anchors.centerIn: parent
spacing: 3 spacing: Theme.spacingXS
DankIcon { DankIcon {
id: diskIcon
name: "storage" name: "storage"
size: Theme.barIconSize(root.barThickness, undefined, root.barConfig?.maximizeWidgetIcons, root.barConfig?.iconScale) size: Theme.barIconSize(root.barThickness, undefined, root.barConfig?.maximizeWidgetIcons, root.barConfig?.iconScale)
color: { color: {
if (root.diskUsagePercent > 90) { if (root.diskUsagePercent > 90) {
return Theme.tempDanger; return Theme.tempDanger;
} }
if (root.diskUsagePercent > 75) { if (root.diskUsagePercent > 75) {
return Theme.tempWarning; return Theme.tempWarning;
} }
return Theme.surfaceText;
return Theme.widgetIconColor;
} }
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
StyledText { StyledText {
id: mountText
text: { text: {
if (!root.selectedMount) { if (!root.selectedMount) {
return "--"; return "--";
@@ -182,32 +189,20 @@ BasePill {
color: Theme.widgetTextColor color: Theme.widgetTextColor
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignLeft horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideNone elide: Text.ElideNone
wrapMode: Text.NoWrap
} }
StyledText { Item {
text: { id: textBox
if (root.diskUsagePercent === undefined || root.diskUsagePercent === null || root.diskUsagePercent === 0) {
return "--%";
}
if (!root.selectedMount)
return "--%";
switch (root.diskUsageMode) {
case 1:
return root.selectedMount.size || "--";
case 2:
return root.selectedMount.avail || "--";
case 3:
return (root.selectedMount.avail || "--") + " / " + (root.selectedMount.size || "--");
default:
return root.diskUsagePercent.toFixed(0) + "%";
}
}
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
color: Theme.widgetTextColor
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignLeft
elide: Text.ElideNone implicitWidth: root.minimumWidth ? Math.max(diskBaseline.width, diskCurrent.width) : diskCurrent.width
implicitHeight: diskText.implicitHeight
width: implicitWidth
height: implicitHeight
StyledTextMetrics { StyledTextMetrics {
id: diskBaseline id: diskBaseline
@@ -225,7 +220,40 @@ BasePill {
} }
} }
width: Math.max(diskBaseline.width, paintedWidth) StyledTextMetrics {
id: diskCurrent
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
text: diskText.text
}
StyledText {
id: diskText
text: {
if (root.diskUsagePercent === undefined || root.diskUsagePercent === null || root.diskUsagePercent === 0) {
return "--%";
}
if (!root.selectedMount)
return "--%";
switch (root.diskUsageMode) {
case 1:
return root.selectedMount.size || "--";
case 2:
return root.selectedMount.avail || "--";
case 3:
return (root.selectedMount.avail || "--") + " / " + (root.selectedMount.size || "--");
default:
return root.diskUsagePercent.toFixed(0) + "%";
}
}
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale, root.barConfig?.maximizeWidgetText)
color: Theme.widgetTextColor
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideNone
wrapMode: Text.NoWrap
}
} }
} }
} }
+1 -1
View File
@@ -404,7 +404,7 @@ Item {
widgetObj.mountPath = "/"; widgetObj.mountPath = "/";
widgetObj.diskUsageMode = 0; widgetObj.diskUsageMode = 0;
} }
if (widgetId === "cpuUsage" || widgetId === "memUsage" || widgetId === "cpuTemp" || widgetId === "gpuTemp") if (widgetId === "cpuUsage" || widgetId === "memUsage" || widgetId === "cpuTemp" || widgetId === "gpuTemp" || widgetId === "diskUsage")
widgetObj.minimumWidth = true; widgetObj.minimumWidth = true;
if (widgetId === "memUsage") if (widgetId === "memUsage")
widgetObj.showInGb = false; widgetObj.showInGb = false;
@@ -320,7 +320,7 @@ Column {
DankActionButton { DankActionButton {
id: minimumWidthButton id: minimumWidthButton
buttonSize: 28 buttonSize: 28
visible: modelData.id === "cpuUsage" || modelData.id === "memUsage" || modelData.id === "cpuTemp" || modelData.id === "gpuTemp" visible: modelData.id === "cpuUsage" || modelData.id === "memUsage" || modelData.id === "cpuTemp" || modelData.id === "gpuTemp" || modelData.id === "diskUsage"
iconName: "straighten" iconName: "straighten"
iconSize: 16 iconSize: 16
iconColor: (modelData.minimumWidth !== undefined ? modelData.minimumWidth : true) ? Theme.primary : Theme.outline iconColor: (modelData.minimumWidth !== undefined ? modelData.minimumWidth : true) ? Theme.primary : Theme.outline