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