[vlc-commits] qml: allow defining a default target for action in NavigableFocusScope

Pierre Lamot git at videolan.org
Fri Sep 6 18:02:09 CEST 2019


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Aug 30 17:56:33 2019 +0200| [448b817a4b6903c88c9b65accd55be3d80a573c8] | committer: Jean-Baptiste Kempf

qml: allow defining a default target for action in NavigableFocusScope

  in most cases actions are forwarded to the parent widget, this allows
  to define this target, then only define non default behaviors. this recude
  the navigation code boilerplate

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

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

diff --git a/modules/gui/qt/qml/utils/NavigableFocusScope.qml b/modules/gui/qt/qml/utils/NavigableFocusScope.qml
index 7b9fe78814..308d3870c5 100644
--- a/modules/gui/qt/qml/utils/NavigableFocusScope.qml
+++ b/modules/gui/qt/qml/utils/NavigableFocusScope.qml
@@ -33,24 +33,71 @@ FocusScope {
     signal actionRight( int index )
     signal actionCancel( int index )
 
+    property var navigationParent: undefined
+    property var navigationUp: defaultNavigationUp
+    property var navigationDown: defaultNavigationDown
+    property var navigationLeft: defaultNavigationLeft
+    property var navigationRight: defaultNavigationRight
+    property var navigationCancel: defaultNavigationCancel
+
+    function defaultNavigationUp(index) {
+        if (navigationParent) {
+            navigationParent.navigationUp(index)
+        } else {
+            actionUp(index)
+        }
+    }
+
+    function defaultNavigationDown(index) {
+        if (navigationParent) {
+            navigationParent.navigationDown(index)
+        } else {
+            actionDown(index)
+        }
+    }
+
+    function defaultNavigationLeft(index) {
+        if (navigationParent) {
+            navigationParent.navigationLeft(index)
+        } else {
+            actionLeft(index)
+        }
+    }
+
+    function defaultNavigationRight(index) {
+        if (navigationParent) {
+            navigationParent.navigationRight(index)
+        } else {
+            actionRight(index)
+        }
+    }
+
+    function defaultNavigationCancel(index) {
+        if (navigationParent) {
+            navigationParent.navigationCancel(index)
+        } else {
+            actionCancel(index)
+        }
+    }
+
     function defaultKeyAction(event, index) {
         if (event.accepted)
             return
         if ( event.key === Qt.Key_Down || event.matches(StandardKey.MoveToNextLine) ||event.matches(StandardKey.SelectNextLine) ) {
             event.accepted = true
-            actionDown( index )
+            navigationDown( index )
         } else if ( event.key === Qt.Key_Up || event.matches(StandardKey.MoveToPreviousLine) ||event.matches(StandardKey.SelectPreviousLine) ) {
             event.accepted = true
-            actionUp( index  )
+            navigationUp( index  )
         } else if (event.key === Qt.Key_Right || event.matches(StandardKey.MoveToNextChar) ) {
             event.accepted = true
-            actionRight( index )
+            navigationRight( index )
         } else if (event.key === Qt.Key_Left || event.matches(StandardKey.MoveToPreviousChar) ) {
             event.accepted = true
-            actionLeft( index )
+            navigationLeft( index )
         } else if ( event.key === Qt.Key_Back || event.key === Qt.Key_Cancel || event.matches(StandardKey.Back) || event.matches(StandardKey.Cancel)) {
             event.accepted = true
-            actionCancel( index )
+            navigationCancel( index )
         }
     }
 }



More information about the vlc-commits mailing list