[vlc-devel] [PATCH 10/22] qml: restore the focus on the last video when navigating back to the video view

Pierre Lamot pierre at videolabs.io
Fri Feb 14 11:23:45 CET 2020


---
 .../gui/qt/medialibrary/qml/VideoDisplay.qml  | 36 +++++++++++++++++--
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index 7b91eaee6a..8cac270b2e 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -29,15 +29,39 @@ import "qrc:///style/"
 
 Widgets.NavigableFocusScope {
     id: root
-    property var currentIndex: view.currentItem.currentIndex
+    readonly property var currentIndex: view.currentItem.currentIndex
+    //the index to "go to" when the view is loaded
+    property var initialIndex: 0
 
     property alias contentModel: videosDelegate.model;
 
     navigationCancel: function() {
-        if (view.currentItem.currentIndex <= 0)
+        if (view.currentItem.currentIndex <= 0) {
             defaultNavigationCancel()
-        else
+        } else {
             view.currentItem.currentIndex = 0;
+            view.currentItem.positionViewAtIndex(0, ItemView.Contain)
+        }
+    }
+
+    onCurrentIndexChanged: {
+        history.update([ "mc", "video", {"initialIndex": currentIndex}])
+    }
+
+    onInitialIndexChanged: resetFocus()
+    onContentModelChanged: resetFocus()
+
+    function resetFocus() {
+        if (videosDelegate.items.count === 0) {
+            return
+        }
+        var initialIndex = root.initialIndex
+        if (initialIndex >= videosDelegate.items.count)
+            initialIndex = 0
+        videosDelegate.selectNone()
+        videosDelegate.items.get(initialIndex).inSelected = true
+        view.currentItem.currentIndex = initialIndex
+        view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
     }
 
     DG.ModalDialog {
@@ -105,6 +129,12 @@ Widgets.NavigableFocusScope {
             Item { Package.name: "grid" }
         }
 
+        onCountChanged: {
+            if (videosDelegate.items.count > 0 && videosDelegate.selectedGroup.count === 0) {
+                root.resetFocus()
+            }
+        }
+
         function actionAtIndex(index) {
             var list = []
             for (var i = 0; i < videosDelegate.selectedGroup.count; i++)
-- 
2.17.1



More information about the vlc-devel mailing list