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