[vlmc-devel] EffectsListView: Use a qml view

Yikai Lu git at videolan.org
Mon Aug 29 17:22:07 CEST 2016


vlmc | branch: medialibrary | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Aug 29 10:02:06 2016 -0500| [589414bcbd55c755946c6932c128d9e19efd6b4a] | committer: Yikai Lu

EffectsListView: Use a qml view

> https://code.videolan.org/videolan/vlmc/commit/589414bcbd55c755946c6932c128d9e19efd6b4a
---

 src/Gui/MainWindow.cpp                    |  2 +-
 src/Gui/effectsengine/EffectsListView.cpp | 84 ++++++++++++++-----------------
 src/Gui/effectsengine/EffectsListView.h   | 25 +++++----
 3 files changed, 50 insertions(+), 61 deletions(-)

diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index 0f90e94..c56c819 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -494,7 +494,7 @@ void
 MainWindow::setupEffectsList()
 {
     m_effectsList = new EffectsListView;
-    m_dockedEffectsList = dockWidget( m_effectsList, Qt::TopDockWidgetArea );
+    m_dockedEffectsList = dockWidget( m_effectsList->container(), Qt::TopDockWidgetArea );
 }
 
 void
diff --git a/src/Gui/effectsengine/EffectsListView.cpp b/src/Gui/effectsengine/EffectsListView.cpp
index 415697e..adf848c 100644
--- a/src/Gui/effectsengine/EffectsListView.cpp
+++ b/src/Gui/effectsengine/EffectsListView.cpp
@@ -30,67 +30,57 @@
 #include "EffectsListView.h"
 #include "EffectWidget.h"
 
-#include <QApplication>
-#include <QDialog>
-#include <QMouseEvent>
-#include <QStandardItem>
-#include <QVBoxLayout>
+#include <QJsonObject>
+#include <QQmlContext>
+#include <QQuickView>
 #include <QMimeData>
 #include <QDrag>
 
-EffectsListView::EffectsListView( QWidget *parent ) :
-    QListView(parent)
+EffectsListView::EffectsListView( QWidget* parent ) :
+    QObject(parent)
 {
-    m_model = new QStandardItemModel( this );
-    setModel( m_model );
-    connect( this, SIGNAL( activated( QModelIndex ) ),
-             this, SLOT( effectActivated( QModelIndex ) ) );
-    setEditTriggers( QAbstractItemView::NoEditTriggers );
-    setObjectName( QStringLiteral( "Effects List" ) );
-
-    for ( auto filter : Backend::instance()->availableFilters() )
-        m_model->appendRow( new QStandardItem( QString::fromStdString( filter.second->identifier() ) ) );
+    setObjectName( QStringLiteral( "EffectsListView" ) );
+    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/EffectsListView.qml" ) ) );
+    view->setResizeMode( QQuickView::SizeRootObjectToView );
 }
 
-void
-EffectsListView::mousePressEvent( QMouseEvent *event )
+QWidget*
+EffectsListView::container()
 {
-    QListView::mousePressEvent( event );
+    return m_container;
+}
 
-    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
-        m_dragStartPos = event->pos();
+QJsonArray
+EffectsListView::effects()
+{
+    QJsonArray array;
+    for ( auto p : Backend::instance()->availableFilters() )
+    {
+        auto info = p.second;
+        QJsonObject jInfo;
+        jInfo[QStringLiteral( "identifier" )] = QString::fromStdString( info->identifier() );
+        jInfo[QStringLiteral( "name" )] = QString::fromStdString( info->name() );
+        jInfo[QStringLiteral( "description" )] = QString::fromStdString( info->description() );
+        jInfo[QStringLiteral( "author" )] = QString::fromStdString( info->author() );
+        array.append( jInfo );
+    }
+    return array;
 }
 
 void
-EffectsListView::mouseMoveEvent( QMouseEvent *event )
+EffectsListView::startDrag( const QString& effectId )
 {
-    if ( ( event->buttons() | Qt::LeftButton ) != Qt::LeftButton )
-         return;
+    QDrag* drag = new QDrag( this );
+    QMimeData* mimeData = new QMimeData;
 
-    if ( ( event->pos() - m_dragStartPos ).manhattanLength()
-          < QApplication::startDragDistance() )
-        return;
+    mimeData->setData( QStringLiteral( "vlmc/effect_name" ), effectId.toUtf8() );
 
-    QMimeData* mimeData = new QMimeData;
-    mimeData->setData( "vlmc/effect_name", m_model->data( currentIndex() ).toByteArray() );
-    QDrag* drag = new QDrag( this );
     drag->setMimeData( mimeData );
-    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
-}
-
-void
-EffectsListView::effectActivated( const QModelIndex &index ) const
-{
-    if ( index.isValid() == false )
-        return ;
-    auto filterInfo = Backend::instance()->filterInfo( m_model->data( index, Qt::DisplayRole ).toString().toStdString() );
+    drag->exec();
 
-    QDialog         *dialog = new QDialog();
-    QVBoxLayout     *layout = new QVBoxLayout( dialog );
-    EffectWidget    *wid = new EffectWidget( dialog );
-    layout->addWidget( wid );
-    wid->setFilterInfo( filterInfo );
-    dialog->setWindowTitle( tr( "%1 informations" ).arg( QString::fromStdString( filterInfo->name() ) ) );
-    dialog->exec();
-    delete dialog;
 }
diff --git a/src/Gui/effectsengine/EffectsListView.h b/src/Gui/effectsengine/EffectsListView.h
index 831c361..932b605 100644
--- a/src/Gui/effectsengine/EffectsListView.h
+++ b/src/Gui/effectsengine/EffectsListView.h
@@ -23,28 +23,27 @@
 #ifndef EFFECTLISTVIEW_H
 #define EFFECTLISTVIEW_H
 
+#include <QObject>
+#include <QJsonArray>
 
-#include <QListView>
+class QWidget;
 
-class   QStandardItemModel;
-
-class EffectsListView : public QListView
+class EffectsListView : public QObject
 {
     Q_OBJECT
 
     public:
-        explicit            EffectsListView(QWidget *parent = 0);
+        explicit            EffectsListView( QWidget* parent = 0 );
+        QWidget*            container();
 
-    protected:
-        void                mousePressEvent( QMouseEvent *event );
-        void                mouseMoveEvent( QMouseEvent *event );
+        Q_INVOKABLE
+        QJsonArray          effects();
 
-    private:
-        QStandardItemModel  *m_model;
-        QPoint              m_dragStartPos;
+public slots:
+    void    startDrag( const QString& effectId );
 
-    private slots:
-        void                effectActivated( const QModelIndex& index ) const;
+    private:
+        QWidget*            m_container;
 };
 
 #endif // EFFECTLISTVIEW_H



More information about the Vlmc-devel mailing list