MediaCellView.cpp 5.3 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
68
69
}

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
70
    m_ui->thumbnail->setScaledContents( false );
Thomas Boquet's avatar
Thomas Boquet committed
71
    m_ui->thumbnail->setPixmap( pixmap.scaled( 64, 64, Qt::KeepAspectRatio ) );
Thomas Boquet's avatar
Thomas Boquet committed
72
73
}

Thomas Boquet's avatar
Thomas Boquet committed
74
75
76
77
78
const QPixmap*  MediaCellView::getThumbnail() const
{
    return m_ui->thumbnail->pixmap();
}

Thomas Boquet's avatar
Thomas Boquet committed
79
80
81
82
83
84
85
86
87
QString  MediaCellView::title() const
{
    return m_ui->title->text();
}

const QUuid&    MediaCellView::uuid() const
{
    return m_uuid;
}
88
89
90

void            MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
91
    if ( ( event->buttons() | Qt::LeftButton ) == Qt::LeftButton )
92
93
94
95
96
97
    {
        ClipProperty* mp = new ClipProperty( Library::getInstance()->getClip( m_uuid ), this );
        mp->setModal( true );
        mp->show();
    }
}
98
99
100

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

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

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 );
125
126
127
128
129
130
131
132
    //FIXME : change the way the library handles Clips
    Clip* clip = Library::getInstance()->getClip( m_uuid );
    if ( 0 == clip )
        return ;
    //getting the media from the current Clip
    Media*  parent = Library::getInstance()->getClip( m_uuid )->getParent();
    if ( 0 == parent )
        return ;
Thomas Boquet's avatar
Thomas Boquet committed
133
134
135
    drag->setPixmap( Library::getInstance()->getClip( m_uuid )->getParent()->getSnapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
    drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
136
137
138
139
140

const ClickableLabel*   MediaCellView::nextButton() const
{
    return m_ui->arrow;
}
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
141
142
143
144
145
146
147
148
149
150

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

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

152
153
154
155
156
void        MediaCellView::arrowButtonClicked( QWidget*, QMouseEvent* )
{
    emit arrowClicked( uuid() );
}

157
void        MediaCellView::setLength( qint64 length, bool mSecs )
158
159
{
    QTime   duration;
160
161
162
163
    if ( mSecs )
        duration = duration.addMSecs( length );
    else
        duration = duration.addSecs( length );
164
165
    m_ui->length->setText( duration.toString( "hh:mm:ss" ) );
}
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

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