1 /*=========================================================================
3 Module: $RCSfile: bbtkQt.cxx,v $
5 Date: $Date: 2009/05/28 14:22:10 $
6 Version: $Revision: 1.3 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
31 #include "bbtkMessageManager.h"
35 #include <QApplication>
40 //=========================================================================
42 //=========================================================================
44 //=========================================================================
45 static QApplication* mgQtApp = 0;
46 // static wxWindow* mgTopWindow = 0;
47 // static wxWindow* mgTopWindowParent = 0;
48 // static bool mgAutoDestroyTopWindow = true;
49 static int mgNbWindowsAlive = 0;
50 static int mgNbWindowsShown = 0;
51 //=========================================================================
53 //=========================================================================
55 static Qt::Signal_type mgQtSignal;
57 //=========================================================================
60 //=========================================================================
61 // The wxApp class which is used when no user wxApp was created
63 class QtApp : public wxApp
67 int OnExit() { return true; }
69 //=========================================================================
70 IMPLEMENT_APP_NO_MAIN(QtApp);
71 //=========================================================================
76 //See http://www.wxwindows.org/faqgtk.htm#locale
77 setlocale(LC_NUMERIC, "C");
82 //=========================================================================
85 const char* argv = "QApp";
87 //=========================================================================
88 void Qt::CreateQtAppIfNeeded()
92 if (QApplication::instance()==0)
97 bbtkGlobalError("Qt::CreateQtAppIfNeeded() : INTERNAL ERROR ! (QCoreApplication::instance()==0) && (mgQtApp != 0)");
99 bbtkDebugMessage("widget",1," --> Creating bbtk QApplication"<<std::endl);
100 char* aargv = const_cast<char*>(argv);
101 mgQtApp = new QApplication(argc,&aargv);
104 bbtkDebugMessage("widget",9," --> QApplication::instance = "<<QApplication::instance()<<std::endl);
107 std::cout << ">>>> mgQtApp.exec()"<<std::endl;
111 std::cout << "<<<< mgQtApp.exec()"<<std::endl;
116 //=========================================================================
118 //=========================================================================
119 void Qt::DestroyQtAppIfNeeded()
124 bbtkDebugMessage("wx",1," --> Destructing bbtk QApplication"<<std::endl);
132 //=========================================================================
134 //=========================================================================
135 void Qt::SetTopWindowParent(QWidget* w)
138 if (mgTopWindowParent != 0)
140 bbtkGlobalError("Qt::SetTopWindowParent : top window parent != 0");
142 mgTopWindowParent = w;
145 //=========================================================================
147 //=========================================================================
148 void Qt::CreateTopWindowIfNeeded()
151 if (mgTopWindow!=0) return;
152 bbtkDebugMessage("wx",1," --> Creating bbtk top window"<<std::endl);
154 CreateQtAppIfNeeded();
157 new wxFrame(mgTopWindowParent,
159 _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
162 Qt::SetTopWindow(top);
165 //=========================================================================
167 //=========================================================================
168 void Qt::DestroyTopWindowIfNeeded()
171 if ( (mgNbWindowsAlive==0) &&
172 (mgAutoDestroyTopWindow) )
174 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
175 mgTopWindow->Close();
178 DestroyQtAppIfNeeded();
182 //=========================================================================
184 //=========================================================================
185 void Qt::LoopUntilAllWindowsClose()
189 while (mgTopWindow != 0)
193 bbtkDebugMessage("wx",2,"Qt::Loop "<<i << std::endl);
201 //=========================================================================
203 //=========================================================================
204 QWidget* Qt::GetTopWindow()
207 Qt::CreateTopWindowIfNeeded();
212 //=========================================================================
214 //=========================================================================
215 bool Qt::TopWindowExists()
217 //return (mgTopWindow!=0);
220 //=========================================================================
223 //=========================================================================
224 void Qt::AddSignalObserver(Slot_function_type f)
226 mgQtSignal.connect(f);
228 //=========================================================================
231 //=========================================================================
232 void Qt::SetAutoDestroyTopWindow(bool b)
234 // mgAutoDestroyTopWindow = b;
236 //=========================================================================
238 //=========================================================================
239 void Qt::SetTopWindow(QWidget* w)
244 bbtkGlobalError("wx::SetTopWindow : top window already set !");
249 //=========================================================================
252 //=========================================================================
253 void Qt::IncNbWindowsAlive()
256 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
262 //=========================================================================
264 //=========================================================================
265 void Qt::DecNbWindowsAlive()
268 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
271 DestroyTopWindowIfNeeded();
276 //=========================================================================
278 //=========================================================================
279 void Qt::IncNbWindowsShown()
282 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
288 //=========================================================================
290 //=========================================================================
291 void Qt::DecNbWindowsShown()
294 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
297 DestroyTopWindowIfNeeded();
303 //=========================================================================
306 //=========================================================================
307 int Qt::GetNbWindowsAlive()
309 return mgNbWindowsAlive;
311 //=========================================================================
313 //=========================================================================
314 bool Qt::IsSomeWindowAlive()
316 return (mgNbWindowsAlive>0);
318 //=========================================================================
321 //=========================================================================
322 int Qt::GetNbWindowsShown()
324 return mgNbWindowsShown;
326 //=========================================================================
328 //=========================================================================
329 bool Qt::IsSomeWindowShown()
331 return (mgNbWindowsShown>0);
333 //=========================================================================
336 //=========================================================================
337 Qt::BusyCursor::BusyCursor()
341 if (wxApp::GetInstance()!=0)
343 bbtkDebugMessage("wx",2,
344 "Qt::BusyCursor::BusyCursor() : creating new cursor"
346 mCursor = new wxBusyCursor;
350 Qt::BusyCursor::~BusyCursor()
356 bbtkDebugMessage("wx",2,
357 "Qt::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
361 //=========================================================================
364 //=========================================================================
365 void Qt::ResetCursor()
367 if (!TopWindowExists()) return;
368 bbtkDebugMessage("wx",9,"Qt::ResetCursor()"<<std::endl);
369 while (wxIsBusy()) ::wxEndBusyCursor();
371 //=========================================================================
372 //=========================================================================
373 void Qt::BeginBusyCursor()
375 if (!TopWindowExists()) return;
376 bbtkDebugMessage("wx",9,"Qt::BeginBusyCursor()"<<std::endl);
377 ::wxBeginBusyCursor();
379 //=========================================================================
380 //=========================================================================
381 void Qt::EndBusyCursor()
383 if (!TopWindowExists()) return;
384 bbtkDebugMessage("wx",9,"Qt::EndBusyCursor()"<<std::endl);
387 //=========================================================================
393 //=======================================================================
395 //=========================================================================
398 Qt::BusyCursor::BusyCursor()
401 Qt::BusyCursor::~BusyCursor()
404 //=========================================================================