]> git.sesse.net Git - kdenlive/blob - src/mainwindow.h
Load layouts can now be added as combobox in toolbar
[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
49 class KdenliveDoc;
50 class TrackView;
51 class MonitorManager;
52 class ProjectList;
53 class EffectsListView;
54 class EffectStackView;
55 class TransitionSettings;
56 class Monitor;
57 class RecMonitor;
58 class CustomTrackView;
59 class RenderWidget;
60 #ifndef NO_JOGSHUTTLE
61 class JogShuttle;
62 class JogShuttleAction;
63 #endif /* NO_JOGSHUTTLE */
64 class DocClipBase;
65 class Render;
66 class Transition;
67 class Histogram;
68 class Vectorscope;
69 class Waveform;
70 class RGBParade;
71 class KActionCollection;
72 class AudioSignal;
73 class AbstractAudioScopeWidget;
74 class AudioSpectrum;
75 class Spectrogram;
76
77 class MainWindow : public KXmlGuiWindow
78 {
79     Q_OBJECT
80     Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
81
82 public:
83
84     /** @brief Initialises the main window.
85      * @param MltPath (optional) path to MLT environment
86      * @param Url (optional) file to open
87      * @param clipsToLoad (optional) a comma separated list of clips to import in project
88      *
89      * If Url is present, it will be opened, otherwhise, if openlastproject is
90      * set, latest project will be opened. If no file is open after trying this,
91      * a default new file will be created. */
92     explicit MainWindow(const QString &MltPath = QString(),
93                         const KUrl &Url = KUrl(), const QString & clipsToLoad = QString(), QWidget *parent = 0);
94     virtual ~MainWindow();
95
96     /** @brief Locates the MLT environment.
97      * @param mltPath (optional) path to MLT environment
98      *
99      * It tries to set the paths of the MLT profiles and renderer, using
100      * mltPath, MLT_PREFIX, searching for the binary `melt`, or asking to the
101      * user. It doesn't fill any list of profiles, while its name suggests so. */
102     void parseProfiles(const QString &mltPath = QString());
103
104     static EffectsList videoEffects;
105     static EffectsList audioEffects;
106     static EffectsList customEffects;
107     static EffectsList transitions;
108 protected:
109
110     /** @brief Closes the window.
111      * @return false if the user presses "Cancel" on a confirmation dialog or
112      *     the operation requested (starting waiting jobs or saving file) fails,
113      *     true otherwise */
114     virtual bool queryClose();
115
116     /** @brief Reports a message in the status bar when an error occurs. */
117     virtual void customEvent(QEvent *e);
118
119     /** @brief Enables live search in the timeline. */
120     virtual void keyPressEvent(QKeyEvent *ke);
121
122     /** @brief Stops the active monitor when the window gets hidden. */
123     virtual void hideEvent(QHideEvent *e);
124
125     /** @brief Filters key events to the live search. */
126     bool eventFilter(QObject *obj, QEvent *ev);
127
128     /** @brief Saves the file and the window properties when saving the session. */
129     virtual void saveProperties(KConfigGroup &config);
130
131     /** @brief Restores the window and the file when a session is loaded. */
132     virtual void readProperties(const KConfigGroup &config);
133
134 private:
135     KTabWidget* m_timelineArea;
136     QProgressBar *m_statusProgressBar;
137
138     /** @brief Sets up all the actions and attaches them to the collection. */
139     void setupActions();
140     KdenliveDoc *m_activeDocument;
141     TrackView *m_activeTimeline;
142     MonitorManager *m_monitorManager;
143
144     QDockWidget *m_projectListDock;
145     ProjectList *m_projectList;
146
147     QDockWidget *m_effectListDock;
148     EffectsListView *m_effectList;
149     //KListWidget *m_effectList;
150
151     QDockWidget *m_notesDock;
152     KTextEdit *m_notesWidget;
153
154     QDockWidget *m_effectStackDock;
155     EffectStackView *m_effectStack;
156
157     QDockWidget *m_transitionConfigDock;
158     TransitionSettings *m_transitionConfig;
159
160     QDockWidget *m_clipMonitorDock;
161     Monitor *m_clipMonitor;
162
163     QDockWidget *m_projectMonitorDock;
164     Monitor *m_projectMonitor;
165
166     QDockWidget *m_recMonitorDock;
167     RecMonitor *m_recMonitor;
168
169     QDockWidget *m_vectorscopeDock;
170     Vectorscope *m_vectorscope;
171
172     QDockWidget *m_waveformDock;
173     Waveform *m_waveform;
174
175     QDockWidget *m_RGBParadeDock;
176     RGBParade *m_RGBParade;
177
178     QDockWidget *m_histogramDock;
179     Histogram *m_histogram;
180
181     QDockWidget *m_audiosignalDock;
182     AudioSignal *m_audiosignal;
183
184     QDockWidget *m_audioSpectrumDock;
185     AudioSpectrum *m_audioSpectrum;
186
187     QDockWidget *m_spectrogramDock;
188     Spectrogram *m_spectrogram;
189
190     QDockWidget *m_undoViewDock;
191     QUndoView *m_undoView;
192     QUndoGroup *m_commandStack;
193
194     KComboBox *m_timecodeFormat;
195
196     /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
197     QList <QDockWidget *> m_gfxScopesList;
198     QList <AbstractAudioScopeWidget *> m_audioScopesList;
199
200     QMenu *m_videoEffectsMenu;
201     QMenu *m_audioEffectsMenu;
202     QMenu *m_customEffectsMenu;
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 queryQuit();
321     void activateDocument();
322     void connectDocument(TrackView*, KdenliveDoc*);
323
324     /** @brief Shows file open dialog. */
325     void openFile();
326     void openLastFile();
327
328     /** @brief Checks whether a URL is available to save to.
329     * @return Whether the file was saved. */
330     bool saveFile();
331
332     /** @brief Shows a save file dialog for saving the project.
333     * @return Whether the file was saved. */
334     bool saveFileAs();
335
336     /** @brief Set properties to match outputFileName and save the document.
337     * @param outputFileName The URL to save to / The document's URL.
338     * @return Whether we had success. */
339     bool saveFileAs(const QString &outputFileName);
340
341     /** @brief Shows the shortcut dialog. */
342     void slotEditKeys();
343     void slotPreferences(int page = -1, int option = -1);
344
345     /** @brief Reflects setting changes to the GUI. */
346     void updateConfiguration();
347     void slotConnectMonitors();
348     void slotRaiseMonitor(bool clipMonitor);
349     void slotUpdateClip(const QString &id);
350     void slotUpdateMousePosition(int pos);
351     void slotAddEffect(const QDomElement effect);
352     void slotEditProfiles();
353     void slotDetectAudioDriver();
354     void slotEditProjectSettings();
355     /** @brief Change current document MLT profile. */
356     void slotUpdateProjectProfile(const QString &profile);
357     void slotDisplayActionMessage(QAction *a);
358
359     /** @brief Turns automatic splitting of audio and video on/off. */
360     void slotSwitchSplitAudio();
361     void slotSwitchVideoThumbs();
362     void slotSwitchAudioThumbs();
363     void slotSwitchMarkersComments();
364     void slotSwitchSnap();
365     void slotRenderProject();
366     void slotFullScreen();
367     void slotUpdateDocumentState(bool modified);
368
369     /** @brief Sets the timeline zoom slider to @param value.
370     *
371     * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
372     void slotSetZoom(int value);
373     /** @brief Decreases the timeline zoom level by 1. */
374     void slotZoomIn();
375     /** @brief Increases the timeline zoom level by 1. */
376     void slotZoomOut();
377     /** @brief Makes the timeline zoom level fit the timeline content. */
378     void slotFitZoom();
379     /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
380     void slotUpdateZoomSliderToolTip(int zoomlevel);
381
382     /** @brief Displays the zoom slider tooltip.
383     * @param zoomlevel (optional) The zoom level to show in the tooltip.
384     *
385     * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
386     void slotShowZoomSliderToolTip(int zoomlevel = -1);
387     /** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
388     bool closeCurrentDocument(bool saveChanges = true);
389     /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
390     void slotDeleteItem();
391     void slotAddClipMarker();
392     void slotDeleteClipMarker();
393     void slotDeleteAllClipMarkers();
394     void slotEditClipMarker();
395
396     /** @brief Adds marker or auide at the current position without showing the marker dialog.
397      *
398      * Adds a marker if clip monitor is active, otherwise a guide.
399      * The comment is set to the current position (therefore not dialog).
400      * This can be useful to mark something during playback. */
401     void slotAddMarkerGuideQuickly();
402     void slotCutTimelineClip();
403     void slotInsertClipOverwrite();
404     void slotSelectTimelineClip();
405     void slotSelectTimelineTransition();
406     void slotDeselectTimelineClip();
407     void slotDeselectTimelineTransition();
408     void slotSelectAddTimelineClip();
409     void slotSelectAddTimelineTransition();
410     void slotAddVideoEffect(QAction *result);
411     void slotAddAudioEffect(QAction *result);
412     void slotAddCustomEffect(QAction *result);
413     void slotAddTransition(QAction *result);
414     void slotAddProjectClip(KUrl url);
415     void slotShowClipProperties(DocClipBase *clip);
416     void slotShowClipProperties(QList <DocClipBase *>cliplist, QMap<QString, QString> commonproperties);
417     void slotActivateEffectStackView();
418     void slotActivateTransitionView(Transition *);
419     void slotChangeTool(QAction * action);
420     void slotChangeEdit(QAction * action);
421     void slotSetTool(PROJECTTOOL tool);
422     void slotSnapForward();
423     void slotSnapRewind();
424     void slotClipStart();
425     void slotClipEnd();
426     void slotZoneStart();
427     void slotZoneEnd();
428     void slotFind();
429     void findTimeout();
430     void slotFindNext();
431     void slotSelectClipInTimeline();
432     void slotClipInTimeline(const QString &clipId);
433
434     void slotInsertSpace();
435     void slotRemoveSpace();
436     void slotAddGuide();
437     void slotEditGuide();
438     void slotDeleteGuide();
439     void slotDeleteAllGuides();
440     void slotGuidesUpdated();
441
442     void slotCopy();
443     void slotPaste();
444     void slotPasteEffects();
445
446     void slotAdjustClipMonitor();
447     void slotAdjustProjectMonitor();
448     void slotSaveZone(Render *render, QPoint zone);
449
450     void slotSetInPoint();
451     void slotSetOutPoint();
452     void slotResizeItemStart();
453     void slotResizeItemEnd();
454     void configureNotifications();
455     void slotInsertTrack(int ix = 0);
456     void slotDeleteTrack(int ix = 0);
457     /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
458     void slotConfigTrack(int ix = -1);
459     void slotGetNewLumaStuff();
460     void slotGetNewTitleStuff();
461     void slotGetNewRenderStuff();
462     void slotGetNewMltProfileStuff();
463     void slotAutoTransition();
464     void slotRunWizard();
465     /** @brief Lets the sampleplugin create a generator.  */
466     void generateClip();
467     void slotZoneMoved(int start, int end);
468     void slotDvdWizard(const QString &url = QString(), const QString &profile = "dv_pal");
469     void slotGroupClips();
470     void slotUnGroupClips();
471     void slotEditItemDuration();
472     void slotClipInProjectTree();
473     //void slotClipToProjectTree();
474     void slotSplitAudio();
475     void slotUpdateClipType(QAction *action);
476     void slotShowTimeline(bool show);
477     void slotMaximizeCurrent(bool show);
478     void slotTranscode(KUrl::List urls = KUrl::List());
479     void slotTranscodeClip();
480     void slotSetDocumentRenderProfile(QMap <QString, QString> props);
481     void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
482
483     /** @brief Switches between displaying frames or timecode.
484     * @param ix 0 = display timecode, 1 = display frames. */
485     void slotUpdateTimecodeFormat(int ix);
486
487     /** @brief Removes the focus of anything. */
488     void slotRemoveFocus();
489     void slotCleanProject();
490     void slotUpdateClipMarkers(DocClipBase *clip);
491     void slotRevert();
492     void slotShutdown();
493     void slotUpdateTrackInfo();
494
495     /** @brief Changes the color scheme. */
496     void slotChangePalette(QAction *action, const QString &themename = QString());
497     void slotSwitchMonitors();
498     void slotCheckRenderStatus();
499     void slotInsertZoneToTree();
500     void slotInsertZoneToTimeline();
501
502     /** @brief Deletes items from timeline and document.
503     * @param ids The ids of the clips to delete.
504     * @param folderids The names and ids of the folders to delete. */
505     void slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids);
506     void slotShowTitleBars(bool show);
507     void slotSwitchTitles();
508     /** @brief Update the capture folder if user asked a change. */
509     void slotUpdateCaptureFolder();
510
511     /** @brief Apply new properties to a clip */
512     void slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload);
513
514     /** @brief Delete a clip from current project */
515     void slotDeleteClip(const QString &id);
516
517     /** @brief Saves the widgets layout */
518     void slotSaveLayout(QAction*);
519     void slotLoadLayout(QAction*);
520
521     /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
522     void slotMonitorRequestRenderFrame(bool request);
523     /** @brief Check if someone needs the render frame sent. */
524     void slotUpdateGfxScopeFrameRequest();
525     /** @brief Check if someone needs the render frame sent. */
526     void slotDoUpdateGfxScopeFrameRequest();
527     void slotUpdateAudioScopeFrameRequest();
528     void slotDoUpdateAudioScopeFrameRequest();
529     /** @brief When switching between monitors, update the visible scopes. */
530     void slotUpdateColorScopes();
531     /** @brief Switch current monitor to fullscreen. */
532     void slotSwitchFullscreen();
533     /** @brief Open the stopmotion dialog. */
534     void slotOpenStopmotion();
535     /** @brief Implements all the actions that are int he ActionsCollection. */
536     void slotDoAction(const QString& action_name);
537  
538 signals:
539     Q_SCRIPTABLE void abortRenderJob(const QString &url);
540 };
541
542
543 #endif