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>
35 #include <KXmlGuiWindow>
37 #include <KListWidget>
40 #include <KRecentFilesAction>
42 #include <kautosavefile.h>
43 #include <KActionCategory>
45 #include "effectslist.h"
47 #include "definitions.h"
48 #include "statusbarmessagelabel.h"
49 #include "dvdwizard.h"
50 #include "stopmotion/stopmotion.h"
51 #include "noteswidget.h"
52 #include "ui_backupdialog_ui.h"
58 class EffectsListView;
59 class EffectStackView;
60 class EffectStackView2;
61 class TransitionSettings;
64 class CustomTrackView;
68 class JogShuttleAction;
78 class KActionCollection;
80 class AbstractAudioScopeWidget;
84 class MainWindow : public KXmlGuiWindow
87 Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
91 /** @brief Initialises the main window.
92 * @param MltPath (optional) path to MLT environment
93 * @param Url (optional) file to open
94 * @param clipsToLoad (optional) a comma separated list of clips to import in project
96 * If Url is present, it will be opened, otherwhise, if openlastproject is
97 * set, latest project will be opened. If no file is open after trying this,
98 * a default new file will be created. */
99 explicit MainWindow(const QString &MltPath = QString(),
100 const KUrl &Url = KUrl(), const QString & clipsToLoad = QString(), QWidget *parent = 0);
101 virtual ~MainWindow();
103 /** @brief Locates the MLT environment.
104 * @param mltPath (optional) path to MLT environment
106 * It tries to set the paths of the MLT profiles and renderer, using
107 * mltPath, MLT_PREFIX, searching for the binary `melt`, or asking to the
108 * user. It doesn't fill any list of profiles, while its name suggests so. */
109 void parseProfiles(const QString &mltPath = QString());
111 static EffectsList videoEffects;
112 static EffectsList audioEffects;
113 static EffectsList customEffects;
114 static EffectsList transitions;
116 /** @brief Cache for luma files thumbnails. */
117 static QMap <QString,QImage> m_lumacache;
121 /** @brief Closes the window.
122 * @return false if the user presses "Cancel" on a confirmation dialog or
123 * the operation requested (starting waiting jobs or saving file) fails,
125 virtual bool queryClose();
127 /** @brief Reports a message in the status bar when an error occurs. */
128 virtual void customEvent(QEvent *e);
130 /** @brief Enables live search in the timeline. */
131 virtual void keyPressEvent(QKeyEvent *ke);
133 /** @brief Stops the active monitor when the window gets hidden. */
134 virtual void hideEvent(QHideEvent *e);
136 /** @brief Filters key events to the live search. */
137 bool eventFilter(QObject *obj, QEvent *ev);
139 /** @brief Saves the file and the window properties when saving the session. */
140 virtual void saveProperties(KConfigGroup &config);
142 /** @brief Restores the window and the file when a session is loaded. */
143 virtual void readProperties(const KConfigGroup &config);
146 KTabWidget* m_timelineArea;
147 QProgressBar *m_statusProgressBar;
149 ScopeManager *m_scopeManager;
151 /** @brief Sets up all the actions and attaches them to the collection. */
153 KdenliveDoc *m_activeDocument;
154 TrackView *m_activeTimeline;
155 MonitorManager *m_monitorManager;
157 QDockWidget *m_projectListDock;
158 ProjectList *m_projectList;
160 QDockWidget *m_effectListDock;
161 EffectsListView *m_effectList;
162 //KListWidget *m_effectList;
164 QDockWidget *m_notesDock;
165 NotesWidget *m_notesWidget;
167 QDockWidget *m_effectStackDock;
168 EffectStackView2 *m_effectStack;
170 QDockWidget *m_transitionConfigDock;
171 TransitionSettings *m_transitionConfig;
173 QDockWidget *m_clipMonitorDock;
174 Monitor *m_clipMonitor;
176 QDockWidget *m_projectMonitorDock;
177 Monitor *m_projectMonitor;
179 QDockWidget *m_recMonitorDock;
180 RecMonitor *m_recMonitor;
182 QDockWidget *m_vectorscopeDock;
183 Vectorscope *m_vectorscope;
185 QDockWidget *m_waveformDock;
186 Waveform *m_waveform;
188 QDockWidget *m_RGBParadeDock;
189 RGBParade *m_RGBParade;
191 QDockWidget *m_histogramDock;
192 Histogram *m_histogram;
194 QDockWidget *m_audiosignalDock;
195 AudioSignal *m_audiosignal;
197 QDockWidget *m_audioSpectrumDock;
198 AudioSpectrum *m_audioSpectrum;
200 QDockWidget *m_spectrogramDock;
201 Spectrogram *m_spectrogram;
203 QDockWidget *m_undoViewDock;
204 QUndoView *m_undoView;
205 QUndoGroup *m_commandStack;
207 KSelectAction *m_timeFormatButton;
209 /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
210 QList <QDockWidget *> m_gfxScopesList;
212 KActionCategory *m_effectActions;
213 QMenu *m_effectsMenu;
214 QMenu *m_transitionsMenu;
215 QMenu *m_timelineContextMenu;
216 QMenu *m_timelineContextClipMenu;
217 QMenu *m_timelineContextTransitionMenu;
220 /** Actions used in the stopmotion widget */
221 KActionCategory *m_stopmotion_actions;
223 /** Action names that can be used in the slotDoAction() slot, with their i18n() names */
224 QStringList m_action_names;
227 /** @brief Shortcut to remove the focus from any element.
229 * It allows to get out of e.g. text input fields and to press another
231 QShortcut* m_shortcutRemoveFocus;
233 RenderWidget *m_renderWidget;
235 #ifdef USE_JOGSHUTTLE
236 JogShuttle *m_jogProcess;
237 JogShuttleAction* m_jogShuttle;
240 KRecentFilesAction *m_fileOpenRecent;
241 KAction *m_fileRevert;
242 KAction *m_projectSearch;
243 KAction *m_projectSearchNext;
245 KAction **m_videoEffects;
246 KAction **m_audioEffects;
247 KAction **m_customEffects;
248 KAction **m_transitions;
249 KAction *m_buttonAudioThumbs;
250 KAction *m_buttonVideoThumbs;
251 KAction *m_buttonShowMarkers;
252 KAction *m_buttonFitZoom;
253 KAction *m_buttonAutomaticSplitAudio;
254 KAction *m_normalEditTool;
255 KAction *m_overwriteEditTool;
256 KAction *m_insertEditTool;
257 KAction *m_buttonSelectTool;
258 KAction *m_buttonRazorTool;
259 KAction *m_buttonSpacerTool;
260 KAction *m_buttonSnap;
261 KAction *m_saveAction;
262 KAction *m_closeAction;
263 QSlider *m_zoomSlider;
269 KSelectAction *m_loadLayout;
270 StatusBarMessageLabel *m_messageLabel;
271 QActionGroup *m_clipTypeGroup;
272 KActionCollection *m_effectsActionCollection;
273 KActionCollection *m_tracksActionCollection;
275 bool m_findActivated;
276 QString m_findString;
281 #ifdef USE_JOGSHUTTLE
282 void activateShuttleDevice();
284 void connectDocumentInfo(KdenliveDoc *doc);
286 void doOpenFile(const KUrl &url, KAutoSaveFile *stale);
287 void recoverFiles(QList<KAutoSaveFile *> staleFiles, const KUrl &originUrl);
289 /** @brief Loads static and dynamic plugins.
291 * It scans static plugins as well as the filesystem: it doesn't load more
292 * than one plugin per file name, to avoid duplication due to conflicting
295 void populateMenus(QObject *plugin);
296 void addToMenu(QObject *plugin, const QStringList &texts,
297 QMenu *menu, const char *member,
298 QActionGroup *actionGroup);
301 /** @brief Instantiates a "Get Hot New Stuff" dialog.
302 * @param configFile configuration file for KNewStuff
303 * @return number of installed items */
304 int getNewStuff(const QString &configFile = QString());
305 QStringList m_pluginFileNames;
306 QByteArray m_timelineState;
307 void loadTranscoders();
308 void loadClipActions();
309 QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config);
311 /** @brief Checks that the Kdenlive mime type is correctly installed.
312 * @param open If set to true, this will return the mimetype allowed for file opening (adds .tar.gz format)
313 * @return The mimetype */
314 QString getMimeType(bool open = true);
316 /** @brief Populates the "load layout" menu. */
319 StopmotionWidget *m_stopmotion;
321 /** @brief The last selected clip in timeline. */
322 ClipItem *m_mainClip;
323 /** @brief Update statusbar stylesheet (in case of color theme change). */
324 void setStatusBarStyleSheet(const QPalette &p);
327 /** @brief Prepares opening @param url.
329 * Checks if already open and whether backup exists */
330 void openFile(const KUrl &url);
331 void slotGotProgressInfo(const QString &message, int progress, MessageType type = DefaultMessage);
332 void slotReloadEffects();
333 Q_SCRIPTABLE void setRenderingProgress(const QString &url, int progress);
334 Q_SCRIPTABLE void setRenderingFinished(const QString &url, int status, const QString &error);
338 void newFile(bool showProjectSettings = true, bool force = false);
339 void activateDocument();
340 void connectDocument(TrackView*, KdenliveDoc*);
342 /** @brief Shows file open dialog. */
346 /** @brief Checks whether a URL is available to save to.
347 * @return Whether the file was saved. */
350 /** @brief Shows a save file dialog for saving the project.
351 * @return Whether the file was saved. */
354 /** @brief Set properties to match outputFileName and save the document.
355 * @param outputFileName The URL to save to / The document's URL.
356 * @return Whether we had success. */
357 bool saveFileAs(const QString &outputFileName);
359 /** @brief Shows the shortcut dialog. */
361 void slotPreferences(int page = -1, int option = -1);
363 /** @brief Reflects setting changes to the GUI. */
364 void updateConfiguration();
365 void slotConnectMonitors();
366 void slotUpdateClip(const QString &id);
367 void slotUpdateMousePosition(int pos);
368 void slotUpdateProjectDuration(int pos);
369 void slotAddEffect(const QDomElement effect);
370 void slotEditProfiles();
371 void slotDetectAudioDriver();
372 void slotEditProjectSettings();
373 /** @brief Change current document MLT profile. */
374 void slotUpdateProjectProfile(const QString &profile);
375 void slotDisplayActionMessage(QAction *a);
377 /** @brief Turns automatic splitting of audio and video on/off. */
378 void slotSwitchSplitAudio();
379 void slotSwitchVideoThumbs();
380 void slotSwitchAudioThumbs();
381 void slotSwitchMarkersComments();
382 void slotSwitchSnap();
383 void slotRenderProject();
384 void slotFullScreen();
385 void slotUpdateDocumentState(bool modified);
387 /** @brief Sets the timeline zoom slider to @param value.
389 * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
390 void slotSetZoom(int value);
391 /** @brief Decreases the timeline zoom level by 1. */
393 /** @brief Increases the timeline zoom level by 1. */
395 /** @brief Makes the timeline zoom level fit the timeline content. */
397 /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
398 void slotUpdateZoomSliderToolTip(int zoomlevel);
400 /** @brief Displays the zoom slider tooltip.
401 * @param zoomlevel (optional) The zoom level to show in the tooltip.
403 * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
404 void slotShowZoomSliderToolTip(int zoomlevel = -1);
405 /** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
406 bool closeCurrentDocument(bool saveChanges = true);
407 /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
408 void slotDeleteItem();
409 void slotAddClipMarker();
410 void slotDeleteClipMarker();
411 void slotDeleteAllClipMarkers();
412 void slotEditClipMarker();
414 /** @brief Adds marker or auide at the current position without showing the marker dialog.
416 * Adds a marker if clip monitor is active, otherwise a guide.
417 * The comment is set to the current position (therefore not dialog).
418 * This can be useful to mark something during playback. */
419 void slotAddMarkerGuideQuickly();
420 void slotCutTimelineClip();
421 void slotInsertClipOverwrite();
422 void slotSelectTimelineClip();
423 void slotSelectTimelineTransition();
424 void slotDeselectTimelineClip();
425 void slotDeselectTimelineTransition();
426 void slotSelectAddTimelineClip();
427 void slotSelectAddTimelineTransition();
428 void slotAddVideoEffect(QAction *result);
429 void slotAddTransition(QAction *result);
430 void slotAddProjectClip(KUrl url, stringMap data = stringMap());
431 void slotAddProjectClipList(KUrl::List urls);
432 void slotShowClipProperties(DocClipBase *clip);
433 void slotShowClipProperties(QList <DocClipBase *>cliplist, QMap<QString, QString> commonproperties);
434 void slotTimelineClipSelected(ClipItem* item, bool raise = true);
435 void slotTrackSelected(int index, TrackInfo info, bool raise = true);
436 void slotActivateTransitionView(Transition *);
437 void slotChangeTool(QAction * action);
438 void slotChangeEdit(QAction * action);
439 void slotSetTool(PROJECTTOOL tool);
440 void slotSnapForward();
441 void slotSnapRewind();
442 void slotClipStart();
444 void slotZoneStart();
449 void slotSelectClipInTimeline();
450 void slotClipInTimeline(const QString &clipId);
452 void slotInsertSpace();
453 void slotRemoveSpace();
455 void slotEditGuide();
456 void slotDeleteGuide();
457 void slotDeleteAllGuides();
458 void slotGuidesUpdated();
462 void slotPasteEffects();
464 void slotAdjustClipMonitor();
465 void slotAdjustProjectMonitor();
466 void slotSaveZone(Render *render, QPoint zone, DocClipBase *baseClip = NULL, KUrl path = KUrl());
468 void slotSetInPoint();
469 void slotSetOutPoint();
470 void slotResizeItemStart();
471 void slotResizeItemEnd();
472 void configureNotifications();
473 void slotInsertTrack(int ix = -1);
474 void slotDeleteTrack(int ix = -1);
475 /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
476 void slotConfigTrack(int ix = -1);
477 /** @brief Select all clips in active track. */
478 void slotSelectTrack();
479 /** @brief Select all clips in timeline. */
480 void slotSelectAllTracks();
481 void slotGetNewLumaStuff();
482 void slotGetNewTitleStuff();
483 void slotGetNewRenderStuff();
484 void slotGetNewMltProfileStuff();
485 void slotAutoTransition();
486 void slotRunWizard();
487 /** @brief Lets the sampleplugin create a generator. */
489 void slotZoneMoved(int start, int end);
490 void slotDvdWizard(const QString &url = QString());
491 void slotGroupClips();
492 void slotUnGroupClips();
493 void slotEditItemDuration();
494 void slotClipInProjectTree();
495 //void slotClipToProjectTree();
496 void slotSplitAudio();
497 void slotSetAudioAlignReference();
498 void slotAlignAudio();
499 void slotUpdateClipType(QAction *action);
500 void slotShowTimeline(bool show);
501 void slotMaximizeCurrent(bool show);
502 void slotTranscode(KUrl::List urls = KUrl::List());
503 void slotStartClipAction();
504 void slotTranscodeClip();
505 /** @brief Archive project: creates a copy of the project file with all clips in a new folder. */
506 void slotArchiveProject();
507 void slotSetDocumentRenderProfile(QMap <QString, QString> props);
508 void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
510 /** @brief Switches between displaying frames or timecode.
511 * @param ix 0 = display timecode, 1 = display frames. */
512 void slotUpdateTimecodeFormat(int ix);
514 /** @brief Removes the focus of anything. */
515 void slotRemoveFocus();
516 void slotCleanProject();
517 void slotUpdateClipMarkers(DocClipBase *clip);
520 void slotUpdateTrackInfo();
522 /** @brief Changes the color scheme. */
523 void slotChangePalette(QAction *action, const QString &themename = QString());
524 void slotSwitchMonitors();
525 void slotCheckRenderStatus();
526 void slotInsertZoneToTree();
527 void slotInsertZoneToTimeline();
529 /** @brief Deletes items from timeline and document.
530 * @param ids The ids of the clips to delete.
531 * @param folderids The names and ids of the folders to delete. */
532 void slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids);
533 void slotShowTitleBars(bool show);
534 void slotSwitchTitles();
535 /** @brief Update the capture folder if user asked a change. */
536 void slotUpdateCaptureFolder();
538 /** @brief Apply new properties to a clip */
539 void slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload);
541 /** @brief Delete a clip from current project */
542 void slotDeleteClip(const QString &id);
544 /** @brief Saves the widgets layout */
545 void slotSaveLayout(QAction*);
546 void slotLoadLayout(QAction*);
548 /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
549 void slotMonitorRequestRenderFrame(bool request);
550 /** @brief Open the stopmotion dialog. */
551 void slotOpenStopmotion();
552 /** @brief Implements all the actions that are int he ActionsCollection. */
553 void slotDoAction(const QString& action_name);
554 /** @brief Update project because the use of proxy clips was enabled / disabled. */
555 void slotUpdateProxySettings();
556 /** @brief Insert current project's timecode into the notes widget. */
557 void slotInsertNotesTimecode();
558 /** @brief Open the project's backupdialog. */
559 void slotOpenBackupDialog(const KUrl url = KUrl());
560 /** @brief Disable proxies for this project. */
561 void slotDisableProxies();
563 void slotElapsedTime();
564 /** @brief Open the online services search dialog. */
565 void slotDownloadResources();
567 void slotChangePalette();
568 /** @brief Save current timeline clip as mlt playlist. */
569 void slotSaveTimelineClip();
570 /** @brief Process keyframe data sent from a clip to effect / transition stack. */
571 void slotProcessImportKeyframes(GRAPHICSRECTITEM type, const QString& data, int maximum);
572 /** @brief Move playhead to mouse curser position if defined key is pressed */
573 void slotAlignPlayheadToMousePos();
574 /** @brief Set MLT's consumer deinterlace method */
575 void slotSetDeinterlacer(int ix);
576 /** @brief Set MLT's consumer interpolation method */
577 void slotSetInterpolation(int ix);
580 Q_SCRIPTABLE void abortRenderJob(const QString &url);