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