diff --git a/Modules/energy/package/contents/ui/Graph.qml b/Modules/energy/package/contents/ui/Graph.qml --- a/Modules/energy/package/contents/ui/Graph.qml +++ b/Modules/energy/package/contents/ui/Graph.qml @@ -52,7 +52,7 @@ //internal - property real plotWidth: width - xPadding *2 + property real plotWidth: width - xPadding property real plotHeight: height - yPadding *2 onDataChanged: { 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,17 +17,15 @@ * 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.5 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 -//We need units from it import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.workspace.components 2.0 as WorkspaceComponents @@ -44,8 +42,6 @@ } } - SystemPalette { id: sysPal; colorGroup: SystemPalette.Active } - property bool showWakeUps: true property int historyType: HistoryModel.ChargeType @@ -104,44 +100,33 @@ currentUdi = kcm.batteries.udi(0) } - implicitWidth: units.gridUnit * 25 - implicitHeight: !!currentBattery ? units.gridUnit * 25 : units.gridUnit * 12 + implicitWidth: units.gridUnit * 30 + implicitHeight: !!currentBattery ? units.gridUnit * 30 : 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 { id: tabView Layout.fillWidth: true Layout.minimumHeight: units.gridUnit * 3 Layout.maximumHeight: Layout.minimumHeight - - frameVisible: true visible: kcm.batteries.count > 1 - verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff - Row { + spacing: Kirigami.Units.smallSpacing 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 +169,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 +217,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,14 +267,10 @@ visible: history.count > 1 } - QQC2.Label { + Kirigami.InlineMessage { Layout.fillWidth: true - Layout.minimumHeight: column.width / 3 - Layout.maximumHeight: column.width / 3 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter + showCloseButton: true text: i18n("This type of history is currently not available for this device.") - wrapMode: Text.WordWrap visible: !graph.visible } } @@ -305,10 +282,9 @@ RowLayout { Layout.fillWidth: true - PlasmaExtras.Heading { + Kirigami.Heading { Layout.fillWidth: true Layout.columnSpan: 2 - color: sysPal.text level: 4 text: i18n("Application Energy Consumption") } @@ -366,7 +342,7 @@ RowLayout { Layout.fillWidth: true - QQC2.Label { + Label { Layout.fillWidth: true elide: Text.ElideRight text: model.prettyName || model.name @@ -381,8 +357,8 @@ ProgressBar { Layout.fillWidth: true - minimumValue: 0 - maximumValue: 100 + from: 0 + to: 100 value: model.wakeUps / kcm.wakeUps.total * 100 } } @@ -395,29 +371,37 @@ Rectangle { Layout.fillWidth: true height: 1 - color: "#ccc" // FIXME palette + color: Kirigami.Theme.textColor // FIXME palette //Layout.topMargin: (compact ? units.gridUnit * 2 : 0) visible: wakeUpsGrid.visible } ColumnLayout { id: detailsColumn - property int legendWidth: 10 Layout.fillWidth: true - spacing: 0 visible: !!currentBattery Repeater { + id: titleRepeater model: root.details + property list layouts + + delegate: Kirigami.FormLayout { + id: currentLayout - ColumnLayout { - spacing: 0//units.smallSpacing + Component.onCompleted: { + // ensure that all visible FormLayout share the same set of twinFormLayouts + titleRepeater.layouts.push(currentLayout); + for (var i = 0, length = titleRepeater.layouts.length; i < length; ++i) { + titleRepeater.layouts[i].twinFormLayouts = titleRepeater.layouts; + } + } - PlasmaExtras.Heading { - level: 4 - color: sysPal.text + Kirigami.Heading { text: modelData.title + Kirigami.FormData.isSection: true + level: 2 // HACK hide section header if all labels are invisible visible: { for (var i = 0, length = detailsRepeater.count; i < length; ++i) { @@ -435,63 +419,46 @@ 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 !== "" } } } } } } + } }