SGL
qtgui.h
1 /*
2  * File: qtgui.h
3  * -------------
4  *
5  * @author Marty Stepp
6  * @version 2018/09/09
7  * - added doc comments for new documentation generation
8  * @version 2018/08/23
9  * - renamed to qtgui.h
10  * @version 2018/07/03
11  * - initial version
12  */
13 
14 
15 #ifndef _qtgui_h
16 #define _qtgui_h
17 
18 #include <string>
19 #include <QApplication>
20 #include <QObject>
21 
22 #include "gthread.h"
23 #include "gtypes.h"
24 
25 #define EXITING_DUE_TO_WINDOW_CLOSE 106
26 
27 class GWindow;
28 
29 class QSGLApplication : public QApplication {
30 public:
31  QSGLApplication(int& argc, char *argv[]);
32  bool notify(QObject* receiver, QEvent* e) override;
33 };
34 
35 
43 class QtGui : public QObject {
44  Q_OBJECT
45 
46 public:
50  void exitGraphics(int exitCode = 0);
51 
52 
58  string getApplicationDisplayName() const;
59 
64  int getArgc() const;
65 
70  char** getArgv() const;
71 
77  void initializeQt();
78 
82  static QtGui* instance();
83 
87  void setArgs(int argc, char** argv);
88 
95  void startBackgroundEventLoop(GThunkInt mainFunc, bool exitAfter = true);
96 
97  void startEventLoop(bool exitAfter = true);
98 
99 
100 public slots:
104  void processEventFromQueue();
105 
106 private:
107  Q_DISABLE_COPY(QtGui)
108 
109  QtGui(); // forbid construction
110 
115  QSGLApplication* getApplication();
116 
117  bool _initialized;
118  int _argc;
119  char** _argv;
120 
121  static QSGLApplication* _app;
122  static QThread* _qtGuiThread;
123  static GThread* _studentThread;
124  static QtGui* _instance;
125 
126  friend class GEventQueue;
127  friend class GThread;
128  friend class GWindow;
129 };
130 
131 namespace sgl {
132 /*
133  * Code that runs when student thread shuts down.
134  * @private
135  */
136 void studentThreadHasExited(const string& reason);
137 } // namespace sgl
138 
139 #endif // _qtgui_h
void studentThreadHasExited(string reason)
Definition: qtgui.cpp:164
Definition: console.h:293
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:98
The GThread class is a utility class containing static methods that allow you to run code on various ...
Definition: gthread.h:111