import QtQuick import qs.Common import qs.Modules.Plugins import qs.Services import qs.Widgets BasePill { id: battery property bool batteryPopupVisible: false property var popoutTarget: null readonly property int barPosition: { switch (axis?.edge) { case "top": return 0; case "bottom": return 1; case "left": return 2; case "right": return 3; default: return 0; } } signal toggleBatteryPopup visible: true content: Component { Item { implicitWidth: battery.isVerticalOrientation ? (battery.widgetThickness - battery.horizontalPadding * 2) : batteryContent.implicitWidth implicitHeight: battery.isVerticalOrientation ? batteryColumn.implicitHeight : (battery.widgetThickness - battery.horizontalPadding * 2) Column { id: batteryColumn visible: battery.isVerticalOrientation anchors.centerIn: parent spacing: 1 DankIcon { name: BatteryService.getBatteryIcon() size: Theme.barIconSize(battery.barThickness) color: { if (!BatteryService.batteryAvailable) { return Theme.widgetIconColor; } if (BatteryService.isLowBattery && !BatteryService.isCharging) { return Theme.error; } if (BatteryService.isCharging || BatteryService.isPluggedIn) { return Theme.primary; } return Theme.widgetIconColor; } anchors.horizontalCenter: parent.horizontalCenter } StyledText { text: BatteryService.batteryLevel.toString() font.pixelSize: Theme.barTextSize(battery.barThickness, battery.barConfig?.fontScale) color: Theme.widgetTextColor anchors.horizontalCenter: parent.horizontalCenter visible: BatteryService.batteryAvailable } } Row { id: batteryContent visible: !battery.isVerticalOrientation anchors.centerIn: parent spacing: (barConfig?.noBackground ?? false) ? 1 : 2 DankIcon { name: BatteryService.getBatteryIcon() size: Theme.barIconSize(battery.barThickness, -4) color: { if (!BatteryService.batteryAvailable) { return Theme.widgetIconColor; } if (BatteryService.isLowBattery && !BatteryService.isCharging) { return Theme.error; } if (BatteryService.isCharging || BatteryService.isPluggedIn) { return Theme.primary; } return Theme.widgetIconColor; } anchors.verticalCenter: parent.verticalCenter } StyledText { text: `${BatteryService.batteryLevel}%` font.pixelSize: Theme.barTextSize(battery.barThickness, battery.barConfig?.fontScale) color: Theme.widgetTextColor anchors.verticalCenter: parent.verticalCenter visible: BatteryService.batteryAvailable } } } } MouseArea { x: -battery.leftMargin y: -battery.topMargin width: battery.width + battery.leftMargin + battery.rightMargin height: battery.height + battery.topMargin + battery.bottomMargin cursorShape: Qt.PointingHandCursor acceptedButtons: Qt.LeftButton onPressed: { toggleBatteryPopup(); } } }