MainWindow.cpp 13.7 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>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34

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

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

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

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

    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
84 85
}

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

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

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

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

    //GUI part :
    LibraryWidget* libraryWidget = new LibraryWidget( this );
121
    MediaLibraryWidget* mediaLibraryWidget = new MediaLibraryWidget( this );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
122 123

    DockWidgetManager::instance()->addDockedWidget( libraryWidget,
124
                                  tr( "Old Media Library" ),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
125 126
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
Christophe Courtaut's avatar
Christophe Courtaut committed
127
                                  Qt::LeftDockWidgetArea );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
128

129 130 131 132 133 134
    DockWidgetManager::instance()->addDockedWidget( mediaLibraryWidget,
                                                    tr( "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
                                                    Qt::LeftDockWidgetArea );

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
135
    //Connecting GUI and Frontend :
136
    connect( libraryWidget,
137
             SIGNAL( newMediaLoadingAsked(const QString& ) ),
138
             library,
139
             SLOT( newMediaLoadingAsked( const QString& ) ) );
140 141

    connect( library,
142
             SIGNAL( newClipLoaded( Clip* ) ),
143
             libraryWidget,
144
             SLOT( newClipLoaded( Clip* ) ) );
145 146

    connect( libraryWidget,
147
             SIGNAL( removingMediaAsked( const QUuid& ) ),
148
             library,
149
             SLOT( removingMediaAsked( const QUuid& ) ) );
150 151

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

156 157
    connect( libraryWidget->getVideoListWidget(), SIGNAL( selectedClipChanged( Clip* ) ),
              m_clipPreview->getGenericRenderer(), SLOT( setClip( Clip* ) ) );
158 159 160 161 162 163

    connect( mediaLibraryWidget->getCurrentViewController(),
             SIGNAL( selectedClipChanged( Clip* ) ),
             m_clipPreview->getGenericRenderer(),
             SLOT( setClip( Clip* ) ) );

164 165
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
166 167
    connect( libraryWidget->getVideoListWidget(), SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
             this, SLOT( mediaListItemDoubleClicked( QListWidgetItem* ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
168 169
}

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
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.
        ProjectManager* pm = new ProjectManager( outputFileName );
        pm->saveProject();
    }
}

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
void    MainWindow::on_actionLoad_Project_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.
        ProjectManager* pm = new ProjectManager( outputFileName );
        pm->loadProject();
    }
}

200 201
void MainWindow::createStatusBar()
{
202 203 204 205 206 207 208 209 210 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
    // 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
237 238 239 240 241 242 243 244 245 246
    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 );
247 248 249 250 251 252 253

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

256
void MainWindow::initializeDockWidgets( void )
257
{
258 259 260 261
    m_timeline = new Timeline( this );
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
262

263
    DockWidgetManager *dockManager = DockWidgetManager::instance();
264 265 266 267 268
    dockManager->addDockedWidget( new FileBrowser( this ),
                                  tr( "FileBrowser" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea);
269

270 271
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
272
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
273 274 275
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
276

277
    m_projectPreview = new PreviewWidget( new WorkflowRenderer(), this );
278
    dockManager->addDockedWidget( m_projectPreview,
279 280 281
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
282
                                  Qt::TopDockWidgetArea );
283

284
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
285 286 287 288
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
289
    setupLibrary();
290
    m_metaDataManager = MetaDataManager::getInstance();
291 292
}

293 294
void        MainWindow::createGlobalPreferences()
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
295
    m_globalPreferences = new Settings( this );
296
    m_globalPreferences->addWidget("VLMC",
Ludovic Fauvet's avatar
Ludovic Fauvet committed
297
                                   new VLMCPreferences( m_globalPreferences ),
298 299
                                   "../images/vlmc.png",
                                   "VLMC settings");
300 301 302
    m_globalPreferences->build();
}

303 304
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
305 306 307 308
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
309 310 311

void MainWindow::on_actionPreferences_triggered()
{
312
   m_globalPreferences->show();
313
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
314 315 316 317 318

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

320
void MainWindow::on_actionTranscode_triggered()
321
{
322 323
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
324
    //Transcode::instance( this )->exec();
325
}
326

327 328 329 330 331 332 333 334 335
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",
336
                                          QDir::currentPath(), "Videos(*.avi *.mpg)" );
337 338 339 340 341 342
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        if ( m_renderer )
            delete m_renderer;
343
        m_renderer = new WorkflowFileRenderer( outputFileName );
344 345 346 347
        m_renderer->run();
    }
}

348 349 350 351
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
352 353 354 355 356 357 358 359 360 361 362 363 364 365
    m_projectPreferences = new Settings(  );
    m_projectPreferences->addWidget("Project",
                                   new ProjectPreferences,
                                   "../images/vlmc.png",
                                   "Project settings");
    m_projectPreferences->addWidget("Video",
                                   new VideoProjectPreferences,
                                   "../images/scalable/video.svg",
                                   "Video settings");
    m_projectPreferences->addWidget("Audio",
                                   new AudioProjectPreferences,
                                   "../images/scalable/audio.svg",
                                   "Audio settings");
    m_projectPreferences->build();
366
    m_projectPreferences->exec();
367 368
}

369 370 371
void MainWindow::on_actionHelp_triggered()
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
372 373
}

374 375 376 377 378 379
void    MainWindow::on_actionImport_triggered()
{
    Import* import = new Import( );
    import->exec();
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
380 381 382 383 384 385 386 387 388
void MainWindow::zoomIn()
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

void MainWindow::zoomOut()
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
389 390 391 392 393 394 395 396

void MainWindow::on_actionFullscreen_triggered( bool checked )
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
397

398
void MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
399
{
400
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
401
}
402 403 404 405

void    MainWindow::mediaListItemDoubleClicked( QListWidgetItem* qItem )
{
    ListViewMediaItem* item = static_cast<ListViewMediaItem*>( qItem );
406
    ClipProperty* mp = new ClipProperty( item->getClip(), this );
407 408
    mp->show();
}
409 410 411 412 413

void MainWindow::toolButtonClicked( int id )
{
    emit toolChanged( (ToolButtons)id );
}