[vlmc-devel] Add ClipLibraryView.cpp

Yikai Lu git at videolan.org
Mon Dec 12 04:20:02 CET 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sun Dec 11 21:14:42 2016 -0600| [749aa66110b04aaf00a3d7c3af7e59691e421f7f] | committer: Yikai Lu

Add ClipLibraryView.cpp

> https://code.videolan.org/videolan/vlmc/commit/749aa66110b04aaf00a3d7c3af7e59691e421f7f
---

 src/Gui/library/ClipLibraryView.cpp | 91 +++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/src/Gui/library/ClipLibraryView.cpp b/src/Gui/library/ClipLibraryView.cpp
new file mode 100644
index 0000000..d8703f9
--- /dev/null
+++ b/src/Gui/library/ClipLibraryView.cpp
@@ -0,0 +1,91 @@
+#include "ClipLibraryView.h"
+
+#include "Library/Library.h"
+#include "Main/Core.h"
+#include "Media/Clip.h"
+#include "Media/Media.h"
+#include "Tools/VlmcDebug.h"
+
+#include <QUuid>
+#include <QDrag>
+#include <QMimeData>
+#include <QtQuick/QQuickView>
+#include <QtQml/QQmlContext>
+
+ClipLibraryView::ClipLibraryView( QWidget* parent )
+    : QObject( parent )
+{
+    setObjectName( QStringLiteral( "Clip Library" ) );
+    auto view = new QQuickView;
+    m_container = QWidget::createWindowContainer( view, parent );
+    m_container->setMinimumSize( 100, 1 );
+    m_container->setObjectName( objectName() );
+
+    view->rootContext()->setContextProperty( QStringLiteral( "view" ), this );
+    view->setSource( QUrl( QStringLiteral( "qrc:/QML/ClipLibraryView.qml" ) ) );
+    view->setResizeMode( QQuickView::SizeRootObjectToView );
+
+    connect( Core::instance()->library(), &Library::clipAdded, this, &ClipLibraryView::onClipAdded );
+    connect( Core::instance()->library(), &Library::clipRemoved, this, &ClipLibraryView::clipRemoved );
+}
+
+QWidget*
+ClipLibraryView::container()
+{
+    return m_container;
+}
+
+QJsonObject
+ClipLibraryView::clip( const QString& uuid )
+{
+    auto clip = Core::instance()->library()->clip( uuid );
+    return QJsonObject{
+        { "uuid", uuid },
+        { "isBaseClip", clip->media()->baseClip() == clip },
+        { "title", clip->media()->title() },
+        { "thumbnailPath", clip->media()->snapshot() },
+        { "mediaId", clip->media()->id() },
+        { "duration", clip->length() },
+        { "onTimeline", clip->onTimeline() },
+    };
+}
+
+void
+ClipLibraryView::onClipAdded( const QString& uuid )
+{
+    auto clip = Core::instance()->library()->clip( uuid );
+    connect( clip.data(), &Clip::onTimelineChanged, this,
+             [this, clip]( bool onTimeline )
+    {
+        emit clipOnTimelineChanged( clip->uuid().toString(), onTimeline );
+    } );
+    emit clipAdded( uuid );
+}
+
+void
+ClipLibraryView::onClipSelected( const QString& uuid )
+{
+    emit clipSelected( uuid );
+}
+
+void
+ClipLibraryView::startDrag( const QString& uuid )
+{
+    auto clip = Core::instance()->library()->clip( uuid );
+    if ( !clip )
+    {
+        vlmcCritical() << "Couldn't find a clip " << uuid;
+        return;
+    }
+
+    QDrag* drag = new QDrag( this );
+    QMimeData* mimeData = new QMimeData;
+
+    mimeData->setData( QStringLiteral( "vlmc/uuid" ), clip->uuid().toByteArray() );
+
+    drag->setMimeData( mimeData );
+    auto thumbnailPath = clip->media()->snapshot();
+    drag->setPixmap( QPixmap( thumbnailPath.isEmpty() ? QStringLiteral( ":/images/vlmc" ) :
+                                thumbnailPath ).scaled( 100, 100, Qt::KeepAspectRatio ) );
+    drag->exec();
+}



More information about the Vlmc-devel mailing list