[vlmc-devel] MediaLibraryView: Set a clip to play ClipPreview when pressed

Yikai Lu git at videolan.org
Mon Dec 12 04:33:58 CET 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sun Dec 11 21:31:44 2016 -0600| [011e16b234c348720c13522ccf8047221d0442ff] | committer: Yikai Lu

MediaLibraryView: Set a clip to play ClipPreview when pressed

> https://code.videolan.org/videolan/vlmc/commit/011e16b234c348720c13522ccf8047221d0442ff
---

 src/Gui/MainWindow.cpp               |  5 +++++
 src/Gui/library/MediaLibraryView.cpp | 19 ++++++++++++++-----
 src/Gui/library/MediaLibraryView.h   |  4 ++++
 src/Gui/library/ui/MediaItem.qml     |  2 +-
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index bae570f..58e67ee 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -531,6 +531,11 @@ MainWindow::setupClipPreview()
     {
         renderer->setClip( Core::instance()->library()->clip( uuid ).data() );
     } );
+    connect( m_mediaLibrary, &MediaLibraryView::baseClipSelected, renderer, [renderer]( const QString& uuid )
+    {
+        renderer->setClip( Core::instance()->library()->clip( uuid ).data() );
+    } );
+
 
     KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "keyboard/mediapreview", this );
     connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
diff --git a/src/Gui/library/MediaLibraryView.cpp b/src/Gui/library/MediaLibraryView.cpp
index a216c7d..530cea2 100644
--- a/src/Gui/library/MediaLibraryView.cpp
+++ b/src/Gui/library/MediaLibraryView.cpp
@@ -76,11 +76,6 @@ MediaLibraryView::startDrag( qint64 mediaId )
     QMimeData* mimeData = new QMimeData;
 
     QSharedPointer<Media> media = Core::instance()->library()->media( mediaId );
-    if ( media == nullptr ) {
-        media.reset( new Media( Core::instance()->library()->model( Library::MediaType::Video )->findMedia( mediaId ) ) );
-        Core::instance()->library()->addMedia( media );
-    }
-
     mimeData->setData( QStringLiteral( "vlmc/uuid" ), media->baseClip()->uuid().toByteArray() );
 
     drag->setMimeData( mimeData );
@@ -89,3 +84,17 @@ MediaLibraryView::startDrag( qint64 mediaId )
                                 thumbnailPath ).scaled( 100, 100, Qt::KeepAspectRatio ) );
     drag->exec();
 }
+
+void
+MediaLibraryView::onMediaSelected( qint64 mediaId )
+{
+    QSharedPointer<Media> media = Core::instance()->library()->media( mediaId );
+    if ( media == nullptr ) {
+        media.reset( new Media( Core::instance()->library()->model( Library::MediaType::Video )->findMedia( mediaId ) ) );
+        Core::instance()->library()->addMedia( media );
+    }
+
+    emit baseClipSelected( media->baseClip()->uuid().toString() );
+
+    startDrag( mediaId );
+}
diff --git a/src/Gui/library/MediaLibraryView.h b/src/Gui/library/MediaLibraryView.h
index 4eba65c..77a759e 100644
--- a/src/Gui/library/MediaLibraryView.h
+++ b/src/Gui/library/MediaLibraryView.h
@@ -38,9 +38,13 @@ class MediaLibraryView : public QObject
 
     public slots:
         void    startDrag( qint64 mediaId );
+        void    onMediaSelected( qint64 mediaId );
 
     private:
         QWidget*    m_container;
+
+    signals:
+        void    baseClipSelected( const QString& uuid );
 };
 
 #endif // MEDIALIBRARYVIEW_H
diff --git a/src/Gui/library/ui/MediaItem.qml b/src/Gui/library/ui/MediaItem.qml
index 49daa43..1af7c15 100644
--- a/src/Gui/library/ui/MediaItem.qml
+++ b/src/Gui/library/ui/MediaItem.qml
@@ -58,7 +58,7 @@ Rectangle {
         anchors.fill: parent
         onPressed: {
             gridView.currentIndex = index;
-            view.startDrag( mediaId );
+            view.onMediaSelected( mediaId );
         }
     }
 }



More information about the Vlmc-devel mailing list