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