]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtSlider.cxx~
ec59dc405da04832fee0358378a496851e2e042f
[creaWT.git] / wt / bbtk_wt_PKG / src / bbwtSlider.cxx~
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbwtSlider.h"
5 #include "bbwtPackage.h"
6 #include "bbtkUtilities.h"
7 namespace bbwt
8 {
9
10         class SliderWidget : public Wt::WContainerWidget
11         {
12                 public:
13                         SliderWidget(Slider* box, Wt::WContainerWidget *parent,
14                                                                          int orientation,
15                                                                          bool changeresolution,
16                                                                          Wt::WString title,
17                                                                          int vmin,
18                                                                          int vmax,
19                                                                          int value,
20                                                                          bool reactiveontrack);
21
22                         ~SliderWidget();
23
24                 /// Events callbacks
25     /// Called when the slider is moved
26         void OnSliderTrack();
27     /// Called when the little slider which controls the resolution
28     /// of the main slider is moved (if activated)
29         void OnResolutionOfSlider();
30
31     // Accessors
32         void SetValue(int v) { mwtSlider->setValue(v); }
33                   int  GetValue() { return mwtSlider->value(); }
34                   int GetMin() {return min;}
35                   int GetMax() {return max;}    
36         void SetRange(int min, int max);
37                         void SetReactiveOnTrack(bool ok);
38
39
40                 private:
41         Slider*      mBox;
42                   Wt::WSlider     *mwtSlider;
43                   Wt::WSlider     *mResolutionOfSlider;
44                   int          min;
45                   int          max;
46                         bool         reactiveOnTrack;
47
48
49         };
50
51   //------------------------------------------------------------------------
52   //------------------------------------------------------------------------
53   //------------------------------------------------------------------------
54
55   
56     
57   //-------------------------------------------------------------------------
58   SliderWidget::SliderWidget(Slider* box, Wt::WContainerWidget *parent,
59                                                                                                      int orientation,
60                                                                                                      bool changeresolution,
61                                                                                                                  Wt::WString title,
62                                                                                                                  int vmin,
63                                                                                                                  int vmax,
64                                                                                                                  int value,
65                              bool reactiveontrack)
66     : 
67         Wt::WContainerWidget(parent),
68         mBox(box),
69                   min(vmin),
70                   max(vmax),
71                         reactiveOnTrack(reactiveontrack)
72
73   {
74                 std::cout<<"Creando SLIDER  --  0  "<<std::endl;
75     Wt::WContainerWidget * panel = this;
76                 Wt::WBorderLayout* layout = new Wt::WBorderLayout();            
77     
78
79
80     mResolutionOfSlider = NULL;
81
82     int sizeX,sizeY;
83     Wt::Orientation wtorientation;
84                 std::cout<<"Creando SLIDER  --  1  "<<std::endl;
85     if (orientation==0) 
86     {
87                                 sizeX                   = 2; 
88                                 sizeY                   = 40;
89                                 wtorientation           = Wt::Horizontal;
90         
91                 } 
92     else 
93     {
94                         sizeX           = 20;
95                         sizeY           = 2;
96                         wtorientation   = Wt::Vertical;
97     }
98     
99     //---------------------------------------------------------------------
100     // 1) Creation of the components of the widget
101     // Any top level sub-widget must have the panel returned by panel
102     // for parent
103     
104                                 std::cout<<"Creando SLIDER  --  2  "<<std::endl;
105                 mwtSlider = new Wt::WSlider(wtorientation);
106                 mwtSlider->resize(sizeX,sizeY);
107                 mwtSlider->setMinimum(min);
108                 mwtSlider->setMaximum(max);             
109                 mwtSlider->setValue(value);
110                 mwtSlider->setTickPosition(Wt::WSlider::TicksBothSides);
111                 mwtSlider->setValueText(title);
112                 mwtSlider->valueChanged().connect(this,&SliderWidget::OnSliderTrack);
113                 mwtSlider->sliderMoved().connect(this,&SliderWidget::OnSliderTrack);
114
115                
116     // If asked : creation of the other little slider which allows to change 
117     // the resolution of the main slider
118                                 std::cout<<"Creando SLIDER  --  3  "<<std::endl;
119     if (changeresolution==true)
120                 {
121       // has panel for parent too
122       mResolutionOfSlider = new Wt::WSlider(Wt::Vertical);
123                 mResolutionOfSlider->setMinimum(1);
124                         mResolutionOfSlider->setMaximum(8);
125                         mResolutionOfSlider->setValue(5);               
126       mResolutionOfSlider->valueChanged().connect(this,&SliderWidget::OnResolutionOfSlider);    
127                         mResolutionOfSlider->resize(5,10);              
128                         if (orientation==0) 
129                   {
130                                 // HORIZONTAL
131                                 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::West);
132                         
133                   } 
134                   else 
135                   {
136                                 // VERTICAL 
137                                 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::South);
138                                 
139                         }
140
141     }
142
143     //---------------------------------------------------------------------
144
145     //---------------------------------------------------------------------
146     // 2) Insertion of the components in the window
147                 std::cout<<"Creando SLIDER  --  4  "<<std::endl;
148                 layout->addWidget(mwtSlider,Wt::WBorderLayout::Center);
149                                 std::cout<<"Creando SLIDER  --  5  "<<std::endl;
150     // Insert the sizer in the main panel and refresh the layout
151     panel->setLayout(layout);
152                 std::cout<<"Creando SLIDER  --  6  "<<std::endl;
153   }
154   //-------------------------------------------------------------------------
155   
156         
157         
158   //-------------------------------------------------------------------------
159   SliderWidget::~SliderWidget()
160   {
161   }
162   //-------------------------------------------------------------------------
163
164
165   //-------------------------------------------------------------------------
166   void SliderWidget::OnResolutionOfSlider()
167   {
168     int value  = mwtSlider->value();
169     int delta  = (int) (pow((double) 4 ,(double) mResolutionOfSlider->value() ));
170     int minTmp = value - delta/2;
171     int maxTmp = value + delta/2;
172     if (minTmp<min)
173     {
174                         minTmp = min;
175         //              maxTmp = delta;
176     }
177     if (maxTmp>max)
178     {
179                         maxTmp = max;
180     }
181                 mwtSlider->setMinimum(minTmp);
182                 mwtSlider->setMaximum(maxTmp);  
183    
184   }
185   //-------------------------------------------------------------------------
186
187
188
189   //-------------------------------------------------------------------------
190   void SliderWidget::OnSliderTrack()
191   {
192
193     // When user releases the slider 
194     // we update the output of the box
195      if(reactiveOnTrack)
196     {
197                   mBox->bbSetOutputOut( mwtSlider->value() );
198                   mBox->bbSetInputIn( mwtSlider->value() );
199                 }
200     // and signal that the output has changed
201     mBox->bbSignalOutputModification(std::string("Out"));    
202
203   }
204
205   //-------------------------------------------------------------------------
206   
207
208   //-------------------------------------------------------------------------
209   void SliderWidget::SetRange(int min, int max)
210   {
211     this->min = min;
212     this->max = max;
213                 mwtSlider->setMinimum(min);
214                 mwtSlider->setMaximum(max);
215   }
216         
217         
218   //-------------------------------------------------------------------------
219         void SliderWidget::SetReactiveOnTrack(bool ok)
220         {
221                 reactiveOnTrack = ok;
222         }
223  
224
225
226
227         BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Slider);
228         BBTK_BLACK_BOX_IMPLEMENTATION(Slider,bbtk::WtBlackBox);
229         //===== 
230         // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your                            modifications will be lost)
231         //===== 
232         void Slider::Process()
233         {
234
235                 bbtkDebugMessage("process",3,
236                                    "Slider "<<bbGetName()<<" input="
237                                    <<bbGetInputIn()<<std::endl);
238
239                         // desperate try // JPR
240                 if ( bbGetInputMin() != ((SliderWidget*)bbGetOutputWidget())->GetMin() ||  bbGetInputMax() != ((SliderWidget*)bbGetOutputWidget())->GetMax() )       
241                 {    
242                         ((SliderWidget*)bbGetOutputWidget())->SetRange(bbGetInputMin(),bbGetInputMax()) ;
243                 }
244
245                 ((SliderWidget*)bbGetOutputWidget())->SetReactiveOnTrack( bbGetInputReactiveOnTrack() ) ;
246                         
247                 bbSetOutputOut( bbGetInputIn() );
248                 if (bbGetOutputWidget()!=0)
249                 {
250                         ((SliderWidget*)bbGetOutputWidget())->SetValue(bbGetInputIn());
251                  }
252                 
253         }
254 //===== 
255 // Before editing this file, make sure it'sWt::WSlider a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
256 //===== 
257         void Slider::CreateWidget(Wt::WContainerWidget* parent)
258         {
259
260         int orientation=0;
261         if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true)    { orientation=1; }
262     
263     
264     //    std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
265     SliderWidget *w =  new SliderWidget(this, 
266                                         parent, //bbGetWxParent(),
267                                         orientation , 
268                                         bbGetInputChangeResolution(), 
269                                         bbtk::std2wt( bbGetInputTitle() ),
270                                         bbGetInputMin(), 
271                                         bbGetInputMax(),
272                                         bbGetInputIn(),
273                                         bbGetInputReactiveOnTrack()
274                                         ); 
275     //    std::cout << "w = "<<w<<std::endl;
276     //  w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
277           
278     bbSetOutputWidget( w );
279   }
280   
281   
282
283 //===== 
284 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
285 //===== 
286 void Slider::bbUserSetDefaultValues()
287 {
288                 bbSetInputIn(0);
289                 bbSetInputMin(0);
290                 bbSetInputMax(500);
291                 bbSetOutputOut(0);
292                 bbSetInputOrientation("HORIZONTAL");
293                 bbSetInputChangeResolution(false);
294                 bbSetInputReactiveOnTrack(false);
295
296
297 }
298 //===== 
299 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
300 //===== 
301 void Slider::bbUserInitializeProcessing()
302 {
303
304 }
305 //===== 
306 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
307 //===== 
308 void Slider::bbUserFinalizeProcessing()
309 {
310
311 }
312 }
313 // EO namespace bbwt
314
315