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