Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/Qt/sg_viewer 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_sg_viewer
0005 #define toolx_Qt_sg_viewer
0006 
0007 #include "glarea"
0008 
0009 #include "session"
0010 
0011 #include <QtCore/qglobal.h> //For QT_VERSION.
0012 
0013 #if QT_VERSION < 0x050000
0014 #include <QtGui/qboxlayout.h>
0015 #else
0016 #include <QtWidgets/qboxlayout.h>
0017 #endif
0018 
0019 namespace toolx {
0020 namespace Qt {
0021 
0022 class sg_viewer : public sg::GL_viewer {
0023   typedef sg::GL_viewer parent;
0024 public:
0025   sg_viewer(session& a_session,
0026             int a_x = 0,int a_y = 0,
0027             unsigned int a_width = 500,unsigned int a_height = 500,
0028             const std::string& a_win_title = "")
0029   :parent(a_session.out(),a_width,a_height)
0030   ,m_session(a_session)
0031   ,m_shell(0)
0032   ,m_own_shell(false)
0033   ,m_glarea(0)
0034   {
0035     if(!m_session.is_valid()) return; //throw
0036     m_shell = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
0037     if(!m_shell) return; //throw
0038     m_own_shell = true;
0039 
0040     m_glarea = new Qt::glarea(0,*this);
0041 
0042     QVBoxLayout* layout = new QVBoxLayout;
0043     layout->setContentsMargins(0,0,0,0);
0044     layout->addWidget(m_glarea);
0045     m_shell->setLayout(layout);
0046   }
0047   virtual ~sg_viewer() {
0048     if(m_glarea) m_glarea->set_device_interactor(0);
0049     if(m_shell && m_own_shell) {
0050       m_session.delete_window(m_shell);
0051     }
0052   }
0053 protected:
0054   sg_viewer(const sg_viewer& a_from)
0055   :parent(a_from)
0056   ,m_session(a_from.m_session)
0057   ,m_shell(0)
0058   ,m_own_shell(false)
0059   ,m_glarea(0)
0060   {}
0061   sg_viewer& operator=(const sg_viewer& a_from){
0062     parent::operator=(a_from);
0063     return *this;
0064   }
0065 public:
0066   bool has_window() const {return m_shell?true:false;} //for SWIG
0067 
0068   bool show() {
0069     if(!m_shell) return false;
0070     m_shell->show();
0071     return true;
0072   }
0073 
0074   void win_render() {
0075     if(!m_glarea) return;
0076     m_glarea->repaint(); //immediate.
0077     m_session.sync();
0078   }
0079 
0080   void emit_win_render() {
0081     if(!m_glarea) return;
0082     m_glarea->update();  //delayed.
0083   }
0084 
0085   bool window_size(unsigned int& a_w,unsigned int& a_h) {
0086     if(!m_glarea) {a_w = 0;a_h = 0;return false;}
0087     a_w = (unsigned int)m_glarea->width();
0088     a_h = (unsigned int)m_glarea->height();
0089     return true;
0090   }
0091   void render_area_size(unsigned int& a_w,unsigned int& a_h) {
0092     a_w = parent::width();
0093     a_h = parent::height();
0094   }
0095 
0096 public:
0097   QWidget* shell() {return m_shell;}
0098   void set_own_shell(bool a_value) {m_own_shell = a_value;}
0099   Qt::glarea* glarea() {return m_glarea;}
0100   void set_device_interactor(tools::sg::device_interactor* a_interactor) {  //we do not have ownership.
0101     if(!m_glarea) return;
0102     m_glarea->set_device_interactor(a_interactor);
0103   }
0104   void enable_keyboard_focus() {
0105     if(!m_glarea) return;
0106     m_glarea->setFocusPolicy(::Qt::StrongFocus);
0107   }
0108 protected:
0109   session& m_session;
0110   QWidget* m_shell;
0111   bool m_own_shell;
0112   Qt::glarea* m_glarea;
0113 };
0114 
0115 }}
0116 
0117 #endif