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>
31 #include <KActionCollection>
32 #include <KStandardAction>
33 #include <KFileDialog>
34 #include <KMessageBox>
36 #include <KIO/NetAccess>
39 #include <KConfigDialog>
40 #include <KXMLGUIFactory>
42 #include <kstandarddirs.h>
43 #include <KUrlRequesterDialog>
44 #include <KTemporaryFile>
45 #include <ktogglefullscreenaction.h>
47 #include <mlt++/Mlt.h>
49 #include "mainwindow.h"
50 #include "kdenlivesettings.h"
51 #include "kdenlivesettingsdialog.h"
52 #include "initeffects.h"
53 #include "profilesdialog.h"
54 #include "projectsettings.h"
56 #include "renderjob.h"
58 #define ID_STATUS_MSG 1
59 #define ID_EDITMODE_MSG 2
60 #define ID_TIMELINE_MSG 3
61 #define ID_TIMELINE_BUTTONS 5
62 #define ID_TIMELINE_POS 6
63 #define ID_TIMELINE_FORMAT 7
65 MainWindow::MainWindow(QWidget *parent)
66 : KXmlGuiWindow(parent),
67 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL) {
70 m_commandStack = new QUndoGroup;
71 m_timelineArea = new KTabWidget(this);
72 m_timelineArea->setTabReorderingEnabled(true);
73 m_timelineArea->setTabBarHidden(true);
75 QToolButton *closeTabButton = new QToolButton;
76 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
77 closeTabButton->setIcon(KIcon("tab-close"));
78 closeTabButton->adjustSize();
79 closeTabButton->setToolTip(i18n("Close the current tab"));
80 m_timelineArea->setCornerWidget(closeTabButton);
81 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
84 initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects);
85 m_monitorManager = new MonitorManager();
87 projectListDock = new QDockWidget(i18n("Project Tree"), this);
88 projectListDock->setObjectName("project_tree");
89 m_projectList = new ProjectList(this);
90 projectListDock->setWidget(m_projectList);
91 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
93 effectListDock = new QDockWidget(i18n("Effect List"), this);
94 effectListDock->setObjectName("effect_list");
95 m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
97 //m_effectList = new KListWidget(this);
98 effectListDock->setWidget(m_effectList);
99 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
101 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
102 effectStackDock->setObjectName("effect_stack");
103 effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this);
104 effectStackDock->setWidget(effectStack);
105 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
107 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
108 transitionConfigDock->setObjectName("transition");
109 transitionConfig = new KListWidget(this);
110 transitionConfigDock->setWidget(transitionConfig);
111 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
114 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
115 clipMonitorDock->setObjectName("clip_monitor");
116 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
117 clipMonitorDock->setWidget(m_clipMonitor);
118 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
119 //m_clipMonitor->stop();
121 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
122 projectMonitorDock->setObjectName("project_monitor");
123 m_projectMonitor = new Monitor("project", m_monitorManager, this);
124 projectMonitorDock->setWidget(m_projectMonitor);
125 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
127 undoViewDock = new QDockWidget(i18n("Undo History"), this);
128 undoViewDock->setObjectName("undo_history");
129 m_undoView = new QUndoView(this);
130 m_undoView->setCleanIcon(KIcon("edit-clear"));
131 m_undoView->setEmptyLabel(i18n("Clean"));
132 undoViewDock->setWidget(m_undoView);
133 m_undoView->setGroup(m_commandStack);
134 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
136 overviewDock = new QDockWidget(i18n("Project Overview"), this);
137 overviewDock->setObjectName("project_overview");
138 m_overView = new CustomTrackView(NULL, NULL, this);
139 overviewDock->setWidget(m_overView);
140 addDockWidget(Qt::TopDockWidgetArea, overviewDock);
143 tabifyDockWidget(projectListDock, effectListDock);
144 tabifyDockWidget(projectListDock, effectStackDock);
145 tabifyDockWidget(projectListDock, transitionConfigDock);
146 tabifyDockWidget(projectListDock, undoViewDock);
147 projectListDock->raise();
149 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
150 setCentralWidget(m_timelineArea);
152 m_timecodeFormat = new KComboBox(this);
153 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
154 m_timecodeFormat->addItem(i18n("Frames"));
156 statusProgressBar = new QProgressBar(this);
157 statusProgressBar->setMinimum(0);
158 statusProgressBar->setMaximum(100);
159 statusProgressBar->setMaximumWidth(150);
160 statusProgressBar->setVisible(false);
161 statusLabel = new QLabel(this);
163 QWidget *w = new QWidget;
164 timeline_buttons_ui.setupUi(w);
165 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
166 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
167 connect(timeline_buttons_ui.buttonVideo, SIGNAL(clicked()), this, SLOT(slotSwitchVideoThumbs()));
168 connect(timeline_buttons_ui.buttonAudio, SIGNAL(clicked()), this, SLOT(slotSwitchAudioThumbs()));
169 connect(timeline_buttons_ui.buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotFitZoom()));
171 statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
172 statusBar()->insertPermanentWidget(1, statusLabel, 1);
173 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
174 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
175 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
176 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
178 timeline_buttons_ui.buttonVideo->setIcon(KIcon("video-mpeg"));
179 timeline_buttons_ui.buttonVideo->setToolTip(i18n("Show video thumbnails"));
180 timeline_buttons_ui.buttonAudio->setIcon(KIcon("audio-mpeg"));
181 timeline_buttons_ui.buttonAudio->setToolTip(i18n("Show audio thumbnails"));
182 timeline_buttons_ui.buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
183 timeline_buttons_ui.buttonFitZoom->setToolTip(i18n("Fit zoom to project"));
185 setupGUI(Default, "kdenliveui.rc");
187 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
188 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
189 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
190 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
191 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
192 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
193 slotConnectMonitors();
195 setAutoSaveSettings();
200 bool MainWindow::queryClose() {
202 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
203 case KMessageBox::Yes :
204 // save document here. If saving fails, return false;
206 case KMessageBox::No :
213 void MainWindow::slotFullScreen() {
214 KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
217 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
218 if (!m_activeDocument) return;
219 if (effect.isNull()) {
220 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
223 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
224 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
227 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
228 if (clipMonitor) clipMonitorDock->raise();
229 else projectMonitorDock->raise();
232 void MainWindow::slotSetClipDuration(int id, int duration) {
233 if (!m_activeDocument) return;
234 m_activeDocument->setProducerDuration(id, duration);
237 void MainWindow::slotConnectMonitors() {
239 m_projectList->setRenderer(m_clipMonitor->render);
240 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
241 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
242 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
243 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
244 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 > &)));
247 void MainWindow::setupActions() {
248 KAction* clearAction = new KAction(this);
249 clearAction->setText(i18n("Clear"));
250 clearAction->setIcon(KIcon("document-new"));
251 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
252 actionCollection()->addAction("clear", clearAction);
253 /*connect(clearAction, SIGNAL(triggered(bool)),
254 textArea, SLOT(clear()));*/
256 KAction* profilesAction = new KAction(this);
257 profilesAction->setText(i18n("Manage Profiles"));
258 profilesAction->setIcon(KIcon("document-new"));
259 actionCollection()->addAction("manage_profiles", profilesAction);
260 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
262 KAction* projectAction = new KAction(this);
263 projectAction->setText(i18n("Project Settings"));
264 projectAction->setIcon(KIcon("document-new"));
265 actionCollection()->addAction("project_settings", projectAction);
266 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
268 KAction* projectRender = new KAction(this);
269 projectRender->setText(i18n("Render Project"));
270 projectRender->setIcon(KIcon("document-new"));
271 actionCollection()->addAction("project_render", projectRender);
272 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
274 KAction* monitorPlay = new KAction(this);
275 monitorPlay->setText(i18n("Play"));
276 monitorPlay->setIcon(KIcon("media-playback-start"));
277 monitorPlay->setShortcut(Qt::Key_Space);
278 actionCollection()->addAction("monitor_play", monitorPlay);
279 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
281 KAction* deleteTimelineClip = new KAction(this);
282 deleteTimelineClip->setText(i18n("Delete Clip"));
283 deleteTimelineClip->setShortcut(Qt::Key_Delete);
284 deleteTimelineClip->setIcon(KIcon("edit-delete"));
285 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
286 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
288 KStandardAction::quit(kapp, SLOT(quit()),
291 KStandardAction::open(this, SLOT(openFile()),
294 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
297 KStandardAction::save(this, SLOT(saveFile()),
300 KStandardAction::saveAs(this, SLOT(saveFileAs()),
303 KStandardAction::openNew(this, SLOT(newFile()),
306 KStandardAction::preferences(this, SLOT(slotPreferences()),
309 KStandardAction::undo(this, SLOT(undo()),
312 KStandardAction::redo(this, SLOT(redo()),
315 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
317 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
318 this, SLOT(slotDisplayActionMessage(QAction*)));
319 //connect(actionCollection(), SIGNAL( clearStatusText() ),
320 //statusBar(), SLOT( clear() ) );
325 void MainWindow::undo() {
326 m_commandStack->undo();
329 void MainWindow::redo() {
330 m_commandStack->redo();
333 void MainWindow::slotDisplayActionMessage(QAction *a) {
334 statusBar()->showMessage(a->data().toString(), 3000);
337 void MainWindow::saveOptions() {
338 KSharedConfigPtr config = KGlobal::config();
339 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
343 void MainWindow::readOptions() {
344 KSharedConfigPtr config = KGlobal::config();
345 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
348 void MainWindow::newFile() {
350 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
352 ProjectSettings *w = new ProjectSettings;
354 profileName = w->selectedProfile();
357 MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
358 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
359 KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
360 TrackView *trackView = new TrackView(doc, this);
361 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
362 if (m_timelineArea->count() == 1)
363 connectDocument(trackView, doc);
364 else m_timelineArea->setTabBarHidden(false);
367 void MainWindow::activateDocument() {
368 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
369 KdenliveDoc *currentDoc = currentTab->document();
370 connectDocument(currentTab, currentDoc);
373 void MainWindow::slotRemoveTab() {
374 QWidget *w = m_timelineArea->currentWidget();
375 // closing current document
376 int ix = m_timelineArea->currentIndex() + 1;
377 if (ix == m_timelineArea->count()) ix = 0;
378 m_timelineArea->setCurrentIndex(ix);
379 TrackView *tabToClose = (TrackView *) w;
380 KdenliveDoc *docToClose = tabToClose->document();
381 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
382 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
387 void MainWindow::saveFileAs(const QString &outputFileName) {
388 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
389 m_activeDocument->setUrl(KUrl(outputFileName));
390 setCaption(m_activeDocument->description());
391 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
392 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
393 m_activeDocument->setModified(false);
396 void MainWindow::saveFileAs() {
397 QString outputFile = KFileDialog::getSaveFileName();
398 if (QFile::exists(outputFile)) {
399 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
401 saveFileAs(outputFile);
404 void MainWindow::saveFile() {
405 if (!m_activeDocument) return;
406 if (m_activeDocument->url().isEmpty()) {
409 saveFileAs(m_activeDocument->url().path());
413 void MainWindow::openFile() { //changed
414 KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
415 if (url.isEmpty()) return;
416 m_fileOpenRecent->addUrl(url);
420 void MainWindow::openFile(const KUrl &url) { //new
421 //TODO: get video profile from url before opening it
422 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
423 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
424 KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
425 TrackView *trackView = new TrackView(doc, this);
426 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
427 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
428 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
429 //connectDocument(trackView, doc);
433 void MainWindow::parseProfiles() {
434 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
435 if (KdenliveSettings::mltpath().isEmpty()) {
436 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
438 if (KdenliveSettings::rendererpath().isEmpty()) {
439 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
441 QStringList profilesFilter;
442 profilesFilter << "*";
443 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
445 if (profilesList.isEmpty()) {
446 // Cannot find MLT path, try finding inigo
447 QString profilePath = KdenliveSettings::rendererpath();
448 if (!profilePath.isEmpty()) {
449 profilePath = profilePath.section('/', 0, -3);
450 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
451 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
454 if (profilesList.isEmpty()) {
455 // Cannot find the MLT profiles, ask for location
456 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
457 getUrl->fileDialog()->setMode(KFile::Directory);
459 KUrl mltPath = getUrl->selectedUrl();
461 if (mltPath.isEmpty()) exit(1);
462 KdenliveSettings::setMltpath(mltPath.path());
463 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
467 if (KdenliveSettings::rendererpath().isEmpty()) {
468 // Cannot find the MLT inigo renderer, ask for location
469 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
471 KUrl rendererPath = getUrl->selectedUrl();
473 if (rendererPath.isEmpty()) exit(1);
474 KdenliveSettings::setRendererpath(rendererPath.path());
477 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
479 // Parse MLT profiles to build a list of available video formats
480 if (profilesList.isEmpty()) parseProfiles();
484 void MainWindow::slotEditProfiles() {
485 ProfilesDialog *w = new ProfilesDialog;
490 void MainWindow::slotEditProjectSettings() {
491 ProjectSettings *w = new ProjectSettings;
492 if (w->exec() == QDialog::Accepted) {
493 QString profile = w->selectedProfile();
494 m_activeDocument->setProfilePath(profile);
495 m_monitorManager->resetProfiles(profile);
496 setCaption(m_activeDocument->description());
497 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
498 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
499 m_monitorManager->setTimecode(m_activeDocument->timecode());
500 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
502 // We need to desactivate & reactivate monitors to get a refresh
503 m_monitorManager->switchMonitors();
508 void MainWindow::slotRenderProject() {
509 if (!m_renderWidget) {
510 m_renderWidget = new RenderWidget(this);
511 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
513 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
514 if (currentTab) m_renderWidget->setTimeline(currentTab);
515 m_renderWidget->setDocument(m_activeDocument);*/
516 m_renderWidget->show();
519 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
520 if (dest.isEmpty()) return;
523 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
524 if (currentTab && zoneOnly) {
525 in = currentTab->inPoint();
526 out = currentTab->outPoint();
529 temp.setAutoRemove(false);
530 temp.setSuffix(".westley");
532 m_projectMonitor->saveSceneList(temp.fileName());
535 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
536 QString videoPlayer = "-";
537 if (playAfter) videoPlayer = "kmplayer";
538 args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
539 QProcess::startDetached("kdenlive_render", args);
543 void MainWindow::slotUpdateMousePosition(int pos) {
544 if (m_activeDocument)
545 switch (m_timecodeFormat->currentIndex()) {
547 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
550 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
554 void MainWindow::slotUpdateDocumentState(bool modified) {
555 setCaption(m_activeDocument->description(), modified);
557 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
558 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
560 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
561 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
565 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
566 //m_projectMonitor->stop();
567 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
568 if (m_activeDocument) {
569 if (m_activeDocument == doc) return;
570 m_activeDocument->backupMltPlaylist();
571 if (m_activeTimeline) {
572 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
573 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
574 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
575 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
576 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
577 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
578 disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
579 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
580 disconnect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
581 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
582 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
583 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
584 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
585 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
586 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
588 m_activeDocument->setRenderer(NULL);
589 disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
590 m_clipMonitor->stop();
592 m_monitorManager->resetProfiles(doc->profilePath());
593 m_projectList->setDocument(doc);
594 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
595 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
596 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
597 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
598 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
599 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
600 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
601 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
602 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
603 connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
604 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
606 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
607 timeline_buttons_ui.zoom_slider->setValue(trackView->currentZoom());
608 connect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
609 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
610 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
611 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
612 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
613 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
614 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
615 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
618 m_activeTimeline = trackView;
619 KdenliveSettings::setCurrent_profile(doc->profilePath());
620 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
621 m_monitorManager->setTimecode(doc->timecode());
622 doc->setRenderer(m_projectMonitor->render);
623 m_commandStack->setActiveStack(doc->commandStack());
624 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
625 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
627 m_overView->setScene(trackView->projectScene());
628 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
629 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
631 setCaption(doc->description());
632 m_activeDocument = doc;
635 void MainWindow::slotPreferences() {
636 //An instance of your dialog could be already created and could be
637 // cached, in which case you want to display the cached dialog
638 // instead of creating another one
639 if (KConfigDialog::showDialog("settings"))
642 // KConfigDialog didn't find an instance of this dialog, so lets
644 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
645 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
649 void MainWindow::updateConfiguration() {
650 //TODO: we should apply settings to all projects, not only the current one
651 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
653 currentTab->refresh();
654 currentTab->projectView()->checkAutoScroll();
655 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
657 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
658 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
661 void MainWindow::slotSwitchVideoThumbs() {
662 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
663 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
665 currentTab->refresh();
667 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
670 void MainWindow::slotSwitchAudioThumbs() {
671 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
672 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
674 currentTab->refresh();
675 currentTab->projectView()->checkAutoScroll();
676 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
678 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
681 void MainWindow::slotDeleteTimelineClip() {
682 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
684 currentTab->projectView()->deleteSelectedClips();
688 void MainWindow::slotZoomIn() {
689 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() - 1);
692 void MainWindow::slotZoomOut() {
693 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() + 1);
696 void MainWindow::slotFitZoom() {
697 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
699 timeline_buttons_ui.zoom_slider->setValue(currentTab->fitZoom());
703 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
704 statusProgressBar->setValue(progress);
706 statusLabel->setText(tr("Creating Audio Thumbs"));
707 statusProgressBar->setVisible(true);
709 statusLabel->setText("");
710 statusProgressBar->setVisible(false);
714 #include "mainwindow.moc"