vlc | branch: master | Fatih Uzunoglu <[email protected]> | Fri Jan 8 00:36:56 2021 +0300| [829ad2185ec3c0150af96885e5210d1fa9d05101] | committer: Pierre Lamot
qml: use DragItem in playlist instead of DNDLabel Signed-off-by: Pierre Lamot <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=829ad2185ec3c0150af96885e5210d1fa9d05101 --- modules/gui/qt/playlist/qml/PlaylistDelegate.qml | 31 +++++++++--------- modules/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: { _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
