]> git.sesse.net Git - kdenlive/blob - src/mainwindow.h
Add option to automatically split audio when adding a clip to timeline (based on...
[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
41 #include "effectslist.h"
42 #include "gentime.h"
43 #include "definitions.h"
44 #include "statusbarmessagelabel.h"
45 #include "dvdwizard.h"
46
47 class KdenliveDoc;
48 class TrackView;
49 class MonitorManager;
50 class ProjectList;
51 class EffectsListView;
52 class EffectStackView;
53 class TransitionSettings;
54 class Monitor;
55 class RecMonitor;
56 class CustomTrackView;
57 class RenderWidget;
58 #ifndef NO_JOGSHUTTLE
59 class JogShuttle;
60 #endif /* NO_JOGSHUTTLE */
61 class DocClipBase;
62 class Render;
63 class Transition;
64
65 class MainWindow : public KXmlGuiWindow
66 {
67     Q_OBJECT
68     Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
69
70 public:
71
72     /** @brief Initialises the main window.
73      * @param MltPath (optional) path to MLT environment
74      * @param Url (optional) file to open
75      *
76      * If Url is present, it will be opened, otherwhise, if openlastproject is
77      * set, latest project will be opened. If no file is open after trying this,
78      * a default new file will be created. */
79     explicit MainWindow(const QString &MltPath = QString(),
80                         const KUrl &Url = KUrl(), QWidget *parent = 0);
81
82     /** @brief Locates the MLT environment.
83      * @param mltPath (optional) path to MLT environment
84      *
85      * It tries to set the paths of the MLT profiles and renderer, using
86      * mltPath, MLT_PREFIX, searching for the binary `melt`, or asking to the
87      * user. It doesn't fill any list of profiles, while its name suggests so. */
88     void parseProfiles(const QString &mltPath = QString());
89
90     static EffectsList videoEffects;
91     static EffectsList audioEffects;
92     static EffectsList customEffects;
93     static EffectsList transitions;
94 protected:
95
96     /** @brief Closes the window.
97      * @return false if the user presses "Cancel" on a confirmation dialog or
98      *     the operation requested (starting waiting jobs or saving file) fails,
99      *     true otherwise */
100     virtual bool queryClose();
101
102     /** @brief Reports a message in the status bar when an error occurs. */
103     virtual void customEvent(QEvent *e);
104
105     /** @brief Enables live search in the timeline. */
106     virtual void keyPressEvent(QKeyEvent *ke);
107
108     /** @brief Stops the active monitor when the window gets hidden. */
109     virtual void hideEvent(QHideEvent *e);
110
111     /** @brief Filters key events to the live search. */
112     bool eventFilter(QObject *obj, QEvent *ev);
113
114     /** @brief Saves the file and the window properties when saving the session. */
115     virtual void saveProperties(KConfigGroup &config);
116
117     /** @brief Restores the window and the file when a session is loaded. */
118     virtual void readProperties(const KConfigGroup &config);
119
120 private:
121     KTabWidget* m_timelineArea;
122     QProgressBar *m_statusProgressBar;
123
124     /** @brief Sets up all the actions and attaches them to the collection. */
125     void setupActions();
126     KdenliveDoc *m_activeDocument;
127     TrackView *m_activeTimeline;
128     MonitorManager *m_monitorManager;
129
130     QDockWidget *m_projectListDock;
131     ProjectList *m_projectList;
132
133     QDockWidget *m_effectListDock;
134     EffectsListView *m_effectList;
135     //KListWidget *m_effectList;
136
137     QDockWidget *m_effectStackDock;
138     EffectStackView *m_effectStack;
139
140     QDockWidget *m_transitionConfigDock;
141     TransitionSettings *m_transitionConfig;
142
143     QDockWidget *m_clipMonitorDock;
144     Monitor *m_clipMonitor;
145
146     QDockWidget *m_projectMonitorDock;
147     Monitor *m_projectMonitor;
148
149     QDockWidget *m_recMonitorDock;
150     RecMonitor *m_recMonitor;
151
152     QDockWidget *m_undoViewDock;
153     QUndoView *m_undoView;
154     QUndoGroup *m_commandStack;
155
156     KComboBox *m_timecodeFormat;
157
158     QMenu *m_videoEffectsMenu;
159     QMenu *m_audioEffectsMenu;
160     QMenu *m_customEffectsMenu;
161     QMenu *m_transitionsMenu;
162     QMenu *m_timelineContextMenu;
163     QMenu *m_timelineContextClipMenu;
164     QMenu *m_timelineContextTransitionMenu;
165     KUrl m_startUrl;
166
167     /** @brief Shortcut to remove the focus from any element.
168      *
169      * It allows to get out of e.g. text input fields and to press another
170      * shortcut. */
171     QShortcut* m_shortcutRemoveFocus;
172
173     RenderWidget *m_renderWidget;
174
175 #ifndef NO_JOGSHUTTLE
176     JogShuttle *m_jogProcess;
177 #endif /* NO_JOGSHUTTLE */
178
179     KRecentFilesAction *m_fileOpenRecent;
180     KAction *m_fileRevert;
181     KAction *m_projectSearch;
182     KAction *m_projectSearchNext;
183
184     KAction **m_videoEffects;
185     KAction **m_audioEffects;
186     KAction **m_customEffects;
187     KAction **m_transitions;
188     KAction *m_buttonAudioThumbs;
189     KAction *m_buttonVideoThumbs;
190     KAction *m_buttonShowMarkers;
191     KAction *m_buttonFitZoom;
192     KAction *m_buttonAutomaticSplitAudio;
193     KAction *m_normalEditTool;
194     KAction *m_overwriteEditTool;
195     KAction *m_insertEditTool;
196     KAction *m_buttonSelectTool;
197     KAction *m_buttonRazorTool;
198     KAction *m_buttonSpacerTool;
199     KAction *m_buttonSnap;
200     KAction *m_saveAction;
201     KAction *m_closeAction;
202     QSlider *m_zoomSlider;
203     KAction *m_zoomIn;
204     KAction *m_zoomOut;
205     KAction *m_loopZone;
206     KAction *m_playZone;
207     StatusBarMessageLabel *m_messageLabel;
208     QActionGroup *m_clipTypeGroup;
209
210     bool m_findActivated;
211     QString m_findString;
212     QTimer m_findTimer;
213
214     void readOptions();
215     void saveOptions();
216 #ifndef NO_JOGSHUTTLE
217     void activateShuttleDevice();
218     void slotShuttleAction(int code);
219 #endif /* NO_JOGSHUTTLE */
220     void connectDocumentInfo(KdenliveDoc *doc);
221     void findAhead();
222     void doOpenFile(const KUrl &url, KAutoSaveFile *stale);
223     void recoverFiles(QList<KAutoSaveFile *> staleFiles);
224     void loadPlugins();
225     void populateMenus(QObject *plugin);
226     void addToMenu(QObject *plugin, const QStringList &texts,
227                    QMenu *menu, const char *member,
228                    QActionGroup *actionGroup);
229     void aboutPlugins();
230
231     /** @brief Instantiates a "Get Hot New Stuff" dialog.
232      * @param configFile configuration file for KNewStuff
233      * @return number of installed items */
234     int getNewStuff(const QString &configFile = QString());
235     QStringList m_pluginFileNames;
236     QByteArray m_timelineState;
237     void loadTranscoders();
238     QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config);
239     /** @brief Checks that the Kdenlive mime type is correctly installed.
240     * @return The mimetype */
241     QString getMimeType();
242
243 public slots:
244     /** @brief Prepares opening @param url.
245     *
246     * Checks if already open and whether backup exists */
247     void openFile(const KUrl &url);
248     void slotGotProgressInfo(const QString &message, int progress);
249     Q_SCRIPTABLE void setRenderingProgress(const QString &url, int progress);
250     Q_SCRIPTABLE void setRenderingFinished(const QString &url, int status, const QString &error);
251
252 private slots:
253     void newFile(bool showProjectSettings = true, bool force = false);
254     void queryQuit();
255     void activateDocument();
256     void connectDocument(TrackView*, KdenliveDoc*);
257     /** @brief Shows file open dialog. */
258     void openFile();
259     void openLastFile();
260     /** @brief Checks whether a URL is available to save to.
261     * @return Whether the file was saved. */
262     bool saveFile();
263     /** @brief Shows a save file dialog for saving the project.
264     * @return Whether the file was saved. */
265     bool saveFileAs();
266     /** @brief Set properties to match outputFileName and save the document.
267     * @param outputFileName The URL to save to / The document's URL.
268     * @return Whether we had success. */
269     bool saveFileAs(const QString &outputFileName);
270     void slotPreferences(int page = -1, int option = -1);
271     void updateConfiguration();
272     void slotConnectMonitors();
273     void slotRaiseMonitor(bool clipMonitor);
274     void slotUpdateClip(const QString &id);
275     void slotUpdateMousePosition(int pos);
276     void slotAddEffect(const QDomElement effect, GenTime pos = GenTime(), int track = -1);
277     void slotEditProfiles();
278     void slotDetectAudioDriver();
279     void slotEditProjectSettings();
280     void slotDisplayActionMessage(QAction *a);
281     /** @brief Turns automatic splitting of audio and video on/off. */
282     void slotSwitchSplitAudio();
283     void slotSwitchVideoThumbs();
284     void slotSwitchAudioThumbs();
285     void slotSwitchMarkersComments();
286     void slotSwitchSnap();
287     void slotRenderProject();
288     void slotFullScreen();
289     void slotUpdateDocumentState(bool modified);
290
291     /** @brief Sets the timeline zoom slider to @param value.
292     *
293     * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
294     void slotSetZoom(int value);
295     /** @brief Decreases the timeline zoom level by 1. */
296     void slotZoomIn();
297     /** @brief Increases the timeline zoom level by 1. */
298     void slotZoomOut();
299     /** @brief Makes the timeline zoom level fit the timeline content. */
300     void slotFitZoom();
301     /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
302     void slotUpdateZoomSliderToolTip(int zoomlevel);
303     /** @brief Displays the zoom slider tooltip.
304     * @param zoomlevel (optional) The zoom level to show in the tooltip. 
305     *
306     * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
307     void slotShowZoomSliderToolTip(int zoomlevel = -1);
308
309     void closeCurrentDocument(bool saveChanges = true);
310     /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
311     void slotDeleteItem();
312     void slotAddClipMarker();
313     void slotDeleteClipMarker();
314     void slotDeleteAllClipMarkers();
315     void slotEditClipMarker();
316     void slotCutTimelineClip();
317     void slotInsertClipOverwrite();
318     void slotSelectTimelineClip();
319     void slotSelectTimelineTransition();
320     void slotDeselectTimelineClip();
321     void slotDeselectTimelineTransition();
322     void slotSelectAddTimelineClip();
323     void slotSelectAddTimelineTransition();
324     void slotAddVideoEffect(QAction *result);
325     void slotAddAudioEffect(QAction *result);
326     void slotAddCustomEffect(QAction *result);
327     void slotAddTransition(QAction *result);
328     void slotAddProjectClip(KUrl url);
329 #ifndef NO_JOGSHUTTLE
330     void slotShuttleButton(int code);
331 #endif /* NO_JOGSHUTTLE */
332     void slotShowClipProperties(DocClipBase *clip);
333     void slotShowClipProperties(QList <DocClipBase *>cliplist, QMap<QString, QString> commonproperties);
334     void slotActivateEffectStackView();
335     void slotActivateTransitionView(Transition *);
336     void slotChangeTool(QAction * action);
337     void slotChangeEdit(QAction * action);
338     void slotSetTool(PROJECTTOOL tool);
339     void slotSnapForward();
340     void slotSnapRewind();
341     void slotClipStart();
342     void slotClipEnd();
343     void slotZoneStart();
344     void slotZoneEnd();
345     void slotFind();
346     void findTimeout();
347     void slotFindNext();
348     void slotSelectClipInTimeline();
349     void slotClipInTimeline(const QString &clipId);
350
351     void slotInsertSpace();
352     void slotRemoveSpace();
353     void slotAddGuide();
354     void slotEditGuide();
355     void slotDeleteGuide();
356     void slotDeleteAllGuides();
357     void slotGuidesUpdated();
358
359     void slotCopy();
360     void slotPaste();
361     void slotPasteEffects();
362     void slotReloadEffects();
363
364     void slotAdjustClipMonitor();
365     void slotAdjustProjectMonitor();
366     void slotSaveZone(Render *render, QPoint zone);
367
368     void slotSetInPoint();
369     void slotSetOutPoint();
370     void slotResizeItemStart();
371     void slotResizeItemEnd();
372     void configureNotifications();
373     void slotInsertTrack(int ix = 0);
374     void slotDeleteTrack(int ix = 0);
375     /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
376     void slotConfigTrack(int ix = -1);
377     void slotGetNewLumaStuff();
378     void slotGetNewTitleStuff();
379     void slotGetNewRenderStuff();
380     void slotGetNewMltProfileStuff();
381     void slotAutoTransition();
382     void slotRunWizard();
383     /** @brief Lets the sampleplugin create a generator.  */
384     void generateClip();
385     void slotZoneMoved(int start, int end);
386     void slotUpdatePreviewSettings();
387     void slotDvdWizard(const QString &url = QString(), const QString &profile = "dv_pal");
388     void slotGroupClips();
389     void slotUnGroupClips();
390     void slotEditItemDuration();
391     void slotClipInProjectTree();
392     void slotSplitAudio();
393     void slotUpdateClipType(QAction *action);
394     void slotShowTimeline(bool show);
395     void slotMaximizeCurrent(bool show);
396     void slotTranscode(KUrl::List urls = KUrl::List());
397     void slotTranscodeClip();
398     void slotSetDocumentRenderProfile(const QString &dest, const QString &group, const QString &name, const QString &file);
399     void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
400     /** @brief Switches between displaying frames or timecode.
401     * @param ix 0 = display timecode, 1 = display frames. */
402     void slotUpdateTimecodeFormat(int ix);
403     /** @brief Removes the focus of anything. */
404     void slotRemoveFocus();
405     void slotCleanProject();
406     void slotUpdateClipMarkers(DocClipBase *clip);
407     void slotRevert();
408     void slotShutdown();
409     void slotUpdateTrackInfo();
410
411     /** @brief Changes the color scheme. */
412     void slotChangePalette(QAction *action, const QString &themename = QString());
413     void slotSwitchMonitors();
414     void slotCheckRenderStatus();
415     void slotInsertZoneToTree();
416     void slotInsertZoneToTimeline();
417     /** @brief Deletes items from timeline and document.
418     * @param ids The ids of the clips to delete.
419     * @param folderids The names and ids of the folders to delete. */
420     void slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids);
421     void slotShowTitleBars(bool show);
422     void slotSwitchTitles();
423
424 signals:
425     Q_SCRIPTABLE void abortRenderJob(const QString &url);
426 };
427
428
429 #endif