Warning, /plasma/plasma-workspace/applets/batterymonitor/package/contents/ui/PopupDialog.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2011 Viranch Mehta <viranch.mehta@gmail.com> 0003 SPDX-FileCopyrightText: 2013-2016 Kai Uwe Broulik <kde@privat.broulik.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 0009 import QtQuick.Layouts 0010 0011 import org.kde.plasma.components as PlasmaComponents3 0012 import org.kde.plasma.extras as PlasmaExtras 0013 import org.kde.kirigami as Kirigami 0014 0015 PlasmaExtras.Representation { 0016 id: dialog 0017 0018 property alias model: batteryRepeater.model 0019 property bool pluggedIn 0020 0021 property int remainingTime 0022 0023 property var profilesInstalled 0024 property string activeProfile 0025 property var profiles 0026 0027 // List of active power management inhibitions (applications that are 0028 // blocking sleep and screen locking). 0029 // 0030 // type: [{ 0031 // Icon: string, 0032 // Name: string, 0033 // Reason: string, 0034 // }] 0035 property var inhibitions: [] 0036 property bool manuallyInhibited 0037 property bool inhibitsLidAction 0038 0039 property string inhibitionReason 0040 property string degradationReason 0041 // type: [{ Name: string, Icon: string, Profile: string, Reason: string }] 0042 required property var profileHolds 0043 0044 signal powerManagementChanged(bool disabled) 0045 signal inhibitionChangeRequested(bool inhibit) 0046 signal activateProfileRequested(string profile) 0047 0048 collapseMarginsHint: true 0049 0050 KeyNavigation.down: pmSwitch.pmCheckBox 0051 0052 header: PlasmaExtras.PlasmoidHeading { 0053 leftPadding: !mirrored ? Kirigami.Units.smallSpacing : 0 0054 rightPadding: mirrored ? Kirigami.Units.smallSpacing : 0 0055 0056 contentItem: PowerManagementItem { 0057 id: pmSwitch 0058 0059 inhibitions: dialog.inhibitions 0060 manuallyInhibited: dialog.manuallyInhibited 0061 inhibitsLidAction: dialog.inhibitsLidAction 0062 pluggedIn: dialog.pluggedIn 0063 0064 onInhibitionChangeRequested: inhibit => { 0065 dialog.inhibitionChangeRequested(inhibit); 0066 } 0067 0068 onDisabledChanged: dialog.powerManagementChanged(disabled) 0069 } 0070 } 0071 0072 contentItem: PlasmaComponents3.ScrollView { 0073 id: scrollView 0074 0075 focus: false 0076 0077 function positionViewAtItem(item) { 0078 if (!PlasmaComponents3.ScrollBar.vertical.visible) { 0079 return; 0080 } 0081 const rect = batteryList.mapFromItem(item, 0, 0, item.width, item.height); 0082 if (rect.y < scrollView.contentItem.contentY) { 0083 scrollView.contentItem.contentY = rect.y; 0084 } else if (rect.y + rect.height > scrollView.contentItem.contentY + scrollView.height) { 0085 scrollView.contentItem.contentY = rect.y + rect.height - scrollView.height; 0086 } 0087 } 0088 0089 Column { 0090 id: batteryList 0091 0092 spacing: Kirigami.Units.smallSpacing * 2 0093 0094 readonly property Item firstHeaderItem: { 0095 if (powerProfileItem.visible) { 0096 return powerProfileItem; 0097 } 0098 return null; 0099 } 0100 readonly property Item lastHeaderItem: { 0101 if (powerProfileItem.visible) { 0102 return powerProfileItem; 0103 } 0104 return null; 0105 } 0106 0107 PowerProfileItem { 0108 id: powerProfileItem 0109 0110 width: scrollView.availableWidth 0111 0112 KeyNavigation.down: batteryRepeater.count > 0 ? batteryRepeater.itemAt(0) : null 0113 KeyNavigation.backtab: KeyNavigation.up 0114 KeyNavigation.tab: KeyNavigation.down 0115 0116 profilesInstalled: dialog.profilesInstalled 0117 profilesAvailable: dialog.profiles.length > 0 0118 activeProfile: dialog.activeProfile 0119 inhibitionReason: dialog.inhibitionReason 0120 degradationReason: dialog.degradationReason 0121 profileHolds: dialog.profileHolds 0122 0123 onActivateProfileRequested: profile => { 0124 dialog.activateProfileRequested(profile); 0125 } 0126 0127 onActiveFocusChanged: if (activeFocus) scrollView.positionViewAtItem(this) 0128 } 0129 0130 Repeater { 0131 id: batteryRepeater 0132 0133 delegate: BatteryItem { 0134 width: scrollView.availableWidth 0135 0136 battery: model 0137 remainingTime: dialog.remainingTime 0138 0139 KeyNavigation.up: index === 0 ? batteryList.lastHeaderItem : batteryRepeater.itemAt(index - 1) 0140 KeyNavigation.down: index + 1 < batteryRepeater.count ? batteryRepeater.itemAt(index + 1) : null 0141 KeyNavigation.backtab: KeyNavigation.up 0142 KeyNavigation.tab: KeyNavigation.down 0143 0144 Keys.onTabPressed: event => { 0145 if (index === batteryRepeater.count - 1) { 0146 // Workaround to leave applet's focus on desktop 0147 nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocusReason); 0148 } else { 0149 event.accepted = false; 0150 } 0151 } 0152 0153 onActiveFocusChanged: if (activeFocus) scrollView.positionViewAtItem(this) 0154 } 0155 } 0156 } 0157 } 0158 } 0159