1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include <QTextStream>
29 #include <KApplication>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
38 #include <KIO/NetAccess>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
50 #include <ktogglefullscreenaction.h>
53 #include <mlt++/Mlt.h>
55 #include "mainwindow.h"
56 #include "kdenlivesettings.h"
57 #include "kdenlivesettingsdialog.h"
58 #include "initeffects.h"
59 #include "profilesdialog.h"
60 #include "projectsettings.h"
62 #include "renderjob.h"
63 #include "clipmanager.h"
64 #include "projectlist.h"
66 #include "recmonitor.h"
67 #include "monitormanager.h"
68 #include "kdenlivedoc.h"
69 #include "trackview.h"
70 #include "customtrackview.h"
71 #include "effectslistview.h"
72 #include "effectstackview.h"
73 #include "transitionsettings.h"
74 #include "renderwidget.h"
76 #include "jogshuttle.h"
77 #include "clipproperties.h"
80 static const int ID_STATUS_MSG = 1;
81 static const int ID_EDITMODE_MSG = 2;
82 static const int ID_TIMELINE_MSG = 3;
83 static const int ID_TIMELINE_BUTTONS = 5;
84 static const int ID_TIMELINE_POS = 6;
85 static const int ID_TIMELINE_FORMAT = 7;
91 EffectsList MainWindow::videoEffects;
92 EffectsList MainWindow::audioEffects;
93 EffectsList MainWindow::customEffects;
94 EffectsList MainWindow::transitions;
96 MainWindow::MainWindow(QWidget *parent)
97 : KXmlGuiWindow(parent),
98 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
99 setlocale(LC_NUMERIC, "POSIX");
100 setFont(KGlobalSettings::toolBarFont());
102 m_commandStack = new QUndoGroup;
103 m_timelineArea = new KTabWidget(this);
104 m_timelineArea->setTabReorderingEnabled(true);
105 m_timelineArea->setTabBarHidden(true);
107 QToolButton *closeTabButton = new QToolButton;
108 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
109 closeTabButton->setIcon(KIcon("tab-close"));
110 closeTabButton->adjustSize();
111 closeTabButton->setToolTip(i18n("Close the current tab"));
112 m_timelineArea->setCornerWidget(closeTabButton);
113 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
115 connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
116 m_findTimer.setSingleShot(true);
118 initEffects::parseEffectFiles();
119 m_monitorManager = new MonitorManager();
121 projectListDock = new QDockWidget(i18n("Project Tree"), this);
122 projectListDock->setObjectName("project_tree");
123 m_projectList = new ProjectList(this);
124 projectListDock->setWidget(m_projectList);
125 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
127 effectListDock = new QDockWidget(i18n("Effect List"), this);
128 effectListDock->setObjectName("effect_list");
129 m_effectList = new EffectsListView();
131 //m_effectList = new KListWidget(this);
132 effectListDock->setWidget(m_effectList);
133 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
135 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
136 effectStackDock->setObjectName("effect_stack");
137 effectStack = new EffectStackView(this);
138 effectStackDock->setWidget(effectStack);
139 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
141 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
142 transitionConfigDock->setObjectName("transition");
143 transitionConfig = new TransitionSettings(this);
144 transitionConfigDock->setWidget(transitionConfig);
145 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
147 KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
148 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
152 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
153 clipMonitorDock->setObjectName("clip_monitor");
154 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
155 clipMonitorDock->setWidget(m_clipMonitor);
156 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
157 //m_clipMonitor->stop();
159 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
160 projectMonitorDock->setObjectName("project_monitor");
161 m_projectMonitor = new Monitor("project", m_monitorManager, this);
162 projectMonitorDock->setWidget(m_projectMonitor);
163 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
165 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
166 recMonitorDock->setObjectName("record_monitor");
167 m_recMonitor = new RecMonitor("record", this);
168 recMonitorDock->setWidget(m_recMonitor);
169 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
171 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
172 connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
174 undoViewDock = new QDockWidget(i18n("Undo History"), this);
175 undoViewDock->setObjectName("undo_history");
176 m_undoView = new QUndoView(this);
177 m_undoView->setCleanIcon(KIcon("edit-clear"));
178 m_undoView->setEmptyLabel(i18n("Clean"));
179 undoViewDock->setWidget(m_undoView);
180 m_undoView->setGroup(m_commandStack);
181 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
183 //overviewDock = new QDockWidget(i18n("Project Overview"), this);
184 //overviewDock->setObjectName("project_overview");
185 //m_overView = new CustomTrackView(NULL, NULL, this);
186 //overviewDock->setWidget(m_overView);
187 //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
190 //tabifyDockWidget(projectListDock, effectListDock);
191 tabifyDockWidget(projectListDock, effectStackDock);
192 tabifyDockWidget(projectListDock, transitionConfigDock);
193 //tabifyDockWidget(projectListDock, undoViewDock);
196 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
197 tabifyDockWidget(clipMonitorDock, recMonitorDock);
198 setCentralWidget(m_timelineArea);
200 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
201 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
203 // build effects menus
205 QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
206 QStringList effects = videoEffects.effectNames();
207 foreach(const QString &name, effects) {
208 action = new QAction(name, this);
209 action->setData(name);
210 videoEffectsMenu->addAction(action);
212 QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
213 effects = audioEffects.effectNames();
214 foreach(const QString &name, effects) {
215 action = new QAction(name, this);
216 action->setData(name);
217 audioEffectsMenu->addAction(action);
219 m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
220 effects = customEffects.effectNames();
221 foreach(const QString &name, effects) {
222 action = new QAction(name, this);
223 action->setData(name);
224 m_customEffectsMenu->addAction(action);
227 QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
228 const QList<QAction *> viewActions = createPopupMenu()->actions();
229 viewMenu->insertActions(NULL, viewActions);
231 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
232 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
233 connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
235 m_timelineContextMenu = new QMenu(this);
236 m_timelineContextClipMenu = new QMenu(this);
237 m_timelineContextTransitionMenu = new QMenu(this);
240 QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
241 effects = transitions.effectNames();
242 foreach(const QString &name, effects) {
243 action = new QAction(name, this);
244 action->setData(name);
245 transitionsMenu->addAction(action);
247 connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
249 m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
251 m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
252 m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
253 m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
254 m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
255 m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
257 QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
258 m_timelineContextClipMenu->addMenu(markersMenu);
259 m_timelineContextClipMenu->addMenu(transitionsMenu);
260 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
261 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
262 m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
264 m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
265 m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
267 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
268 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
269 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
270 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
271 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
272 connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
274 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
275 slotConnectMonitors();
277 setAutoSaveSettings();
279 if (KdenliveSettings::openlastproject()) {
283 activateShuttleDevice();
284 projectListDock->raise();
287 void MainWindow::queryQuit() {
288 kDebug() << "----- SAVING CONFUIG";
289 if (queryClose()) kapp->quit();
293 bool MainWindow::queryClose() {
295 if (m_activeDocument && m_activeDocument->isModified()) {
296 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
297 case KMessageBox::Yes :
298 // save document here. If saving fails, return false;
301 case KMessageBox::No :
310 void MainWindow::saveProperties(KConfig*) {
311 // save properties here,used by session management
316 void MainWindow::readProperties(KConfig *config) {
317 // read properties here,used by session management
318 QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
319 openFile(KUrl(Lastproject));
322 void MainWindow::slotReloadEffects() {
323 initEffects::parseCustomEffectsFile();
324 m_customEffectsMenu->clear();
325 const QStringList effects = customEffects.effectNames();
327 foreach(const QString &name, effects) {
328 action = new QAction(name, this);
329 action->setData(name);
330 m_customEffectsMenu->addAction(action);
332 m_effectList->reloadEffectList();
335 void MainWindow::activateShuttleDevice() {
336 if (m_jogProcess) delete m_jogProcess;
338 if (KdenliveSettings::enableshuttle() == false) return;
339 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
340 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
341 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
342 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
343 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
344 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
345 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
348 void MainWindow::slotShuttleButton(int code) {
351 slotShuttleAction(KdenliveSettings::shuttle1());
354 slotShuttleAction(KdenliveSettings::shuttle2());
357 slotShuttleAction(KdenliveSettings::shuttle3());
360 slotShuttleAction(KdenliveSettings::shuttle4());
363 slotShuttleAction(KdenliveSettings::shuttle5());
368 void MainWindow::slotShuttleAction(int code) {
373 m_monitorManager->slotPlay();
376 m_monitorManager->slotPlay();
381 void MainWindow::slotFullScreen() {
382 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
385 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
386 if (!m_activeDocument) return;
387 if (effect.isNull()) {
388 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
391 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
392 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
395 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
396 if (clipMonitor) clipMonitorDock->raise();
397 else projectMonitorDock->raise();
400 void MainWindow::slotSetClipDuration(int id, int duration) {
401 if (!m_activeDocument) return;
402 m_activeDocument->setProducerDuration(id, duration);
405 void MainWindow::slotConnectMonitors() {
407 m_projectList->setRenderer(m_clipMonitor->render);
408 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
409 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
410 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
411 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
412 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
414 connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(int)), m_projectList, SLOT(slotRemoveInvalidClip(int)));
416 connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
419 void MainWindow::setupActions() {
421 m_timecodeFormat = new KComboBox(this);
422 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
423 m_timecodeFormat->addItem(i18n("Frames"));
425 statusProgressBar = new QProgressBar(this);
426 statusProgressBar->setMinimum(0);
427 statusProgressBar->setMaximum(100);
428 statusProgressBar->setMaximumWidth(150);
429 statusProgressBar->setVisible(false);
431 QWidget *w = new QWidget;
433 QHBoxLayout *layout = new QHBoxLayout;
434 w->setLayout(layout);
435 layout->setContentsMargins(5, 0, 5, 0);
436 QToolBar *toolbar = new QToolBar("statusToolBar", this);
439 m_toolGroup = new QActionGroup(this);
441 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;}";
443 m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
444 m_buttonSelectTool->setCheckable(true);
445 m_buttonSelectTool->setChecked(true);
447 m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
448 m_buttonRazorTool->setCheckable(true);
449 m_buttonRazorTool->setChecked(false);
451 m_toolGroup->addAction(m_buttonSelectTool);
452 m_toolGroup->addAction(m_buttonRazorTool);
453 m_toolGroup->setExclusive(true);
454 toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
456 QWidget * actionWidget;
457 actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
458 actionWidget->setMaximumWidth(24);
459 actionWidget->setMinimumHeight(17);
461 actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
462 actionWidget->setMaximumWidth(24);
463 actionWidget->setMinimumHeight(17);
465 toolbar->setStyleSheet(style1);
466 connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
468 toolbar->addSeparator();
469 m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
470 m_buttonFitZoom->setCheckable(false);
471 connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
473 actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
474 actionWidget->setMaximumWidth(24);
475 actionWidget->setMinimumHeight(17);
477 m_zoomSlider = new QSlider(Qt::Horizontal, this);
478 m_zoomSlider->setMaximum(13);
479 m_zoomSlider->setPageStep(1);
481 m_zoomSlider->setMaximumWidth(150);
482 m_zoomSlider->setMinimumWidth(100);
484 const int contentHeight = QFontMetrics(w->font()).height() + 8;
485 QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
486 style.append("QSlider::handle:horizontal { background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
487 m_zoomSlider->setStyleSheet(style);
489 //m_zoomSlider->setMaximumHeight(contentHeight);
490 //m_zoomSlider->height() + 5;
491 statusBar()->setMinimumHeight(contentHeight);
494 toolbar->addWidget(m_zoomSlider);
496 m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
497 m_buttonVideoThumbs->setCheckable(true);
498 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
499 connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
501 m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
502 m_buttonAudioThumbs->setCheckable(true);
503 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
504 connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
506 m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
507 m_buttonShowMarkers->setCheckable(true);
508 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
509 connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
511 m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
512 m_buttonSnap->setCheckable(true);
513 m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
514 connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
515 layout->addWidget(toolbar);
518 actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
519 actionWidget->setMaximumWidth(24);
520 actionWidget->setMinimumHeight(17);
522 actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
523 actionWidget->setMaximumWidth(24);
524 actionWidget->setMinimumHeight(17);
526 actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
527 actionWidget->setMaximumWidth(24);
528 actionWidget->setMinimumHeight(17);
530 actionWidget = toolbar->widgetForAction(m_buttonSnap);
531 actionWidget->setMaximumWidth(24);
532 actionWidget->setMinimumHeight(17);
534 m_messageLabel = new StatusBarMessageLabel(this);
535 m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
537 statusBar()->addWidget(m_messageLabel, 10);
538 statusBar()->addWidget(statusProgressBar, 0);
539 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
540 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
541 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
542 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
543 m_messageLabel->hide();
545 actionCollection()->addAction("select_tool", m_buttonSelectTool);
546 actionCollection()->addAction("razor_tool", m_buttonRazorTool);
548 actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
549 actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
550 actionCollection()->addAction("show_markers", m_buttonShowMarkers);
551 actionCollection()->addAction("snap", m_buttonSnap);
552 actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
554 m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
555 actionCollection()->addAction("project_find", m_projectSearch);
556 connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
557 m_projectSearch->setShortcut(Qt::Key_Slash);
559 m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
560 actionCollection()->addAction("project_find_next", m_projectSearchNext);
561 connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
562 m_projectSearchNext->setShortcut(Qt::Key_F3);
563 m_projectSearchNext->setEnabled(false);
565 KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
566 actionCollection()->addAction("manage_profiles", profilesAction);
567 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
569 KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
570 actionCollection()->addAction("project_settings", projectAction);
571 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
573 KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
574 actionCollection()->addAction("project_render", projectRender);
575 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
577 KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
578 monitorPlay->setShortcut(Qt::Key_Space);
579 actionCollection()->addAction("monitor_play", monitorPlay);
580 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
582 KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
583 monitorSeekBackward->setShortcut(Qt::Key_J);
584 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
585 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
587 KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
588 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
589 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
590 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
592 KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
593 monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
594 actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
595 connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
597 KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
598 monitorSeekForward->setShortcut(Qt::Key_L);
599 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
600 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
602 KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
603 clipStart->setShortcut(Qt::Key_Home);
604 actionCollection()->addAction("seek_clip_start", clipStart);
605 connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
607 KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
608 clipEnd->setShortcut(Qt::Key_End);
609 actionCollection()->addAction("seek_clip_end", clipEnd);
610 connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
612 KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
613 projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
614 actionCollection()->addAction("seek_start", projectStart);
615 connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
617 KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
618 projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
619 actionCollection()->addAction("seek_end", projectEnd);
620 connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
622 KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
623 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
624 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
625 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
627 KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
628 monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
629 actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
630 connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
632 KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
633 deleteTimelineClip->setShortcut(Qt::Key_Delete);
634 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
635 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
637 KAction* editTimelineClipSpeed = new KAction(KIcon("edit-delete"), i18n("Change Clip Speed"), this);
638 actionCollection()->addAction("change_clip_speed", editTimelineClipSpeed);
639 connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
641 KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
642 cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
643 actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
644 connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
646 KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
647 actionCollection()->addAction("add_clip_marker", addClipMarker);
648 connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
650 KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
651 actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
652 connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
654 KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
655 actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
656 connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
658 KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
659 actionCollection()->addAction("edit_clip_marker", editClipMarker);
660 connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
662 KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
663 actionCollection()->addAction("add_guide", addGuide);
664 connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
666 QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
667 actionCollection()->addAction("delete_guide", delGuide);
668 connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
670 QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
671 actionCollection()->addAction("edit_guide", editGuide);
672 connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
674 QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
675 actionCollection()->addAction("delete_all_guides", delAllGuides);
676 connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
678 QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
679 actionCollection()->addAction("paste_effects", pasteEffects);
680 connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
682 KStandardAction::quit(this, SLOT(queryQuit()),
685 KStandardAction::open(this, SLOT(openFile()),
688 KStandardAction::save(this, SLOT(saveFile()),
691 KStandardAction::saveAs(this, SLOT(saveFileAs()),
694 KStandardAction::openNew(this, SLOT(newFile()),
697 KStandardAction::preferences(this, SLOT(slotPreferences()),
700 KStandardAction::copy(this, SLOT(slotCopy()),
703 KStandardAction::paste(this, SLOT(slotPaste()),
706 KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
708 undo->setEnabled(false);
709 connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
711 KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
713 redo->setEnabled(false);
714 connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
716 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
718 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
719 this, SLOT(slotDisplayActionMessage(QAction*)));
720 //connect(actionCollection(), SIGNAL( clearStatusText() ),
721 //statusBar(), SLOT( clear() ) );
724 void MainWindow::slotDisplayActionMessage(QAction *a) {
725 statusBar()->showMessage(a->data().toString(), 3000);
728 void MainWindow::saveOptions() {
729 KdenliveSettings::self()->writeConfig();
730 KSharedConfigPtr config = KGlobal::config();
731 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
735 void MainWindow::readOptions() {
736 KSharedConfigPtr config = KGlobal::config();
737 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
738 KConfigGroup initialGroup(config, "version");
739 if (!initialGroup.exists()) {
740 // this is our first run, show Wizard
741 Wizard *w = new Wizard(this);
742 if (w->exec() == QDialog::Accepted) {
744 initialGroup.writeEntry("version", "0.7");
750 void MainWindow::newFile() {
753 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
755 ProjectSettings *w = new ProjectSettings;
756 if (w->exec() != QDialog::Accepted) return;
757 profileName = w->selectedProfile();
758 projectFolder = w->selectedFolder();
761 KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, this);
762 doc->setProfilePath(profileName);
763 TrackView *trackView = new TrackView(doc, this);
764 m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
765 if (m_timelineArea->count() == 1) {
766 connectDocumentInfo(doc);
767 connectDocument(trackView, doc);
768 } else m_timelineArea->setTabBarHidden(false);
771 void MainWindow::activateDocument() {
772 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
773 KdenliveDoc *currentDoc = currentTab->document();
774 connectDocumentInfo(currentDoc);
775 connectDocument(currentTab, currentDoc);
778 void MainWindow::slotRemoveTab() {
779 QWidget *w = m_timelineArea->currentWidget();
780 // closing current document
781 int ix = m_timelineArea->currentIndex() + 1;
782 if (ix == m_timelineArea->count()) ix = 0;
783 m_timelineArea->setCurrentIndex(ix);
784 TrackView *tabToClose = (TrackView *) w;
785 KdenliveDoc *docToClose = tabToClose->document();
786 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
787 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
792 void MainWindow::saveFileAs(const QString &outputFileName) {
793 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
794 m_activeDocument->setUrl(KUrl(outputFileName));
795 setCaption(m_activeDocument->description());
796 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
797 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
798 m_activeDocument->setModified(false);
799 m_fileOpenRecent->addUrl(KUrl(outputFileName));
802 void MainWindow::saveFileAs() {
803 QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
804 if (QFile::exists(outputFile)) {
805 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
807 saveFileAs(outputFile);
810 void MainWindow::saveFile() {
811 if (!m_activeDocument) return;
812 if (m_activeDocument->url().isEmpty()) {
815 saveFileAs(m_activeDocument->url().path());
819 void MainWindow::openFile() {
820 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
821 if (url.isEmpty()) return;
822 m_fileOpenRecent->addUrl(url);
826 void MainWindow::openLastFile() {
827 KSharedConfigPtr config = KGlobal::config();
828 KUrl::List urls = m_fileOpenRecent->urls();
829 if (urls.isEmpty()) newFile();
830 else openFile(urls.last());
833 void MainWindow::openFile(const KUrl &url) {
834 // Check for backup file
835 bool recovery = false;
836 QString directory = url.directory();
837 QString fileName = url.fileName();
839 recoveryUrl.setDirectory(directory);
840 recoveryUrl.setFileName("~" + fileName);
841 if (KIO::NetAccess::exists(recoveryUrl, KIO::NetAccess::SourceSide, this)) {
842 KFileItem bkup(KFileItem::Unknown, KFileItem::Unknown, recoveryUrl, true);
843 KFileItem src(KFileItem::Unknown, KFileItem::Unknown, url, true);
844 if (bkup.time(KFileItem::ModificationTime) > src.time(KFileItem::ModificationTime)) {
845 // Backup file is more recent than source file, ask user for recovery
846 if (KMessageBox::questionYesNo(this, i18n("A newer recovery file exists for <b>%1</b>\nOpen recovery file ?", url.fileName())) == KMessageBox::Yes) recovery = true;
850 //TODO: get video profile from url before opening it
851 /*MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
852 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
854 KdenliveSettings::setCurrent_profile(prof.path);*/
857 doc = new KdenliveDoc(recoveryUrl, KUrl(), m_commandStack, this);
859 doc->setModified(true);
860 } else doc = new KdenliveDoc(url, KUrl(), m_commandStack, this);
861 connectDocumentInfo(doc);
862 TrackView *trackView = new TrackView(doc, this);
863 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
864 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
865 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
866 slotGotProgressInfo(QString(), -1);
867 m_projectMonitor->refreshMonitor(true);
871 void MainWindow::parseProfiles() {
872 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
874 //KdenliveSettings::setDefaulttmpfolder();
875 if (KdenliveSettings::mltpath().isEmpty()) {
876 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
878 if (KdenliveSettings::rendererpath().isEmpty()) {
879 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
881 QStringList profilesFilter;
882 profilesFilter << "*";
883 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
885 if (profilesList.isEmpty()) {
886 // Cannot find MLT path, try finding inigo
887 QString profilePath = KdenliveSettings::rendererpath();
888 if (!profilePath.isEmpty()) {
889 profilePath = profilePath.section('/', 0, -3);
890 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
891 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
894 if (profilesList.isEmpty()) {
895 // Cannot find the MLT profiles, ask for location
896 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
897 getUrl->fileDialog()->setMode(KFile::Directory);
899 KUrl mltPath = getUrl->selectedUrl();
901 if (mltPath.isEmpty()) kapp->quit();
902 KdenliveSettings::setMltpath(mltPath.path());
903 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
907 if (KdenliveSettings::rendererpath().isEmpty()) {
908 // Cannot find the MLT inigo renderer, ask for location
909 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
911 KUrl rendererPath = getUrl->selectedUrl();
913 if (rendererPath.isEmpty()) kapp->quit();
914 KdenliveSettings::setRendererpath(rendererPath.path());
917 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
919 // Parse MLT profiles to build a list of available video formats
920 if (profilesList.isEmpty()) parseProfiles();
924 void MainWindow::slotEditProfiles() {
925 ProfilesDialog *w = new ProfilesDialog;
930 void MainWindow::slotEditProjectSettings() {
931 ProjectSettings *w = new ProjectSettings;
932 if (w->exec() == QDialog::Accepted) {
933 QString profile = w->selectedProfile();
934 m_activeDocument->setProfilePath(profile);
935 KdenliveSettings::setCurrent_profile(profile);
936 KdenliveSettings::setProject_fps(m_activeDocument->fps());
937 setCaption(m_activeDocument->description());
938 m_monitorManager->resetProfiles();
939 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
940 m_monitorManager->setTimecode(m_activeDocument->timecode());
941 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
943 // We need to desactivate & reactivate monitors to get a refresh
944 m_monitorManager->switchMonitors();
949 void MainWindow::slotRenderProject() {
950 if (!m_renderWidget) {
951 m_renderWidget = new RenderWidget(this);
952 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
954 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
955 if (currentTab) m_renderWidget->setTimeline(currentTab);
956 m_renderWidget->setDocument(m_activeDocument);*/
957 m_renderWidget->show();
960 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
961 if (dest.isEmpty()) return;
964 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
965 if (currentTab && zoneOnly) {
966 in = currentTab->inPoint();
967 out = currentTab->outPoint();
970 temp.setAutoRemove(false);
971 temp.setSuffix(".westley");
973 m_projectMonitor->saveSceneList(temp.fileName());
976 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
977 QString videoPlayer = "-";
979 videoPlayer = KdenliveSettings::defaultplayerapp();
980 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."));
982 args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
983 QProcess::startDetached("kdenlive_render", args);
987 void MainWindow::slotUpdateMousePosition(int pos) {
988 if (m_activeDocument)
989 switch (m_timecodeFormat->currentIndex()) {
991 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
994 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
998 void MainWindow::slotUpdateDocumentState(bool modified) {
999 setCaption(m_activeDocument->description(), modified);
1001 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1002 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1004 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1005 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1009 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1010 if (m_activeDocument) {
1011 if (m_activeDocument == doc) return;
1012 disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1014 connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1017 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1018 //m_projectMonitor->stop();
1019 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
1020 if (m_activeDocument) {
1021 if (m_activeDocument == doc) return;
1022 m_activeDocument->backupMltPlaylist();
1023 if (m_activeTimeline) {
1024 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1025 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1026 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1027 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1028 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1029 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1030 disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1031 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
1032 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1033 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1034 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1035 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1036 disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1037 disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1038 disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1040 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1041 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1042 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1043 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1044 disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1045 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1046 disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1047 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1048 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1050 m_activeDocument->setRenderer(NULL);
1051 disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1052 m_clipMonitor->stop();
1054 KdenliveSettings::setCurrent_profile(doc->profilePath());
1055 KdenliveSettings::setProject_fps(doc->fps());
1056 m_monitorManager->resetProfiles();
1057 m_projectList->setDocument(doc);
1058 connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1059 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1060 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1061 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1062 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1063 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1064 connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1065 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1066 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1067 connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1069 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1070 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1074 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1075 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1076 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1077 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1078 m_zoomSlider->setValue(doc->zoom());
1079 connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1080 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1081 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1082 connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1084 connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1087 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1088 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1089 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1090 connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1091 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1092 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1093 connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1095 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1096 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1097 m_activeTimeline = trackView;
1098 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1099 m_monitorManager->setTimecode(doc->timecode());
1100 doc->setRenderer(m_projectMonitor->render);
1101 m_commandStack->setActiveStack(doc->commandStack());
1103 doc->updateAllProjectClips();
1105 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
1106 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
1108 //m_overView->setScene(trackView->projectScene());
1109 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1110 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1112 setCaption(doc->description());
1113 m_activeDocument = doc;
1116 void MainWindow::slotPreferences(int page, int option) {
1117 //An instance of your dialog could be already created and could be
1118 // cached, in which case you want to display the cached dialog
1119 // instead of creating another one
1120 if (KConfigDialog::showDialog("settings")) {
1121 if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
1125 // KConfigDialog didn't find an instance of this dialog, so lets
1127 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1128 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1129 connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(resetProfiles()));
1131 if (page != -1) dialog->showPage(page, option);
1134 void MainWindow::updateConfiguration() {
1135 //TODO: we should apply settings to all projects, not only the current one
1136 if (m_activeTimeline) {
1137 m_activeTimeline->refresh();
1138 m_activeTimeline->projectView()->checkAutoScroll();
1139 m_activeTimeline->projectView()->checkTrackHeight();
1140 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1142 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1143 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1144 activateShuttleDevice();
1148 void MainWindow::slotSwitchVideoThumbs() {
1149 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1150 if (m_activeTimeline) {
1151 m_activeTimeline->refresh();
1153 m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1156 void MainWindow::slotSwitchAudioThumbs() {
1157 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1158 if (m_activeTimeline) {
1159 m_activeTimeline->refresh();
1160 m_activeTimeline->projectView()->checkAutoScroll();
1161 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1163 m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1166 void MainWindow::slotSwitchMarkersComments() {
1167 KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1168 if (m_activeTimeline) {
1169 m_activeTimeline->refresh();
1171 m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1174 void MainWindow::slotSwitchSnap() {
1175 KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1176 m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1180 void MainWindow::slotDeleteTimelineClip() {
1181 if (m_activeTimeline) {
1182 m_activeTimeline->projectView()->deleteSelectedClips();
1186 void MainWindow::slotChangeClipSpeed() {
1187 if (m_activeTimeline) {
1188 m_activeTimeline->projectView()->changeClipSpeed();
1192 void MainWindow::slotAddClipMarker() {
1193 if (m_activeTimeline) {
1194 m_activeTimeline->projectView()->slotAddClipMarker();
1198 void MainWindow::slotDeleteClipMarker() {
1199 if (m_activeTimeline) {
1200 m_activeTimeline->projectView()->slotDeleteClipMarker();
1204 void MainWindow::slotDeleteAllClipMarkers() {
1205 if (m_activeTimeline) {
1206 m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1210 void MainWindow::slotEditClipMarker() {
1211 if (m_activeTimeline) {
1212 m_activeTimeline->projectView()->slotEditClipMarker();
1216 void MainWindow::slotAddGuide() {
1217 if (m_activeTimeline)
1218 m_activeTimeline->projectView()->slotAddGuide();
1221 void MainWindow::slotEditGuide() {
1222 if (m_activeTimeline)
1223 m_activeTimeline->projectView()->slotEditGuide();
1226 void MainWindow::slotDeleteGuide() {
1227 if (m_activeTimeline)
1228 m_activeTimeline->projectView()->slotDeleteGuide();
1231 void MainWindow::slotDeleteAllGuides() {
1232 if (m_activeTimeline)
1233 m_activeTimeline->projectView()->slotDeleteAllGuides();
1236 void MainWindow::slotCutTimelineClip() {
1237 if (m_activeTimeline) {
1238 m_activeTimeline->projectView()->cutSelectedClips();
1242 void MainWindow::slotAddProjectClip(KUrl url) {
1243 if (m_activeDocument)
1244 m_activeDocument->slotAddClipFile(url, QString());
1247 void MainWindow::slotAddTransition(QAction *result) {
1248 if (!result) return;
1249 QDomElement effect = transitions.getEffectByName(result->data().toString());
1250 if (m_activeTimeline) {
1251 m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1255 void MainWindow::slotAddVideoEffect(QAction *result) {
1256 if (!result) return;
1257 QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1258 slotAddEffect(effect);
1261 void MainWindow::slotAddAudioEffect(QAction *result) {
1262 if (!result) return;
1263 QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1264 slotAddEffect(effect);
1267 void MainWindow::slotAddCustomEffect(QAction *result) {
1268 if (!result) return;
1269 QDomElement effect = customEffects.getEffectByName(result->data().toString());
1270 slotAddEffect(effect);
1273 void MainWindow::slotZoomIn() {
1274 m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1277 void MainWindow::slotZoomOut() {
1278 m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1281 void MainWindow::slotFitZoom() {
1282 if (m_activeTimeline) {
1283 m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1287 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1288 statusProgressBar->setValue(progress);
1289 if (progress >= 0) {
1290 if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1291 statusProgressBar->setVisible(true);
1293 m_messageLabel->setMessage(QString(), DefaultMessage);
1294 statusProgressBar->setVisible(false);
1298 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1299 if (clip->clipType() == TEXT) {
1300 m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1303 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1304 connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1305 if (dia.exec() == QDialog::Accepted) {
1306 m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1307 if (dia.needsTimelineRefresh()) {
1308 // update clip occurences in timeline
1309 m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1314 void MainWindow::customEvent(QEvent* e) {
1315 if (e->type() == QEvent::User) {
1316 // The timeline playing position changed...
1317 kDebug() << "RECIEVED JOG EVEMNT!!!";
1320 void MainWindow::slotActivateEffectStackView() {
1321 effectStack->raiseWindow(effectStackDock);
1324 void MainWindow::slotActivateTransitionView() {
1325 transitionConfig->raiseWindow(transitionConfigDock);
1328 void MainWindow::slotSnapRewind() {
1329 if (m_monitorManager->projectMonitorFocused()) {
1330 if (m_activeTimeline)
1331 m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1335 void MainWindow::slotSnapForward() {
1336 if (m_monitorManager->projectMonitorFocused()) {
1337 if (m_activeTimeline)
1338 m_activeTimeline->projectView()->slotSeekToNextSnap();
1342 void MainWindow::slotClipStart() {
1343 if (m_monitorManager->projectMonitorFocused()) {
1344 if (m_activeTimeline)
1345 m_activeTimeline->projectView()->clipStart();
1349 void MainWindow::slotClipEnd() {
1350 if (m_monitorManager->projectMonitorFocused()) {
1351 if (m_activeTimeline)
1352 m_activeTimeline->projectView()->clipEnd();
1356 void MainWindow::slotChangeTool(QAction * action) {
1357 if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1358 else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1361 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1362 if (m_activeDocument && m_activeTimeline) {
1363 //m_activeDocument->setTool(tool);
1364 m_activeTimeline->projectView()->setTool(tool);
1368 void MainWindow::slotCopy() {
1369 if (!m_activeDocument || !m_activeTimeline) return;
1370 m_activeTimeline->projectView()->copyClip();
1373 void MainWindow::slotPaste() {
1374 if (!m_activeDocument || !m_activeTimeline) return;
1375 m_activeTimeline->projectView()->pasteClip();
1378 void MainWindow::slotPasteEffects() {
1379 if (!m_activeDocument || !m_activeTimeline) return;
1380 m_activeTimeline->projectView()->pasteClipEffects();
1383 void MainWindow::slotFind() {
1384 if (!m_activeDocument || !m_activeTimeline) return;
1385 m_projectSearch->setEnabled(false);
1386 m_findActivated = true;
1387 m_findString = QString();
1388 m_activeTimeline->projectView()->initSearchStrings();
1389 statusBar()->showMessage(i18n("Starting -- find text as you type"));
1390 m_findTimer.start(5000);
1391 qApp->installEventFilter(this);
1394 void MainWindow::slotFindNext() {
1395 if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1396 statusBar()->showMessage(i18n("Found : %1", m_findString));
1398 statusBar()->showMessage(i18n("Reached end of project"));
1400 m_findTimer.start(4000);
1403 void MainWindow::findAhead() {
1404 if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1405 m_projectSearchNext->setEnabled(true);
1406 statusBar()->showMessage(i18n("Found : %1", m_findString));
1408 m_projectSearchNext->setEnabled(false);
1409 statusBar()->showMessage(i18n("Not found : %1", m_findString));
1413 void MainWindow::findTimeout() {
1414 m_projectSearchNext->setEnabled(false);
1415 m_findActivated = false;
1416 m_findString = QString();
1417 statusBar()->showMessage(i18n("Find stopped"), 3000);
1418 if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1419 m_projectSearch->setEnabled(true);
1420 removeEventFilter(this);
1423 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1424 if (m_findActivated) {
1425 if (ke->key() == Qt::Key_Backspace) {
1426 m_findString = m_findString.left(m_findString.length() - 1);
1428 if (!m_findString.isEmpty()) {
1434 m_findTimer.start(4000);
1437 } else if (ke->key() == Qt::Key_Escape) {
1441 } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1442 m_findString += ke->text();
1446 m_findTimer.start(4000);
1450 } else KXmlGuiWindow::keyPressEvent(ke);
1453 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1454 if (m_findActivated) {
1455 if (event->type() == QEvent::ShortcutOverride) {
1456 QKeyEvent* ke = (QKeyEvent*) event;
1457 if (ke->text().trimmed().isEmpty()) return false;
1460 } else return false;
1462 // pass the event on to the parent class
1463 return QMainWindow::eventFilter(obj, event);
1467 #include "mainwindow.moc"