Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef toolx_Qt_zb_viewer 5 #define toolx_Qt_zb_viewer 6 7 #include "pixwin" 8 #include <tools/sg/zb_viewer> 9 10 #include "session" 11 12 #include <QtCore/qglobal.h> //For QT_VERSION. 13 14 #if QT_VERSION < 0x050000 15 #include <QtGui/qboxlayout.h> 16 #else 17 #include <QtWidgets/qboxlayout.h> 18 #endif 19 20 namespace toolx { 21 namespace Qt { 22 23 class zb_viewer: public tools::sg::zb_viewer { 24 typedef tools::sg::zb_viewer parent; 25 typedef pixwin render_area_t; 26 public: 27 zb_viewer(session& a_session, 28 int a_x = 0,int a_y = 0, 29 unsigned int a_width = 500,unsigned int a_height = 500, 30 const std::string& a_win_title = "") 31 :parent(a_session.out(),a_width,a_height) 32 ,m_session(a_session) 33 ,m_shell(0) 34 ,m_own_shell(false) 35 ,m_render_area(0) 36 { 37 if(!m_session.is_valid()) return; //throw 38 m_shell = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height); 39 if(!m_shell) return; //throw 40 m_own_shell = true; 41 42 m_render_area = new render_area_t(0,*this); 43 44 QVBoxLayout* layout = new QVBoxLayout; 45 layout->setContentsMargins(0,0,0,0); 46 layout->addWidget(m_render_area); 47 m_shell->setLayout(layout); 48 } 49 virtual ~zb_viewer() { 50 if(m_render_area) m_render_area->set_device_interactor(0); 51 if(m_shell && m_own_shell) { 52 m_session.delete_window(m_shell); 53 //m_session.sync(); 54 } 55 } 56 protected: 57 zb_viewer(const zb_viewer& a_from) 58 :parent(a_from) 59 ,m_session(a_from.m_session) 60 ,m_shell(0) 61 ,m_own_shell(false) 62 ,m_render_area(0) 63 {} 64 zb_viewer& operator=(const zb_viewer& a_from){ 65 parent::operator=(a_from); 66 return *this; 67 } 68 public: 69 bool has_window() const {return m_shell?true:false;} //for SWIG 70 71 bool show() { 72 if(!m_shell) return false; 73 m_shell->show(); 74 return true; 75 } 76 77 void win_render() { 78 if(!m_render_area) return; 79 //m_render_area->update(); //delayed. 80 m_render_area->repaint(); //immediate. 81 } 82 83 void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership. 84 if(!m_render_area) return; 85 m_render_area->set_device_interactor(a_interactor); 86 } 87 public: 88 QWidget* shell() {return m_shell;} 89 void set_own_shell(bool a_value) {m_own_shell = a_value;} 90 render_area_t* render_area() {return m_render_area;} 91 void enable_keyboard_focus() { 92 if(!m_render_area) return; 93 m_render_area->setFocusPolicy(::Qt::StrongFocus); 94 } 95 protected: 96 session& m_session; 97 QWidget* m_shell; 98 bool m_own_shell; 99 render_area_t* m_render_area; 100 }; 101 102 }} 103 104 105 #endif 106