MediaCellView.cpp 5.51 KB
Newer Older
Thomas Boquet's avatar
Thomas Boquet committed
1
2
3
4
5
6
/*****************************************************************************
 * MediaCellView.cpp
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * 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>
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
30
#include <QDebug>
Thomas Boquet's avatar
Thomas Boquet committed
31
32
33
34
35

MediaCellView::MediaCellView( const QUuid& uuid, QWidget *parent ) :
        QWidget( parent ), m_ui( new Ui::MediaCellView ), m_uuid( uuid )
{
    m_ui->setupUi( this );
36
    setFocusPolicy( Qt::ClickFocus );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
37
38
    setAutoFillBackground( true );
    connect( m_ui->delLabel, SIGNAL( clicked( QWidget*, QMouseEvent* ) ), this, SLOT( deleteButtonClicked( QWidget*, QMouseEvent* ) ) );
39
40
41
42
    //TODO : if it's a clip, disable the arrow
    connect( m_ui->arrow,
             SIGNAL( clicked( QWidget*, QMouseEvent* ) ),
             SLOT( arrowButtonClicked( QWidget*, QMouseEvent* ) ) );
Thomas Boquet's avatar
Thomas Boquet committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
}

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

68
69
70
71
72
void            MediaCellView::setNbClips( int nbClip )
{
    m_ui->clipCount->setText( QString::number( nbClip ) );
}

Thomas Boquet's avatar
Thomas Boquet committed
73
74
void            MediaCellView::setThumbnail( const QPixmap& pixmap )
{
Thomas Boquet's avatar
Thomas Boquet committed
75
    m_ui->thumbnail->setScaledContents( false );
Thomas Boquet's avatar
Thomas Boquet committed
76
    m_ui->thumbnail->setPixmap( pixmap.scaled( 64, 64, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
77
78
}

Thomas Boquet's avatar
Thomas Boquet committed
79
80
81
82
83
const QPixmap*  MediaCellView::getThumbnail() const
{
    return m_ui->thumbnail->pixmap();
}

Thomas Boquet's avatar
Thomas Boquet committed
84
85
86
87
88
89
90
91
92
QString  MediaCellView::title() const
{
    return m_ui->title->text();
}

const QUuid&    MediaCellView::uuid() const
{
    return m_uuid;
}
93
94
95

void            MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
96
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
97
    {
98
        ClipProperty* mp = new ClipProperty( Library::getInstance()->clip( m_uuid ), this );
99
100
101
102
        mp->setModal( true );
        mp->show();
    }
}
103
104
105

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

108
109
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
    {
Thomas Boquet's avatar
Thomas Boquet committed
110
        m_dragStartPos = event->pos();
111
112
113
        emit cellSelected( m_uuid );
    }
}
Thomas Boquet's avatar
Thomas Boquet committed
114
115
116

void    MediaCellView::mouseMoveEvent( QMouseEvent* event )
{
117
    qDebug() << "in MediaCellView::mouseMoveEvent";
Thomas Boquet's avatar
Thomas Boquet committed
118
119
120
121
122
123
124
125
126
127
128
129
130
    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 );
131
    //FIXME : change the way the library handles Clips
132
    Clip* clip = Library::getInstance()->clip( m_uuid );
133
134
135
    if ( 0 == clip )
        return ;
    //getting the media from the current Clip
136
    Media*  parent = Library::getInstance()->clip( m_uuid )->getParent();
137
138
    if ( 0 == parent )
        return ;
139
    drag->setPixmap( Library::getInstance()->clip( m_uuid )->getParent()->getSnapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
140
141
    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
142
143
144
145
146

const ClickableLabel*   MediaCellView::nextButton() const
{
    return m_ui->arrow;
}
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
147
148
149
150
151
152
153
154
155
156

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

void        MediaCellView::deleteButtonClicked( QWidget*, QMouseEvent* )
{
    emit cellDeleted( uuid() );
}
157

158
159
void        MediaCellView::arrowButtonClicked( QWidget*, QMouseEvent* )
{
160
    qDebug() << "arrow clicked for uuid" << uuid();
161
162
163
    emit arrowClicked( uuid() );
}

164
void        MediaCellView::setLength( qint64 length, bool mSecs )
165
166
{
    QTime   duration;
167
168
169
170
    if ( mSecs )
        duration = duration.addMSecs( length );
    else
        duration = duration.addSecs( length );
171
172
    m_ui->length->setText( duration.toString( "hh:mm:ss" ) );
}
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

void        MediaCellView::incrementClipCount()
{
    int clips = m_ui->clipCount->text().toInt();

    clips += 1;
    m_ui->clipCount->setText( QString::number( clips ) );
}

void        MediaCellView::decrementClipCount( const int nb )
{
    int clips = m_ui->clipCount->text().toInt();

    clips -= nb;
    if ( clips < 0 )
        clips = 0;
    m_ui->clipCount->setText( QString::number( clips ) );
}