]> Creatis software - bbtk.git/blob - kernel/src/bbtkQtBlackBox.cxx
Feature #1774
[bbtk.git] / kernel / src / bbtkQtBlackBox.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkQtBlackBox.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.4 $
34 =========================================================================*/
35
36
37 /**
38  *  \file 
39  *  \brief 
40  */
41
42 #ifdef USE_QT
43
44
45 #include "bbtkQtBlackBox.h"
46 //#include "bbtkBlackBoxOutputConnector.h"
47 //#include "bbtkQtBlackBoxDialog.h"
48 #include "bbtkQtBlackBoxDialog.h"
49
50
51 namespace bbtk
52 {
53
54
55
56   //=========================================================================
57   // QtBlackBox
58   //=========================================================================
59
60   //=========================================================================
61   //=========================================================================
62   //=========================================================================
63   //=========================================================================
64   BBTK_BLACK_BOX_IMPLEMENTATION(QtBlackBox,WidgetBlackBox<QWidget>);
65   //=========================================================================
66   
67   //==================================================================    
68   /// Callback for creating a Dialog window (modal)
69   void QtBlackBox::bbCreateDialogWindow()
70   {
71     Qt::CreateQtAppIfNeeded();
72     QtBlackBoxDialog* w = 0;  
73     w = new QtBlackBoxDialog( GetThisPointer<QtBlackBox>(),
74                               0, 
75                               bbGetInputWinTitle() 
76                               + " - bbtk (c) CREATIS LRMN",
77                               bbGetInputWinWidth() , 
78                               bbGetInputWinHeight()  );
79   }
80   //==================================================================    
81
82   //==================================================================    
83   /// Callback for creating a Frame window 
84   void QtBlackBox::bbCreateFrameWindow()
85   {
86     
87     this->bbCreateDialogWindow();
88
89   }
90   //==================================================================    
91
92   //==================================================================    
93   void QtBlackBox::bbUserSetDefaultValues()
94   {
95     bbtkBlackBoxDebugMessage("widget",5,"QtBlackBox::bbUserSetDefaultValues()"<<std::endl);
96     bbmWindow = 0;
97   }
98   //==================================================================    
99
100   //==================================================================    
101   void QtBlackBox::bbUserInitializeProcessing()
102   {
103   }
104   //==================================================================    
105  
106   //==================================================================    
107   void QtBlackBox::bbUserFinalizeProcessing()
108   {
109     bbtkBlackBoxDebugMessage("widget",5,"==> QtBlackBox::bbUserFinalizeProcessing()"<<std::endl);
110     bbDestroyWindow();
111     bbtkBlackBoxDebugMessage("widget",5,"<== QtBlackBox::bbUserFinalizeProcessing()"<<std::endl);
112   }
113   //==================================================================    
114    
115   //==================================================================    
116   void QtBlackBox::bbSetWindow(QWidget* w) 
117   {
118     bbtkBlackBoxDebugMessage("widget",9,"==> QtBlackBox::bbSetWindow("<<w<<")"<<std::endl);
119     if ((bbmWindow != 0)&&(w!=0)) 
120       { 
121         std::cout << "ERRRRRRRROOOOR"<<std::endl; 
122       }
123     bbmWindow = w;
124   }
125   //==================================================================    
126
127   //==================================================================    
128   void QtBlackBox::bbShowWindow()
129   {
130     if ((bbmWindow) && (!bbIsShown()))
131       {
132         bbtkBlackBoxDebugMessage("widget",3,"==> QtBlackBox::bbShowWindow()"
133                          <<std::endl);
134         if (bbGetInputWinDialog()) 
135           {
136             bbmWindow->updateGeometry();
137             ((QDialog*)bbmWindow)->exec();
138             bbDestroyWindow();  
139           }
140         else
141           {
142             bbmWindow->updateGeometry();
143             ((QDialog*)bbmWindow)->exec();
144             bbSetShown(true);
145           } 
146     }
147   }
148   //==================================================================    
149
150   //==================================================================    
151   void QtBlackBox::bbDestroyWindow()
152   {
153     bbtkBlackBoxDebugMessage("widget",3,"==> QtBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
154     if (bbGetWindow()!=NULL) 
155       {
156         //       wxWindow* w = bbGetWindow();
157         //bbSetWindow(0);
158         // WE SHOULD DESTROY THE WINDOW WITH THE Close METHOD
159         // HOWEVER I
160         //w->Close(true);
161         //
162         delete bbGetWindow();
163         bbSetShown(false);
164       }
165     bbtkBlackBoxDebugMessage("widget",3,"<== QtBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
166
167   }
168   //==================================================================    
169
170   //==================================================================
171   //  void QtBlackBox::InitWindowManagerIfNeeded() { Qt::
172   void QtBlackBox::IncNbWindowsAlive() { Qt::IncNbWindowsAlive(); }
173   void QtBlackBox::DecNbWindowsAlive() { Qt::DecNbWindowsAlive(); }
174   int  QtBlackBox::GetNbWindowsAlive() { return Qt::GetNbWindowsAlive(); }
175   bool QtBlackBox::IsSomeWindowAlive() { return Qt::IsSomeWindowAlive(); }
176   
177   void QtBlackBox::IncNbWindowsShown() { Qt::IncNbWindowsShown(); }
178   void QtBlackBox::DecNbWindowsShown() { Qt::DecNbWindowsShown(); }
179   int  QtBlackBox::GetNbWindowsShown() { return Qt::GetNbWindowsShown(); }
180   bool QtBlackBox::IsSomeWindowShown() { return Qt::GetNbWindowsShown(); }
181   //==================================================================
182   
183
184
185
186 }//namespace bbtk
187
188
189 #endif
190