iCub-main
dc1394sliderwb.cpp
Go to the documentation of this file.
1 #include "dc1394sliderwb.h"
2 #include "ui_dc1394sliderwb.h"
3 
4 #include "log.h"
5 
7  DC1394SliderBase(parent),
8  ui(new Ui::DC1394SliderWB)
9 {
10  ui->setupUi(this);
11 
12  m_bInactive=false;
13 
14  m_old_red=m_old_blu=-1.0;
15 }
16 
18 {
19 
20  disconnectWidgets();
21 
22  delete ui;
23 }
24 
26 {
27  int rvalue = ui->m_SliderRed->value();
28  double rval = (double)rvalue/1000;
29  int rw = ui->m_SliderRed->width() - 30;
30  double rnewX = ((double)rw/(double)1000) * (double)rvalue;
31  ui->lblValueRed->setGeometry(rnewX,0,30,20);
32  ui->lblValueRed->setText(QString("%L1").arg(rval,0,'f',3));
33 
34  int bvalue = ui->m_SliderBlue->value();
35  double bval = (double)bvalue/1000;
36  int bw = ui->m_SliderBlue->width() - 30;
37  double bnewX = ((double)bw/(double)1000) * (double)bvalue;
38  ui->lblValueBlue->setGeometry(bnewX,0,30,20);
39  ui->lblValueBlue->setText(QString("%L1").arg(bval,0,'f',3));
40 }
41 
42 void DC1394SliderWB::resizeEvent(QResizeEvent* event)
43 {
44  QWidget::resizeEvent(event);
45 
46  updateSliders();
47 }
48 
49 bool DC1394SliderWB::init(DC1394Thread *controlThread)
50 {
51 // if (!((pFG=fg)->hasFeatureDC1394(YARP_FEATURE_WHITE_BALANCE))){
52 
53 // m_bInactive=true;
54 // setVisible(false);
55 // return false;
56 // }
57  this->controlThread = controlThread;
58 
59  connect(controlThread,SIGNAL(sliderHasFeatureDone(QObject*,bool)),
60  this,SLOT(onHasFeatureDone(QObject*,bool)),Qt::QueuedConnection);
61 
62  connect(controlThread,SIGNAL(sliderWBRefreshDone(QObject*,bool,bool,bool,bool,bool,bool,double,double)),
63  this,SLOT(onRefreshDone(QObject*,bool,bool,bool,bool,bool,bool,double,double)),Qt::QueuedConnection);
64 
65  connect(controlThread,SIGNAL(sliderWBSetFeatureDC1394Done(QObject*,double,double)),
66  this,SLOT(onSliderWBSetFeatureDone(QObject*,double,double)),Qt::QueuedConnection);
67 
68  connect(controlThread,SIGNAL(sliderRadioAutoDone(QObject*,bool,bool)),
69  this,SLOT(onRadioAutoDone(QObject*,bool,bool)),Qt::QueuedConnection);
70 
71  connect(controlThread,SIGNAL(sliderPowerDone(QObject*,bool,bool,bool,bool)),
72  this,SLOT(onPowerDone(QObject*,bool,bool,bool,bool)),Qt::QueuedConnection);
73 
74  connect(controlThread,SIGNAL(sliderWBOnePushDone(QObject*,double,double)),
75  this,SLOT(onOnePushDone(QObject*,double,double)),Qt::QueuedConnection);
76 
77  type = SLIDERWB;
78 
79  ui->label->setTitle("White Balance");
80 
81  connectWidgets();
82 
83  QVariantList list;
84  list.append(qVariantFromValue((void*)this));
85  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
86  controlThread->doTask(_sliderHasFeature,list);
87 
88  return true;
89 
90 }
91 
92 void DC1394SliderWB::onHasFeatureDone(QObject *slider, bool hasFeature)
93 {
94  if(slider != this){
95  return;
96  }
97 
98  if(hasFeature){
99  return;
100  }
101 
102  disconnectWidgets();
103 
104  m_bInactive=true;
105  setVisible(false);
106 
107  featureDisabled(this);
108 }
109 
110 
111 void DC1394SliderWB::connectWidgets()
112 {
113  connect(ui->m_SliderRed,SIGNAL(valueChanged(int)),this,SLOT(onSliderRedValueChanged(int)));
114  connect(ui->m_SliderRed,SIGNAL(sliderReleased()),this,SLOT(onSliderRedReleased()));
115 
116 
117  connect(ui->m_SliderBlue,SIGNAL(valueChanged(int)),this,SLOT(onSliderBlueValueChanged(int)));
118  connect(ui->m_SliderBlue,SIGNAL(sliderReleased()),this,SLOT(onSliderBlueReleased()));
119 
120  connect(ui->m_OnePush,SIGNAL(clicked()),this,SLOT(onOnePushClicked()));
121  connect(ui->pRBa,SIGNAL(toggled(bool)),this,SLOT(onRadioAuto(bool)));
122  connect(ui->pPwr,SIGNAL(toggled(bool)),this,SLOT(onPower(bool)));
123 }
124 
125 void DC1394SliderWB::disconnectWidgets()
126 {
127  disconnect(ui->m_SliderRed,SIGNAL(valueChanged(int)),this,SLOT(onSliderRedValueChanged(int)));
128  disconnect(ui->m_SliderRed,SIGNAL(sliderReleased()),this,SLOT(onSliderRedReleased()));
129  disconnect(ui->m_SliderBlue,SIGNAL(valueChanged(int)),this,SLOT(onSliderBlueValueChanged(int)));
130  disconnect(ui->m_SliderBlue,SIGNAL(sliderReleased()),this,SLOT(onSliderBlueReleased()));
131 
132  disconnect(ui->m_OnePush,SIGNAL(clicked()),this,SLOT(onOnePushClicked()));
133  disconnect(ui->pRBa,SIGNAL(toggled(bool)),this,SLOT(onRadioAuto(bool)));
134  disconnect(ui->pPwr,SIGNAL(toggled(bool)),this,SLOT(onPower(bool)));
135 }
136 
137 
139 {
140  if (m_bInactive){
141  return;
142  }
143 
144  int f = (int)YARP_FEATURE_WHITE_BALANCE;
145  QVariantList list;
146  list.append(qVariantFromValue((void*)this));
147  list.append(QVariant(f));
148  controlThread->doTask(_sliderWBRefresh,list);
149 }
150 
151 void DC1394SliderWB::onRefreshDone(QObject *slider,bool bON,bool bAuto,bool bHasOnOff,bool bHasAuto,bool bHasManual,bool bHasOnePush,double redVal, double blueVal)
152 {
153  if(slider != this){
154  return;
155  }
156  disconnectWidgets();
157 
158  if (bAuto) {
159  ui->pRBa->setChecked(true);
160  } else {
161  ui->pRBm->setChecked(true);
162  }
163 
164  ui->pPwr->setChecked(bON);
165 
166  ui->pPwr->setEnabled(bHasOnOff || bON || bAuto);
167  ui->pRBa->setEnabled(bON && bHasAuto);
168  ui->pRBm->setEnabled(bON && bHasManual);
169  ui->m_SliderRed->setEnabled(bHasManual && !bAuto);
170  ui->m_SliderBlue->setEnabled(bHasManual && !bAuto);
171  ui->m_OnePush->setEnabled(bON && bHasOnePush);
172 
173  m_new_blu = blueVal;
174  m_new_red = redVal;
175 
176  if (bAuto) {
177  ui->pRBa->setChecked(true);
178  } else {
179  ui->pRBm->setChecked(true);
180  }
181 
182  if (m_new_blu!=m_old_blu){
183  m_old_blu=m_new_blu;
184  ui->m_SliderBlue->setValue(m_new_blu * 1000);
185  ui->m_SliderBlue->update();
186  onSliderBlueValueChanged(m_new_blu * 1000);
187  }
188 
189  if (m_new_red!=m_old_red){
190  m_old_red=m_new_red;
191  ui->m_SliderRed->setValue(m_new_red * 1000);
192  ui->m_SliderRed->update();
193  onSliderRedValueChanged(m_new_red * 1000);
194  }
195 
196  connectWidgets();
197 }
198 
200 {
201  if (m_bInactive){
202  return;
203  }
204 
205  QVariantList list;
206  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
207  list.append(QVariant((double)ui->m_SliderRed->value()/1000));
208  list.append(QVariant((double)ui->m_SliderBlue->value()/1000));
209  list.append(QVariant(ui->pRBa->isChecked()));
210  list.append(QVariant(ui->pPwr->isChecked()));
211 
212  controlThread->doTask(_sliderWBPropagate,list);
213 
214 
215 // pFG->setWhiteBalanceDC1394(ui->m_SliderBlue->value()/1000,ui->m_SliderRed->value()/1000);
216 // pFG->setModeDC1394(YARP_FEATURE_WHITE_BALANCE,ui->pRBa->isChecked());
217 // pFG->setActiveDC1394(YARP_FEATURE_WHITE_BALANCE,ui->pPwr->isChecked());
218 }
219 
220 void DC1394SliderWB::onSliderRedReleased()
221 {
222  double val = (double)ui->m_SliderRed->value()/1000;
223  QVariantList list;
224  list.append(qVariantFromValue((void*)this));
225  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
226  list.append(QVariant(val));
227  list.append(QVariant((double)ui->m_SliderBlue->value()/1000));
228  controlThread->doTask(_sliderWBSetFeature,list);
229 }
230 
231 void DC1394SliderWB::onSliderRedValueChanged(int value)
232 {
233  double val = (double)value/1000;
234  int w = ui->m_SliderRed->width() - 30;
235  double newX = ((double)w/(double)1000) * (double)value;
236  ui->lblValueRed->setGeometry(newX,0,30,20);
237  ui->lblValueRed->setText(QString("%L1").arg(val,0,'f',3));
238 
239  //pFG->setWhiteBalanceDC1394(ui->m_SliderBlue->value()/1000,value/1000);
240  //LOG("white balance %f %f\n",ui->m_SliderBlue->value()/1000,ui->m_SliderRed->value()/1000);
241 }
242 
243 void DC1394SliderWB::onSliderBlueReleased()
244 {
245  double val = (double)ui->m_SliderBlue->value()/1000;
246  QVariantList list;
247  list.append(qVariantFromValue((void*)this));
248  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
249  list.append(QVariant((double)ui->m_SliderRed->value()/1000));
250  list.append(QVariant(val));
251  controlThread->doTask(_sliderWBSetFeature,list);
252 }
253 
254 void DC1394SliderWB::onSliderBlueValueChanged(int value)
255 {
256  double val = (double)value/1000;
257  int w = ui->m_SliderBlue->width() - 30;
258  double newX = ((double)w/(double)1000) * (double)value;
259  ui->lblValueBlue->setGeometry(newX,0,30,20);
260  ui->lblValueBlue->setText(QString("%L1").arg(val,0,'f',3));
261 
262  //pFG->setWhiteBalanceDC1394(value/1000,ui->m_SliderRed->value()/1000);
263  //LOG("white balance %f %f\n",ui->m_SliderBlue->value()/1000,ui->m_SliderRed->value()/1000);
264 }
265 
266 void DC1394SliderWB::onSliderWBSetFeatureDone(QObject *slider,double redVal,double blueVal)
267 {
268  if(slider != this){
269  return;
270  }
271  LOG("white balance %f %f\n",blueVal,redVal);
272 }
273 
274 void DC1394SliderWB::onOnePushClicked()
275 {
276  QVariantList list;
277  list.append(qVariantFromValue((void*)this));
278  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
279  controlThread->doTask(_sliderWBOnePush,list);
280 
281 
282 // //pFG->getWhiteBalanceDC1394(m_old_blu,m_old_red);
283 // pFG->setOnePushDC1394(YARP_FEATURE_WHITE_BALANCE);
284 // pFG->getWhiteBalanceDC1394(m_new_blu,m_new_red);
285 // LOG("one push\n");
286 
287 // disconnectWidgets();
288 // if (m_new_blu!=m_old_blu){
289 // m_old_blu=m_new_blu;
290 // ui->m_SliderBlue->setValue(m_new_blu * 1000);
291 // onSliderBlueValueChanged(m_new_blu);
292 // }
293 
294 // if (m_new_red!=m_old_red){
295 // m_old_red=m_new_red;
296 // ui->m_SliderRed->setValue(m_new_red * 1000);
297 // onSliderRedValueChanged(m_new_red);
298 // }
299 
300 // connectWidgets();
301 // reload();
302 }
303 
304 void DC1394SliderWB::onOnePushDone(QObject *slider, double redVal, double blueVal)
305 {
306  if(slider != this){
307  return;
308  }
309 
310  m_new_blu = blueVal;
311  m_new_red = redVal;
312 
313  disconnectWidgets();
314  if (m_new_blu!=m_old_blu){
315  m_old_blu=m_new_blu;
316  ui->m_SliderBlue->setValue(m_new_blu * 1000);
317  //onSliderBlueValueChanged(m_new_blu);
318  onSliderBlueReleased();
319  }
320 
321  if (m_new_red!=m_old_red){
322  m_old_red=m_new_red;
323  ui->m_SliderRed->setValue(m_new_red * 1000);
324  //onSliderRedValueChanged(m_new_red);
325  onSliderRedReleased();
326  }
327 
328  connectWidgets();
329 
330  controlThread->doTask(_reload);
331 }
332 
333 
334 void DC1394SliderWB::onRadioAuto(bool toggled)
335 {
336  bool bAuto=toggled;
337 
338  QVariantList list;
339  list.append(qVariantFromValue((void*)this));
340  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
341  list.append(QVariant(bAuto));
342  controlThread->doTask(_sliderRadioAuto,list);
343 
344 // pFG->setModeDC1394(YARP_FEATURE_WHITE_BALANCE,bAuto);
345 // ui->m_SliderRed->setEnabled(!bAuto);
346 // ui->m_SliderBlue->setEnabled(!bAuto);
347 // LOG("%s\n",ui->pRBa->isEnabled() ? "auto":"man");
348 // reload();
349 }
350 
351 void DC1394SliderWB::onRadioAutoDone(QObject *slider,bool bON, bool bAuto)
352 {
353  if(slider != this){
354  return;
355  }
356 
357  ui->m_SliderRed->setEnabled(!bAuto);
358  ui->m_SliderBlue->setEnabled(!bAuto);
359  LOG("%s\n",ui->pRBa->isEnabled() ? "auto":"man");
360  controlThread->doTask(_reload);
361 }
362 
363 void DC1394SliderWB::onPower(bool checked)
364 {
365  bool bON=checked;
366 
367  QVariantList list;
368  list.append(qVariantFromValue((void*)this));
369  list.append(QVariant((int)YARP_FEATURE_WHITE_BALANCE));
370  list.append(QVariant(bON));
371  controlThread->doTask(_sliderPower,list);
372 
373 // pFG->setActiveDC1394(YARP_FEATURE_WHITE_BALANCE,bON);
374 // ui->pRBa->setEnabled(bON && pFG->hasAutoDC1394(YARP_FEATURE_WHITE_BALANCE));
375 // ui->pRBm->setEnabled(bON && pFG->hasManualDC1394(YARP_FEATURE_WHITE_BALANCE));
376 // ui->m_SliderRed->setEnabled(bON && ui->pRBm->isChecked());
377 // ui->m_SliderBlue->setEnabled(bON && ui->pRBm->isChecked());
378 // ui->m_OnePush->setEnabled(bON && pFG->hasOnePushDC1394(YARP_FEATURE_WHITE_BALANCE));
379 // LOG("power %s\n",ui->pPwr->isEnabled() ? "on":"off");
380 // reload();
381 }
382 
383 void DC1394SliderWB::onPowerDone(QObject *slider, bool bON,bool hasAuto, bool hasManual, bool hasOnePush)
384 {
385  if(slider != this){
386  return;
387  }
388 
389  //pFG->setActiveDC1394(m_Feature,bON);
390  ui->pRBa->setEnabled(bON && hasAuto);
391  ui->pRBm->setEnabled(bON && hasManual);
392  ui->m_SliderRed->setEnabled(bON && ui->pRBm->isChecked());
393  ui->m_SliderBlue->setEnabled(bON && ui->pRBm->isChecked());
394  ui->m_OnePush->setEnabled(bON && hasOnePush);
395  LOG("power %s\n",ui->pPwr->isChecked()?"on":"off");
396 
397  //pFG->Reload();
398  //reload();
399  controlThread->doTask(_reload);
400 }
401 
402 void DC1394SliderWB::set_value(double blue,double red)
403 {
404  ui->m_SliderBlue->setValue(blue * 1000);
405  ui->m_SliderRed->setValue(red * 1000);
406 
407  onSliderBlueReleased();
408  onSliderRedReleased();
409 }
void featureDisabled(QObject *)
void resizeEvent(QResizeEvent *event)
DC1394SliderWB(QWidget *parent=0)
void set_value(double blue, double red)
bool init(DC1394Thread *controlThread)
void doTask(threadFunction)
#define SLIDERWB
@ _sliderWBOnePush
Definition: dc1394thread.h:36
@ _reload
Definition: dc1394thread.h:17
@ _sliderRadioAuto
Definition: dc1394thread.h:37
@ _sliderWBPropagate
Definition: dc1394thread.h:32
@ _sliderWBRefresh
Definition: dc1394thread.h:30
@ _sliderPower
Definition: dc1394thread.h:38
@ _sliderWBSetFeature
Definition: dc1394thread.h:34
@ _sliderHasFeature
Definition: dc1394thread.h:39
#define LOG(...)
Definition: log.h:7