[vlc-commits] [Git][videolan/vlc][master] 5 commits: qml: implement transferFocus in Helpers

Steve Lhomme (@robUx4) gitlab at videolan.org
Sun May 4 09:21:56 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
d9803d33 by Prince Gupta at 2025-05-04T08:23:09+00:00
qml: implement transferFocus in Helpers

- - - - -
a568b799 by Prince Gupta at 2025-05-04T08:23:09+00:00
qml: use transferFocus in NavigableCol

- - - - -
8b761e21 by Prince Gupta at 2025-05-04T08:23:09+00:00
qml: use transferFocus in NavigableRow

- - - - -
3d69677d by Prince Gupta at 2025-05-04T08:23:09+00:00
qml: fix intial focus transfer in Browse view

- - - - -
6c52a368 by Prince Gupta at 2025-05-04T08:23:09+00:00
qml: fix possible invalid access

fixes related warnings as well

- - - - -


4 changed files:

- modules/gui/qt/network/qml/BrowseHomeDisplay.qml
- modules/gui/qt/util/qml/Helpers.qml
- modules/gui/qt/widgets/qml/NavigableCol.qml
- modules/gui/qt/widgets/qml/NavigableRow.qml


Changes:

=====================================
modules/gui/qt/network/qml/BrowseHomeDisplay.qml
=====================================
@@ -33,6 +33,9 @@ FocusScope {
 
     // Properties
 
+    property bool _initialized: false
+    property bool _resetFocusPendingAfterInitialization: false
+
     property int leftPadding: 0
     property int rightPadding: 0
 
@@ -69,8 +72,24 @@ FocusScope {
 
     focus: true
 
-    Component.onCompleted: resetFocus()
-    onActiveFocusChanged: resetFocus()
+
+    Component.onCompleted: {
+        _initialized = true
+        if (_resetFocusPendingAfterInitialization) {
+            resetFocus()
+
+            _resetFocusPendingAfterInitialization = false
+        }
+    }
+
+    onActiveFocusChanged: {
+        if (!_initialized) {
+            _resetFocusPendingAfterInitialization = true
+            return
+        }
+
+        resetFocus()
+    }
 
     function setCurrentItemFocus(reason) {
         if (foldersSection.visible)
@@ -256,20 +275,20 @@ FocusScope {
     }
 
     function resetFocus() {
+        if (!activeFocus)
+            return
+
         for (let i = 0; i < column.count; ++i) {
             const widget = column.itemAt(i)
             if (widget.activeFocus && widget.visible)
                 return
         }
 
-        let found  = false;
         for (let i = 0; i < column.count; ++i){
             const widget = column.itemAt(i)
-            if (widget.visible && !found) {
-                widget.focus = true
-                found = true
-            } else {
-                widget.focus = false
+            if (widget.visible) {
+                Helpers.transferFocus(widget, Qt.TabFocusReason)
+                break
             }
         }
     }


=====================================
modules/gui/qt/util/qml/Helpers.qml
=====================================
@@ -30,6 +30,16 @@ QtObject {
         return (!!object && (object instanceof type))
     }
 
+    function transferFocus(item, reason) {
+        if (item.activeFocus && item.focusReason === reason)
+            return
+
+        if (item.setCurrentItemFocus)
+            item.setCurrentItemFocus(reason)
+        else
+            item.forceActiveFocus(reason)
+    }
+
     // NOTE: This allows us to force another 'reason' even when the item has activeFocus.
     function enforceFocus(item, reason) {
         if (item.activeFocus && item.focusReason === reason)


=====================================
modules/gui/qt/widgets/qml/NavigableCol.qml
=====================================
@@ -20,6 +20,7 @@ import QtQuick
 import QtQuick.Templates as T
 
 import VLC.MainInterface
+import VLC.Util
 
 T.Control {
     id: root
@@ -67,7 +68,7 @@ T.Control {
                 const item = repeater.itemAt(i);
 
                 if (item.visible && item.enabled) {
-                    item.forceActiveFocus(Qt.TabFocusReason);
+                    Helpers.transferFocus(item, Qt.TabFocusReason);
 
                     return;
                 }
@@ -79,7 +80,7 @@ T.Control {
                 const item = repeater.itemAt(i);
 
                 if (item.visible && item.enabled) {
-                    item.forceActiveFocus(Qt.BacktabFocusReason);
+                    Helpers.transferFocus(item, Qt.BacktabFocusReason);
 
                     return;
                 }
@@ -103,7 +104,7 @@ T.Control {
             }
 
             if (itemFocus)
-                itemFocus.forceActiveFocus(focusReason);
+                Helpers.transferFocus(itemFocus, focusReason);
         }
     }
 
@@ -121,7 +122,7 @@ T.Control {
         const item = repeater.itemAt(indexFocus);
 
         if (item.visible && item.enabled) {
-            item.forceActiveFocus(focusReason);
+            Helpers.transferFocus(item, focusReason);
 
             return true;
         }
@@ -163,7 +164,7 @@ T.Control {
                     if (i == -1)
                         root.Navigation.defaultNavigationUp();
                     else
-                        repeater.itemAt(i).forceActiveFocus(Qt.BacktabFocusReason);
+                        Helpers.transferFocus(repeater.itemAt(i), Qt.BacktabFocusReason);
                 }
 
                 item.Navigation.downAction = function() {
@@ -178,7 +179,7 @@ T.Control {
                     if (i == repeater.count)
                         root.Navigation.defaultNavigationDown();
                     else
-                        repeater.itemAt(i).forceActiveFocus(Qt.TabFocusReason);
+                        Helpers.transferFocus(repeater.itemAt(i), Qt.TabFocusReason);
                 }
             }
 


=====================================
modules/gui/qt/widgets/qml/NavigableRow.qml
=====================================
@@ -20,6 +20,7 @@ import QtQuick
 import QtQuick.Templates as T
 
 import VLC.MainInterface
+import VLC.Util
 
 T.Control {
     id: root
@@ -61,7 +62,7 @@ T.Control {
                 const item = repeater.itemAt(i);
 
                 if (item.visible && item.enabled) {
-                    item.forceActiveFocus(Qt.TabFocusReason);
+                    Helpers.transferFocus(item, Qt.TabFocusReason)
 
                     return;
                 }
@@ -73,7 +74,7 @@ T.Control {
                 const item = repeater.itemAt(i);
 
                 if (item.visible && item.enabled) {
-                    item.forceActiveFocus(Qt.BacktabFocusReason);
+                    Helpers.transferFocus(item, Qt.BacktabFocusReason)
 
                     return;
                 }
@@ -97,7 +98,7 @@ T.Control {
             }
 
             if (itemFocus)
-                itemFocus.forceActiveFocus(focusReason);
+                Helpers.transferFocus(itemFocus, focusReason)
         }
     }
 
@@ -115,7 +116,7 @@ T.Control {
         const item = repeater.itemAt(indexFocus);
 
         if (item.visible && item.enabled) {
-            item.forceActiveFocus(focusReason);
+            Helpers.transferFocus(itemFocus, focusReason)
 
             return true;
         }
@@ -159,7 +160,7 @@ T.Control {
                     if (i == -1)
                         root.Navigation.defaultNavigationLeft();
                     else
-                        repeater.itemAt(i).forceActiveFocus(Qt.BacktabFocusReason);
+                        Helpers.transferFocus(repeater.itemAt(i), Qt.BacktabFocusReason)
                 };
 
                 item.Navigation.rightAction = function() {
@@ -174,7 +175,7 @@ T.Control {
                     if (i === count)
                         root.Navigation.defaultNavigationRight();
                     else
-                        repeater.itemAt(i).forceActiveFocus(Qt.TabFocusReason);
+                        Helpers.transferFocus(repeater.itemAt(i), Qt.TabFocusReason)
                 };
             }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/311302fec64e29a48952df6b8ef0c0dab00a5fb5...6c52a36889c5ec2ac95be73d5484a3c2af442974

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/311302fec64e29a48952df6b8ef0c0dab00a5fb5...6c52a36889c5ec2ac95be73d5484a3c2af442974
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list