[vlc-commits] [Git][videolan/vlc][master] 14 commits: qml/MainViewLoader: Make 'setCurrentItemFocusDefault' public

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jul 31 15:41:56 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f3bc6404 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/MainViewLoader: Make 'setCurrentItemFocusDefault' public

- - - - -
23c85b25 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/VideoAllSubDisplay: Fix the 'setCurrentItemFocus' function

- - - - -
3119708a by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/navigation_attached: Update the defaultNavigationCancel focus reason

- - - - -
6e82b5b0 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml: Update the History.previous usage

- - - - -
40b270ae by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/VideoPlaylistsDisplay: Pass the focusReason value

- - - - -
bf305a38 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/ExpandGridView: Add the 'setCurrentItem' function

- - - - -
62160b86 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/KeyNavigableListView: Add the 'setCurrentItem' function

- - - - -
00ba859c by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/KeyNavigableTableView: Add the 'setCurrentItem' function

- - - - -
9240af5d by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/MainViewLoader: Add the 'count' property

- - - - -
3cdfb042 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/MainViewLoader: Use 'setCurrentItem' for selection

- - - - -
4e96e7d8 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/MainViewLoader: Update the loading implementation

- - - - -
20f5f09f by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/PlaylistMediaDisplay: Fix the keyboard selection and focus

- - - - -
9915d216 by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/Music(s): Fix the keyboard selection and focus

- - - - -
fe85873b by Benjamin Arnaud at 2023-07-31T14:59:12+00:00
qml/BrowseTreeDisplay: Fix the keyboard selection and focus

- - - - -


17 changed files:

- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/maininterface/qml/MainViewLoader.qml
- modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
- modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
- modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoAllSubDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
- modules/gui/qt/network/qml/BrowseTreeHeader.qml
- modules/gui/qt/network/qml/ServicesSources.qml
- modules/gui/qt/player/qml/ControlBar.qml
- modules/gui/qt/widgets/native/navigation_attached.cpp
- modules/gui/qt/widgets/qml/EmptyLabel.qml
- modules/gui/qt/widgets/qml/EmptyLabelButton.qml
- modules/gui/qt/widgets/qml/ExpandGridView.qml
- modules/gui/qt/widgets/qml/KeyNavigableListView.qml
- modules/gui/qt/widgets/qml/KeyNavigableTableView.qml


Changes:

=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -122,7 +122,7 @@ FocusScope {
     }
 
     Navigation.cancelAction: function() {
-        History.previous()
+        History.previous(Qt.BacktabFocusReason)
     }
 
     Keys.onPressed: {


=====================================
modules/gui/qt/maininterface/qml/MainViewLoader.qml
=====================================
@@ -49,9 +49,14 @@ Widgets.StackViewExt {
     // view's model
     /* required */ property var model
 
-    // optional, loaded when model.loading is true
+    // optional, loaded when isLoading is true
     property Component loadingComponent: null
 
+    // NOTE: Sometimes the model has no 'loading' property.
+    readonly property bool isLoading: (model.loading) ? model.loading : false
+
+    readonly property int count: model.count
+
     property var selectionModel: Util.SelectableDelegateModel {
         model: root.model
     }
@@ -67,22 +72,42 @@ Widgets.StackViewExt {
 
     // used in custom focus management for explicit "focusReason" transfer
     readonly property var setCurrentItemFocus: {
-        return Helpers.get(currentItem, "setCurrentItemFocus", _setCurrentItemFocusDefault)
+        return Helpers.get(currentItem, "setCurrentItemFocus", setCurrentItemFocusDefault)
     }
 
     // NOTE: We have to use a Component here. When using a var the onCurrentComponentChanged event
     //       gets called multiple times even when the currentComponent stays the same.
     property Component currentComponent: {
-        if (model.loading)
-            return loadingComponent
-        else if (model.count === 0)
+        if (isLoading) {
+            if (loadingComponent)
+                return loadingComponent
+        } else if (count === 0)
             return emptyLabel
-        else if (MainCtx.gridView)
+
+        if (MainCtx.gridView)
             return grid
         else
             return list
     }
 
+    // Navigation
+
+    // handle cancelAction, if currentIndex is set reset it to 0
+    // otherwise perform default Navigation action
+    Navigation.cancelAction: function () {
+        if (isLoading || count === 0 || currentItem === null || currentItem.currentIndex === 0)
+            return false // transfer cancel action to parent
+
+        if (currentItem.hasOwnProperty("positionViewAtIndex"))
+            currentItem.positionViewAtIndex(0, ItemView.Contain)
+
+        currentItem.setCurrentItem(0)
+
+        return true
+    }
+
+    // Events
+
     Component.onCompleted: {
         _updateView()
 
@@ -98,13 +123,42 @@ Widgets.StackViewExt {
         target: model
 
         onCountChanged: {
-            if (model.count === 0 || selectionModel.hasSelection)
+            if (selectionModel.hasSelection)
                 return
 
             resetFocus()
         }
     }
 
+    // makes the views currentIndex initial index and position view at that index
+    function resetFocus() {
+        if (isLoading || count === 0 || initialIndex === -1) return
+
+        var index
+
+        if (initialIndex < count)
+            index = initialIndex
+        else
+            index = 0
+
+        selectionModel.select(model.index(index, 0), ItemSelectionModel.ClearAndSelect)
+
+        if (currentItem.hasOwnProperty("positionViewAtIndex"))
+            currentItem.positionViewAtIndex(index, ItemView.Contain)
+
+        currentItem.setCurrentItem(index)
+    }
+
+    function setCurrentItemFocusDefault(reason) {
+        if (currentItem) {
+            if (currentItem.setCurrentItemFocus)
+                currentItem.setCurrentItemFocus(reason)
+            else
+                currentItem.forceActiveFocus(reason)
+        } else
+            Helpers.enforceFocus(root, reason)
+    }
+
     function _updateView() {
         // NOTE: When the currentItem is null we default to the StackView focusReason.
         if (currentItem && currentItem.activeFocus)
@@ -120,42 +174,4 @@ Widgets.StackViewExt {
 
         setCurrentItemFocus(reason)
     }
-
-    function _setCurrentItemFocusDefault(reason) {
-        if (currentItem)
-            currentItem.forceActiveFocus(reason)
-        else
-            Helpers.enforceFocus(root, reason)
-    }
-
-    // makes the views currentIndex initial index and position view at that index
-    function resetFocus() {
-        if (!model || model.count === 0) return
-
-        let initialIndex = root.initialIndex
-        if (initialIndex >= model.count)
-            initialIndex = 0
-
-        selectionModel.select(model.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
-        if (currentItem && currentItem.hasOwnProperty("positionViewAtIndex")) {
-            currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
-
-            // Table View require this for focus handling
-            if (!MainCtx.gridView)
-                currentItem.currentIndex = initialIndex
-        }
-    }
-
-    // handle cancelAction, if currentIndex is set reset it to 0
-    // otherwise perform default Navigation action
-    Navigation.cancelAction: function () {
-        if (Helpers.get(currentItem, "currentIndex", 0) <= 0) {
-            return false // transfer cancel action to parent
-        }
-
-        currentItem.currentIndex = 0
-        currentItem.positionViewAtIndex(0, ItemView.Contain)
-        return true
-    }
-
 }


=====================================
modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
=====================================
@@ -69,19 +69,13 @@ FocusScope {
             return
         }
 
-        if (artistModel.count === 0) {
-            return
-        }
-        let initialIndex = root.initialIndex
-        if (initialIndex >= artistModel.count)
-            initialIndex = 0
-        if (initialIndex !== artistList.currentIndex) {
-            selectionModel.select(artistModel.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
-            if (artistList) {
-                artistList.currentIndex = initialIndex
-                artistList.positionViewAtIndex(initialIndex, ItemView.Contain)
-            }
-        }
+        if (model.count === 0 || initialIndex === -1) return
+
+        selectionModel.select(model.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
+
+        artistList.positionViewAtIndex(initialIndex, ItemView.Contain)
+
+        artistList.setCurrentItem(initialIndex)
     }
 
     function setCurrentItemFocus(reason) {
@@ -101,12 +95,10 @@ FocusScope {
         ml: MediaLib
 
         onCountChanged: {
-            if (artistModel.count > 0 && !selectionModel.hasSelection) {
-                let initialIndex = root.initialIndex
-                if (initialIndex >= artistModel.count)
-                    initialIndex = 0
-                artistList.currentIndex = initialIndex
-            }
+            if (count === 0 || selectionModel.hasSelection)
+                return
+
+            root.resetFocus()
         }
 
         onDataChanged: {
@@ -167,10 +159,15 @@ FocusScope {
             }
 
             Navigation.cancelAction: function() {
-                if (artistList.currentIndex <= 0)
+                if (artistList.currentIndex <= 0) {
                     root.Navigation.defaultNavigationCancel()
-                else
-                    artistList.currentIndex = 0;
+
+                    return
+                }
+
+                artistList.positionViewAtIndex(0, ItemView.Contain)
+
+                artistList.setCurrentItem(0)
             }
 
             header: Widgets.SubtitleLabel {


=====================================
modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
=====================================
@@ -98,11 +98,8 @@ Widgets.PageLoader {
 
             onCurrentIndexChanged: _updateHistoryList(currentIndex)
 
-            onShowList: {
-                History.push(["mc", "music", "playlists", "list",
-                             { parentId: model.id, name: model.name }]);
-
-            }
+            onShowList: History.push(["mc", "music", "playlists", "list",
+                                      { parentId: model.id, name: model.name }], reason)
         }
     }
 


=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
=====================================
@@ -73,16 +73,22 @@ FocusScope {
     function setCurrentItemFocus(reason) { view.setCurrentItemFocus(reason); }
 
     function resetFocus() {
-        if (model.count === 0) return
+        const count = model.count
 
-        let initialIndex = root.initialIndex
+        if (count === 0 || initialIndex === -1) return
 
-        if (initialIndex >= model.count)
-            initialIndex = 0
+        var index
 
-        modelSelect.select(model.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect);
+        if (initialIndex < count)
+            index = initialIndex
+        else
+            index = 0
 
-        view.positionViewAtIndex(initialIndex, ItemView.Contain);
+        modelSelect.select(model.index(index, 0), ItemSelectionModel.ClearAndSelect)
+
+        view.positionViewAtIndex(index, ItemView.Contain)
+
+        view.setCurrentItem(index)
     }
 
     // Events
@@ -181,8 +187,9 @@ FocusScope {
             if (view.currentIndex <= 0) {
                 root.Navigation.defaultNavigationCancel()
             } else {
-                view.currentIndex = 0;
-                view.positionViewAtIndex(0, ItemView.Contain);
+                positionViewAtIndex(0, ItemView.Contain)
+
+                setCurrentItem(0)
             }
         }
 


=====================================
modules/gui/qt/medialibrary/qml/VideoAllSubDisplay.qml
=====================================
@@ -25,6 +25,7 @@ import org.videolan.medialib 0.1
 
 import "qrc:///widgets/" as Widgets
 import "qrc:///util/" as Util
+import "qrc:///util/Helpers.js" as Helpers
 import "qrc:///style/"
 
 VideoAll {
@@ -94,10 +95,8 @@ VideoAll {
     function setCurrentItemFocus(reason) {
         if (headerItem && headerItem.focus)
             headerItem.forceActiveFocus(reason) // continue watching section
-        else if (currentItem.setCurrentItemFocus)
-            currentItem.setCurrentItemFocus(reason) // grid or list view
         else
-            currentItem.forceActiveFocus(reason) // empty label
+            setCurrentItemFocusDefault(reason)
     }
 
     // VideoAll events reimplementation


=====================================
modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
=====================================
@@ -101,7 +101,7 @@ Widgets.PageLoader {
 
             onShowList: {
                 History.push(["mc", "video", "playlists", "list",
-                             { parentId: model.id, name: model.name }]);
+                             { parentId: model.id, name: model.name }], reason);
             }
         }
     }


=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -54,9 +54,7 @@ MainInterface.MainViewLoader {
 
     signal browse(var tree, int reason)
 
-    Navigation.cancelAction: function() {
-        History.previous()
-    }
+    // Settings
 
     model: SortFilterProxyModel {
         id: filterModel
@@ -69,8 +67,13 @@ MainInterface.MainViewLoader {
     list: tableComponent
 
     loadingComponent: emptyLabelComponent
+
     emptyLabel: emptyLabelComponent
 
+    Navigation.cancelAction: function() {
+        History.previous(Qt.BacktabFocusReason)
+    }
+
     onTreeChanged: providerModel.tree = tree
 
     function playSelected() {
@@ -310,17 +313,22 @@ MainInterface.MainViewLoader {
         FocusScope {
             id: focusScope
 
+            // NOTE: This is required to pass the focusReason when the current view changes in
+            //       MainViewLoader.
+            property int focusReason: (header.activeFocus) ? header.focusReason
+                                                           : emptyLabel.focusReason
+
             Navigation.navigable: layout.Navigation.navigable || (emptyLabel.visible && emptyLabel.button.enabled)
 
             // used by MainDisplay to transfer focus
             function setCurrentItemFocus(reason) {
-                if (!focusScope.Navigation.navigable)
+                if (!Navigation.navigable)
                     return
 
                 if (header.Navigation.navigable)
-                    header.forceActiveFocus(reason)
+                    Helpers.enforceFocus(header, reason)
                 else
-                    emptyLabel.forceActiveFocus(reason)
+                    Helpers.enforceFocus(emptyLabel, reason)
             }
 
             ColumnLayout {
@@ -358,8 +366,8 @@ MainInterface.MainViewLoader {
                     button.enabled: !History.previousEmpty
                     button.width: button.implicitWidth
 
-                    function onNavigate() {
-                        History.previous()
+                    function onNavigate(reason) {
+                        History.previous(reason)
                     }
 
                     Layout.fillHeight: true


=====================================
modules/gui/qt/network/qml/BrowseTreeHeader.qml
=====================================
@@ -16,8 +16,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 import QtQuick 2.11
 import QtQuick.Layouts 1.11
+import QtQuick.Templates 2.12 as T
 
 import org.videolan.vlc 0.1
 
@@ -26,7 +28,7 @@ import "qrc:///util/Helpers.js" as Helpers
 import "qrc:///widgets/" as Widgets
 import "qrc:///style/"
 
-FocusScope {
+T.Control {
     id: root
 
     // Network* model
@@ -38,16 +40,16 @@ FocusScope {
         colorSet: ColorContext.View
     }
 
-    property int leftPadding: VLCStyle.margin_large
-    property int rightPadding: VLCStyle.margin_small
-
-    property int topPadding: VLCStyle.margin_large
-    property int bottomPadding: VLCStyle.margin_normal
-
     height: implicitHeight
     implicitHeight: layout.implicitHeight + topPadding + bottomPadding
 
+    leftPadding: VLCStyle.margin_large
+    rightPadding: VLCStyle.margin_small
+    topPadding: VLCStyle.margin_large
+    bottomPadding: VLCStyle.margin_normal
+
     focus: medialibraryBtn.visible
+
     Navigation.navigable: medialibraryBtn.visible
 
     RowLayout {


=====================================
modules/gui/qt/network/qml/ServicesSources.qml
=====================================
@@ -108,7 +108,7 @@ MainInterface.MainGridView {
     Navigation.parentItem: root
 
     Navigation.cancelAction: function() {
-        History.previous(Qt.TabFocusReason)
+        History.previous(Qt.BacktabFocusReason)
     }
 
     NetworkSourcesModel {


=====================================
modules/gui/qt/player/qml/ControlBar.qml
=====================================
@@ -65,7 +65,7 @@ T.Pane {
 
     Keys.priority: Keys.AfterItem
     Keys.onPressed: root.Navigation.defaultKeyAction(event)
-    Navigation.cancelAction: function() { History.previous() }
+    Navigation.cancelAction: function() { History.previous(Qt.BacktabFocusReason) }
 
     Accessible.name: I18n.qtr("Player controls")
 


=====================================
modules/gui/qt/widgets/native/navigation_attached.cpp
=====================================
@@ -100,7 +100,7 @@ void NavigationAttached::defaultNavigationCancel()
 {
     defaultNavigationGeneric(m_cancelAction, m_cancelItem,
                              &NavigationAttached::defaultNavigationCancel,
-                             Qt::OtherFocusReason);
+                             Qt::BacktabFocusReason);
 }
 
 void NavigationAttached::defaultKeyAction(QObject* event)


=====================================
modules/gui/qt/widgets/qml/EmptyLabel.qml
=====================================
@@ -23,15 +23,13 @@ import org.videolan.vlc 0.1
 import "qrc:///style/"
 import "qrc:///widgets/" as Widgets
 
-FocusScope {
+T.Control {
     id: root
 
     // Aliases
 
     default property alias contents: column.data
 
-    property alias spacing: column.spacing
-
     property alias cover: cover.source
 
     property alias coverWidth: coverContainer.width
@@ -41,7 +39,10 @@ FocusScope {
 
     property alias column: column
 
+    spacing: VLCStyle.margin_small
+
     enabled: visible
+
     Accessible.role: Accessible.Pane
     Accessible.name: I18n.qtr("Empty view")
 
@@ -59,7 +60,7 @@ FocusScope {
 
         width: root.width
 
-        spacing: VLCStyle.margin_small
+        spacing: root.spacing
 
         Item {
             width: parent.width


=====================================
modules/gui/qt/widgets/qml/EmptyLabelButton.qml
=====================================
@@ -37,8 +37,8 @@ EmptyLabel {
 
     // Functions
 
-    function onNavigate() {
-        History.push(["mc", "network"])
+    function onNavigate(reason) {
+        History.push(["mc", "network"], reason)
     }
 
     // Keys
@@ -58,7 +58,7 @@ EmptyLabel {
         _keyPressed = false
 
         if (KeyHelper.matchOk(event))
-            onNavigate()
+            onNavigate(Qt.TabFocusReason)
 
         Navigation.defaultKeyReleaseAction(event)
     }
@@ -79,6 +79,6 @@ EmptyLabel {
 
         Navigation.parentItem: root
 
-        onClicked: onNavigate()
+        onClicked: onNavigate(Qt.OtherFocusReason)
     }
 }


=====================================
modules/gui/qt/widgets/qml/ExpandGridView.qml
=====================================
@@ -15,10 +15,13 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 import QtQuick 2.12
-import QtQml.Models 2.12
+import QtQuick.Window 2.12
 import QtQuick.Controls 2.12
 
+import QtQml.Models 2.12
+
 import org.videolan.vlc 0.1
 
 import "qrc:///style/"
@@ -304,6 +307,32 @@ FocusScope {
 
     // Functions
 
+    // NOTE: This function is useful to set the currentItem without losing the visual focus.
+    function setCurrentItem(index) {
+        if (currentIndex === index)
+            return
+
+        let reason
+
+        let item = _getItem(index)
+
+        if (item)
+            reason = item.focusReason
+        else
+            reason = _currentFocusReason
+
+        currentIndex = index
+
+        item = _getItem(index)
+
+        if (reason !== Qt.OtherFocusReason) {
+            if (item)
+                Helpers.enforceFocus(item, reason)
+            else
+                setCurrentItemFocus(reason)
+        }
+    }
+
     function setCurrentItemFocus(reason) {
 
         // NOTE: Saving the focus reason for later.


=====================================
modules/gui/qt/widgets/qml/KeyNavigableListView.qml
=====================================
@@ -15,8 +15,11 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 import QtQuick 2.12
+import QtQuick.Window 2.12
 import QtQuick.Controls 2.12
+
 import QtGraphicalEffects 1.12
 
 import org.videolan.vlc 0.1
@@ -129,6 +132,28 @@ FadingEdgeListView {
 
     // Functions
 
+    // NOTE: This function is useful to set the currentItem without losing the visual focus.
+    function setCurrentItem(index) {
+        if (currentIndex === index)
+            return
+
+        let reason
+
+        if (currentItem)
+            reason = currentItem.focusReason
+        else
+            reason = _currentFocusReason
+
+        currentIndex = index
+
+        if (reason !== Qt.OtherFocusReason) {
+            if (currentItem)
+                Helpers.enforceFocus(currentItem, reason)
+            else
+                setCurrentItemFocus(reason)
+        }
+    }
+
     function setCurrentItemFocus(reason) {
         if (!model || model.count === 0) {
             // NOTE: By default we want the focus on the flickable.


=====================================
modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
=====================================
@@ -159,6 +159,10 @@ FocusScope {
 
     // Functions
 
+    function setCurrentItem(index) {
+        view.setCurrentItem(index)
+    }
+
     function setCurrentItemFocus(reason) {
         view.setCurrentItemFocus(reason);
     }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6e6db6f4bf12f38418b1cd44672ddbf5112c5e12...fe85873b6bade3f1be39d73bb83fce8a0e64fb8e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6e6db6f4bf12f38418b1cd44672ddbf5112c5e12...fe85873b6bade3f1be39d73bb83fce8a0e64fb8e
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