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