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,182 +1,159 @@
/* // 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
property string vendor property string vendor
property string product property string product
property string currentUdi property string currentUdi
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 {
Layout.fillWidth: true
visible: history.count > 1
contentItem: ColumnLayout {
spacing: 0
MobileForm.FormCardHeader {
title: i18n("Usage Graph")
}
MobileForm.AbstractFormDelegate {
Layout.fillWidth: true
background: Item {}
clip: true
contentItem: Flickable {
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 FormCard.FormCard {
readonly property var xDivisionWidths: [1000 * 60 * 10, 1000 * 60 * 60 * 12, 1000 * 60 * 60, 1000 * 60 * 30, 1000 * 60 * 60 * 2, 1000 * 60 * 10] visible: history.count > 1
xTicksAt: graph.xTicksAtFullSecondHour
xDivisionWidth: xDivisionWidths[xTicksAt]
xMin: history.firstDataPointTime FormCard.AbstractFormDelegate {
xMax: history.lastDataPointTime background: null
xDuration: history.duration clip: true
yMax: 100 contentItem: Flickable {
yStep: 20 implicitWidth: 500
visible: history.count > 1 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.FormCard {
Layout.fillWidth: true FormCard.FormHeader {
Layout.topMargin: Kirigami.Units.gridUnit title: i18n("Information")
}
contentItem: ColumnLayout {
spacing: 0 FormCard.FormCard {
FormCard.FormTextDelegate {
MobileForm.FormCardHeader { id: isRechargeableDelegate
title: i18n("Information") text: i18n("Is Rechargeable")
description: battery.rechargeable ? i18n("Yes") : i18n("No")
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextDelegate {
id: chargeStateDelegate
text: i18n("Charge State")
description: {
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.FormTextDelegate { }
id: isRechargeableDelegate
text: i18n("Is Rechargeable") FormCard.FormDelegateSeparator {}
description: battery.rechargeable ? i18n("Yes") : i18n("No")
} FormCard.FormTextDelegate {
id: currentChargeDelegate
MobileForm.FormDelegateSeparator {} text: i18n("Current Charge")
description: i18nc("%1 is percentage value", "%1 %", Number(battery.chargePercent).toLocaleString(Qt.locale(), "f", 0))
MobileForm.FormTextDelegate { }
id: chargeStateDelegate
text: i18n("Charge State") FormCard.FormDelegateSeparator {}
description: {
switch (battery.chargeState) { FormCard.FormTextDelegate {
case Battery.NoCharge: return i18n("Not charging") id: healthDelegate
case Battery.Charging: return i18n("Charging") text: i18n("Health")
case Battery.Discharging: return i18n("Discharging") description: i18nc("%1 is percentage value", "%1 %", Number(battery.capacity).toLocaleString(Qt.locale(), "f", 0))
case Battery.FullyCharged: return i18n("Fully charged") }
default: return i18n("Unknown")
} FormCard.FormDelegateSeparator {}
}
} FormCard.FormTextDelegate {
id: vendorDelegate
MobileForm.FormDelegateSeparator {} text: i18n("Vendor")
description: root.vendor
MobileForm.FormTextDelegate { }
id: currentChargeDelegate
text: i18n("Current Charge") FormCard.FormDelegateSeparator {}
description: i18nc("%1 is percentage value", "%1 %", Number(battery.chargePercent).toLocaleString(Qt.locale(), "f", 0))
} FormCard.FormTextDelegate {
id: modelDelegate
MobileForm.FormDelegateSeparator {} text: i18n("Model")
description: root.product
MobileForm.FormTextDelegate { }
id: healthDelegate
text: i18n("Health") FormCard.FormDelegateSeparator {}
description: i18nc("%1 is percentage value", "%1 %", Number(battery.capacity).toLocaleString(Qt.locale(), "f", 0))
} FormCard.FormTextDelegate {
id: serialDelegate
MobileForm.FormDelegateSeparator {} text: i18n("Serial Number")
description: battery.serial
MobileForm.FormTextDelegate { }
id: vendorDelegate
text: i18n("Vendor") FormCard.FormDelegateSeparator {}
description: root.vendor
} FormCard.FormTextDelegate {
id: technologyDelegate
MobileForm.FormDelegateSeparator {} text: i18n("Technology")
description: {
MobileForm.FormTextDelegate { switch (battery.technology) {
id: modelDelegate case Battery.LithiumIon: return i18n("Lithium ion")
text: i18n("Model") case Battery.LithiumPolymer: return i18n("Lithium polymer")
description: root.product case Battery.LithiumIronPhosphate: return i18n("Lithium iron phosphate")
} case Battery.LeadAcid: return i18n("Lead acid")
case Battery.NickelCadmium: return i18n("Nickel cadmium")
MobileForm.FormDelegateSeparator {} case Battery.NickelMetalHydride: return i18n("Nickel metal hydride")
default: return i18n("Unknown technology")
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")
}
}
} }
} }
} }