[vlc-commits] qml: expose isSelected API in SelectableDelegate model

Pierre Lamot git at videolan.org
Wed Jun 3 12:06:41 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Feb 26 11:08:20 2020 +0100| [259f9228fba330fd6f3fe02a2192220ca0cf2fd9] | committer: Pierre Lamot

qml: expose isSelected API in SelectableDelegate model

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

 modules/gui/qt/medialibrary/qml/MusicAlbums.qml           |  9 +++++++++
 modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml   |  8 +++++++-
 modules/gui/qt/medialibrary/qml/MusicGenres.qml           | 13 ++++++++++++-
 modules/gui/qt/network/qml/NetworkListItem.qml            |  2 --
 .../gui/qt/network/qml/NetworksSectionSelectableDM.qml    |  6 ++++++
 modules/gui/qt/util/qml/SelectableDelegateModel.qml       | 15 ++++++++++++++-
 modules/gui/qt/widgets/qml/ExpandGridView.qml             |  4 +---
 modules/gui/qt/widgets/qml/KeyNavigableTableView.qml      |  7 ++++++-
 modules/gui/qt/widgets/qml/ListItem.qml                   |  4 +++-
 9 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index 16ab1375c9..b152d964ae 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -85,10 +85,19 @@ Widgets.NavigableFocusScope {
             id: element
 
             Widgets.ListItem {
+                id: listDelegate
+
                 Package.name: "list"
+
                 width: root.width
                 height: VLCStyle.icon_normal + VLCStyle.margin_small
 
+                selected: delegateModelId.isSelected(index)
+                Connections {
+                   target: delegateModelId
+                   onSelectionChanged: listDelegate.selected = delegateModelId.isSelected(index)
+                }
+
                 cover: Image {
                     id: cover_obj
                     fillMode: Image.PreserveAspectFit
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index 73badd0960..d07731b514 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -79,7 +79,13 @@ Widgets.NavigableFocusScope {
             height: VLCStyle.icon_normal + VLCStyle.margin_small
             width: artistList.width
 
-            color: VLCStyle.colors.getBgColor(delegateModel.inSelected, this.hovered, this.activeFocus)
+            property bool selected: delegateModel.isSelected(index)
+            Connections {
+               target: delegateModel
+               onSelectionChanged: selected = delegateModel.isSelected(index)
+            }
+
+            color: VLCStyle.colors.getBgColor(selected, this.hovered, this.activeFocus)
 
             cover: Widgets.RoundImage {
                 source: model.cover || VLCStyle.noArtArtistSmall
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index 7c1a1fb9a1..d88534601e 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -93,10 +93,17 @@ Widgets.NavigableFocusScope {
 
         delegate: Package {
             Widgets.ListItem {
+                id: listDelegate
                 Package.name: "list"
 
                 width: root.width
                 height: VLCStyle.icon_normal + VLCStyle.margin_small
+                selected: delegateModelId.isSelected(index)
+                Connections {
+                   target: delegateModelId
+                   onSelectionChanged: listDelegate.selected = delegateModelId.isSelected(index)
+                }
+
 
                 cover: Image {
                     id: cover_obj
@@ -171,7 +178,11 @@ Widgets.NavigableFocusScope {
                 image: model.cover || VLCStyle.noArtAlbum
                 title: model.name || "Unknown genre"
                 subtitle: ""
-                //selected: element.delegateModelId.inSelected
+                selected: delegateModelId.isSelected( index )
+                Connections {
+                   target: delegateModelId
+                   onSelectionChanged: selected = delegateModelId.isSelected(index)
+                }
 
                 onItemClicked: {
                     delegateModelId.updateSelection( modifier , view.currentItem.currentIndex, index)
diff --git a/modules/gui/qt/network/qml/NetworkListItem.qml b/modules/gui/qt/network/qml/NetworkListItem.qml
index d64b5fe369..2f4287a9ea 100644
--- a/modules/gui/qt/network/qml/NetworkListItem.qml
+++ b/modules/gui/qt/network/qml/NetworkListItem.qml
@@ -33,8 +33,6 @@ Widgets.ListItem {
 
     focus: true
 
-    color: VLCStyle.colors.getBgColor(element.DelegateModel.inSelected, this.hovered, this.activeFocus)
-
     cover: Image {
         id: cover_obj
         fillMode: Image.PreserveAspectFit
diff --git a/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml b/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml
index 8ca62b32ad..b28487f376 100644
--- a/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml
+++ b/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml
@@ -64,6 +64,12 @@ Util.SelectableDelegateModel {
             focus: true
             Package.name: "list"
 
+            selected: delegateModel.isSelected( index )
+            Connections {
+               target: delegateModel
+               onSelectionChanged: delegateList.selected = delegateModel.isSelected(index)
+            }
+
             onItemClicked : {
                 delegateModel.updateSelection( modifier, delegateModel.currentIndex, index )
                 delegateModel.currentIndex = index
diff --git a/modules/gui/qt/util/qml/SelectableDelegateModel.qml b/modules/gui/qt/util/qml/SelectableDelegateModel.qml
index af7fa67ce1..f07ea867a4 100644
--- a/modules/gui/qt/util/qml/SelectableDelegateModel.qml
+++ b/modules/gui/qt/util/qml/SelectableDelegateModel.qml
@@ -25,6 +25,8 @@ DelegateModel {
     property alias selectedGroup: selectedGroup
     readonly property bool hasSelection: selectedGroup.count > 0
 
+    signal selectionChanged()
+
     groups: [
         DelegateModelGroup { id: selectedGroup; name: "selected"; includeByDefault: false }
     ]
@@ -33,20 +35,25 @@ DelegateModel {
         for (var i = from; i <= to; i++) {
             delegateModel.items.get(i).inSelected = true
         }
+        selectionChanged()
     }
     function _delRange(from, to) {
         for (var i = from; i <= to; i++) {
             delegateModel.items.get(i).inSelected = false
         }
+        selectionChanged()
     }
 
     function selectNone() {
-        if (hasSelection)
+        if (hasSelection) {
             selectedGroup.remove(0,selectedGroup.count)
+            selectionChanged()
+        }
     }
 
     function selectAll() {
         delegateModel.items.addGroups(0, delegateModel.items.count, ["selected"])
+        selectionChanged()
     }
 
     function selectedIndexes() {
@@ -58,6 +65,12 @@ DelegateModel {
         return list
     }
 
+    function isSelected( index ) {
+        if (index < 0 || index >= delegateModel.count)
+            return false
+        return items.get(index).inSelected
+    }
+
     function select( index, command ) {
         switch (command) {
             case ItemSelectionModel.Select:
diff --git a/modules/gui/qt/widgets/qml/ExpandGridView.qml b/modules/gui/qt/widgets/qml/ExpandGridView.qml
index 53c4bb4e39..c5296d239a 100644
--- a/modules/gui/qt/widgets/qml/ExpandGridView.qml
+++ b/modules/gui/qt/widgets/qml/ExpandGridView.qml
@@ -160,7 +160,7 @@ NavigableFocusScope {
     function _updateSelected() {
         for (var id in _idChildrenMap) {
             var item = _idChildrenMap[id]
-            item.selected = delegateModel.items.get(id).inSelected
+            item.selected = delegateModel.isSelected(id)
         }
     }
 
@@ -290,9 +290,7 @@ NavigableFocusScope {
             var pos = root.getItemPos(i)
             _defineObjProperty(item, "index", i)
             //theses needs an actual binding
-            //item.selected = Qt.binding(function() { return delegateModel.items.get(i).inSelected })
             item.model = delegateModel.items.get(i).model
-            //console.log("initialize", .inSelected)
 
             //theses properties are always defined in Item
             item.focus = (i === root.currentIndex) && (root._expandIndex === -1)
diff --git a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
index ff07686edb..7c1a8fe03d 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -67,6 +67,11 @@ NavigableFocusScope {
         delegate: Package {
             id: element
             property var rowModel: model
+            property bool selected: delegateModel.isSelected(index)
+            Connections {
+               target: delegateModel
+               onSelectionChanged: element.selected = delegateModel.isSelected(index)
+            }
 
             Rectangle {
                 Package.name: "list"
@@ -74,7 +79,7 @@ NavigableFocusScope {
 
                 width: root.width
                 height: root.rowHeight
-                color: VLCStyle.colors.getBgColor(element.DelegateModel.inSelected, hoverArea.containsMouse, lineView.activeFocus)
+                color: VLCStyle.colors.getBgColor(selected, hoverArea.containsMouse, lineView.activeFocus)
 
                 MouseArea {
                     id: hoverArea
diff --git a/modules/gui/qt/widgets/qml/ListItem.qml b/modules/gui/qt/widgets/qml/ListItem.qml
index 805447958e..b23749bd2c 100644
--- a/modules/gui/qt/widgets/qml/ListItem.qml
+++ b/modules/gui/qt/widgets/qml/ListItem.qml
@@ -43,6 +43,8 @@ NavigableFocusScope {
     property alias color: linerect.color
     property bool showContextButton: false
 
+    property bool selected: false
+
     Keys.onMenuPressed: root.contextMenuButtonClicked(cover_bg)
 
     Accessible.role: Accessible.ListItem
@@ -88,7 +90,7 @@ NavigableFocusScope {
         id: linerect
         anchors.fill: parent
         color: VLCStyle.colors.getBgColor(
-                   root.isSelected, root.hovered,
+                   root.selected, root.hovered,
                    root.activeFocus)
 
         MouseArea {



More information about the vlc-commits mailing list