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;
54 //------------------------------------------------------------------------
55 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
60 //-------------------------------------------------------------------------
61 SliderWidget::SliderWidget(Slider* box, Wt::WContainerWidget *parent,
63 bool changeresolution,
70 Wt::WContainerWidget(parent),
75 reactiveOnTrack(reactiveontrack)
78 std::cout<<"Creando SLIDER -- 0 "<<std::endl;
79 Wt::WContainerWidget * panel = this;
80 Wt::WBorderLayout* layout = new Wt::WBorderLayout();
84 mResolutionOfSlider = NULL;
87 Wt::Orientation wtorientation;
88 std::cout<<"Creando SLIDER -- 1 "<<std::endl;
93 wtorientation = Wt::Horizontal;
100 wtorientation = Wt::Vertical;
103 //---------------------------------------------------------------------
104 // 1) Creation of the components of the widget
105 // Any top level sub-widget must have the panel returned by panel
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);
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)
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);
136 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::West);
142 layout->addWidget(mResolutionOfSlider,Wt::WBorderLayout::South);
148 //---------------------------------------------------------------------
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;
161 //-------------------------------------------------------------------------
165 //-------------------------------------------------------------------------
166 SliderWidget::~SliderWidget()
169 //-------------------------------------------------------------------------
172 //-------------------------------------------------------------------------
173 void SliderWidget::OnResolutionOfSlider()
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;
188 mwtSlider->setMinimum(minTmp);
189 mwtSlider->setMaximum(maxTmp);
192 //-------------------------------------------------------------------------
196 //-------------------------------------------------------------------------
197 void SliderWidget::OnSliderTrack()
200 printf("EED SliderWidget::OnSliderTrack value=%d\n", mwtSlider->value() );
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());
211 //-------------------------------------------------------------------------
212 void SliderWidget::OnSliderMove()
214 printf("EED SliderWidget::OnSliderMove value=%d\n",mwtSlider->value() );
216 // When user releases the slider
217 // we update the output of the box
218 if(reactiveOnTrack==true)
220 mBox->bbSetOutputOut( mwtSlider->value() );
221 mBox->bbSetInputIn( mwtSlider->value() );
222 mBox->bbSignalOutputModification(std::string("Out"));
224 textTitle->setText(tTitle + bbtk::std2wt(" :: ") + mwtSlider->valueText());
227 //-------------------------------------------------------------------------
230 //-------------------------------------------------------------------------
231 void SliderWidget::SetRange(int min, int max)
235 mwtSlider->setMinimum(min);
236 mwtSlider->setMaximum(max);
240 //-------------------------------------------------------------------------
241 void SliderWidget::SetReactiveOnTrack(bool ok)
243 reactiveOnTrack = ok;
249 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Slider);
250 BBTK_BLACK_BOX_IMPLEMENTATION(Slider,bbtk::WtBlackBox);
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)
254 void Slider::Process()
257 bbtkDebugMessage("process",3,
258 "Slider "<<bbGetName()<<" input="
259 <<bbGetInputIn()<<std::endl);
262 // desperate try // JPR
263 if ( bbGetInputMin() != ((SliderWidget*)bbGetOutputWidget())->GetMin() || bbGetInputMax() != ((SliderWidget*)bbGetOutputWidget())->GetMax() )
265 ((SliderWidget*)bbGetOutputWidget())->SetRange(bbGetInputMin(),bbGetInputMax()) ;
268 ((SliderWidget*)bbGetOutputWidget())->SetReactiveOnTrack( bbGetInputReactiveOnTrack() ) ;
270 bbSetOutputOut( bbGetInputIn() );
271 if (bbGetOutputWidget()!=0)
273 ((SliderWidget*)bbGetOutputWidget())->SetValue(bbGetInputIn());
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)
280 void Slider::CreateWidget(Wt::WContainerWidget* parent)
284 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true) { orientation=1; }
287 // std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
288 SliderWidget *w = new SliderWidget(this,
289 parent, //bbGetWxParent(),
291 bbGetInputChangeResolution(),
292 bbtk::std2wt( bbGetInputTitle() ),
296 bbGetInputReactiveOnTrack()
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 );
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)
310 void Slider::bbUserSetDefaultValues()
316 bbSetInputOrientation("HORIZONTAL");
317 bbSetInputChangeResolution(false);
318 bbSetInputReactiveOnTrack(false);
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)
325 void Slider::bbUserInitializeProcessing()
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)
332 void Slider::bbUserFinalizeProcessing()