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

Last change on this file since 861 was 856, checked in by garnier, 17 years ago

now we could have a external QApplication

  • Property svn:mime-type set to text/cpp
File size: 6.3 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//
[608]27// $Id: G4Qt.cc,v 1.7 2007/11/15 18:24:28 lgarnier Exp $
[850]28// GEANT4 tag $Name: HEAD $
[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"
[481]40
[595]41#include <qapplication.h>
[593]42
43
[481]44#define NewString(str) \
45 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
46
47//static void XWidgetIconify (Widget);
48//static void XWidgetUniconify (Widget);
49//static void XDisplaySetWindowToNormalState (Display*,Window);
50
[484]51G4Qt* G4Qt::instance = NULL;
[481]52
[484]53static G4bool QtInited = FALSE;
54//static int argn = 0;
55//static char** args = NULL;
56// static QtAppContext appContext = NULL;
[496]57//static QApplication app = NULL;
[484]58
[481]59/***************************************************************************/
[484]60G4Qt* G4Qt::getInstance (
[481]61)
62/***************************************************************************/
63/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
64{
[484]65 return G4Qt::getInstance (0,NULL,(char*)"Geant4");
[481]66}
67/***************************************************************************/
[484]68G4Qt* G4Qt::getInstance (
[481]69 int a_argn
70,char** a_args
71,char* a_class
72)
73/***************************************************************************/
74/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
75{
76 if (instance==NULL) {
[484]77 instance = new G4Qt(a_argn,a_args,a_class);
[481]78 }
79 return instance;
80}
81/***************************************************************************/
[484]82G4Qt::G4Qt (
[481]83 int a_argn
84,char** a_args
85,char* a_class
86)
87/***************************************************************************/
88/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
89{
[608]90#ifdef GEANT4_QT_DEBUG
[571]91 printf("G4Qt::G4Qt try to inited Qt\n");
[608]92#endif
[856]93 // Check if Qt already init in another external app
94 if(qApp) {
[606]95 QtInited = TRUE;
[850]96 //#if QT_VERSION < 0x040000
97 // SetMainInteractor (&qApp);
98 //#else
[606]99 SetMainInteractor (qApp);
[850]100 //#endif
[606]101 SetArguments (a_argn,a_args);
[608]102#ifdef GEANT4_QT_DEBUG
[856]103 printf("G4Qt::G4Qt alredy inited in external \n");
[608]104#endif
[856]105 } else {
106
107 if(QtInited==FALSE) { //Qt should be Inited once !
108#ifdef GEANT4_QT_DEBUG
109 printf("G4Qt::G4Qt inited Qt\n");
110#endif
111#if QT_VERSION < 0x040000
112 qApp = new QApplication (a_argn, a_args);
113 // QApplication qApp(a_argn, a_args);
114 // if(&qApp == NULL) {
115#else
116 new QApplication (a_argn, a_args);
117#endif
118 if(!qApp) {
119
120 G4cout << "G4Qt : Unable to init Qt." << G4endl;
121 } else {
122 QtInited = TRUE;
123 //#if QT_VERSION < 0x040000
124 // SetMainInteractor (&qApp);
125 //#else
126 SetMainInteractor (qApp);
127 //#endif
128 SetArguments (a_argn,a_args);
129#ifdef GEANT4_QT_DEBUG
130 printf("G4Qt::G4Qt inited Qt END\n");
131#endif
132 }
[481]133 }
134 }
[608]135#ifdef GEANT4_QT_DEBUG
[617]136 if (qApp) {
[606]137 printf("G4Qt::qApp exist\n");
[617]138 } else {
139 printf("G4Qt::qApp not exist\n");
140 }
[608]141#endif
[496]142 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
[481]143}
144/***************************************************************************/
[484]145G4Qt::~G4Qt (
[481]146)
147/***************************************************************************/
148/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
149{
150 if(this==instance) {
151 instance = NULL;
152 }
153}
154/***************************************************************************/
[484]155G4bool G4Qt::Inited (
[481]156)
157/***************************************************************************/
158/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
159{
[484]160 return QtInited;
[481]161}
162/***************************************************************************/
[850]163/**
164 Si j'ai bien compris, cette fonction ne sert à rien
165 */
[484]166void* G4Qt::GetEvent (
[481]167)
168/***************************************************************************/
169/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
170{
[850]171//FIXME
172// G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
173// static XEvent event;
174// if(appContext==NULL) return NULL;
175// if(mainApp==NULL) return NULL;
176// QtAppNextEvent (appContext, &event);
177// return &event;
178 printf("*");
[593]179 return 0;
[481]180}
181/***************************************************************************/
[484]182void G4Qt::FlushAndWaitExecution (
[481]183)
184/***************************************************************************/
185/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
186{
[850]187 // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n");
[578]188 if(!qApp) return;
189 qApp->processEvents();
[481]190}
191
192#endif
193
194
195
Note: See TracBrowser for help on using the repository browser.