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