]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
f4f28149768b730e04ca44d0fb8d70ff472059d8
[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 #include <stdlib.h>
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 #include <KNotification>
53 #include <KNotifyConfigWidget>
54
55 #include <mlt++/Mlt.h>
56
57 #include "mainwindow.h"
58 #include "kdenlivesettings.h"
59 #include "kdenlivesettingsdialog.h"
60 #include "initeffects.h"
61 #include "profilesdialog.h"
62 #include "projectsettings.h"
63 #include "events.h"
64 #include "clipmanager.h"
65 #include "projectlist.h"
66 #include "monitor.h"
67 #include "recmonitor.h"
68 #include "monitormanager.h"
69 #include "kdenlivedoc.h"
70 #include "trackview.h"
71 #include "customtrackview.h"
72 #include "effectslistview.h"
73 #include "effectstackview.h"
74 #include "transitionsettings.h"
75 #include "renderwidget.h"
76 #include "renderer.h"
77 #ifndef NO_JOGSHUTTLE
78 #include "jogshuttle.h"
79 #endif /* NO_JOGSHUTTLE */
80 #include "clipproperties.h"
81 #include "wizard.h"
82 #include "editclipcommand.h"
83 #include "titlewidget.h"
84 #include "markerdialog.h"
85 #include "clipitem.h"
86
87 static const int ID_STATUS_MSG = 1;
88 static const int ID_EDITMODE_MSG = 2;
89 static const int ID_TIMELINE_MSG = 3;
90 static const int ID_TIMELINE_BUTTONS = 5;
91 static const int ID_TIMELINE_POS = 6;
92 static const int ID_TIMELINE_FORMAT = 7;
93
94 namespace Mlt {
95 class Producer;
96 };
97
98 EffectsList MainWindow::videoEffects;
99 EffectsList MainWindow::audioEffects;
100 EffectsList MainWindow::customEffects;
101 EffectsList MainWindow::transitions;
102
103 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
104         : KXmlGuiWindow(parent),
105         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
106 #ifndef NO_JOGSHUTTLE
107         m_jogProcess(NULL),
108 #endif /* NO_JOGSHUTTLE */
109         m_findActivated(false), m_initialized(false) {
110     setlocale(LC_NUMERIC, "POSIX");
111     setFont(KGlobalSettings::toolBarFont());
112     parseProfiles(MltPath);
113     m_commandStack = new QUndoGroup;
114     m_timelineArea = new KTabWidget(this);
115     m_timelineArea->setTabReorderingEnabled(true);
116     m_timelineArea->setTabBarHidden(true);
117
118     QToolButton *closeTabButton = new QToolButton;
119     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
120     closeTabButton->setIcon(KIcon("tab-close"));
121     closeTabButton->adjustSize();
122     closeTabButton->setToolTip(i18n("Close the current tab"));
123     m_timelineArea->setCornerWidget(closeTabButton);
124     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
125
126     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
127     m_findTimer.setSingleShot(true);
128
129     initEffects::parseEffectFiles();
130     //initEffects::parseCustomEffectsFile();
131
132     m_monitorManager = new MonitorManager();
133
134     projectListDock = new QDockWidget(i18n("Project Tree"), this);
135     projectListDock->setObjectName("project_tree");
136     m_projectList = new ProjectList(this);
137     projectListDock->setWidget(m_projectList);
138     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
139
140     effectListDock = new QDockWidget(i18n("Effect List"), this);
141     effectListDock->setObjectName("effect_list");
142     m_effectList = new EffectsListView();
143
144     //m_effectList = new KListWidget(this);
145     effectListDock->setWidget(m_effectList);
146     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
147
148     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
149     effectStackDock->setObjectName("effect_stack");
150     effectStack = new EffectStackView(this);
151     effectStackDock->setWidget(effectStack);
152     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
153
154     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
155     transitionConfigDock->setObjectName("transition");
156     transitionConfig = new TransitionSettings(this);
157     transitionConfigDock->setWidget(transitionConfig);
158     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
159
160     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
161     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
162                        actionCollection());
163     readOptions();
164
165     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
166     clipMonitorDock->setObjectName("clip_monitor");
167     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
168     clipMonitorDock->setWidget(m_clipMonitor);
169     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
170     //m_clipMonitor->stop();
171
172     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
173     projectMonitorDock->setObjectName("project_monitor");
174     m_projectMonitor = new Monitor("project", m_monitorManager, this);
175     projectMonitorDock->setWidget(m_projectMonitor);
176     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
177
178     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
179     recMonitorDock->setObjectName("record_monitor");
180     m_recMonitor = new RecMonitor("record", this);
181     recMonitorDock->setWidget(m_recMonitor);
182     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
183
184     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
185     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
186
187     undoViewDock = new QDockWidget(i18n("Undo History"), this);
188     undoViewDock->setObjectName("undo_history");
189     m_undoView = new QUndoView(this);
190     m_undoView->setCleanIcon(KIcon("edit-clear"));
191     m_undoView->setEmptyLabel(i18n("Clean"));
192     undoViewDock->setWidget(m_undoView);
193     m_undoView->setGroup(m_commandStack);
194     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
195
196     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
197     //overviewDock->setObjectName("project_overview");
198     //m_overView = new CustomTrackView(NULL, NULL, this);
199     //overviewDock->setWidget(m_overView);
200     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
201
202     setupActions();
203     //tabifyDockWidget(projectListDock, effectListDock);
204     tabifyDockWidget(projectListDock, effectStackDock);
205     tabifyDockWidget(projectListDock, transitionConfigDock);
206     //tabifyDockWidget(projectListDock, undoViewDock);
207
208
209     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
210     tabifyDockWidget(clipMonitorDock, recMonitorDock);
211     setCentralWidget(m_timelineArea);
212
213     setupGUI();
214     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
215
216     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
217     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), static_cast<QMenu*>(factory()->container("marker_menu", this)));
218
219     // build effects menus
220     QAction *action;
221     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
222
223     QStringList effectInfo;
224     QMap<QString, QStringList> effectsList;
225     for (int ix = 0; ix < videoEffects.count(); ix++) {
226         effectInfo = videoEffects.effectIdInfo(ix);
227         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
228     }
229
230     foreach(QStringList value, effectsList) {
231         action = new QAction(value.at(0), this);
232         action->setData(value);
233         videoEffectsMenu->addAction(action);
234     }
235
236     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
237
238
239     effectsList.clear();
240     for (int ix = 0; ix < audioEffects.count(); ix++) {
241         effectInfo = audioEffects.effectIdInfo(ix);
242         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
243     }
244
245     foreach(QStringList value, effectsList) {
246         action = new QAction(value.at(0), this);
247         action->setData(value);
248         audioEffectsMenu->addAction(action);
249     }
250
251     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
252
253     if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
254     else m_customEffectsMenu->setEnabled(true);
255
256     effectsList.clear();
257     for (int ix = 0; ix < customEffects.count(); ix++) {
258         effectInfo = customEffects.effectIdInfo(ix);
259         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
260     }
261
262     foreach(QStringList value, effectsList) {
263         action = new QAction(value.at(0), this);
264         action->setData(value);
265         m_customEffectsMenu->addAction(action);
266     }
267
268     QMenu *newEffect = new QMenu(this);
269     newEffect->addMenu(videoEffectsMenu);
270     newEffect->addMenu(audioEffectsMenu);
271     newEffect->addMenu(m_customEffectsMenu);
272     effectStack->setMenu(newEffect);
273
274
275     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
276     const QList<QAction *> viewActions = createPopupMenu()->actions();
277     viewMenu->insertActions(NULL, viewActions);
278
279     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
280     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
281     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
282
283     m_timelineContextMenu = new QMenu(this);
284     m_timelineContextClipMenu = new QMenu(this);
285     m_timelineContextTransitionMenu = new QMenu(this);
286
287
288     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
289     QStringList effects = transitions.effectNames();
290
291     effectsList.clear();
292     for (int ix = 0; ix < transitions.count(); ix++) {
293         effectInfo = transitions.effectIdInfo(ix);
294         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
295     }
296     foreach(QStringList value, effectsList) {
297         action = new QAction(value.at(0), this);
298         action->setData(value);
299         transitionsMenu->addAction(action);
300     }
301     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
302
303     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
304     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
305     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
306
307     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
308     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
309     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
310     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
311     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
312
313     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
314     m_timelineContextClipMenu->addMenu(markersMenu);
315     m_timelineContextClipMenu->addMenu(transitionsMenu);
316     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
317     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
318     //TODO: re-enable custom effects menu when it is implemented
319     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
320
321     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
322     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
323
324     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
325     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
326     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
327     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
328     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
329     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
330
331     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
332     slotConnectMonitors();
333
334     // Open or create a file.  Command line argument passed in Url has
335     // precedence, then "openlastproject", then just a plain empty file.
336     // If opening Url fails, openlastproject will _not_ be used.
337     if (!Url.isEmpty()) {
338         openFile(Url);
339     } else {
340         if (KdenliveSettings::openlastproject()) {
341             openLastFile();
342         }
343     }
344     if (m_timelineArea->count() == 0) {
345         newFile(false);
346     }
347
348 #ifndef NO_JOGSHUTTLE
349     activateShuttleDevice();
350 #endif /* NO_JOGSHUTTLE */
351     projectListDock->raise();
352 }
353
354 void MainWindow::queryQuit() {
355     kDebug() << "----- SAVING CONFUIG";
356     if (queryClose()) kapp->quit();
357 }
358
359 //virtual
360 bool MainWindow::queryClose() {
361     saveOptions();
362     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
363     if (m_activeDocument && m_activeDocument->isModified()) {
364         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
365         case KMessageBox::Yes :
366             // save document here. If saving fails, return false;
367             return saveFile();
368         case KMessageBox::No :
369             return true;
370         default: // cancel
371             return false;
372         }
373     }
374     return true;
375 }
376
377 void MainWindow::saveProperties(KConfig*) {
378     // save properties here,used by session management
379     saveFile();
380 }
381
382
383 void MainWindow::readProperties(KConfig *config) {
384     // read properties here,used by session management
385     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
386     openFile(KUrl(Lastproject));
387 }
388
389 void MainWindow::slotReloadEffects() {
390     initEffects::parseCustomEffectsFile();
391     m_customEffectsMenu->clear();
392     const QStringList effects = customEffects.effectNames();
393     QAction *action;
394     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
395     else m_customEffectsMenu->setEnabled(true);
396
397     foreach(const QString &name, effects) {
398         action = new QAction(name, this);
399         action->setData(name);
400         m_customEffectsMenu->addAction(action);
401     }
402     m_effectList->reloadEffectList();
403 }
404
405 #ifndef NO_JOGSHUTTLE
406 void MainWindow::activateShuttleDevice() {
407     if (m_jogProcess) delete m_jogProcess;
408     m_jogProcess = NULL;
409     if (KdenliveSettings::enableshuttle() == false) return;
410     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
411     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
412     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
413     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
414     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
415     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
416     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
417 }
418
419 void MainWindow::slotShuttleButton(int code) {
420     switch (code) {
421     case 5:
422         slotShuttleAction(KdenliveSettings::shuttle1());
423         break;
424     case 6:
425         slotShuttleAction(KdenliveSettings::shuttle2());
426         break;
427     case 7:
428         slotShuttleAction(KdenliveSettings::shuttle3());
429         break;
430     case 8:
431         slotShuttleAction(KdenliveSettings::shuttle4());
432         break;
433     case 9:
434         slotShuttleAction(KdenliveSettings::shuttle5());
435         break;
436     }
437 }
438
439 void MainWindow::slotShuttleAction(int code) {
440     switch (code) {
441     case 0:
442         return;
443     case 1:
444         m_monitorManager->slotPlay();
445         break;
446     default:
447         m_monitorManager->slotPlay();
448         break;
449     }
450 }
451 #endif /* NO_JOGSHUTTLE */
452
453 void MainWindow::configureNotifications() {
454     KNotifyConfigWidget::configure(this);
455 }
456
457 void MainWindow::slotFullScreen() {
458     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
459 }
460
461 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
462     if (!m_activeDocument) return;
463     if (effect.isNull()) {
464         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
465         return;
466     }
467     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
468     currentTimeLine->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
469 }
470
471 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
472     if (clipMonitor) clipMonitorDock->raise();
473     else projectMonitorDock->raise();
474 }
475
476 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
477     if (!m_activeDocument) return;
478     m_activeDocument->setProducerDuration(id, duration);
479 }
480
481 void MainWindow::slotConnectMonitors() {
482
483     m_projectList->setRenderer(m_clipMonitor->render);
484     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
485     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
486     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
487     connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
488     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
489
490     connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
491
492     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
493
494     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
495     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
496
497     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
498     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
499 }
500
501 void MainWindow::slotAdjustClipMonitor() {
502     clipMonitorDock->updateGeometry();
503     clipMonitorDock->adjustSize();
504     m_clipMonitor->resetSize();
505 }
506
507 void MainWindow::slotAdjustProjectMonitor() {
508     projectMonitorDock->updateGeometry();
509     projectMonitorDock->adjustSize();
510     m_projectMonitor->resetSize();
511 }
512
513 void MainWindow::setupActions() {
514
515     KActionCollection* collection = actionCollection();
516     m_timecodeFormat = new KComboBox(this);
517     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
518     m_timecodeFormat->addItem(i18n("Frames"));
519
520     statusProgressBar = new QProgressBar(this);
521     statusProgressBar->setMinimum(0);
522     statusProgressBar->setMaximum(100);
523     statusProgressBar->setMaximumWidth(150);
524     statusProgressBar->setVisible(false);
525
526     QWidget *w = new QWidget;
527
528     QHBoxLayout *layout = new QHBoxLayout;
529     w->setLayout(layout);
530     layout->setContentsMargins(5, 0, 5, 0);
531     QToolBar *toolbar = new QToolBar("statusToolBar", this);
532
533
534     m_toolGroup = new QActionGroup(this);
535
536     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;}";
537
538     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
539     toolbar->addAction(m_buttonSelectTool);
540     m_buttonSelectTool->setCheckable(true);
541     m_buttonSelectTool->setChecked(true);
542
543     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
544     toolbar->addAction(m_buttonRazorTool);
545     m_buttonRazorTool->setCheckable(true);
546     m_buttonRazorTool->setChecked(false);
547
548     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
549     toolbar->addAction(m_buttonSpacerTool);
550     m_buttonSpacerTool->setCheckable(true);
551     m_buttonSpacerTool->setChecked(false);
552
553     m_toolGroup->addAction(m_buttonSelectTool);
554     m_toolGroup->addAction(m_buttonRazorTool);
555     m_toolGroup->addAction(m_buttonSpacerTool);
556     m_toolGroup->setExclusive(true);
557     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
558
559     QWidget * actionWidget;
560     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
561     actionWidget->setMaximumWidth(24);
562     actionWidget->setMinimumHeight(17);
563
564     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
565     actionWidget->setMaximumWidth(24);
566     actionWidget->setMinimumHeight(17);
567
568     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
569     actionWidget->setMaximumWidth(24);
570     actionWidget->setMinimumHeight(17);
571
572     toolbar->setStyleSheet(style1);
573     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
574
575     toolbar->addSeparator();
576     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
577     toolbar->addAction(m_buttonFitZoom);
578     m_buttonFitZoom->setCheckable(false);
579     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
580
581     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
582     actionWidget->setMaximumWidth(24);
583     actionWidget->setMinimumHeight(17);
584
585     m_zoomSlider = new QSlider(Qt::Horizontal, this);
586     m_zoomSlider->setMaximum(13);
587     m_zoomSlider->setPageStep(1);
588
589     m_zoomSlider->setMaximumWidth(150);
590     m_zoomSlider->setMinimumWidth(100);
591
592     const int contentHeight = QFontMetrics(w->font()).height() + 8;
593
594     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
595     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
596
597     m_zoomSlider->setStyleSheet(style);
598
599     //m_zoomSlider->height() + 5;
600     statusBar()->setMinimumHeight(contentHeight);
601
602
603     toolbar->addWidget(m_zoomSlider);
604
605     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
606     toolbar->addAction(m_buttonVideoThumbs);
607     m_buttonVideoThumbs->setCheckable(true);
608     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
609     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
610
611     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
612     toolbar->addAction(m_buttonAudioThumbs);
613     m_buttonAudioThumbs->setCheckable(true);
614     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
615     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
616
617     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
618     toolbar->addAction(m_buttonShowMarkers);
619     m_buttonShowMarkers->setCheckable(true);
620     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
621     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
622
623     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
624     toolbar->addAction(m_buttonSnap);
625     m_buttonSnap->setCheckable(true);
626     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
627     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
628     layout->addWidget(toolbar);
629
630
631     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
632     actionWidget->setMaximumWidth(24);
633     actionWidget->setMinimumHeight(17);
634
635     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
636     actionWidget->setMaximumWidth(24);
637     actionWidget->setMinimumHeight(17);
638
639     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
640     actionWidget->setMaximumWidth(24);
641     actionWidget->setMinimumHeight(17);
642
643     actionWidget = toolbar->widgetForAction(m_buttonSnap);
644     actionWidget->setMaximumWidth(24);
645     actionWidget->setMinimumHeight(17);
646
647     m_messageLabel = new StatusBarMessageLabel(this);
648     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
649
650     statusBar()->addWidget(m_messageLabel, 10);
651     statusBar()->addWidget(statusProgressBar, 0);
652     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
653     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
654     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
655     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
656     m_messageLabel->hide();
657
658     collection->addAction("select_tool", m_buttonSelectTool);
659     collection->addAction("razor_tool", m_buttonRazorTool);
660     collection->addAction("spacer_tool", m_buttonSpacerTool);
661
662     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
663     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
664     collection->addAction("show_markers", m_buttonShowMarkers);
665     collection->addAction("snap", m_buttonSnap);
666     collection->addAction("zoom_fit", m_buttonFitZoom);
667
668     KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
669     collection->addAction("zoom_in", zoomIn);
670     connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
671     zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
672
673     KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
674     collection->addAction("zoom_out", zoomOut);
675     connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
676     zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
677
678     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
679     collection->addAction("project_find", m_projectSearch);
680     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
681     m_projectSearch->setShortcut(Qt::Key_Slash);
682
683     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
684     collection->addAction("project_find_next", m_projectSearchNext);
685     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
686     m_projectSearchNext->setShortcut(Qt::Key_F3);
687     m_projectSearchNext->setEnabled(false);
688
689     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
690     collection->addAction("manage_profiles", profilesAction);
691     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
692
693     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
694     collection->addAction("project_settings", projectAction);
695     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
696
697     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
698     collection->addAction("project_render", projectRender);
699     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
700     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
701
702     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
703     KShortcut playShortcut;
704     playShortcut.setPrimary(Qt::Key_Space);
705     playShortcut.setAlternate(Qt::Key_K);
706     monitorPlay->setShortcut(playShortcut);
707     collection->addAction("monitor_play", monitorPlay);
708     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
709
710     KAction *markIn = collection->addAction("mark_in");
711     markIn->setText(i18n("Set In Point"));
712     markIn->setShortcut(Qt::Key_I);
713     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
714
715     KAction *markOut = collection->addAction("mark_out");
716     markOut->setText(i18n("Set Out Point"));
717     markOut->setShortcut(Qt::Key_O);
718     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
719
720     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
721     monitorSeekBackward->setShortcut(Qt::Key_J);
722     collection->addAction("monitor_seek_backward", monitorSeekBackward);
723     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
724
725     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
726     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
727     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
728     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
729
730     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
731     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
732     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
733     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
734
735     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
736     monitorSeekForward->setShortcut(Qt::Key_L);
737     collection->addAction("monitor_seek_forward", monitorSeekForward);
738     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
739
740     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
741     clipStart->setShortcut(Qt::Key_Home);
742     collection->addAction("seek_clip_start", clipStart);
743     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
744
745     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
746     clipEnd->setShortcut(Qt::Key_End);
747     collection->addAction("seek_clip_end", clipEnd);
748     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
749
750     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
751     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
752     collection->addAction("seek_start", projectStart);
753     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
754
755     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
756     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
757     collection->addAction("seek_end", projectEnd);
758     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
759
760     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
761     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
762     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
763     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
764
765     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
766     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
767     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
768     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
769
770     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
771     deleteTimelineClip->setShortcut(Qt::Key_Delete);
772     collection->addAction("delete_timeline_clip", deleteTimelineClip);
773     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
774
775     KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
776     collection->addAction("change_clip_speed", editTimelineClipSpeed);
777     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
778
779     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
780     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
781     collection->addAction("cut_timeline_clip", cutTimelineClip);
782     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
783
784     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
785     collection->addAction("add_clip_marker", addClipMarker);
786     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
787
788     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
789     collection->addAction("delete_clip_marker", deleteClipMarker);
790     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
791
792     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
793     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
794     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
795
796     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
797     collection->addAction("edit_clip_marker", editClipMarker);
798     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
799
800     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
801     collection->addAction("insert_space", insertSpace);
802     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
803
804     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
805     collection->addAction("delete_space", removeSpace);
806     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
807
808     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
809     collection->addAction("insert_track", insertTrack);
810     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
811
812     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
813     collection->addAction("delete_track", deleteTrack);
814     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
815
816     KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
817     collection->addAction("change_track", changeTrack);
818     connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
819
820     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
821     collection->addAction("add_guide", addGuide);
822     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
823
824     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
825     collection->addAction("delete_guide", delGuide);
826     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
827
828     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
829     collection->addAction("edit_guide", editGuide);
830     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
831
832     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
833     collection->addAction("delete_all_guides", delAllGuides);
834     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
835
836     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
837     collection->addAction("paste_effects", pasteEffects);
838     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
839
840     m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
841
842     KStandardAction::quit(this, SLOT(queryQuit()), collection);
843
844     KStandardAction::open(this, SLOT(openFile()), collection);
845
846     m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
847
848     KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
849
850     KStandardAction::openNew(this, SLOT(newFile()), collection);
851
852     KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
853
854     KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
855
856     KStandardAction::copy(this, SLOT(slotCopy()), collection);
857
858     KStandardAction::paste(this, SLOT(slotPaste()), collection);
859
860     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
861     undo->setEnabled(false);
862     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
863
864     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
865     redo->setEnabled(false);
866     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
867
868     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
869
870     connect(collection, SIGNAL(actionHovered(QAction*)),
871             this, SLOT(slotDisplayActionMessage(QAction*)));
872     //connect(collection, SIGNAL( clearStatusText() ),
873     //statusBar(), SLOT( clear() ) );
874 }
875
876 void MainWindow::slotDisplayActionMessage(QAction *a) {
877     statusBar()->showMessage(a->data().toString(), 3000);
878 }
879
880 void MainWindow::saveOptions() {
881     KdenliveSettings::self()->writeConfig();
882     KSharedConfigPtr config = KGlobal::config();
883     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
884     KConfigGroup treecolumns(config, "Project Tree");
885     treecolumns.writeEntry("columns", m_projectList->headerInfo());
886     config->sync();
887 }
888
889 void MainWindow::readOptions() {
890     KSharedConfigPtr config = KGlobal::config();
891     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
892     KConfigGroup initialGroup(config, "version");
893     if (!initialGroup.exists()) {
894         // this is our first run, show Wizard
895         Wizard *w = new Wizard(this);
896         if (w->exec() == QDialog::Accepted && w->isOk()) {
897             w->adjustSettings();
898             initialGroup.writeEntry("version", "0.7");
899             delete w;
900         } else {
901             ::exit(1);
902         }
903     } else if (initialGroup.readEntry("version") == "0.7") {
904         //Add new settings from 0.7.1
905         if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
906             QString path = QDir::homePath() + "/kdenlive";
907             if (KStandardDirs::makeDir(path)  == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
908             KdenliveSettings::setDefaultprojectfolder(path);
909         }
910     }
911     KConfigGroup treecolumns(config, "Project Tree");
912     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
913     if (!state.isEmpty())
914         m_projectList->setHeaderInfo(state);
915 }
916
917 void MainWindow::newFile(bool showProjectSettings) {
918     QString profileName;
919     KUrl projectFolder;
920     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
921     if (!showProjectSettings && m_timelineArea->count() == 0) {
922         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
923         profileName = KdenliveSettings::default_profile();
924     } else {
925         ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
926         if (w->exec() != QDialog::Accepted) return;
927         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
928         profileName = w->selectedProfile();
929         projectFolder = w->selectedFolder();
930         projectTracks = w->tracks();
931         delete w;
932     }
933     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks,  this);
934     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
935     TrackView *trackView = new TrackView(doc, this);
936     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
937     if (m_timelineArea->count() == 1) {
938         connectDocumentInfo(doc);
939         connectDocument(trackView, doc);
940     } else m_timelineArea->setTabBarHidden(false);
941     m_closeAction->setEnabled(m_timelineArea->count() > 1);
942 }
943
944 void MainWindow::activateDocument() {
945     if (m_timelineArea->currentWidget() == NULL) return;
946     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
947     KdenliveDoc *currentDoc = currentTab->document();
948     connectDocumentInfo(currentDoc);
949     connectDocument(currentTab, currentDoc);
950 }
951
952 void MainWindow::closeCurrentDocument() {
953     QWidget *w = m_timelineArea->currentWidget();
954     if (!w) return;
955     // closing current document
956     int ix = m_timelineArea->currentIndex() + 1;
957     if (ix == m_timelineArea->count()) ix = 0;
958     m_timelineArea->setCurrentIndex(ix);
959     TrackView *tabToClose = (TrackView *) w;
960     KdenliveDoc *docToClose = tabToClose->document();
961     if (docToClose && docToClose->isModified()) {
962         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
963         case KMessageBox::Yes :
964             // save document here. If saving fails, return false;
965             saveFile();
966             break;
967         case KMessageBox::Cancel :
968             return;
969         default:
970             break;
971         }
972     }
973     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
974     if (m_timelineArea->count() == 1) {
975         m_timelineArea->setTabBarHidden(true);
976         m_closeAction->setEnabled(false);
977     }
978     delete docToClose;
979     delete w;
980     if (m_timelineArea->count() == 0) {
981         m_activeDocument = NULL;
982         effectStack->clear();
983         transitionConfig->slotTransitionItemSelected(NULL, false);
984     }
985 }
986
987 bool MainWindow::saveFileAs(const QString &outputFileName) {
988     QDomDocument currentSceneList = m_projectMonitor->sceneList();
989     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
990         return false;
991     m_activeDocument->setUrl(KUrl(outputFileName));
992     if (m_activeDocument->m_autosave == NULL) {
993         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
994     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
995     setCaption(m_activeDocument->description());
996     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
997     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
998     m_activeDocument->setModified(false);
999     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1000     return true;
1001 }
1002
1003 bool MainWindow::saveFileAs() {
1004     // Check that the Kdenlive mime type is correctly installed
1005     QString mimetype = "application/x-kdenlive";
1006     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1007     if (!mime) mimetype = "*.kdenlive";
1008
1009     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1010     if (outputFile.isEmpty()) return false;
1011     if (QFile::exists(outputFile)) {
1012         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
1013     }
1014     return saveFileAs(outputFile);
1015 }
1016
1017 bool MainWindow::saveFile() {
1018     if (!m_activeDocument) return true;
1019     if (m_activeDocument->url().isEmpty()) {
1020         return saveFileAs();
1021     } else {
1022         bool result = saveFileAs(m_activeDocument->url().path());
1023         m_activeDocument->m_autosave->resize(0);
1024         return result;
1025     }
1026 }
1027
1028 void MainWindow::openFile() {
1029     // Check that the Kdenlive mime type is correctly installed
1030     QString mimetype = "application/x-kdenlive";
1031     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1032     if (!mime) mimetype = "*.kdenlive";
1033
1034     KUrl url = KFileDialog::getOpenUrl(KUrl(), mimetype);
1035     if (url.isEmpty()) return;
1036     m_fileOpenRecent->addUrl(url);
1037     openFile(url);
1038 }
1039
1040 void MainWindow::openLastFile() {
1041     KSharedConfigPtr config = KGlobal::config();
1042     KUrl::List urls = m_fileOpenRecent->urls();
1043     if (urls.isEmpty()) newFile(false);
1044     else openFile(urls.last());
1045 }
1046
1047 void MainWindow::openFile(const KUrl &url) {
1048     // Check if the document is already opened
1049     const int ct = m_timelineArea->count();
1050     bool isOpened = false;
1051     int i;
1052     for (i = 0; i < ct; i++) {
1053         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1054         KdenliveDoc *doc = tab->document();
1055         if (doc->url() == url) {
1056             isOpened = true;
1057             break;
1058         }
1059     }
1060     if (isOpened) {
1061         m_timelineArea->setCurrentIndex(i);
1062         return;
1063     }
1064
1065     // Check for backup file
1066     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1067     if (!staleFiles.isEmpty()) {
1068         if (KMessageBox::questionYesNo(this,
1069                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1070                                        i18n("File Recovery"),
1071                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1072             recoverFiles(staleFiles);
1073             return;
1074         } else {
1075             // remove the stale files
1076             foreach(KAutoSaveFile *stale, staleFiles) {
1077                 stale->open(QIODevice::ReadWrite);
1078                 delete stale;
1079             }
1080         }
1081     }
1082     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1083     doOpenFile(url, NULL);
1084 }
1085
1086 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1087     KdenliveDoc *doc;
1088     doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
1089     if (stale == NULL) {
1090         stale = new KAutoSaveFile(url, doc);
1091         doc->m_autosave = stale;
1092     } else {
1093         doc->m_autosave = stale;
1094         doc->setUrl(stale->managedFile());
1095         doc->setModified(true);
1096         stale->setParent(doc);
1097     }
1098     connectDocumentInfo(doc);
1099     TrackView *trackView = new TrackView(doc, this);
1100     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1101     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1102     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1103     slotGotProgressInfo(QString(), -1);
1104     m_clipMonitor->refreshMonitor(true);
1105 }
1106
1107 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1108     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1109     foreach(KAutoSaveFile *stale, staleFiles) {
1110         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1111                   // show an error message; we could not steal the lockfile
1112                   // maybe another application got to the file before us?
1113                   delete stale;
1114                   continue;
1115         }*/
1116         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1117         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1118         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1119         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1120     }
1121 }
1122
1123
1124 void MainWindow::parseProfiles(const QString &mltPath) {
1125     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1126
1127     //KdenliveSettings::setDefaulttmpfolder();
1128     if (!mltPath.isEmpty()) {
1129         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1130         KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1131     }
1132
1133     if (KdenliveSettings::mltpath().isEmpty()) {
1134         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1135     }
1136     if (KdenliveSettings::rendererpath().isEmpty()) {
1137         QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1138         if (!QFile::exists(inigoPath))
1139             inigoPath = KStandardDirs::findExe("inigo");
1140         else KdenliveSettings::setRendererpath(inigoPath);
1141     }
1142     QStringList profilesFilter;
1143     profilesFilter << "*";
1144     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1145
1146     if (profilesList.isEmpty()) {
1147         // Cannot find MLT path, try finding inigo
1148         QString profilePath = KdenliveSettings::rendererpath();
1149         if (!profilePath.isEmpty()) {
1150             profilePath = profilePath.section('/', 0, -3);
1151             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1152             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1153         }
1154
1155         if (profilesList.isEmpty()) {
1156             // Cannot find the MLT profiles, ask for location
1157             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1158             getUrl->fileDialog()->setMode(KFile::Directory);
1159             if (getUrl->exec() == QDialog::Rejected) {
1160                 ::exit(0);
1161             }
1162             KUrl mltPath = getUrl->selectedUrl();
1163             delete getUrl;
1164             if (mltPath.isEmpty()) ::exit(0);
1165             KdenliveSettings::setMltpath(mltPath.path());
1166             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1167         }
1168     }
1169
1170     if (KdenliveSettings::rendererpath().isEmpty()) {
1171         // Cannot find the MLT inigo renderer, ask for location
1172         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1173         if (getUrl->exec() == QDialog::Rejected) {
1174             ::exit(0);
1175         }
1176         KUrl rendererPath = getUrl->selectedUrl();
1177         delete getUrl;
1178         if (rendererPath.isEmpty()) ::exit(0);
1179         KdenliveSettings::setRendererpath(rendererPath.path());
1180     }
1181
1182     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1183
1184     // Parse MLT profiles to build a list of available video formats
1185     if (profilesList.isEmpty()) parseProfiles();
1186 }
1187
1188
1189 void MainWindow::slotEditProfiles() {
1190     ProfilesDialog *w = new ProfilesDialog;
1191     w->exec();
1192     delete w;
1193 }
1194
1195 void MainWindow::slotEditProjectSettings() {
1196     QPoint p = m_activeDocument->getTracksCount();
1197     ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1198
1199     if (w->exec() == QDialog::Accepted) {
1200         QString profile = w->selectedProfile();
1201         m_activeDocument->setProfilePath(profile);
1202         KdenliveSettings::setCurrent_profile(profile);
1203         KdenliveSettings::setProject_fps(m_activeDocument->fps());
1204         setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1205         m_monitorManager->resetProfiles(m_activeDocument->timecode());
1206         if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1207         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1208
1209         // We need to desactivate & reactivate monitors to get a refresh
1210         m_monitorManager->switchMonitors();
1211     }
1212     delete w;
1213 }
1214
1215 void MainWindow::slotRenderProject() {
1216     if (!m_renderWidget) {
1217         m_renderWidget = new RenderWidget(this);
1218         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)));
1219         if (m_activeDocument) {
1220             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1221             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1222         }
1223     }
1224     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1225     if (currentTab) m_renderWidget->setTimeline(currentTab);
1226     m_renderWidget->setDocument(m_activeDocument);*/
1227     m_renderWidget->show();
1228 }
1229
1230 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &overlay_args, const QStringList &avformat_args, bool zoneOnly, bool playAfter, double guideStart, double guideEnd) {
1231     if (dest.isEmpty()) return;
1232     int in;
1233     int out;
1234     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1235     if (currentTab && zoneOnly) {
1236         in = currentTab->inPoint();
1237         out = currentTab->outPoint();
1238     }
1239     KTemporaryFile temp;
1240     temp.setAutoRemove(false);
1241     temp.setSuffix(".westley");
1242     if (temp.open()) {
1243         m_projectMonitor->saveSceneList(temp.fileName());
1244         QStringList args;
1245         args << "-erase";
1246         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1247         else if (guideStart != -1) {
1248             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1249         }
1250         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1251         QString videoPlayer = "-";
1252         if (playAfter) {
1253             videoPlayer = KdenliveSettings::defaultplayerapp();
1254             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."));
1255         }
1256         if (!QFile::exists(KdenliveSettings::rendererpath())) {
1257             KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1258             return;
1259         }
1260         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1261         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1262         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1263         QProcess::startDetached(renderer, args);
1264
1265         KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1266     }
1267 }
1268
1269 void MainWindow::slotUpdateMousePosition(int pos) {
1270     if (m_activeDocument)
1271         switch (m_timecodeFormat->currentIndex()) {
1272         case 0:
1273             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1274             break;
1275         default:
1276             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1277         }
1278 }
1279
1280 void MainWindow::slotUpdateDocumentState(bool modified) {
1281     setCaption(m_activeDocument->description(), modified);
1282     m_saveAction->setEnabled(modified);
1283     if (modified) {
1284         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1285         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1286     } else {
1287         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1288         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1289     }
1290 }
1291
1292 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1293     if (m_activeDocument) {
1294         if (m_activeDocument == doc) return;
1295         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1296     }
1297     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1298 }
1299
1300 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1301     //m_projectMonitor->stop();
1302     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1303     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1304     if (m_activeDocument) {
1305         if (m_activeDocument == doc) return;
1306         m_activeDocument->backupMltPlaylist();
1307         if (m_activeTimeline) {
1308             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1309             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1310             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1311             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1312
1313
1314             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1315             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1316             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1317             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1318             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1319             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1320             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1321             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1322             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1323             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1324             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1325             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1326             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1327             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1328             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1329             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1330             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1331             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1332             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1333             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1334             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1335             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1336             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1337             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1338             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1339             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1340             disconnect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), m_activeTimeline->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1341             disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1342             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1343             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1344             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1345             effectStack->clear();
1346         }
1347         m_activeDocument->setRenderer(NULL);
1348         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1349         m_clipMonitor->stop();
1350     }
1351     KdenliveSettings::setCurrent_profile(doc->profilePath());
1352     KdenliveSettings::setProject_fps(doc->fps());
1353     m_monitorManager->resetProfiles(doc->timecode());
1354     m_projectList->setDocument(doc);
1355     transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1356     effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1357     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1358     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1359     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1360     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1361     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1362     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1363     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1364     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1365     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1366     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1367     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1368     connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1369     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1370     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1371     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1372
1373     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1374     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1375     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1376
1377
1378     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1379     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1380     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1381     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1382     m_zoomSlider->setValue(doc->zoom());
1383     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1384     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1385     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1386     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1387
1388     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1389
1390
1391     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1392     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1393     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1394     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1395     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1396     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1397     connect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), trackView->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1398     connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1399     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1400
1401     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1402     connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1403     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1404
1405     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1406     m_activeTimeline = trackView;
1407     if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
1408     doc->setRenderer(m_projectMonitor->render);
1409     m_commandStack->setActiveStack(doc->commandStack());
1410     KdenliveSettings::setProject_display_ratio(doc->dar());
1411     m_projectList->updateAllClips();
1412     //doc->clipManager()->checkAudioThumbs();
1413
1414     //m_overView->setScene(trackView->projectScene());
1415     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1416     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1417
1418     setCaption(doc->description(), doc->isModified());
1419     m_saveAction->setEnabled(doc->isModified());
1420     m_activeDocument = doc;
1421 }
1422
1423 void MainWindow::slotGuidesUpdated() {
1424     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1425 }
1426
1427 void MainWindow::slotPreferences(int page, int option) {
1428     //An instance of your dialog could be already created and could be
1429     // cached, in which case you want to display the cached dialog
1430     // instead of creating another one
1431     if (KConfigDialog::showDialog("settings")) {
1432         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1433         if (page != -1) d->showPage(page, option);
1434         d->checkProfile();
1435         return;
1436     }
1437
1438     // KConfigDialog didn't find an instance of this dialog, so lets
1439     // create it :
1440     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1441     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1442     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1443     dialog->show();
1444     if (page != -1) dialog->showPage(page, option);
1445 }
1446
1447 void MainWindow::updateConfiguration() {
1448     //TODO: we should apply settings to all projects, not only the current one
1449     if (m_activeTimeline) {
1450         m_activeTimeline->refresh();
1451         m_activeTimeline->projectView()->checkAutoScroll();
1452         m_activeTimeline->projectView()->checkTrackHeight();
1453         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1454     }
1455     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1456     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1457 #ifndef NO_JOGSHUTTLE
1458     activateShuttleDevice();
1459 #endif /* NO_JOGSHUTTLE */
1460
1461 }
1462
1463 void MainWindow::slotSwitchVideoThumbs() {
1464     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1465     if (m_activeTimeline) {
1466         m_activeTimeline->refresh();
1467     }
1468     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1469 }
1470
1471 void MainWindow::slotSwitchAudioThumbs() {
1472     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1473     if (m_activeTimeline) {
1474         m_activeTimeline->refresh();
1475         m_activeTimeline->projectView()->checkAutoScroll();
1476         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1477     }
1478     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1479 }
1480
1481 void MainWindow::slotSwitchMarkersComments() {
1482     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1483     if (m_activeTimeline) {
1484         m_activeTimeline->refresh();
1485     }
1486     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1487 }
1488
1489 void MainWindow::slotSwitchSnap() {
1490     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1491     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1492 }
1493
1494
1495 void MainWindow::slotDeleteTimelineClip() {
1496     if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1497     else if (m_activeTimeline) {
1498         m_activeTimeline->projectView()->deleteSelectedClips();
1499     }
1500 }
1501
1502 void MainWindow::slotChangeClipSpeed() {
1503     if (m_activeTimeline) {
1504         m_activeTimeline->projectView()->changeClipSpeed();
1505     }
1506 }
1507
1508 void MainWindow::slotAddClipMarker() {
1509     DocClipBase *clip = NULL;
1510     GenTime pos;
1511     if (m_projectMonitor->isActive()) {
1512         if (m_activeTimeline) {
1513             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1514             if (item) {
1515                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1516                 clip = item->baseClip();
1517             }
1518         }
1519     } else {
1520         clip = m_clipMonitor->activeClip();
1521         pos = m_clipMonitor->position();
1522     }
1523     if (!clip) {
1524         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1525         return;
1526     }
1527     QString id = clip->getId();
1528     CommentedTime marker(pos, i18n("Marker"));
1529     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1530     if (d.exec() == QDialog::Accepted) {
1531         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1532     }
1533     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1534 }
1535
1536 void MainWindow::slotDeleteClipMarker() {
1537     DocClipBase *clip = NULL;
1538     GenTime pos;
1539     if (m_projectMonitor->isActive()) {
1540         if (m_activeTimeline) {
1541             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1542             if (item) {
1543                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1544                 clip = item->baseClip();
1545             }
1546         }
1547     } else {
1548         clip = m_clipMonitor->activeClip();
1549         pos = m_clipMonitor->position();
1550     }
1551     if (!clip) {
1552         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1553         return;
1554     }
1555
1556     QString id = clip->getId();
1557     QString comment = clip->markerComment(pos);
1558     if (comment.isEmpty()) {
1559         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1560         return;
1561     }
1562     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
1563     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1564
1565 }
1566
1567 void MainWindow::slotDeleteAllClipMarkers() {
1568     DocClipBase *clip = NULL;
1569     if (m_projectMonitor->isActive()) {
1570         if (m_activeTimeline) {
1571             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1572             if (item) {
1573                 clip = item->baseClip();
1574             }
1575         }
1576     } else {
1577         clip = m_clipMonitor->activeClip();
1578     }
1579     if (!clip) {
1580         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1581         return;
1582     }
1583     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
1584     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1585 }
1586
1587 void MainWindow::slotEditClipMarker() {
1588     DocClipBase *clip = NULL;
1589     GenTime pos;
1590     if (m_projectMonitor->isActive()) {
1591         if (m_activeTimeline) {
1592             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1593             if (item) {
1594                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1595                 clip = item->baseClip();
1596             }
1597         }
1598     } else {
1599         clip = m_clipMonitor->activeClip();
1600         pos = m_clipMonitor->position();
1601     }
1602     if (!clip) {
1603         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1604         return;
1605     }
1606
1607     QString id = clip->getId();
1608     QString oldcomment = clip->markerComment(pos);
1609     if (oldcomment.isEmpty()) {
1610         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1611         return;
1612     }
1613
1614     CommentedTime marker(pos, oldcomment);
1615     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
1616     if (d.exec() == QDialog::Accepted) {
1617         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1618         if (d.newMarker().time() != pos) {
1619             // remove old marker
1620             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
1621         }
1622         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1623     }
1624 }
1625
1626 void MainWindow::slotAddGuide() {
1627     if (m_activeTimeline)
1628         m_activeTimeline->projectView()->slotAddGuide();
1629 }
1630
1631 void MainWindow::slotInsertSpace() {
1632     if (m_activeTimeline)
1633         m_activeTimeline->projectView()->slotInsertSpace();
1634 }
1635
1636 void MainWindow::slotRemoveSpace() {
1637     if (m_activeTimeline)
1638         m_activeTimeline->projectView()->slotRemoveSpace();
1639 }
1640
1641 void MainWindow::slotInsertTrack(int ix) {
1642     m_projectMonitor->activateMonitor();
1643     if (m_activeTimeline)
1644         m_activeTimeline->projectView()->slotInsertTrack(ix);
1645 }
1646
1647 void MainWindow::slotDeleteTrack(int ix) {
1648     m_projectMonitor->activateMonitor();
1649     if (m_activeTimeline)
1650         m_activeTimeline->projectView()->slotDeleteTrack(ix);
1651 }
1652
1653 void MainWindow::slotChangeTrack(int ix) {
1654     m_projectMonitor->activateMonitor();
1655     if (m_activeTimeline)
1656         m_activeTimeline->projectView()->slotChangeTrack(ix);
1657 }
1658
1659 void MainWindow::slotEditGuide() {
1660     if (m_activeTimeline)
1661         m_activeTimeline->projectView()->slotEditGuide();
1662 }
1663
1664 void MainWindow::slotDeleteGuide() {
1665     if (m_activeTimeline)
1666         m_activeTimeline->projectView()->slotDeleteGuide();
1667 }
1668
1669 void MainWindow::slotDeleteAllGuides() {
1670     if (m_activeTimeline)
1671         m_activeTimeline->projectView()->slotDeleteAllGuides();
1672 }
1673
1674 void MainWindow::slotCutTimelineClip() {
1675     if (m_activeTimeline) {
1676         m_activeTimeline->projectView()->cutSelectedClips();
1677     }
1678 }
1679
1680 void MainWindow::slotAddProjectClip(KUrl url) {
1681     if (m_activeDocument)
1682         m_activeDocument->slotAddClipFile(url, QString());
1683 }
1684
1685 void MainWindow::slotAddTransition(QAction *result) {
1686     if (!result) return;
1687     QStringList info = result->data().toStringList();
1688     if (info.isEmpty()) return;
1689     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
1690     if (m_activeTimeline && !transition.isNull()) {
1691         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
1692     }
1693 }
1694
1695 void MainWindow::slotAddVideoEffect(QAction *result) {
1696     if (!result) return;
1697     QStringList info = result->data().toStringList();
1698     if (info.isEmpty()) return;
1699     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
1700     slotAddEffect(effect);
1701 }
1702
1703 void MainWindow::slotAddAudioEffect(QAction *result) {
1704     if (!result) return;
1705     QStringList info = result->data().toStringList();
1706     if (info.isEmpty()) return;
1707     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
1708     slotAddEffect(effect);
1709 }
1710
1711 void MainWindow::slotAddCustomEffect(QAction *result) {
1712     if (!result) return;
1713     QStringList info = result->data().toStringList();
1714     if (info.isEmpty()) return;
1715     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
1716     slotAddEffect(effect);
1717 }
1718
1719 void MainWindow::slotZoomIn() {
1720     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1721 }
1722
1723 void MainWindow::slotZoomOut() {
1724     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1725 }
1726
1727 void MainWindow::slotFitZoom() {
1728     if (m_activeTimeline) {
1729         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1730     }
1731 }
1732
1733 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1734     statusProgressBar->setValue(progress);
1735     if (progress >= 0) {
1736         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1737         statusProgressBar->setVisible(true);
1738     } else {
1739         m_messageLabel->setMessage(QString(), DefaultMessage);
1740         statusProgressBar->setVisible(false);
1741     }
1742 }
1743
1744 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1745     if (clip->clipType() == TEXT) {
1746         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1747         QString path = clip->getProperty("resource");
1748         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1749         QDomDocument doc;
1750         doc.setContent(clip->getProperty("xmldata"));
1751         dia_ui->setXml(doc);
1752         if (dia_ui->exec() == QDialog::Accepted) {
1753             QPixmap pix = dia_ui->renderedPixmap();
1754             pix.save(path);
1755             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1756             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1757             QMap <QString, QString> newprops;
1758             newprops.insert("xmldata", dia_ui->xml().toString());
1759             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1760             m_activeDocument->commandStack()->push(command);
1761             m_clipMonitor->refreshMonitor(true);
1762             m_activeDocument->setModified(true);
1763         }
1764         delete dia_ui;
1765
1766         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1767         return;
1768     }
1769     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1770     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1771     if (dia.exec() == QDialog::Accepted) {
1772         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1773         m_activeDocument->commandStack()->push(command);
1774
1775         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1776         if (dia.needsTimelineRefresh()) {
1777             // update clip occurences in timeline
1778             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1779         }
1780     }
1781 }
1782
1783 void MainWindow::customEvent(QEvent* e) {
1784     if (e->type() == QEvent::User) {
1785         // The timeline playing position changed...
1786         kDebug() << "RECIEVED JOG EVEMNT!!!";
1787     }
1788 }
1789 void MainWindow::slotActivateEffectStackView() {
1790     effectStack->raiseWindow(effectStackDock);
1791 }
1792
1793 void MainWindow::slotActivateTransitionView() {
1794     transitionConfig->raiseWindow(transitionConfigDock);
1795 }
1796
1797 void MainWindow::slotSnapRewind() {
1798     if (m_projectMonitor->isActive()) {
1799         if (m_activeTimeline)
1800             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1801     } else m_clipMonitor->slotSeekToPreviousSnap();
1802 }
1803
1804 void MainWindow::slotSnapForward() {
1805     if (m_projectMonitor->isActive()) {
1806         if (m_activeTimeline)
1807             m_activeTimeline->projectView()->slotSeekToNextSnap();
1808     } else m_clipMonitor->slotSeekToNextSnap();
1809 }
1810
1811 void MainWindow::slotClipStart() {
1812     if (m_projectMonitor->isActive()) {
1813         if (m_activeTimeline)
1814             m_activeTimeline->projectView()->clipStart();
1815     }
1816 }
1817
1818 void MainWindow::slotClipEnd() {
1819     if (m_projectMonitor->isActive()) {
1820         if (m_activeTimeline)
1821             m_activeTimeline->projectView()->clipEnd();
1822     }
1823 }
1824
1825 void MainWindow::slotChangeTool(QAction * action) {
1826     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1827     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1828     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
1829 }
1830
1831 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1832     if (m_activeDocument && m_activeTimeline) {
1833         //m_activeDocument->setTool(tool);
1834         m_activeTimeline->projectView()->setTool(tool);
1835     }
1836 }
1837
1838 void MainWindow::slotCopy() {
1839     if (!m_activeDocument || !m_activeTimeline) return;
1840     m_activeTimeline->projectView()->copyClip();
1841 }
1842
1843 void MainWindow::slotPaste() {
1844     if (!m_activeDocument || !m_activeTimeline) return;
1845     m_activeTimeline->projectView()->pasteClip();
1846 }
1847
1848 void MainWindow::slotPasteEffects() {
1849     if (!m_activeDocument || !m_activeTimeline) return;
1850     m_activeTimeline->projectView()->pasteClipEffects();
1851 }
1852
1853 void MainWindow::slotFind() {
1854     if (!m_activeDocument || !m_activeTimeline) return;
1855     m_projectSearch->setEnabled(false);
1856     m_findActivated = true;
1857     m_findString = QString();
1858     m_activeTimeline->projectView()->initSearchStrings();
1859     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1860     m_findTimer.start(5000);
1861     qApp->installEventFilter(this);
1862 }
1863
1864 void MainWindow::slotFindNext() {
1865     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1866         statusBar()->showMessage(i18n("Found : %1", m_findString));
1867     } else {
1868         statusBar()->showMessage(i18n("Reached end of project"));
1869     }
1870     m_findTimer.start(4000);
1871 }
1872
1873 void MainWindow::findAhead() {
1874     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1875         m_projectSearchNext->setEnabled(true);
1876         statusBar()->showMessage(i18n("Found : %1", m_findString));
1877     } else {
1878         m_projectSearchNext->setEnabled(false);
1879         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1880     }
1881 }
1882
1883 void MainWindow::findTimeout() {
1884     m_projectSearchNext->setEnabled(false);
1885     m_findActivated = false;
1886     m_findString = QString();
1887     statusBar()->showMessage(i18n("Find stopped"), 3000);
1888     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1889     m_projectSearch->setEnabled(true);
1890     removeEventFilter(this);
1891 }
1892
1893 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1894     if (m_findActivated) {
1895         if (ke->key() == Qt::Key_Backspace) {
1896             m_findString = m_findString.left(m_findString.length() - 1);
1897
1898             if (!m_findString.isEmpty()) {
1899                 findAhead();
1900             } else {
1901                 findTimeout();
1902             }
1903
1904             m_findTimer.start(4000);
1905             ke->accept();
1906             return;
1907         } else if (ke->key() == Qt::Key_Escape) {
1908             findTimeout();
1909             ke->accept();
1910             return;
1911         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1912             m_findString += ke->text();
1913
1914             findAhead();
1915
1916             m_findTimer.start(4000);
1917             ke->accept();
1918             return;
1919         }
1920     } else KXmlGuiWindow::keyPressEvent(ke);
1921 }
1922
1923
1924 /** Gets called when the window gets hidden */
1925 void MainWindow::hideEvent(QHideEvent *event) {
1926     // kDebug() << "I was hidden";
1927     // issue http://www.kdenlive.org/mantis/view.php?id=231
1928     if (this->isMinimized()) {
1929         // kDebug() << "I am minimized";
1930         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
1931     }
1932 }
1933
1934 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1935     if (m_findActivated) {
1936         if (event->type() == QEvent::ShortcutOverride) {
1937             QKeyEvent* ke = (QKeyEvent*) event;
1938             if (ke->text().trimmed().isEmpty()) return false;
1939             ke->accept();
1940             return true;
1941         } else return false;
1942     } else {
1943         // pass the event on to the parent class
1944         return QMainWindow::eventFilter(obj, event);
1945     }
1946 }
1947
1948 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1949     KDialog *dialog = new KDialog(this);
1950     dialog->setCaption("Save clip zone");
1951     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1952
1953     QWidget *widget = new QWidget(dialog);
1954     dialog->setMainWidget(widget);
1955
1956     QVBoxLayout *vbox = new QVBoxLayout(widget);
1957     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1958     QString path = m_activeDocument->projectFolder().path();
1959     path.append("/");
1960     path.append("untitled.westley");
1961     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1962     url->setFilter("video/mlt-playlist");
1963     QLabel *label2 = new QLabel(i18n("Description:"), this);
1964     KLineEdit *edit = new KLineEdit(this);
1965     vbox->addWidget(label1);
1966     vbox->addWidget(url);
1967     vbox->addWidget(label2);
1968     vbox->addWidget(edit);
1969     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1970
1971 }
1972
1973 void MainWindow::slotSetInPoint() {
1974     if (m_clipMonitor->isActive()) {
1975         m_clipMonitor->slotSetZoneStart();
1976     } else m_activeTimeline->projectView()->setInPoint();
1977 }
1978
1979 void MainWindow::slotSetOutPoint() {
1980     if (m_clipMonitor->isActive()) {
1981         m_clipMonitor->slotSetZoneEnd();
1982     } else m_activeTimeline->projectView()->setOutPoint();
1983 }
1984
1985
1986 #include "mainwindow.moc"