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