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

MediaLibraryView: Drag and Drop by QtGui api

parent 8c222c11
......@@ -132,6 +132,7 @@ nodist_vlmc_SOURCES = \
src/Library/Library.moc.cpp \
src/Library/MediaLibrary.moc.cpp \
src/Library/MediaLibraryModel.moc.cpp \
src/Gui/library/MediaLibraryView.moc.cpp \
$(NULL)
vlmc_RC = \
......
......@@ -35,6 +35,8 @@
#include <QtQuick/QQuickView>
#include <QQmlContext>
#include <QUrl>
#include <QDrag>
#include <QMimeData>
MediaLibraryView::MediaLibraryView( QWidget* parent )
: QObject( parent )
......@@ -47,6 +49,7 @@ MediaLibraryView::MediaLibraryView( QWidget* parent )
auto ctx = view->rootContext();
ctx->setContextProperty( QStringLiteral( "mlModel" ), Core::instance()->mediaLibrary()->model( MediaLibrary::MediaType::Video ) );
ctx->setContextProperty( QStringLiteral( "view" ), this );
view->setSource( QUrl( QStringLiteral( "qrc:/qml/MediaLibraryView.qml" ) ) );
view->setResizeMode(QQuickView::SizeRootObjectToView);
......@@ -61,3 +64,18 @@ MediaLibraryView::container()
{
return m_container;
}
void
MediaLibraryView::startDrag( const QString& mediaPath, const QString& thumbnailPath )
{
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 ) );
drag->exec();
}
......@@ -27,6 +27,7 @@
class MediaLibraryView : public QObject
{
Q_OBJECT
Q_DISABLE_COPY( MediaLibraryView )
public:
......@@ -35,6 +36,9 @@ class MediaLibraryView : public QObject
QWidget* container();
public slots:
void startDrag( const QString& mediaPath, const QString& thumbnailPath );
private:
QWidget* m_container;
};
......
......@@ -52,16 +52,12 @@ Rectangle {
}
}
Drag.active: dragArea.drag.active
Drag.dragType: Drag.Automatic
Drag.mimeData: {
"vlmc/uuid":"test",
}
MouseArea {
id: dragArea
drag.target: parent
anchors.fill: parent
onPressed: {
view.startDrag( "", thumbnailPath );
}
onClicked: gridView.currentIndex = index
}
}
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