iCub-main
dc1394slider.cpp
Go to the documentation of this file.
1 #include "dc1394slider.h"
2 #include "ui_dc1394slider.h"
3 #include "log.h"
4 
5 DC1394Slider::DC1394Slider(QWidget *parent) :
6  DC1394SliderBase(parent),
7  ui(new Ui::DC1394Slider)
8 {
9  ui->setupUi(this);
10 
11 
12  m_bInactive=false;
13 
14  m_old_value=-1.0;
15  pressed = false;
16 
17 }
18 
20 {
21  disconnectWidgets();
22  delete ui;
23 }
24 
26 {
27  int value = ui->m_Slider->value();
28  double val = (double)value/1000;
29  int w = ui->m_Slider->width() - 30;
30  double newX = ((double)w/(double)1000) * (double)value;
31  ui->lblValue->setGeometry(newX,0,30,20);
32  ui->lblValue->setText(QString("%L1").arg(val,0,'f',3));
33 }
34 
35 void DC1394Slider::resizeEvent(QResizeEvent* event)
36 {
37  QWidget::resizeEvent(event);
38 
39  updateSliders();
40 }
41 
42 bool DC1394Slider::init(cameraFeature_id_t feature, char* label, DC1394Thread *controlThread)
43 {
44  m_Feature=feature;
45  this->controlThread = controlThread;
46 
47  connect(controlThread,SIGNAL(sliderHasFeatureDone(QObject*,bool)),
48  this,SLOT(onHasFeatureDone(QObject*,bool)),Qt::QueuedConnection);
49 
50  connect(controlThread,SIGNAL(sliderRefreshDone(QObject*,bool,bool,bool,bool,bool,bool,double)),
51  this,SLOT(onRefreshDone(QObject*,bool,bool,bool,bool,bool,bool,double)),Qt::QueuedConnection);
52 
53  connect(controlThread,SIGNAL(sliderSetFeatureDC1394Done(QObject*,double)),
54  this,SLOT(onSliderSetFeatureDone(QObject*,double)),Qt::QueuedConnection);
55 
56  connect(controlThread,SIGNAL(sliderRadioAutoDone(QObject*,bool,bool)),
57  this,SLOT(onRadioAutoDone(QObject*,bool,bool)),Qt::QueuedConnection);
58 
59  connect(controlThread,SIGNAL(sliderPowerDone(QObject*,bool,bool,bool,bool)),
60  this,SLOT(onPowerDone(QObject*,bool,bool,bool,bool)),Qt::QueuedConnection);
61 
62  connect(controlThread,SIGNAL(sliderOnePushDone(QObject*,double)),
63  this,SLOT(onOnePushDone(QObject*,double)),Qt::QueuedConnection);
64 
65  type = SLIDER;
66  m_Name=label;
67 
68  ui->label->setTitle(m_Name);
69 
70  connectWidgets();
71 
72  QVariantList list;
73  list.append(qVariantFromValue((void*)this));
74  list.append(QVariant((int)m_Feature));
75  controlThread->doTask(_sliderHasFeature,list);
76 
77  return true;
78 }
79 
80 void DC1394Slider::onHasFeatureDone(QObject *slider, bool hasFeature)
81 {
82  if(slider != this){
83  return;
84  }
85 
86  if(hasFeature){
87  return;
88  }
89 
90  disconnectWidgets();
91 
92  m_bInactive=true;
93  setVisible(false);
94 
95  featureDisabled(this);
96 }
97 
98 void DC1394Slider::connectWidgets()
99 {
100  connect(ui->m_Slider,SIGNAL(valueChanged(int)),this,SLOT(onSliderValueChanged(int)));
101  connect(ui->m_Slider,SIGNAL(sliderPressed()),this,SLOT(onSliderPressed()));
102  connect(ui->m_Slider,SIGNAL(sliderReleased()),this,SLOT(onSliderReleased()));
103 
104  connect(ui->m_OnePush,SIGNAL(clicked()),this,SLOT(onOnePushClicked()));
105  connect(ui->pRBa,SIGNAL(toggled(bool)),this,SLOT(onRadioAuto(bool)));
106  //connect(ui->pRBm,SIGNAL(toggled(bool)),this,SLOT(onRadioManual(bool)));
107  connect(ui->pPwr,SIGNAL(toggled(bool)),this,SLOT(onPower(bool)));
108 }
109 
110 void DC1394Slider::disconnectWidgets()
111 {
112  disconnect(ui->m_Slider,SIGNAL(valueChanged(int)),this,SLOT(onSliderValueChanged(int)));
113  disconnect(ui->m_Slider,SIGNAL(sliderPressed()),this,SLOT(onSliderPressed()));
114  disconnect(ui->m_Slider,SIGNAL(sliderReleased()),this,SLOT(onSliderReleased()));
115  disconnect(ui->m_OnePush,SIGNAL(clicked()),this,SLOT(onOnePushClicked()));
116  disconnect(ui->pRBa,SIGNAL(toggled(bool)),this,SLOT(onRadioAuto(bool)));
117  //disconnect(ui->pRBm,SIGNAL(toggled(bool)),this,SLOT(onRadioManual(bool)));
118  disconnect(ui->pPwr,SIGNAL(toggled(bool)),this,SLOT(onPower(bool)));
119 }
120 
121 
123 {
124  if (m_bInactive){
125  return;
126  }
127 
128  int f = (int)m_Feature;
129  QVariantList list;
130  list.append(qVariantFromValue((void*)this));
131  list.append(QVariant(f));
132  controlThread->doTask(_sliderRefresh,list);
133 }
134 
135 void DC1394Slider::onRefreshDone(QObject *slider,bool bON,bool bAuto,bool bHasOnOff,bool bHasAuto,bool bHasManual,bool bHasOnePush,double val)
136 {
137  if(slider != this){
138  return;
139  }
140  disconnectWidgets();
141 
142  ui->pPwr->setChecked(bON);
143  ui->pPwr->setEnabled(bHasOnOff || bON);
144  ui->pRBa->setEnabled(bON && bHasAuto);
145  ui->pRBm->setEnabled(bON && bHasManual);
146 
147  ui->m_Slider->setEnabled(bHasManual && !bAuto);
148  ui->lblValue->setEnabled(bHasManual && !bAuto);
149  ui->m_OnePush->setEnabled(bON && bHasOnePush); // why setEnabled(false) is different from setDisable(true)?
150 
151  if (bAuto) {
152  ui->pRBa->setChecked(true);
153  } else {
154  ui->pRBm->setChecked(true);
155  }
156 
157  if (m_old_value != (m_new_value=val)){
159  ui->m_Slider->setValue(m_new_value * 1000);
160  ui->m_Slider->update();
161  onSliderValueChanged(m_new_value * 1000);
162  }
163 
164  connectWidgets();
165 }
166 
168 {
169  if (m_bInactive){
170  return;
171  }
172 
173  QVariantList list;
174  list.append(QVariant((int)m_Feature));
175  list.append(QVariant((double)ui->m_Slider->value() / 1000));
176  list.append(QVariant(ui->pRBa->isChecked()));
177  list.append(QVariant(ui->pPwr->isChecked()));
178 
179  controlThread->doTask(_sliderPropagate,list);
180 }
181 
182 void DC1394Slider::onSliderPressed()
183 {
184  pressed = true;
185 }
186 
187 void DC1394Slider::onSliderReleased()
188 {
189 
190  pressed = false;
191  double val = (double)ui->m_Slider->value()/1000;
192 
193  QVariantList list;
194  list.append(qVariantFromValue((void*)this));
195  list.append(QVariant((int)m_Feature));
196  list.append(QVariant(val));
197  controlThread->doTask(_sliderSetFeature,list);
198 }
199 
200 void DC1394Slider::onSliderValueChanged(int value)
201 {
202  double val = (double)value/1000;
203  int w = ui->m_Slider->width() - 30;
204  double newX = ((double)w/(double)1000) * (double)value;
205  ui->lblValue->setGeometry(newX,0,30,20);
206  ui->lblValue->setText(QString("%L1").arg(val,0,'f',3));
207 }
208 
209 void DC1394Slider::onSliderSetFeatureDone(QObject *slider, double val)
210 {
211  if(slider != this){
212  return;
213  }
214  LOG("%s new value %lf\n",m_Name.toLatin1().data(),val);
215 }
216 
217 void DC1394Slider::onOnePushClicked()
218 {
219 
220  QVariantList list;
221  list.append(qVariantFromValue((void*)this));
222  list.append(QVariant((int)m_Feature));
223  controlThread->doTask(_sliderOnePush,list);
224 }
225 
226 void DC1394Slider::onOnePushDone(QObject *slider, double val)
227 {
228  if(slider != this){
229  return;
230  }
231 
232  disconnectWidgets();
233  if (m_old_value!=(m_new_value=val)){
235  ui->m_Slider->setValue(m_new_value * 1000);
236  onSliderReleased();
237  }
238  connectWidgets();
239 
240  controlThread->doTask(_reload);
241 }
242 
243 void DC1394Slider::onRadioAuto(bool toggled)
244 {
245  bool bAuto=toggled;
246 
247  QVariantList list;
248  list.append(qVariantFromValue((void*)this));
249  list.append(QVariant((int)m_Feature));
250  list.append(QVariant(bAuto));
251  controlThread->doTask(_sliderRadioAuto,list);
252 }
253 
254 void DC1394Slider::onRadioAutoDone(QObject *slider,bool bON, bool bAuto)
255 {
256  if(slider != this){
257  return;
258  }
259 
260  ui->m_Slider->setEnabled(bON && !bAuto);
261  ui->lblValue->setEnabled(bON && !bAuto);
262  LOG("%s\n",ui->pRBa->isChecked() ? "auto":"man");
263 
264  controlThread->doTask(_reload);
265 }
266 
267 void DC1394Slider::onPower(bool checked)
268 {
269  bool bON=checked;
270 
271  QVariantList list;
272  list.append(qVariantFromValue((void*)this));
273  list.append(QVariant((int)m_Feature));
274  list.append(QVariant(bON));
275  controlThread->doTask(_sliderPower,list);
276 }
277 
278 void DC1394Slider::onPowerDone(QObject *slider, bool bON,bool hasAuto, bool hasManual, bool hasOnePush)
279 {
280  if(slider != this){
281  return;
282  }
283 
284  ui->pRBa->setEnabled(bON && hasAuto);
285  ui->pRBm->setEnabled(bON && hasManual);
286  ui->m_Slider->setEnabled(bON && ui->pRBm->isChecked());
287  ui->lblValue->setEnabled(bON && ui->pRBm->isChecked());
288  ui->m_OnePush->setEnabled(bON && hasOnePush); // why setEnabled(false) is different from setDisable(true)?
289  LOG("power %s\n",ui->pPwr->isChecked()?"on":"off");
290 
291  controlThread->doTask(_reload);
292 }
293 
294 void DC1394Slider::set_value(double val)
295 {
296  ui->m_Slider->setValue(val * 1000);
297  onSliderValueChanged(val * 1000);
298  onSliderReleased();
299 }
void featureDisabled(QObject *)
void updateSliders()
double m_old_value
Definition: dc1394slider.h:34
DC1394Slider(QWidget *parent=0)
Definition: dc1394slider.cpp:5
void set_value(double val)
QString m_Name
Definition: dc1394slider.h:33
void resizeEvent(QResizeEvent *event)
bool init(cameraFeature_id_t feature, char *label, DC1394Thread *controlThread)
double m_new_value
Definition: dc1394slider.h:34
cameraFeature_id_t m_Feature
Definition: dc1394slider.h:35
void doTask(threadFunction)
#define SLIDER
@ _sliderOnePush
Definition: dc1394thread.h:35
@ _sliderSetFeature
Definition: dc1394thread.h:33
@ _sliderPropagate
Definition: dc1394thread.h:31
@ _reload
Definition: dc1394thread.h:17
@ _sliderRadioAuto
Definition: dc1394thread.h:37
@ _sliderRefresh
Definition: dc1394thread.h:29
@ _sliderPower
Definition: dc1394thread.h:38
@ _sliderHasFeature
Definition: dc1394thread.h:39
#define LOG(...)
Definition: log.h:7