Back to home page

EIC code displayed by LXR

 
 

    


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