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 // When user releases the slider
201 // we update the output of the box
204 mBox->bbSetOutputOut( mwtSlider->value() );
205 mBox->bbSetInputIn( mwtSlider->value() );
207 // and signal that the output has changed
208 mBox->bbSignalOutputModification(std::string("Out"));
209 textTitle->setText(tTitle + bbtk::std2wt(" : ") + mwtSlider->valueText());
213 //-------------------------------------------------------------------------
214 void SliderWidget::OnSliderMove()
217 // When user releases the slider
218 // we update the output of the box
221 mBox->bbSetOutputOut( mwtSlider->value() );
222 mBox->bbSetInputIn( mwtSlider->value() );
224 // and signal that the output has changed
225 mBox->bbSignalOutputModification(std::string("Out"));
226 textTitle->setText(tTitle + bbtk::std2wt(" : ") + mwtSlider->valueText());
230 //-------------------------------------------------------------------------
233 //-------------------------------------------------------------------------
234 void SliderWidget::SetRange(int min, int max)
238 mwtSlider->setMinimum(min);
239 mwtSlider->setMaximum(max);
243 //-------------------------------------------------------------------------
244 void SliderWidget::SetReactiveOnTrack(bool ok)
246 reactiveOnTrack = ok;
252 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Slider);
253 BBTK_BLACK_BOX_IMPLEMENTATION(Slider,bbtk::WtBlackBox);
255 // 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)
257 void Slider::Process()
260 bbtkDebugMessage("process",3,
261 "Slider "<<bbGetName()<<" input="
262 <<bbGetInputIn()<<std::endl);
265 // desperate try // JPR
266 if ( bbGetInputMin() != ((SliderWidget*)bbGetOutputWidget())->GetMin() || bbGetInputMax() != ((SliderWidget*)bbGetOutputWidget())->GetMax() )
268 ((SliderWidget*)bbGetOutputWidget())->SetRange(bbGetInputMin(),bbGetInputMax()) ;
271 ((SliderWidget*)bbGetOutputWidget())->SetReactiveOnTrack( bbGetInputReactiveOnTrack() ) ;
273 bbSetOutputOut( bbGetInputIn() );
274 if (bbGetOutputWidget()!=0)
276 ((SliderWidget*)bbGetOutputWidget())->SetValue(bbGetInputIn());
281 // 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)
283 void Slider::CreateWidget(Wt::WContainerWidget* parent)
287 if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true) { orientation=1; }
290 // std::cout << "bbGetWxParent = "<<bbGetWxParent()<<std::endl;
291 SliderWidget *w = new SliderWidget(this,
292 parent, //bbGetWxParent(),
294 bbGetInputChangeResolution(),
295 bbtk::std2wt( bbGetInputTitle() ),
299 bbGetInputReactiveOnTrack()
301 // std::cout << "w = "<<w<<std::endl;
302 // w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
303 w->setMinimumSize(Wt::WLength::Auto, 120);
304 w->setMaximumSize(Wt::WLength::Auto, 180);
305 bbSetOutputWidget( w );
311 // 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)
313 void Slider::bbUserSetDefaultValues()
319 bbSetInputOrientation("HORIZONTAL");
320 bbSetInputChangeResolution(false);
321 bbSetInputReactiveOnTrack(false);
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::bbUserInitializeProcessing()
333 // 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)
335 void Slider::bbUserFinalizeProcessing()