[vlc-devel] [PATCH 11/15] qml: Create PlaylistMediaDelegate

Benjamin Arnaud benjamin.arnaud at videolabs.io
Thu Mar 11 09:16:55 UTC 2021


---
 modules/gui/qt/Makefile.am                    |  1 +
 .../qml/PlaylistMediaDelegate.qml             | 81 +++++++++++++++++++
 modules/gui/qt/vlc.qrc                        |  1 +
 po/POTFILES.in                                |  1 +
 4 files changed, 84 insertions(+)
 create mode 100644 modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index bc98deb3b2..f762e5035c 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -675,6 +675,7 @@ libqt_plugin_la_QML = \
 	gui/qt/medialibrary/qml/VideoAllDisplay.qml \
 	gui/qt/medialibrary/qml/PlaylistMediaList.qml \
 	gui/qt/medialibrary/qml/PlaylistMedia.qml \
+	gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml \
 	gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml \
 	gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml \
 	gui/qt/medialibrary/qml/VideoDisplayRecentVideos.qml \
diff --git a/modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml b/modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml
new file mode 100644
index 0000000000..b72fcf3c8a
--- /dev/null
+++ b/modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * Copyright (C) 2021 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
+
+import "qrc:///widgets/" as Widgets
+
+Widgets.TableViewDelegate {
+    id: delegate
+
+    //---------------------------------------------------------------------------------------------
+    // Functions
+    //---------------------------------------------------------------------------------------------
+
+    function _applyPosition(drag)
+    {
+        if (root.isDroppable(drag, index) === false) {
+
+            root.hideLine(delegate);
+
+            return;
+        }
+
+        if (index === _getDropIndex(drag.y))
+            root.showLine(delegate, true);
+        else
+            root.showLine(delegate, false);
+    }
+
+    //---------------------------------------------------------------------------------------------
+
+    function _getDropIndex(y)
+    {
+        var size = Math.round(height / 2);
+
+        if (y < size)
+            return index;
+        else
+            return index + 1;
+    }
+
+    //---------------------------------------------------------------------------------------------
+    // Childs
+    //---------------------------------------------------------------------------------------------
+
+    // NOTE: We are usng a single DropArea and a single line Rectangle in PlaylistMedia.
+    DropArea {
+        anchors.fill: parent
+
+        onEntered: _applyPosition(drag)
+
+        onPositionChanged: _applyPosition(drag)
+
+        onExited: root.hideLine(delegate)
+
+        onDropped: {
+            if (isDroppable(drop, index) === false) {
+                root.hideLine(delegate);
+
+                return;
+            }
+
+            root.applyDrop(drop, _getDropIndex(drag.y));
+        }
+    }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index fb620c93bc..4576eb4545 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -276,6 +276,7 @@
         <file alias="VideoAllDisplay.qml">medialibrary/qml/VideoAllDisplay.qml</file>
         <file alias="PlaylistMediaList.qml">medialibrary/qml/PlaylistMediaList.qml</file>
         <file alias="PlaylistMedia.qml">medialibrary/qml/PlaylistMedia.qml</file>
+        <file alias="PlaylistMediaDelegate.qml">medialibrary/qml/PlaylistMediaDelegate.qml</file>
         <file alias="PlaylistMediaDisplay.qml">medialibrary/qml/PlaylistMediaDisplay.qml</file>
         <file alias="VideoPlaylistsDisplay.qml">medialibrary/qml/VideoPlaylistsDisplay.qml</file>
         <file alias="MusicAlbumsDisplay.qml">medialibrary/qml/MusicAlbumsDisplay.qml</file>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ad8c6a6981..eafb5c6adb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -831,6 +831,7 @@ modules/gui/qt/medialibrary/qml/VideoAll.qml
 modules/gui/qt/medialibrary/qml/VideoAllDisplay.qml
 modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
 modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
+modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml
 modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
 modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
 modules/gui/qt/menus/qml/Menubar.qml
-- 
2.25.1



More information about the vlc-devel mailing list