[vlc-commits] [Git][videolan/vlc][master] 7 commits: qml: refactor loading view in MainViewLoader for clarity

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri May 10 16:20:05 UTC 2024



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
870911a6 by Prince Gupta at 2024-05-10T15:56:50+00:00
qml: refactor loading view in MainViewLoader for clarity

- - - - -
ac3b1833 by Prince Gupta at 2024-05-10T15:56:50+00:00
qml: add more strict constaints for 'loadingComponent'

- - - - -
0d955392 by Prince Gupta at 2024-05-10T15:56:50+00:00
qml: remove redundant property

- - - - -
146575c0 by Prince Gupta at 2024-05-10T15:56:50+00:00
qt: remove shadowed member function

BaseModel has getCount

- - - - -
0c96e3b6 by Prince Gupta at 2024-05-10T15:56:50+00:00
qml: separate loading and empty component in BrowseTreeDisplay

- - - - -
4149672b by Prince Gupta at 2024-05-10T15:56:50+00:00
qml: fix focus handling in BrowseTreeHeader

Control doesn't handle focusable children well

- - - - -
4fc045f1 by Prince Gupta at 2024-05-10T15:56:50+00:00
qml: fix double padding

- - - - -


4 changed files:

- modules/gui/qt/maininterface/qml/MainViewLoader.qml
- modules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
- modules/gui/qt/network/qml/BrowseTreeHeader.qml


Changes:

=====================================
modules/gui/qt/maininterface/qml/MainViewLoader.qml
=====================================
@@ -53,6 +53,7 @@ Widgets.StackViewExt {
     property var pagePrefix: []
 
     // optional, loaded when isLoading is true
+    // only loaded on initial load, when count is less then 1
     property Component loadingComponent: null
 
     // NOTE: Sometimes the model has no 'loading' property.
@@ -85,9 +86,10 @@ Widgets.StackViewExt {
     // 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 (isLoading) {
+        if (isLoading && count < 1) {
             if (loadingComponent)
                 return loadingComponent
+            // fall through to load 'grid' or 'list' view
         } else if (count === 0)
             return emptyLabel
 
@@ -119,7 +121,7 @@ Widgets.StackViewExt {
         _updateView()
 
         // NOTE: This call is useful to avoid a binding loop on currentComponent.
-        currentComponentChanged.connect(function() { _updateView() })
+        currentComponentChanged.connect(_updateView)
     }
 
     onModelChanged: resetFocus()
@@ -169,16 +171,17 @@ Widgets.StackViewExt {
     function _updateView() {
         // NOTE: When the currentItem is null we default to the StackView focusReason.
         if (currentItem && currentItem.activeFocus)
-            _applyView(currentItem.focusReason)
+            _loadView(currentItem.focusReason)
         else if (activeFocus)
-            _applyView(focusReason)
+            _loadView(focusReason)
         else
-            replace(null, currentComponent)
+            _loadView()
     }
 
-    function _applyView(reason) {
+    function _loadView(reason) {
         replace(null, currentComponent)
 
-        setCurrentItemFocus(reason)
+        if (typeof reason !== "undefined")
+            setCurrentItemFocus(reason)
     }
 }


=====================================
modules/gui/qt/network/networkmediamodel.hpp
=====================================
@@ -164,7 +164,6 @@ public:
     inline ItemType getType() const { return m_type; }
     inline bool isIndexed() const { return m_indexed; }
     inline bool canBeIndexed() const { return m_canBeIndexed; }
-    int getCount() const;
 
     Q_INVOKABLE bool insertIntoPlaylist( const QModelIndexList& itemIdList, ssize_t playlistIndex );
     Q_INVOKABLE bool addToPlaylist( int index );


=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -38,9 +38,6 @@ MainInterface.MainViewLoader {
     readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
     readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
 
-     // 'loading' property is not available with NetworkDevicesModel
-    readonly property bool loading: model?.loading ?? false
-
     // fixme remove this
     property Item _currentView: currentItem
 
@@ -60,7 +57,7 @@ MainInterface.MainViewLoader {
     grid: gridComponent
     list: tableComponent
 
-    loadingComponent: emptyLabelComponent
+    loadingComponent: busyIndicatorComponent
 
     emptyLabel: emptyLabelComponent
 
@@ -316,98 +313,113 @@ MainInterface.MainViewLoader {
     Component {
         id: emptyLabelComponent
 
-        FocusScope {
-            id: focusScope
+        StandardView {
+            view: Widgets.EmptyLabelButton {
+                id: emptyLabel
 
-            // NOTE: This is required to pass the focusReason when the current view changes in
-            //       MainViewLoader.
-            property int focusReason: (header.activeFocus) ? header.focusReason
-                                                           : emptyLabel.focusReason
+                visible: !root.isLoading
 
-            Navigation.navigable: layout.Navigation.navigable || (emptyLabel.visible && emptyLabel.button.enabled)
+                // FIXME: find better cover
+                cover: VLCStyle.noArtVideoCover
+                coverWidth : VLCStyle.dp(182, VLCStyle.scale)
+                coverHeight: VLCStyle.dp(114, VLCStyle.scale)
 
-            // used by MainDisplay to transfer focus
-            function setCurrentItemFocus(reason) {
-                if (!Navigation.navigable)
-                    return
+                text: qsTr("Nothing to see here, go back.")
 
-                if (header.Navigation.navigable)
-                    Helpers.enforceFocus(header, reason)
-                else
-                    Helpers.enforceFocus(emptyLabel, reason)
-            }
+                button.iconTxt: VLCIcons.back
+                button.text: qsTr("Back")
+                button.enabled: !History.previousEmpty
+                button.width: button.implicitWidth
+
+                function onNavigate(reason) {
+                    History.previous(reason)
+                }
+
+                Layout.fillHeight: true
+                Layout.fillWidth: true
 
-            ColumnLayout {
-                id: layout
+                Navigation.parentItem: root
+            }
+        }
+    }
 
-                anchors.fill: parent
+    Component {
+        id: busyIndicatorComponent
 
-                BrowseTreeHeader {
-                    id: header
+        StandardView {
+            view: Item {
+                Navigation.navigable: false
 
-                    focus: true
+                visible: root.isLoading
 
-                    providerModel: root.model
+                Layout.fillHeight: true
+                Layout.fillWidth: true
 
-                    Layout.fillWidth: true
+                Widgets.BusyIndicatorExt {
+                    id: busyIndicator
 
-                    Navigation.parentItem: root
-                    Navigation.downItem: emptyLabel
+                    runningDelayed: root.isLoading
+                    anchors.centerIn: parent
+                    z: 1
                 }
+            }
+        }
+    }
 
-                Widgets.EmptyLabelButton {
-                    id: emptyLabel
+    // Helper view i.e a ColumnLayout with BrowseHeader
+    component StandardView : FocusScope {
+        required property Item view
 
-                    visible: !root.loading
+        // NOTE: This is required to pass the focusReason when the current view changes in
+        //       MainViewLoader.
+        property int focusReason: (header.activeFocus) ? header.focusReason
+                                                       : view?.focusReason ?? Qt.NoFocusReason
 
-                    // FIXME: find better cover
-                    cover: VLCStyle.noArtVideoCover
-                    coverWidth : VLCStyle.dp(182, VLCStyle.scale)
-                    coverHeight: VLCStyle.dp(114, VLCStyle.scale)
+        // used by MainDisplay to transfer focus
+        function setCurrentItemFocus(reason) {
+            if (!Navigation.navigable)
+                return
 
-                    text: qsTr("Nothing to see here, go back.")
+            if (header.Navigation.navigable)
+                Helpers.enforceFocus(header, reason)
+            else
+                Helpers.enforceFocus(view, reason)
+        }
 
-                    button.iconTxt: VLCIcons.back
-                    button.text: qsTr("Back")
-                    button.enabled: !History.previousEmpty
-                    button.width: button.implicitWidth
+        onViewChanged: {
+            if (layout.children.length === 2)
+                layout.children.pop()
 
-                    function onNavigate(reason) {
-                        History.previous(reason)
-                    }
+            layout.children.push(view)
+            view.Navigation.upAction = function () {
+                // FIXME: for some reason default navigation flow doesn't work
+                // i.e setting Navigtaion.upItem doesn't fallthrough to parent's
+                // action if it's navigable is false
 
-                    Layout.fillHeight: true
-                    Layout.fillWidth: true
+                if (header.Navigation.navigable)
+                    header.forceActiveFocus(Qt.BacktabFocusReason)
+                else
+                    return false // fallthrough default action
+            }
+        }
 
-                    Navigation.parentItem: root
-                    Navigation.upAction: function () {
-                        // FIXME: for some reason default navigation flow doesn't work
-                        // i.e setting Navigtaion.upItem doesn't fallthrough to parent's
-                        // action if Navigtaion.upItem.Navigtaion.navigble is false
+        ColumnLayout {
+            id: layout
 
-                        if (header.Navigation.navigable)
-                            header.forceActiveFocus(Qt.TabFocusReason)
-                        else
-                            return false // fallthrough default action
-                    }
-                }
+            anchors.fill: parent
 
-                Item {
-                    visible: root.loading
+            BrowseTreeHeader {
+                id: header
 
-                    Layout.fillHeight: true
-                    Layout.fillWidth: true
+                focus: true
 
-                    Widgets.BusyIndicatorExt {
-                        id: busyIndicator
+                providerModel: root.model
 
-                        runningDelayed: root.loading
-                        anchors.centerIn: parent
-                        z: 1
-                    }
-                }
+                Layout.fillWidth: true
+
+                Navigation.parentItem: root
+                Navigation.downItem: (view.Navigation.navigable) ? view : null
             }
         }
-
     }
 }


=====================================
modules/gui/qt/network/qml/BrowseTreeHeader.qml
=====================================
@@ -28,7 +28,7 @@ import "qrc:///util/Helpers.js" as Helpers
 import "qrc:///widgets/" as Widgets
 import "qrc:///style/"
 
-T.Control {
+T.Pane {
     id: root
 
     // Network* model
@@ -40,28 +40,20 @@ T.Control {
         colorSet: ColorContext.View
     }
 
-    height: implicitHeight
-    implicitHeight: layout.implicitHeight + topPadding + bottomPadding
-
     topPadding: VLCStyle.layoutTitle_top_padding
     bottomPadding: VLCStyle.layoutTitle_bottom_padding
 
-    focus: medialibraryBtn.visible
+    height: implicitHeight
+    implicitHeight: layout.implicitHeight + topPadding + bottomPadding
+    implicitWidth: layout.implicitWidth + leftPadding + rightPadding
 
+    focus: medialibraryBtn.visible
     Navigation.navigable: medialibraryBtn.visible
 
     RowLayout {
         id: layout
 
-        anchors {
-            fill: parent
-
-            leftMargin: root.leftPadding
-            rightMargin: root.rightPadding
-
-            topMargin: root.topPadding
-            bottomMargin: root.bottomPadding
-        }
+        anchors.fill: parent
 
         Widgets.SubtitleLabel {
             text: providerModel.name



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/24e663be6f40820db3c12f32f0d2772ef7abaaff...4fc045f1ea19cdf6e6f524e97021b30031efea77

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/24e663be6f40820db3c12f32f0d2772ef7abaaff...4fc045f1ea19cdf6e6f524e97021b30031efea77
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