[vlmc-devel] Use a Qml view to display the media library

Hugo Beauzée-Luyssen git at videolan.org
Mon Jul 4 15:34:53 CEST 2016


vlmc | branch: medialibrary | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Jul  4 15:31:33 2016 +0200| [c2e5d95908ac62846e92b7ec4959f64d73d89889] | committer: Hugo Beauzée-Luyssen

Use a Qml view to display the media library

/!\ WIP /!\

> https://code.videolan.org/videolan/vlmc/commit/c2e5d95908ac62846e92b7ec4959f64d73d89889
---

 resources.qrc                           |  3 ++
 src/CMakeLists.txt                      |  1 -
 src/Gui/library/MediaLibraryView.cpp    | 43 +++++++++------------
 src/Gui/library/MediaLibraryView.h      | 12 ------
 src/Gui/library/ui/MediaLibraryView.qml | 60 +++++++++++++++++++++++++++++
 src/Gui/library/ui/MediaLibraryView.ui  | 67 ---------------------------------
 6 files changed, 80 insertions(+), 106 deletions(-)

diff --git a/resources.qrc b/resources.qrc
index de01d03..490d2c1 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -57,4 +57,7 @@
         <file>THANKS</file>
         <file>TRANSLATORS</file>
     </qresource>
+    <qresource prefix="/qml">
+        <file alias="MediaLibraryView">src/Gui/library/ui/MediaLibraryView.qml</file>
+    </qresource>
 </RCC>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7bc7943..03ba04c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -222,7 +222,6 @@ ELSE(NOT WITH_GUI)
         Gui/export/RendererSettings.ui
         Gui/export/ShareOnInternet.ui
         Gui/import/ui/TagWidget.ui
-        Gui/library/ui/MediaLibraryView.ui
         Gui/media/ui/ClipMetadataDisplayer.ui
         Gui/preview/ui/PreviewWidget.ui
         Gui/settings/ui/FolderListWidget.ui
diff --git a/src/Gui/library/MediaLibraryView.cpp b/src/Gui/library/MediaLibraryView.cpp
index d171289..35b1958 100644
--- a/src/Gui/library/MediaLibraryView.cpp
+++ b/src/Gui/library/MediaLibraryView.cpp
@@ -22,40 +22,31 @@
 
 #include "MediaLibraryView.h"
 
-#include "Project/Project.h"
-#include "Media/Clip.h"
-#include "Library/Library.h"
+#include "Library/MediaLibrary.h"
+#include "Library/MediaLibraryModel.h"
 #include "Main/Core.h"
-#include "Media/Media.h"
-#include "MediaCellView.h"
-#include "ViewController.h"
-#include "Tools/VlmcDebug.h"
 
+#include <QBoxLayout>
 #include <QListView>
+#include <QtQuick/QQuickView>
+#include <QQmlContext>
 #include <QUrl>
-#include <QMimeData>
 
-MediaLibraryView::MediaLibraryView(QWidget *parent) : QWidget(parent),
-    m_ui( new Ui::MediaLibraryView() )
+MediaLibraryView::MediaLibraryView(QWidget *parent)
+    : QWidget(parent)
 {
-    m_ui->setupUi( this );
-}
+    setObjectName( QStringLiteral( "medialibrary" ) );
+    auto view = new QQuickView;
+    auto container = QWidget::createWindowContainer( view, this );
+    auto layout = new QBoxLayout( QBoxLayout::TopToBottom, this );
+    layout->addWidget( container );
 
-MediaLibraryView::~MediaLibraryView()
-{
-    delete m_ui;
+    view->setSource( QUrl( "qrc:/qml/MediaLibraryView" ) );
+    view->setResizeMode(QQuickView::SizeRootObjectToView);
+    auto ctx = view->rootContext();
+    ctx->setContextProperty( "mlModel", Core::instance()->mediaLibrary()->model( MediaLibrary::MediaType::Video ) );
 }
 
-void
-MediaLibraryView::changeEvent( QEvent *e )
+MediaLibraryView::~MediaLibraryView()
 {
-    QWidget::changeEvent( e );
-    switch ( e->type() )
-    {
-        case QEvent::LanguageChange:
-            m_ui->retranslateUi( this );
-            break;
-        default:
-            break;
-    }
 }
diff --git a/src/Gui/library/MediaLibraryView.h b/src/Gui/library/MediaLibraryView.h
index a85469f..c5b71a4 100644
--- a/src/Gui/library/MediaLibraryView.h
+++ b/src/Gui/library/MediaLibraryView.h
@@ -25,25 +25,13 @@
 
 #include <QWidget>
 
-#include "ui_MediaLibraryView.h"
-
-class   Clip;
-
 class MediaLibraryView : public QWidget
 {
-    Q_OBJECT
     Q_DISABLE_COPY( MediaLibraryView );
 
     public:
-        typedef bool    (*Filter)( const Clip*, const QString& filter );
         explicit MediaLibraryView( QWidget *parent = 0);
         virtual ~MediaLibraryView();
-
-    protected:
-        void        changeEvent( QEvent *e );
-
-    private:
-        Ui::MediaLibraryView *m_ui;
 };
 
 #endif // MEDIALIBRARYVIEW_H
diff --git a/src/Gui/library/ui/MediaLibraryView.qml b/src/Gui/library/ui/MediaLibraryView.qml
new file mode 100644
index 0000000..4aafa11
--- /dev/null
+++ b/src/Gui/library/ui/MediaLibraryView.qml
@@ -0,0 +1,60 @@
+import QtQuick 2.0
+import QtQml 2.0
+import QtQuick.Controls 1.4
+import QtQuick.Layouts 1.3
+
+RowLayout {
+    anchors.fill: parent
+    ScrollView {
+        Layout.fillWidth: true
+        Layout.fillHeight: true
+        Component {
+            id: mediaDelegate
+            Rectangle {
+                property point origin
+                id: mediaItem
+                GridLayout {
+                    rows: 2
+                    columns: 2
+                    anchors.fill: parent
+                    height: 100
+
+                    Image {
+                        height: 100
+                        source: "file://" + thumbnailPath
+                        fillMode: Image.PreserveAspectFit
+                        Layout.rowSpan: 2
+                    }
+                    Text { text: title }
+                    Text {
+                        text: "Duration: " + duration
+                        //text: "Duration: " + Qt.formatDateTime( new Date( duration ) )
+                    }
+                }
+
+                Drag.active: dragArea.drag.active
+                Drag.hotSpot.x: 32
+                Drag.hotSpot.y: 32
+                MouseArea {
+                    id: dragArea
+                    onPressed: mediaItem.origin = Qt.point(mediaItem.x, mediaItem.y)
+                    onReleased: {
+                        mediaItem.x = mediaItem.origin.x
+                        mediaItem.y = mediaItem.origin.y
+                    }
+                    drag.target: mediaItem
+                    anchors.fill: parent
+                    anchors.centerIn: parent
+                }
+            }
+        }
+
+        ListView {
+            id: listView
+            model: mlModel
+            delegate: mediaDelegate
+            focus: true
+        }
+    }
+
+}
diff --git a/src/Gui/library/ui/MediaLibraryView.ui b/src/Gui/library/ui/MediaLibraryView.ui
deleted file mode 100644
index e4c211a..0000000
--- a/src/Gui/library/ui/MediaLibraryView.ui
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>MediaLibraryView</class>
- <widget class="QWidget" name="MediaLibraryView">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>280</width>
-    <height>219</height>
-   </rect>
-  </property>
-  <property name="minimumSize">
-   <size>
-    <width>280</width>
-    <height>0</height>
-   </size>
-  </property>
-  <property name="acceptDrops">
-   <bool>true</bool>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <layout class="QGridLayout" name="gridLayout">
-     <item row="0" column="0">
-      <widget class="SearchLineEdit" name="filterInput"/>
-     </item>
-     <item row="0" column="1">
-      <widget class="QComboBox" name="filterType">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <item>
-        <property name="text">
-         <string>Name</string>
-        </property>
-       </item>
-       <item>
-        <property name="text">
-         <string>Tags</string>
-        </property>
-       </item>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <widget class="QWidget" name="mediaListContainer" native="true"/>
-   </item>
-  </layout>
- </widget>
- <customwidgets>
-  <customwidget>
-   <class>SearchLineEdit</class>
-   <extends>QLineEdit</extends>
-   <header>Gui/widgets/SearchLineEdit.h</header>
-  </customwidget>
- </customwidgets>
- <resources/>
- <connections/>
-</ui>



More information about the Vlmc-devel mailing list