00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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 * , 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
00064
00065
00066
00067
00068 if (!qApp) {
00069
00070 QApplication::setColorSpec( QApplication::ManyColor );
00071 QString display = gSystem->Getenv("DISPLAY");
00072
00073 if (display.contains("QT_BATCH")) GUIenabled = false;
00074 #ifndef R__WIN32
00075 QCoreApplication::setAttribute(Qt::AA_ImmediateWidgetCreation);
00076 #endif
00077
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
00089 new QApplication(argc,argv,GUIenabled);
00090 } else {
00091 new QApplication(argc,argv,GUIenabled);
00092 }
00093
00094
00095
00096
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
00103 TTimer *idle = new TTimer(240); idle->TurnOn();
00104 #endif
00105 }
00106
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
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
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
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
00158 return QVersion(QT_VERSION_STR);
00159 }
00160
00161 bool TQtApplication::IsThisGuiThread()
00162 {
00163
00164 return true;
00165 }