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 <mlt++/Mlt.h>
54 #include "mainwindow.h"
55 #include "kdenlivesettings.h"
56 #include "kdenlivesettingsdialog.h"
57 #include "initeffects.h"
58 #include "profilesdialog.h"
59 #include "projectsettings.h"
61 #include "renderjob.h"
62 #include "clipmanager.h"
63 #include "projectlist.h"
65 #include "recmonitor.h"
66 #include "monitormanager.h"
67 #include "kdenlivedoc.h"
68 #include "trackview.h"
69 #include "customtrackview.h"
70 #include "effectslistview.h"
71 #include "effectstackview.h"
72 #include "transitionsettings.h"
73 #include "renderwidget.h"
75 #include "jogshuttle.h"
76 #include "clipproperties.h"
78 #define ID_STATUS_MSG 1
79 #define ID_EDITMODE_MSG 2
80 #define ID_TIMELINE_MSG 3
81 #define ID_TIMELINE_BUTTONS 5
82 #define ID_TIMELINE_POS 6
83 #define ID_TIMELINE_FORMAT 7
85 EffectsList MainWindow::videoEffects;
86 EffectsList MainWindow::audioEffects;
87 EffectsList MainWindow::customEffects;
88 EffectsList MainWindow::transitions;
90 MainWindow::MainWindow(QWidget *parent)
91 : KXmlGuiWindow(parent),
92 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
93 setlocale(LC_NUMERIC, "POSIX");
95 setFont(KGlobalSettings::toolBarFont());
96 m_commandStack = new QUndoGroup;
97 m_timelineArea = new KTabWidget(this);
98 m_timelineArea->setTabReorderingEnabled(true);
99 m_timelineArea->setTabBarHidden(true);
101 QToolButton *closeTabButton = new QToolButton;
102 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
103 closeTabButton->setIcon(KIcon("tab-close"));
104 closeTabButton->adjustSize();
105 closeTabButton->setToolTip(i18n("Close the current tab"));
106 m_timelineArea->setCornerWidget(closeTabButton);
107 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
109 connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
110 m_findTimer.setSingleShot(true);
112 initEffects::parseEffectFiles();
113 m_monitorManager = new MonitorManager();
115 projectListDock = new QDockWidget(i18n("Project Tree"), this);
116 projectListDock->setObjectName("project_tree");
117 m_projectList = new ProjectList(this);
118 projectListDock->setWidget(m_projectList);
119 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
121 effectListDock = new QDockWidget(i18n("Effect List"), this);
122 effectListDock->setObjectName("effect_list");
123 m_effectList = new EffectsListView();
125 //m_effectList = new KListWidget(this);
126 effectListDock->setWidget(m_effectList);
127 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
129 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
130 effectStackDock->setObjectName("effect_stack");
131 effectStack = new EffectStackView(this);
132 effectStackDock->setWidget(effectStack);
133 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
135 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
136 transitionConfigDock->setObjectName("transition");
137 transitionConfig = new TransitionSettings(this);
138 transitionConfigDock->setWidget(transitionConfig);
139 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
142 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
143 clipMonitorDock->setObjectName("clip_monitor");
144 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
145 clipMonitorDock->setWidget(m_clipMonitor);
146 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
147 //m_clipMonitor->stop();
149 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
150 projectMonitorDock->setObjectName("project_monitor");
151 m_projectMonitor = new Monitor("project", m_monitorManager, this);
152 projectMonitorDock->setWidget(m_projectMonitor);
153 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
155 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
156 recMonitorDock->setObjectName("record_monitor");
157 m_recMonitor = new RecMonitor("record", this);
158 recMonitorDock->setWidget(m_recMonitor);
159 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
161 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
163 undoViewDock = new QDockWidget(i18n("Undo History"), this);
164 undoViewDock->setObjectName("undo_history");
165 m_undoView = new QUndoView(this);
166 m_undoView->setCleanIcon(KIcon("edit-clear"));
167 m_undoView->setEmptyLabel(i18n("Clean"));
168 undoViewDock->setWidget(m_undoView);
169 m_undoView->setGroup(m_commandStack);
170 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
172 //overviewDock = new QDockWidget(i18n("Project Overview"), this);
173 //overviewDock->setObjectName("project_overview");
174 //m_overView = new CustomTrackView(NULL, NULL, this);
175 //overviewDock->setWidget(m_overView);
176 //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
179 //tabifyDockWidget(projectListDock, effectListDock);
180 tabifyDockWidget(projectListDock, effectStackDock);
181 tabifyDockWidget(projectListDock, transitionConfigDock);
182 //tabifyDockWidget(projectListDock, undoViewDock);
183 projectListDock->raise();
185 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
186 tabifyDockWidget(clipMonitorDock, recMonitorDock);
187 setCentralWidget(m_timelineArea);
189 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
190 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
192 // build effects menus
194 QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
195 QStringList effects = videoEffects.effectNames();
196 foreach(const QString &name, effects) {
197 action = new QAction(name, this);
198 action->setData(name);
199 videoEffectsMenu->addAction(action);
201 QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
202 effects = audioEffects.effectNames();
203 foreach(const QString &name, effects) {
204 action = new QAction(name, this);
205 action->setData(name);
206 audioEffectsMenu->addAction(action);
208 QMenu *customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
209 effects = customEffects.effectNames();
210 foreach(const QString &name, effects) {
211 action = new QAction(name, this);
212 action->setData(name);
213 customEffectsMenu->addAction(action);
216 QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
217 const QList<QAction *> viewActions = createPopupMenu()->actions();
218 viewMenu->insertActions(NULL, viewActions);
220 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
221 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
222 connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
224 m_timelineContextMenu = new QMenu(this);
225 m_timelineContextClipMenu = new QMenu(this);
226 m_timelineContextTransitionMenu = new QMenu(this);
229 QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
230 effects = transitions.effectNames();
231 foreach(const QString &name, effects) {
232 action = new QAction(name, this);
233 action->setData(name);
234 transitionsMenu->addAction(action);
236 connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
238 m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
240 m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
241 m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
242 m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
244 QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
245 m_timelineContextClipMenu->addMenu(markersMenu);
246 m_timelineContextClipMenu->addMenu(transitionsMenu);
247 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
248 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
249 m_timelineContextClipMenu->addMenu(customEffectsMenu);
251 m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
252 m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
254 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
255 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
256 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
257 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
258 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
259 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
260 slotConnectMonitors();
262 setAutoSaveSettings();
264 if (KdenliveSettings::openlastproject()) {
268 activateShuttleDevice();
271 void MainWindow::queryQuit() {
272 kDebug() << "----- SAVING CONFUIG";
273 if (queryClose()) kapp->quit();
277 bool MainWindow::queryClose() {
279 if (m_activeDocument && m_activeDocument->isModified()) {
280 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
281 case KMessageBox::Yes :
282 // save document here. If saving fails, return false;
284 case KMessageBox::No :
293 void MainWindow::saveProperties(KConfig*) {
294 // save properties here,used by session management
299 void MainWindow::readProperties(KConfig *config) {
300 // read properties here,used by session management
301 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
302 openFile(KUrl(Lastproject));
305 void MainWindow::activateShuttleDevice() {
306 if (m_jogProcess) delete m_jogProcess;
308 if (KdenliveSettings::enableshuttle() == false) return;
309 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
310 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
311 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
312 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
313 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
314 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
315 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
318 void MainWindow::slotShuttleButton(int code) {
321 slotShuttleAction(KdenliveSettings::shuttle1());
324 slotShuttleAction(KdenliveSettings::shuttle2());
327 slotShuttleAction(KdenliveSettings::shuttle3());
330 slotShuttleAction(KdenliveSettings::shuttle4());
333 slotShuttleAction(KdenliveSettings::shuttle5());
338 void MainWindow::slotShuttleAction(int code) {
343 m_monitorManager->slotPlay();
346 m_monitorManager->slotPlay();
351 void MainWindow::slotFullScreen() {
352 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
355 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
356 if (!m_activeDocument) return;
357 if (effect.isNull()) {
358 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
361 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
362 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
365 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
366 if (clipMonitor) clipMonitorDock->raise();
367 else projectMonitorDock->raise();
370 void MainWindow::slotSetClipDuration(int id, int duration) {
371 if (!m_activeDocument) return;
372 m_activeDocument->setProducerDuration(id, duration);
375 void MainWindow::slotConnectMonitors() {
377 m_projectList->setRenderer(m_clipMonitor->render);
378 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
379 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
380 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
381 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
382 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
383 connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
386 void MainWindow::setupActions() {
388 m_timecodeFormat = new KComboBox(this);
389 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
390 m_timecodeFormat->addItem(i18n("Frames"));
392 statusProgressBar = new QProgressBar(this);
393 statusProgressBar->setMinimum(0);
394 statusProgressBar->setMaximum(100);
395 statusProgressBar->setMaximumWidth(150);
396 statusProgressBar->setVisible(false);
398 QWidget *w = new QWidget;
400 QHBoxLayout *layout = new QHBoxLayout;
401 w->setLayout(layout);
402 layout->setContentsMargins(5, 0, 5, 0);
403 QToolBar *toolbar = new QToolBar("statusToolBar", this);
406 m_toolGroup = new QActionGroup(this);
408 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;}";
410 m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
411 m_buttonSelectTool->setCheckable(true);
412 m_buttonSelectTool->setChecked(true);
414 m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
415 m_buttonRazorTool->setCheckable(true);
416 m_buttonRazorTool->setChecked(false);
418 m_toolGroup->addAction(m_buttonSelectTool);
419 m_toolGroup->addAction(m_buttonRazorTool);
420 m_toolGroup->setExclusive(true);
421 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
423 QWidget * actionWidget;
424 actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
425 actionWidget->setMaximumWidth(24);
426 actionWidget->setMinimumHeight(17);
428 actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
429 actionWidget->setMaximumWidth(24);
430 actionWidget->setMinimumHeight(17);
432 toolbar->setStyleSheet(style1);
433 connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
435 toolbar->addSeparator();
436 m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
437 m_buttonFitZoom->setCheckable(false);
438 connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
440 actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
441 actionWidget->setMaximumWidth(24);
442 actionWidget->setMinimumHeight(17);
444 m_zoomSlider = new QSlider(Qt::Horizontal, this);
445 m_zoomSlider->setMaximum(13);
447 m_zoomSlider->setMaximumWidth(150);
448 m_zoomSlider->setMinimumWidth(100);
450 const int contentHeight = QFontMetrics(w->font()).height() + 8;
451 QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
452 style.append("QSlider::handle:horizontal { background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
453 m_zoomSlider->setStyleSheet(style);
455 //m_zoomSlider->setMaximumHeight(contentHeight);
456 //m_zoomSlider->height() + 5;
457 statusBar()->setMinimumHeight(contentHeight);
460 toolbar->addWidget(m_zoomSlider);
462 m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
463 m_buttonVideoThumbs->setCheckable(true);
464 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
465 connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
467 m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
468 m_buttonAudioThumbs->setCheckable(true);
469 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
470 connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
472 m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
473 m_buttonShowMarkers->setCheckable(true);
474 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
475 connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
477 m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
478 m_buttonSnap->setCheckable(true);
479 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
480 connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
481 layout->addWidget(toolbar);
484 actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
485 actionWidget->setMaximumWidth(24);
486 actionWidget->setMinimumHeight(17);
488 actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
489 actionWidget->setMaximumWidth(24);
490 actionWidget->setMinimumHeight(17);
492 actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
493 actionWidget->setMaximumWidth(24);
494 actionWidget->setMinimumHeight(17);
496 actionWidget = toolbar->widgetForAction(m_buttonSnap);
497 actionWidget->setMaximumWidth(24);
498 actionWidget->setMinimumHeight(17);
500 m_messageLabel = new StatusBarMessageLabel(this);
501 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
503 statusBar()->addWidget(m_messageLabel, 10);
504 statusBar()->addWidget(statusProgressBar, 0);
505 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
506 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
507 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
508 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
509 m_messageLabel->hide();
511 actionCollection()->addAction("select_tool", m_buttonSelectTool);
512 actionCollection()->addAction("razor_tool", m_buttonRazorTool);
514 actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
515 actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
516 actionCollection()->addAction("show_markers", m_buttonShowMarkers);
517 actionCollection()->addAction("snap", m_buttonSnap);
518 actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
520 m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
521 actionCollection()->addAction("project_find", m_projectSearch);
522 connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
523 m_projectSearch->setShortcut(Qt::Key_Slash);
525 m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
526 actionCollection()->addAction("project_find_next", m_projectSearchNext);
527 connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
528 m_projectSearchNext->setShortcut(Qt::Key_F3);
529 m_projectSearchNext->setEnabled(false);
531 KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
532 actionCollection()->addAction("manage_profiles", profilesAction);
533 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
535 KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
536 actionCollection()->addAction("project_settings", projectAction);
537 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
539 KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
540 actionCollection()->addAction("project_render", projectRender);
541 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
543 KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
544 monitorPlay->setShortcut(Qt::Key_Space);
545 actionCollection()->addAction("monitor_play", monitorPlay);
546 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
548 KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
549 monitorSeekBackward->setShortcut(Qt::Key_J);
550 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
551 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
553 KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
554 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
555 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
556 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
558 KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
559 monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
560 actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
561 connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
563 KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
564 monitorSeekForward->setShortcut(Qt::Key_L);
565 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
566 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
568 KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
569 clipStart->setShortcut(Qt::Key_Home);
570 actionCollection()->addAction("seek_clip_start", clipStart);
571 connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
573 KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
574 clipEnd->setShortcut(Qt::Key_End);
575 actionCollection()->addAction("seek_clip_end", clipEnd);
576 connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
578 KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
579 projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
580 actionCollection()->addAction("seek_start", projectStart);
581 connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
583 KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
584 projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
585 actionCollection()->addAction("seek_end", projectEnd);
586 connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
588 KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
589 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
590 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
591 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
593 KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
594 monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
595 actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
596 connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
598 KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
599 deleteTimelineClip->setShortcut(Qt::Key_Delete);
600 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
601 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
603 KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
604 cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
605 actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
606 connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
608 KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
609 actionCollection()->addAction("add_clip_marker", addClipMarker);
610 connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
612 KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
613 actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
614 connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
616 KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
617 actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
618 connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
620 KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
621 actionCollection()->addAction("edit_clip_marker", editClipMarker);
622 connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
624 KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
625 actionCollection()->addAction("add_guide", addGuide);
626 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
628 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
629 actionCollection()->addAction("delete_guide", delGuide);
630 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
632 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
633 actionCollection()->addAction("edit_guide", editGuide);
634 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
636 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
637 actionCollection()->addAction("delete_all_guides", delAllGuides);
638 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
640 KStandardAction::quit(this, SLOT(queryQuit()),
643 KStandardAction::open(this, SLOT(openFile()),
646 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
649 KStandardAction::save(this, SLOT(saveFile()),
652 KStandardAction::saveAs(this, SLOT(saveFileAs()),
655 KStandardAction::openNew(this, SLOT(newFile()),
658 KStandardAction::preferences(this, SLOT(slotPreferences()),
661 KStandardAction::copy(this, SLOT(slotCopy()),
664 KStandardAction::paste(this, SLOT(slotPaste()),
667 KStandardAction::undo(this, SLOT(undo()),
670 KStandardAction::redo(this, SLOT(redo()),
673 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
675 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
676 this, SLOT(slotDisplayActionMessage(QAction*)));
677 //connect(actionCollection(), SIGNAL( clearStatusText() ),
678 //statusBar(), SLOT( clear() ) );
683 void MainWindow::undo() {
684 m_commandStack->undo();
687 void MainWindow::redo() {
688 m_commandStack->redo();
691 void MainWindow::slotDisplayActionMessage(QAction *a) {
692 statusBar()->showMessage(a->data().toString(), 3000);
695 void MainWindow::saveOptions() {
696 KdenliveSettings::self()->writeConfig();
697 KSharedConfigPtr config = KGlobal::config();
698 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
702 void MainWindow::readOptions() {
703 KSharedConfigPtr config = KGlobal::config();
704 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
707 void MainWindow::newFile() {
710 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
712 ProjectSettings *w = new ProjectSettings;
713 if (w->exec() != QDialog::Accepted) return;
714 profileName = w->selectedProfile();
715 projectFolder = w->selectedFolder();
718 MltVideoProfile prof;
719 if (!profileName.isEmpty()) prof = ProfilesDialog::getVideoProfile(profileName);
720 else prof = ProfilesDialog::getVideoProfile("dv_pal");
721 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
722 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
723 TrackView *trackView = new TrackView(doc, this);
724 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
725 if (m_timelineArea->count() == 1) {
726 connectDocumentInfo(doc);
727 connectDocument(trackView, doc);
728 } else m_timelineArea->setTabBarHidden(false);
731 void MainWindow::activateDocument() {
732 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
733 KdenliveDoc *currentDoc = currentTab->document();
734 connectDocumentInfo(currentDoc);
735 connectDocument(currentTab, currentDoc);
738 void MainWindow::slotRemoveTab() {
739 QWidget *w = m_timelineArea->currentWidget();
740 // closing current document
741 int ix = m_timelineArea->currentIndex() + 1;
742 if (ix == m_timelineArea->count()) ix = 0;
743 m_timelineArea->setCurrentIndex(ix);
744 TrackView *tabToClose = (TrackView *) w;
745 KdenliveDoc *docToClose = tabToClose->document();
746 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
747 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
752 void MainWindow::saveFileAs(const QString &outputFileName) {
753 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml(m_activeTimeline->projectView()->xmlInfo()));
754 m_activeDocument->setUrl(KUrl(outputFileName));
755 setCaption(m_activeDocument->description());
756 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
757 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
758 m_activeDocument->setModified(false);
759 m_fileOpenRecent->addUrl(KUrl(outputFileName));
762 void MainWindow::saveFileAs() {
763 QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
764 if (QFile::exists(outputFile)) {
765 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
767 saveFileAs(outputFile);
770 void MainWindow::saveFile() {
771 if (!m_activeDocument) return;
772 if (m_activeDocument->url().isEmpty()) {
775 saveFileAs(m_activeDocument->url().path());
779 void MainWindow::openFile() { //changed
780 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
781 if (url.isEmpty()) return;
782 m_fileOpenRecent->addUrl(url);
786 void MainWindow::openLastFile() {
787 KSharedConfigPtr config = KGlobal::config();
788 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
789 openFile(KUrl(Lastproject));
792 void MainWindow::openFile(const KUrl &url) { //new
793 //TODO: get video profile from url before opening it
794 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
795 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
796 KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
797 connectDocumentInfo(doc);
798 TrackView *trackView = new TrackView(doc, this);
799 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
800 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
801 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
802 slotGotProgressInfo(QString(), -1);
803 m_projectMonitor->refreshMonitor(true);
804 //connectDocument(trackView, doc);
808 void MainWindow::parseProfiles() {
809 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
811 //KdenliveSettings::setDefaulttmpfolder();
812 if (KdenliveSettings::mltpath().isEmpty()) {
813 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
815 if (KdenliveSettings::rendererpath().isEmpty()) {
816 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
818 QStringList profilesFilter;
819 profilesFilter << "*";
820 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
822 if (profilesList.isEmpty()) {
823 // Cannot find MLT path, try finding inigo
824 QString profilePath = KdenliveSettings::rendererpath();
825 if (!profilePath.isEmpty()) {
826 profilePath = profilePath.section('/', 0, -3);
827 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
828 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
831 if (profilesList.isEmpty()) {
832 // Cannot find the MLT profiles, ask for location
833 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
834 getUrl->fileDialog()->setMode(KFile::Directory);
836 KUrl mltPath = getUrl->selectedUrl();
838 if (mltPath.isEmpty()) kapp->quit();
839 KdenliveSettings::setMltpath(mltPath.path());
840 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
844 if (KdenliveSettings::rendererpath().isEmpty()) {
845 // Cannot find the MLT inigo renderer, ask for location
846 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
848 KUrl rendererPath = getUrl->selectedUrl();
850 if (rendererPath.isEmpty()) kapp->quit();
851 KdenliveSettings::setRendererpath(rendererPath.path());
854 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
856 // Parse MLT profiles to build a list of available video formats
857 if (profilesList.isEmpty()) parseProfiles();
861 void MainWindow::slotEditProfiles() {
862 ProfilesDialog *w = new ProfilesDialog;
867 void MainWindow::slotEditProjectSettings() {
868 ProjectSettings *w = new ProjectSettings;
869 if (w->exec() == QDialog::Accepted) {
870 QString profile = w->selectedProfile();
871 m_activeDocument->setProfilePath(profile);
872 m_monitorManager->resetProfiles(profile);
873 setCaption(m_activeDocument->description());
874 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
875 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
876 m_monitorManager->setTimecode(m_activeDocument->timecode());
877 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
879 // We need to desactivate & reactivate monitors to get a refresh
880 m_monitorManager->switchMonitors();
885 void MainWindow::slotRenderProject() {
886 if (!m_renderWidget) {
887 m_renderWidget = new RenderWidget(this);
888 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
890 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
891 if (currentTab) m_renderWidget->setTimeline(currentTab);
892 m_renderWidget->setDocument(m_activeDocument);*/
893 m_renderWidget->show();
896 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
897 if (dest.isEmpty()) return;
900 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
901 if (currentTab && zoneOnly) {
902 in = currentTab->inPoint();
903 out = currentTab->outPoint();
906 temp.setAutoRemove(false);
907 temp.setSuffix(".westley");
909 m_projectMonitor->saveSceneList(temp.fileName());
912 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
913 QString videoPlayer = "-";
915 videoPlayer = KdenliveSettings::defaultplayerapp();
916 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."));
918 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
919 QProcess::startDetached("kdenlive_render", args);
923 void MainWindow::slotUpdateMousePosition(int pos) {
924 if (m_activeDocument)
925 switch (m_timecodeFormat->currentIndex()) {
927 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
930 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
934 void MainWindow::slotUpdateDocumentState(bool modified) {
935 setCaption(m_activeDocument->description(), modified);
937 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
938 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
940 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
941 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
945 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
946 if (m_activeDocument) {
947 if (m_activeDocument == doc) return;
948 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
950 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
953 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
954 //m_projectMonitor->stop();
955 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
956 if (m_activeDocument) {
957 if (m_activeDocument == doc) return;
958 m_activeDocument->backupMltPlaylist();
959 if (m_activeTimeline) {
960 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
961 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
962 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
963 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
964 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
965 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
966 disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
967 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
968 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
969 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
970 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
971 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
972 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
973 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
974 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
976 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
977 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
978 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
979 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
980 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
981 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
982 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
983 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
985 m_activeDocument->setRenderer(NULL);
986 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
987 m_clipMonitor->stop();
989 m_monitorManager->resetProfiles(doc->profilePath());
990 m_projectList->setDocument(doc);
991 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
992 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
993 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
994 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
995 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
996 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
997 connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
998 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
999 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1000 connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1002 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1003 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1007 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1008 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1009 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1010 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1011 m_zoomSlider->setValue(trackView->currentZoom());
1012 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1013 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1014 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1015 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1017 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1020 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1021 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1022 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1023 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1024 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1025 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1026 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1027 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1028 m_activeTimeline = trackView;
1029 KdenliveSettings::setCurrent_profile(doc->profilePath());
1030 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1031 m_monitorManager->setTimecode(doc->timecode());
1032 doc->setRenderer(m_projectMonitor->render);
1033 m_commandStack->setActiveStack(doc->commandStack());
1035 doc->updateAllProjectClips();
1037 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
1038 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
1040 //m_overView->setScene(trackView->projectScene());
1041 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1042 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1044 setCaption(doc->description());
1045 m_activeDocument = doc;
1048 void MainWindow::slotPreferences() {
1049 //An instance of your dialog could be already created and could be
1050 // cached, in which case you want to display the cached dialog
1051 // instead of creating another one
1052 if (KConfigDialog::showDialog("settings"))
1055 // KConfigDialog didn't find an instance of this dialog, so lets
1057 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1058 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1062 void MainWindow::updateConfiguration() {
1063 //TODO: we should apply settings to all projects, not only the current one
1064 if (m_activeTimeline) {
1065 m_activeTimeline->refresh();
1066 m_activeTimeline->projectView()->checkAutoScroll();
1067 m_activeTimeline->projectView()->checkTrackHeight();
1068 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1070 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1071 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1072 activateShuttleDevice();
1076 void MainWindow::slotSwitchVideoThumbs() {
1077 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1078 if (m_activeTimeline) {
1079 m_activeTimeline->refresh();
1081 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1084 void MainWindow::slotSwitchAudioThumbs() {
1085 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1086 if (m_activeTimeline) {
1087 m_activeTimeline->refresh();
1088 m_activeTimeline->projectView()->checkAutoScroll();
1089 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1091 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1094 void MainWindow::slotSwitchMarkersComments() {
1095 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1096 if (m_activeTimeline) {
1097 m_activeTimeline->refresh();
1099 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1102 void MainWindow::slotSwitchSnap() {
1103 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1104 m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1108 void MainWindow::slotDeleteTimelineClip() {
1109 if (m_activeTimeline) {
1110 m_activeTimeline->projectView()->deleteSelectedClips();
1114 void MainWindow::slotAddClipMarker() {
1115 if (m_activeTimeline) {
1116 m_activeTimeline->projectView()->slotAddClipMarker();
1120 void MainWindow::slotDeleteClipMarker() {
1121 if (m_activeTimeline) {
1122 m_activeTimeline->projectView()->slotDeleteClipMarker();
1126 void MainWindow::slotDeleteAllClipMarkers() {
1127 if (m_activeTimeline) {
1128 m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1132 void MainWindow::slotEditClipMarker() {
1133 if (m_activeTimeline) {
1134 m_activeTimeline->projectView()->slotEditClipMarker();
1138 void MainWindow::slotAddGuide() {
1139 if (m_activeTimeline)
1140 m_activeTimeline->projectView()->slotAddGuide();
1143 void MainWindow::slotEditGuide() {
1144 if (m_activeTimeline)
1145 m_activeTimeline->projectView()->slotEditGuide();
1148 void MainWindow::slotDeleteGuide() {
1149 if (m_activeTimeline)
1150 m_activeTimeline->projectView()->slotDeleteGuide();
1153 void MainWindow::slotDeleteAllGuides() {
1154 if (m_activeTimeline)
1155 m_activeTimeline->projectView()->slotDeleteAllGuides();
1158 void MainWindow::slotCutTimelineClip() {
1159 if (m_activeTimeline) {
1160 m_activeTimeline->projectView()->cutSelectedClips();
1164 void MainWindow::slotAddProjectClip(KUrl url) {
1165 if (m_activeDocument)
1166 m_activeDocument->slotAddClipFile(url, QString());
1169 void MainWindow::slotAddTransition(QAction *result) {
1170 if (!result) return;
1171 QDomElement effect = transitions.getEffectByName(result->data().toString());
1172 if (m_activeTimeline) {
1173 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1177 void MainWindow::slotAddVideoEffect(QAction *result) {
1178 if (!result) return;
1179 QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1180 slotAddEffect(effect);
1183 void MainWindow::slotAddAudioEffect(QAction *result) {
1184 if (!result) return;
1185 QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1186 slotAddEffect(effect);
1189 void MainWindow::slotAddCustomEffect(QAction *result) {
1190 if (!result) return;
1191 QDomElement effect = customEffects.getEffectByName(result->data().toString());
1192 slotAddEffect(effect);
1195 void MainWindow::slotZoomIn() {
1196 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1199 void MainWindow::slotZoomOut() {
1200 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1203 void MainWindow::slotFitZoom() {
1204 if (m_activeTimeline) {
1205 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1209 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1210 statusProgressBar->setValue(progress);
1211 if (progress >= 0) {
1212 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1213 statusProgressBar->setVisible(true);
1215 m_messageLabel->setMessage(QString(), DefaultMessage);
1216 statusProgressBar->setVisible(false);
1220 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1221 if (clip->clipType() == TEXT) {
1222 m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1225 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1226 connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1227 if (dia.exec() == QDialog::Accepted) {
1228 m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1229 if (dia.needsTimelineRefresh()) {
1230 // update clip occurences in timeline
1231 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1236 void MainWindow::customEvent(QEvent* e) {
1237 if (e->type() == QEvent::User) {
1238 // The timeline playing position changed...
1239 kDebug() << "RECIEVED JOG EVEMNT!!!";
1242 void MainWindow::slotActivateEffectStackView() {
1243 effectStack->raiseWindow(effectStackDock);
1246 void MainWindow::slotActivateTransitionView() {
1247 transitionConfig->raiseWindow(transitionConfigDock);
1250 void MainWindow::slotSnapRewind() {
1251 if (m_monitorManager->projectMonitorFocused()) {
1252 if (m_activeTimeline)
1253 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1257 void MainWindow::slotSnapForward() {
1258 if (m_monitorManager->projectMonitorFocused()) {
1259 if (m_activeTimeline)
1260 m_activeTimeline->projectView()->slotSeekToNextSnap();
1264 void MainWindow::slotClipStart() {
1265 if (m_monitorManager->projectMonitorFocused()) {
1266 if (m_activeTimeline)
1267 m_activeTimeline->projectView()->clipStart();
1271 void MainWindow::slotClipEnd() {
1272 if (m_monitorManager->projectMonitorFocused()) {
1273 if (m_activeTimeline)
1274 m_activeTimeline->projectView()->clipEnd();
1278 void MainWindow::slotChangeTool(QAction * action) {
1279 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1280 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1283 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1284 if (m_activeDocument && m_activeTimeline) {
1285 //m_activeDocument->setTool(tool);
1286 m_activeTimeline->projectView()->setTool(tool);
1290 void MainWindow::slotCopy() {
1291 if (!m_activeDocument || !m_activeTimeline) return;
1292 m_activeTimeline->projectView()->copyClip();
1295 void MainWindow::slotPaste() {
1296 if (!m_activeDocument || !m_activeTimeline) return;
1297 m_activeTimeline->projectView()->pasteClip();
1300 void MainWindow::slotFind() {
1301 if (!m_activeDocument || !m_activeTimeline) return;
1302 m_projectSearch->setEnabled(false);
1303 m_findActivated = true;
1304 m_findString = QString();
1305 m_activeTimeline->projectView()->initSearchStrings();
1306 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1307 m_findTimer.start(5000);
1308 qApp->installEventFilter(this);
1311 void MainWindow::slotFindNext() {
1312 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1313 statusBar()->showMessage(i18n("Found : %1", m_findString));
1315 statusBar()->showMessage(i18n("Reached end of project"));
1317 m_findTimer.start(4000);
1320 void MainWindow::findAhead() {
1321 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1322 m_projectSearchNext->setEnabled(true);
1323 statusBar()->showMessage(i18n("Found : %1", m_findString));
1325 m_projectSearchNext->setEnabled(false);
1326 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1330 void MainWindow::findTimeout() {
1331 m_projectSearchNext->setEnabled(false);
1332 m_findActivated = false;
1333 m_findString = QString();
1334 statusBar()->showMessage(i18n("Find stopped"), 3000);
1335 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1336 m_projectSearch->setEnabled(true);
1337 removeEventFilter(this);
1340 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1341 if (m_findActivated) {
1342 if (ke->key() == Qt::Key_Backspace) {
1343 m_findString = m_findString.left(m_findString.length() - 1);
1345 if (!m_findString.isEmpty()) {
1351 m_findTimer.start(4000);
1354 } else if (ke->key() == Qt::Key_Escape) {
1358 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1359 m_findString += ke->text();
1363 m_findTimer.start(4000);
1367 } else KXmlGuiWindow::keyPressEvent(ke);
1370 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1371 if (m_findActivated) {
1372 if (event->type() == QEvent::ShortcutOverride) {
1373 QKeyEvent* ke = (QKeyEvent*) event;
1374 if (ke->text().trimmed().isEmpty()) return false;
1377 } else return false;
1379 // pass the event on to the parent class
1380 return QMainWindow::eventFilter(obj, event);
1384 #include "mainwindow.moc"