[vlc-commits] qml: add key navigation wrapping support to KeyNavigableListView

Fatih Uzunoglu git at videolan.org
Thu Oct 15 10:32:31 CEST 2020


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Oct  9 19:56:23 2020 +0300| [16e5755e04b795c06084923129a45808eff0e7d3] | committer: Pierre Lamot

qml: add key navigation wrapping support to KeyNavigableListView

ListView's keyNavigationWraps property does not work. So, it had to be reimplemented.

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

 modules/gui/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)
                 }



More information about the vlc-commits mailing list