Commit 2924fca2 authored by luyikei's avatar luyikei Committed by Hugo Beauzée-Luyssen

MediaLibraryView: Drag media with its id

parent 9241dd22
......@@ -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();
}
......@@ -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;
......
......@@ -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
}
......
......@@ -60,6 +60,7 @@ Rectangle {
duration: model.duration
thumbnailPath: model.thumbnailPath
title: model.title
mediaId: model.id
}
}
}
......
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