CuteLogger
Fast and simple logging solution for Qt based applications
mainwindow.h
1 /*
2  * Copyright (c) 2011-2021 Meltytech, LLC
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MAINWINDOW_H
19 #define MAINWINDOW_H
20 
21 #include <QMainWindow>
22 #include <QMutex>
23 #include <QTimer>
24 #include <QUrl>
25 #include <QNetworkAccessManager>
26 #include <QScopedPointer>
27 #include <QSharedPointer>
28 #include <QDateTime>
29 #include "mltcontroller.h"
30 #include "mltxmlchecker.h"
31 
32 #define EXIT_RESTART (42)
33 #define EXIT_RESET (43)
34 
35 namespace Ui {
36 class MainWindow;
37 }
38 class Player;
39 class RecentDock;
40 class EncodeDock;
41 class JobsDock;
42 class PlaylistDock;
43 class QUndoStack;
44 class QActionGroup;
45 class FilterController;
46 class ScopeController;
47 class FiltersDock;
48 class TimelineDock;
49 class AutoSaveFile;
50 class QNetworkReply;
51 class KeyframesDock;
52 class MarkersDock;
53 class NotesDock;
54 
55 class MainWindow : public QMainWindow
56 {
57  Q_OBJECT
58 
59 public:
60  enum LayoutMode {
61  Custom = 0,
62  Logging,
63  Editing,
64  Effects,
65  Color,
66  Audio,
67  PlayerOnly
68  };
69 
70  static MainWindow &singleton();
71  ~MainWindow();
72  void open(Mlt::Producer *producer);
73  bool continueModified();
74  bool continueJobsRunning();
75  QUndoStack *undoStack() const;
76  bool saveXML(const QString &filename, bool withRelativePaths = true);
77  static void changeTheme(const QString &theme);
78  PlaylistDock *playlistDock() const
79  {
80  return m_playlistDock;
81  }
82  FilterController *filterController() const
83  {
84  return m_filterController;
85  }
86  Mlt::Playlist *playlist() const;
87  bool isPlaylistValid() const;
88  Mlt::Producer *multitrack() const;
89  bool isMultitrackValid() const;
90  void doAutosave();
91  void setFullScreen(bool isFullScreen);
92  QString removeFileScheme(QUrl &url);
93  QString untitledFileName() const;
94  void setProfile(const QString &profile_name);
95  QString fileName() const
96  {
97  return m_currentFile;
98  }
99  bool isSourceClipMyProject(QString resource = MLT.resource(), bool withDialog = true);
100  bool keyframesDockIsVisible() const;
101 
102  void keyPressEvent(QKeyEvent *);
103  void keyReleaseEvent(QKeyEvent *);
104  void hideSetDataDirectory();
105  QMenu *customProfileMenu() const
106  {
107  return m_customProfileMenu;
108  }
109  QAction *actionAddCustomProfile() const;
110  QAction *actionProfileRemove() const;
111  QActionGroup *profileGroup() const
112  {
113  return m_profileGroup;
114  }
115  void buildVideoModeMenu(QMenu *topMenu, QMenu *&customMenu, QActionGroup *group, QAction *addAction,
116  QAction *removeAction);
117  void newProject(const QString &filename, bool isProjectFolder = false);
118  void addCustomProfile(const QString &name, QMenu *menu, QAction *action, QActionGroup *group);
119  void removeCustomProfiles(const QStringList &profiles, QDir &dir, QMenu *menu, QAction *action);
120  QUuid timelineClipUuid(int trackIndex, int clipIndex);
121  void replaceInTimeline(const QUuid &uuid, Mlt::Producer &producer);
122  void replaceAllByHash(const QString &hash, Mlt::Producer &producer, bool isProxy = false);
123  bool isClipboardNewer() const
124  {
125  return m_clipboardUpdatedAt > m_sourceUpdatedAt;
126  }
127  int mltIndexForTrack(int trackIndex) const;
128  int bottomVideoTrackIndex() const;
129 
130 signals:
131  void audioChannelsChanged();
132  void producerOpened(bool withReopen = true);
133  void profileChanged();
134  void openFailed(QString);
135  void aboutToShutDown();
136  void renameRequested();
137  void serviceInChanged(int delta, Mlt::Service *);
138  void serviceOutChanged(int delta, Mlt::Service *);
139 
140 protected:
141  MainWindow();
142  bool eventFilter(QObject *target, QEvent *event);
143  void dragEnterEvent(QDragEnterEvent *);
144  void dropEvent(QDropEvent *);
145  void closeEvent(QCloseEvent *);
146  void showEvent(QShowEvent *);
147  void hideEvent(QHideEvent *event);
148 
149 private:
150  void connectFocusSignals();
151  void registerDebugCallback();
152  void connectUISignals();
153  void setupAndConnectUndoStack();
154  void setupAndConnectPlayerWidget();
155  void setupLayoutSwitcher();
156  void centerLayoutInRemainingToolbarSpace();
157  void setupAndConnectDocks();
158  void setupMenuView();
159  void connectVideoWidgetSignals();
160  void setupAndConnectLeapNetworkListener();
161  void setupSettingsMenu();
162  void setupOpenOtherMenu();
163  void setupActions();
164  QAction *addProfile(QActionGroup *actionGroup, const QString &desc, const QString &name);
165  QAction *addLayout(QActionGroup *actionGroup, const QString &name);
166  void readPlayerSettings();
167  void readWindowSettings();
168  void writeSettings();
169  void configureVideoWidget();
170  void setCurrentFile(const QString &filename);
171  void changeAudioChannels(bool checked, int channels);
172  void changeDeinterlacer(bool checked, const char *method);
173  void changeInterpolation(bool checked, const char *method);
174  bool checkAutoSave(QString &url);
175  bool saveRepairedXmlFile(MltXmlChecker &checker, QString &fileName);
176  void setAudioChannels(int channels);
177  void showSaveError();
178  void setPreviewScale(int scale);
179  void setVideoModeMenu();
180  void resetVideoModeMenu();
181  void resetDockCorners();
182  void showIncompatibleProjectMessage(const QString &shotcutVersion);
183  void restartAfterChangeTheme();
184 
185  Ui::MainWindow *ui;
186  Player *m_player;
187  QDockWidget *m_propertiesDock;
188  RecentDock *m_recentDock;
189  EncodeDock *m_encodeDock;
190  JobsDock *m_jobsDock;
191  PlaylistDock *m_playlistDock;
192  TimelineDock *m_timelineDock;
193  QString m_currentFile;
194  bool m_isKKeyPressed;
195  QUndoStack *m_undoStack;
196  QDockWidget *m_historyDock;
197  QActionGroup *m_profileGroup;
198  QActionGroup *m_externalGroup;
199  QActionGroup *m_keyerGroup;
200  QActionGroup *m_layoutGroup;
201  QActionGroup *m_previewScaleGroup;
202  FiltersDock *m_filtersDock;
203  FilterController *m_filterController;
204  ScopeController *m_scopeController;
205  QMenu *m_customProfileMenu;
206  QMenu *m_keyerMenu;
207  QStringList m_multipleFiles;
208  bool m_isPlaylistLoaded;
209  QActionGroup *m_languagesGroup;
210  QSharedPointer<AutoSaveFile> m_autosaveFile;
211  QMutex m_autosaveMutex;
212  QTimer m_autosaveTimer;
213  int m_exitCode;
214  QScopedPointer<QAction> m_statusBarAction;
215  QNetworkAccessManager m_network;
216  QString m_upgradeUrl;
217  KeyframesDock *m_keyframesDock;
218  QDateTime m_clipboardUpdatedAt;
219  QDateTime m_sourceUpdatedAt;
220  MarkersDock *m_markersDock;
221  NotesDock *m_notesDock;
222 
223 #ifdef WITH_LIBLEAP
224  LeapListener m_leapListener;
225 #endif
226 
227 public slots:
228  bool isCompatibleWithGpuMode(MltXmlChecker &checker);
229  bool isXmlRepaired(MltXmlChecker &checker, QString &fileName);
230  bool open(QString url, const Mlt::Properties * = nullptr, bool play = true);
231  void openMultiple(const QStringList &paths);
232  void openMultiple(const QList<QUrl> &urls);
233  void openVideo();
234  void openCut(Mlt::Producer *producer, bool play = false);
235  void hideProducer();
236  void closeProducer();
237  void showStatusMessage(QAction *action, int timeoutSeconds = 5);
238  void showStatusMessage(const QString &message, int timeoutSeconds = 5,
239  QPalette::ColorRole role = QPalette::ToolTipBase);
240  void onStatusMessageClicked();
241  void seekPlaylist(int start);
242  void seekTimeline(int position, bool seekPlayer = true);
243  void seekKeyframes(int position);
244  QWidget *loadProducerWidget(Mlt::Producer *producer);
245  void onProducerOpened(bool withReopen = true);
246  void onGpuNotSupported();
247  void onShuttle(float x);
248  void onPropertiesDockTriggered(bool checked = true);
249  bool on_actionSave_triggered();
250 
251 private slots:
252  void showUpgradePrompt();
253  void on_actionAbout_Shotcut_triggered();
254  void on_actionOpenOther_triggered();
255  void onProducerChanged();
256  bool on_actionSave_As_triggered();
257  void onEncodeTriggered(bool checked = true);
258  void onCaptureStateChanged(bool started);
259  void onJobsDockTriggered(bool = true);
260  void onRecentDockTriggered(bool checked = true);
261  void onPlaylistDockTriggered(bool checked = true);
262  void onTimelineDockTriggered(bool checked = true);
263  void onHistoryDockTriggered(bool checked = true);
264  void onFiltersDockTriggered(bool checked = true);
265  void onKeyframesDockTriggered(bool checked = true);
266  void onMarkersDockTriggered(bool = true);
267  void onNotesDockTriggered(bool = true);
268  void onPlaylistCreated();
269  void onPlaylistLoaded();
270  void onPlaylistCleared();
271  void onPlaylistClosed();
272  void onPlaylistModified();
273  void onMultitrackCreated();
274  void onMultitrackClosed();
275  void onMultitrackModified();
276  void onMultitrackDurationChanged();
277  void onNoteModified();
278  void onCutModified();
279  void onProducerModified();
280  void onFilterModelChanged();
281  void updateMarkers();
282  void updateThumbnails();
283  void on_actionUndo_triggered();
284  void on_actionRedo_triggered();
285  void on_actionFAQ_triggered();
286  void on_actionForum_triggered();
287  void on_actionEnterFullScreen_triggered();
288  void on_actionRealtime_triggered(bool checked);
289  void on_actionProgressive_triggered(bool checked);
290  void on_actionChannels1_triggered(bool checked);
291  void on_actionChannels2_triggered(bool checked);
292  void on_actionChannels6_triggered(bool checked);
293  void on_actionOneField_triggered(bool checked);
294  void on_actionLinearBlend_triggered(bool checked);
295  void on_actionYadifTemporal_triggered(bool checked);
296  void on_actionYadifSpatial_triggered(bool checked);
297  void on_actionNearest_triggered(bool checked);
298  void on_actionBilinear_triggered(bool checked);
299  void on_actionBicubic_triggered(bool checked);
300  void on_actionHyper_triggered(bool checked);
301  void on_actionJack_triggered(bool checked);
302  void on_actionGPU_triggered(bool checked);
303  void onExternalTriggered(QAction *);
304  void onKeyerTriggered(QAction *);
305  void onProfileTriggered(QAction *);
306  void onProfileChanged();
307  void on_actionAddCustomProfile_triggered();
308  void processMultipleFiles();
309  void onLanguageTriggered(QAction *);
310  void on_actionSystemTheme_triggered();
311  void on_actionFusionDark_triggered();
312  void on_actionJobPriorityLow_triggered();
313  void on_actionJobPriorityNormal_triggered();
314  void on_actionFusionLight_triggered();
315  void on_actionTutorials_triggered();
316  void on_actionRestoreLayout_triggered();
317  void on_actionShowTitleBars_triggered(bool checked);
318  void on_actionShowToolbar_triggered(bool checked);
319  void onToolbarVisibilityChanged(bool visible);
320  void on_menuExternal_aboutToShow();
321  void on_actionUpgrade_triggered();
322  void on_actionOpenXML_triggered();
323  void onAutosaveTimeout();
324  void on_actionGammaSRGB_triggered(bool checked);
325  void on_actionGammaRec709_triggered(bool checked);
326  void onFocusChanged(QWidget *old, QWidget *now) const;
327  void onFocusObjectChanged(QObject *obj) const;
328  void onFocusWindowChanged(QWindow *window) const;
329  void onTimelineClipSelected();
330  void onAddAllToTimeline(Mlt::Playlist *playlist, bool skipProxy);
331  void on_actionScrubAudio_triggered(bool checked);
332 #if !defined(Q_OS_MAC)
333  void onDrawingMethodTriggered(QAction *);
334 #endif
335  void on_actionApplicationLog_triggered();
336  void on_actionClose_triggered();
337  void onPlayerTabIndexChanged(int index);
338  void onUpgradeCheckFinished(QNetworkReply *reply);
339  void onUpgradeTriggered();
340  void onClipCopied();
341  void on_actionExportEDL_triggered();
342  void on_actionExportFrame_triggered();
343  void onGLWidgetImageReady();
344  void on_actionAppDataSet_triggered();
345  void on_actionAppDataShow_triggered();
346  void on_actionNew_triggered();
347  void on_actionKeyboardShortcuts_triggered();
348  void on_actionLayoutLogging_triggered();
349  void on_actionLayoutEditing_triggered();
350  void on_actionLayoutEffects_triggered();
351  void on_actionLayoutColor_triggered();
352  void on_actionLayoutAudio_triggered();
353  void on_actionLayoutPlayer_triggered();
354  void on_actionLayoutPlaylist_triggered();
355  void on_actionLayoutClip_triggered();
356  void on_actionLayoutAdd_triggered();
357  void onLayoutTriggered(QAction *);
358  void on_actionProfileRemove_triggered();
359  void on_actionLayoutRemove_triggered();
360  void on_actionOpenOther2_triggered();
361  void onOpenOtherTriggered(QWidget *widget);
362  void onOpenOtherTriggered();
363  void on_actionClearRecentOnExit_toggled(bool arg1);
364  void onSceneGraphInitialized();
365  void on_actionShowTextUnderIcons_toggled(bool b);
366  void on_actionShowSmallIcons_toggled(bool b);
367  void onPlaylistInChanged(int in);
368  void onPlaylistOutChanged(int out);
369  void on_actionPreviewNone_triggered(bool checked);
370  void on_actionPreview360_triggered(bool checked);
371  void on_actionPreview540_triggered(bool checked);
372  void on_actionPreview720_triggered(bool checked);
373  void on_actionTopics_triggered();
374  void on_actionSync_triggered();
375  void on_actionUseProxy_triggered(bool checked);
376  void on_actionProxyStorageSet_triggered();
377  void on_actionProxyStorageShow_triggered();
378  void on_actionProxyUseProjectFolder_triggered(bool checked);
379  void on_actionProxyUseHardware_triggered(bool checked);
380  void on_actionProxyConfigureHardware_triggered();
381  void updateLayoutSwitcher();
382  void clearCurrentLayout();
383  void onClipboardChanged();
384  void sourceUpdated();
385  void resetSourceUpdated();
386  void on_actionExportChapters_triggered();
387  void on_actionAudioVideoDevice_triggered();
388  void on_actionReset_triggered();
389 };
390 
391 #define MAIN MainWindow::singleton()
392 
393 #endif // MAINWINDOW_H