Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef toolx_Qt_glarea 4 #ifndef toolx_Qt_glarea 5 #define toolx_Qt_glarea 5 #define toolx_Qt_glarea 6 6 7 #include "../sg/GL_viewer" 7 #include "../sg/GL_viewer" 8 8 9 #include <QtCore/qglobal.h> //For QT_VERSION. << 10 << 11 #if QT_VERSION < 0x060000 << 12 #include <QtOpenGL/qgl.h> 9 #include <QtOpenGL/qgl.h> 13 #else << 14 #include <QtOpenGLWidgets/qopenglwidget.h> << 15 #endif << 16 << 17 #include <QtGui/qevent.h> 10 #include <QtGui/qevent.h> 18 11 19 #include <tools/sg/device_interactor> 12 #include <tools/sg/device_interactor> 20 #ifdef TOOLS_MEM << 21 #include <tools/mem> << 22 #endif << 23 13 24 namespace toolx { 14 namespace toolx { 25 namespace Qt { 15 namespace Qt { 26 16 27 class glarea << 17 class glarea : public QGLWidget { 28 #if QT_VERSION < 0x060000 << 29 :public QGLWidget << 30 #else << 31 :public QOpenGLWidget << 32 #endif << 33 { << 34 #if QT_VERSION < 0x060000 << 35 typedef QGLWidget parent; 18 typedef QGLWidget parent; >> 19 public: >> 20 virtual void initialieGL() {} >> 21 virtual void resizeGL(int a_w,int a_h){ >> 22 //::printf("debug : resize : %d %d\n",a_w,a_h); >> 23 #if QT_VERSION < 0x050000 36 #else 24 #else 37 using parent = QOpenGLWidget; << 25 m_width = a_w; >> 26 m_height = a_h; 38 #endif 27 #endif 39 TOOLS_SCLASS(toolx::Qt::glarea) << 28 } 40 public: << 29 //virtual void paintGL(); 41 virtual void initializeGL() {} << 42 virtual void paintGL() { 30 virtual void paintGL() { 43 #if QT_VERSION < 0x050000 31 #if QT_VERSION < 0x050000 >> 32 //::printf("debug : toolx::Qt::glarea::paintGL %d %d\n",width(),height()); 44 m_viewer.set_size(width(),height()); 33 m_viewer.set_size(width(),height()); 45 #else 34 #else 46 m_viewer.set_size(devicePixelRatio()*width << 35 //::printf("debug : toolx::Qt::glarea::paintGL %d %d\n",m_width,m_height); >> 36 m_viewer.set_size(m_width,m_height); 47 #endif 37 #endif 48 m_viewer.render(); 38 m_viewer.render(); 49 } 39 } 50 40 51 virtual void keyPressEvent(QKeyEvent* a_even 41 virtual void keyPressEvent(QKeyEvent* a_event) { 52 if(!m_interactor) return; 42 if(!m_interactor) return; 53 tools::sg::key_down_event _event(convert_k << 43 tools::sg::key_down_event event(convert(a_event->key())); 54 m_interactor->key_press(_event); << 44 m_interactor->key_press(event); 55 } 45 } 56 virtual void keyReleaseEvent(QKeyEvent* a_ev 46 virtual void keyReleaseEvent(QKeyEvent* a_event) { 57 if(!m_interactor) return; 47 if(!m_interactor) return; 58 tools::sg::key_up_event _event(convert_key << 48 tools::sg::key_up_event event(convert(a_event->key())); 59 m_interactor->key_release(_event); << 49 m_interactor->key_release(event); 60 } 50 } 61 virtual void mousePressEvent(QMouseEvent* a_ 51 virtual void mousePressEvent(QMouseEvent* a_event) { 62 if(!m_interactor) return; 52 if(!m_interactor) return; 63 #if QT_VERSION < 0x060000 << 53 tools::sg::mouse_down_event event(a_event->x(),a_event->y()); 64 tools::sg::mouse_down_event _event(a_event << 54 m_interactor->mouse_press(event); 65 #else << 66 tools::sg::mouse_down_event _event(a_event << 67 #endif << 68 m_interactor->mouse_press(_event); << 69 } 55 } 70 virtual void mouseReleaseEvent(QMouseEvent* 56 virtual void mouseReleaseEvent(QMouseEvent* a_event) { 71 if(!m_interactor) return; 57 if(!m_interactor) return; 72 #if QT_VERSION < 0x060000 << 58 tools::sg::mouse_up_event event(a_event->x(),a_event->y()); 73 tools::sg::mouse_up_event _event(a_event-> << 59 m_interactor->mouse_release(event); 74 #else << 75 tools::sg::mouse_up_event _event(a_event-> << 76 #endif << 77 m_interactor->mouse_release(_event); << 78 } 60 } 79 virtual void mouseMoveEvent(QMouseEvent* a_e 61 virtual void mouseMoveEvent(QMouseEvent* a_event) { 80 if(!m_interactor) return; 62 if(!m_interactor) return; 81 #if QT_VERSION < 0x060000 << 63 tools::sg::mouse_move_event event(a_event->x(),a_event->y(),0,0,false); 82 tools::sg::mouse_move_event _event(a_event << 64 m_interactor->mouse_move(event); 83 #else << 84 tools::sg::mouse_move_event _event(a_event << 85 #endif << 86 m_interactor->mouse_move(_event); << 87 } 65 } >> 66 //virtual void mouseDoubleClickEvent(QMouseEvent* a_event) { >> 67 // if(!m_interactor) return; >> 68 // tools::sg::mouse_double_click_event event(a_event->x(),a_event->y()); >> 69 // m_interactor->mouse_double_click(event); >> 70 //} 88 virtual void wheelEvent(QWheelEvent* a_event 71 virtual void wheelEvent(QWheelEvent* a_event) { 89 if(!m_interactor) return; 72 if(!m_interactor) return; 90 tools::sg::wheel_rotate_event _event(a_eve << 73 tools::sg::wheel_rotate_event event(a_event->angleDelta().y()); 91 m_interactor->wheel_rotate(_event); << 74 m_interactor->wheel_rotate(event); 92 } 75 } 93 76 94 public: 77 public: 95 glarea(QWidget* a_parent,toolx::sg::GL_viewe << 78 glarea(QWidget* a_parent,toolx::sg::GL_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer),m_interactor(0){} 96 #ifdef TOOLS_MEM << 79 virtual ~glarea(){} 97 tools::mem::increment(s_class().c_str()); << 98 #endif << 99 } << 100 virtual ~glarea(){ << 101 #ifdef TOOLS_MEM << 102 tools::mem::decrement(s_class().c_str()); << 103 #endif << 104 } << 105 public: 80 public: 106 void set_device_interactor(tools::sg::device 81 void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;} //we do not have ownership. 107 protected: 82 protected: 108 tools::key_code convert_key(/*Qt::Key*/int a << 83 tools::key_code convert(/*Qt::Key*/int a_key) {return a_key;} 109 protected: 84 protected: 110 toolx::sg::GL_viewer& m_viewer; 85 toolx::sg::GL_viewer& m_viewer; >> 86 #if QT_VERSION < 0x050000 >> 87 #else >> 88 protected: >> 89 int m_width; >> 90 int m_height; >> 91 #endif 111 tools::sg::device_interactor* m_interactor; 92 tools::sg::device_interactor* m_interactor; 112 }; 93 }; 113 94 114 }} 95 }} 115 << 116 96 117 #endif 97 #endif