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