PARP Research Group University of Murcia, Spain


src/qvgui/qvcamerawidget.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #include <qvgui/qvcamerawidget.h>
00026 
00027 QVCameraWidget::QVCameraWidget(QVCamera *cam, QWidget *parent):QWidget(parent)
00028         {
00029         setupUi(this);
00030         this->camera = cam;
00031         this->sliderActive = true;
00032         if (this->camera->isLiveCamera())
00033                 seekSlider->setEnabled(false);
00034 
00035         // Connection of signals in camera control widget to private slots...
00036         /*
00037         connect(pause_button,SIGNAL(pressed()),this,SLOT(pausePressed()));
00038         connect(play_button,SIGNAL(pressed()),this,SLOT(unpausePressed()));
00039         connect(next_button,SIGNAL(pressed()),this,SLOT(nextFramePressed()));
00040         connect(stop_button, SIGNAL(pressed()),this,SLOT(closePressed()));
00041 
00042         connect(this,SIGNAL(pause_pressed()),camera,SLOT(pauseCam()));
00043         connect(this,SIGNAL(unpause_pressed()),camera,SLOT(unpauseCam()));
00044         connect(this,SIGNAL(next_frame_pressed()),camera,SLOT(nextFrameCam()));
00045         connect(this,SIGNAL(close_pressed()),camera,SLOT(closeCam()));
00046         */
00047 
00048         connect(pause_button,SIGNAL(pressed()),camera,SLOT(pauseCam()));
00049         connect(play_button,SIGNAL(pressed()),camera,SLOT(unpauseCam()));
00050         connect(next_button,SIGNAL(pressed()),camera,SLOT(nextFrameCam()));
00051         connect(stop_button, SIGNAL(pressed()),camera,SLOT(closeCam()));
00052 
00054         connect(seekSlider,SIGNAL(sliderPressed()),this,SLOT(seekPressed()));
00055         connect(seekSlider,SIGNAL(sliderReleased()),this,SLOT(seekReleased()));
00056         connect(seekSlider,SIGNAL(valueChanged(int)),this,SLOT(seekMoved()));
00057         connect(seekSlider,SIGNAL(sliderMoved(int)),this,SLOT(seekMoved()));
00058 
00059         connect(this,SIGNAL(seek_pressed(QVCamera::TSeekType,double)), camera,SLOT(seekCam(QVCamera::TSeekType,double)));
00060 
00061         // ...and from private signals to public camera slots...
00062         connect(speed_button,SIGNAL(pressed()),this,SLOT(speedPressed()));
00063         connect(this,SIGNAL(speed_pressed(double)), camera,SLOT(setSpeedCam(double)));
00064 
00065         // ... and, finally, of camera newGrab and newRead signals to the
00066         // updateVisibleInfo slot...
00067         connect(camera,SIGNAL(newRead()), this, SLOT(updateCameraVisibleInfoSlot()));
00068         connect(camera,SIGNAL(newGrab()), this, SLOT(updateCameraVisibleInfoSlot()));
00069         connect(camera,SIGNAL(statusChange(QVCamera::TCameraStatus)),
00070                 this,SLOT(updateCameraStateSlot(QVCamera::TCameraStatus)));
00071 
00072         // ... and the closed signal of the camera, also to the closePressed slot:
00073         //connect(camera,SIGNAL(camClosed()),this,SLOT(closePressed()));
00074         }
00075 
00076 void QVCameraWidget::seekPressed()
00077         {
00078         sliderActive = false;
00079         }
00080 
00081 void QVCameraWidget::seekReleased()
00082         {
00083         sliderActive = true;
00084         emit seek_pressed((QVCamera::TSeekType)1,seekSlider->value());
00085         }
00086 
00087 void QVCameraWidget::seekMoved()
00088         {
00089         //emit seek_pressed((QVCamera::TSeekType)1,seekSlider->value());
00090         }
00091 
00092 void QVCameraWidget::speedPressed()
00093         {
00094         emit speed_pressed(speed_spin_box->value());
00095         }
00096 
00097 // Public slots:
00098 void QVCameraWidget::updateCameraVisibleInfoSlot()
00099 {
00100     // We update the fixed camera widget visible info (file name, fps, speed 
00101     // and size):
00102     filename_label->setText(camera->getUrlBase());
00103     fps_orig_label->setText(QString("fps: %1").
00104                             arg(static_cast<int>(camera->getFPS())));
00105     speed_label->setText(QString("speed: x %1")
00106                          .arg(camera->getSpeed(),0,'f',2));
00107     size_label->setText(QString("size: %1x%2").
00108                         arg(camera->getRows()).arg(camera->getCols()));
00109     // We update the variable camera widget visible info (frames
00110     // grabbed/updated and elapsed/total time):
00111     frames_label->setText(QString("frames grabbed/read: %1/%2").
00112                        arg(camera->getFramesGrabbed()).
00113                        arg(camera->getFramesRead()));
00114     pos_label->setText(QString("secs: %1/%2").
00115                        arg(camera->getTimePos()).
00116                        arg(camera->getTimeLength()));
00117     int percen = (int)((100*camera->getTimePos())/camera->getTimeLength());
00118         if (sliderActive) seekSlider->setValue(percen); 
00119 }
00120 
00121 void QVCameraWidget::updateCameraStateSlot(QVCamera::TCameraStatus status)
00122         {
00123         switch(status)
00124                 {
00125                 //case QVCamera::EndOfFile:
00126                 case QVCamera::Closed:
00127                         stop_button->setEnabled(FALSE);
00128                         pause_button->setEnabled(FALSE);
00129                         play_button->setEnabled(FALSE);
00130                         next_button->setEnabled(FALSE);
00131                         break;
00132 
00133                 case QVCamera::Running:
00134                         pause_button->setEnabled(TRUE);
00135                         play_button->setEnabled(FALSE);
00136                         next_button->setEnabled(FALSE);
00137                         break;
00138 
00139                 case QVCamera::RunningOneStep:
00140                 case QVCamera::Paused:
00141                         pause_button->setEnabled(FALSE);
00142                         play_button->setEnabled(TRUE);
00143                         next_button->setEnabled(TRUE);
00144                         break;
00145 
00146                 default:
00147                         break;
00148                 }
00149         }
00150 



QVision framework. PARP research group, copyright 2007, 2008.