MediaCellView.cpp 5.97 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* ) ) );
43
    if ( clip->isRootClip() == true )
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    {
        connect( m_ui->arrow,
                 SIGNAL( clicked( QWidget*, QMouseEvent* ) ),
                 SLOT( arrowButtonClicked( QWidget*, QMouseEvent* ) ) );
        m_ui->clipCount->setText( QString::number( clip->getParent()->clipsCount() ) );
        connect( clip->getParent(), SIGNAL( clipAdded(Clip*) ),
                 this, SLOT( nbClipUpdated( Clip* ) ) );
        connect( clip->getParent(), SIGNAL( clipRemoved( Clip* ) ),
                 this, SLOT( nbClipUpdated( Clip* ) ) );
    }
    else
    {
        m_ui->clipCount->hide();
        m_ui->clipCountLabel->hide();
        m_ui->arrow->hide();
        disconnect( m_ui->arrow,
                    SIGNAL( clicked( QWidget*, QMouseEvent* ) ), this,
                    SLOT( arrowButtonClicked( QWidget*, QMouseEvent* ) ) );
    }
63 64
    if ( clip->getParent()->isMetadataComputed() == false )
        setEnabled( false );
65 66 67 68
    connect( clip->getParent(), SIGNAL( metaDataComputed(const Media*) ),
             this, SLOT( metadataUpdated( const Media*) ) );
    connect( clip->getParent(), SIGNAL( snapshotComputed(const Media*) ),
             this, SLOT( snapshotUpdated(const Media*) ) );
69

70 71 72
    setThumbnail( clip->getParent()->snapshot() );
    setTitle( clip->getParent()->fileName() );
    setLength( clip->lengthSecond() * 1000 );
73 74
}

75 76 77 78 79
MediaCellView::~MediaCellView()
{
    delete m_ui;
}

80 81 82 83 84 85 86 87 88 89 90
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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
}

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 );
}

111
void            MediaCellView::nbClipUpdated( Clip *clip )
112
{
113
    m_ui->clipCount->setText( QString::number( clip->getParent()->clipsCount() ) );
114 115
}

116 117
void
MediaCellView::setThumbnail( const QPixmap &pixmap )
Thomas Boquet's avatar
Thomas Boquet committed
118
{
Thomas Boquet's avatar
Thomas Boquet committed
119
    m_ui->thumbnail->setScaledContents( false );
Thomas Boquet's avatar
Thomas Boquet committed
120
    m_ui->thumbnail->setPixmap( pixmap.scaled( 64, 64, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
121 122
}

Thomas Boquet's avatar
Thomas Boquet committed
123 124 125 126 127
const QPixmap*  MediaCellView::getThumbnail() const
{
    return m_ui->thumbnail->pixmap();
}

Thomas Boquet's avatar
Thomas Boquet committed
128 129 130 131 132
QString  MediaCellView::title() const
{
    return m_ui->title->text();
}

133 134
void            MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
135
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
136
    {
137
        ClipProperty* cp = new ClipProperty( m_clip, this );
138
        cp->setModal( true );
139
        cp->exec();
140
        delete cp;
141 142
    }
}
143 144 145

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

148 149
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
    {
Thomas Boquet's avatar
Thomas Boquet committed
150
        m_dragStartPos = event->pos();
151
        emit cellSelected( m_clip->uuid() );
152 153
    }
}
Thomas Boquet's avatar
Thomas Boquet committed
154 155 156 157 158 159 160 161 162 163 164

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;
165 166 167
    //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
168 169
    QDrag* drag = new QDrag( this );
    drag->setMimeData( mimeData );
170
    const Media*  parent = m_clip->getParent();
171
    drag->setPixmap( parent->snapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
172 173
    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
174

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
175 176
void        MediaCellView::deleteButtonClicked( QWidget*, QMouseEvent* )
{
177
    emit cellDeleted( m_clip->uuid() );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
178
}
179

180 181
void        MediaCellView::arrowButtonClicked( QWidget*, QMouseEvent* )
{
182
    emit arrowClicked( m_clip->uuid() );
183 184
}

185
void        MediaCellView::setLength( qint64 length, bool mSecs )
186 187
{
    QTime   duration;
188 189 190 191
    if ( mSecs )
        duration = duration.addMSecs( length );
    else
        duration = duration.addSecs( length );
192 193
    m_ui->length->setText( duration.toString( "hh:mm:ss" ) );
}
194

195 196 197
void
MediaCellView::containsClip()
{
198

199
}
200 201 202 203 204 205

const QUuid&
MediaCellView::uuid() const
{
    return m_clip->uuid();
}