]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
* Delete transition from context menu
[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
28 #include <KApplication>
29 #include <KAction>
30 #include <KLocale>
31 #include <KGlobal>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 #include <KFileDialog>
35 #include <KMessageBox>
36 #include <KDebug>
37 #include <KIO/NetAccess>
38 #include <KSaveFile>
39 #include <KRuler>
40 #include <KConfigDialog>
41 #include <KXMLGUIFactory>
42 #include <KStatusBar>
43 #include <kstandarddirs.h>
44 #include <KUrlRequesterDialog>
45 #include <KTemporaryFile>
46 #include <KActionMenu>
47 #include <KMenu>
48 #include <locale.h>
49 #include <ktogglefullscreenaction.h>
50
51 #include <mlt++/Mlt.h>
52
53 #include "mainwindow.h"
54 #include "kdenlivesettings.h"
55 #include "kdenlivesettingsdialog.h"
56 #include "initeffects.h"
57 #include "profilesdialog.h"
58 #include "projectsettings.h"
59 #include "events.h"
60 #include "renderjob.h"
61 #include "clipmanager.h"
62 #include "projectlist.h"
63 #include "monitor.h"
64 #include "recmonitor.h"
65 #include "monitormanager.h"
66 #include "kdenlivedoc.h"
67 #include "trackview.h"
68 #include "customtrackview.h"
69 #include "effectslistview.h"
70 #include "effectstackview.h"
71 #include "transitionsettings.h"
72 #include "renderwidget.h"
73 #include "renderer.h"
74 #include "jogshuttle.h"
75 #include "clipproperties.h"
76
77 #define ID_STATUS_MSG 1
78 #define ID_EDITMODE_MSG 2
79 #define ID_TIMELINE_MSG 3
80 #define ID_TIMELINE_BUTTONS 5
81 #define ID_TIMELINE_POS 6
82 #define ID_TIMELINE_FORMAT 7
83
84 EffectsList MainWindow::videoEffects;
85 EffectsList MainWindow::audioEffects;
86 EffectsList MainWindow::customEffects;
87 EffectsList MainWindow::transitions;
88
89 MainWindow::MainWindow(QWidget *parent)
90         : KXmlGuiWindow(parent),
91         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL) {
92     setlocale(LC_NUMERIC, "POSIX");
93     parseProfiles();
94     setFont(KGlobalSettings::toolBarFont());
95     m_commandStack = new QUndoGroup;
96     m_timelineArea = new KTabWidget(this);
97     m_timelineArea->setTabReorderingEnabled(true);
98     m_timelineArea->setTabBarHidden(true);
99
100     QToolButton *closeTabButton = new QToolButton;
101     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
102     closeTabButton->setIcon(KIcon("tab-close"));
103     closeTabButton->adjustSize();
104     closeTabButton->setToolTip(i18n("Close the current tab"));
105     m_timelineArea->setCornerWidget(closeTabButton);
106     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
107
108     initEffects::parseEffectFiles();
109     m_monitorManager = new MonitorManager();
110
111     projectListDock = new QDockWidget(i18n("Project Tree"), this);
112     projectListDock->setObjectName("project_tree");
113     m_projectList = new ProjectList(this);
114     projectListDock->setWidget(m_projectList);
115     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
116
117     effectListDock = new QDockWidget(i18n("Effect List"), this);
118     effectListDock->setObjectName("effect_list");
119     m_effectList = new EffectsListView();
120
121     //m_effectList = new KListWidget(this);
122     effectListDock->setWidget(m_effectList);
123     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
124
125     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
126     effectStackDock->setObjectName("effect_stack");
127     effectStack = new EffectStackView(this);
128     effectStackDock->setWidget(effectStack);
129     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
130
131     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
132     transitionConfigDock->setObjectName("transition");
133     transitionConfig = new TransitionSettings(this);
134     transitionConfigDock->setWidget(transitionConfig);
135     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
136
137
138     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
139     clipMonitorDock->setObjectName("clip_monitor");
140     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
141     clipMonitorDock->setWidget(m_clipMonitor);
142     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
143     //m_clipMonitor->stop();
144
145     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
146     projectMonitorDock->setObjectName("project_monitor");
147     m_projectMonitor = new Monitor("project", m_monitorManager, this);
148     projectMonitorDock->setWidget(m_projectMonitor);
149     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
150
151     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
152     recMonitorDock->setObjectName("record_monitor");
153     m_recMonitor = new RecMonitor("record", this);
154     recMonitorDock->setWidget(m_recMonitor);
155     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
156
157     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
158
159     undoViewDock = new QDockWidget(i18n("Undo History"), this);
160     undoViewDock->setObjectName("undo_history");
161     m_undoView = new QUndoView(this);
162     m_undoView->setCleanIcon(KIcon("edit-clear"));
163     m_undoView->setEmptyLabel(i18n("Clean"));
164     undoViewDock->setWidget(m_undoView);
165     m_undoView->setGroup(m_commandStack);
166     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
167
168     overviewDock = new QDockWidget(i18n("Project Overview"), this);
169     overviewDock->setObjectName("project_overview");
170     //m_overView = new CustomTrackView(NULL, NULL, this);
171     //overviewDock->setWidget(m_overView);
172     addDockWidget(Qt::TopDockWidgetArea, overviewDock);
173
174     setupActions();
175     tabifyDockWidget(projectListDock, effectListDock);
176     tabifyDockWidget(projectListDock, effectStackDock);
177     tabifyDockWidget(projectListDock, transitionConfigDock);
178     tabifyDockWidget(projectListDock, undoViewDock);
179     projectListDock->raise();
180
181     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
182     setCentralWidget(m_timelineArea);
183
184     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
185     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
186
187     // build effects menus
188     QAction *action;
189     QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
190     QStringList effects = videoEffects.effectNames();
191     foreach(const QString &name, effects) {
192         action = new QAction(name, this);
193         action->setData(name);
194         videoEffectsMenu->addAction(action);
195     }
196     QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
197     effects = audioEffects.effectNames();
198     foreach(const QString &name, effects) {
199         action = new QAction(name, this);
200         action->setData(name);
201         audioEffectsMenu->addAction(action);
202     }
203     QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
204     effects = customEffects.effectNames();
205     foreach(const QString &name, effects) {
206         action = new QAction(name, this);
207         action->setData(name);
208         customEffectsMenu->addAction(action);
209     }
210
211     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
212     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
213     connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
214
215     m_timelineContextMenu = new QMenu(this);
216     m_timelineContextClipMenu = new QMenu(this);
217     m_timelineContextTransitionMenu = new QMenu(this);
218
219     action = actionCollection()->action("delete_timeline_clip");
220     m_timelineContextClipMenu->addAction(action);
221     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
222     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
223     m_timelineContextClipMenu->addMenu(customEffectsMenu);
224
225     m_timelineContextTransitionMenu->addAction(action);
226
227     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
228     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
229     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
230     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
231     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
232     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
233     slotConnectMonitors();
234
235     setAutoSaveSettings();
236     newFile();
237
238     activateShuttleDevice();
239 }
240
241 void MainWindow::queryQuit() {
242     kDebug() << "----- SAVING CONFUIG";
243     if (queryClose()) kapp->quit();
244 }
245
246 //virtual
247 bool MainWindow::queryClose() {
248     saveOptions();
249     if (m_activeDocument && m_activeDocument->isModified()) {
250         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
251         case KMessageBox::Yes :
252             // save document here. If saving fails, return false;
253             return true;
254         case KMessageBox::No :
255             return true;
256         default: // cancel
257             return false;
258         }
259     }
260     return true;
261 }
262
263 void MainWindow::activateShuttleDevice() {
264     if (m_jogProcess) delete m_jogProcess;
265     m_jogProcess = NULL;
266     if (KdenliveSettings::enableshuttle() == false) return;
267     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
268     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
269     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
270     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
271     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
272     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
273     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
274 }
275
276 void MainWindow::slotShuttleButton(int code) {
277     switch (code) {
278     case 5:
279         slotShuttleAction(KdenliveSettings::shuttle1());
280         break;
281     case 6:
282         slotShuttleAction(KdenliveSettings::shuttle2());
283         break;
284     case 7:
285         slotShuttleAction(KdenliveSettings::shuttle3());
286         break;
287     case 8:
288         slotShuttleAction(KdenliveSettings::shuttle4());
289         break;
290     case 9:
291         slotShuttleAction(KdenliveSettings::shuttle5());
292         break;
293     }
294 }
295
296 void MainWindow::slotShuttleAction(int code) {
297     switch (code) {
298     case 0:
299         return;
300     case 1:
301         m_monitorManager->slotPlay();
302         break;
303     default:
304         m_monitorManager->slotPlay();
305         break;
306     }
307 }
308
309 void MainWindow::slotFullScreen() {
310     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
311 }
312
313 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
314     if (!m_activeDocument) return;
315     if (effect.isNull()) {
316         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
317         return;
318     }
319     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
320     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
321 }
322
323 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
324     if (clipMonitor) clipMonitorDock->raise();
325     else projectMonitorDock->raise();
326 }
327
328 void MainWindow::slotSetClipDuration(int id, int duration) {
329     if (!m_activeDocument) return;
330     m_activeDocument->setProducerDuration(id, duration);
331 }
332
333 void MainWindow::slotConnectMonitors() {
334
335     m_projectList->setRenderer(m_clipMonitor->render);
336     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
337     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
338     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
339     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
340     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
341     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
342 }
343
344 void MainWindow::setupActions() {
345
346     m_timecodeFormat = new KComboBox(this);
347     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
348     m_timecodeFormat->addItem(i18n("Frames"));
349
350     statusProgressBar = new QProgressBar(this);
351     statusProgressBar->setMinimum(0);
352     statusProgressBar->setMaximum(100);
353     statusProgressBar->setMaximumWidth(150);
354     statusProgressBar->setVisible(false);
355     statusLabel = new QLabel(this);
356
357     QWidget *w = new QWidget;
358
359     QHBoxLayout *layout = new QHBoxLayout;
360     w->setLayout(layout);
361     layout->setContentsMargins(5, 0, 5, 0);
362     QToolBar *toolbar = new QToolBar("statusToolBar", this);
363
364
365     m_toolGroup = new QActionGroup(this);
366
367     QString style1 = "QToolButton { background-color: rgba(230, 230, 230, 20); border-style: inset; border:1px solid #666666;border-radius: 3px;margin: 0px 3px} QToolButton:checked { background-color: rgba(224, 0, 0, 100); border-style: inset; border:1px solid #666666;border-radius: 3px;}";
368
369     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
370     m_buttonSelectTool->setCheckable(true);
371     m_buttonSelectTool->setChecked(true);
372
373     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
374     m_buttonRazorTool->setCheckable(true);
375     m_buttonRazorTool->setChecked(false);
376
377     m_toolGroup->addAction(m_buttonSelectTool);
378     m_toolGroup->addAction(m_buttonRazorTool);
379     m_toolGroup->setExclusive(true);
380     toolbar->setStyleSheet(style1);
381     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
382
383     toolbar->addSeparator();
384     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
385     m_buttonFitZoom->setCheckable(false);
386     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
387
388     m_zoomSlider = new QSlider(Qt::Horizontal, this);
389     m_zoomSlider->setMaximum(13);
390
391     m_zoomSlider->setMaximumWidth(150);
392     m_zoomSlider->setMinimumWidth(100);
393
394     const int contentHeight = QFontMetrics(w->font()).height() + 3;
395     QString style = "QSlider::groove:horizontal { border: 1px solid #999999;height: 8px }";
396     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 8px;margin: -2px 0;border-radius: 3px; }");
397     m_zoomSlider->setStyleSheet(style);
398
399     //m_zoomSlider->setMaximumHeight(contentHeight);
400     //m_zoomSlider->height() + 5;
401     statusBar()->setMinimumHeight(contentHeight + 5);
402
403
404     toolbar->addWidget(m_zoomSlider);
405
406     m_buttonVideoThumbs = toolbar->addAction(KIcon("video-mpeg"), i18n("Show videoo thumbnails"));
407     m_buttonVideoThumbs->setCheckable(true);
408     m_buttonVideoThumbs->setChecked(KdenliveSettings::audiothumbnails());
409     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
410
411     m_buttonAudioThumbs = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show audio thumbnails"));
412     m_buttonAudioThumbs->setCheckable(true);
413     m_buttonAudioThumbs->setChecked(KdenliveSettings::videothumbnails());
414     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
415     layout->addWidget(toolbar);
416
417     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
418     statusBar()->insertPermanentWidget(1, statusLabel, 1);
419     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
420     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
421     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
422     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
423
424     actionCollection()->addAction("select_tool", m_buttonSelectTool);
425     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
426
427     KAction* clearAction = new KAction(KIcon("document-new"), i18n("Clear"), this);
428     clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
429     actionCollection()->addAction("clear", clearAction);
430     /*connect(clearAction, SIGNAL(triggered(bool)),
431             textArea, SLOT(clear()));*/
432
433     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
434     actionCollection()->addAction("manage_profiles", profilesAction);
435     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
436
437     KAction* projectAction = new KAction(KIcon("document-new"), i18n("Project Settings"), this);
438     actionCollection()->addAction("project_settings", projectAction);
439     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
440
441     KAction* projectRender = new KAction(KIcon("document-new"), i18n("Render Project"), this);
442     actionCollection()->addAction("project_render", projectRender);
443     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
444
445     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
446     monitorPlay->setShortcut(Qt::Key_Space);
447     actionCollection()->addAction("monitor_play", monitorPlay);
448     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
449
450     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
451     monitorSeekBackward->setShortcut(Qt::Key_J);
452     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
453     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
454
455     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
456     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
457     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
458     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
459
460     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
461     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
462     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
463     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
464
465     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
466     monitorSeekForward->setShortcut(Qt::Key_L);
467     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
468     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
469
470     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
471     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
472     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
473     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
474
475     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
476     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
477     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
478     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
479
480     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
481     deleteTimelineClip->setShortcut(Qt::Key_Delete);
482     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
483     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
484
485     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
486     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
487     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
488     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
489
490     KStandardAction::quit(this, SLOT(queryQuit()),
491                           actionCollection());
492
493     KStandardAction::open(this, SLOT(openFile()),
494                           actionCollection());
495
496     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
497                        actionCollection());
498
499     KStandardAction::save(this, SLOT(saveFile()),
500                           actionCollection());
501
502     KStandardAction::saveAs(this, SLOT(saveFileAs()),
503                             actionCollection());
504
505     KStandardAction::openNew(this, SLOT(newFile()),
506                              actionCollection());
507
508     KStandardAction::preferences(this, SLOT(slotPreferences()),
509                                  actionCollection());
510
511     KStandardAction::undo(this, SLOT(undo()),
512                           actionCollection());
513
514     KStandardAction::redo(this, SLOT(redo()),
515                           actionCollection());
516
517     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
518
519     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
520             this, SLOT(slotDisplayActionMessage(QAction*)));
521     //connect(actionCollection(), SIGNAL( clearStatusText() ),
522     //statusBar(), SLOT( clear() ) );
523
524     readOptions();
525 }
526
527 void MainWindow::undo() {
528     m_commandStack->undo();
529 }
530
531 void MainWindow::redo() {
532     m_commandStack->redo();
533 }
534
535 void MainWindow::slotDisplayActionMessage(QAction *a) {
536     statusBar()->showMessage(a->data().toString(), 3000);
537 }
538
539 void MainWindow::saveOptions() {
540     KdenliveSettings::self()->writeConfig();
541     KSharedConfigPtr config = KGlobal::config();
542     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
543     config->sync();
544 }
545
546 void MainWindow::readOptions() {
547     KSharedConfigPtr config = KGlobal::config();
548     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
549 }
550
551 void MainWindow::newFile() {
552     QString profileName;
553     KUrl projectFolder;
554     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
555     else {
556         ProjectSettings *w = new ProjectSettings;
557         if (w->exec() != QDialog::Accepted) return;
558         profileName = w->selectedProfile();
559         projectFolder = w->selectedFolder();
560         delete w;
561     }
562     MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
563     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
564     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack);
565     TrackView *trackView = new TrackView(doc, this);
566     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
567     if (m_timelineArea->count() == 1)
568         connectDocument(trackView, doc);
569     else m_timelineArea->setTabBarHidden(false);
570 }
571
572 void MainWindow::activateDocument() {
573     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
574     KdenliveDoc *currentDoc = currentTab->document();
575     connectDocument(currentTab, currentDoc);
576 }
577
578 void MainWindow::slotRemoveTab() {
579     QWidget *w = m_timelineArea->currentWidget();
580     // closing current document
581     int ix = m_timelineArea->currentIndex() + 1;
582     if (ix == m_timelineArea->count()) ix = 0;
583     m_timelineArea->setCurrentIndex(ix);
584     TrackView *tabToClose = (TrackView *) w;
585     KdenliveDoc *docToClose = tabToClose->document();
586     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
587     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
588     delete docToClose;
589     delete w;
590 }
591
592 void MainWindow::saveFileAs(const QString &outputFileName) {
593     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
594     m_activeDocument->setUrl(KUrl(outputFileName));
595     setCaption(m_activeDocument->description());
596     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
597     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
598     m_activeDocument->setModified(false);
599 }
600
601 void MainWindow::saveFileAs() {
602     QString outputFile = KFileDialog::getSaveFileName();
603     if (QFile::exists(outputFile)) {
604         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
605     }
606     saveFileAs(outputFile);
607 }
608
609 void MainWindow::saveFile() {
610     if (!m_activeDocument) return;
611     if (m_activeDocument->url().isEmpty()) {
612         saveFileAs();
613     } else {
614         saveFileAs(m_activeDocument->url().path());
615     }
616 }
617
618 void MainWindow::openFile() { //changed
619     KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
620     if (url.isEmpty()) return;
621     m_fileOpenRecent->addUrl(url);
622     openFile(url);
623 }
624
625 void MainWindow::openFile(const KUrl &url) { //new
626     //TODO: get video profile from url before opening it
627     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
628     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
629     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack);
630     TrackView *trackView = new TrackView(doc, this);
631     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
632     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
633     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
634     //connectDocument(trackView, doc);
635 }
636
637
638 void MainWindow::parseProfiles() {
639     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
640
641     //KdenliveSettings::setDefaulttmpfolder();
642     if (KdenliveSettings::mltpath().isEmpty()) {
643         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
644     }
645     if (KdenliveSettings::rendererpath().isEmpty()) {
646         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
647     }
648     QStringList profilesFilter;
649     profilesFilter << "*";
650     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
651
652     if (profilesList.isEmpty()) {
653         // Cannot find MLT path, try finding inigo
654         QString profilePath = KdenliveSettings::rendererpath();
655         if (!profilePath.isEmpty()) {
656             profilePath = profilePath.section('/', 0, -3);
657             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
658             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
659         }
660
661         if (profilesList.isEmpty()) {
662             // Cannot find the MLT profiles, ask for location
663             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
664             getUrl->fileDialog()->setMode(KFile::Directory);
665             getUrl->exec();
666             KUrl mltPath = getUrl->selectedUrl();
667             delete getUrl;
668             if (mltPath.isEmpty()) exit(1);
669             KdenliveSettings::setMltpath(mltPath.path());
670             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
671         }
672     }
673
674     if (KdenliveSettings::rendererpath().isEmpty()) {
675         // Cannot find the MLT inigo renderer, ask for location
676         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
677         getUrl->exec();
678         KUrl rendererPath = getUrl->selectedUrl();
679         delete getUrl;
680         if (rendererPath.isEmpty()) exit(1);
681         KdenliveSettings::setRendererpath(rendererPath.path());
682     }
683
684     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
685
686     // Parse MLT profiles to build a list of available video formats
687     if (profilesList.isEmpty()) parseProfiles();
688 }
689
690
691 void MainWindow::slotEditProfiles() {
692     ProfilesDialog *w = new ProfilesDialog;
693     w->exec();
694     delete w;
695 }
696
697 void MainWindow::slotEditProjectSettings() {
698     ProjectSettings *w = new ProjectSettings;
699     if (w->exec() == QDialog::Accepted) {
700         QString profile = w->selectedProfile();
701         m_activeDocument->setProfilePath(profile);
702         m_monitorManager->resetProfiles(profile);
703         setCaption(m_activeDocument->description());
704         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
705         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
706         m_monitorManager->setTimecode(m_activeDocument->timecode());
707         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
708
709         // We need to desactivate & reactivate monitors to get a refresh
710         m_monitorManager->switchMonitors();
711     }
712     delete w;
713 }
714
715 void MainWindow::slotRenderProject() {
716     if (!m_renderWidget) {
717         m_renderWidget = new RenderWidget(this);
718         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
719     }
720     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
721     if (currentTab) m_renderWidget->setTimeline(currentTab);
722     m_renderWidget->setDocument(m_activeDocument);*/
723     m_renderWidget->show();
724 }
725
726 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
727     if (dest.isEmpty()) return;
728     int in;
729     int out;
730     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
731     if (currentTab && zoneOnly) {
732         in = currentTab->inPoint();
733         out = currentTab->outPoint();
734     }
735     KTemporaryFile temp;
736     temp.setAutoRemove(false);
737     temp.setSuffix(".westley");
738     if (temp.open()) {
739         m_projectMonitor->saveSceneList(temp.fileName());
740         QStringList args;
741         args << "-erase";
742         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
743         QString videoPlayer = "-";
744         if (playAfter) videoPlayer = "kmplayer";
745         args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
746         QProcess::startDetached("kdenlive_render", args);
747     }
748 }
749
750 void MainWindow::slotUpdateMousePosition(int pos) {
751     if (m_activeDocument)
752         switch (m_timecodeFormat->currentIndex()) {
753         case 0:
754             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
755             break;
756         default:
757             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
758         }
759 }
760
761 void MainWindow::slotUpdateDocumentState(bool modified) {
762     setCaption(m_activeDocument->description(), modified);
763     if (modified) {
764         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
765         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
766     } else {
767         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
768         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
769     }
770 }
771
772 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
773     //m_projectMonitor->stop();
774     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
775     if (m_activeDocument) {
776         if (m_activeDocument == doc) return;
777         m_activeDocument->backupMltPlaylist();
778         if (m_activeTimeline) {
779             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
780             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
781             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
782             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
783             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
784             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
785             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
786             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
787             disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
788             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
789             disconnect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
790             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
791             disconnect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
792             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
793             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
794             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
795             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
796             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
797             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
798             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
799             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
800             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
801         }
802         m_activeDocument->setRenderer(NULL);
803         disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
804         m_clipMonitor->stop();
805     }
806     m_monitorManager->resetProfiles(doc->profilePath());
807     m_projectList->setDocument(doc);
808     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
809     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
810     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
811     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
812     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
813     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
814     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
815     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
816     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
817     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
818
819     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
820     connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
821     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
822
823
824
825     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
826     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
827     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
828     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
829     m_zoomSlider->setValue(trackView->currentZoom());
830     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
831     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
832     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
833     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
834     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
835     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
836     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
837     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
838     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
839     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
840     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
841     m_activeTimeline = trackView;
842     KdenliveSettings::setCurrent_profile(doc->profilePath());
843     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
844     m_monitorManager->setTimecode(doc->timecode());
845     doc->setRenderer(m_projectMonitor->render);
846     m_commandStack->setActiveStack(doc->commandStack());
847     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
848     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
849
850     //m_overView->setScene(trackView->projectScene());
851     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
852     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
853
854     setCaption(doc->description());
855     m_activeDocument = doc;
856 }
857
858 void MainWindow::slotPreferences() {
859     //An instance of your dialog could be already created and could be
860     // cached, in which case you want to display the cached dialog
861     // instead of creating another one
862     if (KConfigDialog::showDialog("settings"))
863         return;
864
865     // KConfigDialog didn't find an instance of this dialog, so lets
866     // create it :
867     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
868     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
869     dialog->show();
870 }
871
872 void MainWindow::updateConfiguration() {
873     //TODO: we should apply settings to all projects, not only the current one
874     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
875     if (currentTab) {
876         currentTab->refresh();
877         currentTab->projectView()->checkAutoScroll();
878         currentTab->projectView()->checkTrackHeight();
879         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
880     }
881     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
882     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
883     activateShuttleDevice();
884
885 }
886
887 void MainWindow::slotSwitchVideoThumbs() {
888     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
889     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
890     if (currentTab) {
891         currentTab->refresh();
892     }
893     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
894 }
895
896 void MainWindow::slotSwitchAudioThumbs() {
897     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
898     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
899     if (currentTab) {
900         currentTab->refresh();
901         currentTab->projectView()->checkAutoScroll();
902         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
903     }
904     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
905 }
906
907 void MainWindow::slotDeleteTimelineClip() {
908     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
909     if (currentTab) {
910         currentTab->projectView()->deleteSelectedClips();
911     }
912 }
913
914 void MainWindow::slotCutTimelineClip() {
915     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
916     if (currentTab) {
917         currentTab->projectView()->cutSelectedClips();
918     }
919 }
920
921 void MainWindow::slotAddProjectClip(KUrl url) {
922     if (m_activeDocument)
923         m_activeDocument->slotAddClipFile(url, QString());
924 }
925
926 void MainWindow::slotAddVideoEffect(QAction *result) {
927     if (!result) return;
928     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
929     slotAddEffect(effect);
930 }
931
932 void MainWindow::slotAddAudioEffect(QAction *result) {
933     if (!result) return;
934     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
935     slotAddEffect(effect);
936 }
937
938 void MainWindow::slotAddCustomEffect(QAction *result) {
939     if (!result) return;
940     QDomElement effect = customEffects.getEffectByName(result->data().toString());
941     slotAddEffect(effect);
942 }
943
944 void MainWindow::slotZoomIn() {
945     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
946 }
947
948 void MainWindow::slotZoomOut() {
949     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
950 }
951
952 void MainWindow::slotFitZoom() {
953     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
954     if (currentTab) {
955         m_zoomSlider->setValue(currentTab->fitZoom());
956     }
957 }
958
959 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
960     statusProgressBar->setValue(progress);
961     if (progress > 0) {
962         statusLabel->setText(tr("Creating Audio Thumbs"));
963         statusProgressBar->setVisible(true);
964     } else {
965         statusLabel->setText("");
966         statusProgressBar->setVisible(false);
967     }
968 }
969
970 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
971     if (clip->clipType() == TEXT) {
972         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
973         return;
974     }
975     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
976     if (dia.exec() == QDialog::Accepted) {
977         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
978         if (dia.needsTimelineRefresh()) {
979             // update clip occurences in timeline
980             TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
981             currentTab->projectView()->slotUpdateClip(dia.clipId());
982         }
983     }
984 }
985
986 void MainWindow::customEvent(QEvent* e) {
987     if (e->type() == QEvent::User) {
988         // The timeline playing position changed...
989         kDebug() << "RECIEVED JOG EVEMNT!!!";
990     }
991 }
992 void MainWindow::slotActivateEffectStackView() {
993     effectStack->raiseWindow(effectStackDock);
994 }
995
996 void MainWindow::slotActivateTransitionView() {
997     transitionConfig->raiseWindow(transitionConfigDock);
998 }
999
1000 void MainWindow::slotSnapRewind() {
1001     if (m_monitorManager->projectMonitorFocused()) {
1002         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1003         currentTab->projectView()->slotSeekToPreviousSnap();
1004     }
1005 }
1006
1007 void MainWindow::slotSnapForward() {
1008     if (m_monitorManager->projectMonitorFocused()) {
1009         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1010         currentTab->projectView()->slotSeekToNextSnap();
1011     }
1012 }
1013
1014 void MainWindow::slotChangeTool(QAction * action) {
1015     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1016     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1017 }
1018
1019 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1020     if (m_activeDocument) {
1021         //m_activeDocument->setTool(tool);
1022         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1023         currentTab->projectView()->setTool(tool);
1024     }
1025 }
1026
1027 #include "mainwindow.moc"