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

Ludovic Fauvet's avatar
Ludovic Fauvet committed
32
#include "MainWindow.h"
33
#include "MediaListWidget.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34 35
#include "LibraryWidget.h"
#include "Library.h"
36
#include "Timeline.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
37
#include "About.h"
38
#include "Transcode.h"
39
#include "FileBrowser.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 50
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
#include "VLMCPreferences.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
51 52

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

Ludovic Fauvet's avatar
Ludovic Fauvet committed
61
    // Translation
62 63
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
64 65

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

    //Global Preferences
    QObject::connect( qApp,
                      SIGNAL( aboutToQuit() ),
                      m_globalPreferences,
                      SLOT( deleteLater() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
80 81
}

82 83
MainWindow::~MainWindow()
{
84 85
    if ( m_renderer )
        delete m_renderer;
86
    MetaDataManager::destroyInstance();
87
    LibVLCpp::Instance::kill();
88 89
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
90 91 92 93 94 95
void MainWindow::changeEvent( QEvent *e )
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui.retranslateUi( this );
96
        emit translateDockWidgetTitle();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
97 98 99 100 101 102
        break;
    default:
        break;
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
103 104 105 106 107 108 109 110 111 112 113 114
void        MainWindow::setupLibrary()
{
    //Library part :
    Library*    library = Library::getInstance();

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

    DockWidgetManager::instance()->addDockedWidget( libraryWidget,
                                  tr( "Media Library" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
115 116
                                  Qt::LeftDockWidgetArea,
                                  m_ui.actionMedia_library );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
117 118

    //Connecting GUI and Frontend :
119
    connect( libraryWidget,
120
             SIGNAL( newMediaLoadingAsked(const QString& ) ),
121
             library,
122
             SLOT( newMediaLoadingAsked( const QString& ) ) );
123 124

    connect( library,
125
             SIGNAL( newClipLoaded( Clip* ) ),
126
             libraryWidget,
127
             SLOT( newClipLoaded( Clip* ) ) );
128 129

    connect( libraryWidget,
130
             SIGNAL( removingMediaAsked( const QUuid& ) ),
131
             library,
132
             SLOT( removingMediaAsked( const QUuid& ) ) );
133 134

    connect( library,
135
             SIGNAL( mediaRemoved( const QUuid& ) ),
136
             libraryWidget,
137
             SLOT( mediaRemoved( const QUuid& ) ) );
138

139 140
    connect( libraryWidget->getVideoListWidget(), SIGNAL( selectedClipChanged( Clip* ) ),
              m_clipPreview->getGenericRenderer(), SLOT( setClip( Clip* ) ) );
141 142
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
143 144
    connect( libraryWidget->getVideoListWidget(), SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
             this, SLOT( mediaListItemDoubleClicked( QListWidgetItem* ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
145 146
}

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
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();
    }
}

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
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();
    }
}

177 178
void MainWindow::createStatusBar()
{
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 205 206 207 208 209 210 211 212 213
    // 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
214 215 216 217 218 219 220 221 222 223
    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 );
224 225 226 227 228 229 230

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

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

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

242 243 244 245
    dockManager->addDockedWidget( new FileBrowser( this ),
                                  tr( "FileBrowser" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
246 247
                                  Qt::TopDockWidgetArea,
                                  m_ui.actionFile_browser );
248

249 250
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
251
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
252 253
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
254 255
                                  Qt::TopDockWidgetArea,
                                  m_ui.actionClip_preview );
256

257
    m_projectPreview = new PreviewWidget( new WorkflowRenderer(), this );
258
    dockManager->addDockedWidget( m_projectPreview,
259 260 261
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
262 263
                                  Qt::TopDockWidgetArea,
                                  m_ui.actionProject_preview );
264

265
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
266 267 268
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
269 270
                                  Qt::LeftDockWidgetArea,
                                  m_ui.actionUndoRedo );
271
    setupLibrary();
272
    m_metaDataManager = MetaDataManager::getInstance();
273 274
}

275 276
void        MainWindow::createGlobalPreferences()
{
277
    m_globalPreferences = new Settings(  );
278 279 280 281
    m_globalPreferences->addWidget("VLMC",
                                   new VLMCPreferences,
                                   "../images/vlmc.png",
                                   "VLMC settings");
282 283 284 285 286
    ////For debugging purpose
    //m_globalPreferences->addWidget("Test",
    //                               new QLabel("This is a test"),
    //                               "images/vlmc.png",
    //                               "Test");
287 288 289
    m_globalPreferences->build();
}

290 291
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
292 293 294 295
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
296 297 298

void MainWindow::on_actionPreferences_triggered()
{
299
   m_globalPreferences->show();
300
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
301 302 303 304 305

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

307
void MainWindow::on_actionTranscode_triggered()
308
{
309 310
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
311
    //Transcode::instance( this )->exec();
312
}
313

314 315 316 317 318 319 320 321 322
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",
323
                                          QDir::currentPath(), "Videos(*.avi *.mpg)" );
324 325 326 327 328 329
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        if ( m_renderer )
            delete m_renderer;
330
        m_renderer = new WorkflowFileRenderer( outputFileName );
331 332 333 334
        m_renderer->run();
    }
}

335 336 337 338
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    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();
    m_projectPreferences->show();
354 355
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
356 357 358 359 360 361 362 363 364
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
365 366 367 368 369 370 371 372

void MainWindow::on_actionFullscreen_triggered( bool checked )
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
373 374 375 376 377

void MainWindow::registerWidgetInViewMenu( QDockWidget* widget )
{
    m_ui.menuView->addAction( widget->toggleViewAction() );
}
378 379 380 381

void    MainWindow::mediaListItemDoubleClicked( QListWidgetItem* qItem )
{
    ListViewMediaItem* item = static_cast<ListViewMediaItem*>( qItem );
382
    ClipProperty* mp = new ClipProperty( item->getClip(), this );
383 384
    mp->show();
}
385 386 387 388 389

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