Commit 55a6bd71 authored by Michael Pyne's avatar Michael Pyne

Fix drag-and-drop of playlist items onto a playlist icon.

This allows you to drag music tracks onto a different playlist, by
dropping the selected tracks onto the name of a different playlist.

There still seem to be other bugs (Dragging items onto play queue
doesn't enable play queue automatically; some playlists aren't properly
saved for some reason). But those will have to be fixed in other
commits.

FIXED-IN:19.04.3
BUG:392705
parent 98995507
Pipeline #4559 passed with stage
in 11 minutes and 19 seconds
......@@ -75,6 +75,8 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
setHeaderLabel("Playlists");
setRootIsDecorated(false);
setContextMenuPolicy(Qt::CustomContextMenu);
viewport()->setAcceptDrops(true);
setDragDropMode(QAbstractItemView::DropOnly);
setDropIndicatorShown(true);
setColumnCount(2); // Use fake column for sorting
......@@ -86,8 +88,6 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
header()->hide();
header()->blockSignals(false);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
setSelectionMode(QAbstractItemView::ExtendedSelection);
m_contextMenu = new QMenu(this);
......@@ -293,6 +293,49 @@ void PlaylistBox::removePlaylist(Playlist *playlist)
m_playlistDict.remove(playlist);
}
Qt::DropActions PlaylistBox::supportedDropActions() const
{
return Qt::CopyAction;
}
bool PlaylistBox::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
{
Q_UNUSED(index);
// The *parent* item won't be null, but index should be zero except in the
// still-broken "tree view" mode.
if(!parent || action != Qt::CopyAction || !data->hasUrls()) {
return false;
}
auto *playlistItem = static_cast<Item *>(parent);
if(!playlistItem) {
return false;
}
auto *playlist = playlistItem->playlist();
const auto droppedUrls = data->urls();
PlaylistItem *lastItem = nullptr;
for(const auto &url : droppedUrls) {
lastItem = playlist->createItem(FileHandle(url.toLocalFile()), lastItem);
}
return true;
}
QStringList PlaylistBox::mimeTypes() const
{
auto result = QTreeWidget::mimeTypes();
// Need to add Playlists's mime type to convince QTreeWidget to allow it as
// a drop option.
result.append(QLatin1String("text/uri-list"));
return result;
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox private methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -81,6 +81,9 @@ public slots:
protected:
virtual void setupPlaylist(Playlist *playlist, const QString &iconName) override;
virtual void removePlaylist(Playlist *playlist) override;
virtual Qt::DropActions supportedDropActions() const override;
virtual bool dropMimeData(QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction) override;
virtual QStringList mimeTypes() const override;
signals:
void signalPlaylistDestroyed(Playlist *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment