[vlc-devel] [PATCH 17/23] qml: show contextmenu when right clicked on an item in Playlist listview
Fatih Uzunoglu
fuzun54 at outlook.com
Thu Jul 2 15:22:02 CEST 2020
---
modules/gui/qt/playlist/qml/PLItem.qml | 15 +++-
.../gui/qt/playlist/qml/PlaylistListView.qml | 78 ++++++++++++++++++-
2 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/modules/gui/qt/playlist/qml/PLItem.qml b/modules/gui/qt/playlist/qml/PLItem.qml
index a0bbb576bb..fef3444c9c 100644
--- a/modules/gui/qt/playlist/qml/PLItem.qml
+++ b/modules/gui/qt/playlist/qml/PLItem.qml
@@ -30,9 +30,10 @@ Rectangle {
property var plmodel
- signal itemClicked(int keys, int modifier)
+ signal itemClicked(int button, int modifier)
signal itemDoubleClicked(int keys, int modifier)
signal dragStarting()
+
property alias hovered: mouse.containsMouse
property var dragitem: null
@@ -67,17 +68,23 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
+ acceptedButtons: acceptedButtons | Qt.RightButton
onClicked:{
- root.itemClicked(mouse.buttons, mouse.modifiers);
+ root.itemClicked(mouse.button, mouse.modifiers);
+ }
+ onDoubleClicked: {
+ if (mouse.button !== Qt.RightButton)
+ root.itemDoubleClicked(mouse.buttons, mouse.modifiers);
}
- onDoubleClicked: root.itemDoubleClicked(mouse.buttons, mouse.modifiers);
drag.target: dragItem
Connections {
target: mouse.drag
onActiveChanged: {
+ if (mouse.button === Qt.RightButton)
+ return
if (target.active) {
root.dragStarting()
dragItem.count = plmodel.getSelection().length
@@ -90,6 +97,8 @@ Rectangle {
}
onPressed: {
+ if (mouse.button === Qt.RightButton)
+ return
var pos = this.mapToGlobal( mouseX, mouseY)
dragItem.updatePos(pos.x, pos.y)
}
diff --git a/modules/gui/qt/playlist/qml/PlaylistListView.qml b/modules/gui/qt/playlist/qml/PlaylistListView.qml
index 7e344f7ae2..0136d826b0 100644
--- a/modules/gui/qt/playlist/qml/PlaylistListView.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistListView.qml
@@ -36,6 +36,7 @@ Widgets.NavigableFocusScope {
property int leftPadding: 0
property int rightPadding: 0
property alias backgroundColor: parentRect.color
+ property alias mediaLibAvailable: contextMenu.medialibAvailable
Rectangle {
id: parentRect
@@ -119,6 +120,74 @@ Widgets.NavigableFocusScope {
}
}
+ Widgets.MenuExt {
+ id: contextMenu
+ property var model: ({})
+ property bool medialibAvailable: false
+ closePolicy: Popup.CloseOnReleaseOutside | Popup.CloseOnEscape
+
+ Widgets.MenuItemExt {
+ text: i18n.qtr("Play")
+ icon.source: "qrc:/toolbar/play_b.svg"
+ icon.width: VLCStyle.icon_small
+ icon.height: VLCStyle.icon_small
+ onTriggered: {
+ mainPlaylistController.goTo(contextMenu.model.getSelection()[0], true)
+ }
+ }
+
+ Widgets.MenuItemExt {
+ text: i18n.qtr("Information...")
+ onTriggered: {
+ // not implemented
+ }
+ }
+
+ MenuSeparator { }
+
+ Widgets.MenuItemExt {
+ text: i18n.qtr("Show Containing Directory...")
+ onTriggered: {
+ // not implemented
+ }
+ }
+
+ MenuSeparator { }
+
+ Widgets.MenuItemExt {
+ text: i18n.qtr("Save Playlist to File...")
+ onTriggered: {
+ dialogProvider.savePlayingToPlaylist();
+ }
+ }
+
+ MenuSeparator { }
+
+ Widgets.MenuItemExt {
+ text: i18n.qtr("Remove Selected")
+ icon.source: "qrc:/buttons/playlist/playlist_remove.svg"
+ icon.width: VLCStyle.icon_small
+ icon.height: VLCStyle.icon_small
+ onTriggered: {
+ contextMenu.model.removeItems(contextMenu.model.getSelection())
+ }
+ }
+
+ Widgets.MenuItemExt {
+ text: i18n.qtr("Clear the playlist")
+ icon.source: "qrc:/toolbar/clear.svg"
+ icon.width: VLCStyle.icon_small
+ icon.height: VLCStyle.icon_small
+ onTriggered: {
+ mainPlaylistController.clear()
+ }
+ }
+
+ MenuSeparator { }
+
+ onClosed: contextMenu.parent.forceActiveFocus()
+ }
+
ColumnLayout {
anchors.fill: parent
anchors.bottomMargin: VLCStyle.margin_normal
@@ -201,11 +270,18 @@ Widgets.NavigableFocusScope {
preTarget++
view.currentIndex = selectedIndexes[0]
root.plmodel.moveItemsPre(selectedIndexes, preTarget)
+ return
} else if (view.mode == "select") {
- } else {
+ } else if (!(root.plmodel.isSelected(index) && button === Qt.RightButton)) {
view.updateSelection(modifier, view.currentIndex, index)
view.currentIndex = index
}
+
+ if (button === Qt.RightButton)
+ {
+ contextMenu.model = root.plmodel
+ contextMenu.popup()
+ }
}
onItemDoubleClicked: mainPlaylistController.goTo(index, true)
color: VLCStyle.colors.getBgColor(model.selected, plitem.hovered, plitem.activeFocus)
--
2.25.1
More information about the vlc-devel
mailing list