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 71 Lines • ▼ Show 20 Line(s) | |||||
110 | 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")] | 109 | 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")] | ||
111 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | 110 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | ||
112 | 111 | | |||
113 | ColumnLayout { | 112 | ColumnLayout { | ||
114 | id: column | 113 | id: column | ||
115 | QQC2.ScrollView { | 114 | QQC2.ScrollView { | ||
116 | id: tabView | 115 | id: tabView | ||
117 | Layout.fillWidth: true | 116 | Layout.fillWidth: true | ||
118 | Layout.minimumHeight: units.gridUnit * 3 | 117 | Layout.minimumHeight: units.gridUnit * 4 | ||
119 | Layout.maximumHeight: Layout.minimumHeight | 118 | Layout.maximumHeight: Layout.minimumHeight | ||
120 | visible: kcm.batteries.count > 1 | 119 | visible: kcm.batteries.count > 1 | ||
121 | 120 | | |||
122 | Row { | 121 | Row { | ||
123 | spacing: Kirigami.Units.smallSpacing | 122 | spacing: Kirigami.Units.smallSpacing | ||
124 | Repeater { | 123 | Repeater { | ||
125 | model: kcm.batteries | 124 | model: kcm.batteries | ||
126 | 125 | | |||
127 | QQC2.Button { | 126 | QQC2.Button { | ||
128 | id: button | 127 | id: button | ||
129 | width: height | 128 | width: units.gridUnit * 10 | ||
130 | height: tabView.height | 129 | height: tabView.height | ||
131 | checked: model.battery == root.currentBattery | 130 | checked: model.battery == root.currentBattery | ||
132 | checkable: true | 131 | checkable: true | ||
133 | onClicked: { | 132 | onClicked: { | ||
134 | root.currentUdi = model.udi | 133 | root.currentUdi = model.udi | ||
135 | root.currentBattery = model.battery | 134 | root.currentBattery = model.battery | ||
136 | // override checked property | 135 | // override checked property | ||
137 | checked = Qt.binding(function() { | 136 | checked = Qt.binding(function() { | ||
138 | return model.battery == root.currentBattery | 137 | return model.battery == root.currentBattery | ||
139 | }) | 138 | }) | ||
140 | 139 | | |||
141 | showWakeUps = (index === 0) | 140 | showWakeUps = (index === 0) | ||
142 | } | 141 | } | ||
143 | 142 | | |||
144 | ColumnLayout { | 143 | ColumnLayout { | ||
145 | anchors { | 144 | anchors { | ||
146 | fill: parent | 145 | fill: parent | ||
147 | margins: units.smallSpacing | 146 | margins: units.smallSpacing * 2 | ||
148 | } | 147 | } | ||
149 | spacing: 0 | 148 | RowLayout { | ||
150 | 149 | | |||
151 | WorkspaceComponents.BatteryIcon { | 150 | Kirigami.Icon { | ||
151 | id: batteryIcon | ||||
152 | Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium | ||||
153 | Layout.preferredHeight: Layout.preferredWidth | ||||
154 | source: { | ||||
155 | switch(model.battery.type) { | ||||
156 | case 3: return model.battery.chargeState === 1 ? "battery-full-charging" : "battery-full" | ||||
157 | case 2: return "battery-ups" | ||||
158 | case 9: return "monitor" | ||||
159 | case 4: return "input-mouse" | ||||
160 | case 5: return "input-keyboard" | ||||
161 | case 1: return "phone" | ||||
162 | case 7: return "smartphone" | ||||
163 | default: return "paint-unknown" | ||||
164 | } | ||||
165 | } | ||||
166 | } | ||||
167 | | ||||
168 | QQC2.Label { | ||||
152 | Layout.fillWidth: true | 169 | Layout.fillWidth: true | ||
153 | Layout.fillHeight: true | 170 | text: { | ||
154 | hasBattery: true | | |||
155 | batteryType: { | | |||
156 | switch(model.battery.type) { | 171 | switch(model.battery.type) { | ||
157 | case 3: return "Battery" | 172 | case 3: return i18n("Internal battery") | ||
158 | case 2: return "Ups" | 173 | case 2: return i18n("UPS battery") | ||
159 | case 9: return "Monitor" | 174 | case 9: return i18n("Monitor battery") | ||
160 | case 4: return "Mouse" | 175 | case 4: return i18n("Mouse battery") | ||
161 | case 5: return "Keyboard" | 176 | case 5: return i18n("Keyboard battery") | ||
162 | case 1: return "Pda" | 177 | case 1: return i18n("PDA battery") | ||
163 | case 7: return "Phone" | 178 | case 7: return i18n("Phone battery") | ||
164 | default: return "Unknown" | 179 | default: return i18n("Unknown battery") | ||
165 | } | 180 | } | ||
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… | |||||
166 | } | 181 | } | ||
167 | percent: model.battery.chargePercent | 182 | elide: Text.ElideRight | ||
168 | //pluggedIn: model.battery.chargeState === 1 // Makes it hard to see | 183 | } | ||
169 | } | 184 | } | ||
170 | 185 | | |||
171 | QQC2.ProgressBar { // TODO make progress bar not eat mouse events | 186 | RowLayout { | ||
187 | QQC2.ProgressBar { | ||||
188 | id: percentageSlider | ||||
172 | Layout.fillWidth: true | 189 | Layout.fillWidth: true | ||
173 | from: 0 | 190 | from: 0 | ||
174 | to: 100 | 191 | to: 100 | ||
175 | value: model.battery.chargePercent | 192 | value: model.battery.chargePercent | ||
176 | enabled: button.checked ? false : true | 193 | } | ||
194 | | ||||
195 | QQC2.Label { | ||||
196 | text: model.battery.chargeState === 1 ? | ||||
197 | i18nc("Battery charge percentage", "%1% (Charging)", Math.round(percentageSlider.value)) : | ||||
198 | i18nc("Battery charge percentage", "%1%", Math.round(percentageSlider.value)) | ||||
199 | } | ||||
177 | } | 200 | } | ||
178 | } | 201 | } | ||
179 | } | 202 | } | ||
180 | } | 203 | } | ||
181 | } | 204 | } | ||
182 | } | 205 | } | ||
183 | 206 | | |||
184 | ColumnLayout { | 207 | ColumnLayout { | ||
▲ Show 20 Lines • Show All 289 Lines • Show Last 20 Lines |
Now you lost the battery level and charging state in the icon.