@ -16,7 +16,7 @@ import org.kde.plasma.workspace.components 2.0
import "logic.js" as Logic
import "logic.js" as Logic
RowLayout {
PlasmaComponents3 . ItemDelegate {
id: root
id: root
/ / W e ' d l o v e t o u s e ` r e q u i r e d ` p r o p e r t i e s , e s p e c i a l l y s i n c e t h e m o d e l p r o v i d e s r o l e n a m e s f o r t h e m ;
/ / W e ' d l o v e t o u s e ` r e q u i r e d ` p r o p e r t i e s , e s p e c i a l l y s i n c e t h e m o d e l p r o v i d e s r o l e n a m e s f o r t h e m ;
@ -54,148 +54,168 @@ RowLayout {
property PlasmaComponents3 . Slider matchHeightOfSlider: PlasmaComponents3 . Slider { }
property PlasmaComponents3 . Slider matchHeightOfSlider: PlasmaComponents3 . Slider { }
readonly property real extraMargin: Math . max ( 0 , Math . floor ( ( matchHeightOfSlider . height - chargeBar . height ) / 2 ) )
readonly property real extraMargin: Math . max ( 0 , Math . floor ( ( matchHeightOfSlider . height - chargeBar . height ) / 2 ) )
spacing: PlasmaCore . Units . gridUnit
background.visible: highlighted
highlighted: activeFocus
text: battery [ "Pretty Name" ]
BatteryIcon {
Accessible.description: ` $ { isPowerSupplyLabel . text } $ { percentLabel . text } ; $ { details . Accessible . description } `
id: batteryIcon
Layout.alignment: Qt . AlignTop
contentItem: RowLayout {
Layout.preferredWidth: PlasmaCore . Units . iconSizes . medium
spacing: PlasmaCore . Units . gridUnit
Layout.preferredHeight: PlasmaCore . Units . iconSizes . medium
batteryType: root . battery . Type
BatteryIcon {
percent: root . battery . Percent
id: batteryIcon
hasBattery: root . isPresent
pluggedIn: root . battery . State === "Charging" && root . battery [ "Is Power Supply" ]
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment: root . isPresent ? Qt.AlignTop : Qt . AlignVCenter
spacing: 0
RowLayout {
spacing: PlasmaCore . Units . smallSpacing
PlasmaComponents3 . Label {
Layout.fillWidth: true
elide: Text . ElideRight
text: root . battery [ "Pretty Name" ]
}
PlasmaComponents3 . Label {
Layout.alignment: Qt . AlignTop
text: Logic . stringForBatteryState ( root . battery )
Layout.preferredWidth: PlasmaCore . Units . iconSizes . medium
visible: root . battery [ "Is Power Supply" ]
Layout.preferredHeight: PlasmaCore . Units . iconSizes . medium
enabled: false
}
PlasmaComponents3 . Label {
batteryType: root . battery . Type
horizontalAlignment: Text . AlignRight
percent: root . battery . Percent
visible: root . isPresent
hasBattery: root . isPresent
text: i18nc ( "Placeholder is battery percentage" , "%1%" , root . battery . Percent )
pluggedIn: root . battery . State === "Charging" && root . battery [ "Is Power Supply" ]
}
}
}
PlasmaComponents3 . ProgressBar {
ColumnLayout {
id: chargeBar
Layout.fillWidth: true
Layout.topMargin: root . extraMargin
Layout.bottomMargin: root . extraMargin
from: 0
to: 100
visible: root . isPresent
value: Number ( root . battery . Percent )
}
/ / T h i s g r i d L a y o u t b a s i c a l l y e m u l a t e s a n a t - m o s t - t w o - r o w s t a b l e w i t h a
/ / s i n g l e w i d e f i l l W i d t h / c o l u m n S p a n h e a d e r . N o t r e a l l y w o r t h i t t r y i n g
/ / t o r e f a c t o r i t i n t o s o m e m o r e c l e v e r f a n c y m o d e l - d e l e g a t e s t u f f .
GridLayout {
id: details
Layout.fillWidth: true
Layout.fillWidth: true
Layout.topMargin: PlasmaCore . Units . smallSpacing
Layout.alignment: root . isPresent ? Qt.AlignTop : Qt . AlignVCenter
spacing: 0
RowLayout {
spacing: PlasmaCore . Units . smallSpacing
PlasmaComponents3 . Label {
Layout.fillWidth: true
elide: Text . ElideRight
text: root . text
}
PlasmaComponents3 . Label {
id: isPowerSupplyLabel
text: Logic . stringForBatteryState ( root . battery )
visible: root . battery [ "Is Power Supply" ]
enabled: false
}
PlasmaComponents3 . Label {
id: percentLabel
horizontalAlignment: Text . AlignRight
visible: root . isPresent
text: i18nc ( "Placeholder is battery percentage" , "%1%" , root . battery . Percent )
}
}
columns: 2
PlasmaComponents3 . ProgressBar {
columnSpacing: PlasmaCore . Units . smallSpacing
id: chargeBar
rowSpacing: 0
component LeftLabel : PlasmaComponents3 . Label {
/ / f i l l W i d t h i s t r u e , s o u s i n g i n t e r n a l a l i g n m e n t
horizontalAlignment: Text . AlignLeft
Layout.fillWidth: true
Layout.fillWidth: true
font: PlasmaCore . Theme . smallestFont
Layout.topMargin: root . extraMargin
wrapMode: Text . WordWrap
Layout.bottomMargin: root . extraMargin
enabled: false
}
component RightLabel : PlasmaComponents3 . Label {
/ / f i l l W i d t h i s f a l s e , s o u s i n g e x t e r n a l ( g r i d - c e l l - i n t e r n a l ) a l i g n m e n t
Layout.alignment: Qt . AlignRight
Layout.fillWidth: false
font: PlasmaCore . Theme . smallestFont
enabled: false
}
PlasmaComponents3 . Label {
from: 0
Layout.fillWidth: true
to: 100
Layout.columnSpan: 2
visible: root . isPresent
value: Number ( root . battery . Percent )
text: root . isBroken && typeof root . battery . Capacity !== "undefined"
? i18n ( "This battery's health is at only %1% and it should be replaced. Contact the manufacturer." , root . battery . Capacity )
: ""
font: PlasmaCore . Theme . smallestFont
color: PlasmaCore . Theme . neutralTextColor
visible: root . isBroken
wrapMode: Text . WordWrap
}
}
readonly property bool remainingTimeRowVisible: root . battery !== null
/ / T h i s g r i d L a y o u t b a s i c a l l y e m u l a t e s a n a t - m o s t - t w o - r o w s t a b l e w i t h a
&& root . remainingTime > 0
/ / s i n g l e w i d e f i l l W i d t h / c o l u m n S p a n h e a d e r . N o t r e a l l y w o r t h i t t r y i n g
&& root . battery [ "Is Power Supply" ]
/ / t o r e f a c t o r i t i n t o s o m e m o r e c l e v e r f a n c y m o d e l - d e l e g a t e s t u f f .
&& [ "Discharging" , "Charging" ] . includes ( root . battery . State )
GridLayout {
id: details
LeftLabel {
text: root . battery . State === "Charging"
? i18n ( "Time To Full:" )
: i18n ( "Remaining Time:" )
visible: details . remainingTimeRowVisible
}
RightLabel {
Layout.fillWidth: true
text: KCoreAddons . Format . formatDuration ( root . remainingTime , KCoreAddons . FormatTypes . HideSeconds )
Layout.topMargin: PlasmaCore . Units . smallSpacing
visible: details . remainingTimeRowVisible
columns: 2
columnSpacing: PlasmaCore . Units . smallSpacing
rowSpacing: 0
Accessible.description: {
let description = [ ] ;
for ( let i = 0 ; i < children . length ; i ++ ) {
if ( children [ i ] . visible && children [ i ] . hasOwnProperty ( "text" ) ) {
description . push ( children [ i ] . text ) ;
}
}
return description . join ( " " ) ;
}
component LeftLabel : PlasmaComponents3 . Label {
/ / f i l l W i d t h i s t r u e , s o u s i n g i n t e r n a l a l i g n m e n t
horizontalAlignment: Text . AlignLeft
Layout.fillWidth: true
font: PlasmaCore . Theme . smallestFont
wrapMode: Text . WordWrap
enabled: false
}
component RightLabel : PlasmaComponents3 . Label {
/ / f i l l W i d t h i s f a l s e , s o u s i n g e x t e r n a l ( g r i d - c e l l - i n t e r n a l ) a l i g n m e n t
Layout.alignment: Qt . AlignRight
Layout.fillWidth: false
font: PlasmaCore . Theme . smallestFont
enabled: false
}
PlasmaComponents3 . Label {
Layout.fillWidth: true
Layout.columnSpan: 2
text: root . isBroken && typeof root . battery . Capacity !== "undefined"
? i18n ( "This battery's health is at only %1% and it should be replaced. Contact the manufacturer." , root . battery . Capacity )
: ""
font: PlasmaCore . Theme . smallestFont
color: PlasmaCore . Theme . neutralTextColor
visible: root . isBroken
wrapMode: Text . WordWrap
}
readonly property bool remainingTimeRowVisible: root . battery !== null
&& root . remainingTime > 0
&& root . battery [ "Is Power Supply" ]
&& [ "Discharging" , "Charging" ] . includes ( root . battery . State )
LeftLabel {
text: root . battery . State === "Charging"
? i18n ( "Time To Full:" )
: i18n ( "Remaining Time:" )
visible: details . remainingTimeRowVisible
}
RightLabel {
text: KCoreAddons . Format . formatDuration ( root . remainingTime , KCoreAddons . FormatTypes . HideSeconds )
visible: details . remainingTimeRowVisible
}
readonly property bool healthRowVisible: root . battery !== null
&& root . battery [ "Is Power Supply" ]
&& root . battery . Capacity !== ""
&& typeof root . battery . Capacity === "number"
&& ! root . isBroken
LeftLabel {
text: i18n ( "Battery Health:" )
visible: details . healthRowVisible
}
RightLabel {
text: details . healthRowVisible
? i18nc ( "Placeholder is battery health percentage" , "%1%" , root . battery . Capacity )
: ""
visible: details . healthRowVisible
}
}
}
readonly property bool healthRowVisible: root . battery !== null
InhibitionHint {
&& root . battery [ "Is Power Supply" ]
Layout.fillWidth: true
&& root . battery . Capacity !== ""
Layout.topMargin: PlasmaCore . Units . smallSpacing
&& typeof root . battery . Capacity === "number"
&& ! root . isBroken
LeftLabel {
text: i18n ( "Battery Health:" )
visible: details . healthRowVisible
}
RightLabel {
readonly property var chargeStopThreshold: pmSource . data [ "Battery" ] ? pmSource . data [ "Battery" ] [ "Charge Stop Threshold" ] : undefined
text: details . healthRowVisible
readonly property bool pluggedIn: pmSource . data [ "AC Adapter" ] !== undefined && pmSource . data [ "AC Adapter" ] [ "Plugged in" ]
? i18nc ( "Placeholder is battery health percentage" , "%1%" , root . battery . Capacity )
visible: pluggedIn && root . isPowerSupply && typeof chargeStopThreshold === "number" && chargeStopThreshold > 0 && chargeStopThreshold < 100
: ""
iconSource: "kt-speed-limits" / / F I X M E g o o d i c o n
visible: details . healthRowVisible
text: i18n ( "Battery is configured to charge up to approximately %1%." , chargeStopThreshold || 0 )
}
}
}
}
InhibitionHint {
Layout.fillWidth: true
Layout.topMargin: PlasmaCore . Units . smallSpacing
readonly property var chargeStopThreshold: pmSource . data [ "Battery" ] ? pmSource . data [ "Battery" ] [ "Charge Stop Threshold" ] : undefined
readonly property bool pluggedIn: pmSource . data [ "AC Adapter" ] !== undefined && pmSource . data [ "AC Adapter" ] [ "Plugged in" ]
visible: pluggedIn && root . isPowerSupply && typeof chargeStopThreshold === "number" && chargeStopThreshold > 0 && chargeStopThreshold < 100
iconSource: "kt-speed-limits" / / F I X M E g o o d i c o n
text: i18n ( "Battery is configured to charge up to approximately %1%." , chargeStopThreshold || 0 )
}
}
}
}
}