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 //m_session.sync();
0052 }
0053 }
0054 protected:
0055 sg_viewer(const sg_viewer& a_from)
0056 :parent(a_from)
0057 ,m_session(a_from.m_session)
0058 ,m_shell(0)
0059 ,m_own_shell(false)
0060 ,m_glarea(0)
0061 {}
0062 sg_viewer& operator=(const sg_viewer& a_from){
0063 parent::operator=(a_from);
0064 return *this;
0065 }
0066 public:
0067 bool has_window() const {return m_shell?true:false;} //for SWIG
0068
0069 bool show() {
0070 if(!m_shell) return false;
0071 m_shell->show();
0072 return true;
0073 }
0074
0075 void win_render() {
0076 if(!m_glarea) return;
0077 m_glarea->update();
0078 }
0079 public:
0080 QWidget* shell() {return m_shell;}
0081 void set_own_shell(bool a_value) {m_own_shell = a_value;}
0082 Qt::glarea* glarea() {return m_glarea;}
0083 void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership.
0084 if(!m_glarea) return;
0085 m_glarea->set_device_interactor(a_interactor);
0086 }
0087 void enable_keyboard_focus() {
0088 if(!m_glarea) return;
0089 m_glarea->setFocusPolicy(::Qt::StrongFocus);
0090 }
0091 protected:
0092 session& m_session;
0093 QWidget* m_shell;
0094 bool m_own_shell;
0095 Qt::glarea* m_glarea;
0096 };
0097
0098 }}
0099
0100 #endif
0101