1 #ifndef Q_gui2_h
2 #define Q_gui2_h
3 
4 #define MKICON(x) ":/new/prefix1/pics/"#x".png"
5 #define MKOSXICON(x) ":/new/prefix1/pics/"#x".icns"
6 
7 #include <vector>
8 #include <QtCore/QUrl>
9 #include <QSlider>
10 #include <QWidget>
11 #include <QtCore/QTimer>
12 #include <string>
13 
14 #include "ADM_mwNavSlider.h"
15 #include "T_thumbSlider.h"
16 #include "ui_gui2.h"
17 #include "gui_action.hxx"
18 #include "myOwnMenu.h"
19 #include "IScriptEngine.h"
20 #include "prefs.h"
21 #include "avi_vars.h"
22 
23 #define ENABLE_EVENT_FILTER
24 
25 /**
26  * \class myQApplication
27  * \brief make sure the checkCrash & friends are done after Qt init
28  * @return
29  */
30 extern void checkCrashFile(void);
31 extern int automation(void);
32 extern int global_argc;
33 extern char **global_argv;
34 extern void ADM_ExitCleanup(void);
35 
36 class myQApplication : public QApplication
37 {
38     Q_OBJECT
39         public:
exec()40                 virtual int exec()
41                 {
42                     connect(&timer, SIGNAL(timeout()), this, SLOT(postInit()));
43                     timer.setSingleShot(true);
44                     timer.start(10);
45                     return QApplication::exec();
46 
47                 }
48 
49                 virtual ~myQApplication();
myQApplication(int & argc,char ** argv)50                 myQApplication(int &argc, char **argv) : QApplication(argc,argv)
51                 {
52 
53                 }
54 
55         protected:
56                 QTimer timer;
57         public slots:
postInit(void)58                 void postInit(void)
59                 {
60                         ADM_info("myQApplication exec\n");
61                         ADM_info("Checking for crash...\n");
62                         checkCrashFile();
63                         if (global_argc >= 2)
64                                 automation();
65                 }
cleanup()66                 void cleanup()
67                 {
68                   //ADM_ExitCleanup();
69                   emit quit();
70                 }
71 
72 };
73 /**
74  * \enum ADM_dragState
75  */
76 enum ADM_dragState
77 {
78     dragState_Normal=0, // no drag
79     dragState_Active=1, // drag on, we process the refresh
80     dragState_HoldOff=2 // Cdrag off, we ignore the refresh
81 };
82 
83 /**
84     \class MainWindow
85 */
86 class MainWindow : public QMainWindow
87 {
88     Q_OBJECT
89 
90 public:
91     Ui_MainWindow ui;
92 
93     MainWindow(const std::vector<IScriptEngine*>& scriptEngines);
94     virtual ~MainWindow();
95 
96     void buildCustomMenu(void);
97     void buildRecentMenu(void);
98     void buildRecentProjectMenu(void);
99     void updateActionShortcuts(void);
100     void volumeWidgetOperational(void);
101     void calcDockWidgetDimensions(uint32_t &width, uint32_t &height);
102     void setBlockZoomChangesFlag(bool block);
103     bool getBlockResizingFlag(void);
104     void setBlockResizingFlag(bool block);
105     void setResizeThreshold(int value);
106     void setActZoomCalledFlag(bool called);
107     void setZoomToFit(void);
108     static void updateCheckDone(int version, const std::string &date, const std::string &downloadLink);
109     static MainWindow *mainWindowSingleton;
110 
111 protected:
112     QMenu *jsMenu;
113     QMenu *pyMenu;
114     QMenu *autoMenu;
115     QMenu *recentFiles;
116     QMenu *recentProjects;
117     QAction *recentFileAction[NB_LAST_FILES];
118     QAction *recentProjectAction[NB_LAST_FILES];
119     ThumbSlider *thumbSlider;
120 
121     bool     refreshCapEnabled;
122     uint32_t refreshCapValue;
123 
124     std::vector<QAction *>ActionsAvailableWhenFileLoaded;
125     std::vector<QAction *>ActionsDisabledOnPlayback;
126     std::vector<QAction *>ActionsAlwaysAvailable;
127     std::vector<QToolButton *>ButtonsAvailableWhenFileLoaded;
128     std::vector<QToolButton *>ButtonsDisabledOnPlayback;
129     std::vector<QPushButton *>PushButtonsAvailableWhenFileLoaded;
130     std::vector<QPushButton *>PushButtonsDisabledOnPlayback;
131 
132     ADM_dragState dragState;
133     QTimer dragTimer;
134     const  std::vector<IScriptEngine*>& _scriptEngines;
135 
136     void addScriptDirToMenu(QMenu* scriptMenu, const QString& dir, const QStringList& fileExts);
137     void addScriptEnginesToFileMenu(std::vector<MenuEntry>& fileMenu);
138     void addScriptShellsToToolsMenu(vector<MenuEntry>& toolMenu);
139     void addScriptReferencesToHelpMenu();
140     void addSessionRestoreToRecentMenu(vector<MenuEntry>& menu);
141     bool buildMyMenu(void);
142     bool buildMenu(QMenu *root,MenuEntry *menu, int nb);
143     void buildRecentMenu(QMenu *menu,std::vector<std::string>files, QAction **actions);
144     void buildActionLists(void);
145     void buildButtonLists(void);
146     void updateCodecWidgetControlsState(void);
147     void widgetsUpdateTooltips(void);
148     void searchMenu(QAction * action,MenuEntry *menu, int nb);
149     void searchRecentFiles(QAction *action, QAction **actionList, int firstEventId);
150 #ifdef ENABLE_EVENT_FILTER
151     bool eventFilter(QObject* watched, QEvent* event);
152 #endif
153     void mousePressEvent(QMouseEvent* event);
154     void dragEnterEvent(QDragEnterEvent *event);
155     void dropEvent(QDropEvent *event);
156     void openFiles(QList<QUrl>);
157     void changeEvent(QEvent* event);
158     /* Zoom control */
159     bool adjustZoom(int width, int height);
160     bool blockResizing;
161     bool blockZoomChanges;
162     bool ignoreResizeEvent; // suppress unwanted zoom changes
163     bool actZoomCalled; // zoom was set to a pre-defined fraction by a menu action
164     int  threshold; // track how much the window was resized
165     /* allow to copy current pts to clipboard using a keyboard shortcut for convenience */
166     void currentTimeToClipboard(void);
167 
168 public slots:
169     void updateAvailableSlot(int version, std::string date, std::string url);
170     void dragTimerTimeout(void);
171     void setRefreshCap(void);
actionSlot(Action a)172     void actionSlot(Action a)
173     {
174         if(a==ACT_PlayAvi) // ugly
175         {
176             playing=1-playing;
177             setMenuItemsEnabledState();
178             playing=1-playing;
179         }
180         HandleAction(a);
181         setMenuItemsEnabledState();
182     }
sendAction(Action a)183     void sendAction(Action a)
184     {
185         //printf("Sending internal event %d\n",(int)a);
186         emit actionSignal(a);
187     }
188     void timeChanged(int);
189     void checkChanged(int);
190     void buttonPressed(void);
191     void toolButtonPressed(bool z);
192     void setMenuItemsEnabledState(void);
193 
194     void comboChanged(int z);
195     void sliderValueChanged(int u);
196     void sliderMoved(int value);
197     void sliderReleased(void);
198     void sliderPressed(void);
199     void sliderWheel(int way);
200     void volumeChange( int u );
201     void audioToggled(bool checked);
202     void previewModeChangedFromMenu(bool status);
203     void previewModeChangedFromToolbar(bool status);
204     void previousIntraFrame(void);
205     void nextIntraFrame(void);
206     void timeChangeFinished(void);
207     void currentFrameChanged(void);
208     void currentTimeChanged(void);
209 
210     void thumbSlider_valueEmitted(int value);
211 
212     void searchFileMenu(QAction * action);
213     void searchRecentMenu(QAction * action);
214     void searchEditMenu(QAction * action);
215     void searchVideoMenu(QAction * action);
216     void searchAudioMenu(QAction * action);
217     void searchHelpMenu(QAction * action);
218     void searchToolMenu(QAction * action);
219     void searchViewMenu(QAction * action);
220     void searchGoMenu(QAction * action);
221     void searchRecentFiles(QAction * action);
222     void searchRecentProjects(QAction * action);
223     void searchToolBar(QAction *);
224 
225     void scriptFileActionHandler();
226     void scriptReferenceActionHandler();
227 
closeEvent(QCloseEvent * event)228     void closeEvent(QCloseEvent *event)
229     {
230         printf("Close event!\n");
231         //QMainWindow::closeEvent(event);
232         sendAction(ACT_EXIT);
233     }
234 
235 signals:
236     void actionSignal(Action a);
237     void updateAvailable(int version,const std::string date,const std::string downloadLink);
238 };
239 #endif	// Q_gui2_h
240