Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/Qt/glarea is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef toolx_Qt_glarea
0005 #define toolx_Qt_glarea
0006 
0007 #include <QtCore/qglobal.h> //For QT_VERSION.
0008 
0009 #if QT_VERSION < 0x060000
0010 #include <QtOpenGL/qgl.h>
0011 #else
0012 #include <QtOpenGLWidgets/qopenglwidget.h>
0013 #endif
0014 
0015 #include <QtGui/qevent.h>
0016 
0017 #include "gl_functions"
0018 
0019 #include "../sg/GL_action"
0020 #include "../sg/GL_viewer"
0021 
0022 namespace toolx {
0023 namespace sg {
0024   using GL_action = GL_action_T<toolx::Qt::gl_functions>;
0025   using GL_manager = GL_manager_T<toolx::Qt::gl_functions>;
0026   using GL_viewer = GL_viewer_T<GL_manager,GL_action>;
0027 }}
0028 
0029 #include <tools/sg/device_interactor>
0030 
0031 namespace toolx {
0032 namespace Qt {
0033 
0034 class glarea
0035 #if QT_VERSION < 0x060000
0036 :public QGLWidget
0037 #else
0038 :public QOpenGLWidget
0039 #endif
0040 {
0041 #if QT_VERSION < 0x060000
0042   typedef QGLWidget parent;
0043 #else
0044   using parent = QOpenGLWidget;
0045 #endif
0046   TOOLS_SCLASS(toolx::Qt::glarea)
0047 public:
0048   virtual void initializeGL() {}
0049   virtual void paintGL() {
0050 #if QT_VERSION < 0x050000
0051     m_viewer.set_size(width(),height());
0052 #else
0053     m_viewer.set_size(devicePixelRatio()*width(),devicePixelRatio()*height());
0054 #endif
0055     m_viewer.render();
0056   }
0057 
0058   virtual void keyPressEvent(QKeyEvent* a_event) {
0059     if(!m_interactor) return;
0060     tools::sg::key_down_event _event(convert_key(a_event->key()));
0061     m_interactor->key_press(_event);
0062   }
0063   virtual void keyReleaseEvent(QKeyEvent* a_event) {
0064     if(!m_interactor) return;
0065     tools::sg::key_up_event _event(convert_key(a_event->key()));
0066     m_interactor->key_release(_event);
0067   }
0068   virtual void mousePressEvent(QMouseEvent* a_event) {
0069     if(!m_interactor) return;
0070 
0071     bool shift_modifier = a_event->modifiers() & ::Qt::ShiftModifier;
0072     bool control_modifier = a_event->modifiers() & ::Qt::ControlModifier;
0073 
0074 #if QT_VERSION < 0x060000
0075     tools::sg::mouse_down_event _event(a_event->x(),a_event->y(),shift_modifier,control_modifier);
0076 #else
0077     tools::sg::mouse_down_event _event(a_event->position().x(),a_event->position().y(),shift_modifier,control_modifier);
0078 #endif
0079     m_interactor->mouse_press(_event);
0080   }
0081   virtual void mouseReleaseEvent(QMouseEvent* a_event) {
0082     if(!m_interactor) return;
0083 
0084     bool shift_modifier = a_event->modifiers() & ::Qt::ShiftModifier;
0085     bool control_modifier = a_event->modifiers() & ::Qt::ControlModifier;
0086 
0087 #if QT_VERSION < 0x060000
0088     tools::sg::mouse_up_event _event(a_event->x(),a_event->y(),shift_modifier,control_modifier);
0089 #else
0090     tools::sg::mouse_up_event _event(a_event->position().x(),a_event->position().y(),shift_modifier,control_modifier);
0091 #endif
0092     m_interactor->mouse_release(_event);
0093   }
0094   virtual void mouseMoveEvent(QMouseEvent* a_event) {
0095     if(!m_interactor) return;
0096 
0097     bool shift_modifier = a_event->modifiers() & ::Qt::ShiftModifier;
0098     bool control_modifier = a_event->modifiers() & ::Qt::ControlModifier;
0099 
0100 #if QT_VERSION < 0x060000
0101     tools::sg::mouse_move_event _event(a_event->x(),a_event->y(),shift_modifier,control_modifier,0,0,false);
0102 #else
0103     tools::sg::mouse_move_event _event(a_event->position().x(),a_event->position().y(),shift_modifier,control_modifier,0,0,false);
0104 #endif
0105     m_interactor->mouse_move(_event);
0106   }
0107   virtual void wheelEvent(QWheelEvent* a_event) {
0108     if(!m_interactor) return;
0109 
0110     bool shift_modifier = a_event->modifiers() & ::Qt::ShiftModifier;
0111     bool control_modifier = a_event->modifiers() & ::Qt::ControlModifier;
0112 
0113 #if QT_VERSION < 0x050f00  //5.15.00
0114     tools::sg::wheel_rotate_event _event(a_event->angleDelta().y(),a_event->x(),a_event->y(),shift_modifier,control_modifier);
0115 #else
0116     tools::sg::wheel_rotate_event _event(a_event->angleDelta().y(),a_event->position().x(),a_event->position().y(),shift_modifier,control_modifier);
0117 #endif
0118     m_interactor->wheel_rotate(_event);
0119   }
0120 
0121 public:
0122   glarea(QWidget* a_parent,toolx::sg::GL_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer),m_interactor(0){
0123   }
0124   virtual ~glarea(){
0125   }
0126 public:
0127   void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;} //we do not have ownership.
0128 protected:
0129   tools::key_code convert_key(/*Qt::Key*/int a_key) {return a_key;}
0130 protected:
0131   toolx::sg::GL_viewer& m_viewer;
0132   tools::sg::device_interactor* m_interactor;
0133 };
0134 
0135 }}
0136 
0137 #endif