]> git.sesse.net Git - kdenlive/blob - src/mainwindow.h
Various changes for getting an OpenGL context (almost) everywhere it is needed.
[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 #include <QMap>
32 #include <QString>
33 #include <QImage>
34
35 #include <KXmlGuiWindow>
36 #include <KTextEdit>
37 #include <KListWidget>
38 #include <KTabWidget>
39 #include <KUndoStack>
40 #include <KRecentFilesAction>
41 #include <KComboBox>
42 #include <kautosavefile.h>
43 #include <KActionCategory>
44
45 #include "effectslist.h"
46 #include "gentime.h"
47 #include "definitions.h"
48 #include "statusbarmessagelabel.h"
49 #include "dvdwizard.h"
50 #include "stopmotion/stopmotion.h"
51 #include "widgets/noteswidget.h"
52 #include "ui_backupdialog_ui.h"
53
54 class KdenliveDoc;
55 class TrackView;
56 class MonitorManager;
57 class ProjectList;
58 class EffectsListView;
59 class EffectStackView;
60 class EffectStackView2;
61 class TransitionSettings;
62 class Monitor;
63 class RecMonitor;
64 class RenderWidget;
65 #ifdef USE_JOGSHUTTLE
66 class JogShuttle;
67 class JogShuttleAction;
68 #endif
69 class DocClipBase;
70 class Render;
71 class Transition;
72 class ScopeManager;
73 class Histogram;
74 class Vectorscope;
75 class Waveform;
76 class RGBParade;
77 class KActionCollection;
78 class AudioSignal;
79 class AudioSpectrum;
80 class Spectrogram;
81 class QGLWidget;
82
83 class MainWindow : public KXmlGuiWindow
84 {
85     Q_OBJECT
86     Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
87
88 public:
89
90     /** @brief Initialises the main window.
91      * @param MltPath (optional) path to MLT environment
92      * @param Url (optional) file to open
93      * @param clipsToLoad (optional) a comma separated list of clips to import in project
94      *
95      * If Url is present, it will be opened, otherwhise, if openlastproject is
96      * set, latest project will be opened. If no file is open after trying this,
97      * a default new file will be created. */
98     explicit MainWindow(const QString &MltPath = QString(),
99                         const KUrl &Url = KUrl(), const QString & clipsToLoad = QString(), QWidget *parent = 0);
100     virtual ~MainWindow();
101
102     /** @brief Locates the MLT environment.
103      * @param mltPath (optional) path to MLT environment
104      *
105      * It tries to set the paths of the MLT profiles and renderer, using
106      * mltPath, MLT_PREFIX, searching for the binary `melt`, or asking to the
107      * user. It doesn't fill any list of profiles, while its name suggests so. */
108     void parseProfiles(const QString &mltPath = QString());
109
110     static EffectsList videoEffects;
111     static EffectsList audioEffects;
112     static EffectsList customEffects;
113     static EffectsList transitions;
114     
115     /** @brief Cache for luma files thumbnails. */
116     static QMap <QString,QImage> m_lumacache;
117
118 protected:
119
120     /** @brief Closes the window.
121      * @return false if the user presses "Cancel" on a confirmation dialog or
122      *     the operation requested (starting waiting jobs or saving file) fails,
123      *     true otherwise */
124     virtual bool queryClose();
125
126     /** @brief Reports a message in the status bar when an error occurs. */
127     virtual void customEvent(QEvent *e);
128
129     /** @brief Enables live search in the timeline. */
130     virtual void keyPressEvent(QKeyEvent *ke);
131
132     /** @brief Stops the active monitor when the window gets hidden. */
133     virtual void hideEvent(QHideEvent *e);
134
135     /** @brief Filters key events to the live search. */
136     bool eventFilter(QObject *obj, QEvent *ev);
137
138     /** @brief Saves the file and the window properties when saving the session. */
139     virtual void saveProperties(KConfigGroup &config);
140
141     /** @brief Restores the window and the file when a session is loaded. */
142     virtual void readProperties(const KConfigGroup &config);
143
144 private:
145     QGLWidget* m_glContext;
146
147     KTabWidget* m_timelineArea;
148     QProgressBar *m_statusProgressBar;
149
150     ScopeManager *m_scopeManager;
151
152     /** @brief Sets up all the actions and attaches them to the collection. */
153     void setupActions();
154     KdenliveDoc *m_activeDocument;
155     TrackView *m_activeTimeline;
156     MonitorManager *m_monitorManager;
157
158     QDockWidget *m_projectListDock;
159     ProjectList *m_projectList;
160
161     QDockWidget *m_effectListDock;
162     EffectsListView *m_effectList;
163     //KListWidget *m_effectList;
164
165     QDockWidget *m_notesDock;
166     NotesWidget *m_notesWidget;
167
168     QDockWidget *m_effectStackDock;
169     EffectStackView2 *m_effectStack;
170
171     QDockWidget *m_transitionConfigDock;
172     TransitionSettings *m_transitionConfig;
173
174     QDockWidget *m_clipMonitorDock;
175     Monitor *m_clipMonitor;
176
177     QDockWidget *m_projectMonitorDock;
178     Monitor *m_projectMonitor;
179
180     QDockWidget *m_recMonitorDock;
181     RecMonitor *m_recMonitor;
182
183     QDockWidget *m_vectorscopeDock;
184     Vectorscope *m_vectorscope;
185
186     QDockWidget *m_waveformDock;
187     Waveform *m_waveform;
188
189     QDockWidget *m_RGBParadeDock;
190     RGBParade *m_RGBParade;
191
192     QDockWidget *m_histogramDock;
193     Histogram *m_histogram;
194
195     QDockWidget *m_audiosignalDock;
196     AudioSignal *m_audiosignal;
197
198     QDockWidget *m_audioSpectrumDock;
199     AudioSpectrum *m_audioSpectrum;
200
201     QDockWidget *m_spectrogramDock;
202     Spectrogram *m_spectrogram;
203
204     QDockWidget *m_undoViewDock;
205     QUndoView *m_undoView;
206     QUndoGroup *m_commandStack;
207
208     KSelectAction *m_timeFormatButton;
209
210     /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
211     QList <QDockWidget *> m_gfxScopesList;
212
213     KActionCategory *m_effectActions;
214     QMenu *m_effectsMenu;
215     QMenu *m_transitionsMenu;
216     QMenu *m_timelineContextMenu;
217     QMenu *m_timelineContextClipMenu;
218     QMenu *m_timelineContextTransitionMenu;
219     KUrl m_startUrl;
220
221     /** Actions used in the stopmotion widget */
222     KActionCategory *m_stopmotion_actions;
223
224     /** Action names that can be used in the slotDoAction() slot, with their i18n() names */
225     QStringList m_action_names;
226
227
228     /** @brief Shortcut to remove the focus from any element.
229      *
230      * It allows to get out of e.g. text input fields and to press another
231      * shortcut. */
232     QShortcut* m_shortcutRemoveFocus;
233
234     RenderWidget *m_renderWidget;
235
236 #ifdef USE_JOGSHUTTLE
237     JogShuttle *m_jogProcess;
238     JogShuttleAction* m_jogShuttle;
239 #endif
240
241     KRecentFilesAction *m_fileOpenRecent;
242     KAction *m_fileRevert;
243     KAction *m_projectSearch;
244     KAction *m_projectSearchNext;
245
246     KAction **m_transitions;
247     KAction *m_buttonAudioThumbs;
248     KAction *m_buttonVideoThumbs;
249     KAction *m_buttonShowMarkers;
250     KAction *m_buttonFitZoom;
251     KAction *m_buttonAutomaticSplitAudio;
252     KAction *m_normalEditTool;
253     KAction *m_overwriteEditTool;
254     KAction *m_insertEditTool;
255     KAction *m_buttonSelectTool;
256     KAction *m_buttonRazorTool;
257     KAction *m_buttonSpacerTool;
258     KAction *m_buttonSnap;
259     KAction *m_saveAction;
260     KAction *m_closeAction;
261     QSlider *m_zoomSlider;
262     KAction *m_zoomIn;
263     KAction *m_zoomOut;
264     KAction *m_loopZone;
265     KAction *m_playZone;
266     KAction *m_loopClip;
267     KSelectAction *m_loadLayout;
268     StatusBarMessageLabel *m_messageLabel;
269     QActionGroup *m_clipTypeGroup;
270     KActionCollection *m_effectsActionCollection;
271     KActionCollection *m_tracksActionCollection;
272
273     bool m_findActivated;
274     QString m_findString;
275     QTimer m_findTimer;
276
277     void readOptions();
278     void saveOptions();
279 #ifdef USE_JOGSHUTTLE
280     void activateShuttleDevice();
281 #endif
282     void connectDocumentInfo(KdenliveDoc *doc);
283     void findAhead();
284     void doOpenFile(const KUrl &url, KAutoSaveFile *stale);
285     void recoverFiles(const QList<KAutoSaveFile *> &staleFiles, const KUrl &originUrl);
286
287     /** @brief Loads static and dynamic plugins.
288      *
289      * It scans static plugins as well as the filesystem: it doesn't load more
290      * than one plugin per file name, to avoid duplication due to conflicting
291      * installations. */
292     void loadPlugins();
293     void populateMenus(QObject *plugin);
294     void addToMenu(QObject *plugin, const QStringList &texts,
295                    QMenu *menu, const char *member,
296                    QActionGroup *actionGroup);
297     void aboutPlugins();
298
299     /** @brief Instantiates a "Get Hot New Stuff" dialog.
300      * @param configFile configuration file for KNewStuff
301      * @return number of installed items */
302     int getNewStuff(const QString &configFile = QString());
303     QStringList m_pluginFileNames;
304     QByteArray m_timelineState;
305     void loadTranscoders();
306     void loadClipActions();
307     QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config);
308
309     /** @brief Checks that the Kdenlive mime type is correctly installed.
310     * @param open If set to true, this will return the mimetype allowed for file opening (adds .tar.gz format)
311     * @return The mimetype */
312     QString getMimeType(bool open = true);
313
314     /** @brief Populates the "load layout" menu. */
315     void loadLayouts();
316
317     StopmotionWidget *m_stopmotion;
318     QTime m_timer;
319     /** @brief The last selected clip in timeline. */
320     ClipItem *m_mainClip;
321     /** @brief Update statusbar stylesheet (in case of color theme change). */
322     void setStatusBarStyleSheet(const QPalette &p);
323
324 public slots:
325     /** @brief Prepares opening @param url.
326     *
327     * Checks if already open and whether backup exists */
328     void openFile(const KUrl &url);
329     void slotGotProgressInfo(const QString &message, int progress, MessageType type = DefaultMessage);
330     void slotReloadEffects();
331     Q_SCRIPTABLE void setRenderingProgress(const QString &url, int progress);
332     Q_SCRIPTABLE void setRenderingFinished(const QString &url, int status, const QString &error);
333
334
335 private slots:
336     void newFile(bool showProjectSettings = true, bool force = false);
337     void activateDocument();
338     void connectDocument(TrackView*, KdenliveDoc*);
339
340     /** @brief Shows file open dialog. */
341     void openFile();
342     void openLastFile();
343
344     /** @brief Checks whether a URL is available to save to.
345     * @return Whether the file was saved. */
346     bool saveFile();
347
348     /** @brief Shows a save file dialog for saving the project.
349     * @return Whether the file was saved. */
350     bool saveFileAs();
351
352     /** @brief Set properties to match outputFileName and save the document.
353     * @param outputFileName The URL to save to / The document's URL.
354     * @return Whether we had success. */
355     bool saveFileAs(const QString &outputFileName);
356
357     /** @brief Shows the shortcut dialog. */
358     void slotEditKeys();
359     void slotPreferences(int page = -1, int option = -1);
360
361     /** @brief Reflects setting changes to the GUI. */
362     void updateConfiguration();
363     void slotConnectMonitors();
364     void slotUpdateClip(const QString &id);
365     void slotUpdateMousePosition(int pos);
366     void slotUpdateProjectDuration(int pos);
367     void slotAddEffect(const QDomElement &effect);
368     void slotEditProfiles();
369     void slotDetectAudioDriver();
370     void slotEditProjectSettings();
371     /** @brief Change current document MLT profile. */
372     void slotUpdateProjectProfile(const QString &profile);
373     void slotDisplayActionMessage(QAction *a);
374
375     /** @brief Turns automatic splitting of audio and video on/off. */
376     void slotSwitchSplitAudio();
377     void slotSwitchVideoThumbs();
378     void slotSwitchAudioThumbs();
379     void slotSwitchMarkersComments();
380     void slotSwitchSnap();
381     void slotRenderProject();
382     void slotFullScreen();
383     void slotUpdateDocumentState(bool modified);
384
385     /** @brief Sets the timeline zoom slider to @param value.
386     *
387     * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
388     void slotSetZoom(int value);
389     /** @brief Decreases the timeline zoom level by 1. */
390     void slotZoomIn();
391     /** @brief Increases the timeline zoom level by 1. */
392     void slotZoomOut();
393     /** @brief Makes the timeline zoom level fit the timeline content. */
394     void slotFitZoom();
395     /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
396     void slotUpdateZoomSliderToolTip(int zoomlevel);
397
398     /** @brief Displays the zoom slider tooltip.
399     * @param zoomlevel (optional) The zoom level to show in the tooltip.
400     *
401     * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
402     void slotShowZoomSliderToolTip(int zoomlevel = -1);
403     /** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
404     bool closeCurrentDocument(bool saveChanges = true);
405     /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
406     void slotDeleteItem();
407     void slotAddClipMarker();
408     void slotDeleteClipMarker();
409     void slotDeleteAllClipMarkers();
410     void slotEditClipMarker();
411
412     /** @brief Adds marker or auide at the current position without showing the marker dialog.
413      *
414      * Adds a marker if clip monitor is active, otherwise a guide.
415      * The comment is set to the current position (therefore not dialog).
416      * This can be useful to mark something during playback. */
417     void slotAddMarkerGuideQuickly();
418     void slotCutTimelineClip();
419     void slotInsertClipOverwrite();
420     void slotSelectTimelineClip();
421     void slotSelectTimelineTransition();
422     void slotDeselectTimelineClip();
423     void slotDeselectTimelineTransition();
424     void slotSelectAddTimelineClip();
425     void slotSelectAddTimelineTransition();
426     void slotAddVideoEffect(QAction *result);
427     void slotAddTransition(QAction *result);
428     void slotAddProjectClip(const KUrl &url, const stringMap &data = stringMap());
429     void slotAddProjectClipList(const KUrl::List &urls);
430     void slotShowClipProperties(DocClipBase *clip);
431     void slotShowClipProperties(const QList<DocClipBase *> &cliplist, const QMap<QString, QString> &commonproperties);
432     void slotTimelineClipSelected(ClipItem* item, bool raise = true);
433     void slotTrackSelected(int index, const TrackInfo &info, bool raise = true);
434     void slotActivateTransitionView(Transition *transition);
435     void slotChangeTool(QAction * action);
436     void slotChangeEdit(QAction * action);
437     void slotSetTool(ProjectTool tool);
438     void slotSnapForward();
439     void slotSnapRewind();
440     void slotClipStart();
441     void slotClipEnd();
442     void slotZoneStart();
443     void slotZoneEnd();
444     void slotFind();
445     void findTimeout();
446     void slotFindNext();
447     void slotSelectClipInTimeline();
448     void slotClipInTimeline(const QString &clipId);
449
450     void slotInsertSpace();
451     void slotRemoveSpace();
452     void slotAddGuide();
453     void slotEditGuide();
454     void slotDeleteGuide();
455     void slotDeleteAllGuides();
456     void slotGuidesUpdated();
457
458     void slotCopy();
459     void slotPaste();
460     void slotPasteEffects();
461
462     void slotAdjustClipMonitor();
463     void slotAdjustProjectMonitor();
464     void slotSaveZone(Render *render, const QPoint &zone, DocClipBase *baseClip = NULL, KUrl path = KUrl());
465
466     void slotSetInPoint();
467     void slotSetOutPoint();
468     void slotResizeItemStart();
469     void slotResizeItemEnd();
470     void configureNotifications();
471     void slotInsertTrack(int ix = -1);
472     void slotDeleteTrack(int ix = -1);
473     /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
474     void slotConfigTrack(int ix = -1);
475     /** @brief Select all clips in active track. */
476     void slotSelectTrack();
477     /** @brief Select all clips in timeline. */
478     void slotSelectAllTracks();
479     void slotGetNewLumaStuff();
480     void slotGetNewTitleStuff();
481     void slotGetNewRenderStuff();
482     void slotGetNewMltProfileStuff();
483     void slotAutoTransition();
484     void slotRunWizard();
485     /** @brief Lets the sampleplugin create a generator.  */
486     void generateClip();
487     void slotZoneMoved(int start, int end);
488     void slotDvdWizard(const QString &url = QString());
489     void slotGroupClips();
490     void slotUnGroupClips();
491     void slotEditItemDuration();
492     void slotClipInProjectTree();
493     //void slotClipToProjectTree();
494     void slotSplitAudio();
495     void slotSetAudioAlignReference();
496     void slotAlignAudio();
497     void slotUpdateClipType(QAction *action);
498     void slotShowTimeline(bool show);
499     void slotMaximizeCurrent(bool show);
500     void slotTranscode(const KUrl::List &urls = KUrl::List());
501     void slotStartClipAction();
502     void slotTranscodeClip();
503     /** @brief Archive project: creates a copy of the project file with all clips in a new folder. */
504     void slotArchiveProject();
505     void slotSetDocumentRenderProfile(const QMap<QString, QString> &props);
506     void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
507
508     /** @brief Switches between displaying frames or timecode.
509     * @param ix 0 = display timecode, 1 = display frames. */
510     void slotUpdateTimecodeFormat(int ix);
511
512     /** @brief Removes the focus of anything. */
513     void slotRemoveFocus();
514     void slotCleanProject();
515     void slotUpdateClipMarkers(DocClipBase *clip);
516     void slotRevert();
517     void slotShutdown();
518     void slotUpdateTrackInfo();
519
520     /** @brief Changes the color scheme. */
521     void slotChangePalette(QAction *action, const QString &themename = QString());
522     void slotSwitchMonitors();
523     void slotCheckRenderStatus();
524     void slotInsertZoneToTree();
525     void slotInsertZoneToTimeline();
526
527     /** @brief Deletes items from timeline and document.
528     * @param ids The ids of the clips to delete.
529     * @param folderids The names and ids of the folders to delete. */
530     void slotDeleteProjectClips(const QStringList &ids, const QMap<QString, QString> &folderids);
531     void slotShowTitleBars(bool show);
532     void slotSwitchTitles();
533     /** @brief Update the capture folder if user asked a change. */
534     void slotUpdateCaptureFolder();
535
536     /** @brief Apply new properties to a clip */
537     void slotApplyNewClipProperties(const QString &id, const QMap <QString, QString> &props, const QMap <QString, QString> &newprops, bool refresh, bool reload);
538
539     /** @brief Delete a clip from current project */
540     void slotDeleteClip(const QString &id);
541
542     /** @brief Saves the widgets layout */
543     void slotSaveLayout(QAction*);
544     void slotLoadLayout(QAction*);
545
546     /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
547     void slotMonitorRequestRenderFrame(bool request);
548     /** @brief Open the stopmotion dialog. */
549     void slotOpenStopmotion();
550     /** @brief Implements all the actions that are int he ActionsCollection. */
551     void slotDoAction(const QString& action_name);
552     /** @brief Update project because the use of proxy clips was enabled / disabled. */
553     void slotUpdateProxySettings();
554     /** @brief Insert current project's timecode into the notes widget. */
555     void slotInsertNotesTimecode();
556     /** @brief Open the project's backupdialog. */
557     void slotOpenBackupDialog(const KUrl &url = KUrl());
558     /** @brief Disable proxies for this project. */
559     void slotDisableProxies();
560
561     void slotElapsedTime();
562     /** @brief Open the online services search dialog. */
563     void slotDownloadResources();
564     
565     void slotChangePalette();
566     /** @brief Save current timeline clip as mlt playlist. */
567     void slotSaveTimelineClip();
568     /** @brief Process keyframe data sent from a clip to effect / transition stack. */
569     void slotProcessImportKeyframes(GraphicsRectItem type, const QString& data, int maximum);
570     /** @brief Move playhead to mouse curser position if defined key is pressed */
571     void slotAlignPlayheadToMousePos();
572     /** @brief Set MLT's consumer deinterlace method */
573     void slotSetDeinterlacer(int ix);
574     /** @brief Set MLT's consumer interpolation method */
575     void slotSetInterpolation(int ix);
576
577 signals:
578     Q_SCRIPTABLE void abortRenderJob(const QString &url);
579 };
580
581
582 #endif