mainwindow.h 16.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/***************************************************************************
 *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/


Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
21 22
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
23

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
24
#include <QDockWidget>
25
#include <QUndoView>
26
#include <QProgressBar>
27
#include <QEvent>
28
#include <QShortcut>
29 30 31
#include <QMap>
#include <QString>
#include <QImage>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
32 33

#include <KXmlGuiWindow>
34
#include <QTabWidget>
35
#include <kautosavefile.h>
36
#include <KActionCategory>
37
#include <KSelectAction>
38
#include <KColorSchemeManager>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
39

40
#include "kdenlivecore_export.h"
Vincent Pinon's avatar
Vincent Pinon committed
41
#include "effectslist/effectslist.h"
42
#include "gentime.h"
43
#include "bin/bin.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
44
#include "definitions.h"
45
#include "statusbarmessagelabel.h"
46
#include "dvdwizard/dvdwizard.h"
47
#include "stopmotion/stopmotion.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
48

49 50 51
class KdenliveDoc;
class EffectsListView;
class EffectStackView;
52
class EffectStackView2;
53 54 55 56
class TransitionSettings;
class Monitor;
class RecMonitor;
class RenderWidget;
57
class Render;
58
class Transition;
59
class KIconLoader;
60

61 62
#define EXIT_RESTART (42)

63
class /*KDENLIVECORE_EXPORT*/ MainWindow : public KXmlGuiWindow
64
{
65 66 67
    Q_OBJECT

public:
68 69 70 71

    /** @brief Initialises the main window.
     * @param MltPath (optional) path to MLT environment
     * @param Url (optional) file to open
72
     * @param clipsToLoad (optional) a comma separated list of clips to import in project
73 74 75 76 77
     *
     * If Url is present, it will be opened, otherwhise, if openlastproject is
     * set, latest project will be opened. If no file is open after trying this,
     * a default new file will be created. */
    explicit MainWindow(const QString &MltPath = QString(),
78
                        const QUrl &Url = QUrl(), const QString & clipsToLoad = QString(), QWidget *parent = 0);
79
    virtual ~MainWindow();
80

Marco Gittler's avatar
Marco Gittler committed
81 82 83 84
    static EffectsList videoEffects;
    static EffectsList audioEffects;
    static EffectsList customEffects;
    static EffectsList transitions;
85 86 87 88
    
    /** @brief Cache for luma files thumbnails. */
    static QMap <QString,QImage> m_lumacache;

89 90
    /** @brief Adds an action to the action collection and stores the name. */
    void addAction(const QString &name, QAction *action);
Till Theato's avatar
Till Theato committed
91
    /** @brief Adds an action to the action collection and stores the name. */
92 93
    QAction *addAction(const QString &name, const QString &text, const QObject *receiver,
                       const char *member, const QIcon &icon = QIcon(), const QKeySequence &shortcut = QKeySequence());
94

95 96 97 98 99 100 101 102 103 104
    /**
     * @brief Adds a new dock widget to this window.
     * @param title title of the dock widget
     * @param objectName objectName of the dock widget (required for storing layouts)
     * @param widget widget to use in the dock
     * @param area area to which the dock should be added to
     * @returns the created dock widget
     */
    QDockWidget *addDock(const QString &title, const QString &objectName, QWidget *widget, Qt::DockWidgetArea area = Qt::TopDockWidgetArea);

Till Theato's avatar
Till Theato committed
105
    // TODO make private again
106
    QTabWidget* m_timelineArea;
Till Theato's avatar
Till Theato committed
107 108 109 110 111
    StopmotionWidget *m_stopmotion;
    QUndoGroup *m_commandStack;
    EffectStackView2 *m_effectStack;
    QUndoView *m_undoView;
    StatusBarMessageLabel *m_messageLabel;
112 113 114
    /** @brief holds info about whether movit is available on this system */
    bool m_gpuAllowed;
    int m_exitCode;
115 116
    QMap<QString, KActionCategory*> kdenliveCategoryMap;
    QList <QAction *> getExtraActions(const QString &name);
Till Theato's avatar
Till Theato committed
117

118
protected:
119 120 121 122 123

    /** @brief Closes the window.
     * @return false if the user presses "Cancel" on a confirmation dialog or
     *     the operation requested (starting waiting jobs or saving file) fails,
     *     true otherwise */
124
    virtual bool queryClose();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
125
    virtual void closeEvent(QCloseEvent*);
126 127 128 129 130

    /** @brief Reports a message in the status bar when an error occurs. */
    virtual void customEvent(QEvent *e);

    /** @brief Stops the active monitor when the window gets hidden. */
131
    virtual void hideEvent(QHideEvent *e);
132 133

    /** @brief Saves the file and the window properties when saving the session. */
134
    virtual void saveProperties(KConfigGroup &config);   
135
    
136
    /** @brief Restores the window and the file when a session is loaded. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
137
    virtual void readProperties(const KConfigGroup &config);
138
    virtual void saveNewToolbarConfig();
139 140

private:
141
    QProgressBar *m_statusProgressBar;
142 143

    /** @brief Sets up all the actions and attaches them to the collection. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
144
    void setupActions();
145

146
    KColorSchemeManager *m_colorschemes;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
147

148
    QDockWidget *m_projectBinDock;
149
    QDockWidget *m_projectListDock;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
150

151
    QDockWidget *m_effectListDock;
152
    EffectsListView *m_effectList;
153 154
    QDockWidget *m_transitionListDock;
    EffectsListView *m_transitionList;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
155

156
    QDockWidget *m_effectStackDock;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
157

158
    QDockWidget *m_clipMonitorDock;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
159 160
    Monitor *m_clipMonitor;

161
    QDockWidget *m_projectMonitorDock;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
162
    Monitor *m_projectMonitor;
163

164
    QDockWidget *m_recMonitorDock;
165 166
    RecMonitor *m_recMonitor;

167
    QDockWidget *m_undoViewDock;
168

169
    KSelectAction *m_timeFormatButton;
170

171
    /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
172
    QList <QDockWidget *> m_gfxScopesList;
173

174
    KActionCategory *m_effectActions;
175
    KActionCategory *m_transitionActions;
176
    QMenu *m_effectsMenu;
177
    QMenu *m_transitionsMenu;
178 179 180 181
    QMenu *m_timelineContextMenu;
    QMenu *m_timelineContextClipMenu;
    QMenu *m_timelineContextTransitionMenu;

182 183
    /** Actions used in the stopmotion widget */
    KActionCategory *m_stopmotion_actions;
184

185
    /** Action names that can be used in the slotDoAction() slot, with their i18n() names */
186
    QStringList m_actionNames;
187

188

189 190 191 192
    /** @brief Shortcut to remove the focus from any element.
     *
     * It allows to get out of e.g. text input fields and to press another
     * shortcut. */
193 194
    QShortcut* m_shortcutRemoveFocus;

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
195
    RenderWidget *m_renderWidget;
196

197
    QList <QAction *>m_transitions;
198 199 200 201 202 203 204 205 206 207 208 209 210
    QAction *m_buttonAudioThumbs;
    QAction *m_buttonVideoThumbs;
    QAction *m_buttonShowMarkers;
    QAction *m_buttonFitZoom;
    QAction *m_buttonAutomaticSplitAudio;
    QAction *m_normalEditTool;
    QAction *m_overwriteEditTool;
    QAction *m_insertEditTool;
    QAction *m_buttonSelectTool;
    QAction *m_buttonRazorTool;
    QAction *m_buttonSpacerTool;
    QAction *m_buttonSnap;
    QAction *m_saveAction;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
211
    QSlider *m_zoomSlider;
212 213 214 215 216
    QAction *m_zoomIn;
    QAction *m_zoomOut;
    QAction *m_loopZone;
    QAction *m_playZone;
    QAction *m_loopClip;
217
    QAction *m_proxyClip;
218
    QActionGroup *m_clipTypeGroup;
219
    QString m_theme;
220
    KIconLoader *m_iconLoader;
221

222 223
    void readOptions();
    void saveOptions();
224
    virtual bool event(QEvent *e);
225 226 227 228 229 230

    /** @brief Loads static and dynamic plugins.
     *
     * It scans static plugins as well as the filesystem: it doesn't load more
     * than one plugin per file name, to avoid duplication due to conflicting
     * installations. */
231 232 233
    void loadPlugins();
    void populateMenus(QObject *plugin);
    void addToMenu(QObject *plugin, const QStringList &texts,
234 235
                   QMenu *menu, const char *member,
                   QActionGroup *actionGroup);
236 237 238 239

    /** @brief Instantiates a "Get Hot New Stuff" dialog.
     * @param configFile configuration file for KNewStuff
     * @return number of installed items */
Alberto Villa's avatar
Alberto Villa committed
240
    int getNewStuff(const QString &configFile = QString());
241
    QStringList m_pluginFileNames;
242
    QByteArray m_timelineState;
243
    void buildDynamicActions();
244
    void loadClipActions();
245

246
    QTime m_timer;
247
    KXMLGUIClient *m_extraFactory;
248 249
    /** @brief The last selected clip in timeline. */
    ClipItem *m_mainClip;
250 251
    bool m_themeInitialized;
    bool m_isDarkTheme;
252
    QListWidget *m_effectBasket;
253 254
    /** @brief Update statusbar stylesheet (in case of color theme change). */
    void setStatusBarStyleSheet(const QPalette &p);
255

256
public slots:
257
    void slotGotProgressInfo(const QString &message, int progress, MessageType type = DefaultMessage);
258
    void slotReloadEffects();
259
    Q_SCRIPTABLE void setRenderingProgress(const QString &url, int progress);
260
    Q_SCRIPTABLE void setRenderingFinished(const QString &url, int status, const QString &error);
261

Till Theato's avatar
Till Theato committed
262 263
    void slotSwitchVideoThumbs();
    void slotSwitchAudioThumbs();
264

Till Theato's avatar
Till Theato committed
265
    void slotPreferences(int page = -1, int option = -1);
266
    void connectDocument();
Till Theato's avatar
Till Theato committed
267
    void slotTimelineClipSelected(ClipItem* item, bool raise = true);
268 269
    /** @brief Reload project profile in config dialog if changed. */
    void slotRefreshProfiles();
270

Till Theato's avatar
Till Theato committed
271
private slots:
272 273
    /** @brief Shows the shortcut dialog. */
    void slotEditKeys();
274
    void loadDockActions();
275
    /** @brief Reflects setting changes to the GUI. */
276
    void updateConfiguration();
277
    void slotConnectMonitors();
278
    void slotUpdateClip(const QString &id, bool reload);
279
    void slotUpdateMousePosition(int pos);
280
    void slotUpdateProjectDuration(int pos);
281
    void slotAddEffect(const QDomElement &effect);
282
    void slotEditProjectSettings();
283

284 285
    /** @brief Turns automatic splitting of audio and video on/off. */
    void slotSwitchSplitAudio();
286
    void slotSwitchMarkersComments();
287
    void slotSwitchSnap();
288
    void slotRenderProject();
289
    void slotFullScreen();
290 291
    /** @brief if modified is true adds "modified" to the caption and enables the save button.
    * (triggered by KdenliveDoc::setModified()) */
292
    void slotUpdateDocumentState(bool modified);
293 294 295 296 297 298

    /** @brief Sets the timeline zoom slider to @param value.
    *
    * Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
    void slotSetZoom(int value);
    /** @brief Decreases the timeline zoom level by 1. */
299
    void slotZoomIn();
300
    /** @brief Increases the timeline zoom level by 1. */
301
    void slotZoomOut();
302
    /** @brief Makes the timeline zoom level fit the timeline content. */
303
    void slotFitZoom();
304 305
    /** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
    void slotUpdateZoomSliderToolTip(int zoomlevel);
306

307
    /** @brief Displays the zoom slider tooltip.
308
    * @param zoomlevel (optional) The zoom level to show in the tooltip.
309 310 311 312
    *
    * Adopted from Dolphin (src/statusbar/dolphinstatusbar.cpp) */
    void slotShowZoomSliderToolTip(int zoomlevel = -1);
    /** @brief Deletes item in timeline, project tree or effect stack depending on focus. */
313
    void slotDeleteItem();
314
    void slotAddClipMarker();
315
    void slotDeleteClipMarker();
316
    void slotDeleteAllClipMarkers();
317
    void slotEditClipMarker();
318 319

    /** @brief Adds marker or auide at the current position without showing the marker dialog.
320
     *
321 322 323 324
     * Adds a marker if clip monitor is active, otherwise a guide.
     * The comment is set to the current position (therefore not dialog).
     * This can be useful to mark something during playback. */
    void slotAddMarkerGuideQuickly();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
325
    void slotCutTimelineClip();
326
    void slotInsertClipOverwrite();
327 328 329 330 331 332
    void slotSelectTimelineClip();
    void slotSelectTimelineTransition();
    void slotDeselectTimelineClip();
    void slotDeselectTimelineTransition();
    void slotSelectAddTimelineClip();
    void slotSelectAddTimelineTransition();
333
    void slotAddVideoEffect(QAction *result);
334
    void slotAddTransition(QAction *result);
335
    void slotAddProjectClip(const QUrl &url);
336
    void slotAddProjectClipList(const QList<QUrl> &urls);
Laurent Montel's avatar
Laurent Montel committed
337
    void slotTrackSelected(int index, const TrackInfo &info, bool raise = true);
338
    void slotActivateTransitionView(Transition *transition);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
339
    void slotChangeTool(QAction * action);
340
    void slotChangeEdit(QAction * action);
341
    void slotSetTool(ProjectTool tool);
342 343
    void slotSnapForward();
    void slotSnapRewind();
344 345
    void slotClipStart();
    void slotClipEnd();
346 347
    void slotSelectClipInTimeline();
    void slotClipInTimeline(const QString &clipId);
348

349
    void slotInsertSpace();
350
    void slotRemoveSpace();
351 352 353 354
    void slotAddGuide();
    void slotEditGuide();
    void slotDeleteGuide();
    void slotDeleteAllGuides();
355
    void slotGuidesUpdated();
356 357 358

    void slotCopy();
    void slotPaste();
359
    void slotPasteEffects();
360 361
    void slotResizeItemStart();
    void slotResizeItemEnd();
362
    void configureNotifications();
363 364
    void slotInsertTrack();
    void slotDeleteTrack();
365
    /** @brief Shows the configure tracks dialog and updates transitions afterwards. */
366
    void slotConfigTrack();
367 368 369 370
    /** @brief Select all clips in active track. */
    void slotSelectTrack();
    /** @brief Select all clips in timeline. */
    void slotSelectAllTracks();
371
    void slotGetNewLumaStuff();
372
    void slotGetNewTitleStuff();
373
    void slotGetNewRenderStuff();
374
    void slotGetNewMltProfileStuff();
375
    void slotAutoTransition();
376
    void slotRunWizard();
377
    /** @brief Lets the sampleplugin create a generator.  */
378
    void generateClip();
379
    void slotZoneMoved(int start, int end);
380
    void slotDvdWizard(const QString &url = QString());
381 382
    void slotGroupClips();
    void slotUnGroupClips();
383
    void slotEditItemDuration();
384
    void slotClipInProjectTree();
385
    //void slotClipToProjectTree();
386
    void slotSplitAudio();
Simon Eugster's avatar
Simon Eugster committed
387 388
    void slotSetAudioAlignReference();
    void slotAlignAudio();
389
    void slotUpdateClipType(QAction *action);
390
    void slotShowTimeline(bool show);
391
    void slotTranscode(const QStringList &urls = QStringList());
392
    void slotTranscodeClip();
393 394
    /** @brief Archive project: creates a copy of the project file with all clips in a new folder. */
    void slotArchiveProject();
Laurent Montel's avatar
Laurent Montel committed
395
    void slotSetDocumentRenderProfile(const QMap<QString, QString> &props);
396
    void slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile);
397

398 399
    /** @brief Switches between displaying frames or timecode.
    * @param ix 0 = display timecode, 1 = display frames. */
400
    void slotUpdateTimecodeFormat(int ix);
401

402
    /** @brief Removes the focus of anything. */
403
    void slotRemoveFocus();
404
    void slotCleanProject();
405
    void slotShutdown();
406
    void slotUpdateTrackInfo();
407

408
    void slotSwitchMonitors();
409 410 411
    void slotSwitchMonitorOverlay(bool show);
    void slotSwitchDropFrames(bool drop);
    void slotSetMonitorGamma(int gamma);
412
    void slotCheckRenderStatus();
413 414
    void slotInsertZoneToTree();
    void slotInsertZoneToTimeline();
415

416 417
    /** @brief Update the capture folder if user asked a change. */
    void slotUpdateCaptureFolder();
418

419 420
    /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
    void slotMonitorRequestRenderFrame(bool request);
421 422
    /** @brief Open the stopmotion dialog. */
    void slotOpenStopmotion();
423 424
    /** @brief Update project because the use of proxy clips was enabled / disabled. */
    void slotUpdateProxySettings();
425 426
    /** @brief Disable proxies for this project. */
    void slotDisableProxies();
427

428
    void slotElapsedTime();
429 430
    /** @brief Open the online services search dialog. */
    void slotDownloadResources();
431

432 433
    /** @brief Save current timeline clip as mlt playlist. */
    void slotSaveTimelineClip();
434
    /** @brief Process keyframe data sent from a clip to effect / transition stack. */
435
    void slotProcessImportKeyframes(GraphicsRectItem type, const QString& data, int maximum);
436 437
    /** @brief Move playhead to mouse curser position if defined key is pressed */
    void slotAlignPlayheadToMousePos();
438

439
    // Ripple Edit 
440
    void slotRippleDelete();
441
    void slotThemeChanged(const QString &);
442
    void slotReloadTheme();
443 444
    /** @brief Close Kdenlive and try to restart it */
    void slotRestart();
445
    void triggerKey(QKeyEvent* ev);
446

447 448
    void slotChangeStyle(QAction *a);

449 450
signals:
    Q_SCRIPTABLE void abortRenderJob(const QString &url);
451
    void configurationChanged();
452
    void GUISetupDone();
453
    void reloadTheme();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
454
};
455

456

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
457
#endif