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,10 @@ import org.kde.kcoreaddons 1.0 as KCoreAddons import "logic.js" as Logic -Item { +ColumnLayout { id: batteryItem - height: childrenRect.height + + spacing: 0 property var battery @@ -87,129 +88,114 @@ } } - Column { - width: parent.width + ColumnLayout { + Layout.alignment: batteryItem.isPresent ? Qt.AlignTop : Qt.AlignVCenter 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 - } - } + RowLayout { + width: batteryItem.width + + BatteryIcon { + id: batteryIcon + width: units.iconSizes.small + height: width + batteryType: model.Type + percent: model.Percent + hasBattery: batteryItem.isPresent + pluggedIn: model.State === "Charging" && model["Is Power Supply"] } - 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"] - } + PlasmaComponents.Label { + id: batteryNameLabel + Layout.fillWidth: true + height: implicitHeight + elide: Text.ElideRight + text: model["Pretty Name"] + } - Column { - Layout.fillWidth: true - Layout.alignment: batteryItem.isPresent ? Qt.AlignTop : Qt.AlignVCenter + PlasmaComponents.Label { + text: Logic.stringForBatteryState(model) + height: implicitHeight + visible: model["Is Power Supply"] + opacity: 0.6 + } - RowLayout { - width: parent.width - spacing: units.smallSpacing + PlasmaComponents.Label { + id: batteryPercent + height: paintedHeight + horizontalAlignment: Text.AlignRight + visible: batteryItem.isPresent + text: i18nc("Placeholder is battery percentage", "%1%", model.Percent) + } + } - PlasmaComponents.Label { - id: batteryNameLabel - Layout.fillWidth: true - height: implicitHeight - elide: Text.ElideRight - text: model["Pretty Name"] - } + PlasmaComponents.ProgressBar { + Layout.fillWidth: true + width: batteryItem.width + minimumValue: 0 + maximumValue: 100 + visible: batteryItem.isPresent + value: Number(model.Percent) + } + } - PlasmaComponents.Label { - text: Logic.stringForBatteryState(model) - height: implicitHeight - visible: model["Is Power Supply"] - opacity: 0.6 - } + PlasmaCore.ToolTipArea { + anchors.fill: parent + 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 + 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 + height: width + batteryType: batteryIcon.batteryType + percent: batteryIcon.percent + hasBattery: batteryIcon.hasBattery + pluggedIn: batteryIcon.pluggedIn + visible: !batteryItem.isBroken + } - PlasmaComponents.Label { - id: batteryPercent - height: paintedHeight - horizontalAlignment: Text.AlignRight - visible: batteryItem.isPresent - text: i18nc("Placeholder is battery percentage", "%1%", model.Percent) - } - } + Column { + id: mainColumn + x: batteryItemToolTip._s + y: batteryItemToolTip._s - PlasmaComponents.ProgressBar { - width: parent.width - minimumValue: 0 - maximumValue: 100 - visible: batteryItem.isPresent - value: Number(model.Percent) - } + PlasmaExtras.Heading { + level: 3 + text: batteryNameLabel.text + } + Loader { + sourceComponent: batteryItem.batteryDetails + opacity: 0.5 } } } + } - 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 + Loader { + id: detailsLoader + property bool inListView: true + anchors { + left: parent.left + 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.small + 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.small + 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,145 @@ signal powermanagementChanged(bool checked) - Column { + PlasmaCore.Svg { + id: lineSvg + imagePath: "widgets/line" + } + + 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 - } - - PowerManagementItem { - id: pmSwitch - width: parent.width - 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.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 + width: parent.width - units.smallSpacing * 2 + height: parent.height + spacing: units.smallSpacing + + PlasmaExtras.ScrollArea { + id: scrollView + Layout.fillWidth: true + Layout.fillHeight: true + flickableItem.boundsBehavior: Flickable.StopAtBounds; + activeFocusOnTab: false + + ColumnLayout { + width: scrollView.viewport.width + + InhibitionHint { + id: lidHint + Layout.leftMargin: units.iconSizes.small + 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.") + } + + InhibitionHint { + id: suppressHint + 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) + } + } else { + return "" + } + } + } + + PlasmaCore.SvgItem { + elementId: "horizontal-line" + Layout.fillWidth: true + visible: lidHint.visible || suppressHint.visible + svg: lineSvg + } + + BrightnessItem { + id: brightnessSlider + Layout.fillWidth: true + + 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 + Layout.fillWidth: true + + 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 + } + } + + Item { + implicitHeight:batteryList.height + ListView { + id: batteryList + height: 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 + PlasmaCore.SvgItem { + elementId: "horizontal-line" + Layout.fillWidth: true + Layout.leftMargin: -units.smallSpacing * 2.5 + Layout.rightMargin: Layout.leftMargin + svg: lineSvg } - width: parent.width - units.gridUnit - - ListView { - id: batteryList - - boundsBehavior: Flickable.StopAtBounds - spacing: Math.round(units.gridUnit / 2) + PowerManagementItem { + id: pmSwitch + Layout.fillWidth: true + onEnabledChanged: powermanagementChanged(enabled) KeyNavigation.tab: brightnessSlider - KeyNavigation.backtab: pmSwitch - - delegate: BatteryItem { - width: parent.width - battery: model - } + KeyNavigation.backtab: batteryList } } - } 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,103 +22,71 @@ 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 { +RowLayout { property alias enabled: pmCheckBox.checked spacing: 0 - RowLayout { - width: parent.width - spacing: units.gridUnit + ColumnLayout { MouseArea { - Layout.fillWidth: true + width: childrenRect.width height: childrenRect.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 - 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") } - } - } - - Components.ToolButton { - iconSource: "configure" - onClicked: batterymonitor.action_powerdevilkcm() - tooltip: i18n("Configure Power Saving...") - visible: batterymonitor.kcmsAuthorized - } - } - Column { - anchors { - left: parent.left - leftMargin: units.iconSizes.medium + units.gridUnit - right: parent.right - } - spacing: units.smallSpacing - - 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.") - } - - 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) + PlasmaCore.ToolTipArea { + anchors.fill: parent + subText: { + var mainMessage = i18n("Disabling power management will prevent your screen and computer from turning off automatically.") + if (lidHint.visible || suppressHint.visible) { + mainMessage += i18n("\n") + if (lidHint.visible) { + mainMessage += i18n("\n") + lidHint.text + } + if (suppressHint.visible) { + mainMessage += i18n("\n") + suppressHint.text + } + } else { + mainMessage += i18n("\n\nMost applications will automatically suppress power management when they don't want to have you interrupted.") + } + return mainMessage } - } else { - return "" } } } } + + Item { + Layout.fillWidth: true + } + + Components.ToolButton { + iconSource: "configure" + onClicked: batterymonitor.action_powerdevilkcm() + tooltip: i18n("Configure Power Saving...") + visible: batterymonitor.kcmsAuthorized + } } 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