From 9c51fa02c4496d05b72b3866c1cab39d05a99cb4 Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Fri, 9 Sep 2022 21:25:05 +0800 Subject: [PATCH] applets/batterymonitor: scroll to item position when item gets focus --- .../package/contents/ui/PopupDialog.qml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/applets/batterymonitor/package/contents/ui/PopupDialog.qml b/applets/batterymonitor/package/contents/ui/PopupDialog.qml index 24650a577..27f9df95a 100644 --- a/applets/batterymonitor/package/contents/ui/PopupDialog.qml +++ b/applets/batterymonitor/package/contents/ui/PopupDialog.qml @@ -70,6 +70,13 @@ PlasmaExtras.Representation { // HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890 PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff + function scrollToY(yPos) { + if (!PlasmaComponents3.ScrollBar.vertical.visible) { + return; + } + PlasmaComponents3.ScrollBar.vertical.position = Math.min(1, Math.max(0, yPos / batteryList.implicitHeight)); + } + Column { id: batteryList @@ -114,6 +121,7 @@ PlasmaExtras.Representation { stepSize: batterymonitor.maximumScreenBrightness/100 onMoved: batterymonitor.screenBrightness = value + onActiveFocusChanged: if (activeFocus) scrollView.scrollToY(y) // Manually dragging the slider around breaks the binding Connections { @@ -142,6 +150,7 @@ PlasmaExtras.Representation { KeyNavigation.tab: KeyNavigation.down onMoved: batterymonitor.keyboardBrightness = value + onActiveFocusChanged: if (activeFocus) scrollView.scrollToY(y) // Manually dragging the slider around breaks the binding Connections { @@ -168,6 +177,8 @@ PlasmaExtras.Representation { degradationReason: dialog.degradationReason profileHolds: dialog.profileHolds onActivateProfileRequested: dialog.activateProfileRequested(profile) + + onActiveFocusChanged: if (activeFocus) scrollView.scrollToY(y) } Repeater { @@ -193,6 +204,8 @@ PlasmaExtras.Representation { event.accepted = false; } } + + onActiveFocusChanged: if (activeFocus) scrollView.scrollToY(y) } } }