diff --git a/applets/batterymonitor/package/contents/ui/BatteryItem.qml b/applets/batterymonitor/package/contents/ui/BatteryItem.qml --- a/applets/batterymonitor/package/contents/ui/BatteryItem.qml +++ b/applets/batterymonitor/package/contents/ui/BatteryItem.qml @@ -28,9 +28,8 @@ import org.kde.kcoreaddons 1.0 as KCoreAddons import "logic.js" as Logic -Item { +ColumnLayout { id: batteryItem - height: childrenRect.height property var battery @@ -40,176 +39,93 @@ readonly property bool isBroken: model.Capacity > 0 && model.Capacity < 50 - property Component batteryDetails: Flow { // GridLayout crashes with a Repeater in it somehow - id: detailsLayout + ColumnLayout { + spacing: 0 - property int leftColumnWidth: 0 - width: units.gridUnit * 11 + RowLayout { - PlasmaComponents.Label { - id: brokenBatteryLabel - width: parent ? parent.width : implicitWidth - wrapMode: Text.WordWrap - text: batteryItem.isBroken && typeof model.Capacity !== "undefined" ? i18n("This battery's health is at only %1% and should be replaced. Please contact your hardware vendor for more details.", model.Capacity) : "" - font.pointSize: !!detailsLayout.parent.inListView ? theme.smallestFont.pointSize : theme.defaultFont.pointSize - visible: batteryItem.isBroken - } - - Repeater { - id: detailsRepeater - model: Logic.batteryDetails(batteryItem.battery, batterymonitor.remainingTime) + BatteryIcon { + id: batteryIcon + Layout.preferredWidth: units.iconSizes.smallMedium + Layout.preferredHeight: Layout.preferredWidth + batteryType: model.Type + percent: model.Percent + hasBattery: batteryItem.isPresent + pluggedIn: model.State === "Charging" && model["Is Power Supply"] + } PlasmaComponents.Label { - id: detailsLabel - width: modelData.value && parent ? parent.width - detailsLayout.leftColumnWidth - units.smallSpacing : detailsLayout.leftColumnWidth + units.smallSpacing - wrapMode: Text.NoWrap - onPaintedWidthChanged: { // horrible HACK to get a column layout - if (paintedWidth > detailsLayout.leftColumnWidth) { - detailsLayout.leftColumnWidth = paintedWidth - } - } - height: implicitHeight - text: modelData.value ? modelData.value : modelData.label - - states: [ - State { - when: !!detailsLayout.parent.inListView // HACK - PropertyChanges { - target: detailsLabel - horizontalAlignment: modelData.value ? Text.AlignRight : Text.AlignLeft - font.pointSize: theme.smallestFont.pointSize - width: parent ? parent.width / 2 : 0 - elide: Text.ElideNone // eliding and height: implicitHeight causes loops - } - } - ] + id: batteryNameLabel + Layout.fillWidth: true + elide: Text.ElideRight + text: model["Pretty Name"] } - } - } - - Column { - width: parent.width - spacing: 0 - PlasmaCore.ToolTipArea { - width: parent.width - height: infoRow.height - active: !detailsLoader.active - z: 2 - - mainItem: Row { - id: batteryItemToolTip - - property int _s: units.largeSpacing / 2 - - Layout.minimumWidth: implicitWidth + batteryItemToolTip._s - Layout.minimumHeight: implicitHeight + batteryItemToolTip._s * 2 - Layout.maximumWidth: implicitWidth + batteryItemToolTip._s - Layout.maximumHeight: implicitHeight + batteryItemToolTip._s * 2 - width: implicitWidth + batteryItemToolTip._s - height: implicitHeight + batteryItemToolTip._s * 2 - - spacing: batteryItemToolTip._s*2 - - BatteryIcon { - x: batteryItemToolTip._s * 2 - y: batteryItemToolTip._s - width: units.iconSizes.desktop // looks weird and small but that's what DefaultTooltip uses - height: width - batteryType: batteryIcon.batteryType - percent: batteryIcon.percent - hasBattery: batteryIcon.hasBattery - pluggedIn: batteryIcon.pluggedIn - visible: !batteryItem.isBroken - } - - Column { - id: mainColumn - x: batteryItemToolTip._s - y: batteryItemToolTip._s - - PlasmaExtras.Heading { - level: 3 - text: batteryNameLabel.text - } - Loader { - sourceComponent: batteryItem.batteryDetails - opacity: 0.5 - } - } + PlasmaComponents.Label { + text: Logic.stringForBatteryState(model) + visible: model["Is Power Supply"] + opacity: 0.6 } - RowLayout { - id: infoRow - width: parent.width - spacing: units.gridUnit - - BatteryIcon { - id: batteryIcon - Layout.alignment: Qt.AlignTop - width: units.iconSizes.medium - height: width - batteryType: model.Type - percent: model.Percent - hasBattery: batteryItem.isPresent - pluggedIn: model.State === "Charging" && model["Is Power Supply"] - } - - Column { - Layout.fillWidth: true - Layout.alignment: batteryItem.isPresent ? Qt.AlignTop : Qt.AlignVCenter + PlasmaComponents.Label { + id: batteryPercent + horizontalAlignment: Text.AlignRight + visible: batteryItem.isPresent + text: i18nc("Placeholder is battery percentage", "%1%", model.Percent) + } + } - RowLayout { - width: parent.width - spacing: units.smallSpacing + PlasmaComponents.ProgressBar { + Layout.fillWidth: true + minimumValue: 0 + maximumValue: 100 + visible: batteryItem.isPresent + value: Number(model.Percent) + } - PlasmaComponents.Label { - id: batteryNameLabel - Layout.fillWidth: true - height: implicitHeight - elide: Text.ElideRight - text: model["Pretty Name"] - } + PlasmaComponents.Label { + id: brokenBatteryLabel + Layout.fillWidth: true + wrapMode: Text.WordWrap + text: batteryItem.isBroken && typeof model.Capacity !== "undefined" ? i18n("This battery's health is at only %1% and should be replaced. Please contact your hardware vendor for more details.", model.Capacity) : "This battery's health is low and should be replaced. Please contact your hardware vendor for more details." + font.pointSize: theme.smallestFont.pointSize + maximumLineCount: 3 + visible: batteryItem.isBroken + } - PlasmaComponents.Label { - text: Logic.stringForBatteryState(model) - height: implicitHeight - visible: model["Is Power Supply"] - opacity: 0.6 + Flow { // GridLayout crashes with a Repeater in it somehow + id: detailsLayout + + property int leftColumnWidth: 0 + property int rightColumnWidth: 0 + spacing: units.smallSpacing + Layout.preferredWidth: leftColumnWidth + spacing + rightColumnWidth + Layout.alignment: Qt.AlignRight + + Repeater { + id: detailsRepeater + model: Logic.batteryDetails(batteryItem.battery, batterymonitor.remainingTime) + + PlasmaComponents.Label { + id: detailsLabel + height: implicitHeight + width: modelData.label ? detailsLayout.leftColumnWidth : detailsLayout.rightColumnWidth + wrapMode: Text.NoWrap + text: modelData.value ? modelData.value : modelData.label + elide: Text.ElideNone // eliding and height: implicitHeight causes loops + horizontalAlignment: Text.AlignRight + opacity: modelData.label ? 0.6 : 1 + + onPaintedWidthChanged: { // horrible HACK to get a column layout + if (modelData.label && paintedWidth > detailsLayout.leftColumnWidth) { + detailsLayout.leftColumnWidth = Math.ceil(paintedWidth) } - - PlasmaComponents.Label { - id: batteryPercent - height: paintedHeight - horizontalAlignment: Text.AlignRight - visible: batteryItem.isPresent - text: i18nc("Placeholder is battery percentage", "%1%", model.Percent) + if (modelData.value && paintedWidth > detailsLayout.rightColumnWidth) { + detailsLayout.rightColumnWidth = Math.ceil(paintedWidth) } } - - PlasmaComponents.ProgressBar { - width: parent.width - minimumValue: 0 - maximumValue: 100 - visible: batteryItem.isPresent - value: Number(model.Percent) - } } } } - - Loader { - id: detailsLoader - property bool inListView: true - anchors { - left: parent.left - leftMargin: batteryIcon.width + units.gridUnit - right: parent.right - } - visible: !!item - opacity: 0.5 - sourceComponent: batteryDetails - } } - } diff --git a/applets/batterymonitor/package/contents/ui/BrightnessItem.qml b/applets/batterymonitor/package/contents/ui/BrightnessItem.qml --- a/applets/batterymonitor/package/contents/ui/BrightnessItem.qml +++ b/applets/batterymonitor/package/contents/ui/BrightnessItem.qml @@ -25,44 +25,37 @@ import org.kde.plasma.components 2.0 as Components import org.kde.plasma.components 3.0 as Components3 -RowLayout { +ColumnLayout { id: item property alias icon: brightnessIcon.source property alias label: brightnessLabel.text property alias value: brightnessSlider.value property alias maximumValue: brightnessSlider.to property alias stepSize: brightnessSlider.stepSize signal moved() - spacing: units.gridUnit + spacing: 0 - PlasmaCore.IconItem { - id: brightnessIcon - Layout.alignment: Qt.AlignTop - Layout.preferredWidth: units.iconSizes.medium - Layout.preferredHeight: width - } - - Column { - id: brightnessColumn - Layout.fillWidth: true - Layout.alignment: Qt.AlignTop - spacing: 0 + RowLayout { + PlasmaCore.IconItem { + id: brightnessIcon + Layout.preferredHeight: units.iconSizes.smallMedium + Layout.preferredWidth: Layout.preferredHeight + } Components.Label { id: brightnessLabel - width: parent.width - height: paintedHeight } + } - Components3.Slider { - id: brightnessSlider - width: parent.width - // Don't allow the slider to turn off the screen - // Please see https://git.reviewboard.kde.org/r/122505/ for more information - from: to > 100 ? 1 : 0 - stepSize: 1 - onMoved: item.moved() - } + Components3.Slider { + id: brightnessSlider + Layout.fillWidth: true + + // Don't allow the slider to turn off the screen + // Please see https://git.reviewboard.kde.org/r/122505/ for more information + from: to > 100 ? 1 : 0 + stepSize: 1 + onMoved: item.moved() } } diff --git a/applets/batterymonitor/package/contents/ui/InhibitionHint.qml b/applets/batterymonitor/package/contents/ui/InhibitionHint.qml --- a/applets/batterymonitor/package/contents/ui/InhibitionHint.qml +++ b/applets/batterymonitor/package/contents/ui/InhibitionHint.qml @@ -30,8 +30,8 @@ PlasmaCore.IconItem { id: iconItem - Layout.preferredWidth: units.iconSizes.medium - Layout.preferredHeight: units.iconSizes.medium + Layout.preferredWidth: units.iconSizes.smallMedium + Layout.preferredHeight: Layout.preferredWidth visible: valid } @@ -43,5 +43,6 @@ wrapMode: Text.WordWrap elide: Text.ElideRight maximumLineCount: 3 + opacity: 0.6 } } diff --git a/applets/batterymonitor/package/contents/ui/PopupDialog.qml b/applets/batterymonitor/package/contents/ui/PopupDialog.qml --- a/applets/batterymonitor/package/contents/ui/PopupDialog.qml +++ b/applets/batterymonitor/package/contents/ui/PopupDialog.qml @@ -18,9 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.0 +import QtQuick 2.2 +import QtQuick.Layouts 1.0 + import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as Components +import org.kde.plasma.components 3.0 as Components3 import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.kquickcontrolsaddons 2.0 @@ -38,94 +41,88 @@ signal powermanagementChanged(bool checked) - Column { + ColumnLayout { id: settingsColumn anchors.horizontalCenter: parent.horizontalCenter - width: parent.width - units.gridUnit - spacing: Math.round(units.gridUnit / 2) - - Components.Label { - // this is just for metrics, TODO use TextMetrics in 5.4 instead - id: percentageMeasurementLabel - text: i18nc("Used for measurement", "100%") - visible: false - } + width: parent.width - units.smallSpacing * 2 + height: parent.height + spacing: units.smallSpacing PowerManagementItem { id: pmSwitch - width: parent.width + Layout.fillWidth: true onEnabledChanged: powermanagementChanged(enabled) - KeyNavigation.tab: batteryList - KeyNavigation.backtab: keyboardBrightnessSlider - } - - BrightnessItem { - id: brightnessSlider - width: parent.width - - icon: "video-display-brightness" - label: i18n("Display Brightness") - visible: isBrightnessAvailable - value: batterymonitor.screenBrightness - maximumValue: batterymonitor.maximumScreenBrightness - KeyNavigation.tab: keyboardBrightnessSlider + KeyNavigation.tab: brightnessSlider KeyNavigation.backtab: batteryList - stepSize: batterymonitor.maximumScreenBrightness/100 - - onMoved: batterymonitor.screenBrightness = value - - // Manually dragging the slider around breaks the binding - Connections { - target: batterymonitor - onScreenBrightnessChanged: brightnessSlider.value = batterymonitor.screenBrightness - } } - BrightnessItem { - id: keyboardBrightnessSlider - width: parent.width - - icon: "input-keyboard-brightness" - label: i18n("Keyboard Brightness") - value: batterymonitor.keyboardBrightness - maximumValue: batterymonitor.maximumKeyboardBrightness - visible: isKeyboardBrightnessAvailable - KeyNavigation.tab: pmSwitch - KeyNavigation.backtab: brightnessSlider - - onMoved: batterymonitor.keyboardBrightness = value - - // Manually dragging the slider around breaks the binding - Connections { - target: batterymonitor - onKeyboardBrightnessChanged: keyboardBrightnessSlider.value = batterymonitor.keyboardBrightness + PlasmaExtras.ScrollArea { + id: scrollView + Layout.fillWidth: true + Layout.fillHeight: true + flickableItem.boundsBehavior: Flickable.StopAtBounds; + activeFocusOnTab: false + + ColumnLayout { + width: scrollView.viewport.width + + BrightnessItem { + id: brightnessSlider + + icon: "video-display-brightness" + label: i18n("Display Brightness") + visible: isBrightnessAvailable + value: batterymonitor.screenBrightness + maximumValue: batterymonitor.maximumScreenBrightness + KeyNavigation.tab: keyboardBrightnessSlider + KeyNavigation.backtab: pmSwitch + stepSize: batterymonitor.maximumScreenBrightness/100 + + onMoved: batterymonitor.screenBrightness = value + + // Manually dragging the slider around breaks the binding + Connections { + target: batterymonitor + onScreenBrightnessChanged: brightnessSlider.value = batterymonitor.screenBrightness + } + } + + BrightnessItem { + id: keyboardBrightnessSlider + + icon: "input-keyboard-brightness" + label: i18n("Keyboard Brightness") + value: batterymonitor.keyboardBrightness + maximumValue: batterymonitor.maximumKeyboardBrightness + visible: isKeyboardBrightnessAvailable + KeyNavigation.tab: batteryList + KeyNavigation.backtab: brightnessSlider + + onMoved: batterymonitor.keyboardBrightness = value + + // Manually dragging the slider around breaks the binding + Connections { + target: batterymonitor + onKeyboardBrightnessChanged: keyboardBrightnessSlider.value = batterymonitor.keyboardBrightness + } + } + + ListView { + id: batteryList + Layout.preferredHeight: childrenRect.height + + boundsBehavior: Flickable.StopAtBounds + spacing: Math.round(units.gridUnit / 2) + + KeyNavigation.tab: pmSwitch + KeyNavigation.backtab: keyboardBrightnessSlider + + delegate: BatteryItem { + width: scrollView.viewport.width + battery: model + } + } } } } - - PlasmaExtras.ScrollArea { - anchors { - horizontalCenter: parent.horizontalCenter - top: settingsColumn.bottom - topMargin: units.gridUnit // not divided by 2 for unified looks - bottom: dialog.bottom - } - width: parent.width - units.gridUnit - - ListView { - id: batteryList - - boundsBehavior: Flickable.StopAtBounds - spacing: Math.round(units.gridUnit / 2) - - KeyNavigation.tab: brightnessSlider - KeyNavigation.backtab: pmSwitch - - delegate: BatteryItem { - width: parent.width - battery: model - } - } - } - } diff --git a/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml b/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml --- a/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml +++ b/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml @@ -22,55 +22,50 @@ import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as Components +import org.kde.plasma.components 3.0 as Components3 import org.kde.kquickcontrolsaddons 2.0 - -Column { - property alias enabled: pmCheckBox.checked - - spacing: 0 +ColumnLayout{ + spacing: units.smallSpacing RowLayout { - width: parent.width - spacing: units.gridUnit + property alias enabled: pmCheckBox.checked + + spacing: 0 MouseArea { - Layout.fillWidth: true - height: childrenRect.height + Layout.preferredWidth: pmRow.width + Layout.preferredHeight: pmRow.height onClicked: { pmCheckBox.forceActiveFocus() pmCheckBox.checked = !pmCheckBox.checked } - PlasmaCore.ToolTipArea { - anchors.fill: parent - subText: i18n("Disabling power management will prevent your screen and computer from turning off automatically.\n\nMost applications will automatically suppress power management when they don't want to have you interrupted.") - } - RowLayout { - width: parent.width - spacing: units.gridUnit - - Item { - width: units.iconSizes.medium - height: width + id: pmRow - Components.CheckBox { - id: pmCheckBox - anchors.centerIn: parent - checked: true - // we don't want to mess with the checked state but still reflect that changing it might not yield the desired result - opacity: inhibitions.length > 0 ? 0.5 : 1 - Behavior on opacity { - NumberAnimation { duration: units.longDuration } - } + Components3.CheckBox { + id: pmCheckBox + checked: true + // we don't want to mess with the checked state but still reflect that changing it might not yield the desired result + opacity: inhibitions.length > 0 ? 0.5 : 1 + Behavior on opacity { + NumberAnimation { duration: units.longDuration } } } Components.Label { - Layout.fillWidth: true - text: i18n("Enable Power Management") + text: i18n("Enable power management") } } + + PlasmaCore.ToolTipArea { + anchors.fill: parent + subText: i18n("Disabling power management will prevent your screen and computer from turning off automatically.\n\nMost applications will automatically suppress power management when they don't want to have you interrupted") + } + } + + Item { + Layout.fillWidth: true } Components.ToolButton { @@ -81,44 +76,47 @@ } } - Column { - anchors { - left: parent.left - leftMargin: units.iconSizes.medium + units.gridUnit - right: parent.right - } - spacing: units.smallSpacing + PlasmaCore.Svg { + id: lineSvg + imagePath: "widgets/line" + } - InhibitionHint { - width: parent.width - visible: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Is Lid Present"] && !pmSource.data["PowerDevil"]["Triggers Lid Action"] ? true : false - iconSource: "computer-laptop" - text: i18n("Your notebook is configured not to suspend when closing the lid while an external monitor is connected.") - } + PlasmaCore.SvgItem { + elementId: "horizontal-line" + Layout.fillWidth: true + Layout.leftMargin: -units.smallSpacing * 2.5 + Layout.rightMargin: Layout.leftMargin + svg: lineSvg + } - InhibitionHint { - width: parent.width - visible: inhibitions.length > 0 - iconSource: inhibitions.length > 0 ? inhibitions[0].Icon || "" : "" - text: { - if (inhibitions.length > 1) { - return i18ncp("Some Application and n others are currently suppressing PM", - "%2 and %1 other application are currently suppressing power management.", - "%2 and %1 other applications are currently suppressing power management.", - inhibitions.length - 1, inhibitions[0].Name) // plural only works on %1 - } else if (inhibitions.length === 1) { - if (!inhibitions[0].Reason) { - return i18nc("Some Application is suppressing PM", - "%1 is currently suppressing power management.", inhibitions[0].Name) - } else { - return i18nc("Some Application is suppressing PM: Reason provided by the app", - "%1 is currently suppressing power management: %2", inhibitions[0].Name, inhibitions[0].Reason) - } + InhibitionHint { + id: lidHint + visible: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Is Lid Present"] && !pmSource.data["PowerDevil"]["Triggers Lid Action"] && pmSwitch.enabled + iconSource: "computer-laptop" + text: i18n("Your notebook is configured not to suspend when closing the lid while an external monitor is connected.") + } + + InhibitionHint { + id: suppressHint + visible: inhibitions.length > 0 && pmSwitch.enabled + iconSource: inhibitions.length > 0 ? inhibitions[0].Icon || "" : "" + text: { + if (inhibitions.length > 1) { + return i18ncp("Some Application and n others are currently suppressing PM", + "%2 and %1 other application are currently suppressing power management.", + "%2 and %1 other applications are currently suppressing power management.", + inhibitions.length - 1, inhibitions[0].Name) // plural only works on %1 + } else if (inhibitions.length === 1) { + if (!inhibitions[0].Reason) { + return i18nc("Some Application is suppressing PM", + "%1 is currently suppressing power management.", inhibitions[0].Name) } else { - return "" + return i18nc("Some Application is suppressing PM: Reason provided by the app", + "%1 is currently suppressing power management: %2", inhibitions[0].Name, inhibitions[0].Reason) } + } else { + return "" } } } } - diff --git a/applets/batterymonitor/package/contents/ui/batterymonitor.qml b/applets/batterymonitor/package/contents/ui/batterymonitor.qml --- a/applets/batterymonitor/package/contents/ui/batterymonitor.qml +++ b/applets/batterymonitor/package/contents/ui/batterymonitor.qml @@ -29,8 +29,8 @@ Item { id: batterymonitor - Plasmoid.switchWidth: units.gridUnit * 10 - Plasmoid.switchHeight: units.gridUnit * 10 + Plasmoid.switchWidth: units.gridUnit * 13 + Plasmoid.switchHeight: units.gridUnit * 5 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.childrenInherit: true @@ -205,9 +205,10 @@ Plasmoid.fullRepresentation: PopupDialog { id: dialogItem - Layout.minimumWidth: units.iconSizes.medium * 9 - Layout.minimumHeight: units.gridUnit * 15 - // TODO Probably needs a sensible preferredHeight too + Layout.minimumWidth: Plasmoid.switchWidth + Layout.minimumHeight: Plasmoid.switchHeight + Layout.preferredWidth: Layout.minimumWidth * 1.5 + Layout.preferredHeight: Layout.minimumHeight * 4 model: plasmoid.expanded ? batteries : null anchors.fill: parent diff --git a/applets/batterymonitor/package/contents/ui/logic.js b/applets/batterymonitor/package/contents/ui/logic.js --- a/applets/batterymonitor/package/contents/ui/logic.js +++ b/applets/batterymonitor/package/contents/ui/logic.js @@ -37,12 +37,12 @@ var data = [] if (remainingTime > 0 && batteryData["Is Power Supply"] && (batteryData["State"] == "Discharging" || batteryData["State"] == "Charging")) { - data.push({label: (batteryData["State"] == "Charging" ? i18n("Time To Full:") : i18n("Time To Empty:")) }) + data.push({label: (batteryData["State"] == "Charging" ? i18n("Time to full:") : i18n("Time to empty:")) }) data.push({value: KCoreAddons.Format.formatDuration(remainingTime, KCoreAddons.FormatTypes.HideSeconds) }) } if (batteryData["Is Power Supply"] && batteryData["Capacity"] != "" && typeof batteryData["Capacity"] == "number") { - data.push({label: i18n("Battery Health:") }) + data.push({label: i18n("Battery health:") }) data.push({value: i18nc("Placeholder is battery health percentage", "%1%", batteryData["Capacity"]) }) }