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