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"
79 #define ID_STATUS_MSG 1
80 #define ID_EDITMODE_MSG 2
81 #define ID_TIMELINE_MSG 3
82 #define ID_TIMELINE_BUTTONS 5
83 #define ID_TIMELINE_POS 6
84 #define ID_TIMELINE_FORMAT 7
86 EffectsList MainWindow::videoEffects;
87 EffectsList MainWindow::audioEffects;
88 EffectsList MainWindow::customEffects;
89 EffectsList MainWindow::transitions;
91 MainWindow::MainWindow(QWidget *parent)
92 : KXmlGuiWindow(parent),
93 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
94 setlocale(LC_NUMERIC, "POSIX");
96 setFont(KGlobalSettings::toolBarFont());
97 m_commandStack = new QUndoGroup;
98 m_timelineArea = new KTabWidget(this);
99 m_timelineArea->setTabReorderingEnabled(true);
100 m_timelineArea->setTabBarHidden(true);
102 QToolButton *closeTabButton = new QToolButton;
103 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
104 closeTabButton->setIcon(KIcon("tab-close"));
105 closeTabButton->adjustSize();
106 closeTabButton->setToolTip(i18n("Close the current tab"));
107 m_timelineArea->setCornerWidget(closeTabButton);
108 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
110 connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
111 m_findTimer.setSingleShot(true);
113 initEffects::parseEffectFiles();
114 m_monitorManager = new MonitorManager();
116 projectListDock = new QDockWidget(i18n("Project Tree"), this);
117 projectListDock->setObjectName("project_tree");
118 m_projectList = new ProjectList(this);
119 projectListDock->setWidget(m_projectList);
120 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
122 effectListDock = new QDockWidget(i18n("Effect List"), this);
123 effectListDock->setObjectName("effect_list");
124 m_effectList = new EffectsListView();
126 //m_effectList = new KListWidget(this);
127 effectListDock->setWidget(m_effectList);
128 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
130 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
131 effectStackDock->setObjectName("effect_stack");
132 effectStack = new EffectStackView(this);
133 effectStackDock->setWidget(effectStack);
134 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
136 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
137 transitionConfigDock->setObjectName("transition");
138 transitionConfig = new TransitionSettings(this);
139 transitionConfigDock->setWidget(transitionConfig);
140 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
143 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
144 clipMonitorDock->setObjectName("clip_monitor");
145 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
146 clipMonitorDock->setWidget(m_clipMonitor);
147 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
148 //m_clipMonitor->stop();
150 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
151 projectMonitorDock->setObjectName("project_monitor");
152 m_projectMonitor = new Monitor("project", m_monitorManager, this);
153 projectMonitorDock->setWidget(m_projectMonitor);
154 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
156 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
157 recMonitorDock->setObjectName("record_monitor");
158 m_recMonitor = new RecMonitor("record", this);
159 recMonitorDock->setWidget(m_recMonitor);
160 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
162 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
164 undoViewDock = new QDockWidget(i18n("Undo History"), this);
165 undoViewDock->setObjectName("undo_history");
166 m_undoView = new QUndoView(this);
167 m_undoView->setCleanIcon(KIcon("edit-clear"));
168 m_undoView->setEmptyLabel(i18n("Clean"));
169 undoViewDock->setWidget(m_undoView);
170 m_undoView->setGroup(m_commandStack);
171 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
173 //overviewDock = new QDockWidget(i18n("Project Overview"), this);
174 //overviewDock->setObjectName("project_overview");
175 //m_overView = new CustomTrackView(NULL, NULL, this);
176 //overviewDock->setWidget(m_overView);
177 //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
180 //tabifyDockWidget(projectListDock, effectListDock);
181 tabifyDockWidget(projectListDock, effectStackDock);
182 tabifyDockWidget(projectListDock, transitionConfigDock);
183 //tabifyDockWidget(projectListDock, undoViewDock);
184 projectListDock->raise();
186 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
187 tabifyDockWidget(clipMonitorDock, recMonitorDock);
188 setCentralWidget(m_timelineArea);
190 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
191 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
193 // build effects menus
195 QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
196 QStringList effects = videoEffects.effectNames();
197 foreach(const QString &name, effects) {
198 action = new QAction(name, this);
199 action->setData(name);
200 videoEffectsMenu->addAction(action);
202 QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
203 effects = audioEffects.effectNames();
204 foreach(const QString &name, effects) {
205 action = new QAction(name, this);
206 action->setData(name);
207 audioEffectsMenu->addAction(action);
209 QMenu *customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
210 effects = customEffects.effectNames();
211 foreach(const QString &name, effects) {
212 action = new QAction(name, this);
213 action->setData(name);
214 customEffectsMenu->addAction(action);
217 QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
218 const QList<QAction *> viewActions = createPopupMenu()->actions();
219 viewMenu->insertActions(NULL, viewActions);
221 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
222 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
223 connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
225 m_timelineContextMenu = new QMenu(this);
226 m_timelineContextClipMenu = new QMenu(this);
227 m_timelineContextTransitionMenu = new QMenu(this);
230 QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
231 effects = transitions.effectNames();
232 foreach(const QString &name, effects) {
233 action = new QAction(name, this);
234 action->setData(name);
235 transitionsMenu->addAction(action);
237 connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
239 m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
241 m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
242 m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
243 m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
245 QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
246 m_timelineContextClipMenu->addMenu(markersMenu);
247 m_timelineContextClipMenu->addMenu(transitionsMenu);
248 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
249 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
250 m_timelineContextClipMenu->addMenu(customEffectsMenu);
252 m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
253 m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
255 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
256 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
257 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
258 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
259 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
260 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
261 slotConnectMonitors();
263 setAutoSaveSettings();
265 if (KdenliveSettings::openlastproject()) {
269 activateShuttleDevice();
272 void MainWindow::queryQuit() {
273 kDebug() << "----- SAVING CONFUIG";
274 if (queryClose()) kapp->quit();
278 bool MainWindow::queryClose() {
280 if (m_activeDocument && m_activeDocument->isModified()) {
281 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
282 case KMessageBox::Yes :
283 // save document here. If saving fails, return false;
286 case KMessageBox::No :
295 void MainWindow::saveProperties(KConfig*) {
296 // save properties here,used by session management
301 void MainWindow::readProperties(KConfig *config) {
302 // read properties here,used by session management
303 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
304 openFile(KUrl(Lastproject));
307 void MainWindow::activateShuttleDevice() {
308 if (m_jogProcess) delete m_jogProcess;
310 if (KdenliveSettings::enableshuttle() == false) return;
311 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
312 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
313 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
314 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
315 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
316 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
317 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
320 void MainWindow::slotShuttleButton(int code) {
323 slotShuttleAction(KdenliveSettings::shuttle1());
326 slotShuttleAction(KdenliveSettings::shuttle2());
329 slotShuttleAction(KdenliveSettings::shuttle3());
332 slotShuttleAction(KdenliveSettings::shuttle4());
335 slotShuttleAction(KdenliveSettings::shuttle5());
340 void MainWindow::slotShuttleAction(int code) {
345 m_monitorManager->slotPlay();
348 m_monitorManager->slotPlay();
353 void MainWindow::slotFullScreen() {
354 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
357 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
358 if (!m_activeDocument) return;
359 if (effect.isNull()) {
360 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
363 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
364 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
367 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
368 if (clipMonitor) clipMonitorDock->raise();
369 else projectMonitorDock->raise();
372 void MainWindow::slotSetClipDuration(int id, int duration) {
373 if (!m_activeDocument) return;
374 m_activeDocument->setProducerDuration(id, duration);
377 void MainWindow::slotConnectMonitors() {
379 m_projectList->setRenderer(m_clipMonitor->render);
380 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
381 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
382 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
383 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
384 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 > &)));
385 connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
388 void MainWindow::setupActions() {
390 m_timecodeFormat = new KComboBox(this);
391 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
392 m_timecodeFormat->addItem(i18n("Frames"));
394 statusProgressBar = new QProgressBar(this);
395 statusProgressBar->setMinimum(0);
396 statusProgressBar->setMaximum(100);
397 statusProgressBar->setMaximumWidth(150);
398 statusProgressBar->setVisible(false);
400 QWidget *w = new QWidget;
402 QHBoxLayout *layout = new QHBoxLayout;
403 w->setLayout(layout);
404 layout->setContentsMargins(5, 0, 5, 0);
405 QToolBar *toolbar = new QToolBar("statusToolBar", this);
408 m_toolGroup = new QActionGroup(this);
410 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;}";
412 m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
413 m_buttonSelectTool->setCheckable(true);
414 m_buttonSelectTool->setChecked(true);
416 m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
417 m_buttonRazorTool->setCheckable(true);
418 m_buttonRazorTool->setChecked(false);
420 m_toolGroup->addAction(m_buttonSelectTool);
421 m_toolGroup->addAction(m_buttonRazorTool);
422 m_toolGroup->setExclusive(true);
423 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
425 QWidget * actionWidget;
426 actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
427 actionWidget->setMaximumWidth(24);
428 actionWidget->setMinimumHeight(17);
430 actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
431 actionWidget->setMaximumWidth(24);
432 actionWidget->setMinimumHeight(17);
434 toolbar->setStyleSheet(style1);
435 connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
437 toolbar->addSeparator();
438 m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
439 m_buttonFitZoom->setCheckable(false);
440 connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
442 actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
443 actionWidget->setMaximumWidth(24);
444 actionWidget->setMinimumHeight(17);
446 m_zoomSlider = new QSlider(Qt::Horizontal, this);
447 m_zoomSlider->setMaximum(13);
448 m_zoomSlider->setPageStep(1);
450 m_zoomSlider->setMaximumWidth(150);
451 m_zoomSlider->setMinimumWidth(100);
453 const int contentHeight = QFontMetrics(w->font()).height() + 8;
454 QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
455 style.append("QSlider::handle:horizontal { background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
456 m_zoomSlider->setStyleSheet(style);
458 //m_zoomSlider->setMaximumHeight(contentHeight);
459 //m_zoomSlider->height() + 5;
460 statusBar()->setMinimumHeight(contentHeight);
463 toolbar->addWidget(m_zoomSlider);
465 m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
466 m_buttonVideoThumbs->setCheckable(true);
467 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
468 connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
470 m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
471 m_buttonAudioThumbs->setCheckable(true);
472 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
473 connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
475 m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
476 m_buttonShowMarkers->setCheckable(true);
477 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
478 connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
480 m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
481 m_buttonSnap->setCheckable(true);
482 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
483 connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
484 layout->addWidget(toolbar);
487 actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
488 actionWidget->setMaximumWidth(24);
489 actionWidget->setMinimumHeight(17);
491 actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
492 actionWidget->setMaximumWidth(24);
493 actionWidget->setMinimumHeight(17);
495 actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
496 actionWidget->setMaximumWidth(24);
497 actionWidget->setMinimumHeight(17);
499 actionWidget = toolbar->widgetForAction(m_buttonSnap);
500 actionWidget->setMaximumWidth(24);
501 actionWidget->setMinimumHeight(17);
503 m_messageLabel = new StatusBarMessageLabel(this);
504 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
506 statusBar()->addWidget(m_messageLabel, 10);
507 statusBar()->addWidget(statusProgressBar, 0);
508 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
509 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
510 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
511 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
512 m_messageLabel->hide();
514 actionCollection()->addAction("select_tool", m_buttonSelectTool);
515 actionCollection()->addAction("razor_tool", m_buttonRazorTool);
517 actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
518 actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
519 actionCollection()->addAction("show_markers", m_buttonShowMarkers);
520 actionCollection()->addAction("snap", m_buttonSnap);
521 actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
523 m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
524 actionCollection()->addAction("project_find", m_projectSearch);
525 connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
526 m_projectSearch->setShortcut(Qt::Key_Slash);
528 m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
529 actionCollection()->addAction("project_find_next", m_projectSearchNext);
530 connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
531 m_projectSearchNext->setShortcut(Qt::Key_F3);
532 m_projectSearchNext->setEnabled(false);
534 KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
535 actionCollection()->addAction("manage_profiles", profilesAction);
536 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
538 KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
539 actionCollection()->addAction("project_settings", projectAction);
540 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
542 KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
543 actionCollection()->addAction("project_render", projectRender);
544 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
546 KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
547 monitorPlay->setShortcut(Qt::Key_Space);
548 actionCollection()->addAction("monitor_play", monitorPlay);
549 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
551 KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
552 monitorSeekBackward->setShortcut(Qt::Key_J);
553 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
554 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
556 KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
557 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
558 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
559 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
561 KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
562 monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
563 actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
564 connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
566 KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
567 monitorSeekForward->setShortcut(Qt::Key_L);
568 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
569 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
571 KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
572 clipStart->setShortcut(Qt::Key_Home);
573 actionCollection()->addAction("seek_clip_start", clipStart);
574 connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
576 KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
577 clipEnd->setShortcut(Qt::Key_End);
578 actionCollection()->addAction("seek_clip_end", clipEnd);
579 connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
581 KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
582 projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
583 actionCollection()->addAction("seek_start", projectStart);
584 connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
586 KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
587 projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
588 actionCollection()->addAction("seek_end", projectEnd);
589 connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
591 KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
592 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
593 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
594 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
596 KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
597 monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
598 actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
599 connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
601 KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
602 deleteTimelineClip->setShortcut(Qt::Key_Delete);
603 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
604 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
606 KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
607 cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
608 actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
609 connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
611 KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
612 actionCollection()->addAction("add_clip_marker", addClipMarker);
613 connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
615 KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
616 actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
617 connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
619 KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
620 actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
621 connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
623 KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
624 actionCollection()->addAction("edit_clip_marker", editClipMarker);
625 connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
627 KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
628 actionCollection()->addAction("add_guide", addGuide);
629 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
631 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
632 actionCollection()->addAction("delete_guide", delGuide);
633 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
635 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
636 actionCollection()->addAction("edit_guide", editGuide);
637 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
639 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
640 actionCollection()->addAction("delete_all_guides", delAllGuides);
641 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
643 KStandardAction::quit(this, SLOT(queryQuit()),
646 KStandardAction::open(this, SLOT(openFile()),
649 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
652 KStandardAction::save(this, SLOT(saveFile()),
655 KStandardAction::saveAs(this, SLOT(saveFileAs()),
658 KStandardAction::openNew(this, SLOT(newFile()),
661 KStandardAction::preferences(this, SLOT(slotPreferences()),
664 KStandardAction::copy(this, SLOT(slotCopy()),
667 KStandardAction::paste(this, SLOT(slotPaste()),
670 KStandardAction::undo(this, SLOT(undo()),
673 KStandardAction::redo(this, SLOT(redo()),
676 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
678 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
679 this, SLOT(slotDisplayActionMessage(QAction*)));
680 //connect(actionCollection(), SIGNAL( clearStatusText() ),
681 //statusBar(), SLOT( clear() ) );
686 void MainWindow::undo() {
687 m_commandStack->undo();
690 void MainWindow::redo() {
691 m_commandStack->redo();
694 void MainWindow::slotDisplayActionMessage(QAction *a) {
695 statusBar()->showMessage(a->data().toString(), 3000);
698 void MainWindow::saveOptions() {
699 KdenliveSettings::self()->writeConfig();
700 KSharedConfigPtr config = KGlobal::config();
701 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
705 void MainWindow::readOptions() {
706 KSharedConfigPtr config = KGlobal::config();
707 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
710 void MainWindow::newFile() {
713 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
715 ProjectSettings *w = new ProjectSettings;
716 if (w->exec() != QDialog::Accepted) return;
717 profileName = w->selectedProfile();
718 projectFolder = w->selectedFolder();
721 MltVideoProfile prof;
722 if (!profileName.isEmpty()) prof = ProfilesDialog::getVideoProfile(profileName);
723 else prof = ProfilesDialog::getVideoProfile("dv_pal");
724 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
725 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
726 TrackView *trackView = new TrackView(doc, this);
727 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
728 if (m_timelineArea->count() == 1) {
729 connectDocumentInfo(doc);
730 connectDocument(trackView, doc);
731 } else m_timelineArea->setTabBarHidden(false);
734 void MainWindow::activateDocument() {
735 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
736 KdenliveDoc *currentDoc = currentTab->document();
737 connectDocumentInfo(currentDoc);
738 connectDocument(currentTab, currentDoc);
741 void MainWindow::slotRemoveTab() {
742 QWidget *w = m_timelineArea->currentWidget();
743 // closing current document
744 int ix = m_timelineArea->currentIndex() + 1;
745 if (ix == m_timelineArea->count()) ix = 0;
746 m_timelineArea->setCurrentIndex(ix);
747 TrackView *tabToClose = (TrackView *) w;
748 KdenliveDoc *docToClose = tabToClose->document();
749 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
750 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
755 void MainWindow::saveFileAs(const QString &outputFileName) {
756 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
757 m_activeDocument->setUrl(KUrl(outputFileName));
758 setCaption(m_activeDocument->description());
759 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
760 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
761 m_activeDocument->setModified(false);
762 m_fileOpenRecent->addUrl(KUrl(outputFileName));
765 void MainWindow::saveFileAs() {
766 QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
767 if (QFile::exists(outputFile)) {
768 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
770 saveFileAs(outputFile);
773 void MainWindow::saveFile() {
774 if (!m_activeDocument) return;
775 if (m_activeDocument->url().isEmpty()) {
778 saveFileAs(m_activeDocument->url().path());
782 void MainWindow::openFile() {
783 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
784 if (url.isEmpty()) return;
785 m_fileOpenRecent->addUrl(url);
789 void MainWindow::openLastFile() {
790 KSharedConfigPtr config = KGlobal::config();
791 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
792 openFile(KUrl(Lastproject));
795 void MainWindow::openFile(const KUrl &url) {
796 // Check for backup file
797 bool recovery = false;
798 QString directory = url.directory();
799 QString fileName = url.fileName();
801 recoveryUrl.setDirectory(directory);
802 recoveryUrl.setFileName("~" + fileName);
803 if (KIO::NetAccess::exists(recoveryUrl, KIO::NetAccess::SourceSide, this)) {
804 KFileItem bkup(KFileItem::Unknown, KFileItem::Unknown, recoveryUrl, true);
805 KFileItem src(KFileItem::Unknown, KFileItem::Unknown, url, true);
806 if (bkup.time(KFileItem::ModificationTime) > src.time(KFileItem::ModificationTime)) {
807 // Backup file is more recent than source file, ask user for recovery
808 if (KMessageBox::questionYesNo(this, i18n("A newer recovery file exists for <b>%1</b>\nOpen recovery file ?", url.fileName())) == KMessageBox::Yes) recovery = true;
812 //TODO: get video profile from url before opening it
813 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
814 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
817 doc = new KdenliveDoc(recoveryUrl, KUrl(), prof, m_commandStack, this);
819 doc->setModified(true);
820 } else doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
821 connectDocumentInfo(doc);
822 TrackView *trackView = new TrackView(doc, this);
823 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
824 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
825 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
826 slotGotProgressInfo(QString(), -1);
827 m_projectMonitor->refreshMonitor(true);
828 //connectDocument(trackView, doc);
832 void MainWindow::parseProfiles() {
833 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
835 //KdenliveSettings::setDefaulttmpfolder();
836 if (KdenliveSettings::mltpath().isEmpty()) {
837 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
839 if (KdenliveSettings::rendererpath().isEmpty()) {
840 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
842 QStringList profilesFilter;
843 profilesFilter << "*";
844 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
846 if (profilesList.isEmpty()) {
847 // Cannot find MLT path, try finding inigo
848 QString profilePath = KdenliveSettings::rendererpath();
849 if (!profilePath.isEmpty()) {
850 profilePath = profilePath.section('/', 0, -3);
851 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
852 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
855 if (profilesList.isEmpty()) {
856 // Cannot find the MLT profiles, ask for location
857 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
858 getUrl->fileDialog()->setMode(KFile::Directory);
860 KUrl mltPath = getUrl->selectedUrl();
862 if (mltPath.isEmpty()) kapp->quit();
863 KdenliveSettings::setMltpath(mltPath.path());
864 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
868 if (KdenliveSettings::rendererpath().isEmpty()) {
869 // Cannot find the MLT inigo renderer, ask for location
870 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
872 KUrl rendererPath = getUrl->selectedUrl();
874 if (rendererPath.isEmpty()) kapp->quit();
875 KdenliveSettings::setRendererpath(rendererPath.path());
878 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
880 // Parse MLT profiles to build a list of available video formats
881 if (profilesList.isEmpty()) parseProfiles();
885 void MainWindow::slotEditProfiles() {
886 ProfilesDialog *w = new ProfilesDialog;
891 void MainWindow::slotEditProjectSettings() {
892 ProjectSettings *w = new ProjectSettings;
893 if (w->exec() == QDialog::Accepted) {
894 QString profile = w->selectedProfile();
895 m_activeDocument->setProfilePath(profile);
896 m_monitorManager->resetProfiles(profile);
897 setCaption(m_activeDocument->description());
898 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
899 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
900 m_monitorManager->setTimecode(m_activeDocument->timecode());
901 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
903 // We need to desactivate & reactivate monitors to get a refresh
904 m_monitorManager->switchMonitors();
909 void MainWindow::slotRenderProject() {
910 if (!m_renderWidget) {
911 m_renderWidget = new RenderWidget(this);
912 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
914 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
915 if (currentTab) m_renderWidget->setTimeline(currentTab);
916 m_renderWidget->setDocument(m_activeDocument);*/
917 m_renderWidget->show();
920 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
921 if (dest.isEmpty()) return;
924 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
925 if (currentTab && zoneOnly) {
926 in = currentTab->inPoint();
927 out = currentTab->outPoint();
930 temp.setAutoRemove(false);
931 temp.setSuffix(".westley");
933 m_projectMonitor->saveSceneList(temp.fileName());
936 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
937 QString videoPlayer = "-";
939 videoPlayer = KdenliveSettings::defaultplayerapp();
940 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."));
942 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
943 QProcess::startDetached("kdenlive_render", args);
947 void MainWindow::slotUpdateMousePosition(int pos) {
948 if (m_activeDocument)
949 switch (m_timecodeFormat->currentIndex()) {
951 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
954 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
958 void MainWindow::slotUpdateDocumentState(bool modified) {
959 setCaption(m_activeDocument->description(), modified);
961 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
962 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
964 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
965 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
969 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
970 if (m_activeDocument) {
971 if (m_activeDocument == doc) return;
972 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
974 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
977 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
978 //m_projectMonitor->stop();
979 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
980 if (m_activeDocument) {
981 if (m_activeDocument == doc) return;
982 m_activeDocument->backupMltPlaylist();
983 if (m_activeTimeline) {
984 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
985 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
986 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
987 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
988 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
989 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
990 disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
991 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
992 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
993 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
994 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
995 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
996 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
997 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
998 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1000 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1001 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1002 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1003 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1004 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1005 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1006 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1007 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1009 m_activeDocument->setRenderer(NULL);
1010 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1011 m_clipMonitor->stop();
1013 m_monitorManager->resetProfiles(doc->profilePath());
1014 m_projectList->setDocument(doc);
1015 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1016 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1017 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1018 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1019 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1020 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1021 connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1022 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1023 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1024 connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1026 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1027 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1031 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1032 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1033 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1034 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1035 m_zoomSlider->setValue(doc->zoom());
1036 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1037 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1038 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1039 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1041 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1044 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1045 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1046 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1047 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1048 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1049 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1050 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1051 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1052 m_activeTimeline = trackView;
1053 KdenliveSettings::setCurrent_profile(doc->profilePath());
1054 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1055 m_monitorManager->setTimecode(doc->timecode());
1056 doc->setRenderer(m_projectMonitor->render);
1057 m_commandStack->setActiveStack(doc->commandStack());
1059 doc->updateAllProjectClips();
1061 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
1062 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
1064 //m_overView->setScene(trackView->projectScene());
1065 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1066 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1068 setCaption(doc->description());
1069 m_activeDocument = doc;
1072 void MainWindow::slotPreferences() {
1073 //An instance of your dialog could be already created and could be
1074 // cached, in which case you want to display the cached dialog
1075 // instead of creating another one
1076 if (KConfigDialog::showDialog("settings"))
1079 // KConfigDialog didn't find an instance of this dialog, so lets
1081 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1082 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1086 void MainWindow::updateConfiguration() {
1087 //TODO: we should apply settings to all projects, not only the current one
1088 if (m_activeTimeline) {
1089 m_activeTimeline->refresh();
1090 m_activeTimeline->projectView()->checkAutoScroll();
1091 m_activeTimeline->projectView()->checkTrackHeight();
1092 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1094 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1095 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1096 activateShuttleDevice();
1100 void MainWindow::slotSwitchVideoThumbs() {
1101 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1102 if (m_activeTimeline) {
1103 m_activeTimeline->refresh();
1105 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1108 void MainWindow::slotSwitchAudioThumbs() {
1109 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1110 if (m_activeTimeline) {
1111 m_activeTimeline->refresh();
1112 m_activeTimeline->projectView()->checkAutoScroll();
1113 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1115 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1118 void MainWindow::slotSwitchMarkersComments() {
1119 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1120 if (m_activeTimeline) {
1121 m_activeTimeline->refresh();
1123 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1126 void MainWindow::slotSwitchSnap() {
1127 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1128 m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1132 void MainWindow::slotDeleteTimelineClip() {
1133 if (m_activeTimeline) {
1134 m_activeTimeline->projectView()->deleteSelectedClips();
1138 void MainWindow::slotAddClipMarker() {
1139 if (m_activeTimeline) {
1140 m_activeTimeline->projectView()->slotAddClipMarker();
1144 void MainWindow::slotDeleteClipMarker() {
1145 if (m_activeTimeline) {
1146 m_activeTimeline->projectView()->slotDeleteClipMarker();
1150 void MainWindow::slotDeleteAllClipMarkers() {
1151 if (m_activeTimeline) {
1152 m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1156 void MainWindow::slotEditClipMarker() {
1157 if (m_activeTimeline) {
1158 m_activeTimeline->projectView()->slotEditClipMarker();
1162 void MainWindow::slotAddGuide() {
1163 if (m_activeTimeline)
1164 m_activeTimeline->projectView()->slotAddGuide();
1167 void MainWindow::slotEditGuide() {
1168 if (m_activeTimeline)
1169 m_activeTimeline->projectView()->slotEditGuide();
1172 void MainWindow::slotDeleteGuide() {
1173 if (m_activeTimeline)
1174 m_activeTimeline->projectView()->slotDeleteGuide();
1177 void MainWindow::slotDeleteAllGuides() {
1178 if (m_activeTimeline)
1179 m_activeTimeline->projectView()->slotDeleteAllGuides();
1182 void MainWindow::slotCutTimelineClip() {
1183 if (m_activeTimeline) {
1184 m_activeTimeline->projectView()->cutSelectedClips();
1188 void MainWindow::slotAddProjectClip(KUrl url) {
1189 if (m_activeDocument)
1190 m_activeDocument->slotAddClipFile(url, QString());
1193 void MainWindow::slotAddTransition(QAction *result) {
1194 if (!result) return;
1195 QDomElement effect = transitions.getEffectByName(result->data().toString());
1196 if (m_activeTimeline) {
1197 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1201 void MainWindow::slotAddVideoEffect(QAction *result) {
1202 if (!result) return;
1203 QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1204 slotAddEffect(effect);
1207 void MainWindow::slotAddAudioEffect(QAction *result) {
1208 if (!result) return;
1209 QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1210 slotAddEffect(effect);
1213 void MainWindow::slotAddCustomEffect(QAction *result) {
1214 if (!result) return;
1215 QDomElement effect = customEffects.getEffectByName(result->data().toString());
1216 slotAddEffect(effect);
1219 void MainWindow::slotZoomIn() {
1220 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1223 void MainWindow::slotZoomOut() {
1224 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1227 void MainWindow::slotFitZoom() {
1228 if (m_activeTimeline) {
1229 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1233 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1234 statusProgressBar->setValue(progress);
1235 if (progress >= 0) {
1236 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1237 statusProgressBar->setVisible(true);
1239 m_messageLabel->setMessage(QString(), DefaultMessage);
1240 statusProgressBar->setVisible(false);
1244 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1245 if (clip->clipType() == TEXT) {
1246 m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1249 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1250 connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1251 if (dia.exec() == QDialog::Accepted) {
1252 m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1253 if (dia.needsTimelineRefresh()) {
1254 // update clip occurences in timeline
1255 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1260 void MainWindow::customEvent(QEvent* e) {
1261 if (e->type() == QEvent::User) {
1262 // The timeline playing position changed...
1263 kDebug() << "RECIEVED JOG EVEMNT!!!";
1266 void MainWindow::slotActivateEffectStackView() {
1267 effectStack->raiseWindow(effectStackDock);
1270 void MainWindow::slotActivateTransitionView() {
1271 transitionConfig->raiseWindow(transitionConfigDock);
1274 void MainWindow::slotSnapRewind() {
1275 if (m_monitorManager->projectMonitorFocused()) {
1276 if (m_activeTimeline)
1277 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1281 void MainWindow::slotSnapForward() {
1282 if (m_monitorManager->projectMonitorFocused()) {
1283 if (m_activeTimeline)
1284 m_activeTimeline->projectView()->slotSeekToNextSnap();
1288 void MainWindow::slotClipStart() {
1289 if (m_monitorManager->projectMonitorFocused()) {
1290 if (m_activeTimeline)
1291 m_activeTimeline->projectView()->clipStart();
1295 void MainWindow::slotClipEnd() {
1296 if (m_monitorManager->projectMonitorFocused()) {
1297 if (m_activeTimeline)
1298 m_activeTimeline->projectView()->clipEnd();
1302 void MainWindow::slotChangeTool(QAction * action) {
1303 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1304 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1307 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1308 if (m_activeDocument && m_activeTimeline) {
1309 //m_activeDocument->setTool(tool);
1310 m_activeTimeline->projectView()->setTool(tool);
1314 void MainWindow::slotCopy() {
1315 if (!m_activeDocument || !m_activeTimeline) return;
1316 m_activeTimeline->projectView()->copyClip();
1319 void MainWindow::slotPaste() {
1320 if (!m_activeDocument || !m_activeTimeline) return;
1321 m_activeTimeline->projectView()->pasteClip();
1324 void MainWindow::slotFind() {
1325 if (!m_activeDocument || !m_activeTimeline) return;
1326 m_projectSearch->setEnabled(false);
1327 m_findActivated = true;
1328 m_findString = QString();
1329 m_activeTimeline->projectView()->initSearchStrings();
1330 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1331 m_findTimer.start(5000);
1332 qApp->installEventFilter(this);
1335 void MainWindow::slotFindNext() {
1336 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1337 statusBar()->showMessage(i18n("Found : %1", m_findString));
1339 statusBar()->showMessage(i18n("Reached end of project"));
1341 m_findTimer.start(4000);
1344 void MainWindow::findAhead() {
1345 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1346 m_projectSearchNext->setEnabled(true);
1347 statusBar()->showMessage(i18n("Found : %1", m_findString));
1349 m_projectSearchNext->setEnabled(false);
1350 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1354 void MainWindow::findTimeout() {
1355 m_projectSearchNext->setEnabled(false);
1356 m_findActivated = false;
1357 m_findString = QString();
1358 statusBar()->showMessage(i18n("Find stopped"), 3000);
1359 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1360 m_projectSearch->setEnabled(true);
1361 removeEventFilter(this);
1364 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1365 if (m_findActivated) {
1366 if (ke->key() == Qt::Key_Backspace) {
1367 m_findString = m_findString.left(m_findString.length() - 1);
1369 if (!m_findString.isEmpty()) {
1375 m_findTimer.start(4000);
1378 } else if (ke->key() == Qt::Key_Escape) {
1382 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1383 m_findString += ke->text();
1387 m_findTimer.start(4000);
1391 } else KXmlGuiWindow::keyPressEvent(ke);
1394 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1395 if (m_findActivated) {
1396 if (event->type() == QEvent::ShortcutOverride) {
1397 QKeyEvent* ke = (QKeyEvent*) event;
1398 if (ke->text().trimmed().isEmpty()) return false;
1401 } else return false;
1403 // pass the event on to the parent class
1404 return QMainWindow::eventFilter(obj, event);
1408 #include "mainwindow.moc"