[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kde-workspace] plasma/generic/applets/batterymonitor/contents/ui: Implement keyboard navigation for
From:       Kai Uwe Broulik <kde () privat ! broulik ! de>
Date:       2013-07-09 14:37:49
Message-ID: E1UwZ37-000612-Tx () scm ! kde ! org
[Download RAW message or body]

Git commit 4b9bd0663b5230f48c1fbcb44cef11242e384c5c by Kai Uwe Broulik.
Committed on 09/07/2013 at 14:34.
Pushed by broulik into branch 'master'.

Implement keyboard navigation for battery monitor

When opening the popup the brightness slider has focus so you can immediately adjust \
brightness using left/right arrow keys. Tab moves you to the keyboard brightness \
slider, then to the PM checkbox which you can toggle using Return/Space, then to the \
battery list through which you navigate using arrow up/down and expand/collapse using \
Return/Space/Arrow left/right.

FIXED-IN: 4.10.95
BUG: 228486

M  +6    -12   plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml
M  +2    -1    plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml
M  +48   -3    plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml
M  +2    -1    plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml
 M  +6    -1    plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml

http://commits.kde.org/kde-workspace/4b9bd0663b5230f48c1fbcb44cef11242e384c5c

diff --git a/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml \
b/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml index \
                3eb250c..a99eece 100644
--- a/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml
+++ b/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml
@@ -34,7 +34,6 @@ Item {
 
     Behavior on height { PropertyAnimation {} }
 
-    property bool highlight
     property bool expanded
     property bool showChargeAnimation
 
@@ -47,13 +46,14 @@ Item {
     KLocale.Locale { id: locale }
 
     function updateSelection() {
+        var hasFocus = batteryList.activeFocus && batteryList.activeIndex == index;
         var containsMouse = mouseArea.containsMouse;
 
-        if (highlight || expanded && containsMouse) {
+        if (expanded && (hasFocus || containsMouse)) {
             padding.opacity = 1;
         } else if (expanded) {
             padding.opacity = 0.8;
-        } else if (containsMouse) {
+        } else if (hasFocus || containsMouse) {
             padding.opacity = 0.65;
         } else {
             padding.opacity = 0;
@@ -69,21 +69,15 @@ Item {
         anchors.fill: parent
     }
 
+    onExpandedChanged: updateSelection()
+
     MouseArea {
         id: mouseArea
         anchors.fill: parent
         hoverEnabled: true
         onEntered: updateSelection()
         onExited: updateSelection()
-        onClicked: {
-            if (expanded) {
-                expanded = false;
-            } else {
-                expanded = true;
-                batteryItem.forceActiveFocus();
-            }
-            updateSelection();
-        }
+        onClicked: expanded = !expanded
     }
 
     Item {
diff --git a/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml \
b/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml index \
                06d7148..72b04a7 100644
--- a/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml
+++ b/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml
@@ -23,7 +23,7 @@ import org.kde.plasma.core 0.1 as PlasmaCore
 import org.kde.plasma.components 0.1 as Components
 import org.kde.qtextracomponents 0.1
 
-Item {
+FocusScope {
     id: brightnessItem
     clip: true
     width: parent.width
@@ -73,6 +73,7 @@ Item {
         minimumValue: 0
         maximumValue: 100
         stepSize: 10
+        focus: true
         onValueChanged: changed(value)
     }
 
diff --git a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml \
b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml index \
                edada37..f4ce3a8 100644
--- a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml
+++ b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml
@@ -24,9 +24,10 @@ import org.kde.plasma.components 0.1 as Components
 import org.kde.qtextracomponents 0.1
 import "plasmapackage:/code/logic.js" as Logic
 
-Item {
+FocusScope {
     id: dialog
     property int actualHeight: batteryColumn.implicitHeight + settingsColumn.height \
+ separator.height + 10 // 10 = separator margins +    focus: true
 
     property alias model: batteryList.model
     property bool pluggedIn
@@ -68,7 +69,45 @@ Item {
 
         Repeater {
             id: batteryList
-            delegate: BatteryItem { showChargeAnimation: popupShown }
+
+            property int activeIndex
+
+            delegate: BatteryItem {
+                showChargeAnimation: popupShown
+            }
+            KeyNavigation.tab: brightnessSlider
+            KeyNavigation.backtab: pmSwitch
+
+            function updateSelection(old,active) {
+                itemAt(old).updateSelection();
+                itemAt(active).updateSelection();
+            }
+
+            onFocusChanged: {
+                oldIndex = activeIndex;
+                activeIndex = 0;
+                updateSelection(oldIndex,activeIndex);
+            }
+            Keys.onDownPressed: {
+                oldIndex = activeIndex;
+                activeIndex++;
+                if (activeIndex >= model.count) {
+                    activeIndex = 0;
+                }
+                updateSelection(oldIndex,activeIndex);
+            }
+            Keys.onUpPressed: {
+                oldIndex = activeIndex;
+                activeIndex--;
+                if (activeIndex < 0) {
+                    activeIndex = model.count-1;
+                }
+                updateSelection(oldIndex,activeIndex);
+            }
+            Keys.onReturnPressed: itemAt(activeIndex).expanded = \
!itemAt(activeIndex).expanded +            Keys.onSpacePressed: \
itemAt(activeIndex).expanded = !itemAt(activeIndex).expanded +            \
Keys.onLeftPressed: itemAt(activeIndex).expanded = false +            \
Keys.onRightPressed: itemAt(activeIndex).expanded = true  }
     }
 
@@ -90,7 +129,9 @@ Item {
             label: i18n("Display Brightness")
             visible: isBrightnessAvailable
             onChanged: brightnessChanged(value)
-
+            KeyNavigation.tab: keyboardBrightnessSlider
+            KeyNavigation.backtab: batteryList
+            focus: true
         }
 
         BrightnessItem {
@@ -99,11 +140,15 @@ Item {
             label: i18n("Keyboard Brightness")
             visible: isKeyboardBrightnessAvailable
             onChanged: keyboardBrightnessChanged(value)
+            KeyNavigation.tab: pmSwitch
+            KeyNavigation.backtab: brightnessSlider
         }
 
         PowerManagementItem {
             id: pmSwitch
             onEnabledChanged: powermanagementChanged(enabled)
+            KeyNavigation.tab: batteryList
+            KeyNavigation.backtab: keyboardBrightnessSlider
         }
     }
 
diff --git a/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml \
b/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml index \
                85555ac..1f494d7 100644
--- a/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml
+++ b/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml
@@ -23,7 +23,7 @@ import org.kde.plasma.core 0.1 as PlasmaCore
 import org.kde.plasma.components 0.1 as Components
 import org.kde.qtextracomponents 0.1
 
-Item {
+FocusScope {
     id: brightnessItem
     clip: true
     width: parent.width
@@ -40,6 +40,7 @@ Item {
             topMargin: padding.margins.top
             bottomMargin: padding.margins.bottom
         }
+        focus: true
         checked: true
     }
 
diff --git a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml \
b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml index \
                75db982..cddd38e 100644
--- a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml
+++ b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml
@@ -53,6 +53,9 @@ Item {
 
     function popupEventSlot(popped) {
         dialogItem.popupShown = popped;
+        if (popped) {
+            dialogItem.forceActiveFocus();
+        }
     }
 
     property Component compactRepresentation: CompactRepresentation {
@@ -109,9 +112,11 @@ Item {
 
     PopupDialog {
         id: dialogItem
-        property bool disableBrightnessUpdate: false
         model: batteries
         anchors.fill: parent
+        focus: true
+
+        property bool disableBrightnessUpdate: false
 
         isBrightnessAvailable: pmSource.data["PowerDevil"]["Screen Brightness \
                Available"] ? true : false
         isKeyboardBrightnessAvailable: pmSource.data["PowerDevil"]["Keyboard \
Brightness Available"] ? true : false


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic