ClipListViewController.cpp 3.71 KB
Newer Older
1 2 3
/*****************************************************************************
 * ClipListViewController.cpp: controller for the library clip list
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *
 * Authors: Clement CHAVANCE <chavance.c@gmail.com>
 *
 * 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.
 *****************************************************************************/

#include <QtDebug>
#include <QWidget>
#include "ClipListViewController.h"
#include "MediaCellView.h"
#include "Library.h"

ClipListViewController::ClipListViewController( StackViewController* nav, const QUuid& mediaId )
    : ListViewController( nav ),
    m_nav( nav ),
    m_mediaId( mediaId ),
33 34
    m_currentUuid(),
    m_deletion( 0 )
35
{
36 37
    connect( this, SIGNAL( clipDeleted( const QUuid&, const QUuid& ) ),
             Library::getInstance(), SLOT( removeClip( const QUuid&, const QUuid& ) ) );
38 39 40 41
}

ClipListViewController::~ClipListViewController()
{
42 43
    foreach( QWidget* cell, m_cells.values() )
        removeCell( cell );
44 45 46 47
}

void    ClipListViewController::addClipsFromMedia( Media* media )
{
48
    foreach( Clip* clip, media->clips() )
49 50 51
        addClip( clip );
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
52
int     ClipListViewController::getNbDeletion() const
53 54 55 56
{
    return m_deletion;
}

57 58 59 60 61
void    ClipListViewController::resetNbDeletion()
{
    m_deletion = 0;
}

62 63
void    ClipListViewController::addClip( Clip* clip )
{
64
    MediaCellView* cell = new MediaCellView( clip->uuid() );
65
    cell->containsClip();
66 67 68
    connect( cell, SIGNAL( cellSelected( QUuid ) ), this, SLOT( cellSelection( const QUuid& ) ) );
    connect( cell, SIGNAL( cellDeleted( const QUuid& ) ), this, SLOT( clipDeletion( const QUuid& ) ) );

69
    cell->setThumbnail( clip->getParent()->snapshot() );
70 71
    QString number;
    number.setNum( m_cells.size() + 1 );
72
    cell->setTitle( clip->getParent()->fileName() + number );
73
    cell->setLength( clip->lengthSecond(), false );
74
    addCell( cell );
75
    m_cells.insert( clip->uuid(), cell );
76
    cell->enableCell();
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
}

void    ClipListViewController::clean()
{
    foreach ( QWidget* widg, m_cells )
    {
        removeCell( widg );
        delete widg;
    }
    m_cells.clear();
}

void    ClipListViewController::cellSelection( const QUuid& uuid )
{
    if ( m_currentUuid == uuid )
        return;

    if ( m_cells.contains( uuid ) )
    {
        if ( !m_currentUuid.isNull() && m_cells.contains( m_currentUuid ) )
            m_cells.value( m_currentUuid )->setPalette( m_cells.value( uuid )->palette() );
        QPalette p = m_cells.value( uuid )->palette();
        p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
        m_cells.value( uuid )->setPalette( p );
        m_currentUuid = uuid;
        emit clipSelected( uuid );
    }
}

void    ClipListViewController::clipDeletion( const QUuid& uuid )
{
    if ( m_cells.contains( uuid ) )
    {
110
        QUuid tmp = uuid;
111
        ++m_deletion;
112 113 114
        QWidget* cell = m_cells.value( uuid );
        removeCell( cell );
        m_currentUuid = QUuid();
115 116
        m_cells.remove( tmp );
        emit clipDeleted( m_mediaId, tmp );
117 118
    }
}