00001 #include "SensorStreamWidget.h" 00002 #include "SensorStreamWidget.moc" 00003 00004 SensorStreamWidget::SensorStreamWidget(QWidget * _parent): 00005 QFrame(_parent), 00006 m_isSeekable(false), 00007 m_position(0) 00008 { 00009 m_layout = new QGridLayout(this); 00010 m_nextButton = new QPushButton("Next", this); 00011 m_sensorSlider = new QSlider(this); 00012 m_sensorBox = new QSpinBox(this); 00013 m_sensorBox->setMinimum(0); 00014 00015 buildGui(); 00016 } 00017 00018 SensorStreamWidget::~SensorStreamWidget(){ 00019 delete m_layout; 00020 delete m_nextButton; 00021 delete m_sensorSlider; 00022 delete m_sensorBox; 00023 } 00024 00025 void SensorStreamWidget::seekPosition(int position){ 00026 unsigned int _position(position); 00027 if(_position == m_position){ 00028 return; 00029 } 00030 m_position = _position; 00031 if(m_isSeekable){ 00032 m_sensorSlider->setValue(_position); 00033 m_sensorBox->setValue(_position); 00034 } 00035 emit newReading(_position); 00036 } 00037 00038 void SensorStreamWidget::nextPosition(){ 00039 if(m_isSeekable){ 00040 seekPosition(m_sensorSlider->value() + m_sensorSlider->singleStep()); 00041 } else { 00042 emit newReading(); 00043 } 00044 } 00045 00046 void SensorStreamWidget::seekable(bool _seek, unsigned int _size){ 00047 m_isSeekable = _seek; 00048 m_sensorSlider->setEnabled(_seek); 00049 m_sensorSlider->setMaximum(_size); 00050 m_sensorBox->setEnabled(_seek); 00051 m_sensorBox->setMaximum(_size); 00052 } 00053 00054 void SensorStreamWidget::streamReady(){ 00055 m_nextButton->setEnabled(true); 00056 } 00057 00058 00059 void SensorStreamWidget::buildGui(){ 00060 m_layout->setSpacing(3); 00061 m_layout->setMargin(3); 00062 m_layout->addWidget(m_sensorSlider, 0,0); 00063 m_layout->addWidget(m_nextButton, 0,1); 00064 m_layout->addWidget(m_sensorBox, 0,2); 00065 00066 m_sensorSlider->setEnabled(false); 00067 m_sensorSlider->setOrientation(Qt::Horizontal); 00068 00069 m_nextButton->setEnabled(false); 00070 00071 connect(m_nextButton, SIGNAL(clicked()), this, SLOT(nextPosition())); 00072 connect(m_sensorSlider, SIGNAL(valueChanged(int)), this, SLOT(seekPosition(int))); 00073 connect(m_sensorBox, SIGNAL(valueChanged(int)), this, SLOT(seekPosition(int))); 00074 }