]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
* Clip Markers are now displayed over the clip monitor
[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 #include <stdlib.h>
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27 #include <QKeyEvent>
28
29 #include <KApplication>
30 #include <KAction>
31 #include <KLocale>
32 #include <KGlobal>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
37 #include <KDebug>
38 #include <KIO/NetAccess>
39 #include <KSaveFile>
40 #include <KRuler>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
43 #include <KStatusBar>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
48 #include <KMenu>
49 #include <locale.h>
50 #include <ktogglefullscreenaction.h>
51 #include <KFileItem>
52 #include <KNotification>
53 #include <KNotifyConfigWidget>
54
55 #include <mlt++/Mlt.h>
56
57 #include "mainwindow.h"
58 #include "kdenlivesettings.h"
59 #include "kdenlivesettingsdialog.h"
60 #include "initeffects.h"
61 #include "profilesdialog.h"
62 #include "projectsettings.h"
63 #include "events.h"
64 #include "clipmanager.h"
65 #include "projectlist.h"
66 #include "monitor.h"
67 #include "recmonitor.h"
68 #include "monitormanager.h"
69 #include "kdenlivedoc.h"
70 #include "trackview.h"
71 #include "customtrackview.h"
72 #include "effectslistview.h"
73 #include "effectstackview.h"
74 #include "transitionsettings.h"
75 #include "renderwidget.h"
76 #include "renderer.h"
77 #ifndef NO_JOGSHUTTLE
78 #include "jogshuttle.h"
79 #endif /* NO_JOGSHUTTLE */
80 #include "clipproperties.h"
81 #include "wizard.h"
82 #include "editclipcommand.h"
83 #include "titlewidget.h"
84
85 static const int ID_STATUS_MSG = 1;
86 static const int ID_EDITMODE_MSG = 2;
87 static const int ID_TIMELINE_MSG = 3;
88 static const int ID_TIMELINE_BUTTONS = 5;
89 static const int ID_TIMELINE_POS = 6;
90 static const int ID_TIMELINE_FORMAT = 7;
91
92 namespace Mlt {
93 class Producer;
94 };
95
96 EffectsList MainWindow::videoEffects;
97 EffectsList MainWindow::audioEffects;
98 EffectsList MainWindow::customEffects;
99 EffectsList MainWindow::transitions;
100
101 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
102         : KXmlGuiWindow(parent),
103         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
104 #ifndef NO_JOGSHUTTLE
105         m_jogProcess(NULL),
106 #endif /* NO_JOGSHUTTLE */
107         m_findActivated(false), m_initialized(false) {
108     setlocale(LC_NUMERIC, "POSIX");
109     setFont(KGlobalSettings::toolBarFont());
110     parseProfiles(MltPath);
111     m_commandStack = new QUndoGroup;
112     m_timelineArea = new KTabWidget(this);
113     m_timelineArea->setTabReorderingEnabled(true);
114     m_timelineArea->setTabBarHidden(true);
115
116     QToolButton *closeTabButton = new QToolButton;
117     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
118     closeTabButton->setIcon(KIcon("tab-close"));
119     closeTabButton->adjustSize();
120     closeTabButton->setToolTip(i18n("Close the current tab"));
121     m_timelineArea->setCornerWidget(closeTabButton);
122     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
123
124     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
125     m_findTimer.setSingleShot(true);
126
127     initEffects::parseEffectFiles();
128     //initEffects::parseCustomEffectsFile();
129
130     m_monitorManager = new MonitorManager();
131
132     projectListDock = new QDockWidget(i18n("Project Tree"), this);
133     projectListDock->setObjectName("project_tree");
134     m_projectList = new ProjectList(this);
135     projectListDock->setWidget(m_projectList);
136     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
137
138     effectListDock = new QDockWidget(i18n("Effect List"), this);
139     effectListDock->setObjectName("effect_list");
140     m_effectList = new EffectsListView();
141
142     //m_effectList = new KListWidget(this);
143     effectListDock->setWidget(m_effectList);
144     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
145
146     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
147     effectStackDock->setObjectName("effect_stack");
148     effectStack = new EffectStackView(this);
149     effectStackDock->setWidget(effectStack);
150     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
151
152     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
153     transitionConfigDock->setObjectName("transition");
154     transitionConfig = new TransitionSettings(this);
155     transitionConfigDock->setWidget(transitionConfig);
156     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
157
158     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
159     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
160                        actionCollection());
161     readOptions();
162
163     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
164     clipMonitorDock->setObjectName("clip_monitor");
165     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
166     clipMonitorDock->setWidget(m_clipMonitor);
167     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
168     //m_clipMonitor->stop();
169
170     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
171     projectMonitorDock->setObjectName("project_monitor");
172     m_projectMonitor = new Monitor("project", m_monitorManager, this);
173     projectMonitorDock->setWidget(m_projectMonitor);
174     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
175
176     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
177     recMonitorDock->setObjectName("record_monitor");
178     m_recMonitor = new RecMonitor("record", this);
179     recMonitorDock->setWidget(m_recMonitor);
180     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
181
182     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
183     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
184
185     undoViewDock = new QDockWidget(i18n("Undo History"), this);
186     undoViewDock->setObjectName("undo_history");
187     m_undoView = new QUndoView(this);
188     m_undoView->setCleanIcon(KIcon("edit-clear"));
189     m_undoView->setEmptyLabel(i18n("Clean"));
190     undoViewDock->setWidget(m_undoView);
191     m_undoView->setGroup(m_commandStack);
192     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
193
194     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
195     //overviewDock->setObjectName("project_overview");
196     //m_overView = new CustomTrackView(NULL, NULL, this);
197     //overviewDock->setWidget(m_overView);
198     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
199
200     setupActions();
201     //tabifyDockWidget(projectListDock, effectListDock);
202     tabifyDockWidget(projectListDock, effectStackDock);
203     tabifyDockWidget(projectListDock, transitionConfigDock);
204     //tabifyDockWidget(projectListDock, undoViewDock);
205
206
207     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
208     tabifyDockWidget(clipMonitorDock, recMonitorDock);
209     setCentralWidget(m_timelineArea);
210
211     setupGUI();
212     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
213
214     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
215     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
216
217     // build effects menus
218     QAction *action;
219     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
220
221     QStringList effectInfo;
222     QMap<QString, QStringList> effectsList;
223     for (int ix = 0; ix < videoEffects.count(); ix++) {
224         effectInfo = videoEffects.effectIdInfo(ix);
225         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
226     }
227
228     foreach(QStringList value, effectsList) {
229         action = new QAction(value.at(0), this);
230         action->setData(value);
231         videoEffectsMenu->addAction(action);
232     }
233
234     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
235
236
237     effectsList.clear();
238     for (int ix = 0; ix < audioEffects.count(); ix++) {
239         effectInfo = audioEffects.effectIdInfo(ix);
240         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
241     }
242
243     foreach(QStringList value, effectsList) {
244         action = new QAction(value.at(0), this);
245         action->setData(value);
246         audioEffectsMenu->addAction(action);
247     }
248
249     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
250
251     if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
252     else m_customEffectsMenu->setEnabled(true);
253
254     effectsList.clear();
255     for (int ix = 0; ix < customEffects.count(); ix++) {
256         effectInfo = customEffects.effectIdInfo(ix);
257         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
258     }
259
260     foreach(QStringList value, effectsList) {
261         action = new QAction(value.at(0), this);
262         action->setData(value);
263         m_customEffectsMenu->addAction(action);
264     }
265
266     QMenu *newEffect = new QMenu(this);
267     newEffect->addMenu(videoEffectsMenu);
268     newEffect->addMenu(audioEffectsMenu);
269     newEffect->addMenu(m_customEffectsMenu);
270     effectStack->setMenu(newEffect);
271
272
273     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
274     const QList<QAction *> viewActions = createPopupMenu()->actions();
275     viewMenu->insertActions(NULL, viewActions);
276
277     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
278     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
279     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
280
281     m_timelineContextMenu = new QMenu(this);
282     m_timelineContextClipMenu = new QMenu(this);
283     m_timelineContextTransitionMenu = new QMenu(this);
284
285
286     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
287     QStringList effects = transitions.effectNames();
288
289     effectsList.clear();
290     for (int ix = 0; ix < transitions.count(); ix++) {
291         effectInfo = transitions.effectIdInfo(ix);
292         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
293     }
294     foreach(QStringList value, effectsList) {
295         action = new QAction(value.at(0), this);
296         action->setData(value);
297         transitionsMenu->addAction(action);
298     }
299     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
300
301     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
302     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
303
304     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
305     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
306     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
307     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
308     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
309
310     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
311     m_timelineContextClipMenu->addMenu(markersMenu);
312     m_timelineContextClipMenu->addMenu(transitionsMenu);
313     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
314     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
315     //TODO: re-enable custom effects menu when it is implemented
316     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
317
318     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
319     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
320
321     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
322     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
323     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
324     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
325     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
326     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
327
328     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
329     slotConnectMonitors();
330
331     // Open or create a file.  Command line argument passed in Url has
332     // precedence, then "openlastproject", then just a plain empty file.
333     // If opening Url fails, openlastproject will _not_ be used.
334     if (!Url.isEmpty()) {
335         openFile(Url);
336     } else {
337         if (KdenliveSettings::openlastproject()) {
338             openLastFile();
339         }
340     }
341     if (m_timelineArea->count() == 0) {
342         newFile(false);
343     }
344
345 #ifndef NO_JOGSHUTTLE
346     activateShuttleDevice();
347 #endif /* NO_JOGSHUTTLE */
348     projectListDock->raise();
349 }
350
351 void MainWindow::queryQuit() {
352     kDebug() << "----- SAVING CONFUIG";
353     if (queryClose()) kapp->quit();
354 }
355
356 //virtual
357 bool MainWindow::queryClose() {
358     saveOptions();
359     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
360     if (m_activeDocument && m_activeDocument->isModified()) {
361         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
362         case KMessageBox::Yes :
363             // save document here. If saving fails, return false;
364             return saveFile();
365         case KMessageBox::No :
366             return true;
367         default: // cancel
368             return false;
369         }
370     }
371     return true;
372 }
373
374 void MainWindow::saveProperties(KConfig*) {
375     // save properties here,used by session management
376     saveFile();
377 }
378
379
380 void MainWindow::readProperties(KConfig *config) {
381     // read properties here,used by session management
382     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
383     openFile(KUrl(Lastproject));
384 }
385
386 void MainWindow::slotReloadEffects() {
387     initEffects::parseCustomEffectsFile();
388     m_customEffectsMenu->clear();
389     const QStringList effects = customEffects.effectNames();
390     QAction *action;
391     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
392     else m_customEffectsMenu->setEnabled(true);
393
394     foreach(const QString &name, effects) {
395         action = new QAction(name, this);
396         action->setData(name);
397         m_customEffectsMenu->addAction(action);
398     }
399     m_effectList->reloadEffectList();
400 }
401
402 #ifndef NO_JOGSHUTTLE
403 void MainWindow::activateShuttleDevice() {
404     if (m_jogProcess) delete m_jogProcess;
405     m_jogProcess = NULL;
406     if (KdenliveSettings::enableshuttle() == false) return;
407     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
408     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
409     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
410     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
411     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
412     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
413     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
414 }
415
416 void MainWindow::slotShuttleButton(int code) {
417     switch (code) {
418     case 5:
419         slotShuttleAction(KdenliveSettings::shuttle1());
420         break;
421     case 6:
422         slotShuttleAction(KdenliveSettings::shuttle2());
423         break;
424     case 7:
425         slotShuttleAction(KdenliveSettings::shuttle3());
426         break;
427     case 8:
428         slotShuttleAction(KdenliveSettings::shuttle4());
429         break;
430     case 9:
431         slotShuttleAction(KdenliveSettings::shuttle5());
432         break;
433     }
434 }
435
436 void MainWindow::slotShuttleAction(int code) {
437     switch (code) {
438     case 0:
439         return;
440     case 1:
441         m_monitorManager->slotPlay();
442         break;
443     default:
444         m_monitorManager->slotPlay();
445         break;
446     }
447 }
448 #endif /* NO_JOGSHUTTLE */
449
450 void MainWindow::configureNotifications() {
451     KNotifyConfigWidget::configure(this);
452 }
453
454 void MainWindow::slotFullScreen() {
455     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
456 }
457
458 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
459     if (!m_activeDocument) return;
460     if (effect.isNull()) {
461         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
462         return;
463     }
464     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
465     currentTimeLine->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
466 }
467
468 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
469     if (clipMonitor) clipMonitorDock->raise();
470     else projectMonitorDock->raise();
471 }
472
473 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
474     if (!m_activeDocument) return;
475     m_activeDocument->setProducerDuration(id, duration);
476 }
477
478 void MainWindow::slotConnectMonitors() {
479
480     m_projectList->setRenderer(m_clipMonitor->render);
481     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
482     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
483     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
484     connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
485     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
486
487     connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
488
489     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
490
491     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
492     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
493
494     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
495     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
496 }
497
498 void MainWindow::slotAdjustClipMonitor() {
499     clipMonitorDock->updateGeometry();
500     clipMonitorDock->adjustSize();
501     m_clipMonitor->resetSize();
502 }
503
504 void MainWindow::slotAdjustProjectMonitor() {
505     projectMonitorDock->updateGeometry();
506     projectMonitorDock->adjustSize();
507     m_projectMonitor->resetSize();
508 }
509
510 void MainWindow::setupActions() {
511
512     KActionCollection* collection = actionCollection();
513     m_timecodeFormat = new KComboBox(this);
514     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
515     m_timecodeFormat->addItem(i18n("Frames"));
516
517     statusProgressBar = new QProgressBar(this);
518     statusProgressBar->setMinimum(0);
519     statusProgressBar->setMaximum(100);
520     statusProgressBar->setMaximumWidth(150);
521     statusProgressBar->setVisible(false);
522
523     QWidget *w = new QWidget;
524
525     QHBoxLayout *layout = new QHBoxLayout;
526     w->setLayout(layout);
527     layout->setContentsMargins(5, 0, 5, 0);
528     QToolBar *toolbar = new QToolBar("statusToolBar", this);
529
530
531     m_toolGroup = new QActionGroup(this);
532
533     QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); border-style: inset; border:1px solid #999999;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:checked { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
534
535     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
536     toolbar->addAction(m_buttonSelectTool);
537     m_buttonSelectTool->setCheckable(true);
538     m_buttonSelectTool->setChecked(true);
539
540     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
541     toolbar->addAction(m_buttonRazorTool);
542     m_buttonRazorTool->setCheckable(true);
543     m_buttonRazorTool->setChecked(false);
544
545     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
546     toolbar->addAction(m_buttonSpacerTool);
547     m_buttonSpacerTool->setCheckable(true);
548     m_buttonSpacerTool->setChecked(false);
549
550     m_toolGroup->addAction(m_buttonSelectTool);
551     m_toolGroup->addAction(m_buttonRazorTool);
552     m_toolGroup->addAction(m_buttonSpacerTool);
553     m_toolGroup->setExclusive(true);
554     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
555
556     QWidget * actionWidget;
557     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
558     actionWidget->setMaximumWidth(24);
559     actionWidget->setMinimumHeight(17);
560
561     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
562     actionWidget->setMaximumWidth(24);
563     actionWidget->setMinimumHeight(17);
564
565     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
566     actionWidget->setMaximumWidth(24);
567     actionWidget->setMinimumHeight(17);
568
569     toolbar->setStyleSheet(style1);
570     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
571
572     toolbar->addSeparator();
573     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
574     toolbar->addAction(m_buttonFitZoom);
575     m_buttonFitZoom->setCheckable(false);
576     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
577
578     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
579     actionWidget->setMaximumWidth(24);
580     actionWidget->setMinimumHeight(17);
581
582     m_zoomSlider = new QSlider(Qt::Horizontal, this);
583     m_zoomSlider->setMaximum(13);
584     m_zoomSlider->setPageStep(1);
585
586     m_zoomSlider->setMaximumWidth(150);
587     m_zoomSlider->setMinimumWidth(100);
588
589     const int contentHeight = QFontMetrics(w->font()).height() + 8;
590
591     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
592     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
593
594     m_zoomSlider->setStyleSheet(style);
595
596     //m_zoomSlider->height() + 5;
597     statusBar()->setMinimumHeight(contentHeight);
598
599
600     toolbar->addWidget(m_zoomSlider);
601
602     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
603     toolbar->addAction(m_buttonVideoThumbs);
604     m_buttonVideoThumbs->setCheckable(true);
605     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
606     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
607
608     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
609     toolbar->addAction(m_buttonAudioThumbs);
610     m_buttonAudioThumbs->setCheckable(true);
611     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
612     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
613
614     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
615     toolbar->addAction(m_buttonShowMarkers);
616     m_buttonShowMarkers->setCheckable(true);
617     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
618     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
619
620     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
621     toolbar->addAction(m_buttonSnap);
622     m_buttonSnap->setCheckable(true);
623     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
624     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
625     layout->addWidget(toolbar);
626
627
628     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
629     actionWidget->setMaximumWidth(24);
630     actionWidget->setMinimumHeight(17);
631
632     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
633     actionWidget->setMaximumWidth(24);
634     actionWidget->setMinimumHeight(17);
635
636     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
637     actionWidget->setMaximumWidth(24);
638     actionWidget->setMinimumHeight(17);
639
640     actionWidget = toolbar->widgetForAction(m_buttonSnap);
641     actionWidget->setMaximumWidth(24);
642     actionWidget->setMinimumHeight(17);
643
644     m_messageLabel = new StatusBarMessageLabel(this);
645     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
646
647     statusBar()->addWidget(m_messageLabel, 10);
648     statusBar()->addWidget(statusProgressBar, 0);
649     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
650     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
651     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
652     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
653     m_messageLabel->hide();
654
655     collection->addAction("select_tool", m_buttonSelectTool);
656     collection->addAction("razor_tool", m_buttonRazorTool);
657     collection->addAction("spacer_tool", m_buttonSpacerTool);
658
659     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
660     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
661     collection->addAction("show_markers", m_buttonShowMarkers);
662     collection->addAction("snap", m_buttonSnap);
663     collection->addAction("zoom_fit", m_buttonFitZoom);
664
665     KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
666     collection->addAction("zoom_in", zoomIn);
667     connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
668     zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
669
670     KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
671     collection->addAction("zoom_out", zoomOut);
672     connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
673     zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
674
675     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
676     collection->addAction("project_find", m_projectSearch);
677     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
678     m_projectSearch->setShortcut(Qt::Key_Slash);
679
680     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
681     collection->addAction("project_find_next", m_projectSearchNext);
682     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
683     m_projectSearchNext->setShortcut(Qt::Key_F3);
684     m_projectSearchNext->setEnabled(false);
685
686     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
687     collection->addAction("manage_profiles", profilesAction);
688     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
689
690     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
691     collection->addAction("project_settings", projectAction);
692     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
693
694     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
695     collection->addAction("project_render", projectRender);
696     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
697     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
698
699     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
700     KShortcut playShortcut;
701     playShortcut.setPrimary(Qt::Key_Space);
702     playShortcut.setAlternate(Qt::Key_K);
703     monitorPlay->setShortcut(playShortcut);
704     collection->addAction("monitor_play", monitorPlay);
705     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
706
707     KAction *markIn = collection->addAction("mark_in");
708     markIn->setText(i18n("Set In Point"));
709     markIn->setShortcut(Qt::Key_I);
710     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
711
712     KAction *markOut = collection->addAction("mark_out");
713     markOut->setText(i18n("Set Out Point"));
714     markOut->setShortcut(Qt::Key_O);
715     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
716
717     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
718     monitorSeekBackward->setShortcut(Qt::Key_J);
719     collection->addAction("monitor_seek_backward", monitorSeekBackward);
720     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
721
722     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
723     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
724     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
725     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
726
727     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
728     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
729     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
730     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
731
732     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
733     monitorSeekForward->setShortcut(Qt::Key_L);
734     collection->addAction("monitor_seek_forward", monitorSeekForward);
735     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
736
737     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
738     clipStart->setShortcut(Qt::Key_Home);
739     collection->addAction("seek_clip_start", clipStart);
740     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
741
742     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
743     clipEnd->setShortcut(Qt::Key_End);
744     collection->addAction("seek_clip_end", clipEnd);
745     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
746
747     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
748     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
749     collection->addAction("seek_start", projectStart);
750     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
751
752     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
753     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
754     collection->addAction("seek_end", projectEnd);
755     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
756
757     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
758     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
759     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
760     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
761
762     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
763     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
764     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
765     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
766
767     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
768     deleteTimelineClip->setShortcut(Qt::Key_Delete);
769     collection->addAction("delete_timeline_clip", deleteTimelineClip);
770     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
771
772     KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
773     collection->addAction("change_clip_speed", editTimelineClipSpeed);
774     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
775
776     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
777     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
778     collection->addAction("cut_timeline_clip", cutTimelineClip);
779     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
780
781     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
782     collection->addAction("add_clip_marker", addClipMarker);
783     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
784
785     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
786     collection->addAction("delete_clip_marker", deleteClipMarker);
787     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
788
789     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
790     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
791     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
792
793     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
794     collection->addAction("edit_clip_marker", editClipMarker);
795     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
796
797     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
798     collection->addAction("insert_space", insertSpace);
799     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
800
801     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
802     collection->addAction("add_guide", addGuide);
803     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
804
805     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
806     collection->addAction("delete_guide", delGuide);
807     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
808
809     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
810     collection->addAction("edit_guide", editGuide);
811     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
812
813     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
814     collection->addAction("delete_all_guides", delAllGuides);
815     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
816
817     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
818     collection->addAction("paste_effects", pasteEffects);
819     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
820
821     m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
822
823     KStandardAction::quit(this, SLOT(queryQuit()), collection);
824
825     KStandardAction::open(this, SLOT(openFile()), collection);
826
827     m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
828
829     KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
830
831     KStandardAction::openNew(this, SLOT(newFile()), collection);
832
833     KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
834
835     KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
836
837     KStandardAction::copy(this, SLOT(slotCopy()), collection);
838
839     KStandardAction::paste(this, SLOT(slotPaste()), collection);
840
841     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
842     undo->setEnabled(false);
843     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
844
845     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
846     redo->setEnabled(false);
847     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
848
849     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
850
851     connect(collection, SIGNAL(actionHovered(QAction*)),
852             this, SLOT(slotDisplayActionMessage(QAction*)));
853     //connect(collection, SIGNAL( clearStatusText() ),
854     //statusBar(), SLOT( clear() ) );
855 }
856
857 void MainWindow::slotDisplayActionMessage(QAction *a) {
858     statusBar()->showMessage(a->data().toString(), 3000);
859 }
860
861 void MainWindow::saveOptions() {
862     KdenliveSettings::self()->writeConfig();
863     KSharedConfigPtr config = KGlobal::config();
864     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
865     KConfigGroup treecolumns(config, "Project Tree");
866     treecolumns.writeEntry("columns", m_projectList->headerInfo());
867     config->sync();
868 }
869
870 void MainWindow::readOptions() {
871     KSharedConfigPtr config = KGlobal::config();
872     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
873     KConfigGroup initialGroup(config, "version");
874     if (!initialGroup.exists()) {
875         // this is our first run, show Wizard
876         Wizard *w = new Wizard(this);
877         if (w->exec() == QDialog::Accepted && w->isOk()) {
878             w->adjustSettings();
879             initialGroup.writeEntry("version", "0.7");
880             delete w;
881         } else {
882             ::exit(1);
883         }
884     }
885     KConfigGroup treecolumns(config, "Project Tree");
886     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
887     if (!state.isEmpty())
888         m_projectList->setHeaderInfo(state);
889 }
890
891 void MainWindow::newFile(bool showProjectSettings) {
892     QString profileName;
893     KUrl projectFolder;
894     QPoint projectTracks(3, 2);
895     if (!showProjectSettings && m_timelineArea->count() == 0) {
896         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
897         profileName = KdenliveSettings::default_profile();
898     } else {
899         ProjectSettings *w = new ProjectSettings;
900         if (w->exec() != QDialog::Accepted) return;
901         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
902         profileName = w->selectedProfile();
903         projectFolder = w->selectedFolder();
904         projectTracks = w->tracks();
905         delete w;
906     }
907     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks,  this);
908     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
909     TrackView *trackView = new TrackView(doc, this);
910     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
911     if (m_timelineArea->count() == 1) {
912         connectDocumentInfo(doc);
913         connectDocument(trackView, doc);
914     } else m_timelineArea->setTabBarHidden(false);
915     m_closeAction->setEnabled(m_timelineArea->count() > 1);
916 }
917
918 void MainWindow::activateDocument() {
919     if (m_timelineArea->currentWidget() == NULL) return;
920     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
921     KdenliveDoc *currentDoc = currentTab->document();
922     connectDocumentInfo(currentDoc);
923     connectDocument(currentTab, currentDoc);
924 }
925
926 void MainWindow::closeCurrentDocument() {
927     QWidget *w = m_timelineArea->currentWidget();
928     if (!w) return;
929     // closing current document
930     int ix = m_timelineArea->currentIndex() + 1;
931     if (ix == m_timelineArea->count()) ix = 0;
932     m_timelineArea->setCurrentIndex(ix);
933     TrackView *tabToClose = (TrackView *) w;
934     KdenliveDoc *docToClose = tabToClose->document();
935     if (docToClose && docToClose->isModified()) {
936         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
937         case KMessageBox::Yes :
938             // save document here. If saving fails, return false;
939             saveFile();
940             break;
941         case KMessageBox::Cancel :
942             return;
943         default:
944             break;
945         }
946     }
947     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
948     if (m_timelineArea->count() == 1) {
949         m_timelineArea->setTabBarHidden(true);
950         m_closeAction->setEnabled(false);
951     }
952     delete docToClose;
953     delete w;
954     if (m_timelineArea->count() == 0) {
955         m_activeDocument = NULL;
956         effectStack->clear();
957         transitionConfig->slotTransitionItemSelected(NULL, false);
958     }
959 }
960
961 bool MainWindow::saveFileAs(const QString &outputFileName) {
962     QDomDocument currentSceneList = m_projectMonitor->sceneList();
963     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
964         return false;
965     m_activeDocument->setUrl(KUrl(outputFileName));
966     if (m_activeDocument->m_autosave == NULL) {
967         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
968     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
969     setCaption(m_activeDocument->description());
970     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
971     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
972     m_activeDocument->setModified(false);
973     m_fileOpenRecent->addUrl(KUrl(outputFileName));
974     return true;
975 }
976
977 bool MainWindow::saveFileAs() {
978     // Check that the Kdenlive mime type is correctly installed
979     QString mimetype = "application/x-kdenlive";
980     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
981     if (!mime) mimetype = "*.kdenlive";
982
983     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
984     if (outputFile.isEmpty()) return false;
985     if (QFile::exists(outputFile)) {
986         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
987     }
988     return saveFileAs(outputFile);
989 }
990
991 bool MainWindow::saveFile() {
992     if (!m_activeDocument) return true;
993     if (m_activeDocument->url().isEmpty()) {
994         return saveFileAs();
995     } else {
996         bool result = saveFileAs(m_activeDocument->url().path());
997         m_activeDocument->m_autosave->resize(0);
998         return result;
999     }
1000 }
1001
1002 void MainWindow::openFile() {
1003     // Check that the Kdenlive mime type is correctly installed
1004     QString mimetype = "application/x-kdenlive";
1005     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1006     if (!mime) mimetype = "*.kdenlive";
1007
1008     KUrl url = KFileDialog::getOpenUrl(KUrl(), mimetype);
1009     if (url.isEmpty()) return;
1010     m_fileOpenRecent->addUrl(url);
1011     openFile(url);
1012 }
1013
1014 void MainWindow::openLastFile() {
1015     KSharedConfigPtr config = KGlobal::config();
1016     KUrl::List urls = m_fileOpenRecent->urls();
1017     if (urls.isEmpty()) newFile(false);
1018     else openFile(urls.last());
1019 }
1020
1021 void MainWindow::openFile(const KUrl &url) {
1022     // Check if the document is already opened
1023     const int ct = m_timelineArea->count();
1024     bool isOpened = false;
1025     int i;
1026     for (i = 0; i < ct; i++) {
1027         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1028         KdenliveDoc *doc = tab->document();
1029         if (doc->url() == url) {
1030             isOpened = true;
1031             break;
1032         }
1033     }
1034     if (isOpened) {
1035         m_timelineArea->setCurrentIndex(i);
1036         return;
1037     }
1038
1039     // Check for backup file
1040     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1041     if (!staleFiles.isEmpty()) {
1042         if (KMessageBox::questionYesNo(this,
1043                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1044                                        i18n("File Recovery"),
1045                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1046             recoverFiles(staleFiles);
1047             return;
1048         } else {
1049             // remove the stale files
1050             foreach(KAutoSaveFile *stale, staleFiles) {
1051                 stale->open(QIODevice::ReadWrite);
1052                 delete stale;
1053             }
1054         }
1055     }
1056     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1057     doOpenFile(url, NULL);
1058 }
1059
1060 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1061     KdenliveDoc *doc;
1062     doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
1063     if (stale == NULL) {
1064         stale = new KAutoSaveFile(url, doc);
1065         doc->m_autosave = stale;
1066     } else {
1067         doc->m_autosave = stale;
1068         doc->setUrl(stale->managedFile());
1069         doc->setModified(true);
1070         stale->setParent(doc);
1071     }
1072     connectDocumentInfo(doc);
1073     TrackView *trackView = new TrackView(doc, this);
1074     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1075     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1076     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1077     slotGotProgressInfo(QString(), -1);
1078     m_clipMonitor->refreshMonitor(true);
1079 }
1080
1081 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1082     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1083     foreach(KAutoSaveFile *stale, staleFiles) {
1084         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1085                   // show an error message; we could not steal the lockfile
1086                   // maybe another application got to the file before us?
1087                   delete stale;
1088                   continue;
1089         }*/
1090         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1091         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1092         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1093         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1094     }
1095 }
1096
1097
1098 void MainWindow::parseProfiles(const QString &mltPath) {
1099     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1100
1101     //KdenliveSettings::setDefaulttmpfolder();
1102     if (!mltPath.isEmpty()) {
1103         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1104         KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1105     }
1106
1107     if (KdenliveSettings::mltpath().isEmpty()) {
1108         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1109     }
1110     if (KdenliveSettings::rendererpath().isEmpty()) {
1111         QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1112         if (!QFile::exists(inigoPath))
1113             inigoPath = KStandardDirs::findExe("inigo");
1114         else KdenliveSettings::setRendererpath(inigoPath);
1115     }
1116     QStringList profilesFilter;
1117     profilesFilter << "*";
1118     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1119
1120     if (profilesList.isEmpty()) {
1121         // Cannot find MLT path, try finding inigo
1122         QString profilePath = KdenliveSettings::rendererpath();
1123         if (!profilePath.isEmpty()) {
1124             profilePath = profilePath.section('/', 0, -3);
1125             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1126             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1127         }
1128
1129         if (profilesList.isEmpty()) {
1130             // Cannot find the MLT profiles, ask for location
1131             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1132             getUrl->fileDialog()->setMode(KFile::Directory);
1133             if (getUrl->exec() == QDialog::Rejected) {
1134                 ::exit(0);
1135             }
1136             KUrl mltPath = getUrl->selectedUrl();
1137             delete getUrl;
1138             if (mltPath.isEmpty()) ::exit(0);
1139             KdenliveSettings::setMltpath(mltPath.path());
1140             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1141         }
1142     }
1143
1144     if (KdenliveSettings::rendererpath().isEmpty()) {
1145         // Cannot find the MLT inigo renderer, ask for location
1146         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1147         if (getUrl->exec() == QDialog::Rejected) {
1148             ::exit(0);
1149         }
1150         KUrl rendererPath = getUrl->selectedUrl();
1151         delete getUrl;
1152         if (rendererPath.isEmpty()) ::exit(0);
1153         KdenliveSettings::setRendererpath(rendererPath.path());
1154     }
1155
1156     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1157
1158     // Parse MLT profiles to build a list of available video formats
1159     if (profilesList.isEmpty()) parseProfiles();
1160 }
1161
1162
1163 void MainWindow::slotEditProfiles() {
1164     ProfilesDialog *w = new ProfilesDialog;
1165     w->exec();
1166     delete w;
1167 }
1168
1169 void MainWindow::slotEditProjectSettings() {
1170     ProjectSettings *w = new ProjectSettings;
1171     if (w->exec() == QDialog::Accepted) {
1172         QString profile = w->selectedProfile();
1173         m_activeDocument->setProfilePath(profile);
1174         KdenliveSettings::setCurrent_profile(profile);
1175         KdenliveSettings::setProject_fps(m_activeDocument->fps());
1176         setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1177         m_monitorManager->resetProfiles(m_activeDocument->timecode());
1178         if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1179         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1180
1181         // We need to desactivate & reactivate monitors to get a refresh
1182         m_monitorManager->switchMonitors();
1183     }
1184     delete w;
1185 }
1186
1187 void MainWindow::slotRenderProject() {
1188     if (!m_renderWidget) {
1189         m_renderWidget = new RenderWidget(this);
1190         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)));
1191         if (m_activeDocument) {
1192             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1193             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1194         }
1195     }
1196     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1197     if (currentTab) m_renderWidget->setTimeline(currentTab);
1198     m_renderWidget->setDocument(m_activeDocument);*/
1199     m_renderWidget->show();
1200 }
1201
1202 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &overlay_args, const QStringList &avformat_args, bool zoneOnly, bool playAfter, double guideStart, double guideEnd) {
1203     if (dest.isEmpty()) return;
1204     int in;
1205     int out;
1206     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1207     if (currentTab && zoneOnly) {
1208         in = currentTab->inPoint();
1209         out = currentTab->outPoint();
1210     }
1211     KTemporaryFile temp;
1212     temp.setAutoRemove(false);
1213     temp.setSuffix(".westley");
1214     if (temp.open()) {
1215         m_projectMonitor->saveSceneList(temp.fileName());
1216         QStringList args;
1217         args << "-erase";
1218         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1219         else if (guideStart != -1) {
1220             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1221         }
1222         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1223         QString videoPlayer = "-";
1224         if (playAfter) {
1225             videoPlayer = KdenliveSettings::defaultplayerapp();
1226             if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
1227         }
1228         if (!QFile::exists(KdenliveSettings::rendererpath())) {
1229             KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1230             return;
1231         }
1232         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1233         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1234         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1235         QProcess::startDetached(renderer, args);
1236
1237         KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1238     }
1239 }
1240
1241 void MainWindow::slotUpdateMousePosition(int pos) {
1242     if (m_activeDocument)
1243         switch (m_timecodeFormat->currentIndex()) {
1244         case 0:
1245             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1246             break;
1247         default:
1248             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1249         }
1250 }
1251
1252 void MainWindow::slotUpdateDocumentState(bool modified) {
1253     setCaption(m_activeDocument->description(), modified);
1254     m_saveAction->setEnabled(modified);
1255     if (modified) {
1256         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1257         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1258     } else {
1259         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1260         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1261     }
1262 }
1263
1264 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1265     if (m_activeDocument) {
1266         if (m_activeDocument == doc) return;
1267         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1268     }
1269     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1270 }
1271
1272 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1273     //m_projectMonitor->stop();
1274     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1275     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1276     if (m_activeDocument) {
1277         if (m_activeDocument == doc) return;
1278         m_activeDocument->backupMltPlaylist();
1279         if (m_activeTimeline) {
1280             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1281             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1282             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1283             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1284             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1285             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1286             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1287             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1288             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1289             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1290             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1291             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1292             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1293             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1294             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1295             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1296             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1297             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1298
1299             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1300             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1301             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1302             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1303             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1304             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1305             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1306             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1307             disconnect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), m_activeTimeline->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1308             disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1309             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1310             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1311             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1312             effectStack->clear();
1313         }
1314         m_activeDocument->setRenderer(NULL);
1315         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1316         m_clipMonitor->stop();
1317     }
1318     KdenliveSettings::setCurrent_profile(doc->profilePath());
1319     KdenliveSettings::setProject_fps(doc->fps());
1320     m_monitorManager->resetProfiles(doc->timecode());
1321     m_projectList->setDocument(doc);
1322     transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1323     effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1324     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1325     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1326     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1327     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1328     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1329     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1330     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1331     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1332     connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1333     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1334     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1335     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1336
1337     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1338     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1339     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1340
1341
1342     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1343     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1344     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1345     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1346     m_zoomSlider->setValue(doc->zoom());
1347     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1348     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1349     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1350     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1351
1352     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1353
1354
1355     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1356     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1357     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1358     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1359     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1360     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1361     connect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), trackView->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1362     connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1363     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1364
1365     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1366     connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1367     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1368
1369     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1370     m_activeTimeline = trackView;
1371     if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
1372     doc->setRenderer(m_projectMonitor->render);
1373     m_commandStack->setActiveStack(doc->commandStack());
1374     KdenliveSettings::setProject_display_ratio(doc->dar());
1375     m_projectList->updateAllClips();
1376     //doc->clipManager()->checkAudioThumbs();
1377
1378     //m_overView->setScene(trackView->projectScene());
1379     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1380     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1381
1382     setCaption(doc->description(), doc->isModified());
1383     m_saveAction->setEnabled(doc->isModified());
1384     m_activeDocument = doc;
1385 }
1386
1387 void MainWindow::slotGuidesUpdated() {
1388     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1389 }
1390
1391 void MainWindow::slotPreferences(int page, int option) {
1392     //An instance of your dialog could be already created and could be
1393     // cached, in which case you want to display the cached dialog
1394     // instead of creating another one
1395     if (KConfigDialog::showDialog("settings")) {
1396         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1397         if (page != -1) d->showPage(page, option);
1398         d->checkProfile();
1399         return;
1400     }
1401
1402     // KConfigDialog didn't find an instance of this dialog, so lets
1403     // create it :
1404     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1405     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1406     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1407     dialog->show();
1408     if (page != -1) dialog->showPage(page, option);
1409 }
1410
1411 void MainWindow::updateConfiguration() {
1412     //TODO: we should apply settings to all projects, not only the current one
1413     if (m_activeTimeline) {
1414         m_activeTimeline->refresh();
1415         m_activeTimeline->projectView()->checkAutoScroll();
1416         m_activeTimeline->projectView()->checkTrackHeight();
1417         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1418     }
1419     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1420     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1421 #ifndef NO_JOGSHUTTLE
1422     activateShuttleDevice();
1423 #endif /* NO_JOGSHUTTLE */
1424
1425 }
1426
1427 void MainWindow::slotSwitchVideoThumbs() {
1428     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1429     if (m_activeTimeline) {
1430         m_activeTimeline->refresh();
1431     }
1432     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1433 }
1434
1435 void MainWindow::slotSwitchAudioThumbs() {
1436     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1437     if (m_activeTimeline) {
1438         m_activeTimeline->refresh();
1439         m_activeTimeline->projectView()->checkAutoScroll();
1440         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1441     }
1442     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1443 }
1444
1445 void MainWindow::slotSwitchMarkersComments() {
1446     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1447     if (m_activeTimeline) {
1448         m_activeTimeline->refresh();
1449     }
1450     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1451 }
1452
1453 void MainWindow::slotSwitchSnap() {
1454     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1455     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1456 }
1457
1458
1459 void MainWindow::slotDeleteTimelineClip() {
1460     if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1461     else if (m_activeTimeline) {
1462         m_activeTimeline->projectView()->deleteSelectedClips();
1463     }
1464 }
1465
1466 void MainWindow::slotChangeClipSpeed() {
1467     if (m_activeTimeline) {
1468         m_activeTimeline->projectView()->changeClipSpeed();
1469     }
1470 }
1471
1472 void MainWindow::slotAddClipMarker() {
1473     if (m_activeTimeline) {
1474         m_activeTimeline->projectView()->slotAddClipMarker();
1475     }
1476 }
1477
1478 void MainWindow::slotDeleteClipMarker() {
1479     if (m_activeTimeline) {
1480         m_activeTimeline->projectView()->slotDeleteClipMarker();
1481     }
1482 }
1483
1484 void MainWindow::slotDeleteAllClipMarkers() {
1485     if (m_activeTimeline) {
1486         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1487     }
1488 }
1489
1490 void MainWindow::slotEditClipMarker() {
1491     if (m_activeTimeline) {
1492         m_activeTimeline->projectView()->slotEditClipMarker();
1493     }
1494 }
1495
1496 void MainWindow::slotAddGuide() {
1497     if (m_activeTimeline)
1498         m_activeTimeline->projectView()->slotAddGuide();
1499 }
1500
1501 void MainWindow::slotInsertSpace() {
1502     if (m_activeTimeline)
1503         m_activeTimeline->projectView()->slotInsertSpace();
1504 }
1505
1506 void MainWindow::slotEditGuide() {
1507     if (m_activeTimeline)
1508         m_activeTimeline->projectView()->slotEditGuide();
1509 }
1510
1511 void MainWindow::slotDeleteGuide() {
1512     if (m_activeTimeline)
1513         m_activeTimeline->projectView()->slotDeleteGuide();
1514 }
1515
1516 void MainWindow::slotDeleteAllGuides() {
1517     if (m_activeTimeline)
1518         m_activeTimeline->projectView()->slotDeleteAllGuides();
1519 }
1520
1521 void MainWindow::slotCutTimelineClip() {
1522     if (m_activeTimeline) {
1523         m_activeTimeline->projectView()->cutSelectedClips();
1524     }
1525 }
1526
1527 void MainWindow::slotAddProjectClip(KUrl url) {
1528     if (m_activeDocument)
1529         m_activeDocument->slotAddClipFile(url, QString());
1530 }
1531
1532 void MainWindow::slotAddTransition(QAction *result) {
1533     if (!result) return;
1534     QStringList info = result->data().toStringList();
1535     if (info.isEmpty()) return;
1536     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
1537     if (m_activeTimeline && !transition.isNull()) {
1538         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
1539     }
1540 }
1541
1542 void MainWindow::slotAddVideoEffect(QAction *result) {
1543     if (!result) return;
1544     QStringList info = result->data().toStringList();
1545     if (info.isEmpty()) return;
1546     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
1547     slotAddEffect(effect);
1548 }
1549
1550 void MainWindow::slotAddAudioEffect(QAction *result) {
1551     if (!result) return;
1552     QStringList info = result->data().toStringList();
1553     if (info.isEmpty()) return;
1554     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
1555     slotAddEffect(effect);
1556 }
1557
1558 void MainWindow::slotAddCustomEffect(QAction *result) {
1559     if (!result) return;
1560     QStringList info = result->data().toStringList();
1561     if (info.isEmpty()) return;
1562     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
1563     slotAddEffect(effect);
1564 }
1565
1566 void MainWindow::slotZoomIn() {
1567     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1568 }
1569
1570 void MainWindow::slotZoomOut() {
1571     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1572 }
1573
1574 void MainWindow::slotFitZoom() {
1575     if (m_activeTimeline) {
1576         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1577     }
1578 }
1579
1580 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1581     statusProgressBar->setValue(progress);
1582     if (progress >= 0) {
1583         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1584         statusProgressBar->setVisible(true);
1585     } else {
1586         m_messageLabel->setMessage(QString(), DefaultMessage);
1587         statusProgressBar->setVisible(false);
1588     }
1589 }
1590
1591 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1592     if (clip->clipType() == TEXT) {
1593         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1594         QString path = clip->getProperty("resource");
1595         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1596         QDomDocument doc;
1597         doc.setContent(clip->getProperty("xmldata"));
1598         dia_ui->setXml(doc);
1599         if (dia_ui->exec() == QDialog::Accepted) {
1600             QPixmap pix = dia_ui->renderedPixmap();
1601             pix.save(path);
1602             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1603             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1604             QMap <QString, QString> newprops;
1605             newprops.insert("xmldata", dia_ui->xml().toString());
1606             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1607             m_activeDocument->commandStack()->push(command);
1608             m_clipMonitor->refreshMonitor(true);
1609             m_activeDocument->setModified(true);
1610         }
1611         delete dia_ui;
1612
1613         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1614         return;
1615     }
1616     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1617     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1618     if (dia.exec() == QDialog::Accepted) {
1619         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1620         m_activeDocument->commandStack()->push(command);
1621
1622         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1623         if (dia.needsTimelineRefresh()) {
1624             // update clip occurences in timeline
1625             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1626         }
1627     }
1628 }
1629
1630 void MainWindow::customEvent(QEvent* e) {
1631     if (e->type() == QEvent::User) {
1632         // The timeline playing position changed...
1633         kDebug() << "RECIEVED JOG EVEMNT!!!";
1634     }
1635 }
1636 void MainWindow::slotActivateEffectStackView() {
1637     effectStack->raiseWindow(effectStackDock);
1638 }
1639
1640 void MainWindow::slotActivateTransitionView() {
1641     transitionConfig->raiseWindow(transitionConfigDock);
1642 }
1643
1644 void MainWindow::slotSnapRewind() {
1645     if (m_projectMonitor->isActive()) {
1646         if (m_activeTimeline)
1647             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1648     } else m_clipMonitor->slotSeekToPreviousSnap();
1649 }
1650
1651 void MainWindow::slotSnapForward() {
1652     if (m_projectMonitor->isActive()) {
1653         if (m_activeTimeline)
1654             m_activeTimeline->projectView()->slotSeekToNextSnap();
1655     } else m_clipMonitor->slotSeekToNextSnap();
1656 }
1657
1658 void MainWindow::slotClipStart() {
1659     if (m_projectMonitor->isActive()) {
1660         if (m_activeTimeline)
1661             m_activeTimeline->projectView()->clipStart();
1662     }
1663 }
1664
1665 void MainWindow::slotClipEnd() {
1666     if (m_projectMonitor->isActive()) {
1667         if (m_activeTimeline)
1668             m_activeTimeline->projectView()->clipEnd();
1669     }
1670 }
1671
1672 void MainWindow::slotChangeTool(QAction * action) {
1673     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1674     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1675     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
1676 }
1677
1678 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1679     if (m_activeDocument && m_activeTimeline) {
1680         //m_activeDocument->setTool(tool);
1681         m_activeTimeline->projectView()->setTool(tool);
1682     }
1683 }
1684
1685 void MainWindow::slotCopy() {
1686     if (!m_activeDocument || !m_activeTimeline) return;
1687     m_activeTimeline->projectView()->copyClip();
1688 }
1689
1690 void MainWindow::slotPaste() {
1691     if (!m_activeDocument || !m_activeTimeline) return;
1692     m_activeTimeline->projectView()->pasteClip();
1693 }
1694
1695 void MainWindow::slotPasteEffects() {
1696     if (!m_activeDocument || !m_activeTimeline) return;
1697     m_activeTimeline->projectView()->pasteClipEffects();
1698 }
1699
1700 void MainWindow::slotFind() {
1701     if (!m_activeDocument || !m_activeTimeline) return;
1702     m_projectSearch->setEnabled(false);
1703     m_findActivated = true;
1704     m_findString = QString();
1705     m_activeTimeline->projectView()->initSearchStrings();
1706     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1707     m_findTimer.start(5000);
1708     qApp->installEventFilter(this);
1709 }
1710
1711 void MainWindow::slotFindNext() {
1712     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1713         statusBar()->showMessage(i18n("Found : %1", m_findString));
1714     } else {
1715         statusBar()->showMessage(i18n("Reached end of project"));
1716     }
1717     m_findTimer.start(4000);
1718 }
1719
1720 void MainWindow::findAhead() {
1721     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1722         m_projectSearchNext->setEnabled(true);
1723         statusBar()->showMessage(i18n("Found : %1", m_findString));
1724     } else {
1725         m_projectSearchNext->setEnabled(false);
1726         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1727     }
1728 }
1729
1730 void MainWindow::findTimeout() {
1731     m_projectSearchNext->setEnabled(false);
1732     m_findActivated = false;
1733     m_findString = QString();
1734     statusBar()->showMessage(i18n("Find stopped"), 3000);
1735     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1736     m_projectSearch->setEnabled(true);
1737     removeEventFilter(this);
1738 }
1739
1740 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1741     if (m_findActivated) {
1742         if (ke->key() == Qt::Key_Backspace) {
1743             m_findString = m_findString.left(m_findString.length() - 1);
1744
1745             if (!m_findString.isEmpty()) {
1746                 findAhead();
1747             } else {
1748                 findTimeout();
1749             }
1750
1751             m_findTimer.start(4000);
1752             ke->accept();
1753             return;
1754         } else if (ke->key() == Qt::Key_Escape) {
1755             findTimeout();
1756             ke->accept();
1757             return;
1758         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1759             m_findString += ke->text();
1760
1761             findAhead();
1762
1763             m_findTimer.start(4000);
1764             ke->accept();
1765             return;
1766         }
1767     } else KXmlGuiWindow::keyPressEvent(ke);
1768 }
1769
1770
1771 /** Gets called when the window gets hidden */
1772 void MainWindow::hideEvent(QHideEvent *event) {
1773     // kDebug() << "I was hidden";
1774     // issue http://www.kdenlive.org/mantis/view.php?id=231
1775     if (this->isMinimized()) {
1776         // kDebug() << "I am minimized";
1777         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
1778     }
1779 }
1780
1781 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1782     if (m_findActivated) {
1783         if (event->type() == QEvent::ShortcutOverride) {
1784             QKeyEvent* ke = (QKeyEvent*) event;
1785             if (ke->text().trimmed().isEmpty()) return false;
1786             ke->accept();
1787             return true;
1788         } else return false;
1789     } else {
1790         // pass the event on to the parent class
1791         return QMainWindow::eventFilter(obj, event);
1792     }
1793 }
1794
1795 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1796     KDialog *dialog = new KDialog(this);
1797     dialog->setCaption("Save clip zone");
1798     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1799
1800     QWidget *widget = new QWidget(dialog);
1801     dialog->setMainWidget(widget);
1802
1803     QVBoxLayout *vbox = new QVBoxLayout(widget);
1804     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1805     QString path = m_activeDocument->projectFolder().path();
1806     path.append("/");
1807     path.append("untitled.westley");
1808     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1809     url->setFilter("video/mlt-playlist");
1810     QLabel *label2 = new QLabel(i18n("Description:"), this);
1811     KLineEdit *edit = new KLineEdit(this);
1812     vbox->addWidget(label1);
1813     vbox->addWidget(url);
1814     vbox->addWidget(label2);
1815     vbox->addWidget(edit);
1816     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1817
1818 }
1819
1820 void MainWindow::slotSetInPoint() {
1821     if (m_clipMonitor->isActive()) {
1822         m_clipMonitor->slotSetZoneStart();
1823     } else m_activeTimeline->projectView()->setInPoint();
1824 }
1825
1826 void MainWindow::slotSetOutPoint() {
1827     if (m_clipMonitor->isActive()) {
1828         m_clipMonitor->slotSetZoneEnd();
1829     } else m_activeTimeline->projectView()->setOutPoint();
1830 }
1831
1832
1833 #include "mainwindow.moc"