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