shift-shell/components/mobileshell/qml/statusbar/indicators/BatteryIndicator.qml
Micah Stanley db98f2cd86 statusbar: fix hidden batteries from taking up space in the statusbar
I noticed at some point after updating my main phone, that non visible external device batteries started taking up extra space in the statusbar. This fixes the issue by filtering out external device batteries by using KSortFilterProxyModel.

Before (with external peripheral connected)

![Screenshot_20260303_124043](/uploads/a469eda41ff6d2a10b85c6a3de88785f/Screenshot_20260303_124043.png){width=399 height=28}

After

![Screenshot_20260303_123956](/uploads/521a7dc7bb16cf08ef026c3ef0655b93/Screenshot_20260303_123956.png){width=399 height=28}
2026-03-05 20:13:34 -05:00

78 lines
2.2 KiB
QML

/*
* SPDX-FileCopyrightText: 2024 Sebastian Kügler <sebas@kde.org>
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.6
import QtQuick.Layouts 1.4
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kitemmodels
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.workspace.components 2.0 as PW
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.battery // needed for charging state
RowLayout {
property real textPixelSize: Kirigami.Units.gridUnit * 0.6
visible: MobileShell.BatteryInfo.isVisible
ListView {
id: batteryRepeater
spacing: 0
model: filterModel
orientation: ListView.Horizontal
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: contentItem.childrenRect.width
Layout.fillHeight: true
Layout.fillWidth: false
KSortFilterProxyModel {
id: filterModel
sourceModel: MobileShell.BatteryInfo.batteries
filterRoleName: "Type"
filterString: "Battery" // only show internal batteries
}
delegate: RowLayout {
id: batteryBase
Layout.fillHeight: false
Layout.alignment: Qt.AlignVCenter
height: batteryRepeater.height
PW.BatteryIcon {
id: battery
Layout.alignment: Qt.AlignVCenter
Layout.fillHeight: true
width: batteryLabel.height
hasBattery: PluggedIn
percent: Percent
pluggedIn: ChargeState === BatteryControlModel.Charging
}
PlasmaComponents.Label {
id: batteryLabel
text: i18n("%1%", Percent)
Layout.alignment: Qt.AlignVCenter
Layout.fillHeight: true
color: Kirigami.Theme.textColor
visible: ShellSettings.Settings.showBatteryPercentage
font.pixelSize: textPixelSize
}
}
}
}