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>
55 #include <mlt++/Mlt.h>
57 #include "mainwindow.h"
58 #include "kdenlivesettings.h"
59 #include "kdenlivesettingsdialog.h"
60 #include "initeffects.h"
61 #include "profilesdialog.h"
62 #include "projectsettings.h"
64 #include "clipmanager.h"
65 #include "projectlist.h"
67 #include "recmonitor.h"
68 #include "monitormanager.h"
69 #include "kdenlivedoc.h"
70 #include "trackview.h"
71 #include "customtrackview.h"
72 #include "effectslistview.h"
73 #include "effectstackview.h"
74 #include "transitionsettings.h"
75 #include "renderwidget.h"
78 #include "jogshuttle.h"
79 #endif /* NO_JOGSHUTTLE */
80 #include "clipproperties.h"
82 #include "editclipcommand.h"
83 #include "titlewidget.h"
84 #include "markerdialog.h"
87 static const int ID_STATUS_MSG = 1;
88 static const int ID_EDITMODE_MSG = 2;
89 static const int ID_TIMELINE_MSG = 3;
90 static const int ID_TIMELINE_BUTTONS = 5;
91 static const int ID_TIMELINE_POS = 6;
92 static const int ID_TIMELINE_FORMAT = 7;
98 EffectsList MainWindow::videoEffects;
99 EffectsList MainWindow::audioEffects;
100 EffectsList MainWindow::customEffects;
101 EffectsList MainWindow::transitions;
103 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
104 : KXmlGuiWindow(parent),
105 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
106 #ifndef NO_JOGSHUTTLE
108 #endif /* NO_JOGSHUTTLE */
109 m_findActivated(false), m_initialized(false) {
110 setlocale(LC_NUMERIC, "POSIX");
111 setFont(KGlobalSettings::toolBarFont());
112 parseProfiles(MltPath);
113 m_commandStack = new QUndoGroup;
114 m_timelineArea = new KTabWidget(this);
115 m_timelineArea->setTabReorderingEnabled(true);
116 m_timelineArea->setTabBarHidden(true);
118 QToolButton *closeTabButton = new QToolButton;
119 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
120 closeTabButton->setIcon(KIcon("tab-close"));
121 closeTabButton->adjustSize();
122 closeTabButton->setToolTip(i18n("Close the current tab"));
123 m_timelineArea->setCornerWidget(closeTabButton);
124 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
126 connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
127 m_findTimer.setSingleShot(true);
129 initEffects::parseEffectFiles();
130 //initEffects::parseCustomEffectsFile();
132 m_monitorManager = new MonitorManager();
134 projectListDock = new QDockWidget(i18n("Project Tree"), this);
135 projectListDock->setObjectName("project_tree");
136 m_projectList = new ProjectList(this);
137 projectListDock->setWidget(m_projectList);
138 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
140 effectListDock = new QDockWidget(i18n("Effect List"), this);
141 effectListDock->setObjectName("effect_list");
142 m_effectList = new EffectsListView();
144 //m_effectList = new KListWidget(this);
145 effectListDock->setWidget(m_effectList);
146 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
148 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
149 effectStackDock->setObjectName("effect_stack");
150 effectStack = new EffectStackView(this);
151 effectStackDock->setWidget(effectStack);
152 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
154 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
155 transitionConfigDock->setObjectName("transition");
156 transitionConfig = new TransitionSettings(this);
157 transitionConfigDock->setWidget(transitionConfig);
158 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
160 KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
161 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
165 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
166 clipMonitorDock->setObjectName("clip_monitor");
167 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
168 clipMonitorDock->setWidget(m_clipMonitor);
169 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
170 //m_clipMonitor->stop();
172 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
173 projectMonitorDock->setObjectName("project_monitor");
174 m_projectMonitor = new Monitor("project", m_monitorManager, this);
175 projectMonitorDock->setWidget(m_projectMonitor);
176 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
178 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
179 recMonitorDock->setObjectName("record_monitor");
180 m_recMonitor = new RecMonitor("record", this);
181 recMonitorDock->setWidget(m_recMonitor);
182 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
184 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
185 connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
187 undoViewDock = new QDockWidget(i18n("Undo History"), this);
188 undoViewDock->setObjectName("undo_history");
189 m_undoView = new QUndoView(this);
190 m_undoView->setCleanIcon(KIcon("edit-clear"));
191 m_undoView->setEmptyLabel(i18n("Clean"));
192 undoViewDock->setWidget(m_undoView);
193 m_undoView->setGroup(m_commandStack);
194 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
196 //overviewDock = new QDockWidget(i18n("Project Overview"), this);
197 //overviewDock->setObjectName("project_overview");
198 //m_overView = new CustomTrackView(NULL, NULL, this);
199 //overviewDock->setWidget(m_overView);
200 //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
203 //tabifyDockWidget(projectListDock, effectListDock);
204 tabifyDockWidget(projectListDock, effectStackDock);
205 tabifyDockWidget(projectListDock, transitionConfigDock);
206 //tabifyDockWidget(projectListDock, undoViewDock);
209 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
210 tabifyDockWidget(clipMonitorDock, recMonitorDock);
211 setCentralWidget(m_timelineArea);
214 //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
216 m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
217 m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), static_cast<QMenu*>(factory()->container("marker_menu", this)));
219 // build effects menus
221 QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
223 QStringList effectInfo;
224 QMap<QString, QStringList> effectsList;
225 for (int ix = 0; ix < videoEffects.count(); ix++) {
226 effectInfo = videoEffects.effectIdInfo(ix);
227 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
230 foreach(QStringList value, effectsList) {
231 action = new QAction(value.at(0), this);
232 action->setData(value);
233 videoEffectsMenu->addAction(action);
236 QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
240 for (int ix = 0; ix < audioEffects.count(); ix++) {
241 effectInfo = audioEffects.effectIdInfo(ix);
242 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
245 foreach(QStringList value, effectsList) {
246 action = new QAction(value.at(0), this);
247 action->setData(value);
248 audioEffectsMenu->addAction(action);
251 m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
253 if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
254 else m_customEffectsMenu->setEnabled(true);
257 for (int ix = 0; ix < customEffects.count(); ix++) {
258 effectInfo = customEffects.effectIdInfo(ix);
259 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
262 foreach(QStringList value, effectsList) {
263 action = new QAction(value.at(0), this);
264 action->setData(value);
265 m_customEffectsMenu->addAction(action);
268 QMenu *newEffect = new QMenu(this);
269 newEffect->addMenu(videoEffectsMenu);
270 newEffect->addMenu(audioEffectsMenu);
271 newEffect->addMenu(m_customEffectsMenu);
272 effectStack->setMenu(newEffect);
275 QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
276 const QList<QAction *> viewActions = createPopupMenu()->actions();
277 viewMenu->insertActions(NULL, viewActions);
279 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
280 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
281 connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
283 m_timelineContextMenu = new QMenu(this);
284 m_timelineContextClipMenu = new QMenu(this);
285 m_timelineContextTransitionMenu = new QMenu(this);
288 QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
289 QStringList effects = transitions.effectNames();
292 for (int ix = 0; ix < transitions.count(); ix++) {
293 effectInfo = transitions.effectIdInfo(ix);
294 effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
296 foreach(QStringList value, effectsList) {
297 action = new QAction(value.at(0), this);
298 action->setData(value);
299 transitionsMenu->addAction(action);
301 connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
303 m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
304 m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
305 m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
307 m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
308 m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
309 m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
310 m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
311 m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
313 QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
314 m_timelineContextClipMenu->addMenu(markersMenu);
315 m_timelineContextClipMenu->addMenu(transitionsMenu);
316 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
317 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
318 //TODO: re-enable custom effects menu when it is implemented
319 m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
321 m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
322 m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
324 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
325 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
326 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
327 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
328 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
329 connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
331 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
332 slotConnectMonitors();
334 // Open or create a file. Command line argument passed in Url has
335 // precedence, then "openlastproject", then just a plain empty file.
336 // If opening Url fails, openlastproject will _not_ be used.
337 if (!Url.isEmpty()) {
340 if (KdenliveSettings::openlastproject()) {
344 if (m_timelineArea->count() == 0) {
348 #ifndef NO_JOGSHUTTLE
349 activateShuttleDevice();
350 #endif /* NO_JOGSHUTTLE */
351 projectListDock->raise();
354 void MainWindow::queryQuit() {
355 kDebug() << "----- SAVING CONFUIG";
356 if (queryClose()) kapp->quit();
360 bool MainWindow::queryClose() {
362 if (m_monitorManager) m_monitorManager->stopActiveMonitor();
363 if (m_activeDocument && m_activeDocument->isModified()) {
364 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
365 case KMessageBox::Yes :
366 // save document here. If saving fails, return false;
368 case KMessageBox::No :
377 void MainWindow::saveProperties(KConfig*) {
378 // save properties here,used by session management
383 void MainWindow::readProperties(KConfig *config) {
384 // read properties here,used by session management
385 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
386 openFile(KUrl(Lastproject));
389 void MainWindow::slotReloadEffects() {
390 initEffects::parseCustomEffectsFile();
391 m_customEffectsMenu->clear();
392 const QStringList effects = customEffects.effectNames();
394 if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
395 else m_customEffectsMenu->setEnabled(true);
397 foreach(const QString &name, effects) {
398 action = new QAction(name, this);
399 action->setData(name);
400 m_customEffectsMenu->addAction(action);
402 m_effectList->reloadEffectList();
405 #ifndef NO_JOGSHUTTLE
406 void MainWindow::activateShuttleDevice() {
407 if (m_jogProcess) delete m_jogProcess;
409 if (KdenliveSettings::enableshuttle() == false) return;
410 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
411 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
412 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
413 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
414 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
415 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
416 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
419 void MainWindow::slotShuttleButton(int code) {
422 slotShuttleAction(KdenliveSettings::shuttle1());
425 slotShuttleAction(KdenliveSettings::shuttle2());
428 slotShuttleAction(KdenliveSettings::shuttle3());
431 slotShuttleAction(KdenliveSettings::shuttle4());
434 slotShuttleAction(KdenliveSettings::shuttle5());
439 void MainWindow::slotShuttleAction(int code) {
444 m_monitorManager->slotPlay();
447 m_monitorManager->slotPlay();
451 #endif /* NO_JOGSHUTTLE */
453 void MainWindow::configureNotifications() {
454 KNotifyConfigWidget::configure(this);
457 void MainWindow::slotFullScreen() {
458 KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
461 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
462 if (!m_activeDocument) return;
463 if (effect.isNull()) {
464 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
467 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
468 currentTimeLine->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
471 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
472 if (clipMonitor) clipMonitorDock->raise();
473 else projectMonitorDock->raise();
476 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
477 if (!m_activeDocument) return;
478 m_activeDocument->setProducerDuration(id, duration);
481 void MainWindow::slotConnectMonitors() {
483 m_projectList->setRenderer(m_clipMonitor->render);
484 connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
485 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
486 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
487 connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
488 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 > &)));
490 connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
492 connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
494 connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
495 connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
497 connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
498 connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
501 void MainWindow::slotAdjustClipMonitor() {
502 clipMonitorDock->updateGeometry();
503 clipMonitorDock->adjustSize();
504 m_clipMonitor->resetSize();
507 void MainWindow::slotAdjustProjectMonitor() {
508 projectMonitorDock->updateGeometry();
509 projectMonitorDock->adjustSize();
510 m_projectMonitor->resetSize();
513 void MainWindow::setupActions() {
515 KActionCollection* collection = actionCollection();
516 m_timecodeFormat = new KComboBox(this);
517 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
518 m_timecodeFormat->addItem(i18n("Frames"));
520 statusProgressBar = new QProgressBar(this);
521 statusProgressBar->setMinimum(0);
522 statusProgressBar->setMaximum(100);
523 statusProgressBar->setMaximumWidth(150);
524 statusProgressBar->setVisible(false);
526 QWidget *w = new QWidget;
528 QHBoxLayout *layout = new QHBoxLayout;
529 w->setLayout(layout);
530 layout->setContentsMargins(5, 0, 5, 0);
531 QToolBar *toolbar = new QToolBar("statusToolBar", this);
534 m_toolGroup = new QActionGroup(this);
536 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;}";
538 m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
539 toolbar->addAction(m_buttonSelectTool);
540 m_buttonSelectTool->setCheckable(true);
541 m_buttonSelectTool->setChecked(true);
543 m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
544 toolbar->addAction(m_buttonRazorTool);
545 m_buttonRazorTool->setCheckable(true);
546 m_buttonRazorTool->setChecked(false);
548 m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
549 toolbar->addAction(m_buttonSpacerTool);
550 m_buttonSpacerTool->setCheckable(true);
551 m_buttonSpacerTool->setChecked(false);
553 m_toolGroup->addAction(m_buttonSelectTool);
554 m_toolGroup->addAction(m_buttonRazorTool);
555 m_toolGroup->addAction(m_buttonSpacerTool);
556 m_toolGroup->setExclusive(true);
557 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
559 QWidget * actionWidget;
560 actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
561 actionWidget->setMaximumWidth(24);
562 actionWidget->setMinimumHeight(17);
564 actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
565 actionWidget->setMaximumWidth(24);
566 actionWidget->setMinimumHeight(17);
568 actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
569 actionWidget->setMaximumWidth(24);
570 actionWidget->setMinimumHeight(17);
572 toolbar->setStyleSheet(style1);
573 connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
575 toolbar->addSeparator();
576 m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
577 toolbar->addAction(m_buttonFitZoom);
578 m_buttonFitZoom->setCheckable(false);
579 connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
581 actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
582 actionWidget->setMaximumWidth(24);
583 actionWidget->setMinimumHeight(17);
585 m_zoomSlider = new QSlider(Qt::Horizontal, this);
586 m_zoomSlider->setMaximum(13);
587 m_zoomSlider->setPageStep(1);
589 m_zoomSlider->setMaximumWidth(150);
590 m_zoomSlider->setMinimumWidth(100);
592 const int contentHeight = QFontMetrics(w->font()).height() + 8;
594 QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
595 style.append("QSlider::handle:horizontal { background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
597 m_zoomSlider->setStyleSheet(style);
599 //m_zoomSlider->height() + 5;
600 statusBar()->setMinimumHeight(contentHeight);
603 toolbar->addWidget(m_zoomSlider);
605 m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
606 toolbar->addAction(m_buttonVideoThumbs);
607 m_buttonVideoThumbs->setCheckable(true);
608 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
609 connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
611 m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
612 toolbar->addAction(m_buttonAudioThumbs);
613 m_buttonAudioThumbs->setCheckable(true);
614 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
615 connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
617 m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
618 toolbar->addAction(m_buttonShowMarkers);
619 m_buttonShowMarkers->setCheckable(true);
620 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
621 connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
623 m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
624 toolbar->addAction(m_buttonSnap);
625 m_buttonSnap->setCheckable(true);
626 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
627 connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
628 layout->addWidget(toolbar);
631 actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
632 actionWidget->setMaximumWidth(24);
633 actionWidget->setMinimumHeight(17);
635 actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
636 actionWidget->setMaximumWidth(24);
637 actionWidget->setMinimumHeight(17);
639 actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
640 actionWidget->setMaximumWidth(24);
641 actionWidget->setMinimumHeight(17);
643 actionWidget = toolbar->widgetForAction(m_buttonSnap);
644 actionWidget->setMaximumWidth(24);
645 actionWidget->setMinimumHeight(17);
647 m_messageLabel = new StatusBarMessageLabel(this);
648 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
650 statusBar()->addWidget(m_messageLabel, 10);
651 statusBar()->addWidget(statusProgressBar, 0);
652 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
653 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
654 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
655 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
656 m_messageLabel->hide();
658 collection->addAction("select_tool", m_buttonSelectTool);
659 collection->addAction("razor_tool", m_buttonRazorTool);
660 collection->addAction("spacer_tool", m_buttonSpacerTool);
662 collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
663 collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
664 collection->addAction("show_markers", m_buttonShowMarkers);
665 collection->addAction("snap", m_buttonSnap);
666 collection->addAction("zoom_fit", m_buttonFitZoom);
668 KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
669 collection->addAction("zoom_in", zoomIn);
670 connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
671 zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
673 KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
674 collection->addAction("zoom_out", zoomOut);
675 connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
676 zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
678 m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
679 collection->addAction("project_find", m_projectSearch);
680 connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
681 m_projectSearch->setShortcut(Qt::Key_Slash);
683 m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
684 collection->addAction("project_find_next", m_projectSearchNext);
685 connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
686 m_projectSearchNext->setShortcut(Qt::Key_F3);
687 m_projectSearchNext->setEnabled(false);
689 KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
690 collection->addAction("manage_profiles", profilesAction);
691 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
693 KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
694 collection->addAction("project_settings", projectAction);
695 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
697 KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
698 collection->addAction("project_render", projectRender);
699 projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
700 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
702 KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
703 KShortcut playShortcut;
704 playShortcut.setPrimary(Qt::Key_Space);
705 playShortcut.setAlternate(Qt::Key_K);
706 monitorPlay->setShortcut(playShortcut);
707 collection->addAction("monitor_play", monitorPlay);
708 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
710 KAction *markIn = collection->addAction("mark_in");
711 markIn->setText(i18n("Set In Point"));
712 markIn->setShortcut(Qt::Key_I);
713 connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
715 KAction *markOut = collection->addAction("mark_out");
716 markOut->setText(i18n("Set Out Point"));
717 markOut->setShortcut(Qt::Key_O);
718 connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
720 KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
721 monitorSeekBackward->setShortcut(Qt::Key_J);
722 collection->addAction("monitor_seek_backward", monitorSeekBackward);
723 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
725 KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
726 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
727 collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
728 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
730 KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
731 monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
732 collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
733 connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
735 KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
736 monitorSeekForward->setShortcut(Qt::Key_L);
737 collection->addAction("monitor_seek_forward", monitorSeekForward);
738 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
740 KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
741 clipStart->setShortcut(Qt::Key_Home);
742 collection->addAction("seek_clip_start", clipStart);
743 connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
745 KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
746 clipEnd->setShortcut(Qt::Key_End);
747 collection->addAction("seek_clip_end", clipEnd);
748 connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
750 KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
751 projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
752 collection->addAction("seek_start", projectStart);
753 connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
755 KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
756 projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
757 collection->addAction("seek_end", projectEnd);
758 connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
760 KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
761 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
762 collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
763 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
765 KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
766 monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
767 collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
768 connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
770 KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
771 deleteTimelineClip->setShortcut(Qt::Key_Delete);
772 collection->addAction("delete_timeline_clip", deleteTimelineClip);
773 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
775 KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
776 collection->addAction("change_clip_speed", editTimelineClipSpeed);
777 connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
779 KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
780 cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
781 collection->addAction("cut_timeline_clip", cutTimelineClip);
782 connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
784 KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
785 collection->addAction("add_clip_marker", addClipMarker);
786 connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
788 KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
789 collection->addAction("delete_clip_marker", deleteClipMarker);
790 connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
792 KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
793 collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
794 connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
796 KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
797 collection->addAction("edit_clip_marker", editClipMarker);
798 connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
800 KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
801 collection->addAction("insert_space", insertSpace);
802 connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
804 KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
805 collection->addAction("delete_space", removeSpace);
806 connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
808 KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
809 collection->addAction("insert_track", insertTrack);
810 connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
812 KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
813 collection->addAction("delete_track", deleteTrack);
814 connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
816 KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
817 collection->addAction("change_track", changeTrack);
818 connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
820 KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
821 collection->addAction("add_guide", addGuide);
822 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
824 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
825 collection->addAction("delete_guide", delGuide);
826 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
828 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
829 collection->addAction("edit_guide", editGuide);
830 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
832 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
833 collection->addAction("delete_all_guides", delAllGuides);
834 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
836 QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
837 collection->addAction("paste_effects", pasteEffects);
838 connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
840 m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
842 KStandardAction::quit(this, SLOT(queryQuit()), collection);
844 KStandardAction::open(this, SLOT(openFile()), collection);
846 m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
848 KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
850 KStandardAction::openNew(this, SLOT(newFile()), collection);
852 KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
854 KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
856 KStandardAction::copy(this, SLOT(slotCopy()), collection);
858 KStandardAction::paste(this, SLOT(slotPaste()), collection);
860 KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
861 undo->setEnabled(false);
862 connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
864 KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
865 redo->setEnabled(false);
866 connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
868 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
870 connect(collection, SIGNAL(actionHovered(QAction*)),
871 this, SLOT(slotDisplayActionMessage(QAction*)));
872 //connect(collection, SIGNAL( clearStatusText() ),
873 //statusBar(), SLOT( clear() ) );
876 void MainWindow::slotDisplayActionMessage(QAction *a) {
877 statusBar()->showMessage(a->data().toString(), 3000);
880 void MainWindow::saveOptions() {
881 KdenliveSettings::self()->writeConfig();
882 KSharedConfigPtr config = KGlobal::config();
883 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
884 KConfigGroup treecolumns(config, "Project Tree");
885 treecolumns.writeEntry("columns", m_projectList->headerInfo());
889 void MainWindow::readOptions() {
890 KSharedConfigPtr config = KGlobal::config();
891 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
892 KConfigGroup initialGroup(config, "version");
893 if (!initialGroup.exists()) {
894 // this is our first run, show Wizard
895 Wizard *w = new Wizard(this);
896 if (w->exec() == QDialog::Accepted && w->isOk()) {
898 initialGroup.writeEntry("version", "0.7");
903 } else if (initialGroup.readEntry("version") == "0.7") {
904 //Add new settings from 0.7.1
905 if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
906 QString path = QDir::homePath() + "/kdenlive";
907 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
908 KdenliveSettings::setDefaultprojectfolder(path);
911 KConfigGroup treecolumns(config, "Project Tree");
912 const QByteArray state = treecolumns.readEntry("columns", QByteArray());
913 if (!state.isEmpty())
914 m_projectList->setHeaderInfo(state);
917 void MainWindow::newFile(bool showProjectSettings) {
920 QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
921 if (!showProjectSettings && m_timelineArea->count() == 0) {
922 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
923 profileName = KdenliveSettings::default_profile();
925 ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
926 if (w->exec() != QDialog::Accepted) return;
927 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
928 profileName = w->selectedProfile();
929 projectFolder = w->selectedFolder();
930 projectTracks = w->tracks();
933 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, this);
934 doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
935 TrackView *trackView = new TrackView(doc, this);
936 m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
937 if (m_timelineArea->count() == 1) {
938 connectDocumentInfo(doc);
939 connectDocument(trackView, doc);
940 } else m_timelineArea->setTabBarHidden(false);
941 m_closeAction->setEnabled(m_timelineArea->count() > 1);
944 void MainWindow::activateDocument() {
945 if (m_timelineArea->currentWidget() == NULL) return;
946 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
947 KdenliveDoc *currentDoc = currentTab->document();
948 connectDocumentInfo(currentDoc);
949 connectDocument(currentTab, currentDoc);
952 void MainWindow::closeCurrentDocument() {
953 QWidget *w = m_timelineArea->currentWidget();
955 // closing current document
956 int ix = m_timelineArea->currentIndex() + 1;
957 if (ix == m_timelineArea->count()) ix = 0;
958 m_timelineArea->setCurrentIndex(ix);
959 TrackView *tabToClose = (TrackView *) w;
960 KdenliveDoc *docToClose = tabToClose->document();
961 if (docToClose && docToClose->isModified()) {
962 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
963 case KMessageBox::Yes :
964 // save document here. If saving fails, return false;
967 case KMessageBox::Cancel :
973 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
974 if (m_timelineArea->count() == 1) {
975 m_timelineArea->setTabBarHidden(true);
976 m_closeAction->setEnabled(false);
980 if (m_timelineArea->count() == 0) {
981 m_activeDocument = NULL;
982 effectStack->clear();
983 transitionConfig->slotTransitionItemSelected(NULL, false);
987 bool MainWindow::saveFileAs(const QString &outputFileName) {
988 QDomDocument currentSceneList = m_projectMonitor->sceneList();
989 if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
991 m_activeDocument->setUrl(KUrl(outputFileName));
992 if (m_activeDocument->m_autosave == NULL) {
993 m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
994 } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
995 setCaption(m_activeDocument->description());
996 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
997 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
998 m_activeDocument->setModified(false);
999 m_fileOpenRecent->addUrl(KUrl(outputFileName));
1003 bool MainWindow::saveFileAs() {
1004 // Check that the Kdenlive mime type is correctly installed
1005 QString mimetype = "application/x-kdenlive";
1006 KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1007 if (!mime) mimetype = "*.kdenlive";
1009 QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1010 if (outputFile.isEmpty()) return false;
1011 if (QFile::exists(outputFile)) {
1012 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
1014 return saveFileAs(outputFile);
1017 bool MainWindow::saveFile() {
1018 if (!m_activeDocument) return true;
1019 if (m_activeDocument->url().isEmpty()) {
1020 return saveFileAs();
1022 bool result = saveFileAs(m_activeDocument->url().path());
1023 m_activeDocument->m_autosave->resize(0);
1028 void MainWindow::openFile() {
1029 // Check that the Kdenlive mime type is correctly installed
1030 QString mimetype = "application/x-kdenlive";
1031 KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1032 if (!mime) mimetype = "*.kdenlive";
1034 KUrl url = KFileDialog::getOpenUrl(KUrl(), mimetype);
1035 if (url.isEmpty()) return;
1036 m_fileOpenRecent->addUrl(url);
1040 void MainWindow::openLastFile() {
1041 KSharedConfigPtr config = KGlobal::config();
1042 KUrl::List urls = m_fileOpenRecent->urls();
1043 if (urls.isEmpty()) newFile(false);
1044 else openFile(urls.last());
1047 void MainWindow::openFile(const KUrl &url) {
1048 // Check if the document is already opened
1049 const int ct = m_timelineArea->count();
1050 bool isOpened = false;
1052 for (i = 0; i < ct; i++) {
1053 TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1054 KdenliveDoc *doc = tab->document();
1055 if (doc->url() == url) {
1061 m_timelineArea->setCurrentIndex(i);
1065 // Check for backup file
1066 QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1067 if (!staleFiles.isEmpty()) {
1068 if (KMessageBox::questionYesNo(this,
1069 i18n("Auto-saved files exist. Do you want to recover them now?"),
1070 i18n("File Recovery"),
1071 KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1072 recoverFiles(staleFiles);
1075 // remove the stale files
1076 foreach(KAutoSaveFile *stale, staleFiles) {
1077 stale->open(QIODevice::ReadWrite);
1082 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1083 doOpenFile(url, NULL);
1086 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1088 doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
1089 if (stale == NULL) {
1090 stale = new KAutoSaveFile(url, doc);
1091 doc->m_autosave = stale;
1093 doc->m_autosave = stale;
1094 doc->setUrl(stale->managedFile());
1095 doc->setModified(true);
1096 stale->setParent(doc);
1098 connectDocumentInfo(doc);
1099 TrackView *trackView = new TrackView(doc, this);
1100 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1101 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1102 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1103 slotGotProgressInfo(QString(), -1);
1104 m_clipMonitor->refreshMonitor(true);
1107 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1108 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1109 foreach(KAutoSaveFile *stale, staleFiles) {
1110 /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1111 // show an error message; we could not steal the lockfile
1112 // maybe another application got to the file before us?
1116 kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1117 // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1118 if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1119 else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1124 void MainWindow::parseProfiles(const QString &mltPath) {
1125 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1127 //KdenliveSettings::setDefaulttmpfolder();
1128 if (!mltPath.isEmpty()) {
1129 KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1130 KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1133 if (KdenliveSettings::mltpath().isEmpty()) {
1134 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1136 if (KdenliveSettings::rendererpath().isEmpty()) {
1137 QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1138 if (!QFile::exists(inigoPath))
1139 inigoPath = KStandardDirs::findExe("inigo");
1140 else KdenliveSettings::setRendererpath(inigoPath);
1142 QStringList profilesFilter;
1143 profilesFilter << "*";
1144 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1146 if (profilesList.isEmpty()) {
1147 // Cannot find MLT path, try finding inigo
1148 QString profilePath = KdenliveSettings::rendererpath();
1149 if (!profilePath.isEmpty()) {
1150 profilePath = profilePath.section('/', 0, -3);
1151 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1152 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1155 if (profilesList.isEmpty()) {
1156 // Cannot find the MLT profiles, ask for location
1157 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1158 getUrl->fileDialog()->setMode(KFile::Directory);
1159 if (getUrl->exec() == QDialog::Rejected) {
1162 KUrl mltPath = getUrl->selectedUrl();
1164 if (mltPath.isEmpty()) ::exit(0);
1165 KdenliveSettings::setMltpath(mltPath.path());
1166 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1170 if (KdenliveSettings::rendererpath().isEmpty()) {
1171 // Cannot find the MLT inigo renderer, ask for location
1172 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1173 if (getUrl->exec() == QDialog::Rejected) {
1176 KUrl rendererPath = getUrl->selectedUrl();
1178 if (rendererPath.isEmpty()) ::exit(0);
1179 KdenliveSettings::setRendererpath(rendererPath.path());
1182 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1184 // Parse MLT profiles to build a list of available video formats
1185 if (profilesList.isEmpty()) parseProfiles();
1189 void MainWindow::slotEditProfiles() {
1190 ProfilesDialog *w = new ProfilesDialog;
1195 void MainWindow::slotEditProjectSettings() {
1196 QPoint p = m_activeDocument->getTracksCount();
1197 ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1199 if (w->exec() == QDialog::Accepted) {
1200 QString profile = w->selectedProfile();
1201 m_activeDocument->setProfilePath(profile);
1202 KdenliveSettings::setCurrent_profile(profile);
1203 KdenliveSettings::setProject_fps(m_activeDocument->fps());
1204 setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1205 m_monitorManager->resetProfiles(m_activeDocument->timecode());
1206 if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1207 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1209 // We need to desactivate & reactivate monitors to get a refresh
1210 m_monitorManager->switchMonitors();
1215 void MainWindow::slotRenderProject() {
1216 if (!m_renderWidget) {
1217 m_renderWidget = new RenderWidget(this);
1218 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)));
1219 if (m_activeDocument) {
1220 m_renderWidget->setProfile(m_activeDocument->mltProfile());
1221 m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1224 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1225 if (currentTab) m_renderWidget->setTimeline(currentTab);
1226 m_renderWidget->setDocument(m_activeDocument);*/
1227 m_renderWidget->show();
1230 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) {
1231 if (dest.isEmpty()) return;
1234 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1235 if (currentTab && zoneOnly) {
1236 in = currentTab->inPoint();
1237 out = currentTab->outPoint();
1239 KTemporaryFile temp;
1240 temp.setAutoRemove(false);
1241 temp.setSuffix(".westley");
1243 m_projectMonitor->saveSceneList(temp.fileName());
1246 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1247 else if (guideStart != -1) {
1248 args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1250 if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1251 QString videoPlayer = "-";
1253 videoPlayer = KdenliveSettings::defaultplayerapp();
1254 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."));
1256 if (!QFile::exists(KdenliveSettings::rendererpath())) {
1257 KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1260 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1261 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1262 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1263 QProcess::startDetached(renderer, args);
1265 KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1269 void MainWindow::slotUpdateMousePosition(int pos) {
1270 if (m_activeDocument)
1271 switch (m_timecodeFormat->currentIndex()) {
1273 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1276 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1280 void MainWindow::slotUpdateDocumentState(bool modified) {
1281 setCaption(m_activeDocument->description(), modified);
1282 m_saveAction->setEnabled(modified);
1284 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1285 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1287 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1288 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1292 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1293 if (m_activeDocument) {
1294 if (m_activeDocument == doc) return;
1295 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1297 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1300 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1301 //m_projectMonitor->stop();
1302 m_closeAction->setEnabled(m_timelineArea->count() > 1);
1303 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
1304 if (m_activeDocument) {
1305 if (m_activeDocument == doc) return;
1306 m_activeDocument->backupMltPlaylist();
1307 if (m_activeTimeline) {
1308 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1309 disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1310 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1311 disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1314 disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1315 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1316 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1317 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1318 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1319 disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1320 disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1321 disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1322 disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1323 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1324 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1325 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1326 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1327 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1328 disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1329 disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1330 disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1331 disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1332 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1333 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1334 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1335 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1336 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1337 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1338 disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1339 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1340 disconnect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), m_activeTimeline->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1341 disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1342 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1343 disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1344 disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1345 effectStack->clear();
1347 m_activeDocument->setRenderer(NULL);
1348 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1349 m_clipMonitor->stop();
1351 KdenliveSettings::setCurrent_profile(doc->profilePath());
1352 KdenliveSettings::setProject_fps(doc->fps());
1353 m_monitorManager->resetProfiles(doc->timecode());
1354 m_projectList->setDocument(doc);
1355 transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1356 effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1357 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1358 connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1359 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1360 connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1361 connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1362 connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1363 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1364 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1365 connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1366 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1367 connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1368 connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1369 connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1370 connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1371 connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1373 connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1374 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1375 connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1378 connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1379 connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1380 connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1381 connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1382 m_zoomSlider->setValue(doc->zoom());
1383 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1384 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1385 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1386 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1388 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1391 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1392 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1393 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1394 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1395 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1396 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1397 connect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), trackView->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1398 connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1399 connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1401 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1402 connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1403 connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1405 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1406 m_activeTimeline = trackView;
1407 if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
1408 doc->setRenderer(m_projectMonitor->render);
1409 m_commandStack->setActiveStack(doc->commandStack());
1410 KdenliveSettings::setProject_display_ratio(doc->dar());
1411 m_projectList->updateAllClips();
1412 //doc->clipManager()->checkAudioThumbs();
1414 //m_overView->setScene(trackView->projectScene());
1415 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1416 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1418 setCaption(doc->description(), doc->isModified());
1419 m_saveAction->setEnabled(doc->isModified());
1420 m_activeDocument = doc;
1423 void MainWindow::slotGuidesUpdated() {
1424 if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1427 void MainWindow::slotPreferences(int page, int option) {
1428 //An instance of your dialog could be already created and could be
1429 // cached, in which case you want to display the cached dialog
1430 // instead of creating another one
1431 if (KConfigDialog::showDialog("settings")) {
1432 KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1433 if (page != -1) d->showPage(page, option);
1438 // KConfigDialog didn't find an instance of this dialog, so lets
1440 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1441 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1442 connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1444 if (page != -1) dialog->showPage(page, option);
1447 void MainWindow::updateConfiguration() {
1448 //TODO: we should apply settings to all projects, not only the current one
1449 if (m_activeTimeline) {
1450 m_activeTimeline->refresh();
1451 m_activeTimeline->projectView()->checkAutoScroll();
1452 m_activeTimeline->projectView()->checkTrackHeight();
1453 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1455 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1456 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1457 #ifndef NO_JOGSHUTTLE
1458 activateShuttleDevice();
1459 #endif /* NO_JOGSHUTTLE */
1463 void MainWindow::slotSwitchVideoThumbs() {
1464 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1465 if (m_activeTimeline) {
1466 m_activeTimeline->refresh();
1468 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1471 void MainWindow::slotSwitchAudioThumbs() {
1472 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1473 if (m_activeTimeline) {
1474 m_activeTimeline->refresh();
1475 m_activeTimeline->projectView()->checkAutoScroll();
1476 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1478 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1481 void MainWindow::slotSwitchMarkersComments() {
1482 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1483 if (m_activeTimeline) {
1484 m_activeTimeline->refresh();
1486 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1489 void MainWindow::slotSwitchSnap() {
1490 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1491 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1495 void MainWindow::slotDeleteTimelineClip() {
1496 if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1497 else if (m_activeTimeline) {
1498 m_activeTimeline->projectView()->deleteSelectedClips();
1502 void MainWindow::slotChangeClipSpeed() {
1503 if (m_activeTimeline) {
1504 m_activeTimeline->projectView()->changeClipSpeed();
1508 void MainWindow::slotAddClipMarker() {
1509 DocClipBase *clip = NULL;
1511 if (m_projectMonitor->isActive()) {
1512 if (m_activeTimeline) {
1513 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1515 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1516 clip = item->baseClip();
1520 clip = m_clipMonitor->activeClip();
1521 pos = m_clipMonitor->position();
1524 m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1527 QString id = clip->getId();
1528 CommentedTime marker(pos, i18n("Marker"));
1529 MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1530 if (d.exec() == QDialog::Accepted) {
1531 m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1533 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1536 void MainWindow::slotDeleteClipMarker() {
1537 DocClipBase *clip = NULL;
1539 if (m_projectMonitor->isActive()) {
1540 if (m_activeTimeline) {
1541 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1543 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1544 clip = item->baseClip();
1548 clip = m_clipMonitor->activeClip();
1549 pos = m_clipMonitor->position();
1552 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1556 QString id = clip->getId();
1557 QString comment = clip->markerComment(pos);
1558 if (comment.isEmpty()) {
1559 m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1562 m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
1563 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1567 void MainWindow::slotDeleteAllClipMarkers() {
1568 DocClipBase *clip = NULL;
1569 if (m_projectMonitor->isActive()) {
1570 if (m_activeTimeline) {
1571 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1573 clip = item->baseClip();
1577 clip = m_clipMonitor->activeClip();
1580 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1583 m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
1584 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1587 void MainWindow::slotEditClipMarker() {
1588 DocClipBase *clip = NULL;
1590 if (m_projectMonitor->isActive()) {
1591 if (m_activeTimeline) {
1592 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1594 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1595 clip = item->baseClip();
1599 clip = m_clipMonitor->activeClip();
1600 pos = m_clipMonitor->position();
1603 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1607 QString id = clip->getId();
1608 QString oldcomment = clip->markerComment(pos);
1609 if (oldcomment.isEmpty()) {
1610 m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1614 CommentedTime marker(pos, oldcomment);
1615 MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
1616 if (d.exec() == QDialog::Accepted) {
1617 m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1618 if (d.newMarker().time() != pos) {
1619 // remove old marker
1620 m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
1622 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1626 void MainWindow::slotAddGuide() {
1627 if (m_activeTimeline)
1628 m_activeTimeline->projectView()->slotAddGuide();
1631 void MainWindow::slotInsertSpace() {
1632 if (m_activeTimeline)
1633 m_activeTimeline->projectView()->slotInsertSpace();
1636 void MainWindow::slotRemoveSpace() {
1637 if (m_activeTimeline)
1638 m_activeTimeline->projectView()->slotRemoveSpace();
1641 void MainWindow::slotInsertTrack(int ix) {
1642 m_projectMonitor->activateMonitor();
1643 if (m_activeTimeline)
1644 m_activeTimeline->projectView()->slotInsertTrack(ix);
1647 void MainWindow::slotDeleteTrack(int ix) {
1648 m_projectMonitor->activateMonitor();
1649 if (m_activeTimeline)
1650 m_activeTimeline->projectView()->slotDeleteTrack(ix);
1653 void MainWindow::slotChangeTrack(int ix) {
1654 m_projectMonitor->activateMonitor();
1655 if (m_activeTimeline)
1656 m_activeTimeline->projectView()->slotChangeTrack(ix);
1659 void MainWindow::slotEditGuide() {
1660 if (m_activeTimeline)
1661 m_activeTimeline->projectView()->slotEditGuide();
1664 void MainWindow::slotDeleteGuide() {
1665 if (m_activeTimeline)
1666 m_activeTimeline->projectView()->slotDeleteGuide();
1669 void MainWindow::slotDeleteAllGuides() {
1670 if (m_activeTimeline)
1671 m_activeTimeline->projectView()->slotDeleteAllGuides();
1674 void MainWindow::slotCutTimelineClip() {
1675 if (m_activeTimeline) {
1676 m_activeTimeline->projectView()->cutSelectedClips();
1680 void MainWindow::slotAddProjectClip(KUrl url) {
1681 if (m_activeDocument)
1682 m_activeDocument->slotAddClipFile(url, QString());
1685 void MainWindow::slotAddTransition(QAction *result) {
1686 if (!result) return;
1687 QStringList info = result->data().toStringList();
1688 if (info.isEmpty()) return;
1689 QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
1690 if (m_activeTimeline && !transition.isNull()) {
1691 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
1695 void MainWindow::slotAddVideoEffect(QAction *result) {
1696 if (!result) return;
1697 QStringList info = result->data().toStringList();
1698 if (info.isEmpty()) return;
1699 QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
1700 slotAddEffect(effect);
1703 void MainWindow::slotAddAudioEffect(QAction *result) {
1704 if (!result) return;
1705 QStringList info = result->data().toStringList();
1706 if (info.isEmpty()) return;
1707 QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
1708 slotAddEffect(effect);
1711 void MainWindow::slotAddCustomEffect(QAction *result) {
1712 if (!result) return;
1713 QStringList info = result->data().toStringList();
1714 if (info.isEmpty()) return;
1715 QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
1716 slotAddEffect(effect);
1719 void MainWindow::slotZoomIn() {
1720 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1723 void MainWindow::slotZoomOut() {
1724 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1727 void MainWindow::slotFitZoom() {
1728 if (m_activeTimeline) {
1729 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1733 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1734 statusProgressBar->setValue(progress);
1735 if (progress >= 0) {
1736 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1737 statusProgressBar->setVisible(true);
1739 m_messageLabel->setMessage(QString(), DefaultMessage);
1740 statusProgressBar->setVisible(false);
1744 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1745 if (clip->clipType() == TEXT) {
1746 QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1747 QString path = clip->getProperty("resource");
1748 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1750 doc.setContent(clip->getProperty("xmldata"));
1751 dia_ui->setXml(doc);
1752 if (dia_ui->exec() == QDialog::Accepted) {
1753 QPixmap pix = dia_ui->renderedPixmap();
1755 //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1756 //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1757 QMap <QString, QString> newprops;
1758 newprops.insert("xmldata", dia_ui->xml().toString());
1759 EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1760 m_activeDocument->commandStack()->push(command);
1761 m_clipMonitor->refreshMonitor(true);
1762 m_activeDocument->setModified(true);
1766 //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1769 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1770 connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1771 if (dia.exec() == QDialog::Accepted) {
1772 EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1773 m_activeDocument->commandStack()->push(command);
1775 //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1776 if (dia.needsTimelineRefresh()) {
1777 // update clip occurences in timeline
1778 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1783 void MainWindow::customEvent(QEvent* e) {
1784 if (e->type() == QEvent::User) {
1785 // The timeline playing position changed...
1786 kDebug() << "RECIEVED JOG EVEMNT!!!";
1789 void MainWindow::slotActivateEffectStackView() {
1790 effectStack->raiseWindow(effectStackDock);
1793 void MainWindow::slotActivateTransitionView() {
1794 transitionConfig->raiseWindow(transitionConfigDock);
1797 void MainWindow::slotSnapRewind() {
1798 if (m_projectMonitor->isActive()) {
1799 if (m_activeTimeline)
1800 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1801 } else m_clipMonitor->slotSeekToPreviousSnap();
1804 void MainWindow::slotSnapForward() {
1805 if (m_projectMonitor->isActive()) {
1806 if (m_activeTimeline)
1807 m_activeTimeline->projectView()->slotSeekToNextSnap();
1808 } else m_clipMonitor->slotSeekToNextSnap();
1811 void MainWindow::slotClipStart() {
1812 if (m_projectMonitor->isActive()) {
1813 if (m_activeTimeline)
1814 m_activeTimeline->projectView()->clipStart();
1818 void MainWindow::slotClipEnd() {
1819 if (m_projectMonitor->isActive()) {
1820 if (m_activeTimeline)
1821 m_activeTimeline->projectView()->clipEnd();
1825 void MainWindow::slotChangeTool(QAction * action) {
1826 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1827 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1828 else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
1831 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1832 if (m_activeDocument && m_activeTimeline) {
1833 //m_activeDocument->setTool(tool);
1834 m_activeTimeline->projectView()->setTool(tool);
1838 void MainWindow::slotCopy() {
1839 if (!m_activeDocument || !m_activeTimeline) return;
1840 m_activeTimeline->projectView()->copyClip();
1843 void MainWindow::slotPaste() {
1844 if (!m_activeDocument || !m_activeTimeline) return;
1845 m_activeTimeline->projectView()->pasteClip();
1848 void MainWindow::slotPasteEffects() {
1849 if (!m_activeDocument || !m_activeTimeline) return;
1850 m_activeTimeline->projectView()->pasteClipEffects();
1853 void MainWindow::slotFind() {
1854 if (!m_activeDocument || !m_activeTimeline) return;
1855 m_projectSearch->setEnabled(false);
1856 m_findActivated = true;
1857 m_findString = QString();
1858 m_activeTimeline->projectView()->initSearchStrings();
1859 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1860 m_findTimer.start(5000);
1861 qApp->installEventFilter(this);
1864 void MainWindow::slotFindNext() {
1865 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1866 statusBar()->showMessage(i18n("Found : %1", m_findString));
1868 statusBar()->showMessage(i18n("Reached end of project"));
1870 m_findTimer.start(4000);
1873 void MainWindow::findAhead() {
1874 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1875 m_projectSearchNext->setEnabled(true);
1876 statusBar()->showMessage(i18n("Found : %1", m_findString));
1878 m_projectSearchNext->setEnabled(false);
1879 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1883 void MainWindow::findTimeout() {
1884 m_projectSearchNext->setEnabled(false);
1885 m_findActivated = false;
1886 m_findString = QString();
1887 statusBar()->showMessage(i18n("Find stopped"), 3000);
1888 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1889 m_projectSearch->setEnabled(true);
1890 removeEventFilter(this);
1893 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1894 if (m_findActivated) {
1895 if (ke->key() == Qt::Key_Backspace) {
1896 m_findString = m_findString.left(m_findString.length() - 1);
1898 if (!m_findString.isEmpty()) {
1904 m_findTimer.start(4000);
1907 } else if (ke->key() == Qt::Key_Escape) {
1911 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1912 m_findString += ke->text();
1916 m_findTimer.start(4000);
1920 } else KXmlGuiWindow::keyPressEvent(ke);
1924 /** Gets called when the window gets hidden */
1925 void MainWindow::hideEvent(QHideEvent *event) {
1926 // kDebug() << "I was hidden";
1927 // issue http://www.kdenlive.org/mantis/view.php?id=231
1928 if (this->isMinimized()) {
1929 // kDebug() << "I am minimized";
1930 if (m_monitorManager) m_monitorManager->stopActiveMonitor();
1934 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1935 if (m_findActivated) {
1936 if (event->type() == QEvent::ShortcutOverride) {
1937 QKeyEvent* ke = (QKeyEvent*) event;
1938 if (ke->text().trimmed().isEmpty()) return false;
1941 } else return false;
1943 // pass the event on to the parent class
1944 return QMainWindow::eventFilter(obj, event);
1948 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1949 KDialog *dialog = new KDialog(this);
1950 dialog->setCaption("Save clip zone");
1951 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1953 QWidget *widget = new QWidget(dialog);
1954 dialog->setMainWidget(widget);
1956 QVBoxLayout *vbox = new QVBoxLayout(widget);
1957 QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1958 QString path = m_activeDocument->projectFolder().path();
1960 path.append("untitled.westley");
1961 KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1962 url->setFilter("video/mlt-playlist");
1963 QLabel *label2 = new QLabel(i18n("Description:"), this);
1964 KLineEdit *edit = new KLineEdit(this);
1965 vbox->addWidget(label1);
1966 vbox->addWidget(url);
1967 vbox->addWidget(label2);
1968 vbox->addWidget(edit);
1969 if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1973 void MainWindow::slotSetInPoint() {
1974 if (m_clipMonitor->isActive()) {
1975 m_clipMonitor->slotSetZoneStart();
1976 } else m_activeTimeline->projectView()->setInPoint();
1979 void MainWindow::slotSetOutPoint() {
1980 if (m_clipMonitor->isActive()) {
1981 m_clipMonitor->slotSetZoneEnd();
1982 } else m_activeTimeline->projectView()->setOutPoint();
1986 #include "mainwindow.moc"