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