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>
29 #include <KApplication>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
38 #include <KIO/NetAccess>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
50 #include <ktogglefullscreenaction.h>
52 #include <KNotification>
53 #include <KNotifyConfigWidget>
54 #include <knewstuff2/engine.h>
55 #include <knewstuff2/ui/knewstuffaction.h>
57 #include <mlt++/Mlt.h>
59 #include "mainwindow.h"
60 #include "kdenlivesettings.h"
61 #include "kdenlivesettingsdialog.h"
62 #include "initeffects.h"
63 #include "profilesdialog.h"
64 #include "projectsettings.h"
66 #include "clipmanager.h"
67 #include "projectlist.h"
69 #include "recmonitor.h"
70 #include "monitormanager.h"
71 #include "kdenlivedoc.h"
72 #include "trackview.h"
73 #include "customtrackview.h"
74 #include "effectslistview.h"
75 #include "effectstackview.h"
76 #include "transitionsettings.h"
77 #include "renderwidget.h"
80 #include "jogshuttle.h"
81 #endif /* NO_JOGSHUTTLE */
82 #include "clipproperties.h"
84 #include "editclipcommand.h"
85 #include "titlewidget.h"
86 #include "markerdialog.h"
89 static const int ID_STATUS_MSG = 1;
90 static const int ID_EDITMODE_MSG = 2;
91 static const int ID_TIMELINE_MSG = 3;
92 static const int ID_TIMELINE_BUTTONS = 5;
93 static const int ID_TIMELINE_POS = 6;
94 static const int ID_TIMELINE_FORMAT = 7;
100 EffectsList MainWindow::videoEffects;
101 EffectsList MainWindow::audioEffects;
102 EffectsList MainWindow::customEffects;
103 EffectsList MainWindow::transitions;
105 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
106 : KXmlGuiWindow(parent),
107 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
108 #ifndef NO_JOGSHUTTLE
110 #endif /* NO_JOGSHUTTLE */
111 m_findActivated(false), m_initialized(false) {
112 setlocale(LC_NUMERIC, "POSIX");
113 setFont(KGlobalSettings::toolBarFont());
114 parseProfiles(MltPath);
115 m_commandStack = new QUndoGroup;
116 m_timelineArea = new KTabWidget(this);
117 m_timelineArea->setTabReorderingEnabled(true);
118 m_timelineArea->setTabBarHidden(true);
120 QToolButton *closeTabButton = new QToolButton;
121 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
122 closeTabButton->setIcon(KIcon("tab-close"));
123 closeTabButton->adjustSize();
124 closeTabButton->setToolTip(i18n("Close the current tab"));
125 m_timelineArea->setCornerWidget(closeTabButton);
126 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
128 connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
129 m_findTimer.setSingleShot(true);
131 initEffects::parseEffectFiles();
132 //initEffects::parseCustomEffectsFile();
134 m_monitorManager = new MonitorManager();
136 projectListDock = new QDockWidget(i18n("Project Tree"), this);
137 projectListDock->setObjectName("project_tree");
138 m_projectList = new ProjectList(this);
139 projectListDock->setWidget(m_projectList);
140 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
142 effectListDock = new QDockWidget(i18n("Effect List"), this);
143 effectListDock->setObjectName("effect_list");
144 m_effectList = new EffectsListView();
146 //m_effectList = new KListWidget(this);
147 effectListDock->setWidget(m_effectList);
148 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
150 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
151 effectStackDock->setObjectName("effect_stack");
152 effectStack = new EffectStackView(this);
153 effectStackDock->setWidget(effectStack);
154 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
156 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
157 transitionConfigDock->setObjectName("transition");
158 transitionConfig = new TransitionSettings(this);
159 transitionConfigDock->setWidget(transitionConfig);
160 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
162 KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
163 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
167 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
168 clipMonitorDock->setObjectName("clip_monitor");
169 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
170 clipMonitorDock->setWidget(m_clipMonitor);
171 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
172 //m_clipMonitor->stop();
174 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
175 projectMonitorDock->setObjectName("project_monitor");
176 m_projectMonitor = new Monitor("project", m_monitorManager, this);
177 projectMonitorDock->setWidget(m_projectMonitor);
178 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
180 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
181 recMonitorDock->setObjectName("record_monitor");
182 m_recMonitor = new RecMonitor("record", this);
183 recMonitorDock->setWidget(m_recMonitor);
184 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
186 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
187 connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
189 undoViewDock = new QDockWidget(i18n("Undo History"), this);
190 undoViewDock->setObjectName("undo_history");
191 m_undoView = new QUndoView(this);
192 m_undoView->setCleanIcon(KIcon("edit-clear"));
193 m_undoView->setEmptyLabel(i18n("Clean"));
194 undoViewDock->setWidget(m_undoView);
195 m_undoView->setGroup(m_commandStack);
196 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
198 //overviewDock = new QDockWidget(i18n("Project Overview"), this);
199 //overviewDock->setObjectName("project_overview");
200 //m_overView = new CustomTrackView(NULL, NULL, this);
201 //overviewDock->setWidget(m_overView);
202 //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
205 //tabifyDockWidget(projectListDock, effectListDock);
206 tabifyDockWidget(projectListDock, effectStackDock);
207 tabifyDockWidget(projectListDock, transitionConfigDock);
208 //tabifyDockWidget(projectListDock, undoViewDock);
211 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
212 tabifyDockWidget(clipMonitorDock, recMonitorDock);
213 setCentralWidget(m_timelineArea);
216 //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
218 m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
219 m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), static_cast<QMenu*>(factory()->container("marker_menu", this)));
221 // build effects menus
223 QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
225 QStringList effectInfo;
226 QMap<QString, QStringList> effectsList;
227 for (int ix = 0; ix < videoEffects.count(); ix++) {
228 effectInfo = videoEffects.effectIdInfo(ix);
229 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
232 foreach(QStringList value, effectsList) {
233 action = new QAction(value.at(0), this);
234 action->setData(value);
235 videoEffectsMenu->addAction(action);
238 QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
242 for (int ix = 0; ix < audioEffects.count(); ix++) {
243 effectInfo = audioEffects.effectIdInfo(ix);
244 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
247 foreach(QStringList value, effectsList) {
248 action = new QAction(value.at(0), this);
249 action->setData(value);
250 audioEffectsMenu->addAction(action);
253 m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
255 if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
256 else m_customEffectsMenu->setEnabled(true);
259 for (int ix = 0; ix < customEffects.count(); ix++) {
260 effectInfo = customEffects.effectIdInfo(ix);
261 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
264 foreach(QStringList value, effectsList) {
265 action = new QAction(value.at(0), this);
266 action->setData(value);
267 m_customEffectsMenu->addAction(action);
270 QMenu *newEffect = new QMenu(this);
271 newEffect->addMenu(videoEffectsMenu);
272 newEffect->addMenu(audioEffectsMenu);
273 newEffect->addMenu(m_customEffectsMenu);
274 effectStack->setMenu(newEffect);
277 QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
278 const QList<QAction *> viewActions = createPopupMenu()->actions();
279 viewMenu->insertActions(NULL, viewActions);
281 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
282 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
283 connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
285 m_timelineContextMenu = new QMenu(this);
286 m_timelineContextClipMenu = new QMenu(this);
287 m_timelineContextTransitionMenu = new QMenu(this);
290 QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
291 QStringList effects = transitions.effectNames();
294 for (int ix = 0; ix < transitions.count(); ix++) {
295 effectInfo = transitions.effectIdInfo(ix);
296 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
298 foreach(QStringList value, effectsList) {
299 action = new QAction(value.at(0), this);
300 action->setData(value);
301 transitionsMenu->addAction(action);
303 connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
305 m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
306 m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
307 m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
309 m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
310 m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
311 m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
312 m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
313 m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
315 QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
316 m_timelineContextClipMenu->addMenu(markersMenu);
317 m_timelineContextClipMenu->addMenu(transitionsMenu);
318 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
319 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
320 //TODO: re-enable custom effects menu when it is implemented
321 m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
323 m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
324 m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
326 m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
328 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
329 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
330 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
331 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
332 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
333 connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
335 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
336 slotConnectMonitors();
338 // Open or create a file. Command line argument passed in Url has
339 // precedence, then "openlastproject", then just a plain empty file.
340 // If opening Url fails, openlastproject will _not_ be used.
341 if (!Url.isEmpty()) {
344 if (KdenliveSettings::openlastproject()) {
348 if (m_timelineArea->count() == 0) {
352 #ifndef NO_JOGSHUTTLE
353 activateShuttleDevice();
354 #endif /* NO_JOGSHUTTLE */
355 projectListDock->raise();
358 void MainWindow::queryQuit() {
359 kDebug() << "----- SAVING CONFUIG";
360 if (queryClose()) kapp->quit();
364 bool MainWindow::queryClose() {
366 if (m_monitorManager) m_monitorManager->stopActiveMonitor();
367 if (m_activeDocument && m_activeDocument->isModified()) {
368 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
369 case KMessageBox::Yes :
370 // save document here. If saving fails, return false;
372 case KMessageBox::No :
381 void MainWindow::saveProperties(KConfig*) {
382 // save properties here,used by session management
387 void MainWindow::readProperties(KConfig *config) {
388 // read properties here,used by session management
389 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
390 openFile(KUrl(Lastproject));
393 void MainWindow::slotReloadEffects() {
394 initEffects::parseCustomEffectsFile();
395 m_customEffectsMenu->clear();
396 const QStringList effects = customEffects.effectNames();
398 if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
399 else m_customEffectsMenu->setEnabled(true);
401 foreach(const QString &name, effects) {
402 action = new QAction(name, this);
403 action->setData(name);
404 m_customEffectsMenu->addAction(action);
406 m_effectList->reloadEffectList();
409 #ifndef NO_JOGSHUTTLE
410 void MainWindow::activateShuttleDevice() {
411 if (m_jogProcess) delete m_jogProcess;
413 if (KdenliveSettings::enableshuttle() == false) return;
414 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
415 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
416 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
417 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
418 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
419 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
420 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
423 void MainWindow::slotShuttleButton(int code) {
426 slotShuttleAction(KdenliveSettings::shuttle1());
429 slotShuttleAction(KdenliveSettings::shuttle2());
432 slotShuttleAction(KdenliveSettings::shuttle3());
435 slotShuttleAction(KdenliveSettings::shuttle4());
438 slotShuttleAction(KdenliveSettings::shuttle5());
443 void MainWindow::slotShuttleAction(int code) {
448 m_monitorManager->slotPlay();
451 m_monitorManager->slotPlay();
455 #endif /* NO_JOGSHUTTLE */
457 void MainWindow::configureNotifications() {
458 KNotifyConfigWidget::configure(this);
461 void MainWindow::slotFullScreen() {
462 KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
465 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
466 if (!m_activeDocument) return;
467 if (effect.isNull()) {
468 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
471 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
472 currentTimeLine->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
475 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
476 if (clipMonitor) clipMonitorDock->raise();
477 else projectMonitorDock->raise();
480 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
481 if (!m_activeDocument) return;
482 m_activeDocument->setProducerDuration(id, duration);
485 void MainWindow::slotConnectMonitors() {
487 m_projectList->setRenderer(m_clipMonitor->render);
488 connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
489 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
490 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
491 connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
492 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
494 connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
496 connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
498 connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
499 connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
501 connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
502 connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
505 void MainWindow::slotAdjustClipMonitor() {
506 clipMonitorDock->updateGeometry();
507 clipMonitorDock->adjustSize();
508 m_clipMonitor->resetSize();
511 void MainWindow::slotAdjustProjectMonitor() {
512 projectMonitorDock->updateGeometry();
513 projectMonitorDock->adjustSize();
514 m_projectMonitor->resetSize();
517 void MainWindow::setupActions() {
519 KActionCollection* collection = actionCollection();
520 m_timecodeFormat = new KComboBox(this);
521 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
522 m_timecodeFormat->addItem(i18n("Frames"));
524 statusProgressBar = new QProgressBar(this);
525 statusProgressBar->setMinimum(0);
526 statusProgressBar->setMaximum(100);
527 statusProgressBar->setMaximumWidth(150);
528 statusProgressBar->setVisible(false);
530 QWidget *w = new QWidget;
532 QHBoxLayout *layout = new QHBoxLayout;
533 w->setLayout(layout);
534 layout->setContentsMargins(5, 0, 5, 0);
535 QToolBar *toolbar = new QToolBar("statusToolBar", this);
538 m_toolGroup = new QActionGroup(this);
540 QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); border-style: inset; border:1px solid #999999;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:checked { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
542 m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
543 toolbar->addAction(m_buttonSelectTool);
544 m_buttonSelectTool->setCheckable(true);
545 m_buttonSelectTool->setChecked(true);
547 m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
548 toolbar->addAction(m_buttonRazorTool);
549 m_buttonRazorTool->setCheckable(true);
550 m_buttonRazorTool->setChecked(false);
552 m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
553 toolbar->addAction(m_buttonSpacerTool);
554 m_buttonSpacerTool->setCheckable(true);
555 m_buttonSpacerTool->setChecked(false);
557 m_toolGroup->addAction(m_buttonSelectTool);
558 m_toolGroup->addAction(m_buttonRazorTool);
559 m_toolGroup->addAction(m_buttonSpacerTool);
560 m_toolGroup->setExclusive(true);
561 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
563 QWidget * actionWidget;
564 actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
565 actionWidget->setMaximumWidth(24);
566 actionWidget->setMinimumHeight(17);
568 actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
569 actionWidget->setMaximumWidth(24);
570 actionWidget->setMinimumHeight(17);
572 actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
573 actionWidget->setMaximumWidth(24);
574 actionWidget->setMinimumHeight(17);
576 toolbar->setStyleSheet(style1);
577 connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
579 toolbar->addSeparator();
580 m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
581 toolbar->addAction(m_buttonFitZoom);
582 m_buttonFitZoom->setCheckable(false);
583 connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
585 actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
586 actionWidget->setMaximumWidth(24);
587 actionWidget->setMinimumHeight(17);
589 m_zoomSlider = new QSlider(Qt::Horizontal, this);
590 m_zoomSlider->setMaximum(13);
591 m_zoomSlider->setPageStep(1);
593 m_zoomSlider->setMaximumWidth(150);
594 m_zoomSlider->setMinimumWidth(100);
596 const int contentHeight = QFontMetrics(w->font()).height() + 8;
598 QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
599 style.append("QSlider::handle:horizontal { background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
601 m_zoomSlider->setStyleSheet(style);
603 //m_zoomSlider->height() + 5;
604 statusBar()->setMinimumHeight(contentHeight);
607 toolbar->addWidget(m_zoomSlider);
609 m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
610 toolbar->addAction(m_buttonVideoThumbs);
611 m_buttonVideoThumbs->setCheckable(true);
612 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
613 connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
615 m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
616 toolbar->addAction(m_buttonAudioThumbs);
617 m_buttonAudioThumbs->setCheckable(true);
618 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
619 connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
621 m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
622 toolbar->addAction(m_buttonShowMarkers);
623 m_buttonShowMarkers->setCheckable(true);
624 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
625 connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
627 m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
628 toolbar->addAction(m_buttonSnap);
629 m_buttonSnap->setCheckable(true);
630 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
631 connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
632 layout->addWidget(toolbar);
635 actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
636 actionWidget->setMaximumWidth(24);
637 actionWidget->setMinimumHeight(17);
639 actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
640 actionWidget->setMaximumWidth(24);
641 actionWidget->setMinimumHeight(17);
643 actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
644 actionWidget->setMaximumWidth(24);
645 actionWidget->setMinimumHeight(17);
647 actionWidget = toolbar->widgetForAction(m_buttonSnap);
648 actionWidget->setMaximumWidth(24);
649 actionWidget->setMinimumHeight(17);
651 m_messageLabel = new StatusBarMessageLabel(this);
652 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
654 statusBar()->addWidget(m_messageLabel, 10);
655 statusBar()->addWidget(statusProgressBar, 0);
656 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
657 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
658 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
659 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
660 m_messageLabel->hide();
662 collection->addAction("select_tool", m_buttonSelectTool);
663 collection->addAction("razor_tool", m_buttonRazorTool);
664 collection->addAction("spacer_tool", m_buttonSpacerTool);
666 collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
667 collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
668 collection->addAction("show_markers", m_buttonShowMarkers);
669 collection->addAction("snap", m_buttonSnap);
670 collection->addAction("zoom_fit", m_buttonFitZoom);
672 KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
673 collection->addAction("zoom_in", zoomIn);
674 connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
675 zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
677 KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
678 collection->addAction("zoom_out", zoomOut);
679 connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
680 zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
682 m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
683 collection->addAction("project_find", m_projectSearch);
684 connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
685 m_projectSearch->setShortcut(Qt::Key_Slash);
687 m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
688 collection->addAction("project_find_next", m_projectSearchNext);
689 connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
690 m_projectSearchNext->setShortcut(Qt::Key_F3);
691 m_projectSearchNext->setEnabled(false);
693 KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
694 collection->addAction("manage_profiles", profilesAction);
695 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
697 KAction* fileGHNS = KNS::standardAction(i18n("Download New Lumas..."), this, SLOT(slotGetNewStuff()), actionCollection(), "get_new_stuff");
699 KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
700 collection->addAction("project_settings", projectAction);
701 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
703 KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
704 collection->addAction("project_render", projectRender);
705 projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
706 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
708 KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
709 KShortcut playShortcut;
710 playShortcut.setPrimary(Qt::Key_Space);
711 playShortcut.setAlternate(Qt::Key_K);
712 monitorPlay->setShortcut(playShortcut);
713 collection->addAction("monitor_play", monitorPlay);
714 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
716 KAction *markIn = collection->addAction("mark_in");
717 markIn->setText(i18n("Set In Point"));
718 markIn->setShortcut(Qt::Key_I);
719 connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
723 KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
724 monitorSeekBackward->setShortcut(Qt::Key_J);
725 collection->addAction("monitor_seek_backward", monitorSeekBackward);
726 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
728 KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
729 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
730 collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
731 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
733 KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
734 monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
735 collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
736 connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
738 KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
739 monitorSeekForward->setShortcut(Qt::Key_L);
740 collection->addAction("monitor_seek_forward", monitorSeekForward);
741 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
743 KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
744 clipStart->setShortcut(Qt::Key_Home);
745 collection->addAction("seek_clip_start", clipStart);
746 connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
748 KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
749 clipEnd->setShortcut(Qt::Key_End);
750 collection->addAction("seek_clip_end", clipEnd);
751 connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
753 KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
754 projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
755 collection->addAction("seek_start", projectStart);
756 connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
758 KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
759 projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
760 collection->addAction("seek_end", projectEnd);
761 connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
763 KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
764 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
765 collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
766 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
768 KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
769 monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
770 collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
771 connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
773 KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
774 deleteTimelineClip->setShortcut(Qt::Key_Delete);
775 collection->addAction("delete_timeline_clip", deleteTimelineClip);
776 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
778 KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
779 collection->addAction("change_clip_speed", editTimelineClipSpeed);
780 connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
782 KAction *stickTransition = collection->addAction("auto_transition");
783 stickTransition->setText(i18n("Automatic Transition"));
784 connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
786 KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
787 cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
788 collection->addAction("cut_timeline_clip", cutTimelineClip);
789 connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
791 KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
792 collection->addAction("add_clip_marker", addClipMarker);
793 connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
795 KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
796 collection->addAction("delete_clip_marker", deleteClipMarker);
797 connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
799 KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
800 collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
801 connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
803 KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
804 collection->addAction("edit_clip_marker", editClipMarker);
805 connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
807 KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
808 collection->addAction("insert_space", insertSpace);
809 connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
811 KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
812 collection->addAction("delete_space", removeSpace);
813 connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
815 KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
816 collection->addAction("insert_track", insertTrack);
817 connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
819 KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
820 collection->addAction("delete_track", deleteTrack);
821 connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
823 KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
824 collection->addAction("change_track", changeTrack);
825 connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
827 KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
828 collection->addAction("add_guide", addGuide);
829 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
831 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
832 collection->addAction("delete_guide", delGuide);
833 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
835 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
836 collection->addAction("edit_guide", editGuide);
837 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
839 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
840 collection->addAction("delete_all_guides", delAllGuides);
841 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
843 QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
844 collection->addAction("paste_effects", pasteEffects);
845 connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
847 m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
849 KStandardAction::quit(this, SLOT(queryQuit()), collection);
851 KStandardAction::open(this, SLOT(openFile()), collection);
853 m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
855 KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
857 KStandardAction::openNew(this, SLOT(newFile()), collection);
859 KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
861 KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
863 KStandardAction::copy(this, SLOT(slotCopy()), collection);
865 KStandardAction::paste(this, SLOT(slotPaste()), collection);
867 KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
868 undo->setEnabled(false);
869 connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
871 KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
872 redo->setEnabled(false);
873 connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
875 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
877 connect(collection, SIGNAL(actionHovered(QAction*)),
878 this, SLOT(slotDisplayActionMessage(QAction*)));
879 //connect(collection, SIGNAL( clearStatusText() ),
880 //statusBar(), SLOT( clear() ) );
883 void MainWindow::slotDisplayActionMessage(QAction *a) {
884 statusBar()->showMessage(a->data().toString(), 3000);
887 void MainWindow::saveOptions() {
888 KdenliveSettings::self()->writeConfig();
889 KSharedConfigPtr config = KGlobal::config();
890 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
891 KConfigGroup treecolumns(config, "Project Tree");
892 treecolumns.writeEntry("columns", m_projectList->headerInfo());
896 void MainWindow::readOptions() {
897 KSharedConfigPtr config = KGlobal::config();
898 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
899 KConfigGroup initialGroup(config, "version");
900 if (!initialGroup.exists()) {
901 // this is our first run, show Wizard
902 Wizard *w = new Wizard(this);
903 if (w->exec() == QDialog::Accepted && w->isOk()) {
905 initialGroup.writeEntry("version", "0.7");
910 } else if (initialGroup.readEntry("version") == "0.7") {
911 //Add new settings from 0.7.1
912 if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
913 QString path = QDir::homePath() + "/kdenlive";
914 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
915 KdenliveSettings::setDefaultprojectfolder(path);
918 KConfigGroup treecolumns(config, "Project Tree");
919 const QByteArray state = treecolumns.readEntry("columns", QByteArray());
920 if (!state.isEmpty())
921 m_projectList->setHeaderInfo(state);
924 void MainWindow::newFile(bool showProjectSettings) {
927 QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
928 if (!showProjectSettings && m_timelineArea->count() == 0) {
929 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
930 profileName = KdenliveSettings::default_profile();
932 ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
933 if (w->exec() != QDialog::Accepted) return;
934 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
935 profileName = w->selectedProfile();
936 projectFolder = w->selectedFolder();
937 projectTracks = w->tracks();
940 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, this);
941 doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
942 TrackView *trackView = new TrackView(doc, this);
943 m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
944 if (m_timelineArea->count() == 1) {
945 connectDocumentInfo(doc);
946 connectDocument(trackView, doc);
947 } else m_timelineArea->setTabBarHidden(false);
948 m_closeAction->setEnabled(m_timelineArea->count() > 1);
951 void MainWindow::activateDocument() {
952 if (m_timelineArea->currentWidget() == NULL) return;
953 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
954 KdenliveDoc *currentDoc = currentTab->document();
955 connectDocumentInfo(currentDoc);
956 connectDocument(currentTab, currentDoc);
959 void MainWindow::closeCurrentDocument() {
960 QWidget *w = m_timelineArea->currentWidget();
962 // closing current document
963 int ix = m_timelineArea->currentIndex() + 1;
964 if (ix == m_timelineArea->count()) ix = 0;
965 m_timelineArea->setCurrentIndex(ix);
966 TrackView *tabToClose = (TrackView *) w;
967 KdenliveDoc *docToClose = tabToClose->document();
968 if (docToClose && docToClose->isModified()) {
969 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
970 case KMessageBox::Yes :
971 // save document here. If saving fails, return false;
974 case KMessageBox::Cancel :
980 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
981 if (m_timelineArea->count() == 1) {
982 m_timelineArea->setTabBarHidden(true);
983 m_closeAction->setEnabled(false);
987 if (m_timelineArea->count() == 0) {
988 m_activeDocument = NULL;
989 effectStack->clear();
990 transitionConfig->slotTransitionItemSelected(NULL, false);
994 bool MainWindow::saveFileAs(const QString &outputFileName) {
995 QDomDocument currentSceneList = m_projectMonitor->sceneList();
996 if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
999 // Save timeline thumbnails
1000 m_activeTimeline->projectView()->saveThumbnails();
1001 m_activeDocument->setUrl(KUrl(outputFileName));
1002 if (m_activeDocument->m_autosave == NULL) {
1003 m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1004 } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1005 setCaption(m_activeDocument->description());
1006 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1007 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1008 m_activeDocument->setModified(false);
1009 m_fileOpenRecent->addUrl(KUrl(outputFileName));
1013 bool MainWindow::saveFileAs() {
1014 // Check that the Kdenlive mime type is correctly installed
1015 QString mimetype = "application/x-kdenlive";
1016 KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1017 if (!mime) mimetype = "*.kdenlive";
1019 QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1020 if (outputFile.isEmpty()) return false;
1021 if (QFile::exists(outputFile)) {
1022 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
1024 return saveFileAs(outputFile);
1027 bool MainWindow::saveFile() {
1028 if (!m_activeDocument) return true;
1029 if (m_activeDocument->url().isEmpty()) {
1030 return saveFileAs();
1032 bool result = saveFileAs(m_activeDocument->url().path());
1033 m_activeDocument->m_autosave->resize(0);
1038 void MainWindow::openFile() {
1039 // Check that the Kdenlive mime type is correctly installed
1040 QString mimetype = "application/x-kdenlive";
1041 KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1042 if (!mime) mimetype = "*.kdenlive";
1044 KUrl url = KFileDialog::getOpenUrl(KUrl(), mimetype);
1045 if (url.isEmpty()) return;
1046 m_fileOpenRecent->addUrl(url);
1050 void MainWindow::openLastFile() {
1051 KSharedConfigPtr config = KGlobal::config();
1052 KUrl::List urls = m_fileOpenRecent->urls();
1053 if (urls.isEmpty()) newFile(false);
1054 else openFile(urls.last());
1057 void MainWindow::openFile(const KUrl &url) {
1058 // Check if the document is already opened
1059 const int ct = m_timelineArea->count();
1060 bool isOpened = false;
1062 for (i = 0; i < ct; i++) {
1063 TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1064 KdenliveDoc *doc = tab->document();
1065 if (doc->url() == url) {
1071 m_timelineArea->setCurrentIndex(i);
1075 // Check for backup file
1076 QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1077 if (!staleFiles.isEmpty()) {
1078 if (KMessageBox::questionYesNo(this,
1079 i18n("Auto-saved files exist. Do you want to recover them now?"),
1080 i18n("File Recovery"),
1081 KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1082 recoverFiles(staleFiles);
1085 // remove the stale files
1086 foreach(KAutoSaveFile *stale, staleFiles) {
1087 stale->open(QIODevice::ReadWrite);
1092 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1093 doOpenFile(url, NULL);
1096 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1098 doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
1099 if (stale == NULL) {
1100 stale = new KAutoSaveFile(url, doc);
1101 doc->m_autosave = stale;
1103 doc->m_autosave = stale;
1104 doc->setUrl(stale->managedFile());
1105 doc->setModified(true);
1106 stale->setParent(doc);
1108 connectDocumentInfo(doc);
1109 TrackView *trackView = new TrackView(doc, this);
1110 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1111 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1112 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1113 slotGotProgressInfo(QString(), -1);
1114 m_clipMonitor->refreshMonitor(true);
1117 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1118 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1119 foreach(KAutoSaveFile *stale, staleFiles) {
1120 /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1121 // show an error message; we could not steal the lockfile
1122 // maybe another application got to the file before us?
1126 kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1127 // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1128 if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1129 else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1134 void MainWindow::parseProfiles(const QString &mltPath) {
1135 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1137 //KdenliveSettings::setDefaulttmpfolder();
1138 if (!mltPath.isEmpty()) {
1139 KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1140 KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1143 if (KdenliveSettings::mltpath().isEmpty()) {
1144 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1146 if (KdenliveSettings::rendererpath().isEmpty()) {
1147 QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1148 if (!QFile::exists(inigoPath))
1149 inigoPath = KStandardDirs::findExe("inigo");
1150 else KdenliveSettings::setRendererpath(inigoPath);
1152 QStringList profilesFilter;
1153 profilesFilter << "*";
1154 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1156 if (profilesList.isEmpty()) {
1157 // Cannot find MLT path, try finding inigo
1158 QString profilePath = KdenliveSettings::rendererpath();
1159 if (!profilePath.isEmpty()) {
1160 profilePath = profilePath.section('/', 0, -3);
1161 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1162 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1165 if (profilesList.isEmpty()) {
1166 // Cannot find the MLT profiles, ask for location
1167 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1168 getUrl->fileDialog()->setMode(KFile::Directory);
1169 if (getUrl->exec() == QDialog::Rejected) {
1172 KUrl mltPath = getUrl->selectedUrl();
1174 if (mltPath.isEmpty()) ::exit(0);
1175 KdenliveSettings::setMltpath(mltPath.path());
1176 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1180 if (KdenliveSettings::rendererpath().isEmpty()) {
1181 // Cannot find the MLT inigo renderer, ask for location
1182 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1183 if (getUrl->exec() == QDialog::Rejected) {
1186 KUrl rendererPath = getUrl->selectedUrl();
1188 if (rendererPath.isEmpty()) ::exit(0);
1189 KdenliveSettings::setRendererpath(rendererPath.path());
1192 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1194 // Parse MLT profiles to build a list of available video formats
1195 if (profilesList.isEmpty()) parseProfiles();
1199 void MainWindow::slotEditProfiles() {
1200 ProfilesDialog *w = new ProfilesDialog;
1205 void MainWindow::slotEditProjectSettings() {
1206 QPoint p = m_activeDocument->getTracksCount();
1207 ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1209 if (w->exec() == QDialog::Accepted) {
1210 QString profile = w->selectedProfile();
1211 m_activeDocument->setProjectFolder(w->selectedFolder());
1212 if (m_activeDocument->profilePath() != profile) {
1213 // Profile was changed
1214 m_activeDocument->setProfilePath(profile);
1215 KdenliveSettings::setCurrent_profile(profile);
1216 KdenliveSettings::setProject_fps(m_activeDocument->fps());
1217 setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1218 m_monitorManager->resetProfiles(m_activeDocument->timecode());
1219 if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1220 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1222 // We need to desactivate & reactivate monitors to get a refresh
1223 m_monitorManager->switchMonitors();
1229 void MainWindow::slotRenderProject() {
1230 if (!m_renderWidget) {
1231 m_renderWidget = new RenderWidget(this);
1232 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)));
1233 if (m_activeDocument) {
1234 m_renderWidget->setProfile(m_activeDocument->mltProfile());
1235 m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1238 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1239 if (currentTab) m_renderWidget->setTimeline(currentTab);
1240 m_renderWidget->setDocument(m_activeDocument);*/
1241 m_renderWidget->show();
1244 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &overlay_args, const QStringList &avformat_args, bool zoneOnly, bool playAfter, double guideStart, double guideEnd) {
1245 if (dest.isEmpty()) return;
1248 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1249 if (currentTab && zoneOnly) {
1250 in = currentTab->inPoint();
1251 out = currentTab->outPoint();
1253 KTemporaryFile temp;
1254 temp.setAutoRemove(false);
1255 temp.setSuffix(".westley");
1257 m_projectMonitor->saveSceneList(temp.fileName());
1260 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1261 else if (guideStart != -1) {
1262 args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1264 if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1265 QString videoPlayer = "-";
1267 videoPlayer = KdenliveSettings::defaultplayerapp();
1268 if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
1270 if (!QFile::exists(KdenliveSettings::rendererpath())) {
1271 KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1274 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1275 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1276 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1277 QProcess::startDetached(renderer, args);
1279 KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1283 void MainWindow::slotUpdateMousePosition(int pos) {
1284 if (m_activeDocument)
1285 switch (m_timecodeFormat->currentIndex()) {
1287 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1290 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1294 void MainWindow::slotUpdateDocumentState(bool modified) {
1295 setCaption(m_activeDocument->description(), modified);
1296 m_saveAction->setEnabled(modified);
1298 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1299 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1301 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1302 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1306 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1307 if (m_activeDocument) {
1308 if (m_activeDocument == doc) return;
1309 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1311 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1314 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1315 //m_projectMonitor->stop();
1316 m_closeAction->setEnabled(m_timelineArea->count() > 1);
1317 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
1318 if (m_activeDocument) {
1319 if (m_activeDocument == doc) return;
1320 m_activeDocument->backupMltPlaylist();
1321 if (m_activeTimeline) {
1322 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1323 disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1324 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1325 disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1328 disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1329 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1330 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1331 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1332 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1333 disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1334 disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1335 disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1336 disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1337 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1338 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1339 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1340 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1341 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1342 disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1343 disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1344 disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1345 disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1346 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1347 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1348 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1349 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1350 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1351 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1352 disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1353 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1354 disconnect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), m_activeTimeline->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1355 disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1356 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1357 disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1358 disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1359 effectStack->clear();
1361 m_activeDocument->setRenderer(NULL);
1362 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1363 m_clipMonitor->stop();
1365 KdenliveSettings::setCurrent_profile(doc->profilePath());
1366 KdenliveSettings::setProject_fps(doc->fps());
1367 m_monitorManager->resetProfiles(doc->timecode());
1368 m_projectList->setDocument(doc);
1369 transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1370 effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1371 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1372 connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1373 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1374 connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1375 connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1376 connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1377 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1378 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1379 connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1380 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1381 connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1382 connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1383 connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1384 connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1385 connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1387 connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1388 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1389 connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1392 connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1393 connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1394 connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1395 connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1396 m_zoomSlider->setValue(doc->zoom());
1397 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1398 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1399 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1400 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1402 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1405 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1406 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1407 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1408 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1409 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1410 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1411 connect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), trackView->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1412 connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1413 connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1415 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1416 connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1417 connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1419 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1420 m_activeTimeline = trackView;
1421 if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
1422 doc->setRenderer(m_projectMonitor->render);
1423 m_commandStack->setActiveStack(doc->commandStack());
1424 KdenliveSettings::setProject_display_ratio(doc->dar());
1425 m_projectList->updateAllClips();
1426 //doc->clipManager()->checkAudioThumbs();
1428 //m_overView->setScene(trackView->projectScene());
1429 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1430 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1432 setCaption(doc->description(), doc->isModified());
1433 m_saveAction->setEnabled(doc->isModified());
1434 m_activeDocument = doc;
1437 void MainWindow::slotGuidesUpdated() {
1438 if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1441 void MainWindow::slotPreferences(int page, int option) {
1442 //An instance of your dialog could be already created and could be
1443 // cached, in which case you want to display the cached dialog
1444 // instead of creating another one
1445 if (KConfigDialog::showDialog("settings")) {
1446 KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1447 if (page != -1) d->showPage(page, option);
1452 // KConfigDialog didn't find an instance of this dialog, so lets
1454 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1455 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1456 connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1458 if (page != -1) dialog->showPage(page, option);
1461 void MainWindow::updateConfiguration() {
1462 //TODO: we should apply settings to all projects, not only the current one
1463 if (m_activeTimeline) {
1464 m_activeTimeline->refresh();
1465 m_activeTimeline->projectView()->checkAutoScroll();
1466 m_activeTimeline->projectView()->checkTrackHeight();
1467 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1469 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1470 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1471 #ifndef NO_JOGSHUTTLE
1472 activateShuttleDevice();
1473 #endif /* NO_JOGSHUTTLE */
1477 void MainWindow::slotSwitchVideoThumbs() {
1478 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1479 if (m_activeTimeline) {
1480 m_activeTimeline->refresh();
1482 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1485 void MainWindow::slotSwitchAudioThumbs() {
1486 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1487 if (m_activeTimeline) {
1488 m_activeTimeline->refresh();
1489 m_activeTimeline->projectView()->checkAutoScroll();
1490 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1492 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1495 void MainWindow::slotSwitchMarkersComments() {
1496 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1497 if (m_activeTimeline) {
1498 m_activeTimeline->refresh();
1500 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1503 void MainWindow::slotSwitchSnap() {
1504 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1505 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1509 void MainWindow::slotDeleteTimelineClip() {
1510 if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1511 else if (m_activeTimeline) {
1512 m_activeTimeline->projectView()->deleteSelectedClips();
1516 void MainWindow::slotChangeClipSpeed() {
1517 if (m_activeTimeline) {
1518 m_activeTimeline->projectView()->changeClipSpeed();
1522 void MainWindow::slotAddClipMarker() {
1523 DocClipBase *clip = NULL;
1525 if (m_projectMonitor->isActive()) {
1526 if (m_activeTimeline) {
1527 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1529 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1530 clip = item->baseClip();
1534 clip = m_clipMonitor->activeClip();
1535 pos = m_clipMonitor->position();
1538 m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1541 QString id = clip->getId();
1542 CommentedTime marker(pos, i18n("Marker"));
1543 MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1544 if (d.exec() == QDialog::Accepted) {
1545 m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1547 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1550 void MainWindow::slotDeleteClipMarker() {
1551 DocClipBase *clip = NULL;
1553 if (m_projectMonitor->isActive()) {
1554 if (m_activeTimeline) {
1555 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1557 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1558 clip = item->baseClip();
1562 clip = m_clipMonitor->activeClip();
1563 pos = m_clipMonitor->position();
1566 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1570 QString id = clip->getId();
1571 QString comment = clip->markerComment(pos);
1572 if (comment.isEmpty()) {
1573 m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1576 m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
1577 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1581 void MainWindow::slotDeleteAllClipMarkers() {
1582 DocClipBase *clip = NULL;
1583 if (m_projectMonitor->isActive()) {
1584 if (m_activeTimeline) {
1585 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1587 clip = item->baseClip();
1591 clip = m_clipMonitor->activeClip();
1594 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1597 m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
1598 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1601 void MainWindow::slotEditClipMarker() {
1602 DocClipBase *clip = NULL;
1604 if (m_projectMonitor->isActive()) {
1605 if (m_activeTimeline) {
1606 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1608 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1609 clip = item->baseClip();
1613 clip = m_clipMonitor->activeClip();
1614 pos = m_clipMonitor->position();
1617 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1621 QString id = clip->getId();
1622 QString oldcomment = clip->markerComment(pos);
1623 if (oldcomment.isEmpty()) {
1624 m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1628 CommentedTime marker(pos, oldcomment);
1629 MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
1630 if (d.exec() == QDialog::Accepted) {
1631 m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1632 if (d.newMarker().time() != pos) {
1633 // remove old marker
1634 m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
1636 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1640 void MainWindow::slotAddGuide() {
1641 if (m_activeTimeline)
1642 m_activeTimeline->projectView()->slotAddGuide();
1645 void MainWindow::slotInsertSpace() {
1646 if (m_activeTimeline)
1647 m_activeTimeline->projectView()->slotInsertSpace();
1650 void MainWindow::slotRemoveSpace() {
1651 if (m_activeTimeline)
1652 m_activeTimeline->projectView()->slotRemoveSpace();
1655 void MainWindow::slotInsertTrack(int ix) {
1656 m_projectMonitor->activateMonitor();
1657 if (m_activeTimeline)
1658 m_activeTimeline->projectView()->slotInsertTrack(ix);
1661 void MainWindow::slotDeleteTrack(int ix) {
1662 m_projectMonitor->activateMonitor();
1663 if (m_activeTimeline)
1664 m_activeTimeline->projectView()->slotDeleteTrack(ix);
1667 void MainWindow::slotChangeTrack(int ix) {
1668 m_projectMonitor->activateMonitor();
1669 if (m_activeTimeline)
1670 m_activeTimeline->projectView()->slotChangeTrack(ix);
1673 void MainWindow::slotEditGuide() {
1674 if (m_activeTimeline)
1675 m_activeTimeline->projectView()->slotEditGuide();
1678 void MainWindow::slotDeleteGuide() {
1679 if (m_activeTimeline)
1680 m_activeTimeline->projectView()->slotDeleteGuide();
1683 void MainWindow::slotDeleteAllGuides() {
1684 if (m_activeTimeline)
1685 m_activeTimeline->projectView()->slotDeleteAllGuides();
1688 void MainWindow::slotCutTimelineClip() {
1689 if (m_activeTimeline) {
1690 m_activeTimeline->projectView()->cutSelectedClips();
1694 void MainWindow::slotAddProjectClip(KUrl url) {
1695 if (m_activeDocument)
1696 m_activeDocument->slotAddClipFile(url, QString());
1699 void MainWindow::slotAddTransition(QAction *result) {
1700 if (!result) return;
1701 QStringList info = result->data().toStringList();
1702 if (info.isEmpty()) return;
1703 QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
1704 if (m_activeTimeline && !transition.isNull()) {
1705 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
1709 void MainWindow::slotAddVideoEffect(QAction *result) {
1710 if (!result) return;
1711 QStringList info = result->data().toStringList();
1712 if (info.isEmpty()) return;
1713 QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
1714 slotAddEffect(effect);
1717 void MainWindow::slotAddAudioEffect(QAction *result) {
1718 if (!result) return;
1719 QStringList info = result->data().toStringList();
1720 if (info.isEmpty()) return;
1721 QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
1722 slotAddEffect(effect);
1725 void MainWindow::slotAddCustomEffect(QAction *result) {
1726 if (!result) return;
1727 QStringList info = result->data().toStringList();
1728 if (info.isEmpty()) return;
1729 QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
1730 slotAddEffect(effect);
1733 void MainWindow::slotZoomIn() {
1734 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1737 void MainWindow::slotZoomOut() {
1738 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1741 void MainWindow::slotFitZoom() {
1742 if (m_activeTimeline) {
1743 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1747 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1748 statusProgressBar->setValue(progress);
1749 if (progress >= 0) {
1750 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1751 statusProgressBar->setVisible(true);
1753 m_messageLabel->setMessage(QString(), DefaultMessage);
1754 statusProgressBar->setVisible(false);
1758 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1759 if (clip->clipType() == TEXT) {
1760 QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1761 QString path = clip->getProperty("resource");
1762 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1764 doc.setContent(clip->getProperty("xmldata"));
1765 dia_ui->setXml(doc);
1766 if (dia_ui->exec() == QDialog::Accepted) {
1767 QPixmap pix = dia_ui->renderedPixmap();
1769 //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1770 //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1771 QMap <QString, QString> newprops;
1772 newprops.insert("xmldata", dia_ui->xml().toString());
1773 EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1774 m_activeDocument->commandStack()->push(command);
1775 m_clipMonitor->refreshMonitor(true);
1776 m_activeDocument->setModified(true);
1780 //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1783 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1784 connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1785 if (dia.exec() == QDialog::Accepted) {
1786 EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1787 m_activeDocument->commandStack()->push(command);
1789 //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1790 if (dia.needsTimelineRefresh()) {
1791 // update clip occurences in timeline
1792 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1797 void MainWindow::customEvent(QEvent* e) {
1798 if (e->type() == QEvent::User) {
1799 // The timeline playing position changed...
1800 kDebug() << "RECIEVED JOG EVEMNT!!!";
1803 void MainWindow::slotActivateEffectStackView() {
1804 effectStack->raiseWindow(effectStackDock);
1807 void MainWindow::slotActivateTransitionView() {
1808 transitionConfig->raiseWindow(transitionConfigDock);
1811 void MainWindow::slotSnapRewind() {
1812 if (m_projectMonitor->isActive()) {
1813 if (m_activeTimeline)
1814 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1815 } else m_clipMonitor->slotSeekToPreviousSnap();
1818 void MainWindow::slotSnapForward() {
1819 if (m_projectMonitor->isActive()) {
1820 if (m_activeTimeline)
1821 m_activeTimeline->projectView()->slotSeekToNextSnap();
1822 } else m_clipMonitor->slotSeekToNextSnap();
1825 void MainWindow::slotClipStart() {
1826 if (m_projectMonitor->isActive()) {
1827 if (m_activeTimeline)
1828 m_activeTimeline->projectView()->clipStart();
1832 void MainWindow::slotClipEnd() {
1833 if (m_projectMonitor->isActive()) {
1834 if (m_activeTimeline)
1835 m_activeTimeline->projectView()->clipEnd();
1839 void MainWindow::slotChangeTool(QAction * action) {
1840 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1841 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1842 else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
1845 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1846 if (m_activeDocument && m_activeTimeline) {
1847 //m_activeDocument->setTool(tool);
1848 m_activeTimeline->projectView()->setTool(tool);
1852 void MainWindow::slotCopy() {
1853 if (!m_activeDocument || !m_activeTimeline) return;
1854 m_activeTimeline->projectView()->copyClip();
1857 void MainWindow::slotPaste() {
1858 if (!m_activeDocument || !m_activeTimeline) return;
1859 m_activeTimeline->projectView()->pasteClip();
1862 void MainWindow::slotPasteEffects() {
1863 if (!m_activeDocument || !m_activeTimeline) return;
1864 m_activeTimeline->projectView()->pasteClipEffects();
1867 void MainWindow::slotFind() {
1868 if (!m_activeDocument || !m_activeTimeline) return;
1869 m_projectSearch->setEnabled(false);
1870 m_findActivated = true;
1871 m_findString = QString();
1872 m_activeTimeline->projectView()->initSearchStrings();
1873 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1874 m_findTimer.start(5000);
1875 qApp->installEventFilter(this);
1878 void MainWindow::slotFindNext() {
1879 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1880 statusBar()->showMessage(i18n("Found : %1", m_findString));
1882 statusBar()->showMessage(i18n("Reached end of project"));
1884 m_findTimer.start(4000);
1887 void MainWindow::findAhead() {
1888 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1889 m_projectSearchNext->setEnabled(true);
1890 statusBar()->showMessage(i18n("Found : %1", m_findString));
1892 m_projectSearchNext->setEnabled(false);
1893 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1897 void MainWindow::findTimeout() {
1898 m_projectSearchNext->setEnabled(false);
1899 m_findActivated = false;
1900 m_findString = QString();
1901 statusBar()->showMessage(i18n("Find stopped"), 3000);
1902 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1903 m_projectSearch->setEnabled(true);
1904 removeEventFilter(this);
1907 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1908 if (m_findActivated) {
1909 if (ke->key() == Qt::Key_Backspace) {
1910 m_findString = m_findString.left(m_findString.length() - 1);
1912 if (!m_findString.isEmpty()) {
1918 m_findTimer.start(4000);
1921 } else if (ke->key() == Qt::Key_Escape) {
1925 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1926 m_findString += ke->text();
1930 m_findTimer.start(4000);
1934 } else KXmlGuiWindow::keyPressEvent(ke);
1938 /** Gets called when the window gets hidden */
1939 void MainWindow::hideEvent(QHideEvent *event) {
1940 // kDebug() << "I was hidden";
1941 // issue http://www.kdenlive.org/mantis/view.php?id=231
1942 if (this->isMinimized()) {
1943 // kDebug() << "I am minimized";
1944 if (m_monitorManager) m_monitorManager->stopActiveMonitor();
1948 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1949 if (m_findActivated) {
1950 if (event->type() == QEvent::ShortcutOverride) {
1951 QKeyEvent* ke = (QKeyEvent*) event;
1952 if (ke->text().trimmed().isEmpty()) return false;
1955 } else return false;
1957 // pass the event on to the parent class
1958 return QMainWindow::eventFilter(obj, event);
1962 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1963 KDialog *dialog = new KDialog(this);
1964 dialog->setCaption("Save clip zone");
1965 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1967 QWidget *widget = new QWidget(dialog);
1968 dialog->setMainWidget(widget);
1970 QVBoxLayout *vbox = new QVBoxLayout(widget);
1971 QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1972 QString path = m_activeDocument->projectFolder().path();
1974 path.append("untitled.westley");
1975 KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1976 url->setFilter("video/mlt-playlist");
1977 QLabel *label2 = new QLabel(i18n("Description:"), this);
1978 KLineEdit *edit = new KLineEdit(this);
1979 vbox->addWidget(label1);
1980 vbox->addWidget(url);
1981 vbox->addWidget(label2);
1982 vbox->addWidget(edit);
1983 if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1987 void MainWindow::slotSetInPoint() {
1988 if (m_clipMonitor->isActive()) {
1989 m_clipMonitor->slotSetZoneStart();
1990 } else m_activeTimeline->projectView()->setInPoint();
1993 void MainWindow::slotSetOutPoint() {
1994 if (m_clipMonitor->isActive()) {
1995 m_clipMonitor->slotSetZoneEnd();
1996 } else m_activeTimeline->projectView()->setOutPoint();
1999 void MainWindow::slotGetNewStuff() {
2000 kDebug() << "// GET NEW STUFF";
2001 //KNS::Entry::List download();
2002 KNS::Entry::List entries = KNS::Engine::download();
2003 int numberInstalled = 0;
2004 // list of changed entries
2005 kDebug() << "// PARSING KNS";
2006 foreach(KNS::Entry* entry, entries) {
2007 // care only about installed ones
2008 if (entry->status() == KNS::Entry::Installed) {
2009 foreach(const QString &file, entry->installedFiles()) {
2010 kDebug() << "// CURRENTLY INSTALLED: " << file;
2014 qDeleteAll(entries);
2015 initEffects::refreshLumas();
2018 void MainWindow::slotAutoTransition() {
2019 m_activeTimeline->projectView()->autoTransition();
2022 #include "mainwindow.moc"