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>
53 #include <mlt++/Mlt.h>
55 #include "mainwindow.h"
56 #include "kdenlivesettings.h"
57 #include "kdenlivesettingsdialog.h"
58 #include "initeffects.h"
59 #include "profilesdialog.h"
60 #include "projectsettings.h"
62 #include "renderjob.h"
63 #include "clipmanager.h"
64 #include "projectlist.h"
66 #include "recmonitor.h"
67 #include "monitormanager.h"
68 #include "kdenlivedoc.h"
69 #include "trackview.h"
70 #include "customtrackview.h"
71 #include "effectslistview.h"
72 #include "effectstackview.h"
73 #include "transitionsettings.h"
74 #include "renderwidget.h"
76 #include "jogshuttle.h"
77 #include "clipproperties.h"
80 static const int ID_STATUS_MSG = 1;
81 static const int ID_EDITMODE_MSG = 2;
82 static const int ID_TIMELINE_MSG = 3;
83 static const int ID_TIMELINE_BUTTONS = 5;
84 static const int ID_TIMELINE_POS = 6;
85 static const int ID_TIMELINE_FORMAT = 7;
91 EffectsList MainWindow::videoEffects;
92 EffectsList MainWindow::audioEffects;
93 EffectsList MainWindow::customEffects;
94 EffectsList MainWindow::transitions;
96 MainWindow::MainWindow(QWidget *parent)
97 : KXmlGuiWindow(parent),
98 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
99 setlocale(LC_NUMERIC, "POSIX");
100 setFont(KGlobalSettings::toolBarFont());
102 m_commandStack = new QUndoGroup;
103 m_timelineArea = new KTabWidget(this);
104 m_timelineArea->setTabReorderingEnabled(true);
105 m_timelineArea->setTabBarHidden(true);
107 QToolButton *closeTabButton = new QToolButton;
108 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
109 closeTabButton->setIcon(KIcon("tab-close"));
110 closeTabButton->adjustSize();
111 closeTabButton->setToolTip(i18n("Close the current tab"));
112 m_timelineArea->setCornerWidget(closeTabButton);
113 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
115 connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
116 m_findTimer.setSingleShot(true);
118 initEffects::parseEffectFiles();
119 m_monitorManager = new MonitorManager();
121 projectListDock = new QDockWidget(i18n("Project Tree"), this);
122 projectListDock->setObjectName("project_tree");
123 m_projectList = new ProjectList(this);
124 projectListDock->setWidget(m_projectList);
125 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
127 effectListDock = new QDockWidget(i18n("Effect List"), this);
128 effectListDock->setObjectName("effect_list");
129 m_effectList = new EffectsListView();
131 //m_effectList = new KListWidget(this);
132 effectListDock->setWidget(m_effectList);
133 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
135 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
136 effectStackDock->setObjectName("effect_stack");
137 effectStack = new EffectStackView(this);
138 effectStackDock->setWidget(effectStack);
139 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
141 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
142 transitionConfigDock->setObjectName("transition");
143 transitionConfig = new TransitionSettings(this);
144 transitionConfigDock->setWidget(transitionConfig);
145 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
147 KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
148 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
152 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
153 clipMonitorDock->setObjectName("clip_monitor");
154 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
155 clipMonitorDock->setWidget(m_clipMonitor);
156 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
157 //m_clipMonitor->stop();
159 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
160 projectMonitorDock->setObjectName("project_monitor");
161 m_projectMonitor = new Monitor("project", m_monitorManager, this);
162 projectMonitorDock->setWidget(m_projectMonitor);
163 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
165 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
166 recMonitorDock->setObjectName("record_monitor");
167 m_recMonitor = new RecMonitor("record", this);
168 recMonitorDock->setWidget(m_recMonitor);
169 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
171 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
172 connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
174 undoViewDock = new QDockWidget(i18n("Undo History"), this);
175 undoViewDock->setObjectName("undo_history");
176 m_undoView = new QUndoView(this);
177 m_undoView->setCleanIcon(KIcon("edit-clear"));
178 m_undoView->setEmptyLabel(i18n("Clean"));
179 undoViewDock->setWidget(m_undoView);
180 m_undoView->setGroup(m_commandStack);
181 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
183 //overviewDock = new QDockWidget(i18n("Project Overview"), this);
184 //overviewDock->setObjectName("project_overview");
185 //m_overView = new CustomTrackView(NULL, NULL, this);
186 //overviewDock->setWidget(m_overView);
187 //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
190 //tabifyDockWidget(projectListDock, effectListDock);
191 tabifyDockWidget(projectListDock, effectStackDock);
192 tabifyDockWidget(projectListDock, transitionConfigDock);
193 //tabifyDockWidget(projectListDock, undoViewDock);
196 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
197 tabifyDockWidget(clipMonitorDock, recMonitorDock);
198 setCentralWidget(m_timelineArea);
200 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
201 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
203 // build effects menus
205 QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
206 QStringList effects = videoEffects.effectNames();
207 foreach(const QString &name, effects) {
208 action = new QAction(name, this);
209 action->setData(name);
210 videoEffectsMenu->addAction(action);
212 QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
213 effects = audioEffects.effectNames();
214 foreach(const QString &name, effects) {
215 action = new QAction(name, this);
216 action->setData(name);
217 audioEffectsMenu->addAction(action);
219 m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
220 effects = customEffects.effectNames();
221 foreach(const QString &name, effects) {
222 action = new QAction(name, this);
223 action->setData(name);
224 m_customEffectsMenu->addAction(action);
227 QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
228 const QList<QAction *> viewActions = createPopupMenu()->actions();
229 viewMenu->insertActions(NULL, viewActions);
231 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
232 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
233 connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
235 m_timelineContextMenu = new QMenu(this);
236 m_timelineContextClipMenu = new QMenu(this);
237 m_timelineContextTransitionMenu = new QMenu(this);
240 QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
241 effects = transitions.effectNames();
242 foreach(const QString &name, effects) {
243 action = new QAction(name, this);
244 action->setData(name);
245 transitionsMenu->addAction(action);
247 connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
249 m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
251 m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
252 m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
253 m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
254 m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
255 m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
257 QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
258 m_timelineContextClipMenu->addMenu(markersMenu);
259 m_timelineContextClipMenu->addMenu(transitionsMenu);
260 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
261 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
262 m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
264 m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
265 m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
267 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
268 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
269 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
270 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
271 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
272 connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
274 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
275 slotConnectMonitors();
277 setAutoSaveSettings();
279 if (KdenliveSettings::openlastproject()) {
283 activateShuttleDevice();
284 projectListDock->raise();
287 void MainWindow::queryQuit() {
288 kDebug() << "----- SAVING CONFUIG";
289 if (queryClose()) kapp->quit();
293 bool MainWindow::queryClose() {
295 if (m_activeDocument && m_activeDocument->isModified()) {
296 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
297 case KMessageBox::Yes :
298 // save document here. If saving fails, return false;
301 case KMessageBox::No :
310 void MainWindow::saveProperties(KConfig*) {
311 // save properties here,used by session management
316 void MainWindow::readProperties(KConfig *config) {
317 // read properties here,used by session management
318 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
319 openFile(KUrl(Lastproject));
322 void MainWindow::slotReloadEffects() {
323 initEffects::parseCustomEffectsFile();
324 m_customEffectsMenu->clear();
325 const QStringList effects = customEffects.effectNames();
327 foreach(const QString &name, effects) {
328 action = new QAction(name, this);
329 action->setData(name);
330 m_customEffectsMenu->addAction(action);
332 m_effectList->reloadEffectList();
335 void MainWindow::activateShuttleDevice() {
336 if (m_jogProcess) delete m_jogProcess;
338 if (KdenliveSettings::enableshuttle() == false) return;
339 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
340 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
341 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
342 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
343 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
344 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
345 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
348 void MainWindow::slotShuttleButton(int code) {
351 slotShuttleAction(KdenliveSettings::shuttle1());
354 slotShuttleAction(KdenliveSettings::shuttle2());
357 slotShuttleAction(KdenliveSettings::shuttle3());
360 slotShuttleAction(KdenliveSettings::shuttle4());
363 slotShuttleAction(KdenliveSettings::shuttle5());
368 void MainWindow::slotShuttleAction(int code) {
373 m_monitorManager->slotPlay();
376 m_monitorManager->slotPlay();
381 void MainWindow::slotFullScreen() {
382 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
385 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
386 if (!m_activeDocument) return;
387 if (effect.isNull()) {
388 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
391 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
392 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
395 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
396 if (clipMonitor) clipMonitorDock->raise();
397 else projectMonitorDock->raise();
400 void MainWindow::slotSetClipDuration(int id, int duration) {
401 if (!m_activeDocument) return;
402 m_activeDocument->setProducerDuration(id, duration);
405 void MainWindow::slotConnectMonitors() {
407 m_projectList->setRenderer(m_clipMonitor->render);
408 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
409 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
410 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
411 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
412 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
414 connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(int)), m_projectList, SLOT(slotRemoveInvalidClip(int)));
416 connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
418 connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
419 connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
422 void MainWindow::slotAdjustClipMonitor() {
423 clipMonitorDock->updateGeometry();
424 clipMonitorDock->adjustSize();
425 m_clipMonitor->resetSize();
428 void MainWindow::slotAdjustProjectMonitor() {
429 projectMonitorDock->updateGeometry();
430 projectMonitorDock->adjustSize();
431 m_projectMonitor->resetSize();
434 void MainWindow::setupActions() {
436 m_timecodeFormat = new KComboBox(this);
437 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
438 m_timecodeFormat->addItem(i18n("Frames"));
440 statusProgressBar = new QProgressBar(this);
441 statusProgressBar->setMinimum(0);
442 statusProgressBar->setMaximum(100);
443 statusProgressBar->setMaximumWidth(150);
444 statusProgressBar->setVisible(false);
446 QWidget *w = new QWidget;
448 QHBoxLayout *layout = new QHBoxLayout;
449 w->setLayout(layout);
450 layout->setContentsMargins(5, 0, 5, 0);
451 QToolBar *toolbar = new QToolBar("statusToolBar", this);
454 m_toolGroup = new QActionGroup(this);
456 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;}";
458 m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
459 m_buttonSelectTool->setCheckable(true);
460 m_buttonSelectTool->setChecked(true);
462 m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
463 m_buttonRazorTool->setCheckable(true);
464 m_buttonRazorTool->setChecked(false);
466 m_toolGroup->addAction(m_buttonSelectTool);
467 m_toolGroup->addAction(m_buttonRazorTool);
468 m_toolGroup->setExclusive(true);
469 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
471 QWidget * actionWidget;
472 actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
473 actionWidget->setMaximumWidth(24);
474 actionWidget->setMinimumHeight(17);
476 actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
477 actionWidget->setMaximumWidth(24);
478 actionWidget->setMinimumHeight(17);
480 toolbar->setStyleSheet(style1);
481 connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
483 toolbar->addSeparator();
484 m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
485 m_buttonFitZoom->setCheckable(false);
486 connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
488 actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
489 actionWidget->setMaximumWidth(24);
490 actionWidget->setMinimumHeight(17);
492 m_zoomSlider = new QSlider(Qt::Horizontal, this);
493 m_zoomSlider->setMaximum(13);
494 m_zoomSlider->setPageStep(1);
496 m_zoomSlider->setMaximumWidth(150);
497 m_zoomSlider->setMinimumWidth(100);
499 const int contentHeight = QFontMetrics(w->font()).height() + 8;
500 QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
501 style.append("QSlider::handle:horizontal { background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
502 m_zoomSlider->setStyleSheet(style);
504 //m_zoomSlider->setMaximumHeight(contentHeight);
505 //m_zoomSlider->height() + 5;
506 statusBar()->setMinimumHeight(contentHeight);
509 toolbar->addWidget(m_zoomSlider);
511 m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
512 m_buttonVideoThumbs->setCheckable(true);
513 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
514 connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
516 m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
517 m_buttonAudioThumbs->setCheckable(true);
518 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
519 connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
521 m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
522 m_buttonShowMarkers->setCheckable(true);
523 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
524 connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
526 m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
527 m_buttonSnap->setCheckable(true);
528 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
529 connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
530 layout->addWidget(toolbar);
533 actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
534 actionWidget->setMaximumWidth(24);
535 actionWidget->setMinimumHeight(17);
537 actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
538 actionWidget->setMaximumWidth(24);
539 actionWidget->setMinimumHeight(17);
541 actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
542 actionWidget->setMaximumWidth(24);
543 actionWidget->setMinimumHeight(17);
545 actionWidget = toolbar->widgetForAction(m_buttonSnap);
546 actionWidget->setMaximumWidth(24);
547 actionWidget->setMinimumHeight(17);
549 m_messageLabel = new StatusBarMessageLabel(this);
550 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
552 statusBar()->addWidget(m_messageLabel, 10);
553 statusBar()->addWidget(statusProgressBar, 0);
554 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
555 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
556 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
557 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
558 m_messageLabel->hide();
560 actionCollection()->addAction("select_tool", m_buttonSelectTool);
561 actionCollection()->addAction("razor_tool", m_buttonRazorTool);
563 actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
564 actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
565 actionCollection()->addAction("show_markers", m_buttonShowMarkers);
566 actionCollection()->addAction("snap", m_buttonSnap);
567 actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
569 m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
570 actionCollection()->addAction("project_find", m_projectSearch);
571 connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
572 m_projectSearch->setShortcut(Qt::Key_Slash);
574 m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
575 actionCollection()->addAction("project_find_next", m_projectSearchNext);
576 connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
577 m_projectSearchNext->setShortcut(Qt::Key_F3);
578 m_projectSearchNext->setEnabled(false);
580 KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
581 actionCollection()->addAction("manage_profiles", profilesAction);
582 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
584 KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
585 actionCollection()->addAction("project_settings", projectAction);
586 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
588 KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
589 actionCollection()->addAction("project_render", projectRender);
590 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
592 KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
593 monitorPlay->setShortcut(Qt::Key_Space);
594 actionCollection()->addAction("monitor_play", monitorPlay);
595 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
597 KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
598 monitorSeekBackward->setShortcut(Qt::Key_J);
599 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
600 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
602 KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
603 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
604 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
605 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
607 KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
608 monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
609 actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
610 connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
612 KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
613 monitorSeekForward->setShortcut(Qt::Key_L);
614 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
615 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
617 KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
618 clipStart->setShortcut(Qt::Key_Home);
619 actionCollection()->addAction("seek_clip_start", clipStart);
620 connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
622 KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
623 clipEnd->setShortcut(Qt::Key_End);
624 actionCollection()->addAction("seek_clip_end", clipEnd);
625 connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
627 KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
628 projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
629 actionCollection()->addAction("seek_start", projectStart);
630 connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
632 KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
633 projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
634 actionCollection()->addAction("seek_end", projectEnd);
635 connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
637 KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
638 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
639 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
640 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
642 KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
643 monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
644 actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
645 connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
647 KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
648 deleteTimelineClip->setShortcut(Qt::Key_Delete);
649 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
650 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
652 KAction* editTimelineClipSpeed = new KAction(KIcon("edit-delete"), i18n("Change Clip Speed"), this);
653 actionCollection()->addAction("change_clip_speed", editTimelineClipSpeed);
654 connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
656 KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
657 cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
658 actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
659 connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
661 KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
662 actionCollection()->addAction("add_clip_marker", addClipMarker);
663 connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
665 KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
666 actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
667 connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
669 KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
670 actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
671 connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
673 KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
674 actionCollection()->addAction("edit_clip_marker", editClipMarker);
675 connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
677 KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
678 actionCollection()->addAction("add_guide", addGuide);
679 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
681 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
682 actionCollection()->addAction("delete_guide", delGuide);
683 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
685 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
686 actionCollection()->addAction("edit_guide", editGuide);
687 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
689 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
690 actionCollection()->addAction("delete_all_guides", delAllGuides);
691 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
693 QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
694 actionCollection()->addAction("paste_effects", pasteEffects);
695 connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
697 KStandardAction::quit(this, SLOT(queryQuit()),
700 KStandardAction::open(this, SLOT(openFile()),
703 KStandardAction::save(this, SLOT(saveFile()),
706 KStandardAction::saveAs(this, SLOT(saveFileAs()),
709 KStandardAction::openNew(this, SLOT(newFile()),
712 KStandardAction::preferences(this, SLOT(slotPreferences()),
715 KStandardAction::copy(this, SLOT(slotCopy()),
718 KStandardAction::paste(this, SLOT(slotPaste()),
721 KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
723 undo->setEnabled(false);
724 connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
726 KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
728 redo->setEnabled(false);
729 connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
731 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
733 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
734 this, SLOT(slotDisplayActionMessage(QAction*)));
735 //connect(actionCollection(), SIGNAL( clearStatusText() ),
736 //statusBar(), SLOT( clear() ) );
739 void MainWindow::slotDisplayActionMessage(QAction *a) {
740 statusBar()->showMessage(a->data().toString(), 3000);
743 void MainWindow::saveOptions() {
744 KdenliveSettings::self()->writeConfig();
745 KSharedConfigPtr config = KGlobal::config();
746 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
750 void MainWindow::readOptions() {
751 KSharedConfigPtr config = KGlobal::config();
752 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
753 KConfigGroup initialGroup(config, "version");
754 if (!initialGroup.exists()) {
755 // this is our first run, show Wizard
756 Wizard *w = new Wizard(this);
757 if (w->exec() == QDialog::Accepted) {
759 initialGroup.writeEntry("version", "0.7");
765 void MainWindow::newFile() {
768 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
770 ProjectSettings *w = new ProjectSettings;
771 if (w->exec() != QDialog::Accepted) return;
772 profileName = w->selectedProfile();
773 projectFolder = w->selectedFolder();
776 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, this);
777 doc->setProfilePath(profileName);
778 TrackView *trackView = new TrackView(doc, this);
779 m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
780 if (m_timelineArea->count() == 1) {
781 connectDocumentInfo(doc);
782 connectDocument(trackView, doc);
783 } else m_timelineArea->setTabBarHidden(false);
786 void MainWindow::activateDocument() {
787 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
788 KdenliveDoc *currentDoc = currentTab->document();
789 connectDocumentInfo(currentDoc);
790 connectDocument(currentTab, currentDoc);
793 void MainWindow::slotRemoveTab() {
794 QWidget *w = m_timelineArea->currentWidget();
795 // closing current document
796 int ix = m_timelineArea->currentIndex() + 1;
797 if (ix == m_timelineArea->count()) ix = 0;
798 m_timelineArea->setCurrentIndex(ix);
799 TrackView *tabToClose = (TrackView *) w;
800 KdenliveDoc *docToClose = tabToClose->document();
801 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
802 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
807 void MainWindow::saveFileAs(const QString &outputFileName) {
808 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
809 m_activeDocument->setUrl(KUrl(outputFileName));
810 setCaption(m_activeDocument->description());
811 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
812 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
813 m_activeDocument->setModified(false);
814 m_fileOpenRecent->addUrl(KUrl(outputFileName));
817 void MainWindow::saveFileAs() {
818 QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
819 if (QFile::exists(outputFile)) {
820 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
822 saveFileAs(outputFile);
825 void MainWindow::saveFile() {
826 if (!m_activeDocument) return;
827 if (m_activeDocument->url().isEmpty()) {
830 saveFileAs(m_activeDocument->url().path());
834 void MainWindow::openFile() {
835 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
836 if (url.isEmpty()) return;
837 m_fileOpenRecent->addUrl(url);
841 void MainWindow::openLastFile() {
842 KSharedConfigPtr config = KGlobal::config();
843 KUrl::List urls = m_fileOpenRecent->urls();
844 if (urls.isEmpty()) newFile();
845 else openFile(urls.last());
848 void MainWindow::openFile(const KUrl &url) {
849 // Check for backup file
850 bool recovery = false;
851 QString directory = url.directory();
852 QString fileName = url.fileName();
854 recoveryUrl.setDirectory(directory);
855 recoveryUrl.setFileName("~" + fileName);
856 if (KIO::NetAccess::exists(recoveryUrl, KIO::NetAccess::SourceSide, this)) {
857 KFileItem bkup(KFileItem::Unknown, KFileItem::Unknown, recoveryUrl, true);
858 KFileItem src(KFileItem::Unknown, KFileItem::Unknown, url, true);
859 if (bkup.time(KFileItem::ModificationTime) > src.time(KFileItem::ModificationTime)) {
860 // Backup file is more recent than source file, ask user for recovery
861 if (KMessageBox::questionYesNo(this, i18n("A newer recovery file exists for <b>%1</b>\nOpen recovery file ?", url.fileName())) == KMessageBox::Yes) recovery = true;
865 //TODO: get video profile from url before opening it
866 /*MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
867 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
869 KdenliveSettings::setCurrent_profile(prof.path);*/
872 doc = new KdenliveDoc(recoveryUrl, KUrl(), m_commandStack, this);
874 doc->setModified(true);
875 } else doc = new KdenliveDoc(url, KUrl(), m_commandStack, this);
876 connectDocumentInfo(doc);
877 TrackView *trackView = new TrackView(doc, this);
878 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
879 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
880 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
881 slotGotProgressInfo(QString(), -1);
882 m_projectMonitor->refreshMonitor(true);
886 void MainWindow::parseProfiles() {
887 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
889 //KdenliveSettings::setDefaulttmpfolder();
890 if (KdenliveSettings::mltpath().isEmpty()) {
891 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
893 if (KdenliveSettings::rendererpath().isEmpty()) {
894 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
896 QStringList profilesFilter;
897 profilesFilter << "*";
898 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
900 if (profilesList.isEmpty()) {
901 // Cannot find MLT path, try finding inigo
902 QString profilePath = KdenliveSettings::rendererpath();
903 if (!profilePath.isEmpty()) {
904 profilePath = profilePath.section('/', 0, -3);
905 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
906 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
909 if (profilesList.isEmpty()) {
910 // Cannot find the MLT profiles, ask for location
911 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
912 getUrl->fileDialog()->setMode(KFile::Directory);
914 KUrl mltPath = getUrl->selectedUrl();
916 if (mltPath.isEmpty()) kapp->quit();
917 KdenliveSettings::setMltpath(mltPath.path());
918 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
922 if (KdenliveSettings::rendererpath().isEmpty()) {
923 // Cannot find the MLT inigo renderer, ask for location
924 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
926 KUrl rendererPath = getUrl->selectedUrl();
928 if (rendererPath.isEmpty()) kapp->quit();
929 KdenliveSettings::setRendererpath(rendererPath.path());
932 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
934 // Parse MLT profiles to build a list of available video formats
935 if (profilesList.isEmpty()) parseProfiles();
939 void MainWindow::slotEditProfiles() {
940 ProfilesDialog *w = new ProfilesDialog;
945 void MainWindow::slotEditProjectSettings() {
946 ProjectSettings *w = new ProjectSettings;
947 if (w->exec() == QDialog::Accepted) {
948 QString profile = w->selectedProfile();
949 m_activeDocument->setProfilePath(profile);
950 KdenliveSettings::setCurrent_profile(profile);
951 KdenliveSettings::setProject_fps(m_activeDocument->fps());
952 setCaption(m_activeDocument->description());
953 m_monitorManager->resetProfiles();
954 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
955 m_monitorManager->setTimecode(m_activeDocument->timecode());
956 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
958 // We need to desactivate & reactivate monitors to get a refresh
959 m_monitorManager->switchMonitors();
964 void MainWindow::slotRenderProject() {
965 if (!m_renderWidget) {
966 m_renderWidget = new RenderWidget(this);
967 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
969 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
970 if (currentTab) m_renderWidget->setTimeline(currentTab);
971 m_renderWidget->setDocument(m_activeDocument);*/
972 m_renderWidget->show();
975 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
976 if (dest.isEmpty()) return;
979 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
980 if (currentTab && zoneOnly) {
981 in = currentTab->inPoint();
982 out = currentTab->outPoint();
985 temp.setAutoRemove(false);
986 temp.setSuffix(".westley");
988 m_projectMonitor->saveSceneList(temp.fileName());
991 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
992 QString videoPlayer = "-";
994 videoPlayer = KdenliveSettings::defaultplayerapp();
995 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."));
997 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
998 QProcess::startDetached("kdenlive_render", args);
1002 void MainWindow::slotUpdateMousePosition(int pos) {
1003 if (m_activeDocument)
1004 switch (m_timecodeFormat->currentIndex()) {
1006 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1009 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1013 void MainWindow::slotUpdateDocumentState(bool modified) {
1014 setCaption(m_activeDocument->description(), modified);
1016 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1017 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1019 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1020 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1024 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1025 if (m_activeDocument) {
1026 if (m_activeDocument == doc) return;
1027 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1029 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1032 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1033 //m_projectMonitor->stop();
1034 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
1035 if (m_activeDocument) {
1036 if (m_activeDocument == doc) return;
1037 m_activeDocument->backupMltPlaylist();
1038 if (m_activeTimeline) {
1039 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1040 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1041 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1042 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1043 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1044 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1045 disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1046 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
1047 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1048 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1049 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1050 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1051 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1052 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1053 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1055 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1056 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1057 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1058 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1059 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1060 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1061 disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1062 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1063 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1065 m_activeDocument->setRenderer(NULL);
1066 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1067 m_clipMonitor->stop();
1069 KdenliveSettings::setCurrent_profile(doc->profilePath());
1070 KdenliveSettings::setProject_fps(doc->fps());
1071 m_monitorManager->resetProfiles();
1072 m_projectList->setDocument(doc);
1073 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1074 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1075 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1076 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1077 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1078 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1079 connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1080 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1081 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1082 connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1084 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1085 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1089 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1090 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1091 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1092 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1093 m_zoomSlider->setValue(doc->zoom());
1094 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1095 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1096 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1097 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1099 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1102 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1103 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1104 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1105 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1106 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1107 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1108 connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1110 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1111 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1112 m_activeTimeline = trackView;
1113 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1114 m_monitorManager->setTimecode(doc->timecode());
1115 doc->setRenderer(m_projectMonitor->render);
1116 m_commandStack->setActiveStack(doc->commandStack());
1117 doc->updateAllProjectClips();
1119 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
1120 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
1122 //m_overView->setScene(trackView->projectScene());
1123 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1124 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1126 setCaption(doc->description());
1127 m_activeDocument = doc;
1130 void MainWindow::slotPreferences(int page, int option) {
1131 //An instance of your dialog could be already created and could be
1132 // cached, in which case you want to display the cached dialog
1133 // instead of creating another one
1134 if (KConfigDialog::showDialog("settings")) {
1135 if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
1139 // KConfigDialog didn't find an instance of this dialog, so lets
1141 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1142 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1143 connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(resetProfiles()));
1145 if (page != -1) dialog->showPage(page, option);
1148 void MainWindow::updateConfiguration() {
1149 //TODO: we should apply settings to all projects, not only the current one
1150 if (m_activeTimeline) {
1151 m_activeTimeline->refresh();
1152 m_activeTimeline->projectView()->checkAutoScroll();
1153 m_activeTimeline->projectView()->checkTrackHeight();
1154 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1156 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1157 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1158 activateShuttleDevice();
1162 void MainWindow::slotSwitchVideoThumbs() {
1163 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1164 if (m_activeTimeline) {
1165 m_activeTimeline->refresh();
1167 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1170 void MainWindow::slotSwitchAudioThumbs() {
1171 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1172 if (m_activeTimeline) {
1173 m_activeTimeline->refresh();
1174 m_activeTimeline->projectView()->checkAutoScroll();
1175 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1177 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1180 void MainWindow::slotSwitchMarkersComments() {
1181 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1182 if (m_activeTimeline) {
1183 m_activeTimeline->refresh();
1185 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1188 void MainWindow::slotSwitchSnap() {
1189 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1190 m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1194 void MainWindow::slotDeleteTimelineClip() {
1195 if (m_activeTimeline) {
1196 m_activeTimeline->projectView()->deleteSelectedClips();
1200 void MainWindow::slotChangeClipSpeed() {
1201 if (m_activeTimeline) {
1202 m_activeTimeline->projectView()->changeClipSpeed();
1206 void MainWindow::slotAddClipMarker() {
1207 if (m_activeTimeline) {
1208 m_activeTimeline->projectView()->slotAddClipMarker();
1212 void MainWindow::slotDeleteClipMarker() {
1213 if (m_activeTimeline) {
1214 m_activeTimeline->projectView()->slotDeleteClipMarker();
1218 void MainWindow::slotDeleteAllClipMarkers() {
1219 if (m_activeTimeline) {
1220 m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1224 void MainWindow::slotEditClipMarker() {
1225 if (m_activeTimeline) {
1226 m_activeTimeline->projectView()->slotEditClipMarker();
1230 void MainWindow::slotAddGuide() {
1231 if (m_activeTimeline)
1232 m_activeTimeline->projectView()->slotAddGuide();
1235 void MainWindow::slotEditGuide() {
1236 if (m_activeTimeline)
1237 m_activeTimeline->projectView()->slotEditGuide();
1240 void MainWindow::slotDeleteGuide() {
1241 if (m_activeTimeline)
1242 m_activeTimeline->projectView()->slotDeleteGuide();
1245 void MainWindow::slotDeleteAllGuides() {
1246 if (m_activeTimeline)
1247 m_activeTimeline->projectView()->slotDeleteAllGuides();
1250 void MainWindow::slotCutTimelineClip() {
1251 if (m_activeTimeline) {
1252 m_activeTimeline->projectView()->cutSelectedClips();
1256 void MainWindow::slotAddProjectClip(KUrl url) {
1257 if (m_activeDocument)
1258 m_activeDocument->slotAddClipFile(url, QString());
1261 void MainWindow::slotAddTransition(QAction *result) {
1262 if (!result) return;
1263 QDomElement effect = transitions.getEffectByName(result->data().toString());
1264 if (m_activeTimeline) {
1265 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1269 void MainWindow::slotAddVideoEffect(QAction *result) {
1270 if (!result) return;
1271 QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1272 slotAddEffect(effect);
1275 void MainWindow::slotAddAudioEffect(QAction *result) {
1276 if (!result) return;
1277 QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1278 slotAddEffect(effect);
1281 void MainWindow::slotAddCustomEffect(QAction *result) {
1282 if (!result) return;
1283 QDomElement effect = customEffects.getEffectByName(result->data().toString());
1284 slotAddEffect(effect);
1287 void MainWindow::slotZoomIn() {
1288 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1291 void MainWindow::slotZoomOut() {
1292 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1295 void MainWindow::slotFitZoom() {
1296 if (m_activeTimeline) {
1297 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1301 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1302 statusProgressBar->setValue(progress);
1303 if (progress >= 0) {
1304 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1305 statusProgressBar->setVisible(true);
1307 m_messageLabel->setMessage(QString(), DefaultMessage);
1308 statusProgressBar->setVisible(false);
1312 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1313 if (clip->clipType() == TEXT) {
1314 m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1317 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1318 connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1319 if (dia.exec() == QDialog::Accepted) {
1320 m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1321 if (dia.needsTimelineRefresh()) {
1322 // update clip occurences in timeline
1323 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1328 void MainWindow::customEvent(QEvent* e) {
1329 if (e->type() == QEvent::User) {
1330 // The timeline playing position changed...
1331 kDebug() << "RECIEVED JOG EVEMNT!!!";
1334 void MainWindow::slotActivateEffectStackView() {
1335 effectStack->raiseWindow(effectStackDock);
1338 void MainWindow::slotActivateTransitionView() {
1339 transitionConfig->raiseWindow(transitionConfigDock);
1342 void MainWindow::slotSnapRewind() {
1343 if (m_monitorManager->projectMonitorFocused()) {
1344 if (m_activeTimeline)
1345 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1349 void MainWindow::slotSnapForward() {
1350 if (m_monitorManager->projectMonitorFocused()) {
1351 if (m_activeTimeline)
1352 m_activeTimeline->projectView()->slotSeekToNextSnap();
1356 void MainWindow::slotClipStart() {
1357 if (m_monitorManager->projectMonitorFocused()) {
1358 if (m_activeTimeline)
1359 m_activeTimeline->projectView()->clipStart();
1363 void MainWindow::slotClipEnd() {
1364 if (m_monitorManager->projectMonitorFocused()) {
1365 if (m_activeTimeline)
1366 m_activeTimeline->projectView()->clipEnd();
1370 void MainWindow::slotChangeTool(QAction * action) {
1371 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1372 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1375 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1376 if (m_activeDocument && m_activeTimeline) {
1377 //m_activeDocument->setTool(tool);
1378 m_activeTimeline->projectView()->setTool(tool);
1382 void MainWindow::slotCopy() {
1383 if (!m_activeDocument || !m_activeTimeline) return;
1384 m_activeTimeline->projectView()->copyClip();
1387 void MainWindow::slotPaste() {
1388 if (!m_activeDocument || !m_activeTimeline) return;
1389 m_activeTimeline->projectView()->pasteClip();
1392 void MainWindow::slotPasteEffects() {
1393 if (!m_activeDocument || !m_activeTimeline) return;
1394 m_activeTimeline->projectView()->pasteClipEffects();
1397 void MainWindow::slotFind() {
1398 if (!m_activeDocument || !m_activeTimeline) return;
1399 m_projectSearch->setEnabled(false);
1400 m_findActivated = true;
1401 m_findString = QString();
1402 m_activeTimeline->projectView()->initSearchStrings();
1403 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1404 m_findTimer.start(5000);
1405 qApp->installEventFilter(this);
1408 void MainWindow::slotFindNext() {
1409 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1410 statusBar()->showMessage(i18n("Found : %1", m_findString));
1412 statusBar()->showMessage(i18n("Reached end of project"));
1414 m_findTimer.start(4000);
1417 void MainWindow::findAhead() {
1418 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1419 m_projectSearchNext->setEnabled(true);
1420 statusBar()->showMessage(i18n("Found : %1", m_findString));
1422 m_projectSearchNext->setEnabled(false);
1423 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1427 void MainWindow::findTimeout() {
1428 m_projectSearchNext->setEnabled(false);
1429 m_findActivated = false;
1430 m_findString = QString();
1431 statusBar()->showMessage(i18n("Find stopped"), 3000);
1432 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1433 m_projectSearch->setEnabled(true);
1434 removeEventFilter(this);
1437 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1438 if (m_findActivated) {
1439 if (ke->key() == Qt::Key_Backspace) {
1440 m_findString = m_findString.left(m_findString.length() - 1);
1442 if (!m_findString.isEmpty()) {
1448 m_findTimer.start(4000);
1451 } else if (ke->key() == Qt::Key_Escape) {
1455 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1456 m_findString += ke->text();
1460 m_findTimer.start(4000);
1464 } else KXmlGuiWindow::keyPressEvent(ke);
1467 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1468 if (m_findActivated) {
1469 if (event->type() == QEvent::ShortcutOverride) {
1470 QKeyEvent* ke = (QKeyEvent*) event;
1471 if (ke->text().trimmed().isEmpty()) return false;
1474 } else return false;
1476 // pass the event on to the parent class
1477 return QMainWindow::eventFilter(obj, event);
1481 #include "mainwindow.moc"