TQtApplication.cxx

Go to the documentation of this file.
00001 // @(#)root/qt:$Id: TQtApplication.cxx 32595 2010-03-12 16:54:29Z pcanal $
00002 // Author: Valeri Fine   21/01/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * Copyright (C) 2002 by Valeri Fine.                                    *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 // TQtApplication -  Instantiate the Qt system within ROOT environment  //
00016 //                                                                      //
00017 // Instantiate the Qt package by createing Qapplication object if any   //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 
00022 #include <assert.h>
00023 #include "TQtApplication.h"
00024 
00025 #include <QApplication>
00026 #include <QCoreApplication>
00027 #include <QDebug>
00028 
00029 #include "TSystem.h"
00030 
00031 #include "TROOT.h"
00032 #include "TEnv.h"
00033 
00034 #include "qmessagebox.h"
00035 
00036 //________________________________________________________________
00037 static int QVersion(const char *ver) {
00038    // convert the Qversion string into the interger
00039     QString version = QString::fromLatin1(ver);
00040     return   (version.section('.',0,0).toInt()<<16)
00041           +  (version.section('.',1,1).toInt()<<8 )
00042           +  (version.section('.',2,2).toInt()    );
00043 }
00044 
00045 TQtApplication *TQtApplication::fgQtApplication = 0;
00046 
00047 ClassImp(TQtApplication)
00048 //
00049 //______________________________________________________________________________
00050 TQtApplication::TQtApplication(const char * /*appClassName*/, int &argc,char **argv)
00051                 : fGUIThread(0)
00052 {
00053    assert(!fgQtApplication);
00054    fgQtApplication  = this;
00055    CreateGUIThread(argc,argv);
00056 }
00057 //______________________________________________________________________________
00058 TQtApplication::~TQtApplication()
00059 { }
00060 //______________________________________________________________________________
00061 void TQtApplication::CreateQApplication(int &argc, char ** argv, bool GUIenabled)
00062 {
00063   //  Initialize the Qt package
00064   //  Check the QT_BATCH environment variable to disactivate Qt GUI mode
00065    
00066   // QApplication must be created in the proper "GUI" thread
00067   // It may be called from TQtApplicationThread::Run
00068    if (!qApp) {
00069       // QApplication::setColorSpec( QApplication::NormalColor );
00070        QApplication::setColorSpec( QApplication::ManyColor );
00071        QString display = gSystem->Getenv("DISPLAY");
00072        // check the QT_BATCH option
00073        if (display.contains("QT_BATCH")) GUIenabled = false;
00074 #ifndef R__WIN32       
00075        QCoreApplication::setAttribute(Qt::AA_ImmediateWidgetCreation);
00076 #endif       
00077        // Check whether we want to debug the Qt X11
00078        QString fatalWarnings = gSystem->Getenv("QT_FATAL_WARNINGS");
00079        if (fatalWarnings.contains("1")) {
00080           int argC = 2;
00081           static const char *argV[] = {"root.exe", "-sync" };
00082           qDebug() << "TQtApplication::CreateQApplication: "
00083                    << "ATTENTION !!! "
00084                    << "The env variable \"QT_FATAL_WARNIGNS\" was defined. The special debug option has  been turned on." 
00085                    << " argc = " << argc << " argv = " << argv[0] << argv[1];
00086           qDebug() << " You may want to restart ROOT with " << argC << " paramaters :"
00087                    << " like this: \"" << argV[0] << " " << argV[1];
00088 //          new QApplication(argC,argV,GUIenabled);
00089           new QApplication(argc,argv,GUIenabled);
00090        } else {       
00091           new QApplication(argc,argv,GUIenabled);
00092        }
00093        // The string must be one of the QStyleFactory::keys(),
00094        // typically one of
00095        //      "windows", "motif",     "cde",    "motifplus", "platinum", "sgi"
00096        //  and "compact", "windowsxp", "aqua" or "macintosh"
00097       QString fromConfig = "native";
00098       if (gEnv)
00099          fromConfig = gEnv->GetValue("Gui.Style","native");
00100       if (fromConfig != "native" ) QApplication::setStyle(fromConfig);
00101 #ifdef Q_WS_MACX
00102       // create a timer to force the event loop with no X-server
00103       TTimer *idle = new TTimer(240); idle->TurnOn();
00104 #endif
00105    }
00106    // Check the compatibility
00107    Int_t validQtVersion = QVersion(ROOT_VALID_QT_VERSION);
00108    Int_t thisQtVersion  = QVersion(qVersion());
00109    if (thisQtVersion < validQtVersion) {
00110        QString s = QApplication::tr("Executable '%1' was compiled with Qt %2 and requires Qt %3 at least, found Qt %4.")
00111             .arg(qAppName())
00112             .arg(QT_VERSION_STR)
00113             .arg(QString::fromLatin1(ROOT_VALID_QT_VERSION))
00114             .arg(QString::fromLatin1(qVersion()) ); 
00115       QMessageBox::critical( 0, QApplication::tr("Incompatible Qt Library Error" ), s, QMessageBox::Abort,0 );
00116       qFatal("%s",s.toAscii().data());
00117    } else if (thisQtVersion < QtVersion()) {
00118        QString s = QApplication::tr("Executable '%1' was compiled with Qt %2, found Qt %3.")
00119             .arg(qAppName())
00120             .arg(QT_VERSION_STR)
00121             .arg(QString::fromLatin1(qVersion()) ); 
00122       QMessageBox::warning( 0, QApplication::tr("Upgrade Qt Library Warning" ), s, QMessageBox::Abort,0 );
00123       qWarning("%s",s.toAscii().data());
00124    }
00125   
00126    // Add Qt plugin path if  present (it is the case for Windows binary ROOT distribution)
00127    char *qtPluginPath = gSystem->ConcatFileName(gSystem->Getenv("ROOTSYS"),"/Qt/plugins");
00128    if (!gSystem->AccessPathName(qtPluginPath))
00129        qApp->addLibraryPath(qtPluginPath);
00130    delete [] qtPluginPath;
00131 }
00132 //______________________________________________________________________________
00133 void TQtApplication::CreateGUIThread(int &argc, char **argv)
00134 {
00135   // Create GUI thread to Qt event loop
00136    if (gROOT->IsBatch()) {
00137      CreateQApplication(argc,argv,kFALSE);
00138    } else {
00139      CreateQApplication(argc,argv, TRUE);
00140    }
00141 }
00142 //______________________________________________________________________________
00143 TQtApplication *TQtApplication::GetQtApplication(){return fgQtApplication;}
00144 //______________________________________________________________________________
00145 bool TQtApplication::Terminate()
00146 {
00147   // Terminate GUI thread
00148   if (fgQtApplication) {
00149     TQtApplication *app = fgQtApplication;
00150     fgQtApplication = 0;
00151     delete  app;
00152   }
00153   return TRUE;
00154 }
00155 //______________________________________________________________________________
00156 Int_t TQtApplication::QtVersion(){
00157      // The Qt version the package was compiled with
00158    return  QVersion(QT_VERSION_STR);
00159 }
00160 //______________________________________________________________________________
00161 bool TQtApplication::IsThisGuiThread()
00162 {
00163    // Check whether the current thread belongs the GUI
00164   return true;
00165 }

Generated on Tue Jul 5 14:14:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1