[vlc-devel] [PATCH 43/55] qml: use DragItem in playlist instead of DNDLabel
Fatih Uzunoglu
fuzun54 at outlook.com
Thu Jan 7 21:36:56 UTC 2021
---
.../gui/qt/playlist/qml/PlaylistDelegate.qml | 31 +++++++-------
.../gui/qt/playlist/qml/PlaylistListView.qml | 40 ++++++++++++++++---
2 files changed, 49 insertions(+), 22 deletions(-)
diff --git a/modules/gui/qt/playlist/qml/PlaylistDelegate.qml b/modules/gui/qt/playlist/qml/PlaylistDelegate.qml
index c774e332e8..8b43aec894 100644
--- a/modules/gui/qt/playlist/qml/PlaylistDelegate.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistDelegate.qml
@@ -162,28 +162,25 @@ Rectangle {
drag.target: dragItem
- Connections {
- target: mouseArea.drag
- onActiveChanged: {
- if (target.active) {
- if (!root.model.isSelected(index)) {
- /* the dragged item is not in the selection, replace the selection */
- root.model.setSelection([index])
- }
- dragItem.model = root.model
- dragItem.count = root.model.getSelection().length
- dragItem.visible = true
- } else {
- dragItem.Drag.drop()
- dragItem.visible = false
+ drag.onActiveChanged: {
+ if (drag.active) {
+ if (!selected) {
+ /* the dragged item is not in the selection, replace the selection */
+ root.model.setSelection([index])
}
+
+ dragItem.index = index
+ dragItem.Drag.active = drag.active
+ }
+ else {
+ dragItem.Drag.drop()
}
}
onPositionChanged: {
- if (dragItem.visible) {
- var pos = this.mapToGlobal(mouseX, mouseY)
- dragItem.updatePos(pos.x + VLCStyle.dp(15, VLCStyle.scale), pos.y)
+ if (drag.active) {
+ var pos = drag.target.parent.mapFromItem(mouseArea, mouseX, mouseY)
+ dragItem.updatePos(pos)
}
}
diff --git a/modules/gui/qt/playlist/qml/PlaylistListView.qml b/modules/gui/qt/playlist/qml/PlaylistListView.qml
index 6058b3bf1e..fbd36a5ddc 100644
--- a/modules/gui/qt/playlist/qml/PlaylistListView.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistListView.qml
@@ -88,21 +88,51 @@ Widgets.NavigableFocusScope {
listView.forceActiveFocus()
}
- Widgets.DNDLabel {
+ Widgets.DragItem {
id: dragItem
+ property int index: -1
+
colors: root.colors
- color: parent.color
- property int _scrollingDirection: 0
+ function updateComponents(maxCovers) {
+ var count = root.model.selectedCount
+ var selection = root.model.getSelection()
+
+ var title = selection.map(function (index){
+ return root.model.itemAt(index).title
+ }).join(", ")
+
+ var covers = selection.map(function (index) {
+ var artwork = root.model.itemAt(index).artwork
+ return {artwork: (artwork && artwork.toString()) ? artwork : VLCStyle.noArtCover}
+ })
+
+ return ({covers: covers, title: title, count: root.model.selectedCount})
+ }
function insertIntoPlaylist(index) {
root.model.moveItemsPre(root.model.getSelection(), index)
}
function canInsertIntoPlaylist(index) {
- var delta = model.index - index
- return delta !== 0 && delta !== -1 && index !== model.index
+ var diff = dragItem.index - index
+ if (diff === 0 || diff === -1)
+ return false
+ else
+ return true
+ }
+
+ property point _pos: null
+ property int _scrollingDirection: 0
+
+ function updatePos(pos) {
+ dragItem.x = pos.x + VLCStyle.dp(15)
+ dragItem.y = pos.y // y should be same otherwise dropIndicator will not be shown correctly (DropArea cares about itemY not mouseY)
+
+ // since we override position update during dragging with updatePos(),
+ // we have to track the final position:
+ _pos = pos
}
on_PosChanged: {
--
2.27.0
More information about the vlc-devel
mailing list