MainWindow.cpp 14.3 KB
Newer Older
Ludovic Fauvet's avatar
Ludovic Fauvet committed
1
/*****************************************************************************
2
 * MainWindow.cpp: VLMC MainWindow
Ludovic Fauvet's avatar
Ludovic Fauvet committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Ludovic Fauvet <etix@l0cal.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.
 *****************************************************************************/

23 24 25
#include <QLabel>
#include <QSizePolicy>
#include <QPalette>
Christophe Courtaut's avatar
Christophe Courtaut committed
26
#include <QDockWidget>
27
#include <QFileDialog>
28
#include <QSlider>
29
#include <QUndoView>
30
#include <QMessageBox>
31 32
#include <QDesktopServices>
#include <QUrl>
33
#include <QSettings>
34
#include <QStringList>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
35

Ludovic Fauvet's avatar
Ludovic Fauvet committed
36
#include "MainWindow.h"
37
#include "MediaListWidget.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
38 39
#include "LibraryWidget.h"
#include "Library.h"
40
#include "Timeline.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
41
#include "About.h"
42
#include "FileBrowser.h"
43
#include "WorkflowRenderer.h"
44
#include "ClipRenderer.h"
45
#include "UndoStack.h"
46
#include "ClipProperty.h"
47
#include "PreviewWidget.h"
48 49
#include "PreferenceWidget.h"
#include "ProjectPreferences.h"
50
#include "ProjectManager.h"
51 52 53
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
#include "VLMCPreferences.h"
54
#include "Import.h"
55
#include "MediaLibraryWidget.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
56 57

MainWindow::MainWindow( QWidget *parent ) :
58
    QMainWindow( parent ), m_renderer( NULL )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
59 60
{
    m_ui.setupUi( this );
61
    DockWidgetManager::instance( this )->setMainWindow( this );
62
    initializeDockWidgets();
63
    createStatusBar();
64
    createGlobalPreferences();
65
    createProjectPreferences();
66

Ludovic Fauvet's avatar
Ludovic Fauvet committed
67
    // Translations
68 69
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
70 71

    // Zoom
72 73
    connect( m_zoomSlider, SIGNAL( valueChanged( int ) ),
             m_timeline, SLOT( changeZoom( int ) ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
74 75 76 77
    connect( m_timeline->tracksView(), SIGNAL( zoomIn() ),
             this, SLOT( zoomIn() ) );
    connect( m_timeline->tracksView(), SIGNAL( zoomOut() ),
             this, SLOT( zoomOut() ) );
78 79
    connect( this, SIGNAL( toolChanged( ToolButtons ) ),
             m_timeline, SLOT( setTool( ToolButtons ) ) );
80 81 82 83 84 85

    QSettings s;
    // Restore the geometry
    restoreGeometry( s.value( "MainWindowGeometry" ).toByteArray() );
    // Restore the layout
    restoreState( s.value( "MainWindowState" ).toByteArray() );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
86 87
}

88 89
MainWindow::~MainWindow()
{
90 91 92 93 94 95 96
    QSettings s;
    // Save the current geometry
    s.setValue( "MainWindowGeometry", saveGeometry() );
    // Save the current layout
    s.setValue( "MainWindowState", saveState() );
    s.sync();

97 98
    if ( m_renderer )
        delete m_renderer;
99
    MetaDataManager::destroyInstance();
100
    LibVLCpp::Instance::destroyInstance();
101 102
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
103 104 105 106 107 108
void MainWindow::changeEvent( QEvent *e )
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui.retranslateUi( this );
109
        emit translateDockWidgetTitle();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
110 111 112 113 114 115
        break;
    default:
        break;
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
116 117 118 119 120 121
void        MainWindow::setupLibrary()
{
    //Library part :
    Library*    library = Library::getInstance();

    //GUI part :
122 123
    LibraryWidget* libraryWidget = new LibraryWidget( this );

124
    MediaLibraryWidget* mediaLibraryWidget = new MediaLibraryWidget( this );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
125

126 127 128 129
    DockWidgetManager::instance()->addDockedWidget( mediaLibraryWidget,
                                                    tr( "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
130

131
                                                    Qt::LeftDockWidgetArea );
132 133 134 135 136
    DockWidgetManager::instance()->addDockedWidget( libraryWidget,
                                      tr( "Old Media Library" ),
                                      Qt::AllDockWidgetAreas,
                                      QDockWidget::AllDockWidgetFeatures,
                                      Qt::LeftDockWidgetArea );
137

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
138
    //Connecting GUI and Frontend :
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    connect( libraryWidget,
             SIGNAL( newMediaLoadingAsked(const QString& ) ),
             library,
             SLOT( newMediaLoadingAsked( const QString& ) ) );

    connect( library,
             SIGNAL( newClipLoaded( Clip* ) ),
             libraryWidget,
             SLOT( newClipLoaded( Clip* ) ) );

    connect( libraryWidget,
             SIGNAL( removingMediaAsked( const QUuid& ) ),
             library,
             SLOT( removingMediaAsked( const QUuid& ) ) );

    connect( library,
             SIGNAL( mediaRemoved( const QUuid& ) ),
             libraryWidget,
             SLOT( mediaRemoved( const QUuid& ) ), Qt::DirectConnection );

    connect( libraryWidget->getVideoListWidget(), SIGNAL( selectedClipChanged( Clip* ) ),
              m_clipPreview->getGenericRenderer(), SLOT( setClip( Clip* ) ) );

    connect( libraryWidget->getVideoListWidget(), SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
                this, SLOT( mediaListItemDoubleClicked( QListWidgetItem* ) ) );

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
165 166
    connect( mediaLibraryWidget, SIGNAL( mediaSelected( Media* ) ),
             m_clipPreview->getGenericRenderer(), SLOT( setMedia( Media* ) ) );
167

168 169
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
170 171
}

172 173 174 175 176 177 178 179 180 181
void    MainWindow::on_actionSave_triggered()
{
    QString outputFileName =
            QFileDialog::getSaveFileName( NULL, "Enter the output file name",
                                          QString(), "VLMC project file(*.vlmc)" );
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        //Project manager will destroy itself.
182 183 184 185 186 187 188
        QStringList list = outputFileName.split( "." );
        if ( list.at( list.size() - 1 ) != "vlmc" )
        {
            list.append( "vlmc" );
            outputFileName = list.join(".");
        }

189 190 191 192 193
        ProjectManager* pm = new ProjectManager( outputFileName );
        pm->saveProject();
    }
}

194 195 196
void    MainWindow::on_actionLoad_Project_triggered()
{
    QString outputFileName =
197
            QFileDialog::getOpenFileName( NULL, "Enter the output file name",
198 199 200 201 202 203 204 205 206 207 208
                                          QString(), "VLMC project file(*.vlmc)" );
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        //Project manager will destroy itself.
        ProjectManager* pm = new ProjectManager( outputFileName );
        pm->loadProject();
    }
}

209 210
void MainWindow::createStatusBar()
{
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    // Mouse (default) tool
    QToolButton* mouseTool = new QToolButton( this );
    mouseTool->setCheckable( true );
    mouseTool->setIcon( QIcon( ":/images/mouse" ) );
    m_ui.statusbar->addPermanentWidget( mouseTool );

    // Cut/Split tool
    QToolButton* splitTool = new QToolButton( this );
    splitTool->setCheckable( true );
    splitTool->setIcon( QIcon( ":/images/editcut" ) );
    m_ui.statusbar->addPermanentWidget( splitTool );

    // Group the two previous buttons
    QButtonGroup* toolButtonGroup = new QButtonGroup( this );
    toolButtonGroup->addButton( mouseTool, TOOL_DEFAULT);
    toolButtonGroup->addButton( splitTool, TOOL_CUT );
    toolButtonGroup->setExclusive( true );
    mouseTool->setChecked( true );

    connect( toolButtonGroup, SIGNAL( buttonClicked( int ) ),
             this, SLOT( toolButtonClicked( int ) ) );

    // Spacer
    QWidget* spacer = new QWidget( this );
    spacer->setFixedWidth( 20 );
    m_ui.statusbar->addPermanentWidget( spacer );

    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );

    // Zoom slider
246 247 248 249 250 251 252 253 254 255
    m_zoomSlider = new QSlider( this );
    m_zoomSlider->setOrientation( Qt::Horizontal );
    m_zoomSlider->setTickInterval( 1 );
    m_zoomSlider->setSingleStep( 1 );
    m_zoomSlider->setPageStep( 1 );
    m_zoomSlider->setMinimum( 0 );
    m_zoomSlider->setMaximum( 13 );
    m_zoomSlider->setValue( 10 );
    m_zoomSlider->setFixedWidth( 80 );
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
256 257 258 259 260 261 262

    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
263 264
}

265
void MainWindow::initializeDockWidgets( void )
266
{
267 268 269 270
    m_timeline = new Timeline( this );
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
271

272
    DockWidgetManager *dockManager = DockWidgetManager::instance();
273 274 275 276 277
    dockManager->addDockedWidget( new FileBrowser( this ),
                                  tr( "FileBrowser" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea);
278

279 280
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
281
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
282 283 284
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
285

286
    m_projectPreview = new PreviewWidget( new WorkflowRenderer(), this );
287
    dockManager->addDockedWidget( m_projectPreview,
288 289 290
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
291
                                  Qt::TopDockWidgetArea );
292

293
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
294 295 296 297
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
298
    setupLibrary();
299
    m_metaDataManager = MetaDataManager::getInstance();
300 301
}

302 303
void        MainWindow::createGlobalPreferences()
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
304
    m_globalPreferences = new Settings( this );
305
    m_globalPreferences->addWidget("VLMC",
Ludovic Fauvet's avatar
Ludovic Fauvet committed
306
                                   new VLMCPreferences( m_globalPreferences ),
307 308
                                   "../images/vlmc.png",
                                   "VLMC settings");
309 310 311
    m_globalPreferences->build();
}

312 313 314
void	    MainWindow::createProjectPreferences()
{
    m_projectPreferences = new Settings(  );
315

316
    m_projectPreferences->addWidget( "Project",
317
                                   new ProjectPreferences,
318 319 320
                                   ":/images/images/vlmc",
                                   "Project settings" );
    m_projectPreferences->addWidget( "Video",
321
                                   new VideoProjectPreferences,
322 323 324
                                   ":/images/images/video",
                                   "Video settings" );
    m_projectPreferences->addWidget( "Audio",
325
                                   new AudioProjectPreferences,
326 327
                                   ":/images/images/audio",
                                   "Audio settings" );
328 329 330
    m_projectPreferences->build();
}

331 332
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
333 334 335 336
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
337 338 339

void MainWindow::on_actionPreferences_triggered()
{
340
   m_globalPreferences->show();
341
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
342 343 344 345 346

void MainWindow::on_actionAbout_triggered()
{
    About::instance()->exec();
}
347

348
void MainWindow::on_actionTranscode_triggered()
349
{
350 351
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
352
    //Transcode::instance( this )->exec();
353
}
354

355 356 357 358 359 360 361 362 363
void    MainWindow::on_actionRender_triggered()
{
    if ( MainWorkflow::getInstance()->getLength() <= 0 )
    {
        QMessageBox::warning( NULL, "VLMC Renderer", "There is nothing to render." );
        return ;
    }
    QString outputFileName =
            QFileDialog::getSaveFileName( NULL, "Enter the output file name",
364
                                          QDir::currentPath(), "Videos(*.avi *.mpg)" );
365 366 367 368 369 370
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        if ( m_renderer )
            delete m_renderer;
371
        m_renderer = new WorkflowFileRenderer( outputFileName );
372 373 374 375
        m_renderer->run();
    }
}

376 377 378 379
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
380 381

    m_projectPreferences->show();
382 383
}

384
void    MainWindow::on_actionHelp_triggered()
385 386
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
387 388
}

389 390
void    MainWindow::on_actionImport_triggered()
{
Thomas Boquet's avatar
Thomas Boquet committed
391 392
    //Import* import = new Import( );
    //import->exec();
393 394
}

395
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
396 397 398 399
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

400
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
401 402 403
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
404

405
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
406 407 408 409 410 411
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
412

413
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
414
{
415
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
416
}
417 418 419 420

void    MainWindow::mediaListItemDoubleClicked( QListWidgetItem* qItem )
{
    ListViewMediaItem* item = static_cast<ListViewMediaItem*>( qItem );
421
    ClipProperty* mp = new ClipProperty( item->getClip(), this );
422 423
    mp->show();
}
424

425
void    MainWindow::toolButtonClicked( int id )
426 427 428
{
    emit toolChanged( (ToolButtons)id );
}
429

430 431 432 433 434 435 436 437 438 439 440
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

    ee = MainWorkflow::getInstance()->getEffectsEngine();
    if (toggled)
        ee->enable();
    else
       ee->disable();
    return ;
}
441

442 443
void MainWindow::on_actionProject_Preferences_triggered()
{
Vincent Carrubba's avatar
Vincent Carrubba committed
444
    m_projectPreferences->show();
445
}