]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
some more ui work, fit zoom to project
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27
28 #include <KApplication>
29 #include <KAction>
30 #include <KLocale>
31 #include <KActionCollection>
32 #include <KStandardAction>
33 #include <KFileDialog>
34 #include <KMessageBox>
35 #include <KDebug>
36 #include <KIO/NetAccess>
37 #include <KSaveFile>
38 #include <KRuler>
39 #include <KConfigDialog>
40 #include <KXMLGUIFactory>
41 #include <KStatusBar>
42 #include <kstandarddirs.h>
43 #include <KUrlRequesterDialog>
44 #include <KTemporaryFile>
45 #include <ktogglefullscreenaction.h>
46
47 #include <mlt++/Mlt.h>
48
49 #include "mainwindow.h"
50 #include "kdenlivesettings.h"
51 #include "kdenlivesettingsdialog.h"
52 #include "initeffects.h"
53 #include "profilesdialog.h"
54 #include "projectsettings.h"
55 #include "events.h"
56 #include "renderjob.h"
57
58 #define ID_STATUS_MSG 1
59 #define ID_EDITMODE_MSG 2
60 #define ID_TIMELINE_MSG 3
61 #define ID_TIMELINE_BUTTONS 5
62 #define ID_TIMELINE_POS 6
63 #define ID_TIMELINE_FORMAT 7
64
65 MainWindow::MainWindow(QWidget *parent)
66         : KXmlGuiWindow(parent),
67         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL) {
68     parseProfiles();
69
70     m_commandStack = new QUndoGroup;
71     m_timelineArea = new KTabWidget(this);
72     m_timelineArea->setTabReorderingEnabled(true);
73     m_timelineArea->setTabBarHidden(true);
74
75     QToolButton *closeTabButton = new QToolButton;
76     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
77     closeTabButton->setIcon(KIcon("tab-close"));
78     closeTabButton->adjustSize();
79     closeTabButton->setToolTip(i18n("Close the current tab"));
80     m_timelineArea->setCornerWidget(closeTabButton);
81     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
82
83
84     initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects);
85     m_monitorManager = new MonitorManager();
86
87     projectListDock = new QDockWidget(i18n("Project Tree"), this);
88     projectListDock->setObjectName("project_tree");
89     m_projectList = new ProjectList(this);
90     projectListDock->setWidget(m_projectList);
91     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
92
93     effectListDock = new QDockWidget(i18n("Effect List"), this);
94     effectListDock->setObjectName("effect_list");
95     m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
96
97     //m_effectList = new KListWidget(this);
98     effectListDock->setWidget(m_effectList);
99     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
100
101     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
102     effectStackDock->setObjectName("effect_stack");
103     effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this);
104     effectStackDock->setWidget(effectStack);
105     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
106
107     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
108     transitionConfigDock->setObjectName("transition");
109     transitionConfig = new KListWidget(this);
110     transitionConfigDock->setWidget(transitionConfig);
111     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
112
113
114     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
115     clipMonitorDock->setObjectName("clip_monitor");
116     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
117     clipMonitorDock->setWidget(m_clipMonitor);
118     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
119     //m_clipMonitor->stop();
120
121     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
122     projectMonitorDock->setObjectName("project_monitor");
123     m_projectMonitor = new Monitor("project", m_monitorManager, this);
124     projectMonitorDock->setWidget(m_projectMonitor);
125     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
126
127     undoViewDock = new QDockWidget(i18n("Undo History"), this);
128     undoViewDock->setObjectName("undo_history");
129     m_undoView = new QUndoView(this);
130     m_undoView->setCleanIcon(KIcon("edit-clear"));
131     m_undoView->setEmptyLabel(i18n("Clean"));
132     undoViewDock->setWidget(m_undoView);
133     m_undoView->setGroup(m_commandStack);
134     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
135
136     overviewDock = new QDockWidget(i18n("Project Overview"), this);
137     overviewDock->setObjectName("project_overview");
138     m_overView = new CustomTrackView(NULL, NULL, this);
139     overviewDock->setWidget(m_overView);
140     addDockWidget(Qt::TopDockWidgetArea, overviewDock);
141
142     setupActions();
143     tabifyDockWidget(projectListDock, effectListDock);
144     tabifyDockWidget(projectListDock, effectStackDock);
145     tabifyDockWidget(projectListDock, transitionConfigDock);
146     tabifyDockWidget(projectListDock, undoViewDock);
147     projectListDock->raise();
148
149     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
150     setCentralWidget(m_timelineArea);
151
152     m_timecodeFormat = new KComboBox(this);
153     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
154     m_timecodeFormat->addItem(i18n("Frames"));
155
156     statusProgressBar = new QProgressBar(this);
157     statusProgressBar->setMinimum(0);
158     statusProgressBar->setMaximum(100);
159     statusProgressBar->setMaximumWidth(150);
160     statusProgressBar->setVisible(false);
161     statusLabel = new QLabel(this);
162
163     QWidget *w = new QWidget;
164     timeline_buttons_ui.setupUi(w);
165     timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
166     timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
167     connect(timeline_buttons_ui.buttonVideo, SIGNAL(clicked()), this, SLOT(slotSwitchVideoThumbs()));
168     connect(timeline_buttons_ui.buttonAudio, SIGNAL(clicked()), this, SLOT(slotSwitchAudioThumbs()));
169     connect(timeline_buttons_ui.buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotFitZoom()));
170
171     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
172     statusBar()->insertPermanentWidget(1, statusLabel, 1);
173     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
174     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
175     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
176     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
177
178     timeline_buttons_ui.buttonVideo->setIcon(KIcon("video-mpeg"));
179     timeline_buttons_ui.buttonVideo->setToolTip(i18n("Show video thumbnails"));
180     timeline_buttons_ui.buttonAudio->setIcon(KIcon("audio-mpeg"));
181     timeline_buttons_ui.buttonAudio->setToolTip(i18n("Show audio thumbnails"));
182     timeline_buttons_ui.buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
183     timeline_buttons_ui.buttonFitZoom->setToolTip(i18n("Fit zoom to project"));
184
185     setupGUI(Default, "kdenliveui.rc");
186
187     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
188     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
189     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
190     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
191     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
192     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
193     slotConnectMonitors();
194
195     setAutoSaveSettings();
196     newFile();
197 }
198
199 //virtual
200 bool MainWindow::queryClose() {
201     saveOptions();
202     switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
203     case KMessageBox::Yes :
204         // save document here. If saving fails, return false;
205         return true;
206     case KMessageBox::No :
207         return true;
208     default: // cancel
209         return false;
210     }
211 }
212
213 void MainWindow::slotFullScreen() {
214     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
215 }
216
217 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
218     if (!m_activeDocument) return;
219     if (effect.isNull()) {
220         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
221         return;
222     }
223     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
224     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
225 }
226
227 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
228     if (clipMonitor) clipMonitorDock->raise();
229     else projectMonitorDock->raise();
230 }
231
232 void MainWindow::slotSetClipDuration(int id, int duration) {
233     if (!m_activeDocument) return;
234     m_activeDocument->setProducerDuration(id, duration);
235 }
236
237 void MainWindow::slotConnectMonitors() {
238
239     m_projectList->setRenderer(m_clipMonitor->render);
240     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
241     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
242     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
243     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
244     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
245 }
246
247 void MainWindow::setupActions() {
248     KAction* clearAction = new KAction(this);
249     clearAction->setText(i18n("Clear"));
250     clearAction->setIcon(KIcon("document-new"));
251     clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
252     actionCollection()->addAction("clear", clearAction);
253     /*connect(clearAction, SIGNAL(triggered(bool)),
254             textArea, SLOT(clear()));*/
255
256     KAction* profilesAction = new KAction(this);
257     profilesAction->setText(i18n("Manage Profiles"));
258     profilesAction->setIcon(KIcon("document-new"));
259     actionCollection()->addAction("manage_profiles", profilesAction);
260     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
261
262     KAction* projectAction = new KAction(this);
263     projectAction->setText(i18n("Project Settings"));
264     projectAction->setIcon(KIcon("document-new"));
265     actionCollection()->addAction("project_settings", projectAction);
266     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
267
268     KAction* projectRender = new KAction(this);
269     projectRender->setText(i18n("Render Project"));
270     projectRender->setIcon(KIcon("document-new"));
271     actionCollection()->addAction("project_render", projectRender);
272     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
273
274     KAction* monitorPlay = new KAction(this);
275     monitorPlay->setText(i18n("Play"));
276     monitorPlay->setIcon(KIcon("media-playback-start"));
277     monitorPlay->setShortcut(Qt::Key_Space);
278     actionCollection()->addAction("monitor_play", monitorPlay);
279     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
280
281     KStandardAction::quit(kapp, SLOT(quit()),
282                           actionCollection());
283
284     KStandardAction::open(this, SLOT(openFile()),
285                           actionCollection());
286
287     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
288                        actionCollection());
289
290     KStandardAction::save(this, SLOT(saveFile()),
291                           actionCollection());
292
293     KStandardAction::saveAs(this, SLOT(saveFileAs()),
294                             actionCollection());
295
296     KStandardAction::openNew(this, SLOT(newFile()),
297                              actionCollection());
298
299     KStandardAction::preferences(this, SLOT(slotPreferences()),
300                                  actionCollection());
301
302     KStandardAction::undo(this, SLOT(undo()),
303                           actionCollection());
304
305     KStandardAction::redo(this, SLOT(redo()),
306                           actionCollection());
307
308     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
309
310     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
311             this, SLOT(slotDisplayActionMessage(QAction*)));
312     //connect(actionCollection(), SIGNAL( clearStatusText() ),
313     //statusBar(), SLOT( clear() ) );
314
315     readOptions();
316 }
317
318 void MainWindow::undo() {
319     m_commandStack->undo();
320 }
321
322 void MainWindow::redo() {
323     m_commandStack->redo();
324 }
325
326 void MainWindow::slotDisplayActionMessage(QAction *a) {
327     statusBar()->showMessage(a->data().toString(), 3000);
328 }
329
330 void MainWindow::saveOptions() {
331     KSharedConfigPtr config = KGlobal::config();
332     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
333     config->sync();
334 }
335
336 void MainWindow::readOptions() {
337     KSharedConfigPtr config = KGlobal::config();
338     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
339 }
340
341 void MainWindow::newFile() {
342     QString profileName;
343     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
344     else {
345         ProjectSettings *w = new ProjectSettings;
346         w->exec();
347         profileName = w->selectedProfile();
348         delete w;
349     }
350     MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
351     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
352     KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
353     TrackView *trackView = new TrackView(doc);
354     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
355     if (m_timelineArea->count() == 1)
356         connectDocument(trackView, doc);
357     else m_timelineArea->setTabBarHidden(false);
358 }
359
360 void MainWindow::activateDocument() {
361     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
362     KdenliveDoc *currentDoc = currentTab->document();
363     connectDocument(currentTab, currentDoc);
364 }
365
366 void MainWindow::slotRemoveTab() {
367     QWidget *w = m_timelineArea->currentWidget();
368     // closing current document
369     int ix = m_timelineArea->currentIndex() + 1;
370     if (ix == m_timelineArea->count()) ix = 0;
371     m_timelineArea->setCurrentIndex(ix);
372     TrackView *tabToClose = (TrackView *) w;
373     KdenliveDoc *docToClose = tabToClose->document();
374     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
375     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
376     delete docToClose;
377     delete w;
378 }
379
380 void MainWindow::saveFileAs(const QString &outputFileName) {
381     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
382     m_activeDocument->setUrl(KUrl(outputFileName));
383     setCaption(m_activeDocument->description());
384     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
385     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
386     m_activeDocument->setModified(false);
387 }
388
389 void MainWindow::saveFileAs() {
390     QString outputFile = KFileDialog::getSaveFileName();
391     if (QFile::exists(outputFile)) {
392         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
393     }
394     saveFileAs(outputFile);
395 }
396
397 void MainWindow::saveFile() {
398     if (!m_activeDocument) return;
399     if (m_activeDocument->url().isEmpty()) {
400         saveFileAs();
401     } else {
402         saveFileAs(m_activeDocument->url().path());
403     }
404 }
405
406 void MainWindow::openFile() { //changed
407     KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
408     if (url.isEmpty()) return;
409     m_fileOpenRecent->addUrl(url);
410     openFile(url);
411 }
412
413 void MainWindow::openFile(const KUrl &url) { //new
414     //TODO: get video profile from url before opening it
415     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
416     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
417     KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
418     TrackView *trackView = new TrackView(doc);
419     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
420     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
421     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
422     //connectDocument(trackView, doc);
423 }
424
425
426 void MainWindow::parseProfiles() {
427     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
428     if (KdenliveSettings::mltpath().isEmpty()) {
429         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
430     }
431     if (KdenliveSettings::rendererpath().isEmpty()) {
432         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
433     }
434     QStringList profilesFilter;
435     profilesFilter << "*";
436     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
437
438     if (profilesList.isEmpty()) {
439         // Cannot find MLT path, try finding inigo
440         QString profilePath = KdenliveSettings::rendererpath();
441         if (!profilePath.isEmpty()) {
442             profilePath = profilePath.section('/', 0, -3);
443             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
444             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
445         }
446
447         if (profilesList.isEmpty()) {
448             // Cannot find the MLT profiles, ask for location
449             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
450             getUrl->fileDialog()->setMode(KFile::Directory);
451             getUrl->exec();
452             KUrl mltPath = getUrl->selectedUrl();
453             delete getUrl;
454             if (mltPath.isEmpty()) exit(1);
455             KdenliveSettings::setMltpath(mltPath.path());
456             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
457         }
458     }
459
460     if (KdenliveSettings::rendererpath().isEmpty()) {
461         // Cannot find the MLT inigo renderer, ask for location
462         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
463         getUrl->exec();
464         KUrl rendererPath = getUrl->selectedUrl();
465         delete getUrl;
466         if (rendererPath.isEmpty()) exit(1);
467         KdenliveSettings::setRendererpath(rendererPath.path());
468     }
469
470     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
471
472     // Parse MLT profiles to build a list of available video formats
473     if (profilesList.isEmpty()) parseProfiles();
474 }
475
476
477 void MainWindow::slotEditProfiles() {
478     ProfilesDialog *w = new ProfilesDialog;
479     w->exec();
480     delete w;
481 }
482
483 void MainWindow::slotEditProjectSettings() {
484     ProjectSettings *w = new ProjectSettings;
485     if (w->exec() == QDialog::Accepted) {
486         QString profile = w->selectedProfile();
487         m_activeDocument->setProfilePath(profile);
488         m_monitorManager->resetProfiles(profile);
489         setCaption(m_activeDocument->description());
490         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
491         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
492         m_monitorManager->setTimecode(m_activeDocument->timecode());
493         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
494
495         // We need to desactivate & reactivate monitors to get a refresh
496         m_monitorManager->switchMonitors();
497     }
498     delete w;
499 }
500
501 void MainWindow::slotRenderProject() {
502     if (!m_renderWidget) {
503         m_renderWidget = new RenderWidget(this);
504         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
505     }
506     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
507     if (currentTab) m_renderWidget->setTimeline(currentTab);
508     m_renderWidget->setDocument(m_activeDocument);*/
509     m_renderWidget->show();
510 }
511
512 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
513     if (dest.isEmpty()) return;
514     int in;
515     int out;
516     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
517     if (currentTab && zoneOnly) {
518         in = currentTab->inPoint();
519         out = currentTab->outPoint();
520     }
521     KTemporaryFile temp;
522     temp.setAutoRemove(false);
523     temp.setSuffix(".westley");
524     if (temp.open()) {
525         m_projectMonitor->saveSceneList(temp.fileName());
526         QStringList args;
527         args << "-erase";
528         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
529         QString videoPlayer = "-";
530         if (playAfter) videoPlayer = "kmplayer";
531         args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
532         QProcess::startDetached("kdenlive_render", args);
533     }
534 }
535
536 void MainWindow::slotUpdateMousePosition(int pos) {
537     if (m_activeDocument)
538         switch (m_timecodeFormat->currentIndex()) {
539         case 0:
540             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
541             break;
542         default:
543             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
544         }
545 }
546
547 void MainWindow::slotUpdateDocumentState(bool modified) {
548     setCaption(m_activeDocument->description(), modified);
549     if (modified) {
550         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
551         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
552     } else {
553         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
554         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
555     }
556 }
557
558 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
559     //m_projectMonitor->stop();
560     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
561     if (m_activeDocument) {
562         if (m_activeDocument == doc) return;
563         m_activeDocument->backupMltPlaylist();
564         if (m_activeTimeline) {
565             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
566             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
567             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
568             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
569             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
570             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
571             disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
572             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
573             disconnect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
574             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
575             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
576             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
577             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
578             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
579             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
580         }
581         m_activeDocument->setRenderer(NULL);
582         disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
583         m_clipMonitor->stop();
584     }
585     m_monitorManager->resetProfiles(doc->profilePath());
586     m_projectList->setDocument(doc);
587     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
588     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
589     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
590     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
591     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
592     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
593     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
594     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
595     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
596     connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
597     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
598
599     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
600     timeline_buttons_ui.zoom_slider->setValue(trackView->currentZoom());
601     connect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
602     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
603     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
604     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
605     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
606     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
607     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
608     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
609
610
611     m_activeTimeline = trackView;
612     KdenliveSettings::setCurrent_profile(doc->profilePath());
613     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
614     m_monitorManager->setTimecode(doc->timecode());
615     doc->setRenderer(m_projectMonitor->render);
616     m_commandStack->setActiveStack(doc->commandStack());
617
618     m_overView->setScene(trackView->projectScene());
619     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
620     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
621
622     setCaption(doc->description());
623     m_activeDocument = doc;
624 }
625
626 void MainWindow::slotPreferences() {
627     //An instance of your dialog could be already created and could be
628     // cached, in which case you want to display the cached dialog
629     // instead of creating another one
630     if (KConfigDialog::showDialog("settings"))
631         return;
632
633     // KConfigDialog didn't find an instance of this dialog, so lets
634     // create it :
635     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
636     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
637     dialog->show();
638 }
639
640 void MainWindow::updateConfiguration() {
641     //TODO: we should apply settings to all projects, not only the current one
642     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
643     if (currentTab) {
644         currentTab->refresh();
645         currentTab->projectView()->checkAutoScroll();
646         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
647     }
648     timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
649     timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
650 }
651
652 void MainWindow::slotSwitchVideoThumbs() {
653     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
654     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
655     if (currentTab) {
656         currentTab->refresh();
657     }
658     timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
659 }
660
661 void MainWindow::slotSwitchAudioThumbs() {
662     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
663     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
664     if (currentTab) {
665         currentTab->refresh();
666         currentTab->projectView()->checkAutoScroll();
667         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
668     }
669     timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
670 }
671
672 void MainWindow::slotZoomIn() {
673     timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() - 1);
674 }
675
676 void MainWindow::slotZoomOut() {
677     timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() + 1);
678 }
679
680 void MainWindow::slotFitZoom() {
681     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
682     if (currentTab) {
683         timeline_buttons_ui.zoom_slider->setValue(currentTab->fitZoom());
684     }
685 }
686
687 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
688     statusProgressBar->setValue(progress);
689     if (progress > 0) {
690         statusLabel->setText(tr("Creating Audio Thumbs"));
691         statusProgressBar->setVisible(true);
692     } else {
693         statusLabel->setText("");
694         statusProgressBar->setVisible(false);
695     }
696 }
697
698 #include "mainwindow.moc"