MediaListViewController.cpp 3.69 KB
Newer Older
1
2
3
/*****************************************************************************
 * MediaLibraryWidget.h
 *****************************************************************************
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
 *
 * Authors: Thomas Boquet <thomas.boquet@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.
 *****************************************************************************/

Thomas Boquet's avatar
Thomas Boquet committed
23
24
#include "MediaListViewController.h"

25
#include "Clip.h"
26
#include "MediaContainer.h"
Thomas Boquet's avatar
Thomas Boquet committed
27

28
29
30
31
32
MediaListViewController::MediaListViewController( StackViewController* nav, MediaContainer* mc ) :
        ListViewController( nav ),
        m_nav( nav ),
        m_clipsListView( 0 ),
        m_mediaContainer( mc )
Thomas Boquet's avatar
Thomas Boquet committed
33
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34
35
36
37
38
39
    connect( mc, SIGNAL( newClipLoaded(Clip*) ),
             this, SLOT( newClipLoaded( Clip* ) ) );
    foreach ( Clip* clip, mc->clips() )
        newClipLoaded( clip );
    connect( m_nav, SIGNAL( previousButtonPushed() ),
             this, SLOT( restoreContext() ) );
Thomas Boquet's avatar
Thomas Boquet committed
40
41
42
43
}

MediaListViewController::~MediaListViewController()
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
44
45
46
    foreach ( QWidget* cell, m_cells )
        delete cell;
    m_cells.clear();
Thomas Boquet's avatar
Thomas Boquet committed
47
}
48

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
49
void        MediaListViewController::newClipLoaded( Clip *clip )
Thomas Boquet's avatar
Thomas Boquet committed
50
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
51
    MediaCellView* cell = new MediaCellView( clip );
Thomas Boquet's avatar
Thomas Boquet committed
52

53
54
    connect( cell, SIGNAL ( cellSelected( QUuid ) ),
             this, SLOT ( cellSelection( QUuid ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
55
56
    connect( cell, SIGNAL ( cellDeleted( const Clip* ) ),
             this, SLOT( clipRemoved( const Clip* ) ) );
57
    connect( cell, SIGNAL( arrowClicked( const QUuid& ) ),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
58
59
60
             this, SLOT( showSubClips( const QUuid& ) ) );
    addCell( cell );
    m_cells.insert( clip->uuid(), cell );
Thomas Boquet's avatar
Thomas Boquet committed
61
}
Thomas Boquet's avatar
Thomas Boquet committed
62

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
63
64
65
66
67
void    MediaListViewController::cellSelection( const QUuid& uuid )
{
    if ( m_currentUuid == uuid )
        return;

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
68
    if ( m_cells.contains( uuid ) )
69
    {
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
70
        if ( !m_currentUuid.isNull() && m_cells.contains( m_currentUuid ) )
71
        {
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
72
73
            QWidget* cell = m_cells.value( m_currentUuid );
            cell->setPalette( m_cells.value( uuid )->palette() );
74
        }
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
75
        QPalette p = m_cells.value( uuid )->palette();
76
        p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
77
        m_cells.value( uuid )->setPalette( p );
78
        m_currentUuid = uuid;
79
        emit clipSelected( m_mediaContainer->clip( uuid ) );
80
    }
81
82
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
83
void    MediaListViewController::clipRemoved( const Clip* clip )
84
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
85
    QWidget* cell = m_cells.value( clip->uuid() );
86
    removeCell( cell );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
87
    m_cells.remove( clip->uuid() );
88
    m_currentUuid = QUuid();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
89
90
91
    m_mediaContainer->removeClip( clip );
    emit clipDeleted( clip->uuid() );
    delete clip;
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
92
}
93

94
95
96
void
MediaListViewController::clear()
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
97
    foreach ( QWidget* cell, m_cells.values() )
98
        removeCell( cell );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
99
    m_cells.clear();
100
101
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
102
void    MediaListViewController::showSubClips( const QUuid& uuid )
103
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
104
105
    Clip*   clip = m_mediaContainer->clip( uuid );
    m_clipsListView = new MediaListViewController( m_nav, clip->getChilds() );
106
107
108
109
110
    m_nav->pushViewController( m_clipsListView );
}

void    MediaListViewController::restoreContext()
{
111
    delete m_clipsListView;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
112
    m_currentUuid = QUuid();
113
}