[vlc-devel] [PATCH 02/27] qml: add key navigation wrapping support to KeyNavigableListView

Fatih Uzunoglu fuzun54 at outlook.com
Fri Oct 9 18:56:23 CEST 2020


ListView's keyNavigationWraps property does not work. So, it had to be reimplemented.
---
 .../qt/widgets/qml/KeyNavigableListView.qml   | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/KeyNavigableListView.qml b/modules/gui/qt/widgets/qml/KeyNavigableListView.qml
index 9d417ef690..4c7e97de9a 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableListView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableListView.qml
@@ -76,6 +76,8 @@ NavigableFocusScope {
 
     property int scrollBarWidth: scroll_id.visible ? scroll_id.width : 0
 
+    property bool keyNavigationWraps : false
+
     Accessible.role: Accessible.List
 
     function nextPage() {
@@ -153,9 +155,12 @@ NavigableFocusScope {
         Connections {
             target: view.currentItem
             ignoreUnknownSignals: true
-            onActionRight: listview_id.navigationRight(currentIndex)
-            onActionLeft: listview_id.navigationLeft(currentIndex)
+            onActionRight: if ( !listview_id.keyNavigationWraps ) listview_id.navigationRight(currentIndex);
+            onActionLeft: if ( !listview_id.keyNavigationWraps ) listview_id.navigationLeft(currentIndex);
             onActionDown: {
+                if ( listview_id.keyNavigationWraps )
+                    return
+
                 if ( currentIndex !== modelCount - 1 ) {
                     var newIndex = currentIndex + 1
                     var oldIndex = currentIndex
@@ -166,6 +171,9 @@ NavigableFocusScope {
                 }
             }
             onActionUp: {
+                if ( listview_id.keyNavigationWraps )
+                    return
+
                 if ( currentIndex !== 0 ) {
                     var newIndex = currentIndex - 1
                     var oldIndex = currentIndex
@@ -185,11 +193,15 @@ NavigableFocusScope {
                 if ( KeyHelper.matchDown(event) ) {
                     if (currentIndex !== modelCount - 1 )
                         newIndex = currentIndex + 1
+                    else if ( listview_id.keyNavigationWraps )
+                        newIndex = 0
                 } else if ( KeyHelper.matchPageDown(event) ) {
                     newIndex = Math.min(modelCount - 1, currentIndex + 10)
                 } else if ( KeyHelper.matchUp(event) ) {
                     if ( currentIndex !== 0 )
                         newIndex = currentIndex - 1
+                    else if ( listview_id.keyNavigationWraps )
+                        newIndex = modelCount - 1
                 } else if ( KeyHelper.matchPageUp(event) ) {
                     newIndex = Math.max(0, currentIndex - 10)
                 }
@@ -197,12 +209,16 @@ NavigableFocusScope {
                 if ( KeyHelper.matchRight(event) ) {
                     if (currentIndex !== modelCount - 1 )
                         newIndex = currentIndex + 1
+                    else if ( listview_id.keyNavigationWraps )
+                        newIndex = 0
                 }
                 else if ( KeyHelper.matchPageDown(event) ) {
                     newIndex = Math.min(modelCount - 1, currentIndex + 10)
                 } else if ( KeyHelper.matchLeft(event) ) {
                     if ( currentIndex !== 0 )
                         newIndex = currentIndex - 1
+                    else if ( listview_id.keyNavigationWraps )
+                        newIndex = modelCount - 1
                 } else if ( KeyHelper.matchPageUp(event) ) {
                     newIndex = Math.max(0, currentIndex - 10)
                 }
-- 
2.25.1



More information about the vlc-devel mailing list