1 /*=========================================================================
3 Module: $RCSfile: bbtkQt.cxx,v $
5 Date: $Date: 2009/05/18 10:45:41 $
6 Version: $Revision: 1.2 $
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()
91 if (QApplication::instance()==0)
95 bbtkGlobalError("Qt::CreateQtAppIfNeeded() : INTERNAL ERROR ! (QCoreApplication::instance()==0) && (mgQtApp != 0)");
97 bbtkDebugMessage("qt",1," --> Creating bbtk QApplication"<<std::endl);
98 char* aargv = const_cast<char*>(argv);
99 mgQtApp = new QApplication(argc,&aargv);
101 // std::cout << ">>>> mgQtApp.exec()"<<std::endl;
105 // std::cout << "<<<< mgQtApp.exec()"<<std::endl;
106 // wxApp::SetInstance(mgQtApp);
115 //=========================================================================
117 //=========================================================================
118 void Qt::DestroyQtAppIfNeeded()
123 bbtkDebugMessage("wx",1," --> Destructing bbtk QApplication"<<std::endl);
131 //=========================================================================
133 //=========================================================================
134 void Qt::SetTopWindowParent(QWidget* w)
137 if (mgTopWindowParent != 0)
139 bbtkGlobalError("Qt::SetTopWindowParent : top window parent != 0");
141 mgTopWindowParent = w;
144 //=========================================================================
146 //=========================================================================
147 void Qt::CreateTopWindowIfNeeded()
150 if (mgTopWindow!=0) return;
151 bbtkDebugMessage("wx",1," --> Creating bbtk top window"<<std::endl);
153 CreateQtAppIfNeeded();
156 new wxFrame(mgTopWindowParent,
158 _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
161 Qt::SetTopWindow(top);
164 //=========================================================================
166 //=========================================================================
167 void Qt::DestroyTopWindowIfNeeded()
170 if ( (mgNbWindowsAlive==0) &&
171 (mgAutoDestroyTopWindow) )
173 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
174 mgTopWindow->Close();
177 DestroyQtAppIfNeeded();
181 //=========================================================================
183 //=========================================================================
184 void Qt::LoopUntilAllWindowsClose()
188 while (mgTopWindow != 0)
192 bbtkDebugMessage("wx",2,"Qt::Loop "<<i << std::endl);
200 //=========================================================================
202 //=========================================================================
203 QWidget* Qt::GetTopWindow()
206 Qt::CreateTopWindowIfNeeded();
211 //=========================================================================
213 //=========================================================================
214 bool Qt::TopWindowExists()
216 //return (mgTopWindow!=0);
219 //=========================================================================
222 //=========================================================================
223 void Qt::AddSignalObserver(Slot_function_type f)
225 mgQtSignal.connect(f);
227 //=========================================================================
230 //=========================================================================
231 void Qt::SetAutoDestroyTopWindow(bool b)
233 // mgAutoDestroyTopWindow = b;
235 //=========================================================================
237 //=========================================================================
238 void Qt::SetTopWindow(QWidget* w)
243 bbtkGlobalError("wx::SetTopWindow : top window already set !");
248 //=========================================================================
251 //=========================================================================
252 void Qt::IncNbWindowsAlive()
255 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
261 //=========================================================================
263 //=========================================================================
264 void Qt::DecNbWindowsAlive()
267 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
270 DestroyTopWindowIfNeeded();
275 //=========================================================================
277 //=========================================================================
278 void Qt::IncNbWindowsShown()
281 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
287 //=========================================================================
289 //=========================================================================
290 void Qt::DecNbWindowsShown()
293 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
296 DestroyTopWindowIfNeeded();
302 //=========================================================================
305 //=========================================================================
306 int Qt::GetNbWindowsAlive()
308 return mgNbWindowsAlive;
310 //=========================================================================
312 //=========================================================================
313 bool Qt::IsSomeWindowAlive()
315 return (mgNbWindowsAlive>0);
317 //=========================================================================
320 //=========================================================================
321 int Qt::GetNbWindowsShown()
323 return mgNbWindowsShown;
325 //=========================================================================
327 //=========================================================================
328 bool Qt::IsSomeWindowShown()
330 return (mgNbWindowsShown>0);
332 //=========================================================================
335 //=========================================================================
336 Qt::BusyCursor::BusyCursor()
340 if (wxApp::GetInstance()!=0)
342 bbtkDebugMessage("wx",2,
343 "Qt::BusyCursor::BusyCursor() : creating new cursor"
345 mCursor = new wxBusyCursor;
349 Qt::BusyCursor::~BusyCursor()
355 bbtkDebugMessage("wx",2,
356 "Qt::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
360 //=========================================================================
363 //=========================================================================
364 void Qt::ResetCursor()
366 if (!TopWindowExists()) return;
367 bbtkDebugMessage("wx",9,"Qt::ResetCursor()"<<std::endl);
368 while (wxIsBusy()) ::wxEndBusyCursor();
370 //=========================================================================
371 //=========================================================================
372 void Qt::BeginBusyCursor()
374 if (!TopWindowExists()) return;
375 bbtkDebugMessage("wx",9,"Qt::BeginBusyCursor()"<<std::endl);
376 ::wxBeginBusyCursor();
378 //=========================================================================
379 //=========================================================================
380 void Qt::EndBusyCursor()
382 if (!TopWindowExists()) return;
383 bbtkDebugMessage("wx",9,"Qt::EndBusyCursor()"<<std::endl);
386 //=========================================================================
392 //=======================================================================
394 //=========================================================================
397 Qt::BusyCursor::BusyCursor()
400 Qt::BusyCursor::~BusyCursor()
403 //=========================================================================