MediaCellView.cpp 5.89 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
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
    setAutoFillBackground( true );
37
38
    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* ) ) );
43
    setEnabled( false );
Thomas Boquet's avatar
Thomas Boquet committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
}

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

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

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

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

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

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

void            MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
97
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
98
    {
99
100
101
        Clip* clip = Library::getInstance()->clip( m_uuid );
        if ( clip == NULL )
            return;
102
103
104
105
        ClipProperty* cp = new ClipProperty( clip, this );
        cp->setModal( true );
        cp->show();
        delete cp;
106
107
    }
}
108
109
110

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

113
114
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
    {
Thomas Boquet's avatar
Thomas Boquet committed
115
        m_dragStartPos = event->pos();
116
117
118
        emit cellSelected( m_uuid );
    }
}
Thomas Boquet's avatar
Thomas Boquet committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

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 );
135
    //FIXME : change the way the library handles Clips
136
    Clip* clip = Library::getInstance()->clip( m_uuid );
137
138
139
    if ( 0 == clip )
        return ;
    //getting the media from the current Clip
140
    Media*  parent = Library::getInstance()->clip( m_uuid )->getParent();
141
142
    if ( 0 == parent )
        return ;
143
144
    drag->setPixmap( Library::getInstance()->clip( m_uuid )->getParent()->
                     snapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
145
146
    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
147
148
149
150
151

const ClickableLabel*   MediaCellView::nextButton() const
{
    return m_ui->arrow;
}
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
152
153
154
155
156
157
158
159
160
161

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

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

163
164
165
166
167
void        MediaCellView::arrowButtonClicked( QWidget*, QMouseEvent* )
{
    emit arrowClicked( uuid() );
}

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

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 ) );
}
195
196
197
198
199
200
201
202
203
204
205

void
MediaCellView::containsClip()
{
    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* ) ) );
}
206
207
208
209
210
211

void
MediaCellView::enableCell()
{
    this->setEnabled( true );
}