]> git.sesse.net Git - kdenlive/blob - src/mainwindow.h
Merge branch 'audioAlign'
[kdenlive] / src / mainwindow.h
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 #ifndef MAINWINDOW_H
22 #define MAINWINDOW_H
23
24 #include <QDockWidget>
25 #include <QUndoView>
26 #include <QLabel>
27 #include <QProgressBar>
28 #include <QEvent>
29 #include <QTimer>
30 #include <QShortcut>
31 #include <QMap>
32 #include <QString>
33 #include <QImage>
34
35 #include <KXmlGuiWindow>
36 #include <KTextEdit>
37 #include <KListWidget>
38 #include <KTabWidget>
39 #include <KUndoStack>
40 #include <KRecentFilesAction>
41 #include <KComboBox>
42 #include <kautosavefile.h>
43 #include <KActionCategory>
44 #include <KImageCache>
45
46 #include "effectslist.h"
47 #include "gentime.h"
48 #include "definitions.h"
49 #include "statusbarmessagelabel.h"
50 #include "dvdwizard.h"
51 #include "stopmotion/stopmotion.h"
52 #include "noteswidget.h"
53 #include "ui_backupdialog_ui.h"
54
55 class KdenliveDoc;
56 class TrackView;
57 class MonitorManager;
58 class ProjectList;
59 class EffectsListView;
60 class EffectStackView;
61 class EffectStackView2;
62 class TransitionSettings;
63 class Monitor;
64 class RecMonitor;
65 class CustomTrackView;
66 class RenderWidget;
67 #ifdef USE_JOGSHUTTLE
68 class JogShuttle;
69 class JogShuttleAction;
70 #endif
71 class DocClipBase;
72 class Render;
73 class Transition;
74 class ScopeManager;
75 class Histogram;
76 class Vectorscope;
77 class Waveform;
78 class RGBParade;
79 class KActionCollection;
80 class AudioSignal;
81 class AbstractAudioScopeWidget;
82 class AudioSpectrum;
83 class Spectrogram;
84
85 class MainWindow : public KXmlGuiWindow
86 {
87     Q_OBJECT
88     Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
89
90 public:
91
92     /** @brief Initialises the main window.
93      * @param MltPath (optional) path to MLT environment
94      * @param Url (optional) file to open
95      * @param clipsToLoad (optional) a comma separated list of clips to import in project
96      *
97      * If Url is present, it will be opened, otherwhise, if openlastproject is
98      * set, latest project will be opened. If no file is open after trying this,
99      * a default new file will be created. */
100     explicit MainWindow(const QString &MltPath = QString(),
101                         const KUrl &Url = KUrl(), const QString & clipsToLoad = QString(), QWidget *parent = 0);
102     virtual ~MainWindow();
103
104     /** @brief Locates the MLT environment.
105      * @param mltPath (optional) path to MLT environment
106      *
107      * It tries to set the paths of the MLT profiles and renderer, using
108      * mltPath, MLT_PREFIX, searching for the binary `melt`, or asking to the
109      * user. It doesn't fill any list of profiles, while its name suggests so. */
110     void parseProfiles(const QString &mltPath = QString());
111
112     static EffectsList videoEffects;
113     static EffectsList audioEffects;
114     static EffectsList customEffects;
115     static EffectsList transitions;
116     
117     /** @brief Cache for luma files thumbnails. */
118     static QMap <QString,QImage> m_lumacache;
119
120 protected:
121
122     /** @brief Closes the window.
123      * @return false if the user presses "Cancel" on a confirmation dialog or
124      *     the operation requested (starting waiting jobs or saving file) fails,
125      *     true otherwise */
126     virtual bool queryClose();
127
128     /** @brief Reports a message in the status bar when an error occurs. */
129     virtual void customEvent(QEvent *e);
130
131     /** @brief Enables live search in the timeline. */
132     virtual void keyPressEvent(QKeyEvent *ke);
133
134     /** @brief Stops the active monitor when the window gets hidden. */
135     virtual void hideEvent(QHideEvent *e);
136
137     /** @brief Filters key events to the live search. */
138     bool eventFilter(QObject *obj, QEvent *ev);
139
140     /** @brief Saves the file and the window properties when saving the session. */
141     virtual void saveProperties(KConfigGroup &config);
142
143     /** @brief Restores the window and the file when a session is loaded. */
144     virtual void readProperties(const KConfigGroup &config);
145
146 private:
147     KTabWidget* m_timelineArea;
148     QProgressBar *m_statusProgressBar;
149
150     ScopeManager *m_scopeManager;
151
152     /** @brief Sets up all the actions and attaches them to the collection. */
153     void setupActions();
154     KdenliveDoc *m_activeDocument;
155     TrackView *m_activeTimeline;
156     MonitorManager *m_monitorManager;
157
158     QDockWidget *m_projectListDock;
159     ProjectList *m_projectList;
160
161     QDockWidget *m_effectListDock;
162     EffectsListView *m_effectList;
163     //KListWidget *m_effectList;
164
165     QDockWidget *m_notesDock;
166     NotesWidget *m_notesWidget;
167
168     QDockWidget *m_effectStackDock;
169     EffectStackView2 *m_effectStack;
170
171     QDockWidget *m_transitionConfigDock;
172     TransitionSettings *m_transitionConfig;
173
174     QDockWidget *m_clipMonitorDock;
175     Monitor *m_clipMonitor;
176
177     QDockWidget *m_projectMonitorDock;
178     Monitor *m_projectMonitor;
179
180     QDockWidget *m_recMonitorDock;
181     RecMonitor *m_recMonitor;
182
183     QDockWidget *m_vectorscopeDock;
184     Vectorscope *m_vectorscope;
185
186     QDockWidget *m_waveformDock;
187     Waveform *m_waveform;
188
189     QDockWidget *m_RGBParadeDock;
190     RGBParade *m_RGBParade;
191
192     QDockWidget *m_histogramDock;
193     Histogram *m_histogram;
194
195     QDockWidget *m_audiosignalDock;
196     AudioSignal *m_audiosignal;
197
198     QDockWidget *m_audioSpectrumDock;
199     AudioSpectrum *m_audioSpectrum;
200
201     QDockWidget *m_spectrogramDock;
202     Spectrogram *m_spectrogram;
203
204     QDockWidget *m_undoViewDock;
205     QUndoView *m_undoView;
206     QUndoGroup *m_commandStack;
207
208     KComboBox *m_timecodeFormat;
209
210     /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
211     QList <QDockWidget *> m_gfxScopesList;
212
213     KActionCategory *m_effectActions;
214     QMenu *m_effectsMenu;
215     QMenu *m_transitionsMenu;
216     QMenu *m_timelineContextMenu;
217     QMenu *m_timelineContextClipMenu;
218     QMenu *m_timelineContextTransitionMenu;
219     KUrl m_startUrl;
220
221     /** Actions used in the stopmotion widget */
222     KActionCategory *m_stopmotion_actions;
223
224     /** Action names that can be used in the slotDoAction() slot, with their i18n() names */
225     QStringList m_action_names;
226
227
228     /** @brief Shortcut to remove the focus from any element.
229      *
230      * It allows to get out of e.g. text input fields and to press another
231      * shortcut. */
232     QShortcut* m_shortcutRemoveFocus;
233
234     RenderWidget *m_renderWidget;
235
236 #ifdef USE_JOGSHUTTLE
237     JogShuttle *m_jogProcess;
238     JogShuttleAction* m_jogShuttle;
239 #endif
240
241     KRecentFilesAction *m_fileOpenRecent;
242     KAction *m_fileRevert;
243     KAction *m_projectSearch;
244     KAction *m_projectSearchNext;
245
246     KAction **m_videoEffects;
247     KAction **m_audioEffects;
248     KAction **m_customEffects;
249     KAction **m_transitions;
250     KAction *m_buttonAudioThumbs;
251     KAction *m_buttonVideoThumbs;
252     KAction *m_buttonShowMarkers;
253     KAction *m_buttonFitZoom;
254     KAction *m_buttonAutomaticSplitAudio;
255     KAction *m_normalEditTool;
256     KAction *m_overwriteEditTool;
257     KAction *m_insertEditTool;
258     KAction *m_buttonSelectTool;
259     KAction *m_buttonRazorTool;
260     KAction *m_buttonSpacerTool;
261     KAction *m_buttonSnap;
262     KAction *m_saveAction;
263     KAction *m_closeAction;
264     QSlider *m_zoomSlider;
265     KAction *m_zoomIn;
266     KAction *m_zoomOut;
267     KAction *m_loopZone;
268     KAction *m_playZone;
269     KAction *m_loopClip;
270     KSelectAction *m_loadLayout;
271     StatusBarMessageLabel *m_messageLabel;
272     QActionGroup *m_clipTypeGroup;
273     KActionCollection *m_effectsActionCollection;
274     KActionCollection *m_tracksActionCollection;
275
276     bool m_findActivated;
277     QString m_findString;
278     QTimer m_findTimer;
279
280     void readOptions();
281     void saveOptions();
282 #ifdef USE_JOGSHUTTLE
283     void activateShuttleDevice();
284 #endif
285     void connectDocumentInfo(KdenliveDoc *doc);
286     void findAhead();
287     void doOpenFile(const KUrl &url, KAutoSaveFile *stale);
288     void recoverFiles(QList<KAutoSaveFile *> staleFiles, const KUrl &originUrl);
289
290     /** @brief Loads static and dynamic plugins.
291      *
292      * It scans static plugins as well as the filesystem: it doesn't load more
293      * than one plugin per file name, to avoid duplication due to conflicting
294      * installations. */
295     void loadPlugins();
296     void populateMenus(QObject *plugin);
297     void addToMenu(QObject *plugin, const QStringList &texts,
298                    QMenu *menu, const char *member,
299                    QActionGroup *actionGroup);
300     void aboutPlugins();
301
302     /** @brief Instantiates a "Get Hot New Stuff" dialog.
303      * @param configFile configuration file for KNewStuff
304      * @return number of installed items */
305     int getNewStuff(const QString &configFile = QString());
306     QStringList m_pluginFileNames;
307     QByteArray m_timelineState;
308     void loadTranscoders();
309     void loadStabilize();
310     QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config);
311
312     /** @brief Checks that the Kdenlive mime type is correctly installed.
313     * @param open If set to true, this will return the mimetype allowed for file opening (adds .tar.gz format)
314     * @return The mimetype */
315     QString getMimeType(bool open = true);
316
317     /** @brief Populates the "load layout" menu. */
318     void loadLayouts();
319
320     StopmotionWidget *m_stopmotion;
321     QTime m_timer;
322     
323     /** @brief Update statusbar stylesheet (in case of color theme change). */
324     void setStatusBarStyleSheet(const QPalette &p);
325
326 public slots:
327     /** @brief Prepares opening @param url.
328     *
329     * Checks if already open and whether backup exists */
330     void openFile(const KUrl &url);
331     void slotGotProgressInfo(const QString &message, int progress);
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);
335
336
337 private slots:
338     void newFile(bool showProjectSettings = true, bool force = false);
339     void activateDocument();
340     void connectDocument(TrackView*, KdenliveDoc*);
341
342     /** @brief Shows file open dialog. */
343     void openFile();
344     void openLastFile();
345
346     /** @brief Checks whether a URL is available to save to.
347     * @return Whether the file was saved. */
348     bool saveFile();
349
350     /** @brief Shows a save file dialog for saving the project.
351     * @return Whether the file was saved. */
352     bool saveFileAs();
353
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);
358
359     /** @brief Shows the shortcut dialog. */
360     void slotEditKeys();
361     void slotPreferences(int page = -1, int option = -1);
362
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 slotAddEffect(const QDomElement effect);
369     void slotEditProfiles();
370     void slotDetectAudioDriver();
371     void slotEditProjectSettings();
372     /** @brief Change current document MLT profile. */
373     void slotUpdateProjectProfile(const QString &profile);
374     void slotDisplayActionMessage(QAction *a);
375
376     /** @brief Turns automatic splitting of audio and video on/off. */
377     void slotSwitchSplitAudio();
378     void slotSwitchVideoThumbs();
379     void slotSwitchAudioThumbs();
380     void slotSwitchMarkersComments();
381     void slotSwitchSnap();
382     void slotRenderProject();
383     void slotFullScreen();
384     void slotUpdateDocumentState(bool modified);
385
386     /** @brief Sets the timeline zoom slider to @param value.
387     *
388     * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
389     void slotSetZoom(int value);
390     /** @brief Decreases the timeline zoom level by 1. */
391     void slotZoomIn();
392     /** @brief Increases the timeline zoom level by 1. */
393     void slotZoomOut();
394     /** @brief Makes the timeline zoom level fit the timeline content. */
395     void slotFitZoom();
396     /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
397     void slotUpdateZoomSliderToolTip(int zoomlevel);
398
399     /** @brief Displays the zoom slider tooltip.
400     * @param zoomlevel (optional) The zoom level to show in the tooltip.
401     *
402     * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
403     void slotShowZoomSliderToolTip(int zoomlevel = -1);
404     /** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
405     bool closeCurrentDocument(bool saveChanges = true);
406     /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
407     void slotDeleteItem();
408     void slotAddClipMarker();
409     void slotDeleteClipMarker();
410     void slotDeleteAllClipMarkers();
411     void slotEditClipMarker();
412
413     /** @brief Adds marker or auide at the current position without showing the marker dialog.
414      *
415      * Adds a marker if clip monitor is active, otherwise a guide.
416      * The comment is set to the current position (therefore not dialog).
417      * This can be useful to mark something during playback. */
418     void slotAddMarkerGuideQuickly();
419     void slotCutTimelineClip();
420     void slotInsertClipOverwrite();
421     void slotSelectTimelineClip();
422     void slotSelectTimelineTransition();
423     void slotDeselectTimelineClip();
424     void slotDeselectTimelineTransition();
425     void slotSelectAddTimelineClip();
426     void slotSelectAddTimelineTransition();
427     void slotAddVideoEffect(QAction *result);
428     void slotAddTransition(QAction *result);
429     void slotAddProjectClip(KUrl url, const QString &comment = QString());
430     void slotAddProjectClipList(KUrl::List urls);
431     void slotShowClipProperties(DocClipBase *clip);
432     void slotShowClipProperties(QList <DocClipBase *>cliplist, QMap<QString, QString> commonproperties);
433     void slotTimelineClipSelected(ClipItem* item, bool raise = true);
434     void slotTrackSelected(int index, TrackInfo info, bool raise = true);
435     void slotActivateTransitionView(Transition *);
436     void slotChangeTool(QAction * action);
437     void slotChangeEdit(QAction * action);
438     void slotSetTool(PROJECTTOOL tool);
439     void slotSnapForward();
440     void slotSnapRewind();
441     void slotClipStart();
442     void slotClipEnd();
443     void slotZoneStart();
444     void slotZoneEnd();
445     void slotFind();
446     void findTimeout();
447     void slotFindNext();
448     void slotSelectClipInTimeline();
449     void slotClipInTimeline(const QString &clipId);
450
451     void slotInsertSpace();
452     void slotRemoveSpace();
453     void slotAddGuide();
454     void slotEditGuide();
455     void slotDeleteGuide();
456     void slotDeleteAllGuides();
457     void slotGuidesUpdated();
458
459     void slotCopy();
460     void slotPaste();
461     void slotPasteEffects();
462
463     void slotAdjustClipMonitor();
464     void slotAdjustProjectMonitor();
465     void slotSaveZone(Render *render, QPoint zone, DocClipBase *baseClip = NULL, KUrl path = KUrl());
466
467     void slotSetInPoint();
468     void slotSetOutPoint();
469     void slotResizeItemStart();
470     void slotResizeItemEnd();
471     void configureNotifications();
472     void slotInsertTrack(int ix = -1);
473     void slotDeleteTrack(int ix = -1);
474     /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
475     void slotConfigTrack(int ix = -1);
476     /** @brief Select all clips in active track. */
477     void slotSelectTrack();
478     /** @brief Select all clips in timeline. */
479     void slotSelectAllTracks();
480     void slotGetNewLumaStuff();
481     void slotGetNewTitleStuff();
482     void slotGetNewRenderStuff();
483     void slotGetNewMltProfileStuff();
484     void slotAutoTransition();
485     void slotRunWizard();
486     /** @brief Lets the sampleplugin create a generator.  */
487     void generateClip();
488     void slotZoneMoved(int start, int end);
489     void slotDvdWizard(const QString &url = QString(), const QString &profile = "dv_pal");
490     void slotGroupClips();
491     void slotUnGroupClips();
492     void slotEditItemDuration();
493     void slotClipInProjectTree();
494     //void slotClipToProjectTree();
495     void slotSplitAudio();
496     void slotSetAudioAlignReference();
497     void slotAlignAudio();
498     void slotUpdateClipType(QAction *action);
499     void slotShowTimeline(bool show);
500     void slotMaximizeCurrent(bool show);
501     void slotTranscode(KUrl::List urls = KUrl::List());
502     void slotStabilize();
503     void slotTranscodeClip();
504     /** @brief Archive project: creates a copy of the project file with all clips in a new folder. */
505     void slotArchiveProject();
506     void slotSetDocumentRenderProfile(QMap <QString, QString> props);
507     void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
508
509     /** @brief Switches between displaying frames or timecode.
510     * @param ix 0 = display timecode, 1 = display frames. */
511     void slotUpdateTimecodeFormat(int ix);
512
513     /** @brief Removes the focus of anything. */
514     void slotRemoveFocus();
515     void slotCleanProject();
516     void slotUpdateClipMarkers(DocClipBase *clip);
517     void slotRevert();
518     void slotShutdown();
519     void slotUpdateTrackInfo();
520
521     /** @brief Changes the color scheme. */
522     void slotChangePalette(QAction *action, const QString &themename = QString());
523     void slotSwitchMonitors();
524     void slotCheckRenderStatus();
525     void slotInsertZoneToTree();
526     void slotInsertZoneToTimeline();
527
528     /** @brief Deletes items from timeline and document.
529     * @param ids The ids of the clips to delete.
530     * @param folderids The names and ids of the folders to delete. */
531     void slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids);
532     void slotShowTitleBars(bool show);
533     void slotSwitchTitles();
534     /** @brief Update the capture folder if user asked a change. */
535     void slotUpdateCaptureFolder();
536
537     /** @brief Apply new properties to a clip */
538     void slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload);
539
540     /** @brief Delete a clip from current project */
541     void slotDeleteClip(const QString &id);
542
543     /** @brief Saves the widgets layout */
544     void slotSaveLayout(QAction*);
545     void slotLoadLayout(QAction*);
546
547     /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
548     void slotMonitorRequestRenderFrame(bool request);
549     /** @brief Open the stopmotion dialog. */
550     void slotOpenStopmotion();
551     /** @brief Implements all the actions that are int he ActionsCollection. */
552     void slotDoAction(const QString& action_name);
553     /** @brief Update project because the use of proxy clips was enabled / disabled. */
554     void slotUpdateProxySettings();
555     /** @brief Insert current project's timecode into the notes widget. */
556     void slotInsertNotesTimecode();
557     /** @brief Open the project's backupdialog. */
558     void slotOpenBackupDialog(const KUrl url = KUrl());
559     /** @brief Disable proxies for this project. */
560     void slotDisableProxies();
561
562     void slotElapsedTime();
563     /** @brief Open the online services search dialog. */
564     void slotDownloadResources();
565     
566     void slotChangePalette();
567     /** @brief Save current timeline clip as mlt playlist. */
568     void slotSaveTimelineClip();
569
570 signals:
571     Q_SCRIPTABLE void abortRenderJob(const QString &url);
572 };
573
574
575 #endif