00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include "qvvideoreaderblockwidget.h"
00026
00027 #ifdef QVMPLAYER
00028 #include <QVMPlayerReaderBlock>
00029 #endif
00030
00031 #ifdef QVIPP
00032 #include <QVYUV4MPEG2ReaderBlock>
00033 #endif
00034
00035 #include <QFileDialog>
00036
00037 QVVideoReaderBlockWidget::QVVideoReaderBlockWidget(QVVideoReaderBlock *cam, QWidget *parent): QWidget(parent), QVPropertyContainer("")
00038 {
00039 slider_active = true;
00040 form.setupUi(this);
00041 this->camera = cam;
00042
00043
00044 setName(QString("GUI for camera ")+cam->getName());
00045
00046
00047
00048
00049
00050
00051 int cols = camera->getPropertyValue<int>("Cols"), rows = camera->getPropertyValue<int>("Rows");
00052 QString url = camera->getPropertyValue<QString>("URL");
00053 bool noloop = camera->getPropertyValue<bool>("NoLoop"), deinterlaced = camera->getPropertyValue<bool>("Deinterlaced");
00054 bool realTime = camera->getPropertyValue<bool>("RealTime");
00055
00056 setPropertyValue<int>("Cols",cols);
00057 setPropertyValue<int>("Rows",rows);
00058 setPropertyValue<QString>("URL",url);
00059 setPropertyValue<bool>("NoLoop",noloop);
00060 setPropertyValue<bool>("Deinterlaced",deinterlaced);
00061
00062 form.spinbox_cols->setValue(cols);
00063 form.spinbox_rows->setValue(rows);
00064 form.url_line_edit->setText(url);
00065 form.noloop_button->setChecked(noloop);
00066 form.deinterlaced_button->setChecked(deinterlaced);
00067 form.real_time_label->setText(realTime?"Real Time":"Max speed");
00068
00069
00070 subscribeToInputProperty(cam,"NoLoop");
00071 subscribeToInputProperty(cam,"Deinterlaced");
00072 subscribeToInputProperty(cam,"URL");
00073 subscribeToInputProperty(cam,"Cols");
00074 subscribeToInputProperty(cam,"Rows");
00075
00076 subscribeToOutputProperty(cam,"Opened");
00077 subscribeToOutputProperty(cam,"FPS");
00078 subscribeToOutputProperty(cam,"Frames");
00079 subscribeToOutputProperty(cam,"ColsR");
00080 subscribeToOutputProperty(cam,"RowsR");
00081 subscribeToOutputProperty(cam,"Pos");
00082 subscribeToOutputProperty(cam,"Length");
00083
00084 connect(cam,SIGNAL(opened()),this,SLOT(updateOpened()));
00085 connect(cam,SIGNAL(closed()),this,SLOT(updateClosed()));
00086 connect(cam,SIGNAL(grabbed()),this,SLOT(newFrameGrabbed()));
00087
00088 connect(form.stop_button,SIGNAL(pressed()),cam,SLOT(resetCameraBlock()));
00089 connect(form.stop_button,SIGNAL(pressed()),this,SLOT(stopPressed()));
00090
00091 connect(form.pause_button,SIGNAL(pressed()),cam,SLOT(pause()));
00092 connect(form.pause_button,SIGNAL(pressed()),this,SLOT(pausePressed()));
00093
00094 connect(form.play_button,SIGNAL(pressed()),cam,SLOT(unPause()));
00095 connect(form.play_button,SIGNAL(pressed()),this,SLOT(playPressed()));
00096
00097 connect(form.next_button,SIGNAL(pressed()),cam,SLOT(step()));
00098 connect(form.next_button,SIGNAL(pressed()),this,SLOT(nextPressed()));
00099
00100 connect(form.seek_slider,SIGNAL(sliderPressed()),this,SLOT(seekPressed()));
00101 connect(form.seek_slider,SIGNAL(sliderReleased()),this,SLOT(seekReleased()));
00102
00103 connect(this,SIGNAL(seek_requested(double)),camera,SLOT(setCurrentPos(double)));
00104
00105 connect(form.url_line_edit,SIGNAL(editingFinished()),this,SLOT(somePropertyChanged()));
00106 connect(form.spinbox_cols,SIGNAL(valueChanged(int)),this,SLOT(somePropertyChanged()));
00107 connect(form.spinbox_rows,SIGNAL(valueChanged(int)),this,SLOT(somePropertyChanged()));
00108 connect(form.noloop_button,SIGNAL(toggled(bool)),this,SLOT(somePropertyChanged()));
00109 connect(form.deinterlaced_button,SIGNAL(toggled(bool)),this,SLOT(somePropertyChanged()));
00110
00111 connect(form.file_open_button,SIGNAL(pressed()),this,SLOT(fileOpenButtonPressed()));
00112 connect(this,SIGNAL(file_selected()),cam,SLOT(reopen()));
00113
00114 connect(form.reopen_button,SIGNAL(pressed()),cam,SLOT(reopen()));
00115
00116 }
00117
00118 void QVVideoReaderBlockWidget::subscribeToOutputProperty(QVPropertyContainer *qvp, QString name, LinkType linktype)
00119 {
00120
00121
00122 addPropertyFromQVariant(name, inputFlag, qvp->getPropertyQVariantValue(name),qvp->getPropertyInfo(name));
00123 qvp->linkProperty(name,this,name,linktype);
00124 }
00125
00126 void QVVideoReaderBlockWidget::subscribeToInputProperty(QVPropertyContainer *qvp, QString name, LinkType linktype)
00127 {
00128
00129
00130 addPropertyFromQVariant(name, outputFlag, qvp->getPropertyQVariantValue(name),qvp->getPropertyInfo(name));
00131 this->linkProperty(name,qvp,name,linktype);
00132 }
00133
00134 void QVVideoReaderBlockWidget::somePropertyChanged()
00135 {
00136 setPropertyValue<QString>("URL",form.url_line_edit->text());
00137 setPropertyValue<int>("Cols",form.spinbox_cols->value());
00138 setPropertyValue<int>("Rows",form.spinbox_rows->value());
00139 setPropertyValue<bool>("NoLoop",form.noloop_button->isChecked());
00140 setPropertyValue<bool>("Deinterlaced",form.deinterlaced_button->isChecked());
00141
00142 writeOutputProperties();
00143 }
00144
00145 void QVVideoReaderBlockWidget::updateOpened()
00146 {
00147 form.stop_button->setEnabled(TRUE);
00148 form.pause_button->setEnabled(TRUE);
00149 form.play_button->setEnabled(FALSE);
00150 form.next_button->setEnabled(FALSE);
00151 }
00152
00153 void QVVideoReaderBlockWidget::updateClosed()
00154 {
00155 form.stop_button->setEnabled(FALSE);
00156 form.pause_button->setEnabled(FALSE);
00157 form.play_button->setEnabled(FALSE);
00158 form.next_button->setEnabled(FALSE);
00159 }
00160
00161 void QVVideoReaderBlockWidget::stopPressed()
00162 {
00163 form.stop_button->setEnabled(FALSE);
00164 form.pause_button->setEnabled(FALSE);
00165 form.play_button->setEnabled(FALSE);
00166 form.next_button->setEnabled(FALSE);
00167 }
00168
00169 void QVVideoReaderBlockWidget::pausePressed()
00170 {
00171 form.pause_button->setEnabled(FALSE);
00172 form.play_button->setEnabled(TRUE);
00173 form.next_button->setEnabled(TRUE);
00174 }
00175
00176 void QVVideoReaderBlockWidget::playPressed()
00177 {
00178 form.pause_button->setEnabled(TRUE);
00179 form.play_button->setEnabled(FALSE);
00180 form.next_button->setEnabled(FALSE);
00181 }
00182
00183 void QVVideoReaderBlockWidget::nextPressed()
00184 {
00185 }
00186
00187 void QVVideoReaderBlockWidget::newFrameGrabbed()
00188 {
00189 readInputProperties();
00190
00191 form.frames_label->setText(QString("Frames: %1").arg(getPropertyValue<int>("Frames")));
00192 form.size_label->setText(QString("Size: %1x%2").arg(getPropertyValue<int>("ColsR")).arg(getPropertyValue<int>("RowsR")));
00193 QString len_string = QString("%1").arg(getPropertyValue<double>("Length"),1,'f',1);
00194 QString pos_string = QString("%1").arg(getPropertyValue<double>("Pos"),1,'f',1);
00195 form.pos_label->setText("Position: " + pos_string + "/" + len_string );
00196 form.fps_label->setText(QString("FPS: %1").arg(getPropertyValue<int>("FPS")));
00197
00198 if(getPropertyValue<double>("Length") > 0)
00199 {
00200 form.seek_slider->setEnabled(TRUE);
00201 if(slider_active)
00202 {
00203 int pos = (int)(form.seek_slider->maximum()*getPropertyValue<double>("Pos")/getPropertyValue<double>("Length"));
00204 form.seek_slider->setValue(pos);
00205 }
00206 }
00207 }
00208
00209
00210 void QVVideoReaderBlockWidget::seekPressed()
00211 {
00212 slider_active = false;
00213 }
00214
00215 void QVVideoReaderBlockWidget::seekReleased()
00216 {
00217 slider_active = true;
00218 emit seek_requested(form.seek_slider->value()*getPropertyValue<double>("Length")/form.seek_slider->maximum());
00219 }
00220
00221 void QVVideoReaderBlockWidget::fileOpenButtonPressed()
00222 {
00223 QFileDialog dialog(this);
00224
00225 QStringList filters;
00226
00227 #ifdef QVIPP
00228 if((dynamic_cast<QVYUV4MPEG2ReaderBlock*>(camera)) != NULL)
00229 filters << "Video Files (*.yuv)" << "All files (*)";
00230 #ifdef QVMPLAYER
00231 else if((dynamic_cast<QVMPlayerReaderBlock*>(camera)) != NULL)
00232 filters << "Video Files (*.avi *.dv *.mpg *.mpeg *.yuv *.wmv)" << "All files (*)";
00233 #endif // QVMPLAYER
00234 else
00235 filters << "All files (*)";
00236 #else // QVIPP
00237 filters << "All files (*)";
00238 #endif // QVIPP
00239
00240 #if QT_VERSION >= 0x040400
00241 dialog.setNameFilters(filters);
00242 #else
00243 dialog.setFilters(filters);
00244 #endif
00245
00246 dialog.setWindowTitle("Open video file");
00247 dialog.setFileMode(QFileDialog::ExistingFile);
00248 dialog.setViewMode(QFileDialog::Detail);
00249
00250 QString str = getPropertyValue<QString>("URL");
00251 QStringList strl = str.split("/");
00252 strl.removeLast();
00253 str = strl.join("/");
00254 QDir dir(str);
00255
00256 if(dir.exists())
00257 dialog.setDirectory(str);
00258 else
00259 dialog.setDirectory(QDir::currentPath());
00260
00261 QString fileName;
00262 if (dialog.exec())
00263 {
00264 QString filename = dialog.selectedFiles().first();
00265 setPropertyValue<QString>("URL",filename);
00266 form.url_line_edit->setText(filename);
00267 writeOutputProperties();
00268 emit file_selected();
00269 }
00270 }
00271
00272