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 "../sg/GL_viewer"
0008
0009 #include <QtCore/qglobal.h> //For QT_VERSION.
0010
0011 #if QT_VERSION < 0x060000
0012 #include <QtOpenGL/qgl.h>
0013 #else
0014 #include <QtOpenGLWidgets/qopenglwidget.h>
0015 #endif
0016
0017 #include <QtGui/qevent.h>
0018
0019 #include <tools/sg/device_interactor>
0020 #ifdef TOOLS_MEM
0021 #include <tools/mem>
0022 #endif
0023
0024 namespace toolx {
0025 namespace Qt {
0026
0027 class glarea
0028 #if QT_VERSION < 0x060000
0029 :public QGLWidget
0030 #else
0031 :public QOpenGLWidget
0032 #endif
0033 {
0034 #if QT_VERSION < 0x060000
0035 typedef QGLWidget parent;
0036 #else
0037 using parent = QOpenGLWidget;
0038 #endif
0039 TOOLS_SCLASS(toolx::Qt::glarea)
0040 public:
0041 virtual void initializeGL() {}
0042 virtual void paintGL() {
0043 #if QT_VERSION < 0x050000
0044 m_viewer.set_size(width(),height());
0045 #else
0046 m_viewer.set_size(devicePixelRatio()*width(),devicePixelRatio()*height());
0047 #endif
0048 m_viewer.render();
0049 }
0050
0051 virtual void keyPressEvent(QKeyEvent* a_event) {
0052 if(!m_interactor) return;
0053 tools::sg::key_down_event _event(convert_key(a_event->key()));
0054 m_interactor->key_press(_event);
0055 }
0056 virtual void keyReleaseEvent(QKeyEvent* a_event) {
0057 if(!m_interactor) return;
0058 tools::sg::key_up_event _event(convert_key(a_event->key()));
0059 m_interactor->key_release(_event);
0060 }
0061 virtual void mousePressEvent(QMouseEvent* a_event) {
0062 if(!m_interactor) return;
0063 #if QT_VERSION < 0x060000
0064 tools::sg::mouse_down_event _event(a_event->x(),a_event->y());
0065 #else
0066 tools::sg::mouse_down_event _event(a_event->position().x(),a_event->position().y());
0067 #endif
0068 m_interactor->mouse_press(_event);
0069 }
0070 virtual void mouseReleaseEvent(QMouseEvent* a_event) {
0071 if(!m_interactor) return;
0072 #if QT_VERSION < 0x060000
0073 tools::sg::mouse_up_event _event(a_event->x(),a_event->y());
0074 #else
0075 tools::sg::mouse_up_event _event(a_event->position().x(),a_event->position().y());
0076 #endif
0077 m_interactor->mouse_release(_event);
0078 }
0079 virtual void mouseMoveEvent(QMouseEvent* a_event) {
0080 if(!m_interactor) return;
0081 #if QT_VERSION < 0x060000
0082 tools::sg::mouse_move_event _event(a_event->x(),a_event->y(),0,0,false);
0083 #else
0084 tools::sg::mouse_move_event _event(a_event->position().x(),a_event->position().y(),0,0,false);
0085 #endif
0086 m_interactor->mouse_move(_event);
0087 }
0088 virtual void wheelEvent(QWheelEvent* a_event) {
0089 if(!m_interactor) return;
0090 tools::sg::wheel_rotate_event _event(a_event->angleDelta().y());
0091 m_interactor->wheel_rotate(_event);
0092 }
0093
0094 public:
0095 glarea(QWidget* a_parent,toolx::sg::GL_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer),m_interactor(0){
0096 #ifdef TOOLS_MEM
0097 tools::mem::increment(s_class().c_str());
0098 #endif
0099 }
0100 virtual ~glarea(){
0101 #ifdef TOOLS_MEM
0102 tools::mem::decrement(s_class().c_str());
0103 #endif
0104 }
0105 public:
0106 void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;} //we do not have ownership.
0107 protected:
0108 tools::key_code convert_key(/*Qt::Key*/int a_key) {return a_key;}
0109 protected:
0110 toolx::sg::GL_viewer& m_viewer;
0111 tools::sg::device_interactor* m_interactor;
0112 };
0113
0114 }}
0115
0116
0117 #endif