[vlc-commits] qml: generalize Playlist drop functionality using new interface PlaylistDroppable
Prince Gupta
git at videolan.org
Thu Dec 10 09:34:46 UTC 2020
vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Wed Nov 11 20:37:17 2020 +0530| [ad260e2d2954bf86159ff21f80a79753aaa97559] | committer: Pierre Lamot
qml: generalize Playlist drop functionality using new interface PlaylistDroppable
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ad260e2d2954bf86159ff21f80a79753aaa97559
---
modules/gui/qt/Makefile.am | 1 +
modules/gui/qt/playlist/qml/PLItem.qml | 78 +++++------------------
modules/gui/qt/playlist/qml/PlaylistDroppable.qml | 31 +++++++++
modules/gui/qt/playlist/qml/PlaylistListView.qml | 59 ++++++++++-------
modules/gui/qt/vlc.qrc | 1 +
modules/gui/qt/widgets/qml/DNDLabel.qml | 16 +++--
6 files changed, 96 insertions(+), 90 deletions(-)
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 8ac71d4b81..77c590c378 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -678,6 +678,7 @@ libqt_plugin_la_QML = \
gui/qt/player/qml/VolumeWidget.qml \
gui/qt/player/qml/ButtonsLayout.qml \
gui/qt/playlist/qml/PLItem.qml \
+ gui/qt/playlist/qml/PlaylistDroppable.qml \
gui/qt/playlist/qml/PlaylistListView.qml \
gui/qt/playlist/qml/PlaylistMenu.qml \
gui/qt/playlist/qml/PlaylistToolbar.qml \
diff --git a/modules/gui/qt/playlist/qml/PLItem.qml b/modules/gui/qt/playlist/qml/PLItem.qml
index e5bc926da1..d26deb0902 100644
--- a/modules/gui/qt/playlist/qml/PLItem.qml
+++ b/modules/gui/qt/playlist/qml/PLItem.qml
@@ -67,6 +67,10 @@ Rectangle {
}
+ function isDropAcceptable(drop, index) {
+ console.assert(false, "parent should reimplement this function")
+ }
+
onHoveredChanged: {
if(hovered)
showTooltip(false)
@@ -284,26 +288,14 @@ Rectangle {
Layout.preferredHeight: parent.height / 2
onEntered: {
- var delta = 1
-
- if(!drag.hasUrls)
- delta = drag.source.model.index - model.index
-
- if(delta === 0 || delta === -1)
- return
-
- root.setItemDropIndicatorVisible(model.index, true, true)
+ if (isDropAcceptable(drag, model.index))
+ root.setItemDropIndicatorVisible(model.index, true, true)
}
onExited: {
root.setItemDropIndicatorVisible(model.index, false, true)
}
onDropped: {
- var delta = 1
-
- if(!drop.hasUrls)
- delta = drag.source.model.index - model.index
-
- if(delta === 0 || delta === -1)
+ if (!isDropAcceptable(drop, model.index))
return
plitem.dropedMovedAt(model.index, drop)
@@ -316,64 +308,24 @@ Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
- property bool _isLastItem : model.index === plitem.plmodel.count - 1
+ readonly property bool _isLastItem: model.index === plitem.plmodel.count - 1
+ readonly property int _targetIndex: _isLastItem ? model.index + 1 : model.index
onEntered: {
- var delta = -1
-
- if(!drag.hasUrls)
- delta = drag.source.model.index - model.index
-
- if(delta === 0 || delta === 1)
+ if (!isDropAcceptable(drag, _targetIndex))
return
- if (_isLastItem)
- {
- root.setItemDropIndicatorVisible(model.index, true, false);
- }
- else
- {
- root.setItemDropIndicatorVisible(model.index + 1, true, true);
- }
+ root.setItemDropIndicatorVisible(_targetIndex, true, !_isLastItem)
}
onExited: {
- if (_isLastItem)
- {
- root.setItemDropIndicatorVisible(model.index, false, false);
- }
- else
- {
- root.setItemDropIndicatorVisible(model.index + 1, false, true);
- }
+ root.setItemDropIndicatorVisible(_targetIndex, false, !_isLastItem)
}
onDropped: {
- var delta = -1
-
- if(!drop.hasUrls)
- delta = drag.source.model.index - model.index
-
- if(delta === 0 || delta === 1)
+ if(!isDropAcceptable(drop, _targetIndex))
return
- if (_isLastItem)
- {
- if (drop.hasUrls) {
- //force conversion to an actual list
- var urlList = []
- for ( var url in drop.urls)
- urlList.push(drop.urls[url])
- mainPlaylistController.insert(root.plmodel.count, urlList, false)
- } else {
- root.plmodel.moveItemsPost(root.plmodel.getSelection(), root.plmodel.count - 1)
- }
- root.setItemDropIndicatorVisible(model.index, false, false);
- drop.accept(Qt.IgnoreAction)
- }
- else
- {
- plitem.dropedMovedAt(model.index + 1, drop)
- root.setItemDropIndicatorVisible(model.index + 1, false, true);
- }
+ plitem.dropedMovedAt(_targetIndex, drop)
+ root.setItemDropIndicatorVisible(_targetIndex, false, !_isLastItem)
}
}
}
diff --git a/modules/gui/qt/playlist/qml/PlaylistDroppable.qml b/modules/gui/qt/playlist/qml/PlaylistDroppable.qml
new file mode 100644
index 0000000000..671990fb9f
--- /dev/null
+++ b/modules/gui/qt/playlist/qml/PlaylistDroppable.qml
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+import QtQuick 2.11
+
+Item {
+ id: root
+
+ function insertIntoPlaylist(index /* <int>: index to insert at*/) {
+ console.assert(false, "parent should reimplement this function")
+ }
+
+ function canInsertIntoPlaylist(index) {
+ return true
+ }
+}
+
diff --git a/modules/gui/qt/playlist/qml/PlaylistListView.qml b/modules/gui/qt/playlist/qml/PlaylistListView.qml
index 8089b1e1ae..91474986ed 100644
--- a/modules/gui/qt/playlist/qml/PlaylistListView.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistListView.qml
@@ -43,6 +43,25 @@ Widgets.NavigableFocusScope {
signal setItemDropIndicatorVisible(int index, bool isVisible, bool top)
+ function isDropAcceptable(drop, index) {
+ return drop.hasUrls
+ || ((!!drop.source && (drop.source instanceof PlaylistDroppable))
+ && drop.source.canInsertIntoPlaylist(index))
+ }
+
+ function acceptDrop(index, drop) {
+ if (!!drop.source && (drop.source instanceof PlaylistDroppable)) {
+ drop.source.insertIntoPlaylist(index)
+ } else if (drop.hasUrls) {
+ //force conversion to an actual list
+ var urlList = []
+ for ( var url in drop.urls)
+ urlList.push(drop.urls[url])
+ mainPlaylistController.insert(index, urlList, false)
+ }
+ drop.accept(Qt.IgnoreAction)
+ }
+
VLCColors {id: vlcNightColors; state: "night"}
function sortPL(key) {
@@ -71,6 +90,15 @@ Widgets.NavigableFocusScope {
property int _scrollingDirection: 0
+ function insertIntoPlaylist(index) {
+ root.plmodel.moveItemsPre(root.plmodel.getSelection(), index)
+ }
+
+ function canInsertIntoPlaylist(index) {
+ var delta = model.index - index
+ return delta !== 0 && delta !== -1 && index !== model.index
+ }
+
on_PosChanged: {
var dragItemY = root.mapToGlobal(dragItem._pos.x, dragItem._pos.y).y
var viewY = root.mapToGlobal(view.x, view.y).y
@@ -421,7 +449,7 @@ Widgets.NavigableFocusScope {
DropArea {
anchors.fill: parent
onEntered: {
- if(!drag.hasUrls && drag.source.model.index === root.plmodel.count - 1)
+ if(!root.isDropAcceptable(drag, root.plmodel.count))
return
root.setItemDropIndicatorVisible(view.modelCount - 1, true, false);
@@ -432,20 +460,10 @@ Widgets.NavigableFocusScope {
root.setItemDropIndicatorVisible(view.modelCount - 1, false, false);
}
onDropped: {
- if(!drop.hasUrls && drop.source.model.index === root.plmodel.count - 1)
+ if(!root.isDropAcceptable(drop, root.plmodel.count))
return
-
- if (drop.hasUrls) {
- //force conversion to an actual list
- var urlList = []
- for ( var url in drop.urls)
- urlList.push(drop.urls[url])
- mainPlaylistController.insert(root.plmodel.count, urlList, false)
- } else {
- root.plmodel.moveItemsPost(root.plmodel.getSelection(), root.plmodel.count - 1)
- }
+ root.acceptDrop(root.plmodel.count, drop)
root.setItemDropIndicatorVisible(view.modelCount - 1, false, false);
- drop.accept()
}
}
}
@@ -520,17 +538,12 @@ Widgets.NavigableFocusScope {
}
}
+ function isDropAcceptable(drop, index) {
+ return root.isDropAcceptable(drop, index)
+ }
+
onDropedMovedAt: {
- if (drop.hasUrls) {
- //force conversion to an actual list
- var urlList = []
- for ( var url in drop.urls)
- urlList.push(drop.urls[url])
- mainPlaylistController.insert(target, urlList, false)
- drop.accept(Qt.IgnoreAction)
- } else {
- root.plmodel.moveItemsPre(root.plmodel.getSelection(), target)
- }
+ root.acceptDrop(target, drop)
}
onHoveredChanged: {
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 3d1cf4284e..8b772d5f49 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -285,6 +285,7 @@
</qresource>
<qresource prefix="/playlist">
<file alias="PLItem.qml">playlist/qml/PLItem.qml</file>
+ <file alias="PlaylistDroppable.qml">playlist/qml/PlaylistDroppable.qml</file>
<file alias="PlaylistListView.qml">playlist/qml/PlaylistListView.qml</file>
<file alias="PlaylistMenu.qml">playlist/qml/PlaylistMenu.qml</file>
<file alias="PlaylistToolbar.qml">playlist/qml/PlaylistToolbar.qml</file>
diff --git a/modules/gui/qt/widgets/qml/DNDLabel.qml b/modules/gui/qt/widgets/qml/DNDLabel.qml
index d6e209245a..dfc0e0b8c7 100644
--- a/modules/gui/qt/widgets/qml/DNDLabel.qml
+++ b/modules/gui/qt/widgets/qml/DNDLabel.qml
@@ -22,22 +22,30 @@ import QtGraphicalEffects 1.0
import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
+import "qrc:///playlist/" as Playlist
import "qrc:///style/"
-Rectangle {
+Playlist.PlaylistDroppable {
property alias text: label.text
property alias model: plitem.model
+ property alias color: bg.color
property VLCColors _colors: VLCStyle.colors
z: 1
width: plitem.visible ? plitem.width : label.width
height: plitem.visible ? plitem.height : label.height
- color: _colors.button
- border.color : _colors.buttonBorder
- radius: 6
opacity: 0.75
visible: false
+ Rectangle {
+ id: bg
+
+ anchors.fill: parent
+ color: _colors.button
+ border.color : _colors.buttonBorder
+ radius: 6
+ }
+
Drag.active: visible
property var count: 0
More information about the vlc-commits
mailing list