PreviewWidget.cpp 6.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*****************************************************************************
 * PreviewWidget.cpp : Main widget for preview. Will dispatch on Clip or
 *                     Render preview
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * 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.
 *****************************************************************************/

24
#include <QtDebug>
25
#include "PreviewWidget.h"
26
#include "ui_PreviewWidget.h"
27
#include "ClipRenderer.h"
28

29
PreviewWidget::PreviewWidget( GenericRenderer* genericRenderer, QWidget *parent ) :
30
    QWidget( parent ),
31
    m_ui( new Ui::PreviewWidget ),
32
33
    m_renderer( genericRenderer ),
    m_previewStopped( true )
34
35
{
    m_ui->setupUi( this );
36

37
    m_ui->rulerWidget->setFocusPolicy( Qt::NoFocus );
38

39
40
41
42
43
44
    // Prepare and set the black background
    m_ui->renderWidget->setAutoFillBackground( true );
    m_videoPalette = m_ui->renderWidget->palette();
    m_videoPalette.setColor( QPalette::Window, QColor( Qt::black ) );
    m_ui->renderWidget->setPalette( m_videoPalette );

45
    // Hide markers and createClip buttons if we are not using a ClipRenderer
46
47
48
49
    if ( !qobject_cast<ClipRenderer*>( genericRenderer ) )
    {
        m_ui->pushButtonMarkerStart->hide();
        m_ui->pushButtonMarkerStop->hide();
50
        m_ui->pushButtonCreateClip->hide();
51
52
    }

53
54
55
    // Give the renderer to the ruler
    m_ui->rulerWidget->setRenderer( m_renderer );

56
    setAcceptDrops( false );
57

58
59
    connect( m_ui->rulerWidget, SIGNAL( timeChanged(int,int,int,int) ),
             m_ui->lcdNumber,   SLOT( setTime(int,int,int,int) ) );
60

61
    m_renderer->setRenderWidget( m_ui->renderWidget );
62
    m_renderer->setPreviewLabel( m_ui->previewLabel );
63
    m_ui->previewLabel->hide();
64

65
66
67
68
69
70
71
72
    connect( m_renderer,     SIGNAL( stopped() ),               this,       SLOT( videoStopped() ) );
    connect( m_renderer,     SIGNAL( paused() ),                this,       SLOT( videoPaused() ) );
    connect( m_renderer,     SIGNAL( playing() ),               this,       SLOT( videoPlaying() ) );
    connect( m_renderer,     SIGNAL( frameChanged(qint64, MainWorkflow::FrameChangedReason) ),
             this, SLOT( frameChanged(qint64, MainWorkflow::FrameChangedReason ) ) );
    connect( m_renderer,     SIGNAL( endReached() ),            this,       SLOT( endReached() ) );
    connect( m_ui->rulerWidget, SIGNAL( frameChanged(qint64, MainWorkflow::FrameChangedReason) ),
             m_renderer,       SLOT( previewWidgetCursorChanged(qint64) ) );
73
74
75

    connect( m_ui->pushButtonMarkerStart, SIGNAL( clicked() ), this, SLOT( markerStartClicked() ) );
    connect( m_ui->pushButtonMarkerStop, SIGNAL( clicked() ), this, SLOT( markerStopClicked() ) );
76
    connect( m_ui->pushButtonCreateClip, SIGNAL( clicked() ), this, SLOT( createNewClipFromMarkers() ) );
77
78
79
80
}

PreviewWidget::~PreviewWidget()
{
81
    delete m_renderer;
82
    delete m_ui;
83
84
85
}

void    PreviewWidget::changeEvent( QEvent *e )
86
87
88
89
90
91
92
93
94
95
96
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui->retranslateUi( this );
        break;
    default:
        break;
    }
}

97
void    PreviewWidget::frameChanged( qint64 currentFrame, MainWorkflow::FrameChangedReason reason )
98
{
99
    if ( m_previewStopped == false && reason != MainWorkflow::PreviewCursor )
100
    {
101
        m_ui->rulerWidget->setFrame( currentFrame, false );
102
    }
103
}
104

105
106
107
108
109
void    PreviewWidget::on_pushButtonStop_clicked()
{
    if ( m_previewStopped == false )
    {
        m_previewStopped = true;
110
        m_renderer->stop();
111
112
113
114
    }
}

void    PreviewWidget::on_pushButtonPlay_clicked()
115
116
117
{
    if ( m_previewStopped == true )
        m_previewStopped = false;
118
    m_renderer->togglePlayPause();
119
120
}

121
void    PreviewWidget::videoPaused()
122
123
124
125
{
    m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
}

126
127
128
129
130
131
void    PreviewWidget::videoStopped()
{
    m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
}

void    PreviewWidget::videoPlaying()
132
133
134
135
136
137
138
139
140
{
    m_ui->pushButtonPlay->setIcon( QIcon( ":/images/pause" ) );
}

void    PreviewWidget::endReached()
{
    m_previewStopped = true;

    m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
141
142
143

    // Set the black background
    m_ui->renderWidget->setPalette( m_videoPalette );
144
}
145

146
147
void        PreviewWidget::on_pushButtonNextFrame_clicked()
{
148
    if ( m_previewStopped == false )
149
        m_renderer->nextFrame();
150
151
152
153
}

void        PreviewWidget::on_pushButtonPreviousFrame_clicked()
{
154
    if ( m_previewStopped == false )
155
        m_renderer->previousFrame();
156
}
157

158
const GenericRenderer*      PreviewWidget::getGenericRenderer() const
159
160
161
{
    return m_renderer;
}
162
163
164
165
166
167

void                        PreviewWidget::stop()
{
    //Ugly but avoid code dupplication.
    on_pushButtonStop_clicked();
}
168
169
170
171
172
173
174
175
176
177

void                        PreviewWidget::markerStartClicked()
{
    m_ui->rulerWidget->setMarker( PreviewRuler::START );
}

void                        PreviewWidget::markerStopClicked()
{
    m_ui->rulerWidget->setMarker( PreviewRuler::STOP );
}
178
179
180
181

void        PreviewWidget::createNewClipFromMarkers()
{
    Media*  selectedMedia = m_renderer->getMedia();
Clement CHAVANCE's avatar
Clement CHAVANCE committed
182
183
    qint64  beg = m_ui->rulerWidget->getMarker( PreviewRuler::START );
    qint64  end = m_ui->rulerWidget->getMarker( PreviewRuler::STOP );
184

185
186
187
    if ( beg == -1 && end == -1 )
        return ;

188
189
    if ( end < beg )
        return ;
190

191
192
193
194
195
196
197
    beg = beg < 0 ? 0 : beg;
    Clip*   part = new Clip( selectedMedia, beg, end );

    //Adding the newly created clip to the media
    selectedMedia->addClip( part );
    return ;
}