Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef toolx_Qt_session 4 #ifndef toolx_Qt_session 5 #define toolx_Qt_session 5 #define toolx_Qt_session 6 6 7 // pure Qt code, no GL. 7 // pure Qt code, no GL. 8 8 9 #include "s2q" 9 #include "s2q" 10 10 11 #include <QtCore/qnamespace.h> 11 #include <QtCore/qnamespace.h> 12 12 13 #if QT_VERSION < 0x050000 13 #if QT_VERSION < 0x050000 14 #include <QtGui/qapplication.h> 14 #include <QtGui/qapplication.h> 15 #include <QtGui/qwidget.h> 15 #include <QtGui/qwidget.h> 16 #else 16 #else 17 #include <QtWidgets/qapplication.h> 17 #include <QtWidgets/qapplication.h> 18 #include <QtWidgets/qwidget.h> 18 #include <QtWidgets/qwidget.h> 19 #endif 19 #endif 20 20 21 #include <ostream> 21 #include <ostream> 22 #include <vector> 22 #include <vector> 23 23 24 namespace toolx { 24 namespace toolx { 25 namespace Qt { 25 namespace Qt { 26 26 27 class session { 27 class session { 28 public: 28 public: 29 session(std::ostream& a_out,int& a_argc,char 29 session(std::ostream& a_out,int& a_argc,char** a_argv) 30 :m_out(a_out) 30 :m_out(a_out) 31 ,m_qapp(0) 31 ,m_qapp(0) 32 ,m_own_qapp(false) 32 ,m_own_qapp(false) 33 { 33 { 34 if(qApp) { 34 if(qApp) { 35 m_qapp = qApp; 35 m_qapp = qApp; 36 m_own_qapp = false; 36 m_own_qapp = false; 37 } else { 37 } else { 38 m_qapp = new QApplication(a_argc,a_argv) 38 m_qapp = new QApplication(a_argc,a_argv); 39 m_own_qapp = true; 39 m_own_qapp = true; 40 } 40 } 41 } 41 } 42 session(std::ostream& a_out,QApplication* a_ 42 session(std::ostream& a_out,QApplication* a_qapp) 43 :m_out(a_out) 43 :m_out(a_out) 44 ,m_qapp(a_qapp) 44 ,m_qapp(a_qapp) 45 ,m_own_qapp(false) 45 ,m_own_qapp(false) 46 {} 46 {} 47 virtual ~session() { 47 virtual ~session() { 48 if(m_own_qapp && m_qapp) delete m_qapp; 48 if(m_own_qapp && m_qapp) delete m_qapp; 49 m_qapp = 0; 49 m_qapp = 0; 50 m_own_qapp = false; 50 m_own_qapp = false; 51 } 51 } 52 protected: 52 protected: 53 session(const session& a_from) 53 session(const session& a_from) 54 :m_out(a_from.m_out) 54 :m_out(a_from.m_out) 55 ,m_qapp(0) 55 ,m_qapp(0) 56 ,m_own_qapp(false) 56 ,m_own_qapp(false) 57 {} 57 {} 58 session& operator=(const session& a_from){ 58 session& operator=(const session& a_from){ 59 if(&a_from==this) return *this; 59 if(&a_from==this) return *this; 60 return *this; 60 return *this; 61 } 61 } 62 public: 62 public: 63 std::ostream& out() const {return m_out;} 63 std::ostream& out() const {return m_out;} 64 bool is_valid() const {return m_qapp?true:fa 64 bool is_valid() const {return m_qapp?true:false;} 65 bool steer() { 65 bool steer() { 66 if(!m_qapp) return false; 66 if(!m_qapp) return false; 67 m_qapp->exec(); 67 m_qapp->exec(); 68 return true; 68 return true; 69 } 69 } 70 bool sync() { 70 bool sync() { 71 if(!m_qapp) return false; 71 if(!m_qapp) return false; 72 m_qapp->processEvents(); 72 m_qapp->processEvents(); 73 return true; 73 return true; 74 } 74 } 75 public: 75 public: 76 QApplication* qapp() const {return m_qapp;} 76 QApplication* qapp() const {return m_qapp;} 77 QWidget* create_window(const char* a_title,i 77 QWidget* create_window(const char* a_title,int a_x,int a_y,unsigned int a_width,unsigned int a_height) { 78 if(!m_qapp) return 0; 78 if(!m_qapp) return 0; 79 #if defined(_MSC_VER) || defined(__MINGW32__) 79 #if defined(_MSC_VER) || defined(__MINGW32__) 80 if(a_y<=0) a_y = 60; 80 if(a_y<=0) a_y = 60; 81 #endif 81 #endif 82 QWidget* top = new QWidget(); 82 QWidget* top = new QWidget(); 83 top->setWindowFlags(::Qt::CustomizeWindowH 83 top->setWindowFlags(::Qt::CustomizeWindowHint 84 | ::Qt::WindowTitleHint 84 | ::Qt::WindowTitleHint 85 | ::Qt::WindowMinMaxButt 85 | ::Qt::WindowMinMaxButtonsHint 86 // | ::Qt::WindowSystemMenu 86 // | ::Qt::WindowSystemMenuHint 87 // | ::Qt::WindowFullscreenButtonHint 87 // | ::Qt::WindowFullscreenButtonHint 88 ); 88 ); 89 top->setGeometry(a_x,a_y,a_width,a_height) 89 top->setGeometry(a_x,a_y,a_width,a_height); 90 top->setWindowTitle(s2q(a_title)); 90 top->setWindowTitle(s2q(a_title)); 91 //top->setAttribute(Qt::WA_DeleteOnClose,fal 91 //top->setAttribute(Qt::WA_DeleteOnClose,false); 92 return top; 92 return top; 93 } 93 } 94 void delete_window(QWidget* a_window) const 94 void delete_window(QWidget* a_window) const { 95 if(!m_qapp) return; 95 if(!m_qapp) return; 96 delete a_window; 96 delete a_window; 97 } 97 } 98 protected: 98 protected: 99 std::ostream& m_out; 99 std::ostream& m_out; 100 QApplication* m_qapp; 100 QApplication* m_qapp; 101 bool m_own_qapp; 101 bool m_own_qapp; 102 }; 102 }; 103 103 104 }} 104 }} 105 105 106 106 107 #endif 107 #endif 108 108