Commit bcd0f5e8 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Allow a media to be drag and dropped directly into the media library.

parent 8ae624c4
......@@ -111,3 +111,43 @@ MediaLibrary::filterTypeChanged()
{
filterUpdated( m_ui->filterInput->text() );
}
void
MediaLibrary::dragEnterEvent( QDragEnterEvent *event )
{
if ( event->mimeData()->hasFormat( "TEXT" ) &&
event->mimeData()->data( "TEXT" ).startsWith( "file://" ) )
{
event->accept();
}
else
event->ignore();
}
void
MediaLibrary::dropEvent( QDropEvent *event )
{
if ( event->mimeData()->hasFormat( "TEXT" ) == true )
{
const QString &data = event->mimeData()->data( "TEXT" );
qDebug() << data;
if ( data.startsWith( "file://" ) == false )
{
event->ignore();
return ;
}
Media *media = Library::getInstance()->addMedia( data.mid( 7 ) );
if ( media != NULL )
{
Clip* clip = new Clip( media );
media->setBaseClip( clip );
Library::getInstance()->addClip( clip );
event->accept();
return ;
}
else
qDebug() << "Failed to load media:" << data.mid(7);
}
event->ignore();
}
......@@ -39,6 +39,10 @@ class MediaLibrary : public QWidget
typedef bool (*Filter)( const Clip*, const QString& filter );
explicit MediaLibrary( QWidget *parent = 0);
protected:
void dragEnterEvent( QDragEnterEvent *event );
void dropEvent( QDropEvent *event );
private:
/**
* \return The appropriate filter function
......
......@@ -16,6 +16,9 @@
<height>0</height>
</size>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
......
......@@ -69,11 +69,10 @@ Library::loadProject( const QDomElement& doc )
mrl = projectPath + mrl.mid( Workspace::workspacePrefix.length() );
}
Media* m = addMedia( mrl );
connect( m, SIGNAL( metaDataComputed( const Media* ) ),
this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
m_medias[mrl] = m;
m_nbMediaToLoad.fetchAndAddAcquire( 1 );
m->computeMetadata();
if ( m == NULL )
qWarning() << "Failed to load media" << mrl << "when loading project.";
else
m_nbMediaToLoad.fetchAndAddAcquire( 1 );
}
media = media.nextSiblingElement();
}
......@@ -128,7 +127,13 @@ Library::addMedia( const QFileInfo &fileInfo )
{
Media* media = MediaContainer::addMedia( fileInfo );
if ( media != NULL )
{
setCleanState( false );
connect( media, SIGNAL( metaDataComputed( const Media* ) ),
this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
m_medias[fileInfo.absoluteFilePath()] = media;
media->computeMetadata();
}
return media;
}
......
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