Commit 8e9e78d4 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactoring preview widget

There's now a central widget that dispatch preview to a ClipPreviewWidget class
if it's a clip In a close future, there will be a RenderPreviewWidget class
parent 946ebcdf
......@@ -21,132 +21,45 @@
*****************************************************************************/
#include <QtDebug>
#include <QUrl>
#include "ClipPreviewWidget.h"
#include "ui_PreviewWidget.h"
#include "MediaListWidget.h"
#include "Library.h"
ClipPreviewWidget::ClipPreviewWidget( QWidget *parent ) :
QWidget( parent ),
m_ui( new Ui::PreviewWidget ), m_clipLoaded( false ), m_videoStopped( true )
ClipPreviewWidget::ClipPreviewWidget( QWidget* renderWidget ) :
m_clipLoaded( false ), m_videoStopped( true )
{
m_ui->setupUi( this );
m_ui->groupBoxButton->hide();
m_ui->seekSlider->setMinimum( 0 );
m_ui->seekSlider->setMaximum( 1000 );
m_ui->seekSlider->setSingleStep( 2 );
m_ui->seekSlider->setFocusPolicy( Qt::NoFocus );
setAcceptDrops( true );
connect( m_ui->seekSlider, SIGNAL( sliderPressed() ), this, SLOT( seekSliderPressed() ) );
connect( m_ui->seekSlider, SIGNAL( sliderPosChanged(int) ), this, SLOT( seekSliderMoved(int) ) );
connect( m_ui->seekSlider, SIGNAL( sliderReleased() ), this, SLOT( seekSliderReleased() ) );
m_mediaPlayer = new LibVLCpp::MediaPlayer();
m_mediaPlayer->setDrawable( m_ui->clipRenderWidget->winId() );
// m_mediaList = new LibVLCpp::MediaList();
// m_mediaList->setMediaPlayer( m_mediaPlayer );
m_mediaPlayer->setDrawable( renderWidget->winId() );
}
ClipPreviewWidget::~ClipPreviewWidget()
{
delete m_mediaPlayer;
delete m_ui;
}
void ClipPreviewWidget::changeEvent( QEvent *e )
{
switch ( e->type() )
{
case QEvent::LanguageChange:
m_ui->retranslateUi( this );
break;
default:
break;
}
}
void ClipPreviewWidget::dragEnterEvent( QDragEnterEvent* event )
void ClipPreviewWidget::startPreview( Media* media )
{
if ( event->mimeData()->hasFormat( "vlmc/uuid" ) )
event->acceptProposedAction();
else if ( event->mimeData()->urls().count() == 1 )
event->acceptProposedAction();
}
void ClipPreviewWidget::dropEvent( QDropEvent* event )
{
Media* media;
if ( event->mimeData()->urls().count() == 1 )
{
Library* lib = Library::getInstance();
lib->newMediaLoadingAsked( event->mimeData()->urls()[0].path() );
media = lib->getMedia( event->mimeData()->urls()[0].path() );
}
else
media = Library::getInstance()->getMedia( QUuid( ( const QString& )event->mimeData()->data( "vlmc/uuid" ) ) );
media->flushParameters();
m_mediaPlayer->setMedia( media->getVLCMedia() );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( videoPaused() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( videoPaused() ) );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( videoPlaying() ) );
connect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( positionChanged() ) );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( endReached() ) );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoPaused() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ) );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( __videoPlaying() ) );
connect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( __positionChanged() ) );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( __endReached() ) );
m_mediaPlayer->play();
m_clipLoaded = true;
m_videoStopped = false;
event->acceptProposedAction();
}
void ClipPreviewWidget::positionChanged()
{
if ( m_clipLoaded == false)
return ;
m_ui->seekSlider->setValue( (int)( m_mediaPlayer->getPosition() * 1000.0 ) );
}
void ClipPreviewWidget::seekSliderPressed()
{
disconnect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( positionChanged() ) );
}
void ClipPreviewWidget::seekSliderMoved( int )
void ClipPreviewWidget::setPosition( float newPos )
{
if ( m_clipLoaded == false || m_videoStopped == true )
return ;
if ( m_ui->seekSlider->value() == m_ui->seekSlider->maximum() )
{
m_endReached = true;
return;
}
m_endReached = false;
m_mediaPlayer->setPosition( (float)m_ui->seekSlider->value() / 1000.0 );
}
void ClipPreviewWidget::seekSliderReleased()
{
if ( m_endReached == true && m_videoStopped == false )
{
//When cursor reaches the maximum right, end reached becomes true.
//When we will release our slider, if endReached is true, we actually set the position.
//Otherwise, we do nothing.
//This prevents the video to stop if we put the slider to the maximum right by mistake
m_mediaPlayer->setPosition( (float)m_ui->seekSlider->maximum() / 1000.0 );
m_endReached = false;
}
connect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( positionChanged() ) );
m_mediaPlayer->setPosition( newPos / 1000.0 );
}
void ClipPreviewWidget::on_pushButtonPlay_clicked()
void ClipPreviewWidget::togglePlayPause()
{
if ( m_clipLoaded == false)
return ;
......@@ -159,24 +72,29 @@ void ClipPreviewWidget::on_pushButtonPlay_clicked()
m_mediaPlayer->play();
}
void ClipPreviewWidget::videoPaused()
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
void ClipPreviewWidget::__videoPaused()
{
emit paused();
}
void ClipPreviewWidget::__videoPlaying()
{
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
emit playing();
}
void ClipPreviewWidget::videoPlaying()
void ClipPreviewWidget::__positionChanged()
{
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/pause" ) );
if ( m_clipLoaded == false)
return ;
emit positionChanged( m_mediaPlayer->getPosition() );
}
void ClipPreviewWidget::endReached()
void ClipPreviewWidget::__endReached()
{
//Media player part :
m_mediaPlayer->stop();
m_videoStopped = true;
//GUI part :
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
m_ui->seekSlider->setValue( 0 );
emit endReached();
}
......@@ -20,50 +20,45 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef PREVIEWWIDGET_H
#define PREVIEWWIDGET_H
#ifndef CLIPPREVIEWWIDGET_H
#define CLIPPREVIEWWIDGET_H
#include <QtGui/QDialog>
#include <QDragEnterEvent>
#include <QUuid>
#include <QWidget>
#include <QObject>
#include "VLCMediaPlayer.h"
#include "VLCMediaList.h"
#include "Media.h"
namespace Ui {
class PreviewWidget;
}
class ClipPreviewWidget : public QWidget
class ClipPreviewWidget : public QObject
{
Q_OBJECT
Q_DISABLE_COPY( ClipPreviewWidget )
public:
explicit ClipPreviewWidget( QWidget *parent = 0 );
explicit ClipPreviewWidget( QWidget* renderWidget );
virtual ~ClipPreviewWidget();
protected:
virtual void changeEvent( QEvent *e );
virtual void dragEnterEvent( QDragEnterEvent* event );
virtual void dropEvent( QDropEvent* event );
private slots:
void on_pushButtonPlay_clicked();
void positionChanged();
void seekSliderPressed();
void seekSliderMoved( int value );
void seekSliderReleased();
void videoPaused();
void videoPlaying();
void endReached();
void startPreview( Media* media );
void setPosition( float newPos );
void togglePlayPause();
private:
Ui::PreviewWidget* m_ui;
LibVLCpp::MediaPlayer* m_mediaPlayer;
// LibVLCpp::MediaList* m_mediaList;
bool m_clipLoaded;
bool m_endReached;
bool m_videoStopped;
public slots:
void __positionChanged();
void __videoPaused();
void __videoPlaying();
void __endReached();
signals:
void stopped();
void paused();
void playing();
void positionChanged( float );
void endReached();
};
#endif // PREVIEWWIDGET_H
#endif // CLIPPREVIEWWIDGET_H
......@@ -34,6 +34,7 @@
#include "About.h"
#include "Transcode.h"
#include "FileBrowser.h"
#include "PreviewWidget.h"
MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent )
......@@ -140,7 +141,7 @@ void MainWindow::m_initializeDockWidgets( void )
setupLibrary();
dockManager->addDockedWidget( new ClipPreviewWidget( this ),
dockManager->addDockedWidget( new PreviewWidget( this ),
tr( "Preview" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures,
......
......@@ -26,7 +26,6 @@
#include <QApplication>
#include <QSlider>
#include "ui_MainWindow.h"
#include "ClipPreviewWidget.h"
#include "DockWidgetManager.h"
#include "Preferences.h"
#include "MetaDataManager.h"
......
/*****************************************************************************
* 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.
*****************************************************************************/
#include <QUrl>
#include "ui_PreviewWidget.h"
#include "gui/PreviewWidget.h"
#include "MediaListWidget.h"
#include "Library.h"
PreviewWidget::PreviewWidget( QWidget *parent ) :
QWidget( parent ),
m_ui( new Ui::PreviewWidget ), m_previewStopped( true )
{
m_ui->setupUi( this );
m_ui->groupBoxButton->hide();
m_ui->seekSlider->setMinimum( 0 );
m_ui->seekSlider->setMaximum( 1000 );
m_ui->seekSlider->setSingleStep( 2 );
m_ui->seekSlider->setFocusPolicy( Qt::NoFocus );
setAcceptDrops( true );
connect( m_ui->seekSlider, SIGNAL( sliderPressed() ), this, SLOT( seekSliderPressed() ) );
connect( m_ui->seekSlider, SIGNAL( sliderPosChanged(int) ), this, SLOT( seekSliderMoved(int) ) );
connect( m_ui->seekSlider, SIGNAL( sliderReleased() ), this, SLOT( seekSliderReleased() ) );
m_clipPreview = new ClipPreviewWidget( m_ui->clipRenderWidget );
}
PreviewWidget::~PreviewWidget()
{
delete m_ui;
}
void PreviewWidget::changeEvent( QEvent *e )
{
switch ( e->type() )
{
case QEvent::LanguageChange:
m_ui->retranslateUi( this );
break;
default:
break;
}
}
void PreviewWidget::dragEnterEvent( QDragEnterEvent* event )
{
if ( event->mimeData()->hasFormat( "vlmc/uuid" ) )
event->acceptProposedAction();
else if ( event->mimeData()->urls().count() == 1 )
event->acceptProposedAction();
}
void PreviewWidget::dropEvent( QDropEvent* event )
{
Media* media;
if ( event->mimeData()->urls().count() == 1 )
{
Library* lib = Library::getInstance();
lib->newMediaLoadingAsked( event->mimeData()->urls()[0].path() );
media = lib->getMedia( event->mimeData()->urls()[0].path() );
}
else
media = Library::getInstance()->getMedia( QUuid( ( const QString& )event->mimeData()->data( "vlmc/uuid" ) ) );
connect( m_clipPreview, SIGNAL( stopped() ), this, SLOT( videoPaused() ) );
connect( m_clipPreview, SIGNAL( paused() ), this, SLOT( videoPaused() ) );
connect( m_clipPreview, SIGNAL( playing() ), this, SLOT( videoPlaying() ) );
connect( m_clipPreview, SIGNAL( positionChanged(float) ), this, SLOT( positionChanged(float) ) );
connect( m_clipPreview, SIGNAL( endReached() ), this, SLOT( endReached() ) );
m_clipPreview->startPreview( media );
event->acceptProposedAction();
m_previewStopped = false;
}
void PreviewWidget::positionChanged( float newPos )
{
m_ui->seekSlider->setValue( (int)( newPos * 1000.0 ) );
}
void PreviewWidget::seekSliderPressed()
{
disconnect( m_clipPreview, SIGNAL( positionChanged( float ) ),
this, SLOT( positionChanged( float ) ) );
}
void PreviewWidget::seekSliderMoved( int )
{
if ( m_ui->seekSlider->value() == m_ui->seekSlider->maximum() )
{
m_endReached = true;
return;
}
m_endReached = false;
m_clipPreview->setPosition( (float)m_ui->seekSlider->value() );
}
void PreviewWidget::seekSliderReleased()
{
if ( m_endReached == true && m_previewStopped == false )
{
//When cursor reaches the maximum right, end reached becomes true.
//When we will release our slider, if endReached is true, we actually set the position.
//Otherwise, we do nothing.
//This prevents the video to stop if we put the slider to the maximum right by mistake
m_clipPreview->setPosition( (float)m_ui->seekSlider->maximum() );
m_previewStopped = false;
}
connect( m_clipPreview, SIGNAL( positionChanged( float ) ), this, SLOT( positionChanged( float ) ) );
}
void PreviewWidget::on_pushButtonPlay_clicked()
{
if ( m_previewStopped == true )
m_previewStopped = false;
m_clipPreview->togglePlayPause();
}
void PreviewWidget::videoPaused()
{
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
}
void PreviewWidget::videoPlaying()
{
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/pause" ) );
}
void PreviewWidget::endReached()
{
m_previewStopped = true;
m_ui->pushButtonPlay->setIcon( QIcon( ":/images/play" ) );
m_ui->seekSlider->setValue( 0 );
}
/*****************************************************************************
* PreviewWidget: Main preview widget
*****************************************************************************
* 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.
*****************************************************************************/
#ifndef PREVIEWWIDGET_H
#define PREVIEWWIDGET_H
#include <QWidget>
#include "ClipPreviewWidget.h"
namespace Ui {
class PreviewWidget;
}
class PreviewWidget : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY( PreviewWidget )
public:
explicit PreviewWidget( QWidget* parent = NULL );
virtual ~PreviewWidget();
private:
Ui::PreviewWidget* m_ui;
ClipPreviewWidget* m_clipPreview;
bool m_endReached;
bool m_previewStopped;
protected:
virtual void changeEvent( QEvent *e );
virtual void dragEnterEvent( QDragEnterEvent* event );
virtual void dropEvent( QDropEvent* event );
private slots:
void on_pushButtonPlay_clicked();
void positionChanged( float );
void seekSliderPressed();
void seekSliderMoved( int value );
void seekSliderReleased();
void videoPaused();
void videoPlaying();
void endReached();
};
#endif // PREVIEWWIDGET_H
......@@ -42,7 +42,8 @@ SOURCES += src/main.cpp \
src/Track.cpp \
src/Workflow/ClipWorkflow.cpp \
src/Workflow/TrackWorkflow.cpp \
src/Workflow/MainWorkflow.cpp
src/Workflow/MainWorkflow.cpp \
src/gui/PreviewWidget.cpp
HEADERS += src/gui/MainWindow.h \
src/gui/DockWidgetManager.h \
src/gui/LibraryWidget.h \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment