1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
22 #include <QTextStream>
28 #include <KApplication>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 #include <KFileDialog>
35 #include <KMessageBox>
37 #include <KIO/NetAccess>
40 #include <KConfigDialog>
41 #include <KXMLGUIFactory>
43 #include <kstandarddirs.h>
44 #include <KUrlRequesterDialog>
45 #include <KTemporaryFile>
46 #include <KActionMenu>
49 #include <ktogglefullscreenaction.h>
51 #include <mlt++/Mlt.h>
53 #include "mainwindow.h"
54 #include "kdenlivesettings.h"
55 #include "kdenlivesettingsdialog.h"
56 #include "initeffects.h"
57 #include "profilesdialog.h"
58 #include "projectsettings.h"
60 #include "renderjob.h"
61 #include "clipmanager.h"
62 #include "projectlist.h"
64 #include "recmonitor.h"
65 #include "monitormanager.h"
66 #include "kdenlivedoc.h"
67 #include "trackview.h"
68 #include "customtrackview.h"
69 #include "effectslistview.h"
70 #include "effectstackview.h"
71 #include "transitionsettings.h"
72 #include "renderwidget.h"
74 #include "jogshuttle.h"
75 #include "clipproperties.h"
77 #define ID_STATUS_MSG 1
78 #define ID_EDITMODE_MSG 2
79 #define ID_TIMELINE_MSG 3
80 #define ID_TIMELINE_BUTTONS 5
81 #define ID_TIMELINE_POS 6
82 #define ID_TIMELINE_FORMAT 7
84 MainWindow::MainWindow(QWidget *parent)
85 : KXmlGuiWindow(parent),
86 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL) {
87 setlocale(LC_NUMERIC, "POSIX");
89 setFont(KGlobalSettings::toolBarFont());
90 m_commandStack = new QUndoGroup;
91 m_timelineArea = new KTabWidget(this);
92 m_timelineArea->setTabReorderingEnabled(true);
93 m_timelineArea->setTabBarHidden(true);
95 QToolButton *closeTabButton = new QToolButton;
96 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
97 closeTabButton->setIcon(KIcon("tab-close"));
98 closeTabButton->adjustSize();
99 closeTabButton->setToolTip(i18n("Close the current tab"));
100 m_timelineArea->setCornerWidget(closeTabButton);
101 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
103 initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects, &m_transitions);
104 m_monitorManager = new MonitorManager();
106 projectListDock = new QDockWidget(i18n("Project Tree"), this);
107 projectListDock->setObjectName("project_tree");
108 m_projectList = new ProjectList(this);
109 projectListDock->setWidget(m_projectList);
110 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
112 effectListDock = new QDockWidget(i18n("Effect List"), this);
113 effectListDock->setObjectName("effect_list");
114 m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
116 //m_effectList = new KListWidget(this);
117 effectListDock->setWidget(m_effectList);
118 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
120 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
121 effectStackDock->setObjectName("effect_stack");
122 effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this);
123 effectStackDock->setWidget(effectStack);
124 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
126 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
127 transitionConfigDock->setObjectName("transition");
128 transitionConfig = new TransitionSettings(&m_transitions, this);
129 transitionConfigDock->setWidget(transitionConfig);
130 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
133 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
134 clipMonitorDock->setObjectName("clip_monitor");
135 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
136 clipMonitorDock->setWidget(m_clipMonitor);
137 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
138 //m_clipMonitor->stop();
140 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
141 projectMonitorDock->setObjectName("project_monitor");
142 m_projectMonitor = new Monitor("project", m_monitorManager, this);
143 projectMonitorDock->setWidget(m_projectMonitor);
144 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
146 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
147 recMonitorDock->setObjectName("record_monitor");
148 m_recMonitor = new RecMonitor("record", this);
149 recMonitorDock->setWidget(m_recMonitor);
150 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
152 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
154 undoViewDock = new QDockWidget(i18n("Undo History"), this);
155 undoViewDock->setObjectName("undo_history");
156 m_undoView = new QUndoView(this);
157 m_undoView->setCleanIcon(KIcon("edit-clear"));
158 m_undoView->setEmptyLabel(i18n("Clean"));
159 undoViewDock->setWidget(m_undoView);
160 m_undoView->setGroup(m_commandStack);
161 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
163 overviewDock = new QDockWidget(i18n("Project Overview"), this);
164 overviewDock->setObjectName("project_overview");
165 m_overView = new CustomTrackView(NULL, NULL, this);
166 overviewDock->setWidget(m_overView);
167 addDockWidget(Qt::TopDockWidgetArea, overviewDock);
170 tabifyDockWidget(projectListDock, effectListDock);
171 tabifyDockWidget(projectListDock, effectStackDock);
172 tabifyDockWidget(projectListDock, transitionConfigDock);
173 tabifyDockWidget(projectListDock, undoViewDock);
174 projectListDock->raise();
176 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
177 setCentralWidget(m_timelineArea);
179 m_timecodeFormat = new KComboBox(this);
180 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
181 m_timecodeFormat->addItem(i18n("Frames"));
183 statusProgressBar = new QProgressBar(this);
184 statusProgressBar->setMinimum(0);
185 statusProgressBar->setMaximum(100);
186 statusProgressBar->setMaximumWidth(150);
187 statusProgressBar->setVisible(false);
188 statusLabel = new QLabel(this);
190 QWidget *w = new QWidget;
191 timeline_buttons_ui.setupUi(w);
192 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
193 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
194 connect(timeline_buttons_ui.buttonVideo, SIGNAL(clicked()), this, SLOT(slotSwitchVideoThumbs()));
195 connect(timeline_buttons_ui.buttonAudio, SIGNAL(clicked()), this, SLOT(slotSwitchAudioThumbs()));
196 connect(timeline_buttons_ui.buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotFitZoom()));
198 statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
199 statusBar()->insertPermanentWidget(1, statusLabel, 1);
200 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
201 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
202 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
203 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
205 timeline_buttons_ui.buttonVideo->setIcon(KIcon("video-mpeg"));
206 timeline_buttons_ui.buttonVideo->setToolTip(i18n("Show video thumbnails"));
207 timeline_buttons_ui.buttonAudio->setIcon(KIcon("audio-mpeg"));
208 timeline_buttons_ui.buttonAudio->setToolTip(i18n("Show audio thumbnails"));
209 timeline_buttons_ui.buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
210 timeline_buttons_ui.buttonFitZoom->setToolTip(i18n("Fit zoom to project"));
212 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
213 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
215 // build effects menus
217 QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
218 QStringList effects = m_videoEffects.effectNames();
219 foreach(QString name, effects) {
220 action = new QAction(name, this);
221 action->setData(name);
222 videoEffectsMenu->addAction(action);
224 QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
225 effects = m_audioEffects.effectNames();
226 foreach(QString name, effects) {
227 action = new QAction(name, this);
228 action->setData(name);
229 audioEffectsMenu->addAction(action);
231 QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
232 effects = m_customEffects.effectNames();
233 foreach(QString name, effects) {
234 action = new QAction(name, this);
235 action->setData(name);
236 customEffectsMenu->addAction(action);
239 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
240 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
241 connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
243 m_timelineContextMenu = new QMenu(this);
244 m_timelineContextClipMenu = new QMenu(this);
245 m_timelineContextTransitionMenu = new QMenu(this);
247 action = actionCollection()->action("delete_timeline_clip");
248 m_timelineContextClipMenu->addAction(action);
249 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
250 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
251 m_timelineContextClipMenu->addMenu(customEffectsMenu);
253 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
254 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
255 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
256 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
257 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
258 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
259 slotConnectMonitors();
261 setAutoSaveSettings();
264 activateShuttleDevice();
267 void MainWindow::queryQuit() {
268 kDebug() << "----- SAVING CONFUIG";
269 if (queryClose()) kapp->quit();
273 bool MainWindow::queryClose() {
275 if (m_activeDocument && m_activeDocument->isModified()) {
276 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
277 case KMessageBox::Yes :
278 // save document here. If saving fails, return false;
280 case KMessageBox::No :
289 void MainWindow::activateShuttleDevice() {
290 if (m_jogProcess) delete m_jogProcess;
292 if (KdenliveSettings::enableshuttle() == false) return;
293 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
294 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
295 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
296 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
297 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
298 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
299 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
302 void MainWindow::slotShuttleButton(int code) {
305 slotShuttleAction(KdenliveSettings::shuttle1());
308 slotShuttleAction(KdenliveSettings::shuttle2());
311 slotShuttleAction(KdenliveSettings::shuttle3());
314 slotShuttleAction(KdenliveSettings::shuttle4());
317 slotShuttleAction(KdenliveSettings::shuttle5());
322 void MainWindow::slotShuttleAction(int code) {
327 m_monitorManager->slotPlay();
330 m_monitorManager->slotPlay();
335 void MainWindow::slotFullScreen() {
336 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
339 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
340 if (!m_activeDocument) return;
341 if (effect.isNull()) {
342 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
345 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
346 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
349 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
350 if (clipMonitor) clipMonitorDock->raise();
351 else projectMonitorDock->raise();
354 void MainWindow::slotSetClipDuration(int id, int duration) {
355 if (!m_activeDocument) return;
356 m_activeDocument->setProducerDuration(id, duration);
359 void MainWindow::slotConnectMonitors() {
361 m_projectList->setRenderer(m_clipMonitor->render);
362 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
363 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
364 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
365 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
366 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
367 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
370 void MainWindow::setupActions() {
371 KAction* clearAction = new KAction(this);
372 clearAction->setText(i18n("Clear"));
373 clearAction->setIcon(KIcon("document-new"));
374 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
375 actionCollection()->addAction("clear", clearAction);
376 /*connect(clearAction, SIGNAL(triggered(bool)),
377 textArea, SLOT(clear()));*/
379 KAction* profilesAction = new KAction(this);
380 profilesAction->setText(i18n("Manage Profiles"));
381 profilesAction->setIcon(KIcon("document-new"));
382 actionCollection()->addAction("manage_profiles", profilesAction);
383 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
385 KAction* projectAction = new KAction(this);
386 projectAction->setText(i18n("Project Settings"));
387 projectAction->setIcon(KIcon("document-new"));
388 actionCollection()->addAction("project_settings", projectAction);
389 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
391 KAction* projectRender = new KAction(this);
392 projectRender->setText(i18n("Render Project"));
393 projectRender->setIcon(KIcon("document-new"));
394 actionCollection()->addAction("project_render", projectRender);
395 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
397 KAction* monitorPlay = new KAction(this);
398 monitorPlay->setText(i18n("Play"));
399 monitorPlay->setIcon(KIcon("media-playback-start"));
400 monitorPlay->setShortcut(Qt::Key_Space);
401 actionCollection()->addAction("monitor_play", monitorPlay);
402 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
404 KAction* monitorSeekBackward = new KAction(this);
405 monitorSeekBackward->setText(i18n("Rewind"));
406 monitorSeekBackward->setIcon(KIcon("media-seek-backward"));
407 monitorSeekBackward->setShortcut(Qt::Key_J);
408 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
409 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
411 KAction* monitorSeekBackwardOneFrame = new KAction(this);
412 monitorSeekBackwardOneFrame->setText(i18n("Rewind 1 Frame"));
413 monitorSeekBackwardOneFrame->setIcon(KIcon("media-skip-backward"));
414 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
415 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
416 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
418 KAction* monitorSeekForward = new KAction(this);
419 monitorSeekForward->setText(i18n("Forward"));
420 monitorSeekForward->setIcon(KIcon("media-seek-forward"));
421 monitorSeekForward->setShortcut(Qt::Key_L);
422 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
423 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
425 KAction* monitorSeekForwardOneFrame = new KAction(this);
426 monitorSeekForwardOneFrame->setText(i18n("Forward 1 Frame"));
427 monitorSeekForwardOneFrame->setIcon(KIcon("media-skip-forward"));
428 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
429 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
430 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
432 KAction* deleteTimelineClip = new KAction(this);
433 deleteTimelineClip->setText(i18n("Delete Clip"));
434 deleteTimelineClip->setShortcut(Qt::Key_Delete);
435 deleteTimelineClip->setIcon(KIcon("edit-delete"));
436 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
437 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
439 KStandardAction::quit(this, SLOT(queryQuit()),
442 KStandardAction::open(this, SLOT(openFile()),
445 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
448 KStandardAction::save(this, SLOT(saveFile()),
451 KStandardAction::saveAs(this, SLOT(saveFileAs()),
454 KStandardAction::openNew(this, SLOT(newFile()),
457 KStandardAction::preferences(this, SLOT(slotPreferences()),
460 KStandardAction::undo(this, SLOT(undo()),
463 KStandardAction::redo(this, SLOT(redo()),
466 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
468 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
469 this, SLOT(slotDisplayActionMessage(QAction*)));
470 //connect(actionCollection(), SIGNAL( clearStatusText() ),
471 //statusBar(), SLOT( clear() ) );
476 void MainWindow::undo() {
477 m_commandStack->undo();
480 void MainWindow::redo() {
481 m_commandStack->redo();
484 void MainWindow::slotDisplayActionMessage(QAction *a) {
485 statusBar()->showMessage(a->data().toString(), 3000);
488 void MainWindow::saveOptions() {
489 KdenliveSettings::self()->writeConfig();
490 KSharedConfigPtr config = KGlobal::config();
491 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
495 void MainWindow::readOptions() {
496 KSharedConfigPtr config = KGlobal::config();
497 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
500 void MainWindow::newFile() {
502 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
504 ProjectSettings *w = new ProjectSettings;
506 profileName = w->selectedProfile();
509 MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
510 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
511 KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
512 TrackView *trackView = new TrackView(doc, this);
513 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
514 if (m_timelineArea->count() == 1)
515 connectDocument(trackView, doc);
516 else m_timelineArea->setTabBarHidden(false);
519 void MainWindow::activateDocument() {
520 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
521 KdenliveDoc *currentDoc = currentTab->document();
522 connectDocument(currentTab, currentDoc);
525 void MainWindow::slotRemoveTab() {
526 QWidget *w = m_timelineArea->currentWidget();
527 // closing current document
528 int ix = m_timelineArea->currentIndex() + 1;
529 if (ix == m_timelineArea->count()) ix = 0;
530 m_timelineArea->setCurrentIndex(ix);
531 TrackView *tabToClose = (TrackView *) w;
532 KdenliveDoc *docToClose = tabToClose->document();
533 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
534 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
539 void MainWindow::saveFileAs(const QString &outputFileName) {
540 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
541 m_activeDocument->setUrl(KUrl(outputFileName));
542 setCaption(m_activeDocument->description());
543 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
544 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
545 m_activeDocument->setModified(false);
548 void MainWindow::saveFileAs() {
549 QString outputFile = KFileDialog::getSaveFileName();
550 if (QFile::exists(outputFile)) {
551 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
553 saveFileAs(outputFile);
556 void MainWindow::saveFile() {
557 if (!m_activeDocument) return;
558 if (m_activeDocument->url().isEmpty()) {
561 saveFileAs(m_activeDocument->url().path());
565 void MainWindow::openFile() { //changed
566 KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
567 if (url.isEmpty()) return;
568 m_fileOpenRecent->addUrl(url);
572 void MainWindow::openFile(const KUrl &url) { //new
573 //TODO: get video profile from url before opening it
574 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
575 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
576 KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
577 TrackView *trackView = new TrackView(doc, this);
578 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
579 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
580 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
581 //connectDocument(trackView, doc);
585 void MainWindow::parseProfiles() {
586 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
587 if (KdenliveSettings::mltpath().isEmpty()) {
588 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
590 if (KdenliveSettings::rendererpath().isEmpty()) {
591 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
593 QStringList profilesFilter;
594 profilesFilter << "*";
595 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
597 if (profilesList.isEmpty()) {
598 // Cannot find MLT path, try finding inigo
599 QString profilePath = KdenliveSettings::rendererpath();
600 if (!profilePath.isEmpty()) {
601 profilePath = profilePath.section('/', 0, -3);
602 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
603 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
606 if (profilesList.isEmpty()) {
607 // Cannot find the MLT profiles, ask for location
608 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
609 getUrl->fileDialog()->setMode(KFile::Directory);
611 KUrl mltPath = getUrl->selectedUrl();
613 if (mltPath.isEmpty()) exit(1);
614 KdenliveSettings::setMltpath(mltPath.path());
615 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
619 if (KdenliveSettings::rendererpath().isEmpty()) {
620 // Cannot find the MLT inigo renderer, ask for location
621 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
623 KUrl rendererPath = getUrl->selectedUrl();
625 if (rendererPath.isEmpty()) exit(1);
626 KdenliveSettings::setRendererpath(rendererPath.path());
629 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
631 // Parse MLT profiles to build a list of available video formats
632 if (profilesList.isEmpty()) parseProfiles();
636 void MainWindow::slotEditProfiles() {
637 ProfilesDialog *w = new ProfilesDialog;
642 void MainWindow::slotEditProjectSettings() {
643 ProjectSettings *w = new ProjectSettings;
644 if (w->exec() == QDialog::Accepted) {
645 QString profile = w->selectedProfile();
646 m_activeDocument->setProfilePath(profile);
647 m_monitorManager->resetProfiles(profile);
648 setCaption(m_activeDocument->description());
649 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
650 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
651 m_monitorManager->setTimecode(m_activeDocument->timecode());
652 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
654 // We need to desactivate & reactivate monitors to get a refresh
655 m_monitorManager->switchMonitors();
660 void MainWindow::slotRenderProject() {
661 if (!m_renderWidget) {
662 m_renderWidget = new RenderWidget(this);
663 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
665 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
666 if (currentTab) m_renderWidget->setTimeline(currentTab);
667 m_renderWidget->setDocument(m_activeDocument);*/
668 m_renderWidget->show();
671 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
672 if (dest.isEmpty()) return;
675 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
676 if (currentTab && zoneOnly) {
677 in = currentTab->inPoint();
678 out = currentTab->outPoint();
681 temp.setAutoRemove(false);
682 temp.setSuffix(".westley");
684 m_projectMonitor->saveSceneList(temp.fileName());
687 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
688 QString videoPlayer = "-";
689 if (playAfter) videoPlayer = "kmplayer";
690 args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
691 QProcess::startDetached("kdenlive_render", args);
695 void MainWindow::slotUpdateMousePosition(int pos) {
696 if (m_activeDocument)
697 switch (m_timecodeFormat->currentIndex()) {
699 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
702 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
706 void MainWindow::slotUpdateDocumentState(bool modified) {
707 setCaption(m_activeDocument->description(), modified);
709 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
710 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
712 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
713 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
717 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
718 //m_projectMonitor->stop();
719 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
720 if (m_activeDocument) {
721 if (m_activeDocument == doc) return;
722 m_activeDocument->backupMltPlaylist();
723 if (m_activeTimeline) {
724 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
725 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
726 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
727 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
728 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
729 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
730 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
731 disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
732 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
733 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
734 disconnect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
735 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
736 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
737 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
738 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
739 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
740 disconnect(transitionConfig, SIGNAL(transitionUpdated(QDomElement, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(QDomElement, QDomElement)));
741 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
743 m_activeDocument->setRenderer(NULL);
744 disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
745 m_clipMonitor->stop();
747 m_monitorManager->resetProfiles(doc->profilePath());
748 m_projectList->setDocument(doc);
749 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
750 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
751 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
752 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
753 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
754 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
755 connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
756 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
757 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
758 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
759 connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
760 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
762 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
763 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
764 timeline_buttons_ui.zoom_slider->setValue(trackView->currentZoom());
765 connect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
766 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
767 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
768 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
769 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
770 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
771 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
772 connect(transitionConfig, SIGNAL(transitionUpdated(QDomElement, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(QDomElement, QDomElement)));
773 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
774 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
775 m_activeTimeline = trackView;
776 KdenliveSettings::setCurrent_profile(doc->profilePath());
777 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
778 m_monitorManager->setTimecode(doc->timecode());
779 doc->setRenderer(m_projectMonitor->render);
780 m_commandStack->setActiveStack(doc->commandStack());
781 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
782 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
784 m_overView->setScene(trackView->projectScene());
785 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
786 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
788 setCaption(doc->description());
789 m_activeDocument = doc;
792 void MainWindow::slotPreferences() {
793 //An instance of your dialog could be already created and could be
794 // cached, in which case you want to display the cached dialog
795 // instead of creating another one
796 if (KConfigDialog::showDialog("settings"))
799 // KConfigDialog didn't find an instance of this dialog, so lets
801 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
802 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
806 void MainWindow::updateConfiguration() {
807 //TODO: we should apply settings to all projects, not only the current one
808 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
810 currentTab->refresh();
811 currentTab->projectView()->checkAutoScroll();
812 currentTab->projectView()->checkTrackHeight();
813 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
815 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
816 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
817 activateShuttleDevice();
821 void MainWindow::slotSwitchVideoThumbs() {
822 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
823 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
825 currentTab->refresh();
827 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
830 void MainWindow::slotSwitchAudioThumbs() {
831 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
832 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
834 currentTab->refresh();
835 currentTab->projectView()->checkAutoScroll();
836 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
838 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
841 void MainWindow::slotDeleteTimelineClip() {
842 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
844 currentTab->projectView()->deleteSelectedClips();
848 void MainWindow::slotAddProjectClip(KUrl url) {
849 if (m_activeDocument)
850 m_activeDocument->slotAddClipFile(url, QString());
853 void MainWindow::slotAddVideoEffect(QAction *result) {
855 QDomElement effect = m_videoEffects.getEffectByName(result->data().toString());
856 slotAddEffect(effect);
859 void MainWindow::slotAddAudioEffect(QAction *result) {
861 QDomElement effect = m_audioEffects.getEffectByName(result->data().toString());
862 slotAddEffect(effect);
865 void MainWindow::slotAddCustomEffect(QAction *result) {
867 QDomElement effect = m_customEffects.getEffectByName(result->data().toString());
868 slotAddEffect(effect);
871 void MainWindow::slotZoomIn() {
872 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() - 1);
875 void MainWindow::slotZoomOut() {
876 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() + 1);
879 void MainWindow::slotFitZoom() {
880 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
882 timeline_buttons_ui.zoom_slider->setValue(currentTab->fitZoom());
886 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
887 statusProgressBar->setValue(progress);
889 statusLabel->setText(tr("Creating Audio Thumbs"));
890 statusProgressBar->setVisible(true);
892 statusLabel->setText("");
893 statusProgressBar->setVisible(false);
897 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
898 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
899 if (dia.exec() == QDialog::Accepted) {
900 m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
904 void MainWindow::customEvent(QEvent* e) {
905 if (e->type() == QEvent::User) {
906 // The timeline playing position changed...
907 kDebug() << "RECIEVED JOG EVEMNT!!!";
912 #include "mainwindow.moc"