ThumbnailImageProvider.cpp 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*****************************************************************************
 * ThumbnailImageProvider.cpp
 *****************************************************************************
 * Copyright (C) 2008-2016 VideoLAN
 *
 * Authors: Yikei Lu    <luyikei.qmltu@gmail.com>
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
 *
 * 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.
 *****************************************************************************/

luyikei's avatar
luyikei committed
24 25 26 27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

luyikei's avatar
luyikei committed
28 29
#include "ThumbnailImageProvider.h"

30 31 32
#include "Library/Library.h"
#include "Media/Clip.h"
#include "Media/Media.h"
luyikei's avatar
luyikei committed
33
#include "Main/Core.h"
34 35
#include "Tools/VlmcDebug.h"
#include "Workflow/MainWorkflow.h"
luyikei's avatar
luyikei committed
36 37

ThumbnailImageProvider::ThumbnailImageProvider()
38
    : QQuickImageProvider( QQuickImageProvider::Image )
luyikei's avatar
luyikei committed
39 40 41
{
}

42 43
QImage
ThumbnailImageProvider::requestImage( const QString& id, QSize* size, const QSize& requestedSize )
luyikei's avatar
luyikei committed
44 45 46 47 48
{
    QString tmp = id;
    tmp.replace( "%7B", "{" );
    tmp.replace( "%7D", "}" );

49 50 51
    auto infos = tmp.split( '/' );
    auto libraryUuid = infos[0];
    auto clip = Core::instance()->library()->clip( libraryUuid );
52 53
    QImage snapshot( clip->media()->snapshot() );
    *size = snapshot.size();
54 55
    auto width = requestedSize.width() > 0 ? requestedSize.width() : size->width();
    auto height = requestedSize.height() > 0 ? requestedSize.height() : size->height();
56
    return snapshot.scaled( width, height );
luyikei's avatar
luyikei committed
57
}