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