bbtkQt.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkQt.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2009/05/28 14:22:10 $
00006   Version:   $Revision: 1.3 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 #include "bbtkQt.h"
00031 #include "bbtkMessageManager.h"
00032 
00033 #ifdef USE_QT
00034 
00035 #include <QApplication>
00036 
00037 
00038 namespace bbtk
00039 {
00040   //=========================================================================
00041   //  class QtApp;
00042   //=========================================================================
00043 
00044   //=========================================================================
00045   static QApplication* mgQtApp = 0;
00046   //  static wxWindow* mgTopWindow = 0;
00047   //  static wxWindow* mgTopWindowParent = 0;
00048   //  static bool mgAutoDestroyTopWindow = true;
00049   static int mgNbWindowsAlive  = 0;
00050   static int mgNbWindowsShown  = 0;
00051   //=========================================================================
00052 
00053   //=========================================================================
00054   // BBTKWXSIG
00055   static Qt::Signal_type mgQtSignal;
00056   // \BBTKWXSIG
00057   //=========================================================================
00058 
00059  
00060   //=========================================================================
00061   // The wxApp class which is used when no user wxApp was created
00062   /*
00063   class QtApp : public wxApp
00064   {
00065   public:
00066     bool OnInit( );
00067     int  OnExit() { return true; }
00068   };
00069   //=========================================================================
00070   IMPLEMENT_APP_NO_MAIN(QtApp);
00071   //=========================================================================
00072   bool QtApp::OnInit( )
00073   {      
00074     wxApp::OnInit();
00075 #ifdef __WXGTK__
00076     //See http://www.wxwindows.org/faqgtk.htm#locale
00077     setlocale(LC_NUMERIC, "C");
00078 #endif
00079     return true;
00080   }
00081   */
00082   //=========================================================================
00083 
00084   int argc = 1;
00085   const char* argv = "QApp";
00086 
00087   //=========================================================================
00088   void Qt::CreateQtAppIfNeeded()
00089   {
00090     
00091 
00092   if (QApplication::instance()==0)
00093       {
00094 
00095         if (mgQtApp != 0) 
00096           {
00097             bbtkGlobalError("Qt::CreateQtAppIfNeeded() : INTERNAL ERROR ! (QCoreApplication::instance()==0) && (mgQtApp != 0)");
00098           }
00099         bbtkDebugMessage("widget",1,"  --> Creating bbtk QApplication"<<std::endl);
00100         char* aargv = const_cast<char*>(argv);
00101         mgQtApp = new QApplication(argc,&aargv);
00102 
00103 
00104         bbtkDebugMessage("widget",9,"  --> QApplication::instance = "<<QApplication::instance()<<std::endl);
00105 
00106         /*
00107         std::cout << ">>>> mgQtApp.exec()"<<std::endl;
00108         
00109         mgQtApp->exec();
00110 
00111         std::cout << "<<<< mgQtApp.exec()"<<std::endl;
00112         */
00113       }
00114     
00115   }
00116   //=========================================================================
00117 
00118   //=========================================================================
00119   void Qt::DestroyQtAppIfNeeded()
00120   {
00121     /*
00122     if (mgQtApp!= 0) 
00123       {
00124         bbtkDebugMessage("wx",1,"  --> Destructing bbtk QApplication"<<std::endl);
00125         //delete mgQtApp;
00126         //      mgQtApp = 0;
00127         // Uninit wx
00128         //      wxUninitialize();
00129       }
00130     */
00131   }
00132   //=========================================================================
00133 
00134   //=========================================================================  
00135   void Qt::SetTopWindowParent(QWidget* w)
00136   {
00137     /*
00138     if (mgTopWindowParent != 0)
00139       {
00140         bbtkGlobalError("Qt::SetTopWindowParent : top window parent != 0");
00141       }
00142     mgTopWindowParent = w;
00143     */
00144   }
00145   //=========================================================================
00146 
00147   //=========================================================================
00148   void Qt::CreateTopWindowIfNeeded()
00149   {
00150     /*
00151     if (mgTopWindow!=0) return;
00152     bbtkDebugMessage("wx",1,"  --> Creating bbtk top window"<<std::endl);
00153 
00154     CreateQtAppIfNeeded();
00155 
00156     wxWindow* top = 
00157       new wxFrame(mgTopWindowParent,
00158                   -1,
00159                   _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
00160     top->Hide();
00161 
00162     Qt::SetTopWindow(top);
00163     */
00164   }
00165   //=========================================================================
00166 
00167   //=========================================================================
00168   void Qt::DestroyTopWindowIfNeeded()
00169   {
00170     /*
00171     if ( (mgNbWindowsAlive==0) && 
00172          (mgAutoDestroyTopWindow) )
00173       {
00174         bbtkDebugMessage("wx",1,"  --> Destructing bbtk top window"<<std::endl);
00175         mgTopWindow->Close();
00176         mgTopWindow = 0;
00177         
00178         DestroyQtAppIfNeeded();
00179       }
00180     */
00181   } 
00182   //=========================================================================
00183 
00184   //=========================================================================
00185   void Qt::LoopUntilAllWindowsClose()
00186   {
00187     /*
00188     int i = 0;
00189     while (mgTopWindow != 0)
00190       {
00191         if (i % 100 == 0) 
00192           {
00193             bbtkDebugMessage("wx",2,"Qt::Loop "<<i << std::endl);
00194           }
00195         i++;
00196         wxMilliSleep(10);
00197 
00198       }
00199     */
00200   }
00201   //=========================================================================
00202 
00203   //=========================================================================
00204   QWidget* Qt::GetTopWindow() 
00205   { 
00206     /*
00207     Qt::CreateTopWindowIfNeeded();
00208     return mgTopWindow; 
00209     */
00210     return 0;
00211   }
00212   //=========================================================================
00213   
00214   //=========================================================================
00215   bool Qt::TopWindowExists()
00216   {
00217     //return (mgTopWindow!=0);
00218     return true;
00219   }
00220   //=========================================================================
00221 
00222   // BBTKWXSIG
00223   //=========================================================================
00224   void Qt::AddSignalObserver(Slot_function_type f)
00225   {
00226     mgQtSignal.connect(f);
00227   }
00228   //=========================================================================
00229   // \BBTKWXSIG
00230 
00231   //=========================================================================
00232   void Qt::SetAutoDestroyTopWindow(bool b)
00233   {
00234     // mgAutoDestroyTopWindow = b;
00235   }
00236   //=========================================================================
00237   
00238   //=========================================================================
00239   void Qt::SetTopWindow(QWidget* w) 
00240   {
00241     /*
00242     if ( mgTopWindow ) 
00243       {
00244         bbtkGlobalError("wx::SetTopWindow : top window already set !");
00245       } 
00246     mgTopWindow = w;
00247     */
00248   }
00249   //=========================================================================
00250 
00251 
00252   //=========================================================================
00253   void Qt::IncNbWindowsAlive() 
00254   { 
00255     mgNbWindowsAlive++; 
00256     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
00257                      <<std::endl);
00258     // BBTKWXSIG
00259     mgQtSignal();
00260     // \BBTKWXSIG
00261   }
00262   //=========================================================================
00263 
00264   //=========================================================================
00265   void Qt::DecNbWindowsAlive()
00266   { 
00267     mgNbWindowsAlive--; 
00268     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
00269                      <<std::endl);
00270 
00271     DestroyTopWindowIfNeeded();
00272      // BBTKWXSIG
00273     mgQtSignal();
00274     // \BBTKWXSIG
00275   }
00276   //=========================================================================
00277   
00278   //=========================================================================
00279   void Qt::IncNbWindowsShown() 
00280   { 
00281     mgNbWindowsShown++; 
00282     bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
00283                      <<std::endl);
00284     // BBTKWXSIG
00285     mgQtSignal();
00286     // \BBTKWXSIG
00287   }
00288   //=========================================================================
00289 
00290   //=========================================================================
00291   void Qt::DecNbWindowsShown()
00292   { 
00293     mgNbWindowsShown--; 
00294     bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
00295                      <<std::endl);
00296 
00297     DestroyTopWindowIfNeeded();
00298 
00299     // BBTKWXSIG
00300     mgQtSignal();
00301     // \BBTKWXSIG
00302   }
00303   //=========================================================================
00304 
00305 
00306   //=========================================================================
00307   int  Qt::GetNbWindowsAlive() 
00308   { 
00309     return mgNbWindowsAlive; 
00310   }
00311   //=========================================================================
00312   
00313   //=========================================================================
00314   bool Qt::IsSomeWindowAlive() 
00315   { 
00316     return (mgNbWindowsAlive>0);
00317   }
00318   //=========================================================================
00319   
00320   
00321   //=========================================================================
00322   int  Qt::GetNbWindowsShown() 
00323   { 
00324     return mgNbWindowsShown; 
00325   }
00326   //=========================================================================
00327   
00328   //=========================================================================
00329   bool Qt::IsSomeWindowShown() 
00330   { 
00331     return (mgNbWindowsShown>0);
00332   }
00333   //=========================================================================
00334   
00335 
00336   //=========================================================================
00337   Qt::BusyCursor::BusyCursor()
00338   {
00339     /*
00340     mCursor = 0;
00341     if (wxApp::GetInstance()!=0) 
00342       {         
00343         bbtkDebugMessage("wx",2,
00344                          "Qt::BusyCursor::BusyCursor() : creating new cursor"
00345                          <<std::endl);
00346         mCursor = new wxBusyCursor; 
00347     }
00348     */
00349   }
00350   Qt::BusyCursor::~BusyCursor()
00351   {
00352     /*
00353     if (mCursor)
00354       { 
00355         delete mCursor;
00356         bbtkDebugMessage("wx",2,
00357                          "Qt::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
00358       }
00359     */
00360   }
00361   //=========================================================================
00362 
00363   /*
00364   //=========================================================================
00365   void Qt::ResetCursor() 
00366   {
00367     if (!TopWindowExists()) return;
00368     bbtkDebugMessage("wx",9,"Qt::ResetCursor()"<<std::endl);
00369     while (wxIsBusy()) ::wxEndBusyCursor();
00370   }
00371   //=========================================================================
00372   //=========================================================================
00373   void Qt::BeginBusyCursor() 
00374   {
00375     if (!TopWindowExists()) return;
00376     bbtkDebugMessage("wx",9,"Qt::BeginBusyCursor()"<<std::endl);
00377     ::wxBeginBusyCursor();
00378   }
00379   //=========================================================================
00380   //=========================================================================
00381   void Qt::EndBusyCursor()
00382   {
00383     if (!TopWindowExists()) return;
00384     bbtkDebugMessage("wx",9,"Qt::EndBusyCursor()"<<std::endl);
00385     ::wxEndBusyCursor();
00386   }
00387   //=========================================================================
00388   */
00389 
00390 } // namespace bbtk
00391 
00392 #else
00393 //=======================================================================
00394 // WITHOUT WX
00395 //=========================================================================
00396 namespace bbtk
00397 {
00398   Qt::BusyCursor::BusyCursor()
00399   {
00400   }
00401   Qt::BusyCursor::~BusyCursor()
00402   {
00403   }
00404   //=========================================================================
00405 
00406 } // namespace bbtk
00407 #endif
00408 

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1