[vlc-commits] qml: restore the focus on the last video when navigating back to the video view

Pierre Lamot git at videolan.org
Fri Feb 14 11:59:58 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Jan 29 14:56:58 2020 +0100| [f0ac4c4178502be58a940b4179efa1f3c9972420] | committer: Jean-Baptiste Kempf

qml: restore the focus on the last video when navigating back to the video view

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

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

 modules/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++)



More information about the vlc-commits mailing list