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
27 /// Called when the little slider which controls the resolution
28 /// of the main slider is moved (if activated)
29 void OnResolutionOfSlider();
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);
42 Wt::WSlider *mwtSlider;
43 Wt::WSlider *mResolutionOfSlider;
51 //------------------------------------------------------------------------
52 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
57 //-------------------------------------------------------------------------
58 SliderWidget::SliderWidget(Slider* box, Wt::WContainerWidget *parent,
60 bool changeresolution,
67 Wt::WContainerWidget(parent),
71 reactiveOnTrack(reactiveontrack)
74 std::cout<<"Creando SLIDER -- 0 "<<std::endl;
75 Wt::WContainerWidget * panel = this;
76 Wt::WBorderLayout* layout = new Wt::WBorderLayout();
80 mResolutionOfSlider = NULL;
83 Wt::Orientation wtorientation;
84 std::cout<<"Creando SLIDER -- 1 "<<std::endl;
89 wtorientation = Wt::Horizontal;
96 wtorientation = Wt::Vertical;
99 //---------------------------------------------------------------------
100 // 1) Creation of the components of the widget
101 // Any top level sub-widget must have the panel returned by panel
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);
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)
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);
131 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::West);
137 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::South);
143 //---------------------------------------------------------------------
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;
154 //-------------------------------------------------------------------------
158 //-------------------------------------------------------------------------
159 SliderWidget::~SliderWidget()
162 //-------------------------------------------------------------------------
165 //-------------------------------------------------------------------------
166 void SliderWidget::OnResolutionOfSlider()
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;
181 mwtSlider->setMinimum(minTmp);
182 mwtSlider->setMaximum(maxTmp);
185 //-------------------------------------------------------------------------
189 //-------------------------------------------------------------------------
190 void SliderWidget::OnSliderTrack()
193 // When user releases the slider
194 // we update the output of the box
197 mBox->bbSetOutputOut( mwtSlider->value() );
198 mBox->bbSetInputIn( mwtSlider->value() );
200 // and signal that the output has changed
201 mBox->bbSignalOutputModification(std::string("Out"));
205 //-------------------------------------------------------------------------
208 //-------------------------------------------------------------------------
209 void SliderWidget::SetRange(int min, int max)
213 mwtSlider->setMinimum(min);
214 mwtSlider->setMaximum(max);
218 //-------------------------------------------------------------------------
219 void SliderWidget::SetReactiveOnTrack(bool ok)
221 reactiveOnTrack = ok;
227 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Slider);
228 BBTK_BLACK_BOX_IMPLEMENTATION(Slider,bbtk::WtBlackBox);
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)
232 void Slider::Process()
235 bbtkDebugMessage("process",3,
236 "Slider "<<bbGetName()<<" input="
237 <<bbGetInputIn()<<std::endl);
239 // desperate try // JPR
240 if ( bbGetInputMin() != ((SliderWidget*)bbGetOutputWidget())->GetMin() || bbGetInputMax() != ((SliderWidget*)bbGetOutputWidget())->GetMax() )
242 ((SliderWidget*)bbGetOutputWidget())->SetRange(bbGetInputMin(),bbGetInputMax()) ;
245 ((SliderWidget*)bbGetOutputWidget())->SetReactiveOnTrack( bbGetInputReactiveOnTrack() ) ;
247 bbSetOutputOut( bbGetInputIn() );
248 if (bbGetOutputWidget()!=0)
250 ((SliderWidget*)bbGetOutputWidget())->SetValue(bbGetInputIn());
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)
257 void Slider::CreateWidget(Wt::WContainerWidget* parent)
261 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true) { orientation=1; }
264 // std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
265 SliderWidget *w = new SliderWidget(this,
266 parent, //bbGetWxParent(),
268 bbGetInputChangeResolution(),
269 bbtk::std2wt( bbGetInputTitle() ),
273 bbGetInputReactiveOnTrack()
275 // std::cout << "w = "<<w<<std::endl;
276 // w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
278 bbSetOutputWidget( w );
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)
286 void Slider::bbUserSetDefaultValues()
292 bbSetInputOrientation("HORIZONTAL");
293 bbSetInputChangeResolution(false);
294 bbSetInputReactiveOnTrack(false);
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)
301 void Slider::bbUserInitializeProcessing()
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)
308 void Slider::bbUserFinalizeProcessing()