MediaLibraryView.cpp 3.04 KB
Newer Older
1 2 3
/*****************************************************************************
 * MediaLibrary.cpp: VLMC media library's ui
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23 24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

27
#include "MediaLibraryView.h"
28

29
#include "Library/Library.h"
30
#include "Library/MediaLibraryModel.h"
31
#include "Main/Core.h"
32 33 34 35
#include "Media/Media.h"
#include "Media/Clip.h"

#include <medialibrary/IMedia.h>
36

37
#include <QBoxLayout>
38
#include <QListView>
39 40
#include <QtQuick/QQuickView>
#include <QQmlContext>
41
#include <QUrl>
42 43
#include <QDrag>
#include <QMimeData>
44

45 46
MediaLibraryView::MediaLibraryView( QWidget* parent )
    : QObject( parent )
47
{
48 49
    setObjectName( QStringLiteral( "medialibrary" ) );
    auto view = new QQuickView;
50 51 52
    m_container = QWidget::createWindowContainer( view, parent );
    m_container->setMinimumSize( 100, 1 );
    m_container->setObjectName( objectName() );
53

54
    auto ctx = view->rootContext();
55
    ctx->setContextProperty( QStringLiteral( "mlModel" ), Core::instance()->library()->model( Library::MediaType::Video ) );
56
    ctx->setContextProperty( QStringLiteral( "view" ), this );
57

58
    view->setSource( QUrl( QStringLiteral( "qrc:/QML/MediaLibraryView.qml" ) ) );
59
    view->setResizeMode(QQuickView::SizeRootObjectToView);
60 61
}

62
MediaLibraryView::~MediaLibraryView()
63 64
{
}
65 66 67 68 69 70

QWidget*
MediaLibraryView::container()
{
    return m_container;
}
71 72

void
73
MediaLibraryView::startDrag( qint64 mediaId )
74 75 76 77
{
    QDrag* drag = new QDrag( this );
    QMimeData* mimeData = new QMimeData;

78 79
    QSharedPointer<Media> media = Core::instance()->library()->media( mediaId );
    if ( media == nullptr ) {
80
        media.reset( new Media( Core::instance()->library()->model( Library::MediaType::Video )->findMedia( mediaId ) ) );
81 82
        Core::instance()->library()->addMedia( media );
    }
83

84 85 86 87 88 89
    mimeData->setData( QStringLiteral( "vlmc/uuid" ), media->baseClip()->uuid().toByteArray() );

    drag->setMimeData( mimeData );
    auto thumbnailPath = media->snapshot();
    drag->setPixmap( QPixmap( thumbnailPath.isEmpty() ? QStringLiteral( ":/images/vlmc" ) :
                                thumbnailPath ).scaled( 100, 100, Qt::KeepAspectRatio ) );
90 91
    drag->exec();
}