[vlc-commits] qml: support custom delegate in local menu group

Prince Gupta git at videolan.org
Fri Nov 27 14:52:21 CET 2020


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Fri Nov 20 23:17:36 2020 +0530| [80c8a5cf4f4a56d42ed45cbf5b6b449f59f9513e] | committer: Pierre Lamot

qml: support custom delegate in local menu group

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

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

 modules/gui/qt/maininterface/qml/BannerSources.qml | 58 ++++++++++++----------
 modules/gui/qt/maininterface/qml/MainDisplay.qml   | 18 ++-----
 modules/gui/qt/medialibrary/qml/MusicDisplay.qml   |  7 +++
 modules/gui/qt/network/qml/DiscoverDisplay.qml     | 13 +++++
 4 files changed, 57 insertions(+), 39 deletions(-)

diff --git a/modules/gui/qt/maininterface/qml/BannerSources.qml b/modules/gui/qt/maininterface/qml/BannerSources.qml
index 9a7c91d69c..50572ec303 100644
--- a/modules/gui/qt/maininterface/qml/BannerSources.qml
+++ b/modules/gui/qt/maininterface/qml/BannerSources.qml
@@ -26,7 +26,7 @@ import QtQml.Models 2.11
 import "qrc:///style/"
 import "qrc:///widgets/" as Widgets
 import "qrc:///menus/" as Menus
-
+import "qrc:///util/KeyHelper.js" as KeyHelper
 
 Widgets.NavigableFocusScope {
     id: root
@@ -41,16 +41,15 @@ Widgets.NavigableFocusScope {
     property int subSelectedIndex: 0
 
     signal itemClicked(int index)
-    signal subItemClicked(int index)
 
     property alias sortModel: sortControl.model
     property var contentModel
 
     property alias model: pLBannerSources.model
-    property alias subTabModel: localMenuGroup.model
     signal toogleMenu()
 
     property var extraLocalActions: undefined
+    property alias localMenuDelegate: localMenuGroup.sourceComponent
 
     // Triggered when the toogleView button is selected
     function toggleView () {
@@ -280,42 +279,49 @@ Widgets.NavigableFocusScope {
                     }
 
                     navigationParent: root
-                    navigationRightItem: localMenuGroup
+                    navigationRightItem: localMenuGroup.visible ? localMenuGroup : playlistGroup
                     navigationUpItem: globalMenuGroup
                 }
 
-                Widgets.NavigableRow {
+                Loader {
                     id: localMenuGroup
-                    anchors {
-                        top: parent.top
-                        bottom: parent.bottom
-                        horizontalCenter: parent.horizontalCenter
-                    }
 
-                    visible: !!model
-                    enabled: !!model
+                    anchors.centerIn: parent
+                    focus: !!item && item.focus && item.visible
+                    visible: !!item
+
                     onVisibleChanged: {
                         //reset the focus on the global group when the local group is hidden,
                         //this avoids losing the focus if the subview changes
                         if (!visible && localMenuGroup.focus) {
-                                        localMenuGroup.focus = false
-                                        globalMenuGroup.focus = true
+                            localMenuGroup.focus = false
+                            globalMenuGroup.focus = true
                         }
                     }
 
-                    delegate: Widgets.BannerTabButton {
-                        text: model.displayText
-                        selected: model.index === subSelectedIndex
-                        onClicked:  root.subItemClicked(model.index)
-                        height: localMenuGroup.height
-                        color: VLCStyle.colors.bg
-                        colorSelected: VLCStyle.colors.bg
+                    onItemChanged: {
+                        if (!item)
+                            return
+                        if (item.hasOwnProperty("navigationParent")) {
+                            item.navigationParent = root
+                            item.navigationLeftItem = localContextGroup.enabled ? localContextGroup : undefined
+                            item.navigationRightItem = playlistGroup.enabled ? playlistGroup : undefined
+                            item.navigationUpItem = globalMenuGroup
+                        } else {
+                            item.KeyNavigation.left = localContextGroup.enabled ? localContextGroup : undefined
+                            item.KeyNavigation.right = playlistGroup.enabled ? playlistGroup : undefined
+                            item.KeyNavigation.up = globalMenuGroup
+                            item.Keys.pressed.connect(function (event) {
+                                if (event.accepted)
+                                    return
+                                if (KeyHelper.matchDown(event)) {
+                                    root.navigationDown()
+                                    event.accepted = true
+                                }
+                            })
+                        }
                     }
 
-                    navigationParent: root
-                    navigationLeftItem: localContextGroup.enabled ? localContextGroup : undefined
-                    navigationRightItem: playlistGroup.enabled ? playlistGroup : undefined
-                    navigationUpItem:  globalMenuGroup
                 }
 
                 Widgets.NavigableRow {
@@ -368,7 +374,7 @@ Widgets.NavigableFocusScope {
                     }
 
                     navigationParent: root
-                    navigationLeftItem: localMenuGroup
+                    navigationLeftItem: localMenuGroup.visible ? localMenuGroup : localContextGroup
                     navigationUpItem: globalMenuGroup
                 }
             }
diff --git a/modules/gui/qt/maininterface/qml/MainDisplay.qml b/modules/gui/qt/maininterface/qml/MainDisplay.qml
index ed40c8f714..2579db8650 100644
--- a/modules/gui/qt/maininterface/qml/MainDisplay.qml
+++ b/modules/gui/qt/maininterface/qml/MainDisplay.qml
@@ -56,10 +56,10 @@ Widgets.NavigableFocusScope {
             return miniPlayer.expanded ? miniPlayer : medialibId
         })
 
-        sourcesBanner.subTabModel = stackView.currentItem.tabModel
-        sourcesBanner.sortModel = stackView.currentItem.sortModel
-        sourcesBanner.contentModel = stackView.currentItem.contentModel
-        sourcesBanner.extraLocalActions = stackView.currentItem.extraLocalActions
+        sourcesBanner.localMenuDelegate = Qt.binding(function () { return !!stackView.currentItem.localMenuDelegate ? stackView.currentItem.localMenuDelegate : null })
+        sourcesBanner.sortModel = Qt.binding(function () { return stackView.currentItem.sortModel  })
+        sourcesBanner.contentModel = Qt.binding(function () { return stackView.currentItem.contentModel })
+        sourcesBanner.extraLocalActions = Qt.binding(function () { return stackView.currentItem.extraLocalActions })
         // Restore sourcesBanner state
         sourcesBanner.selectedIndex = pageModel.filter(function (e) {
             return e.listed;
@@ -169,20 +169,12 @@ Widgets.NavigableFocusScope {
                     model: root.tabModel
 
                     onItemClicked: {
-                        sourcesBanner.subTabModel = undefined
+                        sourcesBanner.localMenuDelegate = null
                         var name = root.tabModel.get(index).name
                         selectedIndex = index
                         history.push(["mc", name])
                     }
 
-                    onSubItemClicked: {
-                        subSelectedIndex = index
-                        stackView.currentItem.loadIndex(index)
-                        sortModel = stackView.currentItem.sortModel
-                        contentModel = stackView.currentItem.contentModel
-                        extraLocalActions = stackView.currentItem.extraLocalActions
-                    }
-
                     navigationParent: medialibId
                     navigationDownItem: stackView
                 }
diff --git a/modules/gui/qt/medialibrary/qml/MusicDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicDisplay.qml
index 5e693f9fc8..5dc10cd8d8 100644
--- a/modules/gui/qt/medialibrary/qml/MusicDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicDisplay.qml
@@ -72,4 +72,11 @@ Widgets.PageLoader {
             })
         }
     }
+
+    property Component localMenuDelegate: Widgets.LocalTabBar {
+        currentView: root.view
+        model: tabModel
+
+        onClicked: root.loadIndex(index)
+    }
 }
diff --git a/modules/gui/qt/network/qml/DiscoverDisplay.qml b/modules/gui/qt/network/qml/DiscoverDisplay.qml
index c5c733edbf..49b0f21f24 100644
--- a/modules/gui/qt/network/qml/DiscoverDisplay.qml
+++ b/modules/gui/qt/network/qml/DiscoverDisplay.qml
@@ -67,4 +67,17 @@ Widgets.PageLoader {
             })
         }
     }
+
+    property Component localMenuDelegate: menuDelegate
+
+    Component {
+        id: menuDelegate
+
+        Widgets.LocalTabBar {
+            currentView: root.view
+            model: tabModel
+
+            onClicked: root.loadIndex(index)
+        }
+    }
 }



More information about the vlc-commits mailing list