MediaCellView.cpp 6.16 KB
Newer Older
Thomas Boquet's avatar
Thomas Boquet committed
1 2 3
/*****************************************************************************
 * MediaCellView.cpp
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
Thomas Boquet's avatar
Thomas Boquet committed
5 6
 *
 * Authors: Thomas Boquet <thomas.boquet@gmail.com>
7
 * Authors: Clement CHAVANCE <chavance.c@gmail.com>
Thomas Boquet's avatar
Thomas Boquet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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
24 25
#include "MediaCellView.h"
#include "ui_MediaCellView.h"
26 27
#include "Library.h"
#include "ClipProperty.h"
28 29

#include <QTime>
Thomas Boquet's avatar
Thomas Boquet committed
30

31 32
#include <QtDebug>

33 34 35 36
MediaCellView::MediaCellView( Clip* clip, QWidget *parent ) :
        QWidget( parent ),
        m_ui( new Ui::MediaCellView ),
        m_clip( clip )
Thomas Boquet's avatar
Thomas Boquet committed
37 38
{
    m_ui->setupUi( this );
39
    setFocusPolicy( Qt::ClickFocus );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
40
    setAutoFillBackground( true );
41 42
    connect( m_ui->delLabel, SIGNAL( clicked( QWidget*, QMouseEvent* ) ),
             this, SLOT( deleteButtonClicked( QWidget*, QMouseEvent* ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
43 44 45 46 47 48 49 50 51
    connect( m_ui->arrow,
             SIGNAL( clicked( QWidget*, QMouseEvent* ) ),
             SLOT( arrowButtonClicked( QWidget*, QMouseEvent* ) ) );
    m_ui->clipCount->setText( QString::number( clip->getChilds()->count() ) );
    connect( clip->getChilds(), SIGNAL( newClipLoaded( Clip* ) ),
             this, SLOT( nbClipUpdated( Clip* ) ) );
    connect( clip->getChilds(), SIGNAL( clipRemoved( const Clip* ) ),
             this, SLOT( nbClipUpdated( const Clip* ) ) );
    if ( clip->getChilds()->count() == 0 )
52 53 54 55 56
    {
        m_ui->clipCount->hide();
        m_ui->clipCountLabel->hide();
        m_ui->arrow->hide();
    }
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
57
    if ( clip->getMedia()->isMetadataComputed() == false )
58
        setEnabled( false );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
59
    connect( clip->getMedia(), SIGNAL( metaDataComputed(const Media*) ),
60
             this, SLOT( metadataUpdated( const Media*) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
61
    connect( clip->getMedia(), SIGNAL( snapshotComputed(const Media*) ),
62
             this, SLOT( snapshotUpdated(const Media*) ) );
63

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
64 65
    setThumbnail( clip->getMedia()->snapshot() );
    setTitle( clip->getMedia()->fileName() );
66
    setLength( clip->lengthSecond() * 1000 );
67 68
}

69 70 71 72 73
MediaCellView::~MediaCellView()
{
    delete m_ui;
}

74 75 76 77 78 79 80 81 82 83 84
void
MediaCellView::metadataUpdated( const Media *media )
{
    setLength( media->lengthMS() );
    setEnabled( true );
}

void
MediaCellView::snapshotUpdated( const Media *media )
{
    setThumbnail( media->snapshot() );
Thomas Boquet's avatar
Thomas Boquet committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
}

void MediaCellView::changeEvent( QEvent *e )
{
    QWidget::changeEvent( e );
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui->retranslateUi( this );
        break;
    default:
        break;
    }
}

void            MediaCellView::setTitle( const QString& title )
{
    m_ui->title->setText( title );
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
105 106
void
MediaCellView::nbClipUpdated( Clip *clip )
107
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    nbClipUpdated( const_cast<const Clip*>( clip ) );
}

void            MediaCellView::nbClipUpdated( const Clip *clip )
{
    quint32     nbClips = clip->getParent()->getChilds()->count();

    if ( nbClips == 0 )
    {
        m_ui->clipCount->hide();
        m_ui->clipCountLabel->hide();
        m_ui->arrow->hide();
        m_ui->clipCount->setText( "0" );
    }
    else
    {
        m_ui->clipCount->show();
        m_ui->clipCountLabel->show();
        m_ui->arrow->show();
        m_ui->clipCount->setText( QString::number( nbClips ) );
    }
129 130
}

131 132
void
MediaCellView::setThumbnail( const QPixmap &pixmap )
Thomas Boquet's avatar
Thomas Boquet committed
133
{
Thomas Boquet's avatar
Thomas Boquet committed
134
    m_ui->thumbnail->setScaledContents( false );
Thomas Boquet's avatar
Thomas Boquet committed
135
    m_ui->thumbnail->setPixmap( pixmap.scaled( 64, 64, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
136 137
}

Thomas Boquet's avatar
Thomas Boquet committed
138 139 140 141 142
const QPixmap*  MediaCellView::getThumbnail() const
{
    return m_ui->thumbnail->pixmap();
}

Thomas Boquet's avatar
Thomas Boquet committed
143 144 145 146 147
QString  MediaCellView::title() const
{
    return m_ui->title->text();
}

148 149
void            MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
150
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
151
    {
152
        ClipProperty* cp = new ClipProperty( m_clip, this );
153
        cp->setModal( true );
154
        cp->exec();
155
        delete cp;
156 157
    }
}
158 159 160

void            MediaCellView::mousePressEvent( QMouseEvent* event )
{
Thomas Boquet's avatar
Thomas Boquet committed
161 162
    QWidget::mousePressEvent( event );

163 164
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
    {
Thomas Boquet's avatar
Thomas Boquet committed
165
        m_dragStartPos = event->pos();
166
        emit cellSelected( m_clip->uuid() );
167 168
    }
}
Thomas Boquet's avatar
Thomas Boquet committed
169 170 171 172 173 174 175 176 177 178 179

void    MediaCellView::mouseMoveEvent( QMouseEvent* event )
{
    if ( ( event->buttons() | Qt::LeftButton ) != Qt::LeftButton )
         return;

    if ( ( event->pos() - m_dragStartPos ).manhattanLength()
          < QApplication::startDragDistance() )
        return;

    QMimeData* mimeData = new QMimeData;
180 181 182
    //FIXME the second argument is a media UUID instead of a Clip
    // and this is not logical... but it works.
    mimeData->setData( "vlmc/uuid", m_clip->uuid().toString().toAscii() );
Thomas Boquet's avatar
Thomas Boquet committed
183 184
    QDrag* drag = new QDrag( this );
    drag->setMimeData( mimeData );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
185
    const Media*  parent = m_clip->getMedia();
186
    drag->setPixmap( parent->snapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
187 188
    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
189

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
190 191
void        MediaCellView::deleteButtonClicked( QWidget*, QMouseEvent* )
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
192
    emit cellDeleted( m_clip );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
193
}
194

195 196
void        MediaCellView::arrowButtonClicked( QWidget*, QMouseEvent* )
{
197
    emit arrowClicked( m_clip->uuid() );
198 199
}

200
void        MediaCellView::setLength( qint64 length, bool mSecs )
201 202
{
    QTime   duration;
203 204 205 206
    if ( mSecs )
        duration = duration.addMSecs( length );
    else
        duration = duration.addSecs( length );
207 208
    m_ui->length->setText( duration.toString( "hh:mm:ss" ) );
}
209

210 211 212 213 214
const QUuid&
MediaCellView::uuid() const
{
    return m_clip->uuid();
}