SGL
qtgui.h
1 /*
2  * File: qtgui.h
3  * -------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2018/09/09
9  * - added doc comments for new documentation generation
10  * @version 2018/08/23
11  * - renamed to qtgui.h
12  * @version 2018/07/03
13  * - initial version
14  */
15 
16 
17 #ifndef _qtgui_h
18 #define _qtgui_h
19 
20 #include <string>
21 #include <QApplication>
22 #include <QObject>
23 
24 #include "gthread.h"
25 #include "gtypes.h"
26 
27 #define EXITING_DUE_TO_WINDOW_CLOSE 106
28 
29 namespace sgl {
30 
31 class GWindow;
32 
33 class QSGLApplication : public QApplication {
34 public:
35  QSGLApplication(int& argc, char *argv[]);
36  bool notify(QObject* receiver, QEvent* e) override;
37 };
38 
39 
47 class QtGui : public QObject {
48  Q_OBJECT
49 
50 public:
54  void exitGraphics(int exitCode = 0);
55 
56 
62  string getApplicationDisplayName() const;
63 
68  int getArgc() const;
69 
74  char** getArgv() const;
75 
81  void initializeQt();
82 
86  static QtGui* instance();
87 
91  void setArgs(int argc, char** argv);
92 
99  void startBackgroundEventLoop(GThunkInt mainFunc, bool exitAfter = true);
100 
101  void startEventLoop(bool exitAfter = true);
102 
103 
104 public slots:
108  void processEventFromQueue();
109 
110 private:
111  Q_DISABLE_COPY(QtGui)
112 
113  QtGui(); // forbid construction
114 
119  QSGLApplication* getApplication();
120 
121  bool _initialized;
122  int _argc;
123  char** _argv;
124 
125  static QSGLApplication* _app;
126  static QThread* _qtGuiThread;
127  static GThread* _studentThread;
128  static QtGui* _instance;
129 
130  friend class GEventQueue;
131  friend class GThread;
132  friend class GWindow;
133 };
134 
135 /*
136  * Code that runs when student thread shuts down.
137  * @private
138  */
139 void studentThreadHasExited(const string& reason);
140 
141 } // namespace sgl
142 
143 #endif // _qtgui_h
void exitGraphics()
Closes all graphics windows and exits from the application without waiting for any additional user in...
Definition: gwindow.cpp:1338
void studentThreadHasExited(string reason)
Definition: qtgui.cpp:166
std::function< int()> GThunkInt
An alias for a function wrapper around a function with no parameters and an int return (such as main(...
Definition: gtypes.h:36
Definition: console.h:45