]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
New wizard at first Kdenlive startup: allows user to select video standard (pal,...
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27 #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
53 #include <mlt++/Mlt.h>
54
55 #include "mainwindow.h"
56 #include "kdenlivesettings.h"
57 #include "kdenlivesettingsdialog.h"
58 #include "initeffects.h"
59 #include "profilesdialog.h"
60 #include "projectsettings.h"
61 #include "events.h"
62 #include "renderjob.h"
63 #include "clipmanager.h"
64 #include "projectlist.h"
65 #include "monitor.h"
66 #include "recmonitor.h"
67 #include "monitormanager.h"
68 #include "kdenlivedoc.h"
69 #include "trackview.h"
70 #include "customtrackview.h"
71 #include "effectslistview.h"
72 #include "effectstackview.h"
73 #include "transitionsettings.h"
74 #include "renderwidget.h"
75 #include "renderer.h"
76 #include "jogshuttle.h"
77 #include "clipproperties.h"
78 #include "wizard.h"
79
80 #define ID_STATUS_MSG 1
81 #define ID_EDITMODE_MSG 2
82 #define ID_TIMELINE_MSG 3
83 #define ID_TIMELINE_BUTTONS 5
84 #define ID_TIMELINE_POS 6
85 #define ID_TIMELINE_FORMAT 7
86
87 namespace Mlt {
88 class Producer;
89 };
90
91 EffectsList MainWindow::videoEffects;
92 EffectsList MainWindow::audioEffects;
93 EffectsList MainWindow::customEffects;
94 EffectsList MainWindow::transitions;
95
96 MainWindow::MainWindow(QWidget *parent)
97         : KXmlGuiWindow(parent),
98         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
99     setlocale(LC_NUMERIC, "POSIX");
100     setFont(KGlobalSettings::toolBarFont());
101     parseProfiles();
102     m_commandStack = new QUndoGroup;
103     m_timelineArea = new KTabWidget(this);
104     m_timelineArea->setTabReorderingEnabled(true);
105     m_timelineArea->setTabBarHidden(true);
106
107     QToolButton *closeTabButton = new QToolButton;
108     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
109     closeTabButton->setIcon(KIcon("tab-close"));
110     closeTabButton->adjustSize();
111     closeTabButton->setToolTip(i18n("Close the current tab"));
112     m_timelineArea->setCornerWidget(closeTabButton);
113     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
114
115     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
116     m_findTimer.setSingleShot(true);
117
118     initEffects::parseEffectFiles();
119     m_monitorManager = new MonitorManager();
120
121     projectListDock = new QDockWidget(i18n("Project Tree"), this);
122     projectListDock->setObjectName("project_tree");
123     m_projectList = new ProjectList(this);
124     projectListDock->setWidget(m_projectList);
125     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
126
127     effectListDock = new QDockWidget(i18n("Effect List"), this);
128     effectListDock->setObjectName("effect_list");
129     m_effectList = new EffectsListView();
130
131     //m_effectList = new KListWidget(this);
132     effectListDock->setWidget(m_effectList);
133     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
134
135     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
136     effectStackDock->setObjectName("effect_stack");
137     effectStack = new EffectStackView(this);
138     effectStackDock->setWidget(effectStack);
139     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
140
141     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
142     transitionConfigDock->setObjectName("transition");
143     transitionConfig = new TransitionSettings(this);
144     transitionConfigDock->setWidget(transitionConfig);
145     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
146
147     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
148     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
149                        actionCollection());
150     readOptions();
151
152     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
153     clipMonitorDock->setObjectName("clip_monitor");
154     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
155     clipMonitorDock->setWidget(m_clipMonitor);
156     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
157     //m_clipMonitor->stop();
158
159     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
160     projectMonitorDock->setObjectName("project_monitor");
161     m_projectMonitor = new Monitor("project", m_monitorManager, this);
162     projectMonitorDock->setWidget(m_projectMonitor);
163     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
164
165     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
166     recMonitorDock->setObjectName("record_monitor");
167     m_recMonitor = new RecMonitor("record", this);
168     recMonitorDock->setWidget(m_recMonitor);
169     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
170
171     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
172     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
173
174     undoViewDock = new QDockWidget(i18n("Undo History"), this);
175     undoViewDock->setObjectName("undo_history");
176     m_undoView = new QUndoView(this);
177     m_undoView->setCleanIcon(KIcon("edit-clear"));
178     m_undoView->setEmptyLabel(i18n("Clean"));
179     undoViewDock->setWidget(m_undoView);
180     m_undoView->setGroup(m_commandStack);
181     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
182
183     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
184     //overviewDock->setObjectName("project_overview");
185     //m_overView = new CustomTrackView(NULL, NULL, this);
186     //overviewDock->setWidget(m_overView);
187     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
188
189     setupActions();
190     //tabifyDockWidget(projectListDock, effectListDock);
191     tabifyDockWidget(projectListDock, effectStackDock);
192     tabifyDockWidget(projectListDock, transitionConfigDock);
193     //tabifyDockWidget(projectListDock, undoViewDock);
194     projectListDock->raise();
195
196     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
197     tabifyDockWidget(clipMonitorDock, recMonitorDock);
198     setCentralWidget(m_timelineArea);
199
200     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
201     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
202
203     // build effects menus
204     QAction *action;
205     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
206     QStringList effects = videoEffects.effectNames();
207     foreach(const QString &name, effects) {
208         action = new QAction(name, this);
209         action->setData(name);
210         videoEffectsMenu->addAction(action);
211     }
212     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
213     effects = audioEffects.effectNames();
214     foreach(const QString &name, effects) {
215         action = new QAction(name, this);
216         action->setData(name);
217         audioEffectsMenu->addAction(action);
218     }
219     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
220     effects = customEffects.effectNames();
221     foreach(const QString &name, effects) {
222         action = new QAction(name, this);
223         action->setData(name);
224         m_customEffectsMenu->addAction(action);
225     }
226
227     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
228     const QList<QAction *> viewActions = createPopupMenu()->actions();
229     viewMenu->insertActions(NULL, viewActions);
230
231     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
232     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
233     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
234
235     m_timelineContextMenu = new QMenu(this);
236     m_timelineContextClipMenu = new QMenu(this);
237     m_timelineContextTransitionMenu = new QMenu(this);
238
239
240     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
241     effects = transitions.effectNames();
242     foreach(const QString &name, effects) {
243         action = new QAction(name, this);
244         action->setData(name);
245         transitionsMenu->addAction(action);
246     }
247     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
248
249     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
250
251     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
252     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
253     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
254     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
255     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
256
257     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
258     m_timelineContextClipMenu->addMenu(markersMenu);
259     m_timelineContextClipMenu->addMenu(transitionsMenu);
260     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
261     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
262     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
263
264     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
265     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
266
267     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
268     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
269     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
270     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
271     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
272     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
273
274     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
275     slotConnectMonitors();
276
277     setAutoSaveSettings();
278
279     if (KdenliveSettings::openlastproject()) {
280         openLastFile();
281     } else newFile();
282
283     activateShuttleDevice();
284 }
285
286 void MainWindow::queryQuit() {
287     kDebug() << "----- SAVING CONFUIG";
288     if (queryClose()) kapp->quit();
289 }
290
291 //virtual
292 bool MainWindow::queryClose() {
293     saveOptions();
294     if (m_activeDocument && m_activeDocument->isModified()) {
295         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
296         case KMessageBox::Yes :
297             // save document here. If saving fails, return false;
298             saveFile();
299             return true;
300         case KMessageBox::No :
301             return true;
302         default: // cancel
303             return false;
304         }
305     }
306     return true;
307 }
308
309 void MainWindow::saveProperties(KConfig*) {
310     // save properties here,used by session management
311     saveFile();
312 }
313
314
315 void MainWindow::readProperties(KConfig *config) {
316     // read properties here,used by session management
317     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
318     openFile(KUrl(Lastproject));
319 }
320
321 void MainWindow::slotReloadEffects() {
322     initEffects::parseCustomEffectsFile();
323     m_customEffectsMenu->clear();
324     const QStringList effects = customEffects.effectNames();
325     QAction *action;
326     foreach(const QString &name, effects) {
327         action = new QAction(name, this);
328         action->setData(name);
329         m_customEffectsMenu->addAction(action);
330     }
331     m_effectList->reloadEffectList();
332 }
333
334 void MainWindow::activateShuttleDevice() {
335     if (m_jogProcess) delete m_jogProcess;
336     m_jogProcess = NULL;
337     if (KdenliveSettings::enableshuttle() == false) return;
338     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
339     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
340     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
341     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
342     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
343     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
344     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
345 }
346
347 void MainWindow::slotShuttleButton(int code) {
348     switch (code) {
349     case 5:
350         slotShuttleAction(KdenliveSettings::shuttle1());
351         break;
352     case 6:
353         slotShuttleAction(KdenliveSettings::shuttle2());
354         break;
355     case 7:
356         slotShuttleAction(KdenliveSettings::shuttle3());
357         break;
358     case 8:
359         slotShuttleAction(KdenliveSettings::shuttle4());
360         break;
361     case 9:
362         slotShuttleAction(KdenliveSettings::shuttle5());
363         break;
364     }
365 }
366
367 void MainWindow::slotShuttleAction(int code) {
368     switch (code) {
369     case 0:
370         return;
371     case 1:
372         m_monitorManager->slotPlay();
373         break;
374     default:
375         m_monitorManager->slotPlay();
376         break;
377     }
378 }
379
380 void MainWindow::slotFullScreen() {
381     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
382 }
383
384 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
385     if (!m_activeDocument) return;
386     if (effect.isNull()) {
387         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
388         return;
389     }
390     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
391     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
392 }
393
394 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
395     if (clipMonitor) clipMonitorDock->raise();
396     else projectMonitorDock->raise();
397 }
398
399 void MainWindow::slotSetClipDuration(int id, int duration) {
400     if (!m_activeDocument) return;
401     m_activeDocument->setProducerDuration(id, duration);
402 }
403
404 void MainWindow::slotConnectMonitors() {
405
406     m_projectList->setRenderer(m_clipMonitor->render);
407     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
408     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
409     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
410     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
411     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
412
413     connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(int)), m_projectList, SLOT(slotRemoveInvalidClip(int)));
414
415     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
416 }
417
418 void MainWindow::setupActions() {
419
420     m_timecodeFormat = new KComboBox(this);
421     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
422     m_timecodeFormat->addItem(i18n("Frames"));
423
424     statusProgressBar = new QProgressBar(this);
425     statusProgressBar->setMinimum(0);
426     statusProgressBar->setMaximum(100);
427     statusProgressBar->setMaximumWidth(150);
428     statusProgressBar->setVisible(false);
429
430     QWidget *w = new QWidget;
431
432     QHBoxLayout *layout = new QHBoxLayout;
433     w->setLayout(layout);
434     layout->setContentsMargins(5, 0, 5, 0);
435     QToolBar *toolbar = new QToolBar("statusToolBar", this);
436
437
438     m_toolGroup = new QActionGroup(this);
439
440     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;}";
441
442     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
443     m_buttonSelectTool->setCheckable(true);
444     m_buttonSelectTool->setChecked(true);
445
446     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
447     m_buttonRazorTool->setCheckable(true);
448     m_buttonRazorTool->setChecked(false);
449
450     m_toolGroup->addAction(m_buttonSelectTool);
451     m_toolGroup->addAction(m_buttonRazorTool);
452     m_toolGroup->setExclusive(true);
453     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
454
455     QWidget * actionWidget;
456     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
457     actionWidget->setMaximumWidth(24);
458     actionWidget->setMinimumHeight(17);
459
460     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
461     actionWidget->setMaximumWidth(24);
462     actionWidget->setMinimumHeight(17);
463
464     toolbar->setStyleSheet(style1);
465     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
466
467     toolbar->addSeparator();
468     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
469     m_buttonFitZoom->setCheckable(false);
470     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
471
472     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
473     actionWidget->setMaximumWidth(24);
474     actionWidget->setMinimumHeight(17);
475
476     m_zoomSlider = new QSlider(Qt::Horizontal, this);
477     m_zoomSlider->setMaximum(13);
478     m_zoomSlider->setPageStep(1);
479
480     m_zoomSlider->setMaximumWidth(150);
481     m_zoomSlider->setMinimumWidth(100);
482
483     const int contentHeight = QFontMetrics(w->font()).height() + 8;
484     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
485     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
486     m_zoomSlider->setStyleSheet(style);
487
488     //m_zoomSlider->setMaximumHeight(contentHeight);
489     //m_zoomSlider->height() + 5;
490     statusBar()->setMinimumHeight(contentHeight);
491
492
493     toolbar->addWidget(m_zoomSlider);
494
495     m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
496     m_buttonVideoThumbs->setCheckable(true);
497     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
498     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
499
500     m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
501     m_buttonAudioThumbs->setCheckable(true);
502     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
503     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
504
505     m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
506     m_buttonShowMarkers->setCheckable(true);
507     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
508     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
509
510     m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
511     m_buttonSnap->setCheckable(true);
512     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
513     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
514     layout->addWidget(toolbar);
515
516
517     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
518     actionWidget->setMaximumWidth(24);
519     actionWidget->setMinimumHeight(17);
520
521     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
522     actionWidget->setMaximumWidth(24);
523     actionWidget->setMinimumHeight(17);
524
525     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
526     actionWidget->setMaximumWidth(24);
527     actionWidget->setMinimumHeight(17);
528
529     actionWidget = toolbar->widgetForAction(m_buttonSnap);
530     actionWidget->setMaximumWidth(24);
531     actionWidget->setMinimumHeight(17);
532
533     m_messageLabel = new StatusBarMessageLabel(this);
534     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
535
536     statusBar()->addWidget(m_messageLabel, 10);
537     statusBar()->addWidget(statusProgressBar, 0);
538     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
539     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
540     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
541     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
542     m_messageLabel->hide();
543
544     actionCollection()->addAction("select_tool", m_buttonSelectTool);
545     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
546
547     actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
548     actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
549     actionCollection()->addAction("show_markers", m_buttonShowMarkers);
550     actionCollection()->addAction("snap", m_buttonSnap);
551     actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
552
553     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
554     actionCollection()->addAction("project_find", m_projectSearch);
555     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
556     m_projectSearch->setShortcut(Qt::Key_Slash);
557
558     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
559     actionCollection()->addAction("project_find_next", m_projectSearchNext);
560     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
561     m_projectSearchNext->setShortcut(Qt::Key_F3);
562     m_projectSearchNext->setEnabled(false);
563
564     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
565     actionCollection()->addAction("manage_profiles", profilesAction);
566     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
567
568     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
569     actionCollection()->addAction("project_settings", projectAction);
570     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
571
572     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
573     actionCollection()->addAction("project_render", projectRender);
574     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
575
576     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
577     monitorPlay->setShortcut(Qt::Key_Space);
578     actionCollection()->addAction("monitor_play", monitorPlay);
579     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
580
581     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
582     monitorSeekBackward->setShortcut(Qt::Key_J);
583     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
584     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
585
586     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
587     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
588     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
589     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
590
591     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
592     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
593     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
594     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
595
596     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
597     monitorSeekForward->setShortcut(Qt::Key_L);
598     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
599     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
600
601     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
602     clipStart->setShortcut(Qt::Key_Home);
603     actionCollection()->addAction("seek_clip_start", clipStart);
604     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
605
606     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
607     clipEnd->setShortcut(Qt::Key_End);
608     actionCollection()->addAction("seek_clip_end", clipEnd);
609     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
610
611     KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
612     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
613     actionCollection()->addAction("seek_start", projectStart);
614     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
615
616     KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
617     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
618     actionCollection()->addAction("seek_end", projectEnd);
619     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
620
621     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
622     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
623     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
624     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
625
626     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
627     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
628     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
629     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
630
631     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
632     deleteTimelineClip->setShortcut(Qt::Key_Delete);
633     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
634     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
635
636     KAction* editTimelineClipSpeed = new KAction(KIcon("edit-delete"), i18n("Change Clip Speed"), this);
637     actionCollection()->addAction("change_clip_speed", editTimelineClipSpeed);
638     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
639
640     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
641     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
642     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
643     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
644
645     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
646     actionCollection()->addAction("add_clip_marker", addClipMarker);
647     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
648
649     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
650     actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
651     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
652
653     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
654     actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
655     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
656
657     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
658     actionCollection()->addAction("edit_clip_marker", editClipMarker);
659     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
660
661     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
662     actionCollection()->addAction("add_guide", addGuide);
663     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
664
665     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
666     actionCollection()->addAction("delete_guide", delGuide);
667     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
668
669     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
670     actionCollection()->addAction("edit_guide", editGuide);
671     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
672
673     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
674     actionCollection()->addAction("delete_all_guides", delAllGuides);
675     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
676
677     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
678     actionCollection()->addAction("paste_effects", pasteEffects);
679     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
680
681     KStandardAction::quit(this, SLOT(queryQuit()),
682                           actionCollection());
683
684     KStandardAction::open(this, SLOT(openFile()),
685                           actionCollection());
686
687     KStandardAction::save(this, SLOT(saveFile()),
688                           actionCollection());
689
690     KStandardAction::saveAs(this, SLOT(saveFileAs()),
691                             actionCollection());
692
693     KStandardAction::openNew(this, SLOT(newFile()),
694                              actionCollection());
695
696     KStandardAction::preferences(this, SLOT(slotPreferences()),
697                                  actionCollection());
698
699     KStandardAction::copy(this, SLOT(slotCopy()),
700                           actionCollection());
701
702     KStandardAction::paste(this, SLOT(slotPaste()),
703                            actionCollection());
704
705     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
706                                           actionCollection());
707     undo->setEnabled(false);
708     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
709
710     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
711                                           actionCollection());
712     redo->setEnabled(false);
713     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
714
715     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
716
717     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
718             this, SLOT(slotDisplayActionMessage(QAction*)));
719     //connect(actionCollection(), SIGNAL( clearStatusText() ),
720     //statusBar(), SLOT( clear() ) );
721 }
722
723 void MainWindow::slotDisplayActionMessage(QAction *a) {
724     statusBar()->showMessage(a->data().toString(), 3000);
725 }
726
727 void MainWindow::saveOptions() {
728     KdenliveSettings::self()->writeConfig();
729     KSharedConfigPtr config = KGlobal::config();
730     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
731     config->sync();
732 }
733
734 void MainWindow::readOptions() {
735     KSharedConfigPtr config = KGlobal::config();
736     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
737     KConfigGroup initialGroup(config, "version");
738     if (!initialGroup.exists()) {
739         // this is our first run, show Wizard
740         Wizard *w = new Wizard(this);
741         if (w->exec() == QDialog::Accepted) {
742             w->adjustSettings();
743             initialGroup.writeEntry("version", "0.7");
744         }
745         delete w;
746     }
747 }
748
749 void MainWindow::newFile() {
750     QString profileName;
751     KUrl projectFolder;
752     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
753     else {
754         ProjectSettings *w = new ProjectSettings;
755         if (w->exec() != QDialog::Accepted) return;
756         profileName = w->selectedProfile();
757         projectFolder = w->selectedFolder();
758         delete w;
759     }
760     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, this);
761     doc->setProfilePath(profileName);
762     TrackView *trackView = new TrackView(doc, this);
763     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
764     if (m_timelineArea->count() == 1) {
765         connectDocumentInfo(doc);
766         connectDocument(trackView, doc);
767     } else m_timelineArea->setTabBarHidden(false);
768 }
769
770 void MainWindow::activateDocument() {
771     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
772     KdenliveDoc *currentDoc = currentTab->document();
773     connectDocumentInfo(currentDoc);
774     connectDocument(currentTab, currentDoc);
775 }
776
777 void MainWindow::slotRemoveTab() {
778     QWidget *w = m_timelineArea->currentWidget();
779     // closing current document
780     int ix = m_timelineArea->currentIndex() + 1;
781     if (ix == m_timelineArea->count()) ix = 0;
782     m_timelineArea->setCurrentIndex(ix);
783     TrackView *tabToClose = (TrackView *) w;
784     KdenliveDoc *docToClose = tabToClose->document();
785     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
786     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
787     delete docToClose;
788     delete w;
789 }
790
791 void MainWindow::saveFileAs(const QString &outputFileName) {
792     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
793     m_activeDocument->setUrl(KUrl(outputFileName));
794     setCaption(m_activeDocument->description());
795     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
796     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
797     m_activeDocument->setModified(false);
798     m_fileOpenRecent->addUrl(KUrl(outputFileName));
799 }
800
801 void MainWindow::saveFileAs() {
802     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
803     if (QFile::exists(outputFile)) {
804         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
805     }
806     saveFileAs(outputFile);
807 }
808
809 void MainWindow::saveFile() {
810     if (!m_activeDocument) return;
811     if (m_activeDocument->url().isEmpty()) {
812         saveFileAs();
813     } else {
814         saveFileAs(m_activeDocument->url().path());
815     }
816 }
817
818 void MainWindow::openFile() {
819     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
820     if (url.isEmpty()) return;
821     m_fileOpenRecent->addUrl(url);
822     openFile(url);
823 }
824
825 void MainWindow::openLastFile() {
826     KSharedConfigPtr config = KGlobal::config();
827     KUrl::List urls = m_fileOpenRecent->urls();
828     if (urls.isEmpty()) newFile();
829     else openFile(urls.last());
830 }
831
832 void MainWindow::openFile(const KUrl &url) {
833     // Check for backup file
834     bool recovery = false;
835     QString directory = url.directory();
836     QString fileName = url.fileName();
837     KUrl recoveryUrl;
838     recoveryUrl.setDirectory(directory);
839     recoveryUrl.setFileName("~" + fileName);
840     if (KIO::NetAccess::exists(recoveryUrl, KIO::NetAccess::SourceSide, this)) {
841         KFileItem bkup(KFileItem::Unknown, KFileItem::Unknown, recoveryUrl, true);
842         KFileItem src(KFileItem::Unknown, KFileItem::Unknown, url, true);
843         if (bkup.time(KFileItem::ModificationTime) > src.time(KFileItem::ModificationTime)) {
844             // Backup file is more recent than source file, ask user for recovery
845             if (KMessageBox::questionYesNo(this, i18n("A newer recovery file exists for <b>%1</b>\nOpen recovery file ?", url.fileName())) == KMessageBox::Yes) recovery = true;
846         }
847     }
848
849     //TODO: get video profile from url before opening it
850     /*MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
851     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
852
853     KdenliveSettings::setCurrent_profile(prof.path);*/
854     KdenliveDoc *doc;
855     if (recovery) {
856         doc = new KdenliveDoc(recoveryUrl, KUrl(), m_commandStack, this);
857         doc->setUrl(url);
858         doc->setModified(true);
859     } else doc = new KdenliveDoc(url, KUrl(), m_commandStack, this);
860     connectDocumentInfo(doc);
861     TrackView *trackView = new TrackView(doc, this);
862     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
863     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
864     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
865     slotGotProgressInfo(QString(), -1);
866     m_projectMonitor->refreshMonitor(true);
867 }
868
869
870 void MainWindow::parseProfiles() {
871     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
872
873     //KdenliveSettings::setDefaulttmpfolder();
874     if (KdenliveSettings::mltpath().isEmpty()) {
875         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
876     }
877     if (KdenliveSettings::rendererpath().isEmpty()) {
878         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
879     }
880     QStringList profilesFilter;
881     profilesFilter << "*";
882     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
883
884     if (profilesList.isEmpty()) {
885         // Cannot find MLT path, try finding inigo
886         QString profilePath = KdenliveSettings::rendererpath();
887         if (!profilePath.isEmpty()) {
888             profilePath = profilePath.section('/', 0, -3);
889             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
890             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
891         }
892
893         if (profilesList.isEmpty()) {
894             // Cannot find the MLT profiles, ask for location
895             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
896             getUrl->fileDialog()->setMode(KFile::Directory);
897             getUrl->exec();
898             KUrl mltPath = getUrl->selectedUrl();
899             delete getUrl;
900             if (mltPath.isEmpty()) kapp->quit();
901             KdenliveSettings::setMltpath(mltPath.path());
902             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
903         }
904     }
905
906     if (KdenliveSettings::rendererpath().isEmpty()) {
907         // Cannot find the MLT inigo renderer, ask for location
908         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
909         getUrl->exec();
910         KUrl rendererPath = getUrl->selectedUrl();
911         delete getUrl;
912         if (rendererPath.isEmpty()) kapp->quit();
913         KdenliveSettings::setRendererpath(rendererPath.path());
914     }
915
916     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
917
918     // Parse MLT profiles to build a list of available video formats
919     if (profilesList.isEmpty()) parseProfiles();
920 }
921
922
923 void MainWindow::slotEditProfiles() {
924     ProfilesDialog *w = new ProfilesDialog;
925     w->exec();
926     delete w;
927 }
928
929 void MainWindow::slotEditProjectSettings() {
930     ProjectSettings *w = new ProjectSettings;
931     if (w->exec() == QDialog::Accepted) {
932         QString profile = w->selectedProfile();
933         m_activeDocument->setProfilePath(profile);
934         KdenliveSettings::setCurrent_profile(profile);
935         KdenliveSettings::setProject_fps(m_activeDocument->fps());
936         setCaption(m_activeDocument->description());
937         m_monitorManager->resetProfiles();
938         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
939         m_monitorManager->setTimecode(m_activeDocument->timecode());
940         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
941
942         // We need to desactivate & reactivate monitors to get a refresh
943         m_monitorManager->switchMonitors();
944     }
945     delete w;
946 }
947
948 void MainWindow::slotRenderProject() {
949     if (!m_renderWidget) {
950         m_renderWidget = new RenderWidget(this);
951         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
952     }
953     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
954     if (currentTab) m_renderWidget->setTimeline(currentTab);
955     m_renderWidget->setDocument(m_activeDocument);*/
956     m_renderWidget->show();
957 }
958
959 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
960     if (dest.isEmpty()) return;
961     int in;
962     int out;
963     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
964     if (currentTab && zoneOnly) {
965         in = currentTab->inPoint();
966         out = currentTab->outPoint();
967     }
968     KTemporaryFile temp;
969     temp.setAutoRemove(false);
970     temp.setSuffix(".westley");
971     if (temp.open()) {
972         m_projectMonitor->saveSceneList(temp.fileName());
973         QStringList args;
974         args << "-erase";
975         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
976         QString videoPlayer = "-";
977         if (playAfter) {
978             videoPlayer = KdenliveSettings::defaultplayerapp();
979             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."));
980         }
981         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
982         QProcess::startDetached("kdenlive_render", args);
983     }
984 }
985
986 void MainWindow::slotUpdateMousePosition(int pos) {
987     if (m_activeDocument)
988         switch (m_timecodeFormat->currentIndex()) {
989         case 0:
990             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
991             break;
992         default:
993             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
994         }
995 }
996
997 void MainWindow::slotUpdateDocumentState(bool modified) {
998     setCaption(m_activeDocument->description(), modified);
999     if (modified) {
1000         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1001         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1002     } else {
1003         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1004         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1005     }
1006 }
1007
1008 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1009     if (m_activeDocument) {
1010         if (m_activeDocument == doc) return;
1011         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1012     }
1013     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1014 }
1015
1016 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1017     //m_projectMonitor->stop();
1018     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1019     if (m_activeDocument) {
1020         if (m_activeDocument == doc) return;
1021         m_activeDocument->backupMltPlaylist();
1022         if (m_activeTimeline) {
1023             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1024             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1025             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1026             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1027             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1028             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1029             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1030             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
1031             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1032             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1033             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1034             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1035             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1036             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1037             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1038
1039             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1040             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1041             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1042             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1043             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1044             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1045             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1046             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1047             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1048         }
1049         m_activeDocument->setRenderer(NULL);
1050         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1051         m_clipMonitor->stop();
1052     }
1053     KdenliveSettings::setCurrent_profile(doc->profilePath());
1054     KdenliveSettings::setProject_fps(doc->fps());
1055     m_monitorManager->resetProfiles();
1056     m_projectList->setDocument(doc);
1057     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1058     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1059     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1060     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1061     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1062     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1063     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1064     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1065     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1066     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1067
1068     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1069     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1070
1071
1072
1073     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1074     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1075     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1076     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1077     m_zoomSlider->setValue(doc->zoom());
1078     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1079     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1080     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1081     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1082
1083     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1084
1085
1086     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1087     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1088     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1089     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1090     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1091     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1092     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1093
1094     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1095     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1096     m_activeTimeline = trackView;
1097     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1098     m_monitorManager->setTimecode(doc->timecode());
1099     doc->setRenderer(m_projectMonitor->render);
1100     m_commandStack->setActiveStack(doc->commandStack());
1101
1102     doc->updateAllProjectClips();
1103
1104     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
1105     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
1106
1107     //m_overView->setScene(trackView->projectScene());
1108     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1109     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1110
1111     setCaption(doc->description());
1112     m_activeDocument = doc;
1113 }
1114
1115 void MainWindow::slotPreferences(int page, int option) {
1116     //An instance of your dialog could be already created and could be
1117     // cached, in which case you want to display the cached dialog
1118     // instead of creating another one
1119     if (KConfigDialog::showDialog("settings")) {
1120         if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
1121         return;
1122     }
1123
1124     // KConfigDialog didn't find an instance of this dialog, so lets
1125     // create it :
1126     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1127     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1128     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(resetProfiles()));
1129     dialog->show();
1130     if (page != -1) dialog->showPage(page, option);
1131 }
1132
1133 void MainWindow::updateConfiguration() {
1134     //TODO: we should apply settings to all projects, not only the current one
1135     if (m_activeTimeline) {
1136         m_activeTimeline->refresh();
1137         m_activeTimeline->projectView()->checkAutoScroll();
1138         m_activeTimeline->projectView()->checkTrackHeight();
1139         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1140     }
1141     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1142     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1143     activateShuttleDevice();
1144
1145 }
1146
1147 void MainWindow::slotSwitchVideoThumbs() {
1148     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1149     if (m_activeTimeline) {
1150         m_activeTimeline->refresh();
1151     }
1152     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1153 }
1154
1155 void MainWindow::slotSwitchAudioThumbs() {
1156     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1157     if (m_activeTimeline) {
1158         m_activeTimeline->refresh();
1159         m_activeTimeline->projectView()->checkAutoScroll();
1160         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1161     }
1162     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1163 }
1164
1165 void MainWindow::slotSwitchMarkersComments() {
1166     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1167     if (m_activeTimeline) {
1168         m_activeTimeline->refresh();
1169     }
1170     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1171 }
1172
1173 void MainWindow::slotSwitchSnap() {
1174     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1175     m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1176 }
1177
1178
1179 void MainWindow::slotDeleteTimelineClip() {
1180     if (m_activeTimeline) {
1181         m_activeTimeline->projectView()->deleteSelectedClips();
1182     }
1183 }
1184
1185 void MainWindow::slotChangeClipSpeed() {
1186     if (m_activeTimeline) {
1187         m_activeTimeline->projectView()->changeClipSpeed();
1188     }
1189 }
1190
1191 void MainWindow::slotAddClipMarker() {
1192     if (m_activeTimeline) {
1193         m_activeTimeline->projectView()->slotAddClipMarker();
1194     }
1195 }
1196
1197 void MainWindow::slotDeleteClipMarker() {
1198     if (m_activeTimeline) {
1199         m_activeTimeline->projectView()->slotDeleteClipMarker();
1200     }
1201 }
1202
1203 void MainWindow::slotDeleteAllClipMarkers() {
1204     if (m_activeTimeline) {
1205         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1206     }
1207 }
1208
1209 void MainWindow::slotEditClipMarker() {
1210     if (m_activeTimeline) {
1211         m_activeTimeline->projectView()->slotEditClipMarker();
1212     }
1213 }
1214
1215 void MainWindow::slotAddGuide() {
1216     if (m_activeTimeline)
1217         m_activeTimeline->projectView()->slotAddGuide();
1218 }
1219
1220 void MainWindow::slotEditGuide() {
1221     if (m_activeTimeline)
1222         m_activeTimeline->projectView()->slotEditGuide();
1223 }
1224
1225 void MainWindow::slotDeleteGuide() {
1226     if (m_activeTimeline)
1227         m_activeTimeline->projectView()->slotDeleteGuide();
1228 }
1229
1230 void MainWindow::slotDeleteAllGuides() {
1231     if (m_activeTimeline)
1232         m_activeTimeline->projectView()->slotDeleteAllGuides();
1233 }
1234
1235 void MainWindow::slotCutTimelineClip() {
1236     if (m_activeTimeline) {
1237         m_activeTimeline->projectView()->cutSelectedClips();
1238     }
1239 }
1240
1241 void MainWindow::slotAddProjectClip(KUrl url) {
1242     if (m_activeDocument)
1243         m_activeDocument->slotAddClipFile(url, QString());
1244 }
1245
1246 void MainWindow::slotAddTransition(QAction *result) {
1247     if (!result) return;
1248     QDomElement effect = transitions.getEffectByName(result->data().toString());
1249     if (m_activeTimeline) {
1250         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1251     }
1252 }
1253
1254 void MainWindow::slotAddVideoEffect(QAction *result) {
1255     if (!result) return;
1256     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1257     slotAddEffect(effect);
1258 }
1259
1260 void MainWindow::slotAddAudioEffect(QAction *result) {
1261     if (!result) return;
1262     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1263     slotAddEffect(effect);
1264 }
1265
1266 void MainWindow::slotAddCustomEffect(QAction *result) {
1267     if (!result) return;
1268     QDomElement effect = customEffects.getEffectByName(result->data().toString());
1269     slotAddEffect(effect);
1270 }
1271
1272 void MainWindow::slotZoomIn() {
1273     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1274 }
1275
1276 void MainWindow::slotZoomOut() {
1277     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1278 }
1279
1280 void MainWindow::slotFitZoom() {
1281     if (m_activeTimeline) {
1282         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1283     }
1284 }
1285
1286 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1287     statusProgressBar->setValue(progress);
1288     if (progress >= 0) {
1289         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1290         statusProgressBar->setVisible(true);
1291     } else {
1292         m_messageLabel->setMessage(QString(), DefaultMessage);
1293         statusProgressBar->setVisible(false);
1294     }
1295 }
1296
1297 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1298     if (clip->clipType() == TEXT) {
1299         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1300         return;
1301     }
1302     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1303     connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1304     if (dia.exec() == QDialog::Accepted) {
1305         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1306         if (dia.needsTimelineRefresh()) {
1307             // update clip occurences in timeline
1308             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1309         }
1310     }
1311 }
1312
1313 void MainWindow::customEvent(QEvent* e) {
1314     if (e->type() == QEvent::User) {
1315         // The timeline playing position changed...
1316         kDebug() << "RECIEVED JOG EVEMNT!!!";
1317     }
1318 }
1319 void MainWindow::slotActivateEffectStackView() {
1320     effectStack->raiseWindow(effectStackDock);
1321 }
1322
1323 void MainWindow::slotActivateTransitionView() {
1324     transitionConfig->raiseWindow(transitionConfigDock);
1325 }
1326
1327 void MainWindow::slotSnapRewind() {
1328     if (m_monitorManager->projectMonitorFocused()) {
1329         if (m_activeTimeline)
1330             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1331     }
1332 }
1333
1334 void MainWindow::slotSnapForward() {
1335     if (m_monitorManager->projectMonitorFocused()) {
1336         if (m_activeTimeline)
1337             m_activeTimeline->projectView()->slotSeekToNextSnap();
1338     }
1339 }
1340
1341 void MainWindow::slotClipStart() {
1342     if (m_monitorManager->projectMonitorFocused()) {
1343         if (m_activeTimeline)
1344             m_activeTimeline->projectView()->clipStart();
1345     }
1346 }
1347
1348 void MainWindow::slotClipEnd() {
1349     if (m_monitorManager->projectMonitorFocused()) {
1350         if (m_activeTimeline)
1351             m_activeTimeline->projectView()->clipEnd();
1352     }
1353 }
1354
1355 void MainWindow::slotChangeTool(QAction * action) {
1356     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1357     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1358 }
1359
1360 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1361     if (m_activeDocument && m_activeTimeline) {
1362         //m_activeDocument->setTool(tool);
1363         m_activeTimeline->projectView()->setTool(tool);
1364     }
1365 }
1366
1367 void MainWindow::slotCopy() {
1368     if (!m_activeDocument || !m_activeTimeline) return;
1369     m_activeTimeline->projectView()->copyClip();
1370 }
1371
1372 void MainWindow::slotPaste() {
1373     if (!m_activeDocument || !m_activeTimeline) return;
1374     m_activeTimeline->projectView()->pasteClip();
1375 }
1376
1377 void MainWindow::slotPasteEffects() {
1378     if (!m_activeDocument || !m_activeTimeline) return;
1379     m_activeTimeline->projectView()->pasteClipEffects();
1380 }
1381
1382 void MainWindow::slotFind() {
1383     if (!m_activeDocument || !m_activeTimeline) return;
1384     m_projectSearch->setEnabled(false);
1385     m_findActivated = true;
1386     m_findString = QString();
1387     m_activeTimeline->projectView()->initSearchStrings();
1388     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1389     m_findTimer.start(5000);
1390     qApp->installEventFilter(this);
1391 }
1392
1393 void MainWindow::slotFindNext() {
1394     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1395         statusBar()->showMessage(i18n("Found : %1", m_findString));
1396     } else {
1397         statusBar()->showMessage(i18n("Reached end of project"));
1398     }
1399     m_findTimer.start(4000);
1400 }
1401
1402 void MainWindow::findAhead() {
1403     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1404         m_projectSearchNext->setEnabled(true);
1405         statusBar()->showMessage(i18n("Found : %1", m_findString));
1406     } else {
1407         m_projectSearchNext->setEnabled(false);
1408         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1409     }
1410 }
1411
1412 void MainWindow::findTimeout() {
1413     m_projectSearchNext->setEnabled(false);
1414     m_findActivated = false;
1415     m_findString = QString();
1416     statusBar()->showMessage(i18n("Find stopped"), 3000);
1417     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1418     m_projectSearch->setEnabled(true);
1419     removeEventFilter(this);
1420 }
1421
1422 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1423     if (m_findActivated) {
1424         if (ke->key() == Qt::Key_Backspace) {
1425             m_findString = m_findString.left(m_findString.length() - 1);
1426
1427             if (!m_findString.isEmpty()) {
1428                 findAhead();
1429             } else {
1430                 findTimeout();
1431             }
1432
1433             m_findTimer.start(4000);
1434             ke->accept();
1435             return;
1436         } else if (ke->key() == Qt::Key_Escape) {
1437             findTimeout();
1438             ke->accept();
1439             return;
1440         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1441             m_findString += ke->text();
1442
1443             findAhead();
1444
1445             m_findTimer.start(4000);
1446             ke->accept();
1447             return;
1448         }
1449     } else KXmlGuiWindow::keyPressEvent(ke);
1450 }
1451
1452 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1453     if (m_findActivated) {
1454         if (event->type() == QEvent::ShortcutOverride) {
1455             QKeyEvent* ke = (QKeyEvent*) event;
1456             if (ke->text().trimmed().isEmpty()) return false;
1457             ke->accept();
1458             return true;
1459         } else return false;
1460     } else {
1461         // pass the event on to the parent class
1462         return QMainWindow::eventFilter(obj, event);
1463     }
1464 }
1465
1466 #include "mainwindow.moc"