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

Ludovic Fauvet's avatar
Ludovic Fauvet committed
31
#include "MainWindow.h"
32
#include "MediaListWidget.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
33 34
#include "LibraryWidget.h"
#include "Library.h"
35
#include "Timeline.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
36
#include "About.h"
37
#include "Transcode.h"
38
#include "FileBrowser.h"
39
#include "WorkflowRenderer.h"
40
#include "ClipRenderer.h"
41
#include "UndoStack.h"
42
#include "ClipProperty.h"
43
#include "PreviewWidget.h"
44 45
#include "PreferenceWidget.h"
#include "ProjectPreferences.h"
46 47 48
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
#include "VLMCPreferences.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
49 50

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

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

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

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

78 79
MainWindow::~MainWindow()
{
80 81
    if ( m_renderer )
        delete m_renderer;
82
    MetaDataManager::destroyInstance();
83
    LibVLCpp::Instance::kill();
84 85
}

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

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
99 100 101 102 103 104 105 106 107 108 109 110
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,
Christophe Courtaut's avatar
Christophe Courtaut committed
111
                                  Qt::LeftDockWidgetArea );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
112 113

    //Connecting GUI and Frontend :
114
    connect( libraryWidget,
115
             SIGNAL( newMediaLoadingAsked(const QString& ) ),
116
             library,
117
             SLOT( newMediaLoadingAsked( const QString& ) ) );
118 119

    connect( library,
120
             SIGNAL( newClipLoaded( Clip* ) ),
121
             libraryWidget,
122
             SLOT( newClipLoaded( Clip* ) ) );
123 124

    connect( libraryWidget,
125
             SIGNAL( removingMediaAsked( const QUuid& ) ),
126
             library,
127
             SLOT( removingMediaAsked( const QUuid& ) ) );
128 129

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

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

142 143 144 145 146 147 148 149 150 151 152 153 154 155
void MainWindow::createStatusBar()
{
    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 );
}

156
void MainWindow::initializeDockWidgets( void )
157
{
158 159 160 161
    m_timeline = new Timeline( this );
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
162

163
    DockWidgetManager *dockManager = DockWidgetManager::instance();
164 165 166 167 168
    dockManager->addDockedWidget( new FileBrowser( this ),
                                  tr( "FileBrowser" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea);
169

170 171
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
172
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
173 174 175
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
176

177
    m_projectPreview = new PreviewWidget( new WorkflowRenderer(), this );
178
    dockManager->addDockedWidget( m_projectPreview,
179 180 181
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
182
                                  Qt::TopDockWidgetArea );
183

184
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
185 186 187 188
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
189
    setupLibrary();
190
    m_metaDataManager = MetaDataManager::getInstance();
191 192
}

193 194
void        MainWindow::createGlobalPreferences()
{
195
    m_globalPreferences = new Settings(  );
196 197 198 199
    m_globalPreferences->addWidget("VLMC",
                                   new VLMCPreferences,
                                   "../images/vlmc.png",
                                   "VLMC settings");
200 201 202 203 204
    ////For debugging purpose
    //m_globalPreferences->addWidget("Test",
    //                               new QLabel("This is a test"),
    //                               "images/vlmc.png",
    //                               "Test");
205 206 207
    m_globalPreferences->build();
}

208 209
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
210 211 212 213
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
214 215 216

void MainWindow::on_actionPreferences_triggered()
{
217
   m_globalPreferences->show();
218
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
219 220 221 222 223

void MainWindow::on_actionAbout_triggered()
{
    About::instance()->exec();
}
224 225 226 227 228

void MainWindow::on_actionTranscode_File_triggered()
{
    Transcode::instance( this )->exec();
}
229

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
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",
                                          QString(), "Videos(*.avi *.mpg)" );
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        if ( m_renderer )
            delete m_renderer;
246
        m_renderer = new WorkflowFileRenderer( outputFileName );
247 248 249 250
        m_renderer->run();
    }
}

251 252 253 254
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    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();
270 271 272 273 274 275 276 277
}

void MainWindow::on_actionOpen_Project_triggered()
{
    QString path = QFileDialog::getOpenFileName( this, tr( "Choose a project to open" ),
                                                 QDir::currentPath(),
                                                 tr( "VideoLAN Movie Creator file (*.vlmc)" ) );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
278 279 280 281 282 283 284 285 286 287

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
288 289 290 291 292 293 294 295

void MainWindow::on_actionFullscreen_triggered( bool checked )
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
296 297 298 299 300

void MainWindow::registerWidgetInViewMenu( QDockWidget* widget )
{
    m_ui.menuView->addAction( widget->toggleViewAction() );
}
301 302 303 304

void    MainWindow::mediaListItemDoubleClicked( QListWidgetItem* qItem )
{
    ListViewMediaItem* item = static_cast<ListViewMediaItem*>( qItem );
305
    ClipProperty* mp = new ClipProperty( item->getClip(), this );
306 307
    mp->show();
}