1 /*=========================================================================
3 Module: $RCSfile: bbtkQt.cxx,v $
5 Date: $Date: 2009/04/08 07:56:11 $
6 Version: $Revision: 1.1 $
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 //=========================================================================
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 mgQtApp = new QApplication(argc,&argv);
100 // std::cout << ">>>> mgQtApp.exec()"<<std::endl;
104 // std::cout << "<<<< mgQtApp.exec()"<<std::endl;
105 // wxApp::SetInstance(mgQtApp);
114 //=========================================================================
116 //=========================================================================
117 void Qt::DestroyQtAppIfNeeded()
122 bbtkDebugMessage("wx",1," --> Destructing bbtk QApplication"<<std::endl);
130 //=========================================================================
132 //=========================================================================
133 void Qt::SetTopWindowParent(QWidget* w)
136 if (mgTopWindowParent != 0)
138 bbtkGlobalError("Qt::SetTopWindowParent : top window parent != 0");
140 mgTopWindowParent = w;
143 //=========================================================================
145 //=========================================================================
146 void Qt::CreateTopWindowIfNeeded()
149 if (mgTopWindow!=0) return;
150 bbtkDebugMessage("wx",1," --> Creating bbtk top window"<<std::endl);
152 CreateQtAppIfNeeded();
155 new wxFrame(mgTopWindowParent,
157 _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
160 Qt::SetTopWindow(top);
163 //=========================================================================
165 //=========================================================================
166 void Qt::DestroyTopWindowIfNeeded()
169 if ( (mgNbWindowsAlive==0) &&
170 (mgAutoDestroyTopWindow) )
172 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
173 mgTopWindow->Close();
176 DestroyQtAppIfNeeded();
180 //=========================================================================
182 //=========================================================================
183 void Qt::LoopUntilAllWindowsClose()
187 while (mgTopWindow != 0)
191 bbtkDebugMessage("wx",2,"Qt::Loop "<<i << std::endl);
199 //=========================================================================
201 //=========================================================================
202 QWidget* Qt::GetTopWindow()
205 Qt::CreateTopWindowIfNeeded();
210 //=========================================================================
212 //=========================================================================
213 bool Qt::TopWindowExists()
215 //return (mgTopWindow!=0);
218 //=========================================================================
221 //=========================================================================
222 void Qt::AddSignalObserver(Slot_function_type f)
224 mgQtSignal.connect(f);
226 //=========================================================================
229 //=========================================================================
230 void Qt::SetAutoDestroyTopWindow(bool b)
232 // mgAutoDestroyTopWindow = b;
234 //=========================================================================
236 //=========================================================================
237 void Qt::SetTopWindow(QWidget* w)
242 bbtkGlobalError("wx::SetTopWindow : top window already set !");
247 //=========================================================================
250 //=========================================================================
251 void Qt::IncNbWindowsAlive()
254 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
260 //=========================================================================
262 //=========================================================================
263 void Qt::DecNbWindowsAlive()
266 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
269 DestroyTopWindowIfNeeded();
274 //=========================================================================
276 //=========================================================================
277 void Qt::IncNbWindowsShown()
280 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
286 //=========================================================================
288 //=========================================================================
289 void Qt::DecNbWindowsShown()
292 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
295 DestroyTopWindowIfNeeded();
301 //=========================================================================
304 //=========================================================================
305 int Qt::GetNbWindowsAlive()
307 return mgNbWindowsAlive;
309 //=========================================================================
311 //=========================================================================
312 bool Qt::IsSomeWindowAlive()
314 return (mgNbWindowsAlive>0);
316 //=========================================================================
319 //=========================================================================
320 int Qt::GetNbWindowsShown()
322 return mgNbWindowsShown;
324 //=========================================================================
326 //=========================================================================
327 bool Qt::IsSomeWindowShown()
329 return (mgNbWindowsShown>0);
331 //=========================================================================
334 //=========================================================================
335 Qt::BusyCursor::BusyCursor()
339 if (wxApp::GetInstance()!=0)
341 bbtkDebugMessage("wx",2,
342 "Qt::BusyCursor::BusyCursor() : creating new cursor"
344 mCursor = new wxBusyCursor;
348 Qt::BusyCursor::~BusyCursor()
354 bbtkDebugMessage("wx",2,
355 "Qt::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
359 //=========================================================================
362 //=========================================================================
363 void Qt::ResetCursor()
365 if (!TopWindowExists()) return;
366 bbtkDebugMessage("wx",9,"Qt::ResetCursor()"<<std::endl);
367 while (wxIsBusy()) ::wxEndBusyCursor();
369 //=========================================================================
370 //=========================================================================
371 void Qt::BeginBusyCursor()
373 if (!TopWindowExists()) return;
374 bbtkDebugMessage("wx",9,"Qt::BeginBusyCursor()"<<std::endl);
375 ::wxBeginBusyCursor();
377 //=========================================================================
378 //=========================================================================
379 void Qt::EndBusyCursor()
381 if (!TopWindowExists()) return;
382 bbtkDebugMessage("wx",9,"Qt::EndBusyCursor()"<<std::endl);
385 //=========================================================================
391 //=======================================================================
393 //=========================================================================
396 Qt::BusyCursor::BusyCursor()
399 Qt::BusyCursor::~BusyCursor()
402 //=========================================================================