[vlc-commits] qml: factorize mouse interaction in grid views

Pierre Lamot git at videolan.org
Mon Sep 28 09:38:12 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Sep 23 11:51:12 2020 +0200| [5e6eb159bb5579c3a6d27017e89b50d5d346169f] | committer: Pierre Lamot

qml: factorize mouse interaction in grid views

  right clicking an unselected item will now select it and drop the current
  selection.

  fixes: #23144

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

 modules/gui/qt/medialibrary/qml/MusicAlbums.qml         |  7 ++-----
 modules/gui/qt/medialibrary/qml/MusicArtist.qml         | 11 +++++------
 modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml | 11 +++++------
 modules/gui/qt/medialibrary/qml/MusicGenres.qml         |  8 +++-----
 modules/gui/qt/medialibrary/qml/VideoDisplay.qml        | 15 +++++++--------
 modules/gui/qt/network/qml/NetworkBrowseDisplay.qml     |  7 ++-----
 modules/gui/qt/widgets/qml/ExpandGridView.qml           | 12 ++++++++++++
 7 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index a918b0deea..983af41afd 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -122,17 +122,14 @@ Widgets.NavigableFocusScope {
 
                 opacity: gridView_id.expandIndex !== -1 && gridView_id.expandIndex !== audioGridItem.index ? .7 : 1
 
-                onItemClicked : {
-                    selectionModel.updateSelection( modifier , root.currentIndex, index)
-                    gridView_id.currentIndex = index
-                    gridView_id.forceActiveFocus()
-                }
+                onItemClicked : gridView_id.leftClickOnItem(modifier, index)
 
                 onItemDoubleClicked: {
                     if ( model.id !== undefined ) { medialib.addAndPlay( model.id ) }
                 }
 
                 onContextMenuButtonClicked: {
+                    gridView_id.rightClickOnItem(index)
                     contextMenu.popup(selectionModel.selectedIndexes, globalMousePos, {
                         "information": index
                     })
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtist.qml b/modules/gui/qt/medialibrary/qml/MusicArtist.qml
index 4be675f22a..1ba3461b62 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtist.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtist.qml
@@ -253,17 +253,16 @@ Widgets.NavigableFocusScope {
 
                 opacity: gridView_id.expandIndex !== -1 && gridView_id.expandIndex !== audioGridItem.index ? .7 : 1
 
-                onItemClicked : {
-                    albumSelectionModel.updateSelection( modifier , gridView_id.currentIndex, index )
-                    gridView_id.currentIndex = index
-                    gridView_id.forceActiveFocus()
-                }
+                onItemClicked : gridView_id.leftClickOnItem(modifier, index)
 
                 onItemDoubleClicked: {
                     if ( model.id !== undefined ) { medialib.addAndPlay( model.id ) }
                 }
 
-                onContextMenuButtonClicked: contextMenu.popup(albumSelectionModel.selectedIndexes, globalMousePos, { "information" : index})
+                onContextMenuButtonClicked: {
+                    gridView_id.rightClickOnItem(index)
+                    contextMenu.popup(albumSelectionModel.selectedIndexes, globalMousePos, { "information" : index})
+                }
 
                 Behavior on opacity {
                     NumberAnimation {
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index e4f91490a2..a7ca1b6646 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -170,15 +170,14 @@ Widgets.NavigableFocusScope {
                         textHorizontalAlignment: Text.AlignHCenter
                         width: VLCStyle.colWidth(1)
 
-                        onItemClicked: {
-                            selectionModel.updateSelection( modifier , view.currentItem.currentIndex, index )
-                            view.currentItem.currentIndex = index
-                            view.currentItem.forceActiveFocus()
-                        }
+                        onItemClicked: artistGrid.leftClickOnItem(modifier, index)
 
                         onItemDoubleClicked: artistAllView.showAlbumView(model)
 
-                        onContextMenuButtonClicked: contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
+                        onContextMenuButtonClicked: {
+                            artistGrid.rightClickOnItem(index)
+                            contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
+                        }
                     }
                 }
             }
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index 94c6594ff2..b74d7aaf94 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -146,17 +146,15 @@ Widgets.NavigableFocusScope {
                 playCoverBorder.width: VLCStyle.dp(3, VLCStyle.scale)
 
                 onItemDoubleClicked: root.showAlbumView(model)
-                onItemClicked: {
-                    selectionModel.updateSelection( modifier , view.currentItem.currentIndex, index)
-                    view.currentItem.currentIndex = index
-                    view.currentItem.forceActiveFocus()
-                }
+                onItemClicked: gridView_id.leftClickOnItem(index)
+
                 onPlayClicked: {
                     if (model.id)
                         medialib.addAndPlay(model.id)
                 }
 
                 onContextMenuButtonClicked: {
+                    gridView_id.rightClickOnItem(index)
                     contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
                 }
 
diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index cc2ef46566..73da8c1e4e 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -113,16 +113,15 @@ Widgets.NavigableFocusScope {
 
                 opacity: videosGV.expandIndex !== -1 && videosGV.expandIndex !== videoGridItem.index ? .7 : 1
 
-                onContextMenuButtonClicked:  contextMenu.popup(selectionModel.selectedIndexes, globalMousePos, {
-                    "information" : index
-                } )
-
-                onItemClicked : {
-                    selectionModel.updateSelection( modifier , videosGV.currentIndex, index)
-                    videosGV.currentIndex = index
-                    videosGV.forceActiveFocus()
+                onContextMenuButtonClicked: {
+                    videosGV.rightClickOnItem(index)
+                    contextMenu.popup(selectionModel.selectedIndexes, globalMousePos, {
+                        "information" : index
+                    } )
                 }
 
+                onItemClicked : videosGV.leftClickOnItem(modifier, index)
+
                 Behavior on opacity {
                     NumberAnimation {
                         duration: 100
diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index e5b78f1097..90e4138e57 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -143,11 +143,7 @@ Widgets.NavigableFocusScope {
                 height: VLCStyle.gridCover_network_height + VLCStyle.margin_xsmall + VLCStyle.fontHeight_normal
 
                 onPlayClicked: selectionModel.model.addAndPlay( index )
-                onItemClicked : {
-                    selectionModel.updateSelection( modifier ,  view.currentItem.currentIndex, index)
-                    view.currentItem.currentIndex = index
-                    delegateGrid.forceActiveFocus()
-                }
+                onItemClicked : gridView.leftClickOnItem(modifier, index)
 
                 onItemDoubleClicked: {
                     if (model.type === NetworkMediaModel.TYPE_NODE || model.type === NetworkMediaModel.TYPE_DIRECTORY)
@@ -157,6 +153,7 @@ Widgets.NavigableFocusScope {
                 }
 
                 onContextMenuButtonClicked: {
+                    gridView.rightClickOnItem(index)
                     contextMenu.popup(selectionModel.selectedIndexes, globalMousePos)
                 }
             }
diff --git a/modules/gui/qt/widgets/qml/ExpandGridView.qml b/modules/gui/qt/widgets/qml/ExpandGridView.qml
index 94cfbe2300..21f484f1e5 100644
--- a/modules/gui/qt/widgets/qml/ExpandGridView.qml
+++ b/modules/gui/qt/widgets/qml/ExpandGridView.qml
@@ -166,6 +166,18 @@ NavigableFocusScope {
             animateFlickableContentY(newContentY)
     }
 
+    function leftClickOnItem(modifier, index) {
+        delegateModel.updateSelection( modifier , currentIndex, index)
+        currentIndex = index
+        root.forceActiveFocus()
+    }
+
+    function rightClickOnItem(index) {
+        if (!delegateModel.isSelected(model.index(index, 0))) {
+            root.leftClickOnItem(Qt.NoModifier, index)
+        }
+    }
+
     function _updateSelected() {
         for (var id in _idChildrenMap) {
             var item = _idChildrenMap[id]



More information about the vlc-commits mailing list