Commit 324b5912 authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere

Merge branch 'master' into geoff_audioSpectrum

parents 69ea3b20 50aa150e
......@@ -67,10 +67,8 @@ void ProjectSettingsDefault::loadProjectDefaults( const QString& part )
{
SettingsManager* setMan = SettingsManager::getInstance();
QVariant defaultName = "project";
QVariant defaultPath = "./";
setMan->setValue( part, "ProjectName", defaultName );
setMan->setValue( part, "ProjectDirectory", defaultPath );
return ;
}
......
/*****************************************************************************
* FileBrowser.cpp: FileBrowser Widget
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Christophe Courtaut <christophe.courtaut@gmail.com>
*
* 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 "FileBrowser.h"
#include "Library.h"
#include <QStringList>
#include <QtDebug>
FileBrowser::FileBrowser( QWidget* parent ) : QWidget( parent )
{
m_ui.setupUi( this );
m_DirsModel = new QDirModel();
m_FilesModel = new QDirModel();
m_previousEntries = new QStack<QModelIndex>();
m_forwadEntries = new QStack<QModelIndex>();
QStringList filters;
filters << "*.mp3" << "*.oga" << "*.flac" << "*.aac" << "*.wav";
filters << "*.mov" << "*.avi" << "*.mkv" << "*.mpg" << "*.mpeg" << "*.wmv" << "*.mp4";
filters << "*.gif" << "*.png" << "*.jpg" << "*.jpeg";
m_FilesModel->setFilter( QDir::AllDirs | QDir::Files | QDir::Readable | QDir::NoDotAndDotDot );
m_FilesModel->sort( 2, Qt::AscendingOrder );
m_FilesModel->sort( 0, Qt::AscendingOrder );
m_FilesModel->setNameFilters( filters );
m_ui.listViewBrowser->setModel( m_FilesModel );
m_ui.listViewBrowser->setRootIndex( m_FilesModel->index( QDir::homePath() ) );
m_DirsModel->setFilter( ( QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Readable ) );
m_ui.treeViewBrowser->setModel( m_DirsModel );
m_ui.treeViewBrowser->setRootIndex( m_DirsModel->index( QDir::rootPath() ) );
m_ui.treeViewBrowser->setCurrentIndex( m_DirsModel->index( QDir::homePath() ) );
m_ui.treeViewBrowser->setExpanded( m_ui.treeViewBrowser->currentIndex() , true );
m_ui.treeViewBrowser->setColumnHidden( 1, true );
m_ui.treeViewBrowser->setColumnHidden( 2, true );
m_ui.treeViewBrowser->setColumnHidden( 3, true );
m_ui.pushButtonBackward->setEnabled( false );
m_ui.pushButtonForward->setEnabled( false );
m_fsWatcher = new QFileSystemWatcher;
m_fsWatcher->addPath( QDir::homePath() );
m_currentlyWatchedDir = QDir::homePath();
connect( m_fsWatcher, SIGNAL( directoryChanged(QString) ), m_DirsModel, SLOT( refresh() ) );
connect( m_fsWatcher, SIGNAL( directoryChanged(QString) ), m_FilesModel, SLOT( refresh() ) );
}
FileBrowser::~FileBrowser()
{
delete m_fsWatcher;
delete m_DirsModel;
delete m_FilesModel;
delete m_forwadEntries;
delete m_previousEntries;
}
void FileBrowser::addElementToHistory()
{
m_previousEntries->push( m_DirsModel->index( m_FilesModel->filePath( m_ui.listViewBrowser->rootIndex() ) ) );
if ( m_previousEntries->count() > 10 )
m_previousEntries->pop_back();
m_ui.pushButtonBackward->setEnabled( true );
}
void FileBrowser::ListViewBrowserDirectoryChanged( QModelIndex& index, bool history )
{
if ( history == true )
addElementToHistory();
m_ui.listViewBrowser->setRootIndex( index );
m_ui.treeViewBrowser->setCurrentIndex( m_DirsModel->index( m_FilesModel->filePath( index ) ) );
}
void FileBrowser::TreeViewBrowserDirectoryChanged( QModelIndex& index, bool history )
{
if ( m_DirsModel->isDir( index ) )
{
updateFsWatcher( m_DirsModel->filePath( index ) );
if ( history == true )
addElementToHistory();
m_ui.listViewBrowser->setRootIndex( m_FilesModel->index( m_DirsModel->filePath( index ) ) );
}
}
void FileBrowser::on_treeViewBrowser_clicked( QModelIndex index )
{
TreeViewBrowserDirectoryChanged( index );
m_forwadEntries->clear();
m_ui.pushButtonForward->setEnabled( false );
}
void FileBrowser::on_listViewBrowser_doubleClicked( QModelIndex index )
{
if ( m_FilesModel->isDir( index ) )
{
updateFsWatcher( m_FilesModel->filePath( index ) );
ListViewBrowserDirectoryChanged( index );
m_forwadEntries->clear();
m_ui.pushButtonForward->setEnabled( false );
}
else //TODO: this should be a signal.
Library::getInstance()->newMediaLoadingAsked( m_FilesModel->filePath( index ) );
}
void FileBrowser::on_pushButtonBackward_clicked()
{
if ( !m_previousEntries->isEmpty() )
{
m_forwadEntries->push( m_ui.treeViewBrowser->currentIndex() );
TreeViewBrowserDirectoryChanged( m_previousEntries->first() , false );
m_ui.treeViewBrowser->setCurrentIndex( m_previousEntries->pop() );
m_ui.pushButtonForward->setEnabled( true );
if ( m_previousEntries->isEmpty() )
m_ui.pushButtonBackward->setEnabled( false );
}
}
void FileBrowser::on_pushButtonForward_clicked()
{
if ( !m_forwadEntries->isEmpty() )
{
m_previousEntries->push( m_ui.treeViewBrowser->currentIndex() );
TreeViewBrowserDirectoryChanged( m_forwadEntries->first() , false );
m_ui.treeViewBrowser->setCurrentIndex( m_forwadEntries->pop() );
m_ui.pushButtonBackward->setEnabled( true );
if ( m_forwadEntries->isEmpty() )
m_ui.pushButtonForward->setEnabled( false );
}
}
void FileBrowser::on_pushButtonParent_clicked()
{
if ( !QDir(m_DirsModel->filePath( m_ui.treeViewBrowser->currentIndex() )).isRoot() )
{
addElementToHistory();
updateFsWatcher( m_DirsModel->filePath( m_ui.treeViewBrowser->currentIndex().parent() ) );
m_ui.listViewBrowser->setRootIndex( m_FilesModel->index( m_DirsModel->filePath( m_ui.treeViewBrowser->currentIndex().parent() ) ) );
m_ui.treeViewBrowser->setCurrentIndex( m_DirsModel->index( m_FilesModel->filePath( m_ui.listViewBrowser->rootIndex() ) ) );
}
}
void FileBrowser::updateFsWatcher( const QString& newPath )
{
m_fsWatcher->removePath( m_currentlyWatchedDir );
m_currentlyWatchedDir = newPath;
m_fsWatcher->addPath( newPath );
}
/*****************************************************************************
* FileBrowser.h: FileBrowser Widget
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Christophe Courtaut <christophe.courtaut@gmail.com>
*
* 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 FILEBROWSER_H
#define FILEBROWSER_H
#include <QWidget>
#include <QDirModel>
#include <QStack>
#include <QFileSystemWatcher>
#include "ui_FileBrowser.h"
class FileBrowser : public QWidget
{
Q_OBJECT
public:
FileBrowser( QWidget* parent = NULL );
virtual ~FileBrowser();
private:
void addElementToHistory();
void ListViewBrowserDirectoryChanged( QModelIndex& index, bool history = true );
void TreeViewBrowserDirectoryChanged( QModelIndex& index, bool history = true );
void updateFsWatcher( const QString& newPath );
private:
Ui::FileBrowser m_ui;
QDirModel* m_DirsModel;
QDirModel* m_FilesModel;
QStack<QModelIndex>* m_previousEntries;
QStack<QModelIndex>* m_forwadEntries;
QFileSystemWatcher* m_fsWatcher;
QString m_currentlyWatchedDir;
private slots:
void on_pushButtonParent_clicked();
void on_pushButtonForward_clicked();
void on_pushButtonBackward_clicked();
void on_listViewBrowser_doubleClicked( QModelIndex index);
void on_treeViewBrowser_clicked( QModelIndex index );
};
#endif /* !FILEBROWSER_H */
FORMS += ui/About.ui \
ui/ClipProperty.ui \
ui/FileBrowser.ui \
ui/Import.ui \
ui/LibraryWidget.ui \
ui/LoadPage.ui \
ui/MainWindow.ui \
ui/PreviewWidget.ui \
......@@ -16,7 +14,6 @@ HEADERS += About.h \
ClickableLabel.h \
ClipProperty.h \
DockWidgetManager.h \
FileBrowser.h \
FileInfoListModel.h \
GraphicsAudioItem.h \
GraphicsCursorItem.h \
......@@ -26,10 +23,7 @@ HEADERS += About.h \
ImportMediaListController.h \
LanguagePreferences.h \
LCDTimecode.h \
LibraryWidget.h \
ListViewMediaItem.h \
MainWindow.h \
MediaListWidget.h \
PreviewRuler.h \
PreviewWidget.h \
TagWidget.h \
......@@ -46,7 +40,6 @@ SOURCES += About.cpp \
ClickableLabel.cpp \
ClipProperty.cpp \
DockWidgetManager.cpp \
FileBrowser.cpp \
FileInfoListModel.cpp \
GraphicsAudioItem.cpp \
GraphicsCursorItem.cpp \
......@@ -55,10 +48,7 @@ SOURCES += About.cpp \
ImportMediaListController.cpp \
LanguagePreferences.cpp \
LCDTimecode.cpp \
LibraryWidget.cpp \
ListViewMediaItem.cpp \
MainWindow.cpp \
MediaListWidget.cpp \
PreviewRuler.cpp \
PreviewWidget.cpp \
TagWidget.cpp \
......
......@@ -192,11 +192,7 @@ void GraphicsMovieItem::hoverMoveEvent( QGraphicsSceneHoverEvent* event )
if ( tracksView()->tool() == TOOL_DEFAULT )
{
QPoint mouseMapped = tracksView()->mapFromScene( event->pos() );
QPoint sizeMapped = tracksView()->mapFromScene( boundingRect().width(), boundingRect().height() );
if ( mouseMapped.x() < RESIZE_ZONE ||
mouseMapped.x() > ( sizeMapped.x() - RESIZE_ZONE ) )
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::OpenHandCursor );
......@@ -208,7 +204,12 @@ void GraphicsMovieItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
setCursor( Qt::ClosedHandCursor );
{
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::ClosedHandCursor );
}
else if ( tracksView()->tool() == TOOL_CUT )
emit split( this, qRound64( event->pos().x() ) );
}
......@@ -221,3 +222,18 @@ void GraphicsMovieItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
if ( tracksView()->tool() == TOOL_DEFAULT )
setCursor( Qt::OpenHandCursor );
}
bool GraphicsMovieItem::resizeZone( const QPointF& position )
{
// Get the current transformation of the view and invert it.
QTransform transform = tracksView()->transform().inverted();
// Map the RESIZE_ZONE distance from the view to the item coordinates.
QLine line = transform.map( QLine( 0, 0, RESIZE_ZONE, 0 ) );
if ( position.x() < line.x2() ||
position.x() > ( boundingRect().width() - line.x2() ) )
{
return true;
}
return false;
}
......@@ -60,6 +60,7 @@ protected:
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
private:
bool resizeZone( const QPointF& position );
Clip* m_clip;
signals:
......
......@@ -31,6 +31,7 @@
class LanguagePreferences : public PreferenceWidget
{
Q_OBJECT
public:
LanguagePreferences( QWidget* parent = 0 );
~LanguagePreferences();
......
/*****************************************************************************
* LibraryWidget.cpp: Multimedia library
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Clement CHAVANCE <chavance.c@gmail.com>
* Christophe Courtaut <christophe.courtaut@gmail.com>
*
* 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 <QDir>
#include <QUrl>
#include "LibraryWidget.h"
LibraryWidget::LibraryWidget( QWidget *parent ) : QWidget( parent ), m_firstDirectoryBrowsing(true)
{
m_ui.setupUi( this );
m_ui.listWidgetAudio->setType( Media::Audio );
m_ui.listWidgetImage->setType( Media::Image );
m_ui.listWidgetVideo->setType( Media::Video );
setAcceptDrops( true );
// *Always* force the selection of the first tab
m_ui.LibraryTabs->setCurrentIndex( 0 );
m_clips = new QList<ListViewMediaItem*>;
connect( m_ui.filterInput, SIGNAL( textChanged( QString ) ), this, SLOT( updateFilter( QString ) ) );
connect( m_ui.clearFilterButton, SIGNAL( clicked() ), m_ui.filterInput, SLOT( clear() ) );
connect( m_ui.LibraryTabs, SIGNAL( currentChanged( int ) ), this, SLOT( tabChanged( int ) ) );
}
LibraryWidget::~LibraryWidget()
{
while ( m_clips->isEmpty() == false )
delete m_clips->takeLast();
delete m_clips;
}
ListViewMediaItem* LibraryWidget::addClip( Clip* clip )
{
Media::FileType fileType = clip->getParent()->getFileType();
ListViewMediaItem* item = new ListViewMediaItem( clip, fileType );
m_clips->append( item );
switch ( fileType )
{
case Media::Audio:
m_ui.listWidgetAudio->addItem( item );
break;
case Media::Video:
m_ui.listWidgetVideo->addItem( item );
break;
case Media::Image:
m_ui.listWidgetImage->addItem( item );
break;
}
return item;
}
void LibraryWidget::mediaRemoved( const QUuid& uuid )
{
removeMedia( uuid );
}
void LibraryWidget::removeMedia( const QUuid& uuid )
{
ListViewMediaItem* item;
foreach (item, *m_clips)
{
if ( item->getClip()->getParent()->getUuid() == uuid )
{
switch( item->getFileType() )
{
case Media::Audio:
m_ui.listWidgetAudio->removeItemWidget( item );
m_ui.listWidgetAudio->unsetSelectedClip();
break;
case Media::Image:
m_ui.listWidgetImage->removeItemWidget( item );
m_ui.listWidgetImage->unsetSelectedClip();
break;
case Media::Video:
m_ui.listWidgetVideo->removeItemWidget( item );
m_ui.listWidgetVideo->unsetSelectedClip();
break;
}
m_clips->removeOne( item );
delete item;
return ;
}
}
}
//
//ListViewMediaItem* LibraryWidget::insertNewMedia( QString fileName, ListViewMediaItem::fType fileType )
//{
// ListViewMediaItem* item = NULL;
// foreach( item, *m_medias )
// {
// if ( item->getClip()->getFileInfo()->absoluteFilePath() == fileName )
// return item;
// }
// QFileInfo* fileInfo = new QFileInfo( fileName );
// item = addMedia( fileInfo, fileType );
// delete fileInfo;
// return item;
//}
void LibraryWidget::newClipLoaded( Clip* clip )
{
addClip( clip );
m_ui.LibraryTabs->setCurrentIndex( (int) clip->getParent()->getFileType() );
}
void LibraryWidget::insertNewMediasFromFileDialog( QString title, QString filter, Media::FileType fileType )
{
Q_UNUSED( fileType );
QSettings settings;
QString path;
if ( m_firstDirectoryBrowsing == true )
path = settings.value( "mediaLibraryDialogPath", QDir::homePath() ).toString();
else
path = m_lastDirectoryBrowsed;
QStringList fileNames = QFileDialog::getOpenFileNames( this, title, path, filter );
if ( fileNames.isEmpty() )
return ;
m_lastDirectoryBrowsed = QFileInfo( fileNames.front() ).absolutePath();
m_firstDirectoryBrowsing = false;
QString filePath;
// ListViewMediaItem* item = NULL;
foreach ( filePath, fileNames )
{
// item = insertNewMedia( fileName, filetype );
// if( fileType == Media::Video )
emit newMediaLoadingAsked( filePath );
}
// if ( item != NULL )
// settings.setValue( "mediaLibraryDialogPath" , item->getClip()->getFileInfo()->absoluteDir().absolutePath() );
// return ;
}
void LibraryWidget::on_pushButtonAddMedia_clicked()
{
switch( m_ui.LibraryTabs->currentIndex() )
{
case 0:
insertNewMediasFromFileDialog( tr( "Open Audios" ),
tr( "Audio Files" ) + " (" + Media::AudioExtensions + ")" ,
Media::Audio );
break;
case 1:
insertNewMediasFromFileDialog( tr( "Open Videos" ),
tr( "Video Files" ) + " (" + Media::VideoExtensions + ")" ,
Media::Video );
break;
case 2:
insertNewMediasFromFileDialog( tr( "Open Images" ),
tr( "Images Files" ) + " (" + Media::ImageExtensions + ")" ,
Media::Image );
break;
}
}
void LibraryWidget::on_pushButtonRemoveMedia_clicked()
{
QListWidget* mediaList = ( QListWidget* )( m_ui.LibraryTabs->currentWidget()->children().back() );
ListViewMediaItem* item = ( ListViewMediaItem* ) mediaList->currentItem();
if ( !item ) return;
// removeMedia( item );
emit removingMediaAsked( item->getClip()->getParent()->getUuid() );
}
void LibraryWidget::changeEvent( QEvent *e )
{
switch ( e->type() )
{
case QEvent::LanguageChange:
m_ui.retranslateUi( this );
break;
default:
break;
}
}
void LibraryWidget::dragEnterEvent( QDragEnterEvent* event )
{
if ( event->mimeData()->urls().count() >= 1 )
event->acceptProposedAction();
}
void LibraryWidget::dropEvent( QDropEvent* event )
{
QUrl url;
Library* lib = Library::getInstance();
foreach ( url, event->mimeData()->urls() )
{
lib->newMediaLoadingAsked( url.path() );
}
}
const MediaListWidget* LibraryWidget::getVideoListWidget() const
{
return m_ui.listWidgetVideo;
}
const MediaListWidget* LibraryWidget::getAudioListWidget() const
{
return m_ui.listWidgetAudio;
}
void LibraryWidget::updateFilter( const QString& filter )
{
QListWidget* mediaList = ( QListWidget* )( m_ui.LibraryTabs->currentWidget()->children().back() );
unsigned int count = mediaList->count();
for ( unsigned int i = 0; i < count; ++i )
{
ListViewMediaItem* item = static_cast<ListViewMediaItem*>( mediaList->item( i ) );
if ( item != NULL )
{
QString filename = item->getClip()->getParent()->getFileInfo()->fileName();
if ( !filename.contains( filter, Qt::CaseInsensitive ) && !item->getClip()->matchMetaTag( filter ) )
item->setHidden( true );
else
item->setHidden( false );
}
}
}
void LibraryWidget::tabChanged( int )
{
updateFilter( m_ui.filterInput->text() );
}
/*****************************************************************************
* LibraryWidget.h: Multimedia library GUI
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Clement CHAVANCE <chavance.c@gmail.com>
* Christophe Courtaut <christophe.courtaut@gmail.com>
*
* 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 LIBRARYWIDGET_H
#define LIBRARYWIDGET_H
#include <QTabWidget>
#include <QListWidget>
#include <QFileInfoList>
#include <QMessageBox>
#include <QFileDialog>
#include <QtDebug>
#include <QMimeData>
#include <QDrag>
#include <QList>
#include <QSettings>