Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/package/contents/ui/main.qml
Show All 21 Lines | |||||
22 | import QtQuick.Layouts 1.1 | 22 | import QtQuick.Layouts 1.1 | ||
23 | import org.kde.kirigami 2.5 as Kirigami | 23 | import org.kde.kirigami 2.5 as Kirigami | ||
24 | 24 | | |||
25 | import org.kde.kquickcontrolsaddons 2.0 | 25 | import org.kde.kquickcontrolsaddons 2.0 | ||
26 | import org.kde.kinfocenter.energy.private 1.0 | 26 | import org.kde.kinfocenter.energy.private 1.0 | ||
27 | 27 | | |||
28 | import org.kde.plasma.core 2.0 as PlasmaCore | 28 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
29 | 29 | | |||
30 | import org.kde.plasma.workspace.components 2.0 as WorkspaceComponents | | |||
31 | import org.kde.kcm 1.1 as KCM | 30 | import org.kde.kcm 1.1 as KCM | ||
32 | 31 | | |||
33 | KCM.SimpleKCM { | 32 | KCM.SimpleKCM { | ||
34 | id: root | 33 | id: root | ||
35 | 34 | | |||
36 | KCM.ConfigModule.quickHelp: i18n("This module lets you see energy information and statistics.") | 35 | KCM.ConfigModule.quickHelp: i18n("This module lets you see energy information and statistics.") | ||
37 | 36 | | |||
38 | property QtObject currentBattery: null | 37 | property QtObject currentBattery: null | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
105 | readonly property var timespanComboChoices: [i18n("Last hour"),i18n("Last 2 hours"),i18n("Last 12 hours"),i18n("Last 24 hours"),i18n("Last 48 hours"), i18n("Last 7 days")] | 104 | readonly property var timespanComboChoices: [i18n("Last hour"),i18n("Last 2 hours"),i18n("Last 12 hours"),i18n("Last 24 hours"),i18n("Last 48 hours"), i18n("Last 7 days")] | ||
106 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | 105 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | ||
107 | 106 | | |||
108 | ColumnLayout { | 107 | ColumnLayout { | ||
109 | id: column | 108 | id: column | ||
110 | QQC2.ScrollView { | 109 | QQC2.ScrollView { | ||
111 | id: tabView | 110 | id: tabView | ||
112 | Layout.fillWidth: true | 111 | Layout.fillWidth: true | ||
113 | Layout.minimumHeight: units.gridUnit * 3 | 112 | Layout.minimumHeight: units.gridUnit * 4 | ||
114 | Layout.maximumHeight: Layout.minimumHeight | 113 | Layout.maximumHeight: Layout.minimumHeight | ||
115 | visible: kcm.batteries.count > 1 | 114 | visible: kcm.batteries.count > 1 | ||
116 | 115 | | |||
117 | Row { | 116 | Row { | ||
118 | spacing: Kirigami.Units.smallSpacing | 117 | spacing: Kirigami.Units.smallSpacing | ||
119 | Repeater { | 118 | Repeater { | ||
120 | model: kcm.batteries | 119 | model: kcm.batteries | ||
121 | 120 | | |||
122 | QQC2.Button { | 121 | QQC2.Button { | ||
123 | id: button | 122 | id: button | ||
124 | width: height | 123 | width: units.gridUnit * 10 | ||
125 | height: tabView.height | 124 | height: tabView.height | ||
126 | checked: model.battery == root.currentBattery | 125 | checked: model.battery == root.currentBattery | ||
127 | checkable: true | 126 | checkable: true | ||
128 | onClicked: { | 127 | onClicked: { | ||
129 | root.currentUdi = model.udi | 128 | root.currentUdi = model.udi | ||
130 | root.currentVendor = model.vendor | 129 | root.currentVendor = model.vendor | ||
131 | root.currentProduct = model.product | 130 | root.currentProduct = model.product | ||
132 | root.currentBattery = model.battery | 131 | root.currentBattery = model.battery | ||
133 | 132 | | |||
134 | // override checked property | 133 | // override checked property | ||
135 | checked = Qt.binding(function() { | 134 | checked = Qt.binding(function() { | ||
136 | return model.battery == root.currentBattery | 135 | return model.battery == root.currentBattery | ||
137 | }) | 136 | }) | ||
138 | 137 | | |||
139 | showWakeUps = (index === 0) | 138 | showWakeUps = (index === 0) | ||
140 | } | 139 | } | ||
141 | 140 | | |||
142 | ColumnLayout { | 141 | ColumnLayout { | ||
143 | anchors { | 142 | anchors { | ||
144 | fill: parent | 143 | fill: parent | ||
145 | margins: units.smallSpacing | 144 | margins: units.smallSpacing * 2 | ||
146 | } | 145 | } | ||
147 | spacing: 0 | 146 | RowLayout { | ||
148 | 147 | | |||
149 | WorkspaceComponents.BatteryIcon { | 148 | Kirigami.Icon { | ||
149 | id: batteryIcon | ||||
150 | Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium | ||||
151 | Layout.preferredHeight: Layout.preferredWidth | ||||
152 | source: { | ||||
153 | switch(model.battery.type) { | ||||
154 | case 3: return model.battery.chargeState === 1 ? "battery-full-charging" : "battery-full" | ||||
155 | case 2: return "battery-ups" | ||||
156 | case 9: return "monitor" | ||||
157 | case 4: return "input-mouse" | ||||
158 | case 5: return "input-keyboard" | ||||
159 | case 1: return "phone" | ||||
160 | case 7: return "smartphone" | ||||
161 | default: return "paint-unknown" | ||||
162 | } | ||||
163 | } | ||||
164 | } | ||||
165 | | ||||
166 | QQC2.Label { | ||||
150 | Layout.fillWidth: true | 167 | Layout.fillWidth: true | ||
151 | Layout.fillHeight: true | 168 | text: { | ||
152 | hasBattery: true | | |||
153 | batteryType: { | | |||
154 | switch(model.battery.type) { | 169 | switch(model.battery.type) { | ||
155 | case 3: return "Battery" | 170 | case 3: return i18n("Internal battery") | ||
156 | case 2: return "Ups" | 171 | case 2: return i18n("UPS battery") | ||
157 | case 9: return "Monitor" | 172 | case 9: return i18n("Monitor battery") | ||
158 | case 4: return "Mouse" | 173 | case 4: return i18n("Mouse battery") | ||
159 | case 5: return "Keyboard" | 174 | case 5: return i18n("Keyboard battery") | ||
160 | case 1: return "Pda" | 175 | case 1: return i18n("PDA battery") | ||
161 | case 7: return "Phone" | 176 | case 7: return i18n("Phone battery") | ||
162 | default: return "Unknown" | 177 | default: return i18n("Unknown battery") | ||
163 | } | 178 | } | ||
broulik: Now you lost the battery level and charging state in the icon. | |||||
Can use the following var iconNameParts = ["battery"]; // Round percentage to the nearest 10% and pad it with leading zeroes to match the icon names iconNameParts.push(String(Math.round(model.battery.chargePercent / 10) * 10).padStart(3, "0")); if (model.battery.chargeState === 1) { // charging iconNameParts.push("charging"); } return iconNameParts.join("-"); broulik: Can use the following
```
var iconNameParts = ["battery"];
// Round percentage to the nearest… | |||||
My thought was that the battery level indicator inside the icon wasn't necessary because this UI has a current charge level indicator below the icon. Might be nice to show the plugged-in status though. ngraham: My thought was that the battery level indicator inside the icon wasn't necessary because this… | |||||
164 | } | 179 | } | ||
165 | percent: model.battery.chargePercent | 180 | elide: Text.ElideRight | ||
166 | //pluggedIn: model.battery.chargeState === 1 // Makes it hard to see | 181 | } | ||
167 | } | 182 | } | ||
168 | 183 | | |||
169 | QQC2.ProgressBar { // TODO make progress bar not eat mouse events | 184 | RowLayout { | ||
185 | QQC2.ProgressBar { | ||||
186 | id: percentageSlider | ||||
170 | Layout.fillWidth: true | 187 | Layout.fillWidth: true | ||
171 | from: 0 | 188 | from: 0 | ||
172 | to: 100 | 189 | to: 100 | ||
173 | value: model.battery.chargePercent | 190 | value: model.battery.chargePercent | ||
174 | enabled: button.checked ? false : true | 191 | } | ||
192 | | ||||
193 | QQC2.Label { | ||||
194 | text: model.battery.chargeState === 1 ? | ||||
195 | i18nc("Battery charge percentage", "%1% (Charging)", Math.round(percentageSlider.value)) : | ||||
196 | i18nc("Battery charge percentage", "%1%", Math.round(percentageSlider.value)) | ||||
197 | } | ||||
175 | } | 198 | } | ||
176 | } | 199 | } | ||
177 | } | 200 | } | ||
178 | } | 201 | } | ||
179 | } | 202 | } | ||
180 | } | 203 | } | ||
181 | 204 | | |||
182 | ColumnLayout { | 205 | ColumnLayout { | ||
▲ Show 20 Lines • Show All 288 Lines • Show Last 20 Lines |
Now you lost the battery level and charging state in the icon.