MainWindow.cpp 13.5 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"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
37
#include "Library.h"
38
#include "Timeline.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
39
#include "About.h"
40
#include "WorkflowRenderer.h"
41
#include "ClipRenderer.h"
42
#include "UndoStack.h"
43
#include "ClipProperty.h"
44
#include "PreviewWidget.h"
45 46
#include "PreferenceWidget.h"
#include "ProjectPreferences.h"
47
#include "ProjectManager.h"
48 49
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
50 51
#include "VLMCSettingsDefault.h"
#include "ProjectSettingsDefault.h"
52
#include "VLMCPreferences.h"
53
#include "Import.h"
54
#include "MediaLibraryWidget.h"
55
#include "LanguagePreferences.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
    qRegisterMetaType<MainWorkflow::TrackType>( "MainWorkflow::TrackType" );
62
    qRegisterMetaType<MainWorkflow::FrameChangedReason>( "MainWorkflow::FrameChangedReason" );
63
    DockWidgetManager::instance( this )->setMainWindow( this );
64
    initializeDockWidgets();
65
    createStatusBar();
66 67
    VLMCSettingsDefault::load( "default" );
    VLMCSettingsDefault::load( "VLMC" );
68
    m_pWizard = new ProjectWizard( this );
69
    createGlobalPreferences();
70
    createProjectPreferences();
71

Ludovic Fauvet's avatar
Ludovic Fauvet committed
72
    // Translations
73 74
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
75 76

    // Zoom
77 78
    connect( m_zoomSlider, SIGNAL( valueChanged( int ) ),
             m_timeline, SLOT( changeZoom( int ) ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
79 80 81 82
    connect( m_timeline->tracksView(), SIGNAL( zoomIn() ),
             this, SLOT( zoomIn() ) );
    connect( m_timeline->tracksView(), SIGNAL( zoomOut() ),
             this, SLOT( zoomOut() ) );
83 84
    connect( this, SIGNAL( toolChanged( ToolButtons ) ),
             m_timeline, SLOT( setTool( ToolButtons ) ) );
85 86 87 88 89 90

    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
91 92
}

93 94
MainWindow::~MainWindow()
{
95 96 97 98 99 100 101
    QSettings s;
    // Save the current geometry
    s.setValue( "MainWindowGeometry", saveGeometry() );
    // Save the current layout
    s.setValue( "MainWindowState", saveState() );
    s.sync();

102 103
    if ( m_renderer )
        delete m_renderer;
104
    LibVLCpp::Instance::destroyInstance();
105 106
}

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

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
120 121 122
void        MainWindow::setupLibrary()
{
    //GUI part :
123

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 );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
132 133
    connect( mediaLibraryWidget, SIGNAL( mediaSelected( Media* ) ),
             m_clipPreview->getGenericRenderer(), SLOT( setMedia( Media* ) ) );
134

135 136
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
137 138
}

139 140 141 142 143 144 145 146 147 148
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.
149 150 151 152 153 154 155
        QStringList list = outputFileName.split( "." );
        if ( list.at( list.size() - 1 ) != "vlmc" )
        {
            list.append( "vlmc" );
            outputFileName = list.join(".");
        }

156 157 158 159 160
        ProjectManager* pm = new ProjectManager( outputFileName );
        pm->saveProject();
    }
}

161 162 163
void    MainWindow::on_actionLoad_Project_triggered()
{
    QString outputFileName =
164
            QFileDialog::getOpenFileName( NULL, "Enter the output file name",
165 166 167 168 169 170 171 172 173 174 175
                                          QString(), "VLMC project file(*.vlmc)" );
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        //Project manager will destroy itself.
        ProjectManager* pm = new ProjectManager( outputFileName );
        pm->loadProject();
    }
}

176 177
void MainWindow::createStatusBar()
{
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    // 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 );

Ludovic Fauvet's avatar
Ludovic Fauvet committed
205 206 207 208 209 210
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
211 212

    // Zoom slider
213 214 215 216 217 218 219 220 221
    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 );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
222
    m_zoomSlider->setInvertedAppearance( true );
223
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
224

Ludovic Fauvet's avatar
Ludovic Fauvet committed
225 226 227 228 229 230
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
231 232
}

233
void MainWindow::initializeDockWidgets( void )
234
{
235 236
    WorkflowRenderer*    workflowRenderer = new WorkflowRenderer();
    m_timeline = new Timeline( workflowRenderer, this );
237 238 239
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
240

241 242
    DockWidgetManager *dockManager = DockWidgetManager::instance();

243 244
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
245
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
246 247 248
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
249 250
    QShortcut*  clipShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Return", "Start clip preview" ) ), this );
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
251

252
    m_projectPreview = new PreviewWidget( workflowRenderer, this );
253
    dockManager->addDockedWidget( m_projectPreview,
254 255 256
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
257
                                  Qt::TopDockWidgetArea );
258 259
    QShortcut*  renderShortcut = new QShortcut( QKeySequence( tr( "Space", "Start render preview" ) ), this );
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
260

261
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
262 263 264 265
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
266
    setupLibrary();
267 268
}

269 270
void        MainWindow::createGlobalPreferences()
{
271
    m_globalPreferences = new Settings( false, "VLMC", this );
272
    m_globalPreferences->addWidget("VLMC",
Ludovic Fauvet's avatar
Ludovic Fauvet committed
273
                                   new VLMCPreferences( m_globalPreferences ),
274 275
                                   "../images/vlmc.png",
                                   "VLMC settings");
276 277 278 279
    m_globalPreferences->addWidget("Language preferences",
                                   new LanguagePreferences( m_globalPreferences ),
                                   "../images/vlmc.png",
                                   "Langage settings");
280 281 282
    m_globalPreferences->build();
}

283 284
void	    MainWindow::createProjectPreferences()
{
285
    m_projectPreferences = new Settings( false, "project", this );
286 287
    m_projectPreferences->addWidget("Project",
                                   new ProjectPreferences,
288 289 290
                                   ":/images/images/vlmc",
                                   "Project settings" );
    m_projectPreferences->addWidget( "Video",
291
                                   new VideoProjectPreferences,
292 293 294
                                   ":/images/images/video",
                                   "Video settings" );
    m_projectPreferences->addWidget( "Audio",
295
                                   new AudioProjectPreferences,
296 297
                                   ":/images/images/audio",
                                   "Audio settings" );
298 299 300
    m_projectPreferences->build();
}

301

302 303
//Private slots definition

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

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

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

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

326 327
void    MainWindow::on_actionRender_triggered()
{
328
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
329 330 331 332 333 334
    {
        QMessageBox::warning( NULL, "VLMC Renderer", "There is nothing to render." );
        return ;
    }
    QString outputFileName =
            QFileDialog::getSaveFileName( NULL, "Enter the output file name",
335
                                          QDir::currentPath(), "Videos(*.avi *.mpg)" );
336 337 338 339 340 341
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        if ( m_renderer )
            delete m_renderer;
342
        m_renderer = new WorkflowFileRenderer( outputFileName );
343 344 345 346
        m_renderer->run();
    }
}

347 348 349 350
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
351 352

    m_projectPreferences->show();
353 354
}

355
void    MainWindow::on_actionHelp_triggered()
356 357
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
358 359
}

360 361
void    MainWindow::on_actionImport_triggered()
{
Thomas Boquet's avatar
Thomas Boquet committed
362 363
    //Import* import = new Import( );
    //import->exec();
364 365
}

366
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
367 368 369 370
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

371
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
372 373 374
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
375

376
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
377 378 379 380 381 382
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
383

384
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
385
{
386
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
387
}
388

389
void    MainWindow::toolButtonClicked( int id )
390 391 392
{
    emit toolChanged( (ToolButtons)id );
}
393

394 395 396 397 398 399 400 401 402 403 404
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

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

406 407
void MainWindow::on_actionProject_Preferences_triggered()
{
408
  m_projectPreferences->show( "project" );
409
}
410 411 412 413 414 415

void MainWindow::on_actionProject_Wizard_triggered()
{
    m_pWizard->show();
}