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>
48 #include <ktogglefullscreenaction.h>
50 #include <mlt++/Mlt.h>
52 #include "mainwindow.h"
53 #include "kdenlivesettings.h"
54 #include "kdenlivesettingsdialog.h"
55 #include "initeffects.h"
56 #include "profilesdialog.h"
57 #include "projectsettings.h"
59 #include "renderjob.h"
61 #define ID_STATUS_MSG 1
62 #define ID_EDITMODE_MSG 2
63 #define ID_TIMELINE_MSG 3
64 #define ID_TIMELINE_BUTTONS 5
65 #define ID_TIMELINE_POS 6
66 #define ID_TIMELINE_FORMAT 7
68 MainWindow::MainWindow(QWidget *parent)
69 : KXmlGuiWindow(parent),
70 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL) {
73 m_commandStack = new QUndoGroup;
74 m_timelineArea = new KTabWidget(this);
75 m_timelineArea->setTabReorderingEnabled(true);
76 m_timelineArea->setTabBarHidden(true);
78 QToolButton *closeTabButton = new QToolButton;
79 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
80 closeTabButton->setIcon(KIcon("tab-close"));
81 closeTabButton->adjustSize();
82 closeTabButton->setToolTip(i18n("Close the current tab"));
83 m_timelineArea->setCornerWidget(closeTabButton);
84 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
86 initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects, &m_transitions);
87 m_monitorManager = new MonitorManager();
89 projectListDock = new QDockWidget(i18n("Project Tree"), this);
90 projectListDock->setObjectName("project_tree");
91 m_projectList = new ProjectList(this);
92 projectListDock->setWidget(m_projectList);
93 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
95 effectListDock = new QDockWidget(i18n("Effect List"), this);
96 effectListDock->setObjectName("effect_list");
97 m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
99 //m_effectList = new KListWidget(this);
100 effectListDock->setWidget(m_effectList);
101 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
103 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
104 effectStackDock->setObjectName("effect_stack");
105 effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this);
106 effectStackDock->setWidget(effectStack);
107 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
109 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
110 transitionConfigDock->setObjectName("transition");
111 transitionConfig = new TransitionSettings(&m_transitions, this);
112 transitionConfigDock->setWidget(transitionConfig);
113 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
116 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
117 clipMonitorDock->setObjectName("clip_monitor");
118 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
119 clipMonitorDock->setWidget(m_clipMonitor);
120 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
121 //m_clipMonitor->stop();
123 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
124 projectMonitorDock->setObjectName("project_monitor");
125 m_projectMonitor = new Monitor("project", m_monitorManager, this);
126 projectMonitorDock->setWidget(m_projectMonitor);
127 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
129 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
130 recMonitorDock->setObjectName("record_monitor");
131 m_recMonitor = new RecMonitor("record", this);
132 recMonitorDock->setWidget(m_recMonitor);
133 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
135 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
137 undoViewDock = new QDockWidget(i18n("Undo History"), this);
138 undoViewDock->setObjectName("undo_history");
139 m_undoView = new QUndoView(this);
140 m_undoView->setCleanIcon(KIcon("edit-clear"));
141 m_undoView->setEmptyLabel(i18n("Clean"));
142 undoViewDock->setWidget(m_undoView);
143 m_undoView->setGroup(m_commandStack);
144 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
146 overviewDock = new QDockWidget(i18n("Project Overview"), this);
147 overviewDock->setObjectName("project_overview");
148 m_overView = new CustomTrackView(NULL, NULL, this);
149 overviewDock->setWidget(m_overView);
150 addDockWidget(Qt::TopDockWidgetArea, overviewDock);
153 tabifyDockWidget(projectListDock, effectListDock);
154 tabifyDockWidget(projectListDock, effectStackDock);
155 tabifyDockWidget(projectListDock, transitionConfigDock);
156 tabifyDockWidget(projectListDock, undoViewDock);
157 projectListDock->raise();
159 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
160 setCentralWidget(m_timelineArea);
162 m_timecodeFormat = new KComboBox(this);
163 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
164 m_timecodeFormat->addItem(i18n("Frames"));
166 statusProgressBar = new QProgressBar(this);
167 statusProgressBar->setMinimum(0);
168 statusProgressBar->setMaximum(100);
169 statusProgressBar->setMaximumWidth(150);
170 statusProgressBar->setVisible(false);
171 statusLabel = new QLabel(this);
173 QWidget *w = new QWidget;
174 timeline_buttons_ui.setupUi(w);
175 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
176 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
177 connect(timeline_buttons_ui.buttonVideo, SIGNAL(clicked()), this, SLOT(slotSwitchVideoThumbs()));
178 connect(timeline_buttons_ui.buttonAudio, SIGNAL(clicked()), this, SLOT(slotSwitchAudioThumbs()));
179 connect(timeline_buttons_ui.buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotFitZoom()));
181 statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
182 statusBar()->insertPermanentWidget(1, statusLabel, 1);
183 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
184 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
185 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
186 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
188 timeline_buttons_ui.buttonVideo->setIcon(KIcon("video-mpeg"));
189 timeline_buttons_ui.buttonVideo->setToolTip(i18n("Show video thumbnails"));
190 timeline_buttons_ui.buttonAudio->setIcon(KIcon("audio-mpeg"));
191 timeline_buttons_ui.buttonAudio->setToolTip(i18n("Show audio thumbnails"));
192 timeline_buttons_ui.buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
193 timeline_buttons_ui.buttonFitZoom->setToolTip(i18n("Fit zoom to project"));
195 setupGUI(Default, "kdenliveui.rc");
197 // build effects menus
199 QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
200 QStringList effects = m_videoEffects.effectNames();
201 foreach(QString name, effects) {
202 action = new QAction(name, this);
203 action->setData(name);
204 videoEffectsMenu->addAction(action);
206 QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
207 effects = m_audioEffects.effectNames();
208 foreach(QString name, effects) {
209 action = new QAction(name, this);
210 action->setData(name);
211 audioEffectsMenu->addAction(action);
213 QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
214 effects = m_customEffects.effectNames();
215 foreach(QString name, effects) {
216 action = new QAction(name, this);
217 action->setData(name);
218 customEffectsMenu->addAction(action);
221 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
222 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
223 connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
225 m_timelineContextMenu = new QMenu(this);
226 m_timelineContextClipMenu = new QMenu(this);
227 m_timelineContextTransitionMenu = new QMenu(this);
229 action = actionCollection()->action("delete_timeline_clip");
230 m_timelineContextClipMenu->addAction(action);
231 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
232 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
233 m_timelineContextClipMenu->addMenu(customEffectsMenu);
235 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
236 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
237 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
238 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
239 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
240 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
241 slotConnectMonitors();
243 setAutoSaveSettings();
246 activateShuttleDevice();
250 bool MainWindow::queryClose() {
252 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
253 case KMessageBox::Yes :
254 // save document here. If saving fails, return false;
256 case KMessageBox::No :
263 void MainWindow::activateShuttleDevice() {
264 if (m_jogProcess) delete m_jogProcess;
266 if (KdenliveSettings::enableshuttle() == false) return;
267 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
268 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
269 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
270 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
271 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
272 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
273 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
276 void MainWindow::slotShuttleButton(int code) {
279 slotShuttleAction(KdenliveSettings::shuttle1());
282 slotShuttleAction(KdenliveSettings::shuttle2());
285 slotShuttleAction(KdenliveSettings::shuttle3());
288 slotShuttleAction(KdenliveSettings::shuttle4());
291 slotShuttleAction(KdenliveSettings::shuttle5());
296 void MainWindow::slotShuttleAction(int code) {
301 m_monitorManager->slotPlay();
304 m_monitorManager->slotPlay();
309 void MainWindow::slotFullScreen() {
310 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
313 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
314 if (!m_activeDocument) return;
315 if (effect.isNull()) {
316 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
319 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
320 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
323 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
324 if (clipMonitor) clipMonitorDock->raise();
325 else projectMonitorDock->raise();
328 void MainWindow::slotSetClipDuration(int id, int duration) {
329 if (!m_activeDocument) return;
330 m_activeDocument->setProducerDuration(id, duration);
333 void MainWindow::slotConnectMonitors() {
335 m_projectList->setRenderer(m_clipMonitor->render);
336 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
337 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
338 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
339 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
340 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 > &)));
343 void MainWindow::setupActions() {
344 KAction* clearAction = new KAction(this);
345 clearAction->setText(i18n("Clear"));
346 clearAction->setIcon(KIcon("document-new"));
347 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
348 actionCollection()->addAction("clear", clearAction);
349 /*connect(clearAction, SIGNAL(triggered(bool)),
350 textArea, SLOT(clear()));*/
352 KAction* profilesAction = new KAction(this);
353 profilesAction->setText(i18n("Manage Profiles"));
354 profilesAction->setIcon(KIcon("document-new"));
355 actionCollection()->addAction("manage_profiles", profilesAction);
356 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
358 KAction* projectAction = new KAction(this);
359 projectAction->setText(i18n("Project Settings"));
360 projectAction->setIcon(KIcon("document-new"));
361 actionCollection()->addAction("project_settings", projectAction);
362 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
364 KAction* projectRender = new KAction(this);
365 projectRender->setText(i18n("Render Project"));
366 projectRender->setIcon(KIcon("document-new"));
367 actionCollection()->addAction("project_render", projectRender);
368 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
370 KAction* monitorPlay = new KAction(this);
371 monitorPlay->setText(i18n("Play"));
372 monitorPlay->setIcon(KIcon("media-playback-start"));
373 monitorPlay->setShortcut(Qt::Key_Space);
374 actionCollection()->addAction("monitor_play", monitorPlay);
375 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
377 KAction* monitorSeekBackward = new KAction(this);
378 monitorSeekBackward->setText(i18n("Rewind"));
379 monitorSeekBackward->setIcon(KIcon("media-seek-backward"));
380 monitorSeekBackward->setShortcut(Qt::Key_J);
381 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
382 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
384 KAction* monitorSeekBackwardOneFrame = new KAction(this);
385 monitorSeekBackwardOneFrame->setText(i18n("Rewind 1 Frame"));
386 monitorSeekBackwardOneFrame->setIcon(KIcon("media-skip-backward"));
387 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
388 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
389 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
391 KAction* monitorSeekForward = new KAction(this);
392 monitorSeekForward->setText(i18n("Forward"));
393 monitorSeekForward->setIcon(KIcon("media-seek-forward"));
394 monitorSeekForward->setShortcut(Qt::Key_L);
395 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
396 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
398 KAction* monitorSeekForwardOneFrame = new KAction(this);
399 monitorSeekForwardOneFrame->setText(i18n("Forward 1 Frame"));
400 monitorSeekForwardOneFrame->setIcon(KIcon("media-skip-forward"));
401 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
402 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
403 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
405 KAction* deleteTimelineClip = new KAction(this);
406 deleteTimelineClip->setText(i18n("Delete Clip"));
407 deleteTimelineClip->setShortcut(Qt::Key_Delete);
408 deleteTimelineClip->setIcon(KIcon("edit-delete"));
409 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
410 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
412 KStandardAction::quit(kapp, SLOT(quit()),
415 KStandardAction::open(this, SLOT(openFile()),
418 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
421 KStandardAction::save(this, SLOT(saveFile()),
424 KStandardAction::saveAs(this, SLOT(saveFileAs()),
427 KStandardAction::openNew(this, SLOT(newFile()),
430 KStandardAction::preferences(this, SLOT(slotPreferences()),
433 KStandardAction::undo(this, SLOT(undo()),
436 KStandardAction::redo(this, SLOT(redo()),
439 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
441 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
442 this, SLOT(slotDisplayActionMessage(QAction*)));
443 //connect(actionCollection(), SIGNAL( clearStatusText() ),
444 //statusBar(), SLOT( clear() ) );
449 void MainWindow::undo() {
450 m_commandStack->undo();
453 void MainWindow::redo() {
454 m_commandStack->redo();
457 void MainWindow::slotDisplayActionMessage(QAction *a) {
458 statusBar()->showMessage(a->data().toString(), 3000);
461 void MainWindow::saveOptions() {
462 KSharedConfigPtr config = KGlobal::config();
463 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
467 void MainWindow::readOptions() {
468 KSharedConfigPtr config = KGlobal::config();
469 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
472 void MainWindow::newFile() {
474 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
476 ProjectSettings *w = new ProjectSettings;
478 profileName = w->selectedProfile();
481 MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
482 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
483 KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
484 TrackView *trackView = new TrackView(doc, this);
485 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
486 if (m_timelineArea->count() == 1)
487 connectDocument(trackView, doc);
488 else m_timelineArea->setTabBarHidden(false);
491 void MainWindow::activateDocument() {
492 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
493 KdenliveDoc *currentDoc = currentTab->document();
494 connectDocument(currentTab, currentDoc);
497 void MainWindow::slotRemoveTab() {
498 QWidget *w = m_timelineArea->currentWidget();
499 // closing current document
500 int ix = m_timelineArea->currentIndex() + 1;
501 if (ix == m_timelineArea->count()) ix = 0;
502 m_timelineArea->setCurrentIndex(ix);
503 TrackView *tabToClose = (TrackView *) w;
504 KdenliveDoc *docToClose = tabToClose->document();
505 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
506 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
511 void MainWindow::saveFileAs(const QString &outputFileName) {
512 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
513 m_activeDocument->setUrl(KUrl(outputFileName));
514 setCaption(m_activeDocument->description());
515 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
516 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
517 m_activeDocument->setModified(false);
520 void MainWindow::saveFileAs() {
521 QString outputFile = KFileDialog::getSaveFileName();
522 if (QFile::exists(outputFile)) {
523 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
525 saveFileAs(outputFile);
528 void MainWindow::saveFile() {
529 if (!m_activeDocument) return;
530 if (m_activeDocument->url().isEmpty()) {
533 saveFileAs(m_activeDocument->url().path());
537 void MainWindow::openFile() { //changed
538 KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
539 if (url.isEmpty()) return;
540 m_fileOpenRecent->addUrl(url);
544 void MainWindow::openFile(const KUrl &url) { //new
545 //TODO: get video profile from url before opening it
546 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
547 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
548 KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
549 TrackView *trackView = new TrackView(doc, this);
550 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
551 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
552 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
553 //connectDocument(trackView, doc);
557 void MainWindow::parseProfiles() {
558 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
559 if (KdenliveSettings::mltpath().isEmpty()) {
560 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
562 if (KdenliveSettings::rendererpath().isEmpty()) {
563 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
565 QStringList profilesFilter;
566 profilesFilter << "*";
567 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
569 if (profilesList.isEmpty()) {
570 // Cannot find MLT path, try finding inigo
571 QString profilePath = KdenliveSettings::rendererpath();
572 if (!profilePath.isEmpty()) {
573 profilePath = profilePath.section('/', 0, -3);
574 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
575 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
578 if (profilesList.isEmpty()) {
579 // Cannot find the MLT profiles, ask for location
580 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
581 getUrl->fileDialog()->setMode(KFile::Directory);
583 KUrl mltPath = getUrl->selectedUrl();
585 if (mltPath.isEmpty()) exit(1);
586 KdenliveSettings::setMltpath(mltPath.path());
587 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
591 if (KdenliveSettings::rendererpath().isEmpty()) {
592 // Cannot find the MLT inigo renderer, ask for location
593 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
595 KUrl rendererPath = getUrl->selectedUrl();
597 if (rendererPath.isEmpty()) exit(1);
598 KdenliveSettings::setRendererpath(rendererPath.path());
601 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
603 // Parse MLT profiles to build a list of available video formats
604 if (profilesList.isEmpty()) parseProfiles();
608 void MainWindow::slotEditProfiles() {
609 ProfilesDialog *w = new ProfilesDialog;
614 void MainWindow::slotEditProjectSettings() {
615 ProjectSettings *w = new ProjectSettings;
616 if (w->exec() == QDialog::Accepted) {
617 QString profile = w->selectedProfile();
618 m_activeDocument->setProfilePath(profile);
619 m_monitorManager->resetProfiles(profile);
620 setCaption(m_activeDocument->description());
621 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
622 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
623 m_monitorManager->setTimecode(m_activeDocument->timecode());
624 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
626 // We need to desactivate & reactivate monitors to get a refresh
627 m_monitorManager->switchMonitors();
632 void MainWindow::slotRenderProject() {
633 if (!m_renderWidget) {
634 m_renderWidget = new RenderWidget(this);
635 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
637 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
638 if (currentTab) m_renderWidget->setTimeline(currentTab);
639 m_renderWidget->setDocument(m_activeDocument);*/
640 m_renderWidget->show();
643 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
644 if (dest.isEmpty()) return;
647 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
648 if (currentTab && zoneOnly) {
649 in = currentTab->inPoint();
650 out = currentTab->outPoint();
653 temp.setAutoRemove(false);
654 temp.setSuffix(".westley");
656 m_projectMonitor->saveSceneList(temp.fileName());
659 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
660 QString videoPlayer = "-";
661 if (playAfter) videoPlayer = "kmplayer";
662 args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
663 QProcess::startDetached("kdenlive_render", args);
667 void MainWindow::slotUpdateMousePosition(int pos) {
668 if (m_activeDocument)
669 switch (m_timecodeFormat->currentIndex()) {
671 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
674 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
678 void MainWindow::slotUpdateDocumentState(bool modified) {
679 setCaption(m_activeDocument->description(), modified);
681 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
682 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
684 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
685 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
689 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
690 //m_projectMonitor->stop();
691 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
692 if (m_activeDocument) {
693 if (m_activeDocument == doc) return;
694 m_activeDocument->backupMltPlaylist();
695 if (m_activeTimeline) {
696 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
697 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
698 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
699 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
700 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
701 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
702 disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
703 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
704 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
705 disconnect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
706 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
707 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
708 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
709 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
710 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
711 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
713 m_activeDocument->setRenderer(NULL);
714 disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
715 m_clipMonitor->stop();
717 m_monitorManager->resetProfiles(doc->profilePath());
718 m_projectList->setDocument(doc);
719 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
720 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
721 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
722 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
723 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
724 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
725 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
726 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
727 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
728 connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
729 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
731 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
732 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
733 timeline_buttons_ui.zoom_slider->setValue(trackView->currentZoom());
734 connect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
735 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
736 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
737 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
738 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
739 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
740 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
741 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
742 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
743 m_activeTimeline = trackView;
744 KdenliveSettings::setCurrent_profile(doc->profilePath());
745 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
746 m_monitorManager->setTimecode(doc->timecode());
747 doc->setRenderer(m_projectMonitor->render);
748 m_commandStack->setActiveStack(doc->commandStack());
749 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
750 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
752 m_overView->setScene(trackView->projectScene());
753 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
754 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
756 setCaption(doc->description());
757 m_activeDocument = doc;
760 void MainWindow::slotPreferences() {
761 //An instance of your dialog could be already created and could be
762 // cached, in which case you want to display the cached dialog
763 // instead of creating another one
764 if (KConfigDialog::showDialog("settings"))
767 // KConfigDialog didn't find an instance of this dialog, so lets
769 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
770 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
774 void MainWindow::updateConfiguration() {
775 //TODO: we should apply settings to all projects, not only the current one
776 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
778 currentTab->refresh();
779 currentTab->projectView()->checkAutoScroll();
780 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
782 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
783 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
784 activateShuttleDevice();
787 void MainWindow::slotSwitchVideoThumbs() {
788 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
789 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
791 currentTab->refresh();
793 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
796 void MainWindow::slotSwitchAudioThumbs() {
797 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
798 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
800 currentTab->refresh();
801 currentTab->projectView()->checkAutoScroll();
802 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
804 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
807 void MainWindow::slotDeleteTimelineClip() {
808 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
810 currentTab->projectView()->deleteSelectedClips();
814 void MainWindow::slotAddProjectClip(KUrl url) {
815 if (m_activeDocument)
816 m_activeDocument->slotAddClipFile(url, QString());
819 void MainWindow::slotAddVideoEffect(QAction *result) {
821 QDomElement effect = m_videoEffects.getEffectByName(result->data().toString());
822 slotAddEffect(effect);
825 void MainWindow::slotAddAudioEffect(QAction *result) {
827 QDomElement effect = m_audioEffects.getEffectByName(result->data().toString());
828 slotAddEffect(effect);
831 void MainWindow::slotAddCustomEffect(QAction *result) {
833 QDomElement effect = m_customEffects.getEffectByName(result->data().toString());
834 slotAddEffect(effect);
837 void MainWindow::slotZoomIn() {
838 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() - 1);
841 void MainWindow::slotZoomOut() {
842 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() + 1);
845 void MainWindow::slotFitZoom() {
846 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
848 timeline_buttons_ui.zoom_slider->setValue(currentTab->fitZoom());
852 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
853 statusProgressBar->setValue(progress);
855 statusLabel->setText(tr("Creating Audio Thumbs"));
856 statusProgressBar->setVisible(true);
858 statusLabel->setText("");
859 statusProgressBar->setVisible(false);
863 void MainWindow::customEvent(QEvent* e) {
864 if (e->type() == QEvent::User) {
865 // The timeline playing position changed...
866 kDebug() << "RECIEVED JOG EVEMNT!!!";
871 #include "mainwindow.moc"