2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkQt.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.4 $
34 =========================================================================*/
38 #include "bbtkMessageManager.h"
42 #include <QApplication>
47 //=========================================================================
49 //=========================================================================
51 //=========================================================================
52 static QApplication* mgQtApp = 0;
53 // static wxWindow* mgTopWindow = 0;
54 // static wxWindow* mgTopWindowParent = 0;
55 // static bool mgAutoDestroyTopWindow = true;
56 static int mgNbWindowsAlive = 0;
57 static int mgNbWindowsShown = 0;
58 //=========================================================================
60 //=========================================================================
62 static Qt::Signal_type mgQtSignal;
64 //=========================================================================
67 //=========================================================================
68 // The wxApp class which is used when no user wxApp was created
70 class QtApp : public wxApp
74 int OnExit() { return true; }
76 //=========================================================================
77 IMPLEMENT_APP_NO_MAIN(QtApp);
78 //=========================================================================
83 //See http://www.wxwindows.org/faqgtk.htm#locale
84 setlocale(LC_NUMERIC, "C");
89 //=========================================================================
92 const char* argv = "QApp";
94 //=========================================================================
95 void Qt::CreateQtAppIfNeeded()
99 if (QApplication::instance()==0)
104 bbtkGlobalError("Qt::CreateQtAppIfNeeded() : INTERNAL ERROR ! (QCoreApplication::instance()==0) && (mgQtApp != 0)");
106 bbtkDebugMessage("widget",1," --> Creating bbtk QApplication"<<std::endl);
107 char* aargv = const_cast<char*>(argv);
108 mgQtApp = new QApplication(argc,&aargv);
111 bbtkDebugMessage("widget",9," --> QApplication::instance = "<<QApplication::instance()<<std::endl);
114 std::cout << ">>>> mgQtApp.exec()"<<std::endl;
118 std::cout << "<<<< mgQtApp.exec()"<<std::endl;
123 //=========================================================================
125 //=========================================================================
126 void Qt::DestroyQtAppIfNeeded()
131 bbtkDebugMessage("wx",1," --> Destructing bbtk QApplication"<<std::endl);
139 //=========================================================================
141 //=========================================================================
142 void Qt::SetTopWindowParent(QWidget* w)
145 if (mgTopWindowParent != 0)
147 bbtkGlobalError("Qt::SetTopWindowParent : top window parent != 0");
149 mgTopWindowParent = w;
152 //=========================================================================
154 //=========================================================================
155 void Qt::CreateTopWindowIfNeeded()
158 if (mgTopWindow!=0) return;
159 bbtkDebugMessage("wx",1," --> Creating bbtk top window"<<std::endl);
161 CreateQtAppIfNeeded();
164 new wxFrame(mgTopWindowParent,
166 _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
169 Qt::SetTopWindow(top);
172 //=========================================================================
174 //=========================================================================
175 void Qt::DestroyTopWindowIfNeeded()
178 if ( (mgNbWindowsAlive==0) &&
179 (mgAutoDestroyTopWindow) )
181 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
182 mgTopWindow->Close();
185 DestroyQtAppIfNeeded();
189 //=========================================================================
191 //=========================================================================
192 void Qt::LoopUntilAllWindowsClose()
196 while (mgTopWindow != 0)
200 bbtkDebugMessage("wx",2,"Qt::Loop "<<i << std::endl);
208 //=========================================================================
210 //=========================================================================
211 QWidget* Qt::GetTopWindow()
214 Qt::CreateTopWindowIfNeeded();
219 //=========================================================================
221 //=========================================================================
222 bool Qt::TopWindowExists()
224 //return (mgTopWindow!=0);
227 //=========================================================================
230 //=========================================================================
231 void Qt::AddSignalObserver(Slot_function_type f)
233 mgQtSignal.connect(f);
235 //=========================================================================
238 //=========================================================================
239 void Qt::SetAutoDestroyTopWindow(bool b)
241 // mgAutoDestroyTopWindow = b;
243 //=========================================================================
245 //=========================================================================
246 void Qt::SetTopWindow(QWidget* w)
251 bbtkGlobalError("wx::SetTopWindow : top window already set !");
256 //=========================================================================
259 //=========================================================================
260 void Qt::IncNbWindowsAlive()
263 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
269 //=========================================================================
271 //=========================================================================
272 void Qt::DecNbWindowsAlive()
275 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
278 DestroyTopWindowIfNeeded();
283 //=========================================================================
285 //=========================================================================
286 void Qt::IncNbWindowsShown()
289 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
295 //=========================================================================
297 //=========================================================================
298 void Qt::DecNbWindowsShown()
301 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
304 DestroyTopWindowIfNeeded();
310 //=========================================================================
313 //=========================================================================
314 int Qt::GetNbWindowsAlive()
316 return mgNbWindowsAlive;
318 //=========================================================================
320 //=========================================================================
321 bool Qt::IsSomeWindowAlive()
323 return (mgNbWindowsAlive>0);
325 //=========================================================================
328 //=========================================================================
329 int Qt::GetNbWindowsShown()
331 return mgNbWindowsShown;
333 //=========================================================================
335 //=========================================================================
336 bool Qt::IsSomeWindowShown()
338 return (mgNbWindowsShown>0);
340 //=========================================================================
343 //=========================================================================
344 Qt::BusyCursor::BusyCursor()
348 if (wxApp::GetInstance()!=0)
350 bbtkDebugMessage("wx",2,
351 "Qt::BusyCursor::BusyCursor() : creating new cursor"
353 mCursor = new wxBusyCursor;
357 Qt::BusyCursor::~BusyCursor()
363 bbtkDebugMessage("wx",2,
364 "Qt::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
368 //=========================================================================
371 //=========================================================================
372 void Qt::ResetCursor()
374 if (!TopWindowExists()) return;
375 bbtkDebugMessage("wx",9,"Qt::ResetCursor()"<<std::endl);
376 while (wxIsBusy()) ::wxEndBusyCursor();
378 //=========================================================================
379 //=========================================================================
380 void Qt::BeginBusyCursor()
382 if (!TopWindowExists()) return;
383 bbtkDebugMessage("wx",9,"Qt::BeginBusyCursor()"<<std::endl);
384 ::wxBeginBusyCursor();
386 //=========================================================================
387 //=========================================================================
388 void Qt::EndBusyCursor()
390 if (!TopWindowExists()) return;
391 bbtkDebugMessage("wx",9,"Qt::EndBusyCursor()"<<std::endl);
394 //=========================================================================
400 //=======================================================================
402 //=========================================================================
405 Qt::BusyCursor::BusyCursor()
408 Qt::BusyCursor::~BusyCursor()
411 //=========================================================================