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