diff --git a/Modules/energy/package/contents/ui/main.qml b/Modules/energy/package/contents/ui/main.qml --- a/Modules/energy/package/contents/ui/main.qml +++ b/Modules/energy/package/contents/ui/main.qml @@ -17,10 +17,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -import QtQuick 2.2 -import QtQuick.Controls 1.3 -import QtQuick.Controls 2.0 as QQC2 +import QtQuick 2.5 +import QtQuick.Controls 2.12 import QtQuick.Layouts 1.1 +import org.kde.kirigami 2.5 as Kirigami import org.kde.kquickcontrolsaddons 2.0 import org.kde.kinfocenter.energy.private 1.0 @@ -107,41 +107,32 @@ implicitWidth: units.gridUnit * 25 implicitHeight: !!currentBattery ? units.gridUnit * 25 : units.gridUnit * 12 - SystemPalette { - id: syspal - } + 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")] + readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] - ScrollView { - id: scrollView + Kirigami.ScrollablePage { anchors.fill: parent - horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff - ColumnLayout { id: column - - width: scrollView.viewport.width - spacing: units.largeSpacing - - ScrollView { + Kirigami.ScrollablePage { id: tabView - Layout.fillWidth: true Layout.minimumHeight: units.gridUnit * 3 Layout.maximumHeight: Layout.minimumHeight - frameVisible: true + // frameVisible: true visible: kcm.batteries.count > 1 - verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff + verticalScrollBarPolicy: ScrollBar.AlwaysOff Row { Repeater { model: kcm.batteries Button { id: button width: height - height: tabView.viewport.height + height: tabView.height checked: model.battery == root.currentBattery checkable: true onClicked: { @@ -184,8 +175,8 @@ ProgressBar { // TODO make progress bar not eat mouse events Layout.fillWidth: true - minimumValue: 0 - maximumValue: 100 + from: 0 + to: 100 value: model.battery.chargePercent enabled: button.checked ? false : true } @@ -232,29 +223,25 @@ ComboBox { id: timespanCombo Layout.minimumWidth: units.gridUnit * 6 - model: [ - {text: i18n("Last hour"), value: 3600}, - {text: i18n("Last 2 hours"), value: 7200}, - {text: i18n("Last 12 hours"), value: 43200}, - {text: i18n("Last 24 hours"), value: 86400}, - {text: i18n("Last 48 hours"), value: 172800}, - {text: i18n("Last 7 days"), value: 604800} - ] + model: timespanComboChoices Accessible.name: i18n("Timespan") Accessible.description: i18n("Timespan of data to display") } Button { - iconName: "view-refresh" - tooltip: i18n("Refresh") - Accessible.name: tooltip + icon.name: "view-refresh" + hoverEnabled: true + ToolTip.text: i18n("Refresh") + ToolTip.visible: hovered + ToolTip.delay: Kirigami.Units.toolTipDelay + Accessible.name: ToolTip.text onClicked: history.refresh() } } HistoryModel { id: history - duration: timespanCombo.model[timespanCombo.currentIndex].value + duration: timespanComboDurations[timespanCombo.currentIndex] device: currentUdi type: root.historyType } @@ -286,7 +273,7 @@ visible: history.count > 1 } - QQC2.Label { + Label { Layout.fillWidth: true Layout.minimumHeight: column.width / 3 Layout.maximumHeight: column.width / 3 @@ -366,7 +353,7 @@ RowLayout { Layout.fillWidth: true - QQC2.Label { + Label { Layout.fillWidth: true elide: Text.ElideRight text: model.prettyName || model.name @@ -381,8 +368,8 @@ ProgressBar { Layout.fillWidth: true - minimumValue: 0 - maximumValue: 100 + from: 0 + to: 100 value: model.wakeUps / kcm.wakeUps.total * 100 } } @@ -402,22 +389,31 @@ ColumnLayout { id: detailsColumn - property int legendWidth: 10 Layout.fillWidth: true - spacing: 0 visible: !!currentBattery Repeater { + id: detailsrepeater model: root.details + property list layouts + + Kirigami.FormLayout { + id: currentLayout + Component.onCompleted: { + if (currentLayout.visible) { + // ensure that all visible FormLayout share the same set of twinFormLayouts + detailsrepeater.layouts.push(currentLayout); + for ( var i = 0, length = detailsrepeater.layouts.length; i < length; ++i) { + detailsrepeater.layouts[i].twinFormLayouts = detailsrepeater.layouts; + } + } + } - ColumnLayout { - spacing: 0//units.smallSpacing - - PlasmaExtras.Heading { - level: 4 - color: sysPal.text + Kirigami.Heading { text: modelData.title + Kirigami.FormData.isSection: true + level: 4 // HACK hide section header if all labels are invisible visible: { for (var i = 0, length = detailsRepeater.count; i < length; ++i) { @@ -435,58 +431,40 @@ id: detailsRepeater model: modelData.data || [] - RowLayout { - Layout.fillWidth: true - spacing: units.smallSpacing * 2 - visible: valueLabel.text !== "" - - QQC2.Label { - Layout.minimumWidth: detailsColumn.legendWidth + units.gridUnit - horizontalAlignment: Text.AlignRight - text: i18n("%1:", modelData.label) - wrapMode: Text.NoWrap - opacity: 0.8 - onPaintedWidthChanged: { - if (paintedWidth > detailsColumn.legendWidth) { - detailsColumn.legendWidth = paintedWidth - } - } - } - - QQC2.Label { - id: valueLabel - Layout.fillWidth: true - text: { - var value = currentBattery[modelData.value] - - if (typeof value === "boolean") { - if (value) { - return i18n("Yes") - } else { - return i18n("No") - } - } - - if (!value) { - return "" + Label { + id: valueLabel + Kirigami.FormData.label: i18n("%1:", modelData.label) + text: { + var value = currentBattery[modelData.value] + + if (typeof value === "boolean") { + if (value) { + return i18n("Yes") + } else { + return i18n("No") } + } - var precision = modelData.precision - if (typeof precision === "number") { // round to decimals - value = Number(value).toLocaleString(Qt.locale(), "f", precision) - } + if (!value) { + return "" + } - if (modelData.modifier && root["modifier_" + modelData.modifier]) { - value = root["modifier_" + modelData.modifier](value) - } + var precision = modelData.precision + if (typeof precision === "number") { // round to decimals + value = Number(value).toLocaleString(Qt.locale(), "f", precision) + } - if (modelData.unit) { - value = i18nc("%1 is value, %2 is unit", "%1 %2", value, modelData.unit) - } + if (modelData.modifier && root["modifier_" + modelData.modifier]) { + value = root["modifier_" + modelData.modifier](value) + } - return value + if (modelData.unit) { + value = i18nc("%1 is value, %2 is unit", "%1 %2", value, modelData.unit) } + + return value } + visible: valueLabel.text !== "" } } }