Commit d207eb60 authored by luyikei's avatar luyikei Committed by Hugo Beauzée-Luyssen

EffectsListView: Use a qml view

parent beb2cb36
......@@ -497,7 +497,7 @@ void
MainWindow::setupEffectsList()
{
m_effectsList = new EffectsListView;
m_dockedEffectsList = dockWidget( m_effectsList, Qt::TopDockWidgetArea );
m_dockedEffectsList = dockWidget( m_effectsList->container(), Qt::TopDockWidgetArea );
}
void
......
......@@ -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;
}
......@@ -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
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