[vlc-commits] qml: allow to set a default navigation target in NavigableFocusScope

Pierre Lamot git at videolan.org
Mon Oct 14 11:59:15 CEST 2019


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Mon Sep 23 10:19:59 2019 +0200| [f68e27b2e692a00b644760ad85545c86a51372d8] | committer: Jean-Baptiste Kempf

qml: allow to set a default navigation target in NavigableFocusScope

  this is the most common action, and allow node traversal like KeyNavigation

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f68e27b2e692a00b644760ad85545c86a51372d8
---

 modules/gui/qt/qml/utils/NavigableFocusScope.qml | 59 ++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt/qml/utils/NavigableFocusScope.qml b/modules/gui/qt/qml/utils/NavigableFocusScope.qml
index 308d3870c5..f24743becf 100644
--- a/modules/gui/qt/qml/utils/NavigableFocusScope.qml
+++ b/modules/gui/qt/qml/utils/NavigableFocusScope.qml
@@ -33,6 +33,8 @@ FocusScope {
     signal actionRight( int index )
     signal actionCancel( int index )
 
+    property bool navigable: true
+
     property var navigationParent: undefined
     property var navigationUp: defaultNavigationUp
     property var navigationDown: defaultNavigationDown
@@ -40,8 +42,23 @@ FocusScope {
     property var navigationRight: defaultNavigationRight
     property var navigationCancel: defaultNavigationCancel
 
+    property var navigationUpItem: undefined
+    property var navigationDownItem: undefined
+    property var navigationLeftItem: undefined
+    property var navigationRightItem: undefined
+    property var navigationCancelItem: undefined
+
+
     function defaultNavigationUp(index) {
-        if (navigationParent) {
+        if (navigationUpItem) {
+            var item = navigationUpItem
+            while (item && (!item.visible || !item.enabled || !(item.navigable === undefined || item.navigable))) {
+                item = item.navigationUpItem
+            }
+            if (item) {
+                item.forceActiveFocus()
+            }
+        } else if (navigationParent) {
             navigationParent.navigationUp(index)
         } else {
             actionUp(index)
@@ -49,7 +66,15 @@ FocusScope {
     }
 
     function defaultNavigationDown(index) {
-        if (navigationParent) {
+        if (navigationDownItem) {
+            var item = navigationDownItem
+            while (item && (!item.visible || !item.enabled || !(item.navigable === undefined || item.navigable))) {
+                item = item.navigationDownItem
+            }
+            if (item) {
+                item.forceActiveFocus()
+            }
+        } else if (navigationParent) {
             navigationParent.navigationDown(index)
         } else {
             actionDown(index)
@@ -57,7 +82,15 @@ FocusScope {
     }
 
     function defaultNavigationLeft(index) {
-        if (navigationParent) {
+        if (navigationLeftItem) {
+            var item = navigationLeftItem
+            while (item && (!item.visible || !item.enabled || !(item.navigable === undefined || item.navigable))) {
+                item = item.navigationLeftItem
+            }
+            if (item) {
+                item.forceActiveFocus()
+            }
+        } else if (navigationParent) {
             navigationParent.navigationLeft(index)
         } else {
             actionLeft(index)
@@ -65,7 +98,15 @@ FocusScope {
     }
 
     function defaultNavigationRight(index) {
-        if (navigationParent) {
+        if (navigationRightItem) {
+            var item = navigationRightItem
+            while (item && (!item.visible || !item.enabled || !(item.navigable === undefined || item.navigable))) {
+                item = item.navigationRightItem
+            }
+            if (item) {
+                item.forceActiveFocus()
+            }
+        } else if (navigationParent) {
             navigationParent.navigationRight(index)
         } else {
             actionRight(index)
@@ -73,7 +114,15 @@ FocusScope {
     }
 
     function defaultNavigationCancel(index) {
-        if (navigationParent) {
+        if (navigationCancelItem) {
+            var item = navigationCancelItem
+            while (item && (!item.visible || !item.enabled || !(item.navigable === undefined || item.navigable))) {
+                item = item.navigationCancelItem
+            }
+            if (item) {
+                item.forceActiveFocus()
+            }
+        } else if (navigationParent) {
             navigationParent.navigationCancel(index)
         } else {
             actionCancel(index)



More information about the vlc-commits mailing list