MediaListViewController.cpp 1.69 KB
Newer Older
Thomas Boquet's avatar
Thomas Boquet committed
1
2
#include "MediaListViewController.h"

Thomas Boquet's avatar
Thomas Boquet committed
3
4
#include <QDebug>

Thomas Boquet's avatar
Thomas Boquet committed
5
MediaListViewController::MediaListViewController( StackViewController* nav ) :
6
        ListViewController( nav ), m_nav( nav )
Thomas Boquet's avatar
Thomas Boquet committed
7
8
{
    connect(Library::getInstance(), SIGNAL( newMediaLoaded( Media* ) ), this, SLOT( newMediaLoaded( Media* ) ) );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
9
    m_cells = new QHash<QUuid, QWidget*>();
Thomas Boquet's avatar
Thomas Boquet committed
10
11
12
13
}

MediaListViewController::~MediaListViewController()
{
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
14
    delete m_cells;
Thomas Boquet's avatar
Thomas Boquet committed
15
16
17
18
19
20
}

void        MediaListViewController::newMediaLoaded( Media* media )
{
    MediaCellView* cell = new MediaCellView( media->getUuid() );

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
21
    connect( cell, SIGNAL ( cellSelected( QUuid ) ), this, SLOT ( cellSelection( QUuid ) ) );
22
    connect( cell, SIGNAL ( cellDeleted( QUuid ) ), this, SLOT( mediaDeletion( QUuid ) ) );
23

Thomas Boquet's avatar
Thomas Boquet committed
24
25
    cell->setThumbnail( media->getSnapshot() );
    cell->setTitle( media->getFileName() );
26
    cell->setLength( media->getLengthMS() );
Thomas Boquet's avatar
Thomas Boquet committed
27
    addCell(cell);
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
28
    m_cells->insert( media->getUuid(), cell );
Thomas Boquet's avatar
Thomas Boquet committed
29
}
Thomas Boquet's avatar
Thomas Boquet committed
30

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
31
32
33
34
35
36
37
38
39
40
41
void    MediaListViewController::cellSelection( const QUuid& uuid )
{
    if ( m_currentUuid == uuid )
        return;

    if ( !m_currentUuid.isNull() )
        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;
42
43
44
45
46
47
48
49
50
51
52
53
54
    emit mediaSelected( Library::getInstance()->getMedia( uuid ) );
}

void    MediaListViewController::mediaDeletion( const QUuid& uuid )
{
    emit mediaDeleted( uuid );
}

void    MediaListViewController::mediaRemoved( const QUuid& uuid )
{
    removeCell( m_cells->value( uuid ) );
    m_cells->remove( uuid );
    m_currentUuid = QUuid();
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
55
}