GlobeEngine
SimpleQTViewerGLWidget.h
Go to the documentation of this file.
1 #ifndef GlobeEngineSimpleQTViewerGLWidget_h
2 #define GlobeEngineSimpleQTViewerGLWidget_h
3 
4 #include "OpenGL_Includes.h"
5 #include "InputControl.h"
6 
7 #include <QLabel>
8 
9 #ifdef __APPLE__
10 # include <QOpenGLTexture>
11 #endif
12 
13 #ifdef GENGINE_QT5
14  #include <QOpenGLDebugLogger>
15  #include <QOpenGLWidget>
16 #else
17  #include <QGLWidget>
18 #endif
19 
20 namespace geQT {
21 #ifdef GENGINE_QT5
22  class SimpleQTViewerGLWidget : public QOpenGLWidget {
23 #else
24  class SimpleQTViewerGLWidget : public QGLWidget {
25 #endif
26  Q_OBJECT
27 
28 public:
31 
32  QSize minimumSizeHint() const;
33  QSize sizeHint() const;
34  void setParentPosition(int _x, int _y);
35 
36  static void setDefaultSurfaceFormatForConfiguration(int _numberOfSamples = 4, int _depthBufferSize = 24, int _stencilBufferSize = 8, int _alphaChannelSize = 0);
37 
38  //void startAnimationLoop();
39  // control UI painting
40  void enableUIPainting(bool _in = true);
41  void disableUIPainting();
42 
43  // cross platform and cross qt version text drawing functions
44  // should only be called within the draw UI function
45  void drawText(vmml::Vector2d _pt, std::string _string, QFont _font);
46 
49 
50 public:
51  // necessary overrides for new widget class
52  virtual void initialize() = 0;
53  virtual void drawGL() = 0;
54  virtual void updateScene() = 0;
55  virtual void drawUI() = 0;
56  virtual void resize(int _width, int _height) = 0;
57 
58  // overrides from QT to handle input events of QTWindow
59  virtual void keyPressEvent(QKeyEvent *e);
60  virtual void keyReleaseEvent(QKeyEvent *e);
61 
62  // Signals comming from the engine
63 signals:
64  void objectSelectionEvent();
65 
66 protected:
67  // overrides from QT to handle graphic events of QT
68  void initializeGL();
69  void paintGL();
70  void resizeGL(int width, int height);
71 
72  // overrides from QT to handle input events of QTWidget
73  virtual void leaveEvent(QEvent * event);
74  virtual void enterEvent(QEvent * event);
75  virtual void wheelEvent(QWheelEvent* event);
76  virtual void mousePressEvent(QMouseEvent *event);
77  virtual void mouseReleaseEvent(QMouseEvent *event);
78  virtual void mouseDoubleClickEvent(QMouseEvent * event);
79  virtual void mouseMoveEvent(QMouseEvent *event);
80 
81  // additional method for QPainter UI painting. This method will call drawUI.
82  void paintUI();
83 
84 protected:
88 
89  // Defines for QPainter drawing on OSX
90 #ifdef __APPLE__
91  QImage* image;
92  QOpenGLTexture* texture;
93  //QOpenGLTexture texture;
94  QSize* paintArea;
95 #endif
96  QPainter* p;
97  QTimer* updateTimer;
98 
99  // Input control
102 
104 
105  // GLContext Information
106 #if defined(_WIN32) || defined(WIN32)
107  HGLRC contextID;
108  HDC hdcID;
109 #endif
110 
111  };
112 }
113 #endif
void paintUI()
Definition: SimpleQTViewerGLWidget.cpp:191
virtual void initialize()=0
ge::InputControl * inputcontrol
Definition: SimpleQTViewerGLWidget.h:100
void setParentPosition(int _x, int _y)
Definition: SimpleQTViewerGLWidget.cpp:68
ge::Engine * engine
Definition: SimpleQTViewerGLWidget.h:101
void paintGL()
Definition: SimpleQTViewerGLWidget.cpp:141
virtual void wheelEvent(QWheelEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:244
int posParentY
Definition: SimpleQTViewerGLWidget.h:87
QTimer * updateTimer
Definition: SimpleQTViewerGLWidget.h:97
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:276
virtual void enterEvent(QEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:239
bool restoreEngineOpenGLContext()
Definition: SimpleQTViewerGLWidget.cpp:130
void enableUIPainting(bool _in=true)
Definition: SimpleQTViewerGLWidget.cpp:322
SimpleQTViewerGLWidget(ge::Engine *_engine, ge::InputControl *_input)
Definition: SimpleQTViewerGLWidget.cpp:48
void initializeGL()
Definition: SimpleQTViewerGLWidget.cpp:84
bool mouseInWidget
Definition: SimpleQTViewerGLWidget.h:85
Definition: SimpleQTViewerGLWidget.h:24
QPainter * p
Definition: SimpleQTViewerGLWidget.h:96
Definition: Engine.h:20
virtual void keyReleaseEvent(QKeyEvent *e)
Definition: SimpleQTViewerGLWidget.cpp:224
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:290
QSize minimumSizeHint() const
Definition: SimpleQTViewerGLWidget.cpp:74
virtual void mousePressEvent(QMouseEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:249
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:262
QSize sizeHint() const
Definition: SimpleQTViewerGLWidget.cpp:79
virtual void updateScene()=0
Definition: ClickableQLabel.h:8
int posParentX
Definition: SimpleQTViewerGLWidget.h:86
void drawText(vmml::Vector2d _pt, std::string _string, QFont _font)
Definition: SimpleQTViewerGLWidget.cpp:197
void resizeGL(int width, int height)
Definition: SimpleQTViewerGLWidget.cpp:205
Definition: InputControl.h:16
virtual void leaveEvent(QEvent *event)
Definition: SimpleQTViewerGLWidget.cpp:233
~SimpleQTViewerGLWidget()
Definition: SimpleQTViewerGLWidget.cpp:62
virtual void keyPressEvent(QKeyEvent *e)
Definition: SimpleQTViewerGLWidget.cpp:215
static void setDefaultSurfaceFormatForConfiguration(int _numberOfSamples=4, int _depthBufferSize=24, int _stencilBufferSize=8, int _alphaChannelSize=0)
Definition: SimpleQTViewerGLWidget.cpp:15
bool paintUIEnabled
Definition: SimpleQTViewerGLWidget.h:103
bool checkIfOpenGLContextActive()
Definition: SimpleQTViewerGLWidget.cpp:114
void disableUIPainting()
Definition: SimpleQTViewerGLWidget.cpp:329
virtual void resize(int _width, int _height)=0