ClipListViewController.cpp 3.37 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
/*****************************************************************************
 * ClipListViewController.cpp: controller for the library clip list
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * 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 ),
    m_currentUuid()
{
}

ClipListViewController::~ClipListViewController()
{
}

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

void    ClipListViewController::addClip( Clip* clip )
{
    MediaCellView* cell = new MediaCellView( clip->getUuid() );
    connect( cell, SIGNAL( cellSelected( QUuid ) ), this, SLOT( cellSelection( const QUuid& ) ) );
    connect( cell, SIGNAL( cellDeleted( const QUuid& ) ), this, SLOT( clipDeletion( const QUuid& ) ) );

    cell->setThumbnail( clip->getParent()->getSnapshot() );
    QString number;
    number.setNum( m_cells.size() + 1 );
    cell->setTitle( clip->getParent()->getFileName() + number );
    cell->setLength( clip->getLengthSecond(), false );
    addCell( cell );
    m_cells.insert( clip->getUuid(), cell );
}

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

void    ClipListViewController::cellSelection( const QUuid& uuid )
{
    qDebug() << "cell selected";
    if ( m_currentUuid == uuid )
        return;

    if ( m_cells.contains( uuid ) )
    {
        qDebug() << "uuid found" << 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 ) )
    {
        QWidget* cell = m_cells.value( uuid );
        removeCell( cell );
        m_cells.remove( uuid );
        m_currentUuid = QUuid();
        Library::getInstance()->getMedia( m_mediaId )->removeClip( uuid );
        m_cells.remove( uuid );
    }
}