#include <assert.h>
#include "TQtApplication.h"
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include "TSystem.h"
#include "TROOT.h"
#include "TEnv.h"
#include "qmessagebox.h"
static int QVersion(const char *ver) {
QString version = QString::fromLatin1(ver);
return (version.section('.',0,0).toInt()<<16)
+ (version.section('.',1,1).toInt()<<8 )
+ (version.section('.',2,2).toInt() );
}
TQtApplication *TQtApplication::fgQtApplication = 0;
ClassImp(TQtApplication)
TQtApplication::TQtApplication(const char * , int &argc,char **argv)
: fGUIThread(0)
{
assert(!fgQtApplication);
fgQtApplication = this;
CreateGUIThread(argc,argv);
}
TQtApplication::~TQtApplication()
{ }
void TQtApplication::CreateQApplication(int &argc, char ** argv, bool GUIenabled)
{
if (!qApp) {
QApplication::setColorSpec( QApplication::ManyColor );
QString display = gSystem->Getenv("DISPLAY");
if (display.contains("QT_BATCH")) GUIenabled = false;
#ifndef R__WIN32
QCoreApplication::setAttribute(Qt::AA_ImmediateWidgetCreation);
#endif
QString fatalWarnings = gSystem->Getenv("QT_FATAL_WARNINGS");
if (fatalWarnings.contains("1")) {
int argC = 2;
static const char *argV[] = {"root.exe", "-sync" };
qDebug() << "TQtApplication::CreateQApplication: "
<< "ATTENTION !!! "
<< "The env variable \"QT_FATAL_WARNIGNS\" was defined. The special debug option has been turned on."
<< " argc = " << argc << " argv = " << argv[0] << argv[1];
qDebug() << " You may want to restart ROOT with " << argC << " paramaters :"
<< " like this: \"" << argV[0] << " " << argV[1];
new QApplication(argc,argv,GUIenabled);
} else {
new QApplication(argc,argv,GUIenabled);
}
QString fromConfig = "native";
if (gEnv)
fromConfig = gEnv->GetValue("Gui.Style","native");
if (fromConfig != "native" ) QApplication::setStyle(fromConfig);
#ifdef Q_WS_MACX
TTimer *idle = new TTimer(240); idle->TurnOn();
#endif
}
Int_t validQtVersion = QVersion(ROOT_VALID_QT_VERSION);
Int_t thisQtVersion = QVersion(qVersion());
if (thisQtVersion < validQtVersion) {
QString s = QApplication::tr("Executable '%1' was compiled with Qt %2 and requires Qt %3 at least, found Qt %4.")
.arg(qAppName())
.arg(QT_VERSION_STR)
.arg(QString::fromLatin1(ROOT_VALID_QT_VERSION))
.arg(QString::fromLatin1(qVersion()) );
QMessageBox::critical( 0, QApplication::tr("Incompatible Qt Library Error" ), s, QMessageBox::Abort,0 );
qFatal("%s",s.toAscii().data());
} else if (thisQtVersion < QtVersion()) {
QString s = QApplication::tr("Executable '%1' was compiled with Qt %2, found Qt %3.")
.arg(qAppName())
.arg(QT_VERSION_STR)
.arg(QString::fromLatin1(qVersion()) );
QMessageBox::warning( 0, QApplication::tr("Upgrade Qt Library Warning" ), s, QMessageBox::Abort,0 );
qWarning("%s",s.toAscii().data());
}
char *qtPluginPath = gSystem->ConcatFileName(gSystem->Getenv("ROOTSYS"),"/Qt/plugins");
if (!gSystem->AccessPathName(qtPluginPath))
qApp->addLibraryPath(qtPluginPath);
delete [] qtPluginPath;
}
void TQtApplication::CreateGUIThread(int &argc, char **argv)
{
if (gROOT->IsBatch()) {
CreateQApplication(argc,argv,kFALSE);
} else {
CreateQApplication(argc,argv, TRUE);
}
}
TQtApplication *TQtApplication::GetQtApplication(){return fgQtApplication;}
bool TQtApplication::Terminate()
{
if (fgQtApplication) {
TQtApplication *app = fgQtApplication;
fgQtApplication = 0;
delete app;
}
return TRUE;
}
Int_t TQtApplication::QtVersion(){
return QVersion(QT_VERSION_STR);
}
bool TQtApplication::IsThisGuiThread()
{
return true;
}