1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
SPDX-FileCopyrightText: 2011 Viranch Mehta <viranch.mehta@gmail.com>
SPDX-FileCopyrightText: 2013-2016 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.components as PlasmaComponents3
import org.kde.plasma.extras as PlasmaExtras
import org.kde.kirigami as Kirigami
PlasmaExtras.Representation {
id: dialog
property alias model: batteryRepeater.model
property bool pluggedIn
property int chargeStopThreshold
property bool isManuallyInhibited
property bool isManuallyInhibitedError
property int remainingTime
property bool profilesInstalled
property string activeProfile
property string activeProfileError
property var profiles
property bool isTlpInstalled
// List of currently requested power management inhibitions (applications that
// are blocking sleep and screen locking). Not all are necessarily active.
//
// type: [{
// appName: string,
// prettyName: string,
// icon: string,
// reason: string,
// what: array<string>, // what's inhibited: "idle", "sleep", both, or any future inhibition types
// active: bool,
// allowed: bool,
// }]
property var requestedInhibitions: []
property bool inhibitsLidAction
property string inhibitionReason
property string degradationReason
// type: [{ Name: string, Icon: string, Profile: string, Reason: string }]
required property var profileHolds
signal inhibitionChangeRequested(bool inhibit)
signal activateProfileRequested(string profile)
collapseMarginsHint: true
KeyNavigation.down: batteryRepeater.headerItem
contentItem: PlasmaComponents3.ScrollView {
id: scrollView
focus: false
function positionViewAtItem(item: Item): void {
if (!PlasmaComponents3.ScrollBar.vertical.visible) {
return;
}
const rect = batteryRepeater.contentItem.mapFromItem(item, 0, 0, item.width, item.height);
if (rect.y < scrollView.contentItem.contentY) {
scrollView.contentItem.contentY = rect.y;
} else if (rect.y + rect.height > scrollView.contentItem.contentY + scrollView.height) {
scrollView.contentItem.contentY = rect.y + rect.height - scrollView.height;
}
}
ListView {
id: batteryRepeater
spacing: Kirigami.Units.smallSpacing * 2
// Note: this Column prevents ListView from throwing a cryptic warning and breaking CI:
// > QQmlComponent: Cannot create new component instance before completing the previous
// However, it also the source of a bug that the view is slightly scrollable for no reason.
header: Column {
width: scrollView.availableWidth
PowerProfileItem {
anchors.left: parent.left
anchors.right: parent.right
KeyNavigation.up: batteryRepeater.footerItem
KeyNavigation.down: batteryRepeater.count > 0 ? batteryRepeater.itemAtIndex(0) : batteryRepeater.footerItem
KeyNavigation.backtab: KeyNavigation.up
KeyNavigation.tab: KeyNavigation.down
profilesInstalled: dialog.profilesInstalled
profilesAvailable: dialog.profiles.length > 0
activeProfile: dialog.activeProfile
activeProfileError: dialog.activeProfileError
inhibitionReason: dialog.inhibitionReason
degradationReason: dialog.degradationReason
profileHolds: dialog.profileHolds
isTlpInstalled: dialog.isTlpInstalled
onActivateProfileRequested: profile => {
dialog.activateProfileRequested(profile);
}
onActiveFocusChanged: if (activeFocus) scrollView.positionViewAtItem(this)
}
}
delegate: BatteryItem {
width: scrollView.availableWidth
batteryPercent: Percent
batteryCapacity: Capacity
batteryEnergy: Energy
batteryPluggedIn: PluggedIn
batteryIsPowerSupply: IsPowerSupply
batteryChargeState: ChargeState
batteryPrettyName: PrettyName
batteryType: Type
remainingTime: dialog.remainingTime
KeyNavigation.up: index === 0 ? null : batteryRepeater.itemAtIndex(index - 1)
KeyNavigation.down: index + 1 < batteryRepeater.count ? batteryRepeater.itemAtIndex(index + 1) : batteryRepeater.footerItem
pluggedIn: dialog.pluggedIn
chargeStopThreshold: dialog.chargeStopThreshold
KeyNavigation.backtab: KeyNavigation.up
KeyNavigation.tab: KeyNavigation.down
Keys.onTabPressed: event => {
if (index === batteryRepeater.count - 1) {
// Workaround to leave applet's focus on desktop
nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocusReason);
} else {
event.accepted = false;
}
}
onActiveFocusChanged: if (activeFocus) scrollView.positionViewAtItem(this)
}
footer: InhibitionItem {
readonly property var inhibitionControl: dialog.inhibitionControl
width: scrollView.availableWidth
KeyNavigation.up: batteryRepeater.itemAtIndex(batteryRepeater.count - 1)
KeyNavigation.down: null
KeyNavigation.backtab:KeyNavigation.up
requestedInhibitions: dialog.requestedInhibitions
isManuallyInhibited: dialog.isManuallyInhibited
isManuallyInhibitedError: dialog.isManuallyInhibitedError
inhibitsLidAction: dialog.inhibitsLidAction
pluggedIn: dialog.pluggedIn
onInhibitionChangeRequested: inhibit => {
batterymonitor.inhibitionChangeRequested(inhibit);
}
onActiveFocusChanged: if (activeFocus) scrollView.positionViewAtItem(this)
}
}
}
}
|