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 ***************************************************************************/
24 #include <QDockWidget>
27 #include <QProgressBar>
32 #include <KXmlGuiWindow>
34 #include <KListWidget>
37 #include <KRecentFilesAction>
39 #include <kautosavefile.h>
40 #include <KActionCategory>
42 #include "effectslist.h"
44 #include "definitions.h"
45 #include "statusbarmessagelabel.h"
46 #include "dvdwizard.h"
47 #include "stopmotion/stopmotion.h"
48 #include "noteswidget.h"
49 #include "ui_backupdialog_ui.h"
55 class EffectsListView;
56 class EffectStackView;
57 class TransitionSettings;
60 class CustomTrackView;
64 class JogShuttleAction;
65 #endif /* NO_JOGSHUTTLE */
73 class KActionCollection;
75 class AbstractAudioScopeWidget;
79 class MainWindow : public KXmlGuiWindow
82 Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
86 /** @brief Initialises the main window.
87 * @param MltPath (optional) path to MLT environment
88 * @param Url (optional) file to open
89 * @param clipsToLoad (optional) a comma separated list of clips to import in project
91 * If Url is present, it will be opened, otherwhise, if openlastproject is
92 * set, latest project will be opened. If no file is open after trying this,
93 * a default new file will be created. */
94 explicit MainWindow(const QString &MltPath = QString(),
95 const KUrl &Url = KUrl(), const QString & clipsToLoad = QString(), QWidget *parent = 0);
96 virtual ~MainWindow();
98 /** @brief Locates the MLT environment.
99 * @param mltPath (optional) path to MLT environment
101 * It tries to set the paths of the MLT profiles and renderer, using
102 * mltPath, MLT_PREFIX, searching for the binary `melt`, or asking to the
103 * user. It doesn't fill any list of profiles, while its name suggests so. */
104 void parseProfiles(const QString &mltPath = QString());
106 static EffectsList videoEffects;
107 static EffectsList audioEffects;
108 static EffectsList customEffects;
109 static EffectsList transitions;
112 /** @brief Closes the window.
113 * @return false if the user presses "Cancel" on a confirmation dialog or
114 * the operation requested (starting waiting jobs or saving file) fails,
116 virtual bool queryClose();
118 /** @brief Reports a message in the status bar when an error occurs. */
119 virtual void customEvent(QEvent *e);
121 /** @brief Enables live search in the timeline. */
122 virtual void keyPressEvent(QKeyEvent *ke);
124 /** @brief Stops the active monitor when the window gets hidden. */
125 virtual void hideEvent(QHideEvent *e);
127 /** @brief Filters key events to the live search. */
128 bool eventFilter(QObject *obj, QEvent *ev);
130 /** @brief Saves the file and the window properties when saving the session. */
131 virtual void saveProperties(KConfigGroup &config);
133 /** @brief Restores the window and the file when a session is loaded. */
134 virtual void readProperties(const KConfigGroup &config);
137 KTabWidget* m_timelineArea;
138 QProgressBar *m_statusProgressBar;
140 /** @brief Sets up all the actions and attaches them to the collection. */
142 KdenliveDoc *m_activeDocument;
143 TrackView *m_activeTimeline;
144 MonitorManager *m_monitorManager;
146 QDockWidget *m_projectListDock;
147 ProjectList *m_projectList;
149 QDockWidget *m_effectListDock;
150 EffectsListView *m_effectList;
151 //KListWidget *m_effectList;
153 QDockWidget *m_notesDock;
154 NotesWidget *m_notesWidget;
156 QDockWidget *m_effectStackDock;
157 EffectStackView *m_effectStack;
159 QDockWidget *m_transitionConfigDock;
160 TransitionSettings *m_transitionConfig;
162 QDockWidget *m_clipMonitorDock;
163 Monitor *m_clipMonitor;
165 QDockWidget *m_projectMonitorDock;
166 Monitor *m_projectMonitor;
168 QDockWidget *m_recMonitorDock;
169 RecMonitor *m_recMonitor;
171 QDockWidget *m_vectorscopeDock;
172 Vectorscope *m_vectorscope;
174 QDockWidget *m_waveformDock;
175 Waveform *m_waveform;
177 QDockWidget *m_RGBParadeDock;
178 RGBParade *m_RGBParade;
180 QDockWidget *m_histogramDock;
181 Histogram *m_histogram;
183 QDockWidget *m_audiosignalDock;
184 AudioSignal *m_audiosignal;
186 QDockWidget *m_audioSpectrumDock;
187 AudioSpectrum *m_audioSpectrum;
189 QDockWidget *m_spectrogramDock;
190 Spectrogram *m_spectrogram;
192 QDockWidget *m_undoViewDock;
193 QUndoView *m_undoView;
194 QUndoGroup *m_commandStack;
196 KComboBox *m_timecodeFormat;
198 /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
199 QList <QDockWidget *> m_gfxScopesList;
200 QList <AbstractAudioScopeWidget *> m_audioScopesList;
202 KActionCategory *m_effectActions;
203 QMenu *m_effectsMenu;
204 QMenu *m_transitionsMenu;
205 QMenu *m_timelineContextMenu;
206 QMenu *m_timelineContextClipMenu;
207 QMenu *m_timelineContextTransitionMenu;
210 /** Actions used in the stopmotion widget */
211 KActionCategory *m_stopmotion_actions;
213 /** Action names that can be used in the slotDoAction() slot, with their i18n() names */
214 QStringList m_action_names;
217 /** @brief Shortcut to remove the focus from any element.
219 * It allows to get out of e.g. text input fields and to press another
221 QShortcut* m_shortcutRemoveFocus;
223 RenderWidget *m_renderWidget;
225 #ifndef NO_JOGSHUTTLE
226 JogShuttle *m_jogProcess;
227 JogShuttleAction* m_jogShuttle;
228 #endif /* NO_JOGSHUTTLE */
230 KRecentFilesAction *m_fileOpenRecent;
231 KAction *m_fileRevert;
232 KAction *m_projectSearch;
233 KAction *m_projectSearchNext;
235 KAction **m_videoEffects;
236 KAction **m_audioEffects;
237 KAction **m_customEffects;
238 KAction **m_transitions;
239 KAction *m_buttonAudioThumbs;
240 KAction *m_buttonVideoThumbs;
241 KAction *m_buttonShowMarkers;
242 KAction *m_buttonFitZoom;
243 KAction *m_buttonAutomaticSplitAudio;
244 KAction *m_normalEditTool;
245 KAction *m_overwriteEditTool;
246 KAction *m_insertEditTool;
247 KAction *m_buttonSelectTool;
248 KAction *m_buttonRazorTool;
249 KAction *m_buttonSpacerTool;
250 KAction *m_buttonSnap;
251 KAction *m_saveAction;
252 KAction *m_closeAction;
253 QSlider *m_zoomSlider;
259 KSelectAction *m_loadLayout;
260 StatusBarMessageLabel *m_messageLabel;
261 QActionGroup *m_clipTypeGroup;
262 KActionCollection *m_effectsActionCollection;
264 bool m_findActivated;
265 QString m_findString;
270 #ifndef NO_JOGSHUTTLE
271 void activateShuttleDevice();
272 #endif /* NO_JOGSHUTTLE */
273 void connectDocumentInfo(KdenliveDoc *doc);
275 void doOpenFile(const KUrl &url, KAutoSaveFile *stale);
276 void recoverFiles(QList<KAutoSaveFile *> staleFiles);
278 /** @brief Loads static and dynamic plugins.
280 * It scans static plugins as well as the filesystem: it doesn't load more
281 * than one plugin per file name, to avoid duplication due to conflicting
284 void populateMenus(QObject *plugin);
285 void addToMenu(QObject *plugin, const QStringList &texts,
286 QMenu *menu, const char *member,
287 QActionGroup *actionGroup);
290 /** @brief Instantiates a "Get Hot New Stuff" dialog.
291 * @param configFile configuration file for KNewStuff
292 * @return number of installed items */
293 int getNewStuff(const QString &configFile = QString());
294 QStringList m_pluginFileNames;
295 QByteArray m_timelineState;
296 void loadTranscoders();
297 QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config);
299 /** @brief Checks that the Kdenlive mime type is correctly installed.
300 * @param open If set to true, this will return the mimetype allowed for file opening (adds .tar.gz format)
301 * @return The mimetype */
302 QString getMimeType(bool open = true);
304 /** @brief Populates the "load layout" menu. */
307 StopmotionWidget *m_stopmotion;
310 /** @brief Prepares opening @param url.
312 * Checks if already open and whether backup exists */
313 void openFile(const KUrl &url);
314 void slotGotProgressInfo(const QString &message, int progress);
315 void slotReloadEffects();
316 Q_SCRIPTABLE void setRenderingProgress(const QString &url, int progress);
317 Q_SCRIPTABLE void setRenderingFinished(const QString &url, int status, const QString &error);
321 void newFile(bool showProjectSettings = true, bool force = false);
322 void activateDocument();
323 void connectDocument(TrackView*, KdenliveDoc*);
325 /** @brief Shows file open dialog. */
329 /** @brief Checks whether a URL is available to save to.
330 * @return Whether the file was saved. */
333 /** @brief Shows a save file dialog for saving the project.
334 * @return Whether the file was saved. */
337 /** @brief Set properties to match outputFileName and save the document.
338 * @param outputFileName The URL to save to / The document's URL.
339 * @return Whether we had success. */
340 bool saveFileAs(const QString &outputFileName);
342 /** @brief Shows the shortcut dialog. */
344 void slotPreferences(int page = -1, int option = -1);
346 /** @brief Reflects setting changes to the GUI. */
347 void updateConfiguration();
348 void slotConnectMonitors();
349 void slotRaiseMonitor(AbstractMonitor *monitor);
350 void slotUpdateClip(const QString &id);
351 void slotUpdateMousePosition(int pos);
352 void slotAddEffect(const QDomElement effect);
353 void slotEditProfiles();
354 void slotDetectAudioDriver();
355 void slotEditProjectSettings();
356 /** @brief Change current document MLT profile. */
357 void slotUpdateProjectProfile(const QString &profile);
358 void slotDisplayActionMessage(QAction *a);
360 /** @brief Turns automatic splitting of audio and video on/off. */
361 void slotSwitchSplitAudio();
362 void slotSwitchVideoThumbs();
363 void slotSwitchAudioThumbs();
364 void slotSwitchMarkersComments();
365 void slotSwitchSnap();
366 void slotRenderProject();
367 void slotFullScreen();
368 void slotUpdateDocumentState(bool modified);
370 /** @brief Sets the timeline zoom slider to @param value.
372 * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
373 void slotSetZoom(int value);
374 /** @brief Decreases the timeline zoom level by 1. */
376 /** @brief Increases the timeline zoom level by 1. */
378 /** @brief Makes the timeline zoom level fit the timeline content. */
380 /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
381 void slotUpdateZoomSliderToolTip(int zoomlevel);
383 /** @brief Displays the zoom slider tooltip.
384 * @param zoomlevel (optional) The zoom level to show in the tooltip.
386 * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
387 void slotShowZoomSliderToolTip(int zoomlevel = -1);
388 /** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
389 bool closeCurrentDocument(bool saveChanges = true);
390 /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
391 void slotDeleteItem();
392 void slotAddClipMarker();
393 void slotDeleteClipMarker();
394 void slotDeleteAllClipMarkers();
395 void slotEditClipMarker();
397 /** @brief Adds marker or auide at the current position without showing the marker dialog.
399 * Adds a marker if clip monitor is active, otherwise a guide.
400 * The comment is set to the current position (therefore not dialog).
401 * This can be useful to mark something during playback. */
402 void slotAddMarkerGuideQuickly();
403 void slotCutTimelineClip();
404 void slotInsertClipOverwrite();
405 void slotSelectTimelineClip();
406 void slotSelectTimelineTransition();
407 void slotDeselectTimelineClip();
408 void slotDeselectTimelineTransition();
409 void slotSelectAddTimelineClip();
410 void slotSelectAddTimelineTransition();
411 void slotAddVideoEffect(QAction *result);
412 void slotAddTransition(QAction *result);
413 void slotAddProjectClip(KUrl url);
414 void slotShowClipProperties(DocClipBase *clip);
415 void slotShowClipProperties(QList <DocClipBase *>cliplist, QMap<QString, QString> commonproperties);
416 void slotActivateEffectStackView(ClipItem* item = NULL, int ix = -1, bool raise = true);
417 void slotActivateTransitionView(Transition *);
418 void slotChangeTool(QAction * action);
419 void slotChangeEdit(QAction * action);
420 void slotSetTool(PROJECTTOOL tool);
421 void slotSnapForward();
422 void slotSnapRewind();
423 void slotClipStart();
425 void slotZoneStart();
430 void slotSelectClipInTimeline();
431 void slotClipInTimeline(const QString &clipId);
433 void slotInsertSpace();
434 void slotRemoveSpace();
436 void slotEditGuide();
437 void slotDeleteGuide();
438 void slotDeleteAllGuides();
439 void slotGuidesUpdated();
443 void slotPasteEffects();
445 void slotAdjustClipMonitor();
446 void slotAdjustProjectMonitor();
447 void slotSaveZone(Render *render, QPoint zone);
449 void slotSetInPoint();
450 void slotSetOutPoint();
451 void slotResizeItemStart();
452 void slotResizeItemEnd();
453 void configureNotifications();
454 void slotInsertTrack(int ix = 0);
455 void slotDeleteTrack(int ix = 0);
456 /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
457 void slotConfigTrack(int ix = -1);
458 void slotGetNewLumaStuff();
459 void slotGetNewTitleStuff();
460 void slotGetNewRenderStuff();
461 void slotGetNewMltProfileStuff();
462 void slotAutoTransition();
463 void slotRunWizard();
464 /** @brief Lets the sampleplugin create a generator. */
466 void slotZoneMoved(int start, int end);
467 void slotDvdWizard(const QString &url = QString(), const QString &profile = "dv_pal");
468 void slotGroupClips();
469 void slotUnGroupClips();
470 void slotEditItemDuration();
471 void slotClipInProjectTree();
472 //void slotClipToProjectTree();
473 void slotSplitAudio();
474 void slotUpdateClipType(QAction *action);
475 void slotShowTimeline(bool show);
476 void slotMaximizeCurrent(bool show);
477 void slotTranscode(KUrl::List urls = KUrl::List());
478 void slotTranscodeClip();
479 /** @brief Archive project: creates a copy of the project file with all clips in a new folder. */
480 void slotArchiveProject();
481 void slotSetDocumentRenderProfile(QMap <QString, QString> props);
482 void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
484 /** @brief Switches between displaying frames or timecode.
485 * @param ix 0 = display timecode, 1 = display frames. */
486 void slotUpdateTimecodeFormat(int ix);
488 /** @brief Removes the focus of anything. */
489 void slotRemoveFocus();
490 void slotCleanProject();
491 void slotUpdateClipMarkers(DocClipBase *clip);
494 void slotUpdateTrackInfo();
496 /** @brief Changes the color scheme. */
497 void slotChangePalette(QAction *action, const QString &themename = QString());
498 void slotSwitchMonitors();
499 void slotCheckRenderStatus();
500 void slotInsertZoneToTree();
501 void slotInsertZoneToTimeline();
503 /** @brief Deletes items from timeline and document.
504 * @param ids The ids of the clips to delete.
505 * @param folderids The names and ids of the folders to delete. */
506 void slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids);
507 void slotShowTitleBars(bool show);
508 void slotSwitchTitles();
509 /** @brief Update the capture folder if user asked a change. */
510 void slotUpdateCaptureFolder();
512 /** @brief Apply new properties to a clip */
513 void slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload);
515 /** @brief Delete a clip from current project */
516 void slotDeleteClip(const QString &id);
518 /** @brief Saves the widgets layout */
519 void slotSaveLayout(QAction*);
520 void slotLoadLayout(QAction*);
522 /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
523 void slotMonitorRequestRenderFrame(bool request);
524 /** @brief Check if someone needs the render frame sent. */
525 void slotUpdateGfxScopeFrameRequest();
526 /** @brief Check if someone needs the render frame sent. */
527 void slotDoUpdateGfxScopeFrameRequest();
528 void slotUpdateAudioScopeFrameRequest();
529 void slotDoUpdateAudioScopeFrameRequest();
530 /** @brief When switching between monitors, update the visible scopes. */
531 void slotUpdateColorScopes();
532 /** @brief Active monitor deleted, clear scopes. */
533 void slotClearColorScopes();
534 /** @brief Switch current monitor to fullscreen. */
535 void slotSwitchFullscreen();
536 /** @brief Open the stopmotion dialog. */
537 void slotOpenStopmotion();
538 /** @brief Implements all the actions that are int he ActionsCollection. */
539 void slotDoAction(const QString& action_name);
540 /** @brief Update project because the use of proxy clips was enabled / disabled. */
541 void slotUpdateProxySettings();
542 /** @brief Insert current project's timecode into the notes widget. */
543 void slotInsertNotesTimecode();
544 /** @brief Open the project's backupdialog. */
545 void slotOpenBackupDialog(const KUrl url = KUrl());
548 Q_SCRIPTABLE void abortRenderJob(const QString &url);