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 *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
809 collection->addAction("add_guide", addGuide);
810 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
812 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
813 collection->addAction("delete_guide", delGuide);
814 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
816 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
817 collection->addAction("edit_guide", editGuide);
818 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
820 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
821 collection->addAction("delete_all_guides", delAllGuides);
822 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
824 QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
825 collection->addAction("paste_effects", pasteEffects);
826 connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
828 m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
830 KStandardAction::quit(this, SLOT(queryQuit()), collection);
832 KStandardAction::open(this, SLOT(openFile()), collection);
834 m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
836 KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
838 KStandardAction::openNew(this, SLOT(newFile()), collection);
840 KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
842 KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
844 KStandardAction::copy(this, SLOT(slotCopy()), collection);
846 KStandardAction::paste(this, SLOT(slotPaste()), collection);
848 KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
849 undo->setEnabled(false);
850 connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
852 KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
853 redo->setEnabled(false);
854 connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
856 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
858 connect(collection, SIGNAL(actionHovered(QAction*)),
859 this, SLOT(slotDisplayActionMessage(QAction*)));
860 //connect(collection, SIGNAL( clearStatusText() ),
861 //statusBar(), SLOT( clear() ) );
864 void MainWindow::slotDisplayActionMessage(QAction *a) {
865 statusBar()->showMessage(a->data().toString(), 3000);
868 void MainWindow::saveOptions() {
869 KdenliveSettings::self()->writeConfig();
870 KSharedConfigPtr config = KGlobal::config();
871 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
872 KConfigGroup treecolumns(config, "Project Tree");
873 treecolumns.writeEntry("columns", m_projectList->headerInfo());
877 void MainWindow::readOptions() {
878 KSharedConfigPtr config = KGlobal::config();
879 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
880 KConfigGroup initialGroup(config, "version");
881 if (!initialGroup.exists()) {
882 // this is our first run, show Wizard
883 Wizard *w = new Wizard(this);
884 if (w->exec() == QDialog::Accepted && w->isOk()) {
886 initialGroup.writeEntry("version", "0.7");
892 KConfigGroup treecolumns(config, "Project Tree");
893 const QByteArray state = treecolumns.readEntry("columns", QByteArray());
894 if (!state.isEmpty())
895 m_projectList->setHeaderInfo(state);
898 void MainWindow::newFile(bool showProjectSettings) {
901 QPoint projectTracks(3, 2);
902 if (!showProjectSettings && m_timelineArea->count() == 0) {
903 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
904 profileName = KdenliveSettings::default_profile();
906 ProjectSettings *w = new ProjectSettings;
907 if (w->exec() != QDialog::Accepted) return;
908 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
909 profileName = w->selectedProfile();
910 projectFolder = w->selectedFolder();
911 projectTracks = w->tracks();
914 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, this);
915 doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
916 TrackView *trackView = new TrackView(doc, this);
917 m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
918 if (m_timelineArea->count() == 1) {
919 connectDocumentInfo(doc);
920 connectDocument(trackView, doc);
921 } else m_timelineArea->setTabBarHidden(false);
922 m_closeAction->setEnabled(m_timelineArea->count() > 1);
925 void MainWindow::activateDocument() {
926 if (m_timelineArea->currentWidget() == NULL) return;
927 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
928 KdenliveDoc *currentDoc = currentTab->document();
929 connectDocumentInfo(currentDoc);
930 connectDocument(currentTab, currentDoc);
933 void MainWindow::closeCurrentDocument() {
934 QWidget *w = m_timelineArea->currentWidget();
936 // closing current document
937 int ix = m_timelineArea->currentIndex() + 1;
938 if (ix == m_timelineArea->count()) ix = 0;
939 m_timelineArea->setCurrentIndex(ix);
940 TrackView *tabToClose = (TrackView *) w;
941 KdenliveDoc *docToClose = tabToClose->document();
942 if (docToClose && docToClose->isModified()) {
943 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
944 case KMessageBox::Yes :
945 // save document here. If saving fails, return false;
948 case KMessageBox::Cancel :
954 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
955 if (m_timelineArea->count() == 1) {
956 m_timelineArea->setTabBarHidden(true);
957 m_closeAction->setEnabled(false);
961 if (m_timelineArea->count() == 0) {
962 m_activeDocument = NULL;
963 effectStack->clear();
964 transitionConfig->slotTransitionItemSelected(NULL, false);
968 bool MainWindow::saveFileAs(const QString &outputFileName) {
969 QDomDocument currentSceneList = m_projectMonitor->sceneList();
970 if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
972 m_activeDocument->setUrl(KUrl(outputFileName));
973 if (m_activeDocument->m_autosave == NULL) {
974 m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
975 } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
976 setCaption(m_activeDocument->description());
977 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
978 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
979 m_activeDocument->setModified(false);
980 m_fileOpenRecent->addUrl(KUrl(outputFileName));
984 bool MainWindow::saveFileAs() {
985 // Check that the Kdenlive mime type is correctly installed
986 QString mimetype = "application/x-kdenlive";
987 KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
988 if (!mime) mimetype = "*.kdenlive";
990 QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
991 if (outputFile.isEmpty()) return false;
992 if (QFile::exists(outputFile)) {
993 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
995 return saveFileAs(outputFile);
998 bool MainWindow::saveFile() {
999 if (!m_activeDocument) return true;
1000 if (m_activeDocument->url().isEmpty()) {
1001 return saveFileAs();
1003 bool result = saveFileAs(m_activeDocument->url().path());
1004 m_activeDocument->m_autosave->resize(0);
1009 void MainWindow::openFile() {
1010 // Check that the Kdenlive mime type is correctly installed
1011 QString mimetype = "application/x-kdenlive";
1012 KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1013 if (!mime) mimetype = "*.kdenlive";
1015 KUrl url = KFileDialog::getOpenUrl(KUrl(), mimetype);
1016 if (url.isEmpty()) return;
1017 m_fileOpenRecent->addUrl(url);
1021 void MainWindow::openLastFile() {
1022 KSharedConfigPtr config = KGlobal::config();
1023 KUrl::List urls = m_fileOpenRecent->urls();
1024 if (urls.isEmpty()) newFile(false);
1025 else openFile(urls.last());
1028 void MainWindow::openFile(const KUrl &url) {
1029 // Check if the document is already opened
1030 const int ct = m_timelineArea->count();
1031 bool isOpened = false;
1033 for (i = 0; i < ct; i++) {
1034 TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1035 KdenliveDoc *doc = tab->document();
1036 if (doc->url() == url) {
1042 m_timelineArea->setCurrentIndex(i);
1046 // Check for backup file
1047 QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1048 if (!staleFiles.isEmpty()) {
1049 if (KMessageBox::questionYesNo(this,
1050 i18n("Auto-saved files exist. Do you want to recover them now?"),
1051 i18n("File Recovery"),
1052 KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1053 recoverFiles(staleFiles);
1056 // remove the stale files
1057 foreach(KAutoSaveFile *stale, staleFiles) {
1058 stale->open(QIODevice::ReadWrite);
1063 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1064 doOpenFile(url, NULL);
1067 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1069 doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
1070 if (stale == NULL) {
1071 stale = new KAutoSaveFile(url, doc);
1072 doc->m_autosave = stale;
1074 doc->m_autosave = stale;
1075 doc->setUrl(stale->managedFile());
1076 doc->setModified(true);
1077 stale->setParent(doc);
1079 connectDocumentInfo(doc);
1080 TrackView *trackView = new TrackView(doc, this);
1081 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1082 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1083 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1084 slotGotProgressInfo(QString(), -1);
1085 m_clipMonitor->refreshMonitor(true);
1088 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1089 if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1090 foreach(KAutoSaveFile *stale, staleFiles) {
1091 /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1092 // show an error message; we could not steal the lockfile
1093 // maybe another application got to the file before us?
1097 kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1098 // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1099 if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1100 else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1105 void MainWindow::parseProfiles(const QString &mltPath) {
1106 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1108 //KdenliveSettings::setDefaulttmpfolder();
1109 if (!mltPath.isEmpty()) {
1110 KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1111 KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1114 if (KdenliveSettings::mltpath().isEmpty()) {
1115 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1117 if (KdenliveSettings::rendererpath().isEmpty()) {
1118 QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1119 if (!QFile::exists(inigoPath))
1120 inigoPath = KStandardDirs::findExe("inigo");
1121 else KdenliveSettings::setRendererpath(inigoPath);
1123 QStringList profilesFilter;
1124 profilesFilter << "*";
1125 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1127 if (profilesList.isEmpty()) {
1128 // Cannot find MLT path, try finding inigo
1129 QString profilePath = KdenliveSettings::rendererpath();
1130 if (!profilePath.isEmpty()) {
1131 profilePath = profilePath.section('/', 0, -3);
1132 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1133 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1136 if (profilesList.isEmpty()) {
1137 // Cannot find the MLT profiles, ask for location
1138 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1139 getUrl->fileDialog()->setMode(KFile::Directory);
1140 if (getUrl->exec() == QDialog::Rejected) {
1143 KUrl mltPath = getUrl->selectedUrl();
1145 if (mltPath.isEmpty()) ::exit(0);
1146 KdenliveSettings::setMltpath(mltPath.path());
1147 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1151 if (KdenliveSettings::rendererpath().isEmpty()) {
1152 // Cannot find the MLT inigo renderer, ask for location
1153 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1154 if (getUrl->exec() == QDialog::Rejected) {
1157 KUrl rendererPath = getUrl->selectedUrl();
1159 if (rendererPath.isEmpty()) ::exit(0);
1160 KdenliveSettings::setRendererpath(rendererPath.path());
1163 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1165 // Parse MLT profiles to build a list of available video formats
1166 if (profilesList.isEmpty()) parseProfiles();
1170 void MainWindow::slotEditProfiles() {
1171 ProfilesDialog *w = new ProfilesDialog;
1176 void MainWindow::slotEditProjectSettings() {
1177 ProjectSettings *w = new ProjectSettings;
1178 if (w->exec() == QDialog::Accepted) {
1179 QString profile = w->selectedProfile();
1180 m_activeDocument->setProfilePath(profile);
1181 KdenliveSettings::setCurrent_profile(profile);
1182 KdenliveSettings::setProject_fps(m_activeDocument->fps());
1183 setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1184 m_monitorManager->resetProfiles(m_activeDocument->timecode());
1185 if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1186 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1188 // We need to desactivate & reactivate monitors to get a refresh
1189 m_monitorManager->switchMonitors();
1194 void MainWindow::slotRenderProject() {
1195 if (!m_renderWidget) {
1196 m_renderWidget = new RenderWidget(this);
1197 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)));
1198 if (m_activeDocument) {
1199 m_renderWidget->setProfile(m_activeDocument->mltProfile());
1200 m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1203 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1204 if (currentTab) m_renderWidget->setTimeline(currentTab);
1205 m_renderWidget->setDocument(m_activeDocument);*/
1206 m_renderWidget->show();
1209 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) {
1210 if (dest.isEmpty()) return;
1213 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1214 if (currentTab && zoneOnly) {
1215 in = currentTab->inPoint();
1216 out = currentTab->outPoint();
1218 KTemporaryFile temp;
1219 temp.setAutoRemove(false);
1220 temp.setSuffix(".westley");
1222 m_projectMonitor->saveSceneList(temp.fileName());
1225 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1226 else if (guideStart != -1) {
1227 args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1229 if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1230 QString videoPlayer = "-";
1232 videoPlayer = KdenliveSettings::defaultplayerapp();
1233 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."));
1235 if (!QFile::exists(KdenliveSettings::rendererpath())) {
1236 KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1239 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1240 QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1241 if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1242 QProcess::startDetached(renderer, args);
1244 KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1248 void MainWindow::slotUpdateMousePosition(int pos) {
1249 if (m_activeDocument)
1250 switch (m_timecodeFormat->currentIndex()) {
1252 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1255 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1259 void MainWindow::slotUpdateDocumentState(bool modified) {
1260 setCaption(m_activeDocument->description(), modified);
1261 m_saveAction->setEnabled(modified);
1263 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1264 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1266 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1267 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1271 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1272 if (m_activeDocument) {
1273 if (m_activeDocument == doc) return;
1274 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1276 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1279 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1280 //m_projectMonitor->stop();
1281 m_closeAction->setEnabled(m_timelineArea->count() > 1);
1282 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
1283 if (m_activeDocument) {
1284 if (m_activeDocument == doc) return;
1285 m_activeDocument->backupMltPlaylist();
1286 if (m_activeTimeline) {
1287 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1288 disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1289 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1290 disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1291 disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1292 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1293 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1294 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1295 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1296 disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1297 disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1298 disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1299 disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1300 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1301 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1302 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1303 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1304 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1306 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1307 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1308 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1309 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1310 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1311 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1312 disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1313 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1314 disconnect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), m_activeTimeline->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1315 disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1316 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1317 disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1318 disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1319 effectStack->clear();
1321 m_activeDocument->setRenderer(NULL);
1322 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1323 m_clipMonitor->stop();
1325 KdenliveSettings::setCurrent_profile(doc->profilePath());
1326 KdenliveSettings::setProject_fps(doc->fps());
1327 m_monitorManager->resetProfiles(doc->timecode());
1328 m_projectList->setDocument(doc);
1329 transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1330 effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1331 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1332 connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1333 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1334 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1335 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1336 connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1337 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1338 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1339 connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1340 connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1341 connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1342 connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1344 connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1345 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1346 connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1349 connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1350 connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1351 connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1352 connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1353 m_zoomSlider->setValue(doc->zoom());
1354 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1355 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1356 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1357 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1359 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1362 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1363 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1364 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1365 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1366 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1367 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1368 connect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), trackView->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1369 connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1370 connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1372 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1373 connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1374 connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1376 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1377 m_activeTimeline = trackView;
1378 if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
1379 doc->setRenderer(m_projectMonitor->render);
1380 m_commandStack->setActiveStack(doc->commandStack());
1381 KdenliveSettings::setProject_display_ratio(doc->dar());
1382 m_projectList->updateAllClips();
1383 //doc->clipManager()->checkAudioThumbs();
1385 //m_overView->setScene(trackView->projectScene());
1386 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1387 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1389 setCaption(doc->description(), doc->isModified());
1390 m_saveAction->setEnabled(doc->isModified());
1391 m_activeDocument = doc;
1394 void MainWindow::slotGuidesUpdated() {
1395 if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1398 void MainWindow::slotPreferences(int page, int option) {
1399 //An instance of your dialog could be already created and could be
1400 // cached, in which case you want to display the cached dialog
1401 // instead of creating another one
1402 if (KConfigDialog::showDialog("settings")) {
1403 KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1404 if (page != -1) d->showPage(page, option);
1409 // KConfigDialog didn't find an instance of this dialog, so lets
1411 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1412 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1413 connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1415 if (page != -1) dialog->showPage(page, option);
1418 void MainWindow::updateConfiguration() {
1419 //TODO: we should apply settings to all projects, not only the current one
1420 if (m_activeTimeline) {
1421 m_activeTimeline->refresh();
1422 m_activeTimeline->projectView()->checkAutoScroll();
1423 m_activeTimeline->projectView()->checkTrackHeight();
1424 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1426 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1427 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1428 #ifndef NO_JOGSHUTTLE
1429 activateShuttleDevice();
1430 #endif /* NO_JOGSHUTTLE */
1434 void MainWindow::slotSwitchVideoThumbs() {
1435 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1436 if (m_activeTimeline) {
1437 m_activeTimeline->refresh();
1439 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1442 void MainWindow::slotSwitchAudioThumbs() {
1443 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1444 if (m_activeTimeline) {
1445 m_activeTimeline->refresh();
1446 m_activeTimeline->projectView()->checkAutoScroll();
1447 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1449 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1452 void MainWindow::slotSwitchMarkersComments() {
1453 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1454 if (m_activeTimeline) {
1455 m_activeTimeline->refresh();
1457 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1460 void MainWindow::slotSwitchSnap() {
1461 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1462 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1466 void MainWindow::slotDeleteTimelineClip() {
1467 if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1468 else if (m_activeTimeline) {
1469 m_activeTimeline->projectView()->deleteSelectedClips();
1473 void MainWindow::slotChangeClipSpeed() {
1474 if (m_activeTimeline) {
1475 m_activeTimeline->projectView()->changeClipSpeed();
1479 void MainWindow::slotAddClipMarker() {
1480 DocClipBase *clip = NULL;
1482 if (m_projectMonitor->isActive()) {
1483 if (m_activeTimeline) {
1484 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1486 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1487 clip = item->baseClip();
1491 clip = m_clipMonitor->activeClip();
1492 pos = m_clipMonitor->position();
1495 m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1498 QString id = clip->getId();
1499 CommentedTime marker(pos, i18n("Marker"));
1500 MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1501 if (d.exec() == QDialog::Accepted) {
1502 m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1504 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1507 void MainWindow::slotDeleteClipMarker() {
1508 DocClipBase *clip = NULL;
1510 if (m_projectMonitor->isActive()) {
1511 if (m_activeTimeline) {
1512 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1514 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1515 clip = item->baseClip();
1519 clip = m_clipMonitor->activeClip();
1520 pos = m_clipMonitor->position();
1523 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1527 QString id = clip->getId();
1528 QString comment = clip->markerComment(pos);
1529 if (comment.isEmpty()) {
1530 m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1533 m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
1534 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1538 void MainWindow::slotDeleteAllClipMarkers() {
1539 DocClipBase *clip = NULL;
1540 if (m_projectMonitor->isActive()) {
1541 if (m_activeTimeline) {
1542 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1544 clip = item->baseClip();
1548 clip = m_clipMonitor->activeClip();
1551 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1554 m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
1555 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1558 void MainWindow::slotEditClipMarker() {
1559 DocClipBase *clip = NULL;
1561 if (m_projectMonitor->isActive()) {
1562 if (m_activeTimeline) {
1563 ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1565 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1566 clip = item->baseClip();
1570 clip = m_clipMonitor->activeClip();
1571 pos = m_clipMonitor->position();
1574 m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1578 QString id = clip->getId();
1579 QString oldcomment = clip->markerComment(pos);
1580 if (oldcomment.isEmpty()) {
1581 m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1585 CommentedTime marker(pos, oldcomment);
1586 MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
1587 if (d.exec() == QDialog::Accepted) {
1588 m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1589 if (d.newMarker().time() != pos) {
1590 // remove old marker
1591 m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
1593 if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1597 void MainWindow::slotAddGuide() {
1598 if (m_activeTimeline)
1599 m_activeTimeline->projectView()->slotAddGuide();
1602 void MainWindow::slotInsertSpace() {
1603 if (m_activeTimeline)
1604 m_activeTimeline->projectView()->slotInsertSpace();
1607 void MainWindow::slotRemoveSpace() {
1608 if (m_activeTimeline)
1609 m_activeTimeline->projectView()->slotRemoveSpace();
1612 void MainWindow::slotEditGuide() {
1613 if (m_activeTimeline)
1614 m_activeTimeline->projectView()->slotEditGuide();
1617 void MainWindow::slotDeleteGuide() {
1618 if (m_activeTimeline)
1619 m_activeTimeline->projectView()->slotDeleteGuide();
1622 void MainWindow::slotDeleteAllGuides() {
1623 if (m_activeTimeline)
1624 m_activeTimeline->projectView()->slotDeleteAllGuides();
1627 void MainWindow::slotCutTimelineClip() {
1628 if (m_activeTimeline) {
1629 m_activeTimeline->projectView()->cutSelectedClips();
1633 void MainWindow::slotAddProjectClip(KUrl url) {
1634 if (m_activeDocument)
1635 m_activeDocument->slotAddClipFile(url, QString());
1638 void MainWindow::slotAddTransition(QAction *result) {
1639 if (!result) return;
1640 QStringList info = result->data().toStringList();
1641 if (info.isEmpty()) return;
1642 QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
1643 if (m_activeTimeline && !transition.isNull()) {
1644 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
1648 void MainWindow::slotAddVideoEffect(QAction *result) {
1649 if (!result) return;
1650 QStringList info = result->data().toStringList();
1651 if (info.isEmpty()) return;
1652 QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
1653 slotAddEffect(effect);
1656 void MainWindow::slotAddAudioEffect(QAction *result) {
1657 if (!result) return;
1658 QStringList info = result->data().toStringList();
1659 if (info.isEmpty()) return;
1660 QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
1661 slotAddEffect(effect);
1664 void MainWindow::slotAddCustomEffect(QAction *result) {
1665 if (!result) return;
1666 QStringList info = result->data().toStringList();
1667 if (info.isEmpty()) return;
1668 QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
1669 slotAddEffect(effect);
1672 void MainWindow::slotZoomIn() {
1673 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1676 void MainWindow::slotZoomOut() {
1677 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1680 void MainWindow::slotFitZoom() {
1681 if (m_activeTimeline) {
1682 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1686 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1687 statusProgressBar->setValue(progress);
1688 if (progress >= 0) {
1689 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1690 statusProgressBar->setVisible(true);
1692 m_messageLabel->setMessage(QString(), DefaultMessage);
1693 statusProgressBar->setVisible(false);
1697 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1698 if (clip->clipType() == TEXT) {
1699 QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1700 QString path = clip->getProperty("resource");
1701 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1703 doc.setContent(clip->getProperty("xmldata"));
1704 dia_ui->setXml(doc);
1705 if (dia_ui->exec() == QDialog::Accepted) {
1706 QPixmap pix = dia_ui->renderedPixmap();
1708 //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1709 //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1710 QMap <QString, QString> newprops;
1711 newprops.insert("xmldata", dia_ui->xml().toString());
1712 EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1713 m_activeDocument->commandStack()->push(command);
1714 m_clipMonitor->refreshMonitor(true);
1715 m_activeDocument->setModified(true);
1719 //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1722 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1723 connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1724 if (dia.exec() == QDialog::Accepted) {
1725 EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1726 m_activeDocument->commandStack()->push(command);
1728 //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1729 if (dia.needsTimelineRefresh()) {
1730 // update clip occurences in timeline
1731 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1736 void MainWindow::customEvent(QEvent* e) {
1737 if (e->type() == QEvent::User) {
1738 // The timeline playing position changed...
1739 kDebug() << "RECIEVED JOG EVEMNT!!!";
1742 void MainWindow::slotActivateEffectStackView() {
1743 effectStack->raiseWindow(effectStackDock);
1746 void MainWindow::slotActivateTransitionView() {
1747 transitionConfig->raiseWindow(transitionConfigDock);
1750 void MainWindow::slotSnapRewind() {
1751 if (m_projectMonitor->isActive()) {
1752 if (m_activeTimeline)
1753 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1754 } else m_clipMonitor->slotSeekToPreviousSnap();
1757 void MainWindow::slotSnapForward() {
1758 if (m_projectMonitor->isActive()) {
1759 if (m_activeTimeline)
1760 m_activeTimeline->projectView()->slotSeekToNextSnap();
1761 } else m_clipMonitor->slotSeekToNextSnap();
1764 void MainWindow::slotClipStart() {
1765 if (m_projectMonitor->isActive()) {
1766 if (m_activeTimeline)
1767 m_activeTimeline->projectView()->clipStart();
1771 void MainWindow::slotClipEnd() {
1772 if (m_projectMonitor->isActive()) {
1773 if (m_activeTimeline)
1774 m_activeTimeline->projectView()->clipEnd();
1778 void MainWindow::slotChangeTool(QAction * action) {
1779 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1780 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1781 else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
1784 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1785 if (m_activeDocument && m_activeTimeline) {
1786 //m_activeDocument->setTool(tool);
1787 m_activeTimeline->projectView()->setTool(tool);
1791 void MainWindow::slotCopy() {
1792 if (!m_activeDocument || !m_activeTimeline) return;
1793 m_activeTimeline->projectView()->copyClip();
1796 void MainWindow::slotPaste() {
1797 if (!m_activeDocument || !m_activeTimeline) return;
1798 m_activeTimeline->projectView()->pasteClip();
1801 void MainWindow::slotPasteEffects() {
1802 if (!m_activeDocument || !m_activeTimeline) return;
1803 m_activeTimeline->projectView()->pasteClipEffects();
1806 void MainWindow::slotFind() {
1807 if (!m_activeDocument || !m_activeTimeline) return;
1808 m_projectSearch->setEnabled(false);
1809 m_findActivated = true;
1810 m_findString = QString();
1811 m_activeTimeline->projectView()->initSearchStrings();
1812 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1813 m_findTimer.start(5000);
1814 qApp->installEventFilter(this);
1817 void MainWindow::slotFindNext() {
1818 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1819 statusBar()->showMessage(i18n("Found : %1", m_findString));
1821 statusBar()->showMessage(i18n("Reached end of project"));
1823 m_findTimer.start(4000);
1826 void MainWindow::findAhead() {
1827 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1828 m_projectSearchNext->setEnabled(true);
1829 statusBar()->showMessage(i18n("Found : %1", m_findString));
1831 m_projectSearchNext->setEnabled(false);
1832 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1836 void MainWindow::findTimeout() {
1837 m_projectSearchNext->setEnabled(false);
1838 m_findActivated = false;
1839 m_findString = QString();
1840 statusBar()->showMessage(i18n("Find stopped"), 3000);
1841 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1842 m_projectSearch->setEnabled(true);
1843 removeEventFilter(this);
1846 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1847 if (m_findActivated) {
1848 if (ke->key() == Qt::Key_Backspace) {
1849 m_findString = m_findString.left(m_findString.length() - 1);
1851 if (!m_findString.isEmpty()) {
1857 m_findTimer.start(4000);
1860 } else if (ke->key() == Qt::Key_Escape) {
1864 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1865 m_findString += ke->text();
1869 m_findTimer.start(4000);
1873 } else KXmlGuiWindow::keyPressEvent(ke);
1877 /** Gets called when the window gets hidden */
1878 void MainWindow::hideEvent(QHideEvent *event) {
1879 // kDebug() << "I was hidden";
1880 // issue http://www.kdenlive.org/mantis/view.php?id=231
1881 if (this->isMinimized()) {
1882 // kDebug() << "I am minimized";
1883 if (m_monitorManager) m_monitorManager->stopActiveMonitor();
1887 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1888 if (m_findActivated) {
1889 if (event->type() == QEvent::ShortcutOverride) {
1890 QKeyEvent* ke = (QKeyEvent*) event;
1891 if (ke->text().trimmed().isEmpty()) return false;
1894 } else return false;
1896 // pass the event on to the parent class
1897 return QMainWindow::eventFilter(obj, event);
1901 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1902 KDialog *dialog = new KDialog(this);
1903 dialog->setCaption("Save clip zone");
1904 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1906 QWidget *widget = new QWidget(dialog);
1907 dialog->setMainWidget(widget);
1909 QVBoxLayout *vbox = new QVBoxLayout(widget);
1910 QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1911 QString path = m_activeDocument->projectFolder().path();
1913 path.append("untitled.westley");
1914 KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1915 url->setFilter("video/mlt-playlist");
1916 QLabel *label2 = new QLabel(i18n("Description:"), this);
1917 KLineEdit *edit = new KLineEdit(this);
1918 vbox->addWidget(label1);
1919 vbox->addWidget(url);
1920 vbox->addWidget(label2);
1921 vbox->addWidget(edit);
1922 if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1926 void MainWindow::slotSetInPoint() {
1927 if (m_clipMonitor->isActive()) {
1928 m_clipMonitor->slotSetZoneStart();
1929 } else m_activeTimeline->projectView()->setInPoint();
1932 void MainWindow::slotSetOutPoint() {
1933 if (m_clipMonitor->isActive()) {
1934 m_clipMonitor->slotSetZoneEnd();
1935 } else m_activeTimeline->projectView()->setOutPoint();
1939 #include "mainwindow.moc"