powermanagement-kcm: Port to FormCard

This commit is contained in:
Carl Schwan 2023-09-21 19:37:12 +02:00
parent dc047a0eb9
commit 8030c73c67
No known key found for this signature in database
GPG key ID: 02325448204E452A

View file

@ -1,20 +1,18 @@
/* // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org> // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.0-or-later
SPDX-License-Identifier: LGPL-2.0-or-later import QtQuick
*/ import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQuick 2.2 import org.kde.kirigami as Kirigami
import QtQuick.Controls 2.10 as QQC2 import org.kde.plasma.components 3 as PlasmaComponents
import QtQuick.Layouts 1.11
import org.kde.kirigami 2.10 as Kirigami
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.kcmutils import org.kde.kcmutils
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm import org.kde.kirigamiaddons.formcard 1 as FormCard
import org.kde.kcm.power.mobile.private 1.0 import org.kde.kcm.power.mobile.private
Kirigami.ScrollablePage { FormCard.FormCardPage {
id: root id: root
property QtObject battery property QtObject battery
@ -24,159 +22,138 @@ Kirigami.ScrollablePage {
title: i18n("Battery Information") title: i18n("Battery Information")
leftPadding: 0 data: HistoryModel {
rightPadding: 0
topPadding: Kirigami.Units.gridUnit
bottomPadding: Kirigami.Units.gridUnit
HistoryModel {
id: history id: history
duration: 86400 // last 24 hours duration: 86400 // last 24 hours
device: currentUdi device: currentUdi
type: HistoryModel.ChargeType type: HistoryModel.ChargeType
} }
ColumnLayout { FormCard.FormHeader {
width: parent.width title: i18n("Usage Graph")
spacing: 0 visible: history.count > 1
}
MobileForm.FormCard { FormCard.FormCard {
Layout.fillWidth: true visible: history.count > 1
visible: history.count > 1
contentItem: ColumnLayout { FormCard.AbstractFormDelegate {
spacing: 0 background: null
clip: true
MobileForm.FormCardHeader { contentItem: Flickable {
title: i18n("Usage Graph") implicitWidth: 500
implicitHeight: 200
contentWidth: 500
contentHeight: 200
Graph {
id: graph
width: 500
height: 200
implicitWidth: 500
implicitHeight: 200
data: history.points
// Set grid lines distances which directly correspondent to the xTicksAt variables
readonly property var xDivisionWidths: [1000 * 60 * 10, 1000 * 60 * 60 * 12, 1000 * 60 * 60, 1000 * 60 * 30, 1000 * 60 * 60 * 2, 1000 * 60 * 10]
xTicksAt: graph.xTicksAtFullSecondHour
xDivisionWidth: xDivisionWidths[xTicksAt]
xMin: history.firstDataPointTime
xMax: history.lastDataPointTime
xDuration: history.duration
yMax: 100
yStep: 20
visible: history.count > 1
} }
}
}
}
MobileForm.AbstractFormDelegate { FormCard.FormHeader {
Layout.fillWidth: true title: i18n("Information")
background: Item {} }
clip: true
contentItem: Flickable { FormCard.FormCard {
implicitWidth: 500 FormCard.FormTextDelegate {
implicitHeight: 200 id: isRechargeableDelegate
contentWidth: 500 text: i18n("Is Rechargeable")
contentHeight: 200 description: battery.rechargeable ? i18n("Yes") : i18n("No")
}
Graph { FormCard.FormDelegateSeparator {}
id: graph
width: 500
height: 200
implicitWidth: 500
implicitHeight: 200
data: history.points
// Set grid lines distances which directly correspondent to the xTicksAt variables FormCard.FormTextDelegate {
readonly property var xDivisionWidths: [1000 * 60 * 10, 1000 * 60 * 60 * 12, 1000 * 60 * 60, 1000 * 60 * 30, 1000 * 60 * 60 * 2, 1000 * 60 * 10] id: chargeStateDelegate
xTicksAt: graph.xTicksAtFullSecondHour text: i18n("Charge State")
xDivisionWidth: xDivisionWidths[xTicksAt] description: {
switch (battery.chargeState) {
xMin: history.firstDataPointTime case Battery.NoCharge: return i18n("Not charging")
xMax: history.lastDataPointTime case Battery.Charging: return i18n("Charging")
xDuration: history.duration case Battery.Discharging: return i18n("Discharging")
case Battery.FullyCharged: return i18n("Fully charged")
yMax: 100 default: return i18n("Unknown")
yStep: 20
visible: history.count > 1
}
}
} }
} }
} }
MobileForm.FormCard { FormCard.FormDelegateSeparator {}
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.gridUnit
contentItem: ColumnLayout { FormCard.FormTextDelegate {
spacing: 0 id: currentChargeDelegate
text: i18n("Current Charge")
description: i18nc("%1 is percentage value", "%1 %", Number(battery.chargePercent).toLocaleString(Qt.locale(), "f", 0))
}
MobileForm.FormCardHeader { FormCard.FormDelegateSeparator {}
title: i18n("Information")
}
MobileForm.FormTextDelegate { FormCard.FormTextDelegate {
id: isRechargeableDelegate id: healthDelegate
text: i18n("Is Rechargeable") text: i18n("Health")
description: battery.rechargeable ? i18n("Yes") : i18n("No") description: i18nc("%1 is percentage value", "%1 %", Number(battery.capacity).toLocaleString(Qt.locale(), "f", 0))
} }
MobileForm.FormDelegateSeparator {} FormCard.FormDelegateSeparator {}
MobileForm.FormTextDelegate { FormCard.FormTextDelegate {
id: chargeStateDelegate id: vendorDelegate
text: i18n("Charge State") text: i18n("Vendor")
description: { description: root.vendor
switch (battery.chargeState) { }
case Battery.NoCharge: return i18n("Not charging")
case Battery.Charging: return i18n("Charging")
case Battery.Discharging: return i18n("Discharging")
case Battery.FullyCharged: return i18n("Fully charged")
default: return i18n("Unknown")
}
}
}
MobileForm.FormDelegateSeparator {} FormCard.FormDelegateSeparator {}
MobileForm.FormTextDelegate { FormCard.FormTextDelegate {
id: currentChargeDelegate id: modelDelegate
text: i18n("Current Charge") text: i18n("Model")
description: i18nc("%1 is percentage value", "%1 %", Number(battery.chargePercent).toLocaleString(Qt.locale(), "f", 0)) description: root.product
} }
MobileForm.FormDelegateSeparator {} FormCard.FormDelegateSeparator {}
MobileForm.FormTextDelegate { FormCard.FormTextDelegate {
id: healthDelegate id: serialDelegate
text: i18n("Health") text: i18n("Serial Number")
description: i18nc("%1 is percentage value", "%1 %", Number(battery.capacity).toLocaleString(Qt.locale(), "f", 0)) description: battery.serial
} }
MobileForm.FormDelegateSeparator {} FormCard.FormDelegateSeparator {}
MobileForm.FormTextDelegate { FormCard.FormTextDelegate {
id: vendorDelegate id: technologyDelegate
text: i18n("Vendor") text: i18n("Technology")
description: root.vendor description: {
} switch (battery.technology) {
case Battery.LithiumIon: return i18n("Lithium ion")
MobileForm.FormDelegateSeparator {} case Battery.LithiumPolymer: return i18n("Lithium polymer")
case Battery.LithiumIronPhosphate: return i18n("Lithium iron phosphate")
MobileForm.FormTextDelegate { case Battery.LeadAcid: return i18n("Lead acid")
id: modelDelegate case Battery.NickelCadmium: return i18n("Nickel cadmium")
text: i18n("Model") case Battery.NickelMetalHydride: return i18n("Nickel metal hydride")
description: root.product default: return i18n("Unknown technology")
}
MobileForm.FormDelegateSeparator {}
MobileForm.FormTextDelegate {
id: serialDelegate
text: i18n("Serial Number")
description: battery.serial
}
MobileForm.FormDelegateSeparator {}
MobileForm.FormTextDelegate {
id: technologyDelegate
text: i18n("Technology")
description: {
switch (battery.technology) {
case Battery.LithiumIon: return i18n("Lithium ion")
case Battery.LithiumPolymer: return i18n("Lithium polymer")
case Battery.LithiumIronPhosphate: return i18n("Lithium iron phosphate")
case Battery.LeadAcid: return i18n("Lead acid")
case Battery.NickelCadmium: return i18n("Nickel cadmium")
case Battery.NickelMetalHydride: return i18n("Nickel metal hydride")
default: return i18n("Unknown technology")
}
}
} }
} }
} }