Warning, /plasma/plasma-workspace/lookandfeel/components/Battery.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Layouts 1.15
0009 
0010 import org.kde.plasma.components 3.0 as PlasmaComponents3
0011 import org.kde.plasma.workspace.components 2.0 as PW
0012 import org.kde.plasma.plasma5support 2.0 as P5Support
0013 import org.kde.kirigami 2.20 as Kirigami
0014 
0015 RowLayout {
0016     id: root
0017 
0018     property int fontSize: Kirigami.Theme.defaultFont.pointSize
0019 
0020     function getOrDefault(source /*object?*/, prop /*string*/, fallback /*T*/) /*-> T*/ {
0021         return (source !== null && source !== undefined && source.hasOwnProperty(prop))
0022             ? source[prop] : fallback;
0023     }
0024 
0025     readonly property var acAdapter: pmSource.data["AC Adapter"]
0026     readonly property var battery: pmSource.data["Battery"]
0027 
0028     readonly property bool pluggedIn: getOrDefault(acAdapter, "Plugged in", false)
0029     readonly property bool hasBattery: getOrDefault(battery, "Has Battery", false)
0030     readonly property int percent: getOrDefault(battery, "Percent", 0)
0031 
0032     spacing: Kirigami.Units.smallSpacing
0033     visible: getOrDefault(battery, "Has Cumulative", false)
0034 
0035     P5Support.DataSource {
0036         id: pmSource
0037         engine: "powermanagement"
0038         connectedSources: ["Battery", "AC Adapter"]
0039     }
0040 
0041     PW.BatteryIcon {
0042         pluggedIn: root.pluggedIn
0043         hasBattery: root.hasBattery
0044         percent: root.percent
0045 
0046         Layout.preferredHeight: Math.max(Kirigami.Units.iconSizes.medium, batteryLabel.implicitHeight)
0047         Layout.preferredWidth: Layout.preferredHeight
0048         Layout.alignment: Qt.AlignVCenter
0049     }
0050 
0051     PlasmaComponents3.Label {
0052         id: batteryLabel
0053         font.pointSize: root.fontSize
0054         text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "%1%", root.percent)
0055         textFormat: Text.PlainText
0056         Accessible.name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Battery at %1%", root.percent)
0057         Layout.alignment: Qt.AlignVCenter
0058     }
0059 }