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