]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
paste effects from one clip to another
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27 #include <QKeyEvent>
28
29 #include <KApplication>
30 #include <KAction>
31 #include <KLocale>
32 #include <KGlobal>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
37 #include <KDebug>
38 #include <KIO/NetAccess>
39 #include <KSaveFile>
40 #include <KRuler>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
43 #include <KStatusBar>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
48 #include <KMenu>
49 #include <locale.h>
50 #include <ktogglefullscreenaction.h>
51 #include <KFileItem>
52
53 #include <mlt++/Mlt.h>
54
55 #include "mainwindow.h"
56 #include "kdenlivesettings.h"
57 #include "kdenlivesettingsdialog.h"
58 #include "initeffects.h"
59 #include "profilesdialog.h"
60 #include "projectsettings.h"
61 #include "events.h"
62 #include "renderjob.h"
63 #include "clipmanager.h"
64 #include "projectlist.h"
65 #include "monitor.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"
75 #include "renderer.h"
76 #include "jogshuttle.h"
77 #include "clipproperties.h"
78
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
85
86 namespace Mlt {
87 class Producer;
88 };
89
90 EffectsList MainWindow::videoEffects;
91 EffectsList MainWindow::audioEffects;
92 EffectsList MainWindow::customEffects;
93 EffectsList MainWindow::transitions;
94
95 MainWindow::MainWindow(QWidget *parent)
96         : KXmlGuiWindow(parent),
97         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
98     setlocale(LC_NUMERIC, "POSIX");
99     parseProfiles();
100     setFont(KGlobalSettings::toolBarFont());
101     m_commandStack = new QUndoGroup;
102     m_timelineArea = new KTabWidget(this);
103     m_timelineArea->setTabReorderingEnabled(true);
104     m_timelineArea->setTabBarHidden(true);
105
106     QToolButton *closeTabButton = new QToolButton;
107     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
108     closeTabButton->setIcon(KIcon("tab-close"));
109     closeTabButton->adjustSize();
110     closeTabButton->setToolTip(i18n("Close the current tab"));
111     m_timelineArea->setCornerWidget(closeTabButton);
112     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
113
114     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
115     m_findTimer.setSingleShot(true);
116
117     initEffects::parseEffectFiles();
118     m_monitorManager = new MonitorManager();
119
120     projectListDock = new QDockWidget(i18n("Project Tree"), this);
121     projectListDock->setObjectName("project_tree");
122     m_projectList = new ProjectList(this);
123     projectListDock->setWidget(m_projectList);
124     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
125
126     effectListDock = new QDockWidget(i18n("Effect List"), this);
127     effectListDock->setObjectName("effect_list");
128     m_effectList = new EffectsListView();
129
130     //m_effectList = new KListWidget(this);
131     effectListDock->setWidget(m_effectList);
132     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
133
134     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
135     effectStackDock->setObjectName("effect_stack");
136     effectStack = new EffectStackView(this);
137     effectStackDock->setWidget(effectStack);
138     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
139
140     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
141     transitionConfigDock->setObjectName("transition");
142     transitionConfig = new TransitionSettings(this);
143     transitionConfigDock->setWidget(transitionConfig);
144     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
145
146
147     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
148     clipMonitorDock->setObjectName("clip_monitor");
149     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
150     clipMonitorDock->setWidget(m_clipMonitor);
151     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
152     //m_clipMonitor->stop();
153
154     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
155     projectMonitorDock->setObjectName("project_monitor");
156     m_projectMonitor = new Monitor("project", m_monitorManager, this);
157     projectMonitorDock->setWidget(m_projectMonitor);
158     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
159
160     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
161     recMonitorDock->setObjectName("record_monitor");
162     m_recMonitor = new RecMonitor("record", this);
163     recMonitorDock->setWidget(m_recMonitor);
164     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
165
166     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
167
168     undoViewDock = new QDockWidget(i18n("Undo History"), this);
169     undoViewDock->setObjectName("undo_history");
170     m_undoView = new QUndoView(this);
171     m_undoView->setCleanIcon(KIcon("edit-clear"));
172     m_undoView->setEmptyLabel(i18n("Clean"));
173     undoViewDock->setWidget(m_undoView);
174     m_undoView->setGroup(m_commandStack);
175     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
176
177     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
178     //overviewDock->setObjectName("project_overview");
179     //m_overView = new CustomTrackView(NULL, NULL, this);
180     //overviewDock->setWidget(m_overView);
181     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
182
183     setupActions();
184     //tabifyDockWidget(projectListDock, effectListDock);
185     tabifyDockWidget(projectListDock, effectStackDock);
186     tabifyDockWidget(projectListDock, transitionConfigDock);
187     //tabifyDockWidget(projectListDock, undoViewDock);
188     projectListDock->raise();
189
190     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
191     tabifyDockWidget(clipMonitorDock, recMonitorDock);
192     setCentralWidget(m_timelineArea);
193
194     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
195     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
196
197     // build effects menus
198     QAction *action;
199     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
200     QStringList effects = videoEffects.effectNames();
201     foreach(const QString &name, effects) {
202         action = new QAction(name, this);
203         action->setData(name);
204         videoEffectsMenu->addAction(action);
205     }
206     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
207     effects = audioEffects.effectNames();
208     foreach(const QString &name, effects) {
209         action = new QAction(name, this);
210         action->setData(name);
211         audioEffectsMenu->addAction(action);
212     }
213     QMenu *customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
214     effects = customEffects.effectNames();
215     foreach(const QString &name, effects) {
216         action = new QAction(name, this);
217         action->setData(name);
218         customEffectsMenu->addAction(action);
219     }
220
221     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
222     const QList<QAction *> viewActions = createPopupMenu()->actions();
223     viewMenu->insertActions(NULL, viewActions);
224
225     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
226     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
227     connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
228
229     m_timelineContextMenu = new QMenu(this);
230     m_timelineContextClipMenu = new QMenu(this);
231     m_timelineContextTransitionMenu = new QMenu(this);
232
233
234     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
235     effects = transitions.effectNames();
236     foreach(const QString &name, effects) {
237         action = new QAction(name, this);
238         action->setData(name);
239         transitionsMenu->addAction(action);
240     }
241     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
242
243     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
244
245     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
246     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
247     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
248     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
249
250     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
251     m_timelineContextClipMenu->addMenu(markersMenu);
252     m_timelineContextClipMenu->addMenu(transitionsMenu);
253     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
254     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
255     m_timelineContextClipMenu->addMenu(customEffectsMenu);
256
257     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
258     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
259
260     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
261     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
262     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
263     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
264     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
265     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
266     slotConnectMonitors();
267
268     setAutoSaveSettings();
269
270     if (KdenliveSettings::openlastproject()) {
271         openLastFile();
272     } else newFile();
273
274     activateShuttleDevice();
275 }
276
277 void MainWindow::queryQuit() {
278     kDebug() << "----- SAVING CONFUIG";
279     if (queryClose()) kapp->quit();
280 }
281
282 //virtual
283 bool MainWindow::queryClose() {
284     saveOptions();
285     if (m_activeDocument && m_activeDocument->isModified()) {
286         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
287         case KMessageBox::Yes :
288             // save document here. If saving fails, return false;
289             saveFile();
290             return true;
291         case KMessageBox::No :
292             return true;
293         default: // cancel
294             return false;
295         }
296     }
297     return true;
298 }
299
300 void MainWindow::saveProperties(KConfig*) {
301     // save properties here,used by session management
302     saveFile();
303 }
304
305
306 void MainWindow::readProperties(KConfig *config) {
307     // read properties here,used by session management
308     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
309     openFile(KUrl(Lastproject));
310 }
311
312 void MainWindow::activateShuttleDevice() {
313     if (m_jogProcess) delete m_jogProcess;
314     m_jogProcess = NULL;
315     if (KdenliveSettings::enableshuttle() == false) return;
316     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
317     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
318     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
319     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
320     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
321     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
322     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
323 }
324
325 void MainWindow::slotShuttleButton(int code) {
326     switch (code) {
327     case 5:
328         slotShuttleAction(KdenliveSettings::shuttle1());
329         break;
330     case 6:
331         slotShuttleAction(KdenliveSettings::shuttle2());
332         break;
333     case 7:
334         slotShuttleAction(KdenliveSettings::shuttle3());
335         break;
336     case 8:
337         slotShuttleAction(KdenliveSettings::shuttle4());
338         break;
339     case 9:
340         slotShuttleAction(KdenliveSettings::shuttle5());
341         break;
342     }
343 }
344
345 void MainWindow::slotShuttleAction(int code) {
346     switch (code) {
347     case 0:
348         return;
349     case 1:
350         m_monitorManager->slotPlay();
351         break;
352     default:
353         m_monitorManager->slotPlay();
354         break;
355     }
356 }
357
358 void MainWindow::slotFullScreen() {
359     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
360 }
361
362 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
363     if (!m_activeDocument) return;
364     if (effect.isNull()) {
365         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
366         return;
367     }
368     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
369     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
370 }
371
372 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
373     if (clipMonitor) clipMonitorDock->raise();
374     else projectMonitorDock->raise();
375 }
376
377 void MainWindow::slotSetClipDuration(int id, int duration) {
378     if (!m_activeDocument) return;
379     m_activeDocument->setProducerDuration(id, duration);
380 }
381
382 void MainWindow::slotConnectMonitors() {
383
384     m_projectList->setRenderer(m_clipMonitor->render);
385     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
386     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
387     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
388     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
389     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 > &)));
390     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
391 }
392
393 void MainWindow::setupActions() {
394
395     m_timecodeFormat = new KComboBox(this);
396     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
397     m_timecodeFormat->addItem(i18n("Frames"));
398
399     statusProgressBar = new QProgressBar(this);
400     statusProgressBar->setMinimum(0);
401     statusProgressBar->setMaximum(100);
402     statusProgressBar->setMaximumWidth(150);
403     statusProgressBar->setVisible(false);
404
405     QWidget *w = new QWidget;
406
407     QHBoxLayout *layout = new QHBoxLayout;
408     w->setLayout(layout);
409     layout->setContentsMargins(5, 0, 5, 0);
410     QToolBar *toolbar = new QToolBar("statusToolBar", this);
411
412
413     m_toolGroup = new QActionGroup(this);
414
415     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;}";
416
417     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
418     m_buttonSelectTool->setCheckable(true);
419     m_buttonSelectTool->setChecked(true);
420
421     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
422     m_buttonRazorTool->setCheckable(true);
423     m_buttonRazorTool->setChecked(false);
424
425     m_toolGroup->addAction(m_buttonSelectTool);
426     m_toolGroup->addAction(m_buttonRazorTool);
427     m_toolGroup->setExclusive(true);
428     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
429
430     QWidget * actionWidget;
431     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
432     actionWidget->setMaximumWidth(24);
433     actionWidget->setMinimumHeight(17);
434
435     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
436     actionWidget->setMaximumWidth(24);
437     actionWidget->setMinimumHeight(17);
438
439     toolbar->setStyleSheet(style1);
440     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
441
442     toolbar->addSeparator();
443     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
444     m_buttonFitZoom->setCheckable(false);
445     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
446
447     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
448     actionWidget->setMaximumWidth(24);
449     actionWidget->setMinimumHeight(17);
450
451     m_zoomSlider = new QSlider(Qt::Horizontal, this);
452     m_zoomSlider->setMaximum(13);
453     m_zoomSlider->setPageStep(1);
454
455     m_zoomSlider->setMaximumWidth(150);
456     m_zoomSlider->setMinimumWidth(100);
457
458     const int contentHeight = QFontMetrics(w->font()).height() + 8;
459     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
460     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
461     m_zoomSlider->setStyleSheet(style);
462
463     //m_zoomSlider->setMaximumHeight(contentHeight);
464     //m_zoomSlider->height() + 5;
465     statusBar()->setMinimumHeight(contentHeight);
466
467
468     toolbar->addWidget(m_zoomSlider);
469
470     m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
471     m_buttonVideoThumbs->setCheckable(true);
472     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
473     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
474
475     m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
476     m_buttonAudioThumbs->setCheckable(true);
477     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
478     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
479
480     m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
481     m_buttonShowMarkers->setCheckable(true);
482     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
483     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
484
485     m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
486     m_buttonSnap->setCheckable(true);
487     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
488     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
489     layout->addWidget(toolbar);
490
491
492     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
493     actionWidget->setMaximumWidth(24);
494     actionWidget->setMinimumHeight(17);
495
496     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
497     actionWidget->setMaximumWidth(24);
498     actionWidget->setMinimumHeight(17);
499
500     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
501     actionWidget->setMaximumWidth(24);
502     actionWidget->setMinimumHeight(17);
503
504     actionWidget = toolbar->widgetForAction(m_buttonSnap);
505     actionWidget->setMaximumWidth(24);
506     actionWidget->setMinimumHeight(17);
507
508     m_messageLabel = new StatusBarMessageLabel(this);
509     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
510
511     statusBar()->addWidget(m_messageLabel, 10);
512     statusBar()->addWidget(statusProgressBar, 0);
513     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
514     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
515     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
516     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
517     m_messageLabel->hide();
518
519     actionCollection()->addAction("select_tool", m_buttonSelectTool);
520     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
521
522     actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
523     actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
524     actionCollection()->addAction("show_markers", m_buttonShowMarkers);
525     actionCollection()->addAction("snap", m_buttonSnap);
526     actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
527
528     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
529     actionCollection()->addAction("project_find", m_projectSearch);
530     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
531     m_projectSearch->setShortcut(Qt::Key_Slash);
532
533     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
534     actionCollection()->addAction("project_find_next", m_projectSearchNext);
535     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
536     m_projectSearchNext->setShortcut(Qt::Key_F3);
537     m_projectSearchNext->setEnabled(false);
538
539     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
540     actionCollection()->addAction("manage_profiles", profilesAction);
541     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
542
543     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
544     actionCollection()->addAction("project_settings", projectAction);
545     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
546
547     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
548     actionCollection()->addAction("project_render", projectRender);
549     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
550
551     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
552     monitorPlay->setShortcut(Qt::Key_Space);
553     actionCollection()->addAction("monitor_play", monitorPlay);
554     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
555
556     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
557     monitorSeekBackward->setShortcut(Qt::Key_J);
558     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
559     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
560
561     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
562     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
563     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
564     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
565
566     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
567     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
568     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
569     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
570
571     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
572     monitorSeekForward->setShortcut(Qt::Key_L);
573     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
574     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
575
576     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
577     clipStart->setShortcut(Qt::Key_Home);
578     actionCollection()->addAction("seek_clip_start", clipStart);
579     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
580
581     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
582     clipEnd->setShortcut(Qt::Key_End);
583     actionCollection()->addAction("seek_clip_end", clipEnd);
584     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
585
586     KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
587     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
588     actionCollection()->addAction("seek_start", projectStart);
589     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
590
591     KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
592     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
593     actionCollection()->addAction("seek_end", projectEnd);
594     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
595
596     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
597     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
598     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
599     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
600
601     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
602     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
603     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
604     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
605
606     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
607     deleteTimelineClip->setShortcut(Qt::Key_Delete);
608     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
609     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
610
611     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
612     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
613     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
614     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
615
616     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
617     actionCollection()->addAction("add_clip_marker", addClipMarker);
618     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
619
620     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
621     actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
622     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
623
624     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
625     actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
626     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
627
628     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
629     actionCollection()->addAction("edit_clip_marker", editClipMarker);
630     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
631
632     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
633     actionCollection()->addAction("add_guide", addGuide);
634     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
635
636     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
637     actionCollection()->addAction("delete_guide", delGuide);
638     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
639
640     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
641     actionCollection()->addAction("edit_guide", editGuide);
642     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
643
644     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
645     actionCollection()->addAction("delete_all_guides", delAllGuides);
646     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
647
648     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
649     actionCollection()->addAction("paste_effects", pasteEffects);
650     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
651
652     KStandardAction::quit(this, SLOT(queryQuit()),
653                           actionCollection());
654
655     KStandardAction::open(this, SLOT(openFile()),
656                           actionCollection());
657
658     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
659                        actionCollection());
660
661     KStandardAction::save(this, SLOT(saveFile()),
662                           actionCollection());
663
664     KStandardAction::saveAs(this, SLOT(saveFileAs()),
665                             actionCollection());
666
667     KStandardAction::openNew(this, SLOT(newFile()),
668                              actionCollection());
669
670     KStandardAction::preferences(this, SLOT(slotPreferences()),
671                                  actionCollection());
672
673     KStandardAction::copy(this, SLOT(slotCopy()),
674                           actionCollection());
675
676     KStandardAction::paste(this, SLOT(slotPaste()),
677                            actionCollection());
678
679     KStandardAction::undo(this, SLOT(undo()),
680                           actionCollection());
681
682     KStandardAction::redo(this, SLOT(redo()),
683                           actionCollection());
684
685     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
686
687     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
688             this, SLOT(slotDisplayActionMessage(QAction*)));
689     //connect(actionCollection(), SIGNAL( clearStatusText() ),
690     //statusBar(), SLOT( clear() ) );
691
692     readOptions();
693 }
694
695 void MainWindow::undo() {
696     m_commandStack->undo();
697 }
698
699 void MainWindow::redo() {
700     m_commandStack->redo();
701 }
702
703 void MainWindow::slotDisplayActionMessage(QAction *a) {
704     statusBar()->showMessage(a->data().toString(), 3000);
705 }
706
707 void MainWindow::saveOptions() {
708     KdenliveSettings::self()->writeConfig();
709     KSharedConfigPtr config = KGlobal::config();
710     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
711     config->sync();
712 }
713
714 void MainWindow::readOptions() {
715     KSharedConfigPtr config = KGlobal::config();
716     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
717 }
718
719 void MainWindow::newFile() {
720     QString profileName;
721     KUrl projectFolder;
722     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
723     else {
724         ProjectSettings *w = new ProjectSettings;
725         if (w->exec() != QDialog::Accepted) return;
726         profileName = w->selectedProfile();
727         projectFolder = w->selectedFolder();
728         delete w;
729     }
730     MltVideoProfile prof;
731     if (!profileName.isEmpty()) prof = ProfilesDialog::getVideoProfile(profileName);
732     else prof = ProfilesDialog::getVideoProfile("dv_pal");
733     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
734     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
735     TrackView *trackView = new TrackView(doc, this);
736     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
737     if (m_timelineArea->count() == 1) {
738         connectDocumentInfo(doc);
739         connectDocument(trackView, doc);
740     } else m_timelineArea->setTabBarHidden(false);
741 }
742
743 void MainWindow::activateDocument() {
744     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
745     KdenliveDoc *currentDoc = currentTab->document();
746     connectDocumentInfo(currentDoc);
747     connectDocument(currentTab, currentDoc);
748 }
749
750 void MainWindow::slotRemoveTab() {
751     QWidget *w = m_timelineArea->currentWidget();
752     // closing current document
753     int ix = m_timelineArea->currentIndex() + 1;
754     if (ix == m_timelineArea->count()) ix = 0;
755     m_timelineArea->setCurrentIndex(ix);
756     TrackView *tabToClose = (TrackView *) w;
757     KdenliveDoc *docToClose = tabToClose->document();
758     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
759     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
760     delete docToClose;
761     delete w;
762 }
763
764 void MainWindow::saveFileAs(const QString &outputFileName) {
765     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
766     m_activeDocument->setUrl(KUrl(outputFileName));
767     setCaption(m_activeDocument->description());
768     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
769     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
770     m_activeDocument->setModified(false);
771     m_fileOpenRecent->addUrl(KUrl(outputFileName));
772 }
773
774 void MainWindow::saveFileAs() {
775     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
776     if (QFile::exists(outputFile)) {
777         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
778     }
779     saveFileAs(outputFile);
780 }
781
782 void MainWindow::saveFile() {
783     if (!m_activeDocument) return;
784     if (m_activeDocument->url().isEmpty()) {
785         saveFileAs();
786     } else {
787         saveFileAs(m_activeDocument->url().path());
788     }
789 }
790
791 void MainWindow::openFile() {
792     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
793     if (url.isEmpty()) return;
794     m_fileOpenRecent->addUrl(url);
795     openFile(url);
796 }
797
798 void MainWindow::openLastFile() {
799     KSharedConfigPtr config = KGlobal::config();
800     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
801     openFile(KUrl(Lastproject));
802 }
803
804 void MainWindow::openFile(const KUrl &url) {
805     // Check for backup file
806     bool recovery = false;
807     QString directory = url.directory();
808     QString fileName = url.fileName();
809     KUrl recoveryUrl;
810     recoveryUrl.setDirectory(directory);
811     recoveryUrl.setFileName("~" + fileName);
812     if (KIO::NetAccess::exists(recoveryUrl, KIO::NetAccess::SourceSide, this)) {
813         KFileItem bkup(KFileItem::Unknown, KFileItem::Unknown, recoveryUrl, true);
814         KFileItem src(KFileItem::Unknown, KFileItem::Unknown, url, true);
815         if (bkup.time(KFileItem::ModificationTime) > src.time(KFileItem::ModificationTime)) {
816             // Backup file is more recent than source file, ask user for recovery
817             if (KMessageBox::questionYesNo(this, i18n("A newer recovery file exists for <b>%1</b>\nOpen recovery file ?", url.fileName())) == KMessageBox::Yes) recovery = true;
818         }
819     }
820
821     //TODO: get video profile from url before opening it
822     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
823     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
824     KdenliveDoc *doc;
825     if (recovery) {
826         doc = new KdenliveDoc(recoveryUrl, KUrl(), prof, m_commandStack, this);
827         doc->setUrl(url);
828         doc->setModified(true);
829     } else doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
830     connectDocumentInfo(doc);
831     TrackView *trackView = new TrackView(doc, this);
832     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
833     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
834     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
835     slotGotProgressInfo(QString(), -1);
836     m_projectMonitor->refreshMonitor(true);
837     //connectDocument(trackView, doc);
838 }
839
840
841 void MainWindow::parseProfiles() {
842     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
843
844     //KdenliveSettings::setDefaulttmpfolder();
845     if (KdenliveSettings::mltpath().isEmpty()) {
846         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
847     }
848     if (KdenliveSettings::rendererpath().isEmpty()) {
849         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
850     }
851     QStringList profilesFilter;
852     profilesFilter << "*";
853     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
854
855     if (profilesList.isEmpty()) {
856         // Cannot find MLT path, try finding inigo
857         QString profilePath = KdenliveSettings::rendererpath();
858         if (!profilePath.isEmpty()) {
859             profilePath = profilePath.section('/', 0, -3);
860             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
861             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
862         }
863
864         if (profilesList.isEmpty()) {
865             // Cannot find the MLT profiles, ask for location
866             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
867             getUrl->fileDialog()->setMode(KFile::Directory);
868             getUrl->exec();
869             KUrl mltPath = getUrl->selectedUrl();
870             delete getUrl;
871             if (mltPath.isEmpty()) kapp->quit();
872             KdenliveSettings::setMltpath(mltPath.path());
873             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
874         }
875     }
876
877     if (KdenliveSettings::rendererpath().isEmpty()) {
878         // Cannot find the MLT inigo renderer, ask for location
879         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
880         getUrl->exec();
881         KUrl rendererPath = getUrl->selectedUrl();
882         delete getUrl;
883         if (rendererPath.isEmpty()) kapp->quit();
884         KdenliveSettings::setRendererpath(rendererPath.path());
885     }
886
887     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
888
889     // Parse MLT profiles to build a list of available video formats
890     if (profilesList.isEmpty()) parseProfiles();
891 }
892
893
894 void MainWindow::slotEditProfiles() {
895     ProfilesDialog *w = new ProfilesDialog;
896     w->exec();
897     delete w;
898 }
899
900 void MainWindow::slotEditProjectSettings() {
901     ProjectSettings *w = new ProjectSettings;
902     if (w->exec() == QDialog::Accepted) {
903         QString profile = w->selectedProfile();
904         m_activeDocument->setProfilePath(profile);
905         m_monitorManager->resetProfiles(profile);
906         setCaption(m_activeDocument->description());
907         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
908         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
909         m_monitorManager->setTimecode(m_activeDocument->timecode());
910         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
911
912         // We need to desactivate & reactivate monitors to get a refresh
913         m_monitorManager->switchMonitors();
914     }
915     delete w;
916 }
917
918 void MainWindow::slotRenderProject() {
919     if (!m_renderWidget) {
920         m_renderWidget = new RenderWidget(this);
921         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
922     }
923     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
924     if (currentTab) m_renderWidget->setTimeline(currentTab);
925     m_renderWidget->setDocument(m_activeDocument);*/
926     m_renderWidget->show();
927 }
928
929 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
930     if (dest.isEmpty()) return;
931     int in;
932     int out;
933     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
934     if (currentTab && zoneOnly) {
935         in = currentTab->inPoint();
936         out = currentTab->outPoint();
937     }
938     KTemporaryFile temp;
939     temp.setAutoRemove(false);
940     temp.setSuffix(".westley");
941     if (temp.open()) {
942         m_projectMonitor->saveSceneList(temp.fileName());
943         QStringList args;
944         args << "-erase";
945         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
946         QString videoPlayer = "-";
947         if (playAfter) {
948             videoPlayer = KdenliveSettings::defaultplayerapp();
949             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."));
950         }
951         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
952         QProcess::startDetached("kdenlive_render", args);
953     }
954 }
955
956 void MainWindow::slotUpdateMousePosition(int pos) {
957     if (m_activeDocument)
958         switch (m_timecodeFormat->currentIndex()) {
959         case 0:
960             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
961             break;
962         default:
963             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
964         }
965 }
966
967 void MainWindow::slotUpdateDocumentState(bool modified) {
968     setCaption(m_activeDocument->description(), modified);
969     if (modified) {
970         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
971         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
972     } else {
973         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
974         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
975     }
976 }
977
978 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
979     if (m_activeDocument) {
980         if (m_activeDocument == doc) return;
981         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
982     }
983     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
984 }
985
986 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
987     //m_projectMonitor->stop();
988     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
989     if (m_activeDocument) {
990         if (m_activeDocument == doc) return;
991         m_activeDocument->backupMltPlaylist();
992         if (m_activeTimeline) {
993             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
994             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
995             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
996             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
997             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
998             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
999             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1000             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
1001             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1002             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1003             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1004             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1005             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1006             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1007             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1008
1009             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1010             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1011             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1012             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1013             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1014             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1015             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1016             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1017         }
1018         m_activeDocument->setRenderer(NULL);
1019         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1020         m_clipMonitor->stop();
1021     }
1022     KdenliveSettings::setProject_fps(doc->fps());
1023     m_monitorManager->resetProfiles(doc->profilePath());
1024     m_projectList->setDocument(doc);
1025     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1026     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1027     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1028     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1029     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1030     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1031     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
1032     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
1033     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1034     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1035
1036     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1037     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1038
1039
1040
1041     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1042     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1043     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1044     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1045     m_zoomSlider->setValue(doc->zoom());
1046     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1047     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1048     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1049     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1050
1051     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1052
1053
1054     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1055     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1056     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1057     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1058     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1059     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1060     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1061     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1062     m_activeTimeline = trackView;
1063     KdenliveSettings::setCurrent_profile(doc->profilePath());
1064     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1065     m_monitorManager->setTimecode(doc->timecode());
1066     doc->setRenderer(m_projectMonitor->render);
1067     m_commandStack->setActiveStack(doc->commandStack());
1068
1069     doc->updateAllProjectClips();
1070
1071     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
1072     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
1073
1074     //m_overView->setScene(trackView->projectScene());
1075     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1076     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1077
1078     setCaption(doc->description());
1079     m_activeDocument = doc;
1080 }
1081
1082 void MainWindow::slotPreferences() {
1083     //An instance of your dialog could be already created and could be
1084     // cached, in which case you want to display the cached dialog
1085     // instead of creating another one
1086     if (KConfigDialog::showDialog("settings"))
1087         return;
1088
1089     // KConfigDialog didn't find an instance of this dialog, so lets
1090     // create it :
1091     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1092     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1093     dialog->show();
1094 }
1095
1096 void MainWindow::updateConfiguration() {
1097     //TODO: we should apply settings to all projects, not only the current one
1098     if (m_activeTimeline) {
1099         m_activeTimeline->refresh();
1100         m_activeTimeline->projectView()->checkAutoScroll();
1101         m_activeTimeline->projectView()->checkTrackHeight();
1102         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1103     }
1104     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1105     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1106     activateShuttleDevice();
1107
1108 }
1109
1110 void MainWindow::slotSwitchVideoThumbs() {
1111     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1112     if (m_activeTimeline) {
1113         m_activeTimeline->refresh();
1114     }
1115     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1116 }
1117
1118 void MainWindow::slotSwitchAudioThumbs() {
1119     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1120     if (m_activeTimeline) {
1121         m_activeTimeline->refresh();
1122         m_activeTimeline->projectView()->checkAutoScroll();
1123         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1124     }
1125     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1126 }
1127
1128 void MainWindow::slotSwitchMarkersComments() {
1129     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1130     if (m_activeTimeline) {
1131         m_activeTimeline->refresh();
1132     }
1133     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1134 }
1135
1136 void MainWindow::slotSwitchSnap() {
1137     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1138     m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1139 }
1140
1141
1142 void MainWindow::slotDeleteTimelineClip() {
1143     if (m_activeTimeline) {
1144         m_activeTimeline->projectView()->deleteSelectedClips();
1145     }
1146 }
1147
1148 void MainWindow::slotAddClipMarker() {
1149     if (m_activeTimeline) {
1150         m_activeTimeline->projectView()->slotAddClipMarker();
1151     }
1152 }
1153
1154 void MainWindow::slotDeleteClipMarker() {
1155     if (m_activeTimeline) {
1156         m_activeTimeline->projectView()->slotDeleteClipMarker();
1157     }
1158 }
1159
1160 void MainWindow::slotDeleteAllClipMarkers() {
1161     if (m_activeTimeline) {
1162         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1163     }
1164 }
1165
1166 void MainWindow::slotEditClipMarker() {
1167     if (m_activeTimeline) {
1168         m_activeTimeline->projectView()->slotEditClipMarker();
1169     }
1170 }
1171
1172 void MainWindow::slotAddGuide() {
1173     if (m_activeTimeline)
1174         m_activeTimeline->projectView()->slotAddGuide();
1175 }
1176
1177 void MainWindow::slotEditGuide() {
1178     if (m_activeTimeline)
1179         m_activeTimeline->projectView()->slotEditGuide();
1180 }
1181
1182 void MainWindow::slotDeleteGuide() {
1183     if (m_activeTimeline)
1184         m_activeTimeline->projectView()->slotDeleteGuide();
1185 }
1186
1187 void MainWindow::slotDeleteAllGuides() {
1188     if (m_activeTimeline)
1189         m_activeTimeline->projectView()->slotDeleteAllGuides();
1190 }
1191
1192 void MainWindow::slotCutTimelineClip() {
1193     if (m_activeTimeline) {
1194         m_activeTimeline->projectView()->cutSelectedClips();
1195     }
1196 }
1197
1198 void MainWindow::slotAddProjectClip(KUrl url) {
1199     if (m_activeDocument)
1200         m_activeDocument->slotAddClipFile(url, QString());
1201 }
1202
1203 void MainWindow::slotAddTransition(QAction *result) {
1204     if (!result) return;
1205     QDomElement effect = transitions.getEffectByName(result->data().toString());
1206     if (m_activeTimeline) {
1207         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1208     }
1209 }
1210
1211 void MainWindow::slotAddVideoEffect(QAction *result) {
1212     if (!result) return;
1213     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1214     slotAddEffect(effect);
1215 }
1216
1217 void MainWindow::slotAddAudioEffect(QAction *result) {
1218     if (!result) return;
1219     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1220     slotAddEffect(effect);
1221 }
1222
1223 void MainWindow::slotAddCustomEffect(QAction *result) {
1224     if (!result) return;
1225     QDomElement effect = customEffects.getEffectByName(result->data().toString());
1226     slotAddEffect(effect);
1227 }
1228
1229 void MainWindow::slotZoomIn() {
1230     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1231 }
1232
1233 void MainWindow::slotZoomOut() {
1234     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1235 }
1236
1237 void MainWindow::slotFitZoom() {
1238     if (m_activeTimeline) {
1239         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1240     }
1241 }
1242
1243 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1244     statusProgressBar->setValue(progress);
1245     if (progress >= 0) {
1246         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1247         statusProgressBar->setVisible(true);
1248     } else {
1249         m_messageLabel->setMessage(QString(), DefaultMessage);
1250         statusProgressBar->setVisible(false);
1251     }
1252 }
1253
1254 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1255     if (clip->clipType() == TEXT) {
1256         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1257         return;
1258     }
1259     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1260     connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1261     if (dia.exec() == QDialog::Accepted) {
1262         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1263         if (dia.needsTimelineRefresh()) {
1264             // update clip occurences in timeline
1265             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1266         }
1267     }
1268 }
1269
1270 void MainWindow::customEvent(QEvent* e) {
1271     if (e->type() == QEvent::User) {
1272         // The timeline playing position changed...
1273         kDebug() << "RECIEVED JOG EVEMNT!!!";
1274     }
1275 }
1276 void MainWindow::slotActivateEffectStackView() {
1277     effectStack->raiseWindow(effectStackDock);
1278 }
1279
1280 void MainWindow::slotActivateTransitionView() {
1281     transitionConfig->raiseWindow(transitionConfigDock);
1282 }
1283
1284 void MainWindow::slotSnapRewind() {
1285     if (m_monitorManager->projectMonitorFocused()) {
1286         if (m_activeTimeline)
1287             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1288     }
1289 }
1290
1291 void MainWindow::slotSnapForward() {
1292     if (m_monitorManager->projectMonitorFocused()) {
1293         if (m_activeTimeline)
1294             m_activeTimeline->projectView()->slotSeekToNextSnap();
1295     }
1296 }
1297
1298 void MainWindow::slotClipStart() {
1299     if (m_monitorManager->projectMonitorFocused()) {
1300         if (m_activeTimeline)
1301             m_activeTimeline->projectView()->clipStart();
1302     }
1303 }
1304
1305 void MainWindow::slotClipEnd() {
1306     if (m_monitorManager->projectMonitorFocused()) {
1307         if (m_activeTimeline)
1308             m_activeTimeline->projectView()->clipEnd();
1309     }
1310 }
1311
1312 void MainWindow::slotChangeTool(QAction * action) {
1313     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1314     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1315 }
1316
1317 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1318     if (m_activeDocument && m_activeTimeline) {
1319         //m_activeDocument->setTool(tool);
1320         m_activeTimeline->projectView()->setTool(tool);
1321     }
1322 }
1323
1324 void MainWindow::slotCopy() {
1325     if (!m_activeDocument || !m_activeTimeline) return;
1326     m_activeTimeline->projectView()->copyClip();
1327 }
1328
1329 void MainWindow::slotPaste() {
1330     if (!m_activeDocument || !m_activeTimeline) return;
1331     m_activeTimeline->projectView()->pasteClip();
1332 }
1333
1334 void MainWindow::slotPasteEffects() {
1335     if (!m_activeDocument || !m_activeTimeline) return;
1336     m_activeTimeline->projectView()->pasteClipEffects();
1337 }
1338
1339 void MainWindow::slotFind() {
1340     if (!m_activeDocument || !m_activeTimeline) return;
1341     m_projectSearch->setEnabled(false);
1342     m_findActivated = true;
1343     m_findString = QString();
1344     m_activeTimeline->projectView()->initSearchStrings();
1345     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1346     m_findTimer.start(5000);
1347     qApp->installEventFilter(this);
1348 }
1349
1350 void MainWindow::slotFindNext() {
1351     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1352         statusBar()->showMessage(i18n("Found : %1", m_findString));
1353     } else {
1354         statusBar()->showMessage(i18n("Reached end of project"));
1355     }
1356     m_findTimer.start(4000);
1357 }
1358
1359 void MainWindow::findAhead() {
1360     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1361         m_projectSearchNext->setEnabled(true);
1362         statusBar()->showMessage(i18n("Found : %1", m_findString));
1363     } else {
1364         m_projectSearchNext->setEnabled(false);
1365         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1366     }
1367 }
1368
1369 void MainWindow::findTimeout() {
1370     m_projectSearchNext->setEnabled(false);
1371     m_findActivated = false;
1372     m_findString = QString();
1373     statusBar()->showMessage(i18n("Find stopped"), 3000);
1374     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1375     m_projectSearch->setEnabled(true);
1376     removeEventFilter(this);
1377 }
1378
1379 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1380     if (m_findActivated) {
1381         if (ke->key() == Qt::Key_Backspace) {
1382             m_findString = m_findString.left(m_findString.length() - 1);
1383
1384             if (!m_findString.isEmpty()) {
1385                 findAhead();
1386             } else {
1387                 findTimeout();
1388             }
1389
1390             m_findTimer.start(4000);
1391             ke->accept();
1392             return;
1393         } else if (ke->key() == Qt::Key_Escape) {
1394             findTimeout();
1395             ke->accept();
1396             return;
1397         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1398             m_findString += ke->text();
1399
1400             findAhead();
1401
1402             m_findTimer.start(4000);
1403             ke->accept();
1404             return;
1405         }
1406     } else KXmlGuiWindow::keyPressEvent(ke);
1407 }
1408
1409 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1410     if (m_findActivated) {
1411         if (event->type() == QEvent::ShortcutOverride) {
1412             QKeyEvent* ke = (QKeyEvent*) event;
1413             if (ke->text().trimmed().isEmpty()) return false;
1414             ke->accept();
1415             return true;
1416         } else return false;
1417     } else {
1418         // pass the event on to the parent class
1419         return QMainWindow::eventFilter(obj, event);
1420     }
1421 }
1422
1423 #include "mainwindow.moc"