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)
4 #include "bbwtSlider.h"
5 #include "bbwtPackage.h"
6 #include "bbtkUtilities.h"
10 class SliderWidget : public Wt::WContainerWidget
13 SliderWidget(Slider* box, Wt::WContainerWidget *parent,
15 bool changeresolution,
20 bool reactiveontrack);
25 /// Called when the slider is moved
28 /// Called when the little slider which controls the resolution
29 /// of the main slider is moved (if activated)
30 void OnResolutionOfSlider();
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);
43 Wt::WSlider *mwtSlider;
44 Wt::WSlider *mResolutionOfSlider;
52 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
54 //------------------------------------------------------------------------
58 //-------------------------------------------------------------------------
59 SliderWidget::SliderWidget(Slider* box, Wt::WContainerWidget *parent,
61 bool changeresolution,
68 Wt::WContainerWidget(parent),
72 reactiveOnTrack(reactiveontrack)
75 std::cout<<"Creando SLIDER -- 0 "<<std::endl;
76 Wt::WContainerWidget * panel = this;
77 Wt::WBorderLayout* layout = new Wt::WBorderLayout();
81 mResolutionOfSlider = NULL;
84 Wt::Orientation wtorientation;
85 std::cout<<"Creando SLIDER -- 1 "<<std::endl;
90 wtorientation = Wt::Horizontal;
97 wtorientation = Wt::Vertical;
100 //---------------------------------------------------------------------
101 // 1) Creation of the components of the widget
102 // Any top level sub-widget must have the panel returned by panel
105 std::cout<<"Creando SLIDER -- 2 "<<std::endl;
106 mwtSlider = new Wt::WSlider(wtorientation);
107 mwtSlider->resize(sizeX,sizeY);
108 mwtSlider->setMinimum(min);
109 mwtSlider->setMaximum(max);
110 mwtSlider->setValue(value);
111 mwtSlider->setTickPosition(Wt::WSlider::TicksBothSides);
112 //mwtSlider->setValueText(title);
113 mwtSlider->valueChanged().connect(this,&SliderWidget::OnSliderTrack);
114 mwtSlider->sliderMoved().connect(this,&SliderWidget::OnSliderMove);
117 // If asked : creation of the other little slider which allows to change
118 // the resolution of the main slider
119 std::cout<<"Creando SLIDER -- 3 "<<std::endl;
120 if (changeresolution==true)
122 // has panel for parent too
123 mResolutionOfSlider = new Wt::WSlider(Wt::Vertical);
124 mResolutionOfSlider->setMinimum(1);
125 mResolutionOfSlider->setMaximum(8);
126 mResolutionOfSlider->setValue(5);
127 mResolutionOfSlider->valueChanged().connect(this,&SliderWidget::OnResolutionOfSlider);
128 mResolutionOfSlider->resize(5,10);
132 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::West);
138 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::South);
144 //---------------------------------------------------------------------
146 //---------------------------------------------------------------------
147 // 2) Insertion of the components in the window
148 std::cout<<"Creando SLIDER -- 4 "<<std::endl;
149 layout->addWidget(new Wt::WText(title),Wt::WBorderLayout::North);
150 layout->addWidget(mwtSlider,Wt::WBorderLayout::Center);
151 std::cout<<"Creando SLIDER -- 5 "<<std::endl;
152 // Insert the sizer in the main panel and refresh the layout
153 panel->setLayout(layout);
154 std::cout<<"Creando SLIDER -- 6 "<<std::endl;
156 //-------------------------------------------------------------------------
160 //-------------------------------------------------------------------------
161 SliderWidget::~SliderWidget()
164 //-------------------------------------------------------------------------
167 //-------------------------------------------------------------------------
168 void SliderWidget::OnResolutionOfSlider()
170 int value = mwtSlider->value();
171 int delta = (int) (pow((double) 4 ,(double) mResolutionOfSlider->value() ));
172 int minTmp = value - delta/2;
173 int maxTmp = value + delta/2;
183 mwtSlider->setMinimum(minTmp);
184 mwtSlider->setMaximum(maxTmp);
187 //-------------------------------------------------------------------------
191 //-------------------------------------------------------------------------
192 void SliderWidget::OnSliderTrack()
195 // When user releases the slider
196 // we update the output of the box
199 mBox->bbSetOutputOut( mwtSlider->value() );
200 mBox->bbSetInputIn( mwtSlider->value() );
202 // and signal that the output has changed
203 mBox->bbSignalOutputModification(std::string("Out"));
208 //-------------------------------------------------------------------------
209 void SliderWidget::OnSliderMove()
212 // When user releases the slider
213 // we update the output of the box
216 mBox->bbSetOutputOut( mwtSlider->value() );
217 mBox->bbSetInputIn( mwtSlider->value() );
219 // and signal that the output has changed
220 mBox->bbSignalOutputModification(std::string("Out"));
224 //-------------------------------------------------------------------------
227 //-------------------------------------------------------------------------
228 void SliderWidget::SetRange(int min, int max)
232 mwtSlider->setMinimum(min);
233 mwtSlider->setMaximum(max);
237 //-------------------------------------------------------------------------
238 void SliderWidget::SetReactiveOnTrack(bool ok)
240 reactiveOnTrack = ok;
246 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Slider);
247 BBTK_BLACK_BOX_IMPLEMENTATION(Slider,bbtk::WtBlackBox);
249 // 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)
251 void Slider::Process()
254 bbtkDebugMessage("process",3,
255 "Slider "<<bbGetName()<<" input="
256 <<bbGetInputIn()<<std::endl);
259 // desperate try // JPR
260 if ( bbGetInputMin() != ((SliderWidget*)bbGetOutputWidget())->GetMin() || bbGetInputMax() != ((SliderWidget*)bbGetOutputWidget())->GetMax() )
262 ((SliderWidget*)bbGetOutputWidget())->SetRange(bbGetInputMin(),bbGetInputMax()) ;
265 ((SliderWidget*)bbGetOutputWidget())->SetReactiveOnTrack( bbGetInputReactiveOnTrack() ) ;
267 bbSetOutputOut( bbGetInputIn() );
268 if (bbGetOutputWidget()!=0)
270 ((SliderWidget*)bbGetOutputWidget())->SetValue(bbGetInputIn());
275 // 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)
277 void Slider::CreateWidget(Wt::WContainerWidget* parent)
281 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true) { orientation=1; }
284 // std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
285 SliderWidget *w = new SliderWidget(this,
286 parent, //bbGetWxParent(),
288 bbGetInputChangeResolution(),
289 bbtk::std2wt( bbGetInputTitle() ),
293 bbGetInputReactiveOnTrack()
295 // std::cout << "w = "<<w<<std::endl;
296 // w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
298 bbSetOutputWidget( w );
304 // 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)
306 void Slider::bbUserSetDefaultValues()
312 bbSetInputOrientation("HORIZONTAL");
313 bbSetInputChangeResolution(false);
314 bbSetInputReactiveOnTrack(false);
319 // 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)
321 void Slider::bbUserInitializeProcessing()
326 // 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)
328 void Slider::bbUserFinalizeProcessing()