Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/Qt/session 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_session
0005 #define toolx_Qt_session
0006 
0007 // pure Qt code, no GL.
0008 
0009 #include "s2q"
0010 
0011 #include <QtCore/qnamespace.h>
0012 
0013 #if QT_VERSION < 0x050000
0014 #include <QtGui/qapplication.h>
0015 #include <QtGui/qwidget.h>
0016 #else
0017 #include <QtWidgets/qapplication.h>
0018 #include <QtWidgets/qwidget.h>
0019 #endif
0020 
0021 #include <ostream>
0022 #include <vector>
0023 
0024 namespace toolx {
0025 namespace Qt {
0026 
0027 class session {
0028 public:
0029   session(std::ostream& a_out,int& a_argc,char** a_argv)
0030   :m_out(a_out)
0031   ,m_qapp(0)
0032   ,m_own_qapp(false)
0033   {
0034     if(qApp) {
0035       m_qapp = qApp;
0036       m_own_qapp = false;
0037     } else {
0038       m_qapp = new QApplication(a_argc,a_argv);
0039       m_own_qapp = true;
0040     }
0041   }
0042   session(std::ostream& a_out,QApplication* a_qapp)
0043   :m_out(a_out)
0044   ,m_qapp(a_qapp)
0045   ,m_own_qapp(false)
0046   {}
0047   virtual ~session() {
0048     if(m_own_qapp && m_qapp) delete m_qapp;
0049     m_qapp = 0;
0050     m_own_qapp = false;
0051   }
0052 protected:
0053   session(const session& a_from)
0054   :m_out(a_from.m_out)
0055   ,m_qapp(0)
0056   ,m_own_qapp(false)
0057   {}
0058   session& operator=(const session& a_from){
0059     if(&a_from==this) return *this;
0060     return *this;
0061   }
0062 public:
0063   std::ostream& out() const {return m_out;}
0064   bool is_valid() const {return m_qapp?true:false;}
0065   bool steer() {
0066     if(!m_qapp) return false;
0067     m_qapp->exec();
0068     return true;
0069   }
0070   bool sync() {
0071     if(!m_qapp) return false;
0072     m_qapp->processEvents();
0073     return true;
0074   }
0075 public:
0076   QApplication* qapp() const {return m_qapp;}
0077   QWidget* create_window(const char* a_title,int a_x,int a_y,unsigned int a_width,unsigned int a_height) {
0078     if(!m_qapp) return 0;
0079 #if defined(_MSC_VER) || defined(__MINGW32__)
0080     if(a_y<=0) a_y = 60;
0081 #endif
0082     QWidget* top = new QWidget();
0083     top->setWindowFlags(::Qt::CustomizeWindowHint
0084                       | ::Qt::WindowTitleHint
0085                       | ::Qt::WindowMinMaxButtonsHint
0086 //                    | ::Qt::WindowSystemMenuHint
0087 //                    | ::Qt::WindowFullscreenButtonHint
0088     );
0089     top->setGeometry(a_x,a_y,a_width,a_height);
0090     top->setWindowTitle(s2q(a_title));
0091   //top->setAttribute(Qt::WA_DeleteOnClose,false);
0092     return top;
0093   }
0094   void delete_window(QWidget* a_window) const {
0095     if(!m_qapp) return;
0096     delete a_window;
0097   }
0098 protected:
0099   std::ostream& m_out;
0100   QApplication* m_qapp;
0101   bool m_own_qapp;
0102 };
0103 
0104 }}
0105 
0106 
0107 #endif
0108