MediaCellView.cpp 4.15 KB
Newer Older
Thomas Boquet's avatar
Thomas Boquet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*****************************************************************************
 * MediaCellView.cpp
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * 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 "MediaCellView.h"
#include "ui_MediaCellView.h"
25
26
#include "Library.h"
#include "ClipProperty.h"
27
28

#include <QTime>
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
29
#include <QDebug>
Thomas Boquet's avatar
Thomas Boquet committed
30
31
32
33
34

MediaCellView::MediaCellView( const QUuid& uuid, QWidget *parent ) :
        QWidget( parent ), m_ui( new Ui::MediaCellView ), m_uuid( uuid )
{
    m_ui->setupUi( this );
35
    setFocusPolicy( Qt::ClickFocus );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
36
37
    setAutoFillBackground( true );
    connect( m_ui->delLabel, SIGNAL( clicked( QWidget*, QMouseEvent* ) ), this, SLOT( deleteButtonClicked( QWidget*, QMouseEvent* ) ) );
Thomas Boquet's avatar
Thomas Boquet committed
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
}

MediaCellView::~MediaCellView()
{
    delete m_ui;
}

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

void            MediaCellView::setThumbnail( const QPixmap& pixmap )
{
Thomas Boquet's avatar
Thomas Boquet committed
65
    m_ui->thumbnail->setScaledContents( false );
Thomas Boquet's avatar
Thomas Boquet committed
66
    m_ui->thumbnail->setPixmap( pixmap.scaled( 64, 64, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
67
68
}

Thomas Boquet's avatar
Thomas Boquet committed
69
70
71
72
73
const QPixmap*  MediaCellView::getThumbnail() const
{
    return m_ui->thumbnail->pixmap();
}

Thomas Boquet's avatar
Thomas Boquet committed
74
75
76
77
78
79
80
81
82
QString  MediaCellView::title() const
{
    return m_ui->title->text();
}

const QUuid&    MediaCellView::uuid() const
{
    return m_uuid;
}
83
84
85

void            MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
86
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
87
88
89
90
91
92
    {
        ClipProperty* mp = new ClipProperty( Library::getInstance()->getClip( m_uuid ), this );
        mp->setModal( true );
        mp->show();
    }
}
93
94
95

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

98
99
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
    {
Thomas Boquet's avatar
Thomas Boquet committed
100
        m_dragStartPos = event->pos();
101
102
103
        emit cellSelected( m_uuid );
    }
}
Thomas Boquet's avatar
Thomas Boquet committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

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;
    //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_uuid.toString().toAscii() );
    QDrag* drag = new QDrag( this );
    drag->setMimeData( mimeData );

    drag->setPixmap( Library::getInstance()->getClip( m_uuid )->getParent()->getSnapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
124
125
126
127
128

const ClickableLabel*   MediaCellView::nextButton() const
{
    return m_ui->arrow;
}
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
129
130
131
132
133
134
135
136
137
138

const ClickableLabel*   MediaCellView::deleteButton() const
{
    return m_ui->delLabel;
}

void        MediaCellView::deleteButtonClicked( QWidget*, QMouseEvent* )
{
    emit cellDeleted( uuid() );
}
139
140
141
142
143
144
145

void        MediaCellView::setLength( qint64 length )
{
    QTime   duration;
    duration = duration.addMSecs( length );
    m_ui->length->setText( duration.toString( "hh:mm:ss" ) );
}