[vlmc-devel] MediaLibraryView: Drag media with its id
Yikai Lu
git at videolan.org
Fri Aug 19 12:09:42 CEST 2016
vlmc | branch: medialibrary | Yikai Lu <luyikei.qmltu at gmail.com> | Fri Aug 19 00:38:59 2016 -0500| [19322c9e48f343d880e44e79f933338919422c06] | committer: Hugo Beauzée-Luyssen
MediaLibraryView: Drag media with its id
> https://code.videolan.org/videolan/vlmc/commit/19322c9e48f343d880e44e79f933338919422c06
---
src/Gui/library/MediaLibraryView.cpp | 23 +++++++++++++++++------
src/Gui/library/MediaLibraryView.h | 2 +-
src/Gui/library/ui/MediaItem.qml | 3 ++-
src/Gui/library/ui/MediaLibraryView.qml | 1 +
4 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/Gui/library/MediaLibraryView.cpp b/src/Gui/library/MediaLibraryView.cpp
index 74337a8..b213f68 100644
--- a/src/Gui/library/MediaLibraryView.cpp
+++ b/src/Gui/library/MediaLibraryView.cpp
@@ -26,9 +26,14 @@
#include "MediaLibraryView.h"
+#include "Library/Library.h"
#include "Library/MediaLibrary.h"
#include "Library/MediaLibraryModel.h"
#include "Main/Core.h"
+#include "Media/Media.h"
+#include "Media/Clip.h"
+
+#include <medialibrary/IMedia.h>
#include <QBoxLayout>
#include <QListView>
@@ -66,16 +71,22 @@ MediaLibraryView::container()
}
void
-MediaLibraryView::startDrag( const QString& mediaPath, const QString& thumbnailPath )
+MediaLibraryView::startDrag( qint64 mediaId )
{
- Q_UNUSED( mediaPath )
-
QDrag* drag = new QDrag( this );
QMimeData* mimeData = new QMimeData;
- drag->setMimeData( mimeData );
- drag->setPixmap( QPixmap( thumbnailPath.isEmpty() ? QStringLiteral( ":/images/vlmc" ) : thumbnailPath )
- .scaled( 100, 100, Qt::KeepAspectRatio ) );
+ QSharedPointer<Media> media = Core::instance()->library()->media( mediaId );
+ if ( media == nullptr ) {
+ media.reset( new Media( Core::instance()->mediaLibrary()->model( MediaLibrary::MediaType::Video )->findMedia( mediaId ) ) );
+ Core::instance()->library()->addMedia( media );
+ }
+ mimeData->setData( QStringLiteral( "vlmc/uuid" ), media->baseClip()->uuid().toByteArray() );
+
+ drag->setMimeData( mimeData );
+ auto thumbnailPath = media->snapshot();
+ drag->setPixmap( QPixmap( thumbnailPath.isEmpty() ? QStringLiteral( ":/images/vlmc" ) :
+ thumbnailPath ).scaled( 100, 100, Qt::KeepAspectRatio ) );
drag->exec();
}
diff --git a/src/Gui/library/MediaLibraryView.h b/src/Gui/library/MediaLibraryView.h
index ce5d171..4eba65c 100644
--- a/src/Gui/library/MediaLibraryView.h
+++ b/src/Gui/library/MediaLibraryView.h
@@ -37,7 +37,7 @@ class MediaLibraryView : public QObject
QWidget* container();
public slots:
- void startDrag( const QString& mediaPath, const QString& thumbnailPath );
+ void startDrag( qint64 mediaId );
private:
QWidget* m_container;
diff --git a/src/Gui/library/ui/MediaItem.qml b/src/Gui/library/ui/MediaItem.qml
index 1400d89..9510f11 100644
--- a/src/Gui/library/ui/MediaItem.qml
+++ b/src/Gui/library/ui/MediaItem.qml
@@ -9,6 +9,7 @@ Rectangle {
property string thumbnailPath
property string title
property int duration
+ property int mediaId
Image {
id: thumbnail
@@ -56,7 +57,7 @@ Rectangle {
id: dragArea
anchors.fill: parent
onPressed: {
- view.startDrag( "", thumbnailPath );
+ view.startDrag( mediaId );
}
onClicked: gridView.currentIndex = index
}
diff --git a/src/Gui/library/ui/MediaLibraryView.qml b/src/Gui/library/ui/MediaLibraryView.qml
index d058fd9..af80e8b 100644
--- a/src/Gui/library/ui/MediaLibraryView.qml
+++ b/src/Gui/library/ui/MediaLibraryView.qml
@@ -60,6 +60,7 @@ Rectangle {
duration: model.duration
thumbnailPath: model.thumbnailPath
title: model.title
+ mediaId: model.id
}
}
}
More information about the Vlmc-devel
mailing list