Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef toolx_Qt_pixwin 5 #define toolx_Qt_pixwin 6 7 #include <QtCore/qglobal.h> //For QT_VERSION. 8 9 #if QT_VERSION < 0x050000 10 #include <QtGui/qwidget.h> 11 #else 12 #include <QtWidgets/qwidget.h> 13 #endif 14 15 #include <QtGui/qevent.h> 16 #include <QtGui/qpainter.h> 17 18 #include <tools/sg/zb_viewer> 19 #include <tools/sg/device_interactor> 20 21 #ifdef TOOLS_MEM 22 #include <tools/mem> 23 #endif 24 25 namespace toolx { 26 namespace Qt { 27 28 class pixwin : public QWidget 29 { 30 typedef QWidget parent; 31 TOOLS_SCLASS(toolx::Qt::pixwin) 32 public: 33 virtual void resizeEvent(QResizeEvent* a_eve 34 //::printf("debug : toolx::Qt::pixwin::resiz 35 parent::resizeEvent(a_event); 36 m_viewer.set_size(a_event->size().width(), 37 } 38 virtual void paintEvent(QPaintEvent* a_event 39 parent::paintEvent(a_event); 40 if(!m_viewer.render(tools::sg::zb_viewer:: 41 //static size_t s_count = 0;::printf("debug 42 QImage image(tools::vec_data(m_viewer.out_ 43 QPixmap pixmap = QPixmap::fromImage(image) 44 QPainter painter(this); 45 painter.drawPixmap(0,0,pixmap); 46 //parent::after_render(); 47 m_viewer.out_buffer_clear(); 48 } 49 50 virtual void keyPressEvent(QKeyEvent* a_even 51 if(!m_interactor) return; 52 tools::sg::key_down_event _event(convert_k 53 m_interactor->key_press(_event); 54 } 55 virtual void keyReleaseEvent(QKeyEvent* a_ev 56 if(!m_interactor) return; 57 tools::sg::key_up_event _event(convert_key 58 m_interactor->key_release(_event); 59 } 60 virtual void mousePressEvent(QMouseEvent* a_ 61 if(!m_interactor) return; 62 #if QT_VERSION < 0x060000 63 tools::sg::mouse_down_event _event(a_event 64 #else 65 tools::sg::mouse_down_event _event(a_event 66 #endif 67 m_interactor->mouse_press(_event); 68 } 69 virtual void mouseReleaseEvent(QMouseEvent* 70 if(!m_interactor) return; 71 #if QT_VERSION < 0x060000 72 tools::sg::mouse_up_event _event(a_event-> 73 #else 74 tools::sg::mouse_up_event _event(a_event-> 75 #endif 76 m_interactor->mouse_release(_event); 77 } 78 virtual void mouseMoveEvent(QMouseEvent* a_e 79 if(!m_interactor) return; 80 #if QT_VERSION < 0x060000 81 tools::sg::mouse_move_event _event(a_event 82 #else 83 tools::sg::mouse_move_event _event(a_event 84 #endif 85 m_interactor->mouse_move(_event); 86 } 87 //virtual void mouseDoubleClickEvent(QMouseEve 88 // if(!m_interactor) return; 89 // tools::sg::mouse_double_click_event _event 90 // m_interactor->mouse_double_click(_event); 91 //} 92 virtual void wheelEvent(QWheelEvent* a_event 93 if(!m_interactor) return; 94 tools::sg::wheel_rotate_event _event(a_eve 95 m_interactor->wheel_rotate(_event); 96 } 97 98 public: 99 pixwin(QWidget* a_parent,tools::sg::zb_viewe 100 #ifdef TOOLS_MEM 101 tools::mem::increment(s_class().c_str()); 102 #endif 103 } 104 virtual ~pixwin(){ 105 #ifdef TOOLS_MEM 106 tools::mem::decrement(s_class().c_str()); 107 #endif 108 } 109 public: 110 void set_device_interactor(tools::sg::device 111 protected: 112 tools::key_code convert_key(/*Qt::Key*/int a 113 protected: 114 tools::sg::zb_viewer& m_viewer; 115 tools::sg::device_interactor* m_interactor; 116 }; 117 118 }} 119 120 121 #endif