MainWindow.cpp 8.12 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"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
42
43

MainWindow::MainWindow( QWidget *parent ) :
44
    QMainWindow( parent ), m_renderer( NULL )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
45
46
{
    m_ui.setupUi( this );
47
    DockWidgetManager::instance( this )->setMainWindow( this );
48
    initializeDockWidgets();
49
    createStatusBar();
50

Ludovic Fauvet's avatar
Ludovic Fauvet committed
51
    // Translation
52
53
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
54
55

    // Zoom
56
57
    connect( m_zoomSlider, SIGNAL( valueChanged( int ) ),
             m_timeline, SLOT( changeZoom( int ) ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
58
59
60
61
    connect( m_timeline->tracksView(), SIGNAL( zoomIn() ),
             this, SLOT( zoomIn() ) );
    connect( m_timeline->tracksView(), SIGNAL( zoomOut() ),
             this, SLOT( zoomOut() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
62
63
}

64
65
MainWindow::~MainWindow()
{
66
67
    if ( m_renderer )
        delete m_renderer;
68
    MetaDataManager::destroyInstance();
69
70
    LibVLCpp::Instance::kill();
    UndoStack::destroyInstance();
71
72
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
73
74
75
76
77
78
void MainWindow::changeEvent( QEvent *e )
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui.retranslateUi( this );
79
        emit translateDockWidgetTitle();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
80
81
82
83
84
85
        break;
    default:
        break;
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
86
87
88
89
90
91
92
93
94
95
96
97
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
98
                                  Qt::LeftDockWidgetArea );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
99
100

    //Connecting GUI and Frontend :
101
    connect( libraryWidget,
102
             SIGNAL( newMediaLoadingAsked(const QString& ) ),
103
             library,
104
             SLOT( newMediaLoadingAsked( const QString& ) ) );
105
106

    connect( library,
107
             SIGNAL( newMediaLoaded( Media* ) ),
108
             libraryWidget,
109
             SLOT( newMediaLoaded( Media* ) ) );
110
111

    connect( libraryWidget,
112
             SIGNAL( removingMediaAsked( const QUuid& ) ),
113
             library,
114
             SLOT( removingMediaAsked( const QUuid& ) ) );
115
116

    connect( library,
117
             SIGNAL( mediaRemoved( const QUuid& ) ),
118
             libraryWidget,
119
             SLOT( mediaRemoved( const QUuid& ) ) );
120

121
    connect( libraryWidget->getVideoListWidget(), SIGNAL( selectedMediaChanged(const Media*) ),
122
              m_clipPreview->getGenericRenderer(), SLOT( setMedia(const Media*) ) );
123
124
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
125
126
}

127
128
129
130
131
132
133
134
135
136
137
138
139
140
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 );
}

141
void MainWindow::initializeDockWidgets( void )
142
{
143
144
145
146
    m_timeline = new Timeline( this );
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
147

148
    DockWidgetManager *dockManager = DockWidgetManager::instance();
149
150
151
152
153
    dockManager->addDockedWidget( new FileBrowser( this ),
                                  tr( "FileBrowser" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea);
154

155
156
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
157
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
158
159
160
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
161

162
163
    m_projectPreview = new PreviewWidget( new WorkflowRenderer( m_timeline->getMainWorkflow() ), this );
    dockManager->addDockedWidget( m_projectPreview,
164
165
166
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
167
                                  Qt::TopDockWidgetArea );
168

169
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
170
171
172
173
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
174
    setupLibrary();
175
    m_metaDataManager = MetaDataManager::getInstance();
176
177
178
179
}

//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
180
181
182
183
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
184
185
186

void MainWindow::on_actionPreferences_triggered()
{
Christophe Courtaut's avatar
Christophe Courtaut committed
187
    Preferences::instance()->exec();
188
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
189
190
191
192
193

void MainWindow::on_actionAbout_triggered()
{
    About::instance()->exec();
}
194
195
196
197
198

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

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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;
        m_renderer = new WorkflowFileRenderer( this, outputFileName );
        m_renderer->run();
    }
}

221
222
223
224
225
226
227
228
229
230
231
232
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
}

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
233
234
235
236
237
238
239
240
241
242

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
243
244
245
246
247
248
249
250

void MainWindow::on_actionFullscreen_triggered( bool checked )
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
251
252
253
254
255

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