main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           main.cpp  -  description
00003                              -------------------
00004     begin                : Fri Jul 19 2002
00005     copyright            : (C) 2002-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00049 
00050 
00051 
00052 // C++ header files
00053 #include <cstdlib>
00054 #include <ctime>
00055 
00056 // Qt header files
00057 #include <qapplication.h>
00058 #include <qfont.h>
00059 #include <qbitmap.h>
00060 #include <qimage.h>
00061 #include <qstring.h>
00062 #include <qtextcodec.h>
00063 #include <qgl.h>
00064 
00065 // Xbrabo header files
00066 #include "iconsets.h"
00067 #include "xbrabo.h"
00068 
00070 static void debugHandler(QtMsgType type, const char* message)
00074 {
00075   switch (type) 
00076   {
00077 #ifndef QT_NO_DEBUG // only print out debug and warning messages in debug builds
00078     case QtDebugMsg:   fprintf(stdout, "%s\n", message);
00079                        break;
00080     case QtWarningMsg: fprintf(stderr, "Warning: %s\n", message);
00081                        break;
00082 #endif
00083     case QtFatalMsg:   fprintf(stderr, "FATAL: %s\n", message);
00084                        fprintf(stderr, "Please note the exact message when reporting this.\n");
00085                        fprintf(stderr, "The application will now shut down.\n");
00086                        abort();
00087     default:           // needed in case QT_NO_DEBUG is not defined
00088                        break;
00089   }
00090 }
00091 
00093 int main(int argc, char *argv[])
00095 {
00096   qInstallMsgHandler(debugHandler); // enables to inhibit all debug messages by a single ifdef
00097   QApplication app(argc, argv);
00098 
00099   if (!QGLFormat::hasOpenGL())
00100     qFatal("This system has no working OpenGL support. Exiting...");
00101 
00103   bool showSplash = true;
00104   for(int i = 1; i < argc; i++)
00105   {
00106     if(QString(argv[i]).contains("-nosplash")) 
00107     {
00108       showSplash = false;
00109       break;
00110     }
00111   }
00113   QWidget* splash = NULL;
00114   if(showSplash)
00115   {
00116     //QTime timer;
00117     //timer.restart();
00118     splash = new QWidget(0, 0, Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop | Qt::WX11BypassWM);
00119     QPixmap pm(IconSets::getSplash());
00120     splash->resize(pm.size());
00121     splash->setBackgroundPixmap(pm);
00122     if(pm.mask())
00123       splash->setMask(*pm.mask());
00124     QRect screenRect = app.desktop()->availableGeometry(app.desktop()->primaryScreen());
00125     splash->move(screenRect.width()/2 - 309, screenRect.height()/2 - 193);
00126     splash->show();
00127   } // all stack-allocated variables are deleted here, before the app starts
00128   //qDebug("time needed to show the splash screen: %d ms",timer.restart());
00129 
00130   //QTranslator tor( 0 );
00131   // set the location where your .qm files are in load() below as the last parameter instead of "."
00132   // for development, use "/" to use the english original as
00133   // .qm files are stored in the base project directory.
00134   //tor.load( QString("xbrabo.") + QTextCodec::locale(), "." );
00135   //app.installTranslator( &tor );
00136 
00137   // the random number generator (needed for calculating hydrogen orbitals)
00138   srand(time(NULL));
00139 
00140   Xbrabo* xbrabo = new Xbrabo();
00141   app.setMainWidget(xbrabo);
00142   if(showSplash)
00143   {
00144     xbrabo->show();
00145     app.processEvents(); // otherwise it will not update the screen
00146   }
00147   xbrabo->init(); // this will show the mainwindow being built in case of using the splash screen
00148   if(showSplash)
00149     app.processEvents(); 
00151   for(int i = 1; i < argc; i++)
00152   {
00153     if(QString(argv[i]).right(4) == ".cml")
00154     {
00155       xbrabo->fileOpen(QString(argv[i]));
00156       if(showSplash)
00157         app.processEvents(); 
00158     }
00159   }
00160   if(showSplash)
00161     splash->deleteLater();
00162   //qDebug("time needed to start the application: %d ms",timer.restart());
00163   return app.exec();
00164 }
00165 

Generated on Fri May 19 14:31:55 2006 for Brabosphere by  doxygen 1.4.6-NO