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