source: trunk/source/interfaces/common/src/G4Qt.cc @ 1253

Last change on this file since 1253 was 1252, checked in by garnier, 14 years ago

avant commit

  • Property svn:mime-type set to text/cpp
File size: 7.5 KB
RevLine 
[481]1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
[1248]27// $Id: G4Qt.cc,v 1.16 2010/04/26 15:46:00 lgarnier Exp $
[867]28// GEANT4 tag $Name:  $
[481]29//
[484]30// L. Garnier
[481]31
[484]32#if defined(G4INTY_BUILD_QT) || defined(G4INTY_USE_QT)
[481]33
34#include <stdlib.h>
35#include <string.h>
36
37#include "G4ios.hh"
38
[484]39#include "G4Qt.hh"
[1252]40// #include "G4UIQt.hh"
[1158]41#include <qwidget.h>
[481]42
[595]43#include <qapplication.h>
[593]44
45
[484]46G4Qt* G4Qt::instance    = NULL;
[481]47
[484]48static G4bool QtInited  = FALSE;
49
[481]50/***************************************************************************/
[484]51G4Qt* G4Qt::getInstance (
[481]52)
53/***************************************************************************/
54/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
55{
[484]56  return G4Qt::getInstance (0,NULL,(char*)"Geant4");
[481]57}
58/***************************************************************************/
[484]59G4Qt* G4Qt::getInstance (
[874]60 int    a_argn
[481]61,char** a_args
62,char*  a_class
63)
64/***************************************************************************/
65/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
66{
67  if (instance==NULL) {
[484]68    instance = new G4Qt(a_argn,a_args,a_class);
[481]69  }
70  return instance;
71}
72/***************************************************************************/
[484]73G4Qt::G4Qt (
[874]74 int    a_argn
[481]75,char** a_args
[989]76 ,char*  /*a_class */
[1163]77 )
[1252]78// :fG4UI(NULL)
[481]79/***************************************************************************/
80/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
81{
[876]82  argn = 0;
83  args = NULL;
84
[1120]85#ifdef G4DEBUG_INTERFACES_COMMON
[571]86  printf("G4Qt::G4Qt try to inited Qt\n");
[608]87#endif
[856]88  // Check if Qt already init in another external app
89  if(qApp) {
[876]90    QtInited  = TRUE;
91    //#if QT_VERSION < 0x040000
92    //      SetMainInteractor (&qApp);
93    //#else
94    SetMainInteractor (qApp);
95    //#endif
96    SetArguments      (a_argn,a_args);
97   
[1120]98#ifdef G4DEBUG_INTERFACES_COMMON
[876]99    printf("G4Qt::G4Qt alredy inited in external \n");
[608]100#endif
[856]101  } else {
[876]102   
[856]103    if(QtInited==FALSE) {  //Qt should be Inited once !
[874]104      // Then two cases :
105      // - It is the first time we create G4UI  (argc!=0)
106      //   -> Inited and register
[876]107      // - It is the first time we create G4VIS  (argc == 0)
[874]108      //   -> Inited and NOT register
[876]109     
110      if (a_argn != 0) {
111        argn = a_argn;
112        args = a_args;
[874]113
114      } else { //argc = 0
115
[876]116        // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
117        // Ex: How to get them from G4Xt ?
118        argn = 1;
119        args = (char **)malloc( 1 * sizeof(char *) );
120        args[0] = (char *)malloc(10 * sizeof(char));
121        strncpy(args[0], "my_app \0", 9);
122      }
[874]123
[876]124      int *p_argn = (int*)malloc(sizeof(int));
125      *p_argn = argn;
[856]126#if QT_VERSION < 0x040000
[889]127      qApp = new QApplication (*p_argn, args);
[856]128#else
[1224]129#ifdef G4DEBUG_INTERFACES_COMMON
[1243]130    printf("G4Qt::G4Qt QAppl \n");
[1224]131#endif
[889]132      new QApplication (*p_argn, args);
[856]133#endif
134      if(!qApp) {
135       
136        G4cout        << "G4Qt : Unable to init Qt." << G4endl;
137      } else {
[876]138        QtInited  = TRUE;
[874]139        if (a_argn != 0) {
[1224]140#ifdef G4DEBUG_INTERFACES_COMMON
141        printf("G4Qt::G4Qt SetMainInteractor\n");
142#endif
[874]143          SetMainInteractor (qApp);
144        }
[876]145        SetArguments      (a_argn,a_args);
[1120]146#ifdef G4DEBUG_INTERFACES_COMMON
[856]147        printf("G4Qt::G4Qt inited Qt END\n");
148#endif
149      }
[481]150    }
151  }
[1120]152#ifdef G4DEBUG_INTERFACES_COMMON
[617]153  if (qApp) {
[1248]154    printf("G4Qt::qApp already exist\n");
[617]155  }  else {
156    printf("G4Qt::qApp not exist\n");
157  }
[608]158#endif
[496]159  //  AddDispatcher     ((G4DispatchFunction)XtDispatchEvent);
[481]160}
161/***************************************************************************/
[484]162G4Qt::~G4Qt (
[481]163)
164/***************************************************************************/
165/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
166{
167  if(this==instance) {
168    instance = NULL;
169  }
170}
171/***************************************************************************/
[484]172G4bool G4Qt::Inited (
[481]173)
174/***************************************************************************/
175/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
176{
[484]177  return QtInited;
[481]178}
179/***************************************************************************/
[850]180/**
181  Si j'ai bien compris, cette fonction ne sert à rien
182 */
[484]183void* G4Qt::GetEvent (
[481]184)
185/***************************************************************************/
186/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
187{
[850]188//FIXME
189//   G4cout        << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
190//  static XEvent  event;
191//  if(appContext==NULL) return NULL;
192//  if(mainApp==NULL) return NULL;
193//  QtAppNextEvent (appContext, &event);
194//  return         &event;
195  printf("*");
[593]196  return 0;
[481]197}
198/***************************************************************************/
[484]199void G4Qt::FlushAndWaitExecution (
[481]200)
201/***************************************************************************/
202/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
203{
[850]204  //  printf("G4Qt::FlushAndWaitExecution ::  Flush ....\n");
[578]205  if(!qApp) return;
206  qApp->processEvents();
[481]207}
208
[1252]209// /***************************************************************************/
210// void G4Qt::SetG4UI (
211//  G4UIQt* ui
212// )
213// /***************************************************************************/
214// /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
215// {
216// #ifdef G4DEBUG_INTERFACES_COMMON
217//     printf("G4Qt::SetG4UI \n");
218// #endif
219//   fG4UI = ui;
220// }
[1158]221
[1252]222// /***************************************************************************/
223// bool G4Qt::AddTabWidget (
224//  QWidget * vis
225// ,QString name
226// ,int sizeX
227// ,int sizeY
228// )
229// /***************************************************************************/
230// /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
231// {
232//   if (fG4UI != NULL) {
233//     //    return fG4UI->AddTabWidget(vis,name,sizeX,sizeY);
234//   }
235//   return false;
236// }
[481]237#endif
238
239
Note: See TracBrowser for help on using the repository browser.