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