src/qvgui/qvparamwidget.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. 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/qvparamwidget.h>
00026 
00027 #include <QLineEdit>
00028 #include <QSlider>
00029 #include <QLabel>
00030 #include <QCheckBox>
00031 
00032 #include <QVBoxLayout>
00033 #include <QHBoxLayout>
00034 
00035 #include <qwt_slider.h>
00036 
00037 QVIntParamWidget::QVIntParamWidget(QVPropertyContainer *_orig_holder, QVPropertyContainer *_gui_holder, const QString _property, QWidget *parent): QWidget(parent), orig_holder(_orig_holder), gui_holder(_gui_holder), property(_property)
00038         {
00039         value = orig_holder->getPropertyValue<int>(property);
00040         if(orig_holder->hasRange(property))
00041                 {
00042                 max = orig_holder->getPropertyMaximum<int>(property);
00043                 min = orig_holder->getPropertyMinimum<int>(property);
00044                 gui_holder->addProperty<int>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"",min,max);
00045                 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00046 
00047                 lineedit = new QLineEdit(this);
00048                 lineedit->setFixedWidth(80);
00049                 slider = new QSlider(Qt::Horizontal,this);
00050                 slider->setMinimum(min);
00051                 slider->setMaximum(max);
00052                 slider->setFixedWidth(150);
00053 
00054                 QVBoxLayout *vboxlayout = new QVBoxLayout(this);
00055                 vboxlayout->setSpacing(0);
00056                 QHBoxLayout *hboxlayout1 = new QHBoxLayout();
00057                 hboxlayout1->addWidget(new QLabel(QString("<i>int</i> <b>%1</b>").arg(property)));
00058                 hboxlayout1->addStretch();
00059                 hboxlayout1->addWidget(new QLabel(QString("(%1,%2)").arg(min).arg(max)));
00060                 QHBoxLayout *hboxlayout2 = new QHBoxLayout();
00061                 hboxlayout2->addWidget(lineedit);
00062                 hboxlayout2->addStretch();
00063                 hboxlayout2->addWidget(slider);
00064                 vboxlayout->addLayout(hboxlayout1);
00065                 vboxlayout->addLayout(hboxlayout2);
00066 
00067                 slider->setValue(value);
00068                 connect(slider,SIGNAL(valueChanged(int)),this,SLOT(setValue()));
00069                 }
00070         else
00071                 {
00072                 gui_holder->addProperty<int>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00073                 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00074 
00075                 lineedit = new QLineEdit(this);
00076                 lineedit->setFixedWidth(80);
00077 
00078                 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00079                 hboxlayout->addWidget(new QLabel(QString("<i>int</i> <b>%1</b>").arg(property)));
00080                 hboxlayout->addWidget(lineedit);
00081                 hboxlayout->addStretch();
00082                 }
00083 
00084         connect(lineedit,SIGNAL(editingFinished()),this,SLOT(setValue()));
00085         gui_holder->setPropertyValue<int>(property+"_internal_gui",value);
00086         lineedit->setText(QString("%1").arg(value));
00087         emit valueChanged(value);
00088         }
00089 
00090 void QVIntParamWidget::setValue()
00091         {
00092         if(sender() == lineedit)
00093                 {
00094                 bool ok;
00095                 value = lineedit->text().toInt(&ok);
00096                 if( (not ok) or
00097                         (orig_holder->hasRange(property) and (value<min or value>max) ) )
00098                         value = gui_holder->getPropertyValue<int>(property+"_internal_gui");
00099                 }
00100         else if(sender() == slider) {
00101                 value = slider->value();
00102                 }
00103         else
00104                 value = gui_holder->getPropertyValue<int>(property+"_internal_gui");
00105 
00106         lineedit->setText(QString("%1").arg(value));
00107         if(orig_holder->hasRange(property))
00108                 slider->setValue(value);
00109         gui_holder->setPropertyValue<int>(property+"_internal_gui",value);
00110         emit valueChanged(value);
00111         }
00112 
00113 
00114 QVDoubleParamWidget::QVDoubleParamWidget(QVPropertyContainer *_orig_holder, QVPropertyContainer *_gui_holder, const QString _property, QWidget *parent): QWidget(parent), orig_holder(_orig_holder), gui_holder(_gui_holder), property(_property)
00115         {
00116 
00117         value = orig_holder->getPropertyValue<double>(property);
00118         if(orig_holder->hasRange(property))
00119                 {
00120                 max = orig_holder->getPropertyMaximum<double>(property);
00121                 min = orig_holder->getPropertyMinimum<double>(property);
00122                 gui_holder->addProperty<double>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"",min,max);
00123                 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00124 
00125                 lineedit = new QLineEdit(this);
00126                 lineedit->setFixedWidth(80);
00127                 qwtslider = new QwtSlider(this,Qt::Horizontal,QwtSlider::NoScale,QwtSlider::BgSlot);
00128                 qwtslider->setThumbLength(20);
00129                 qwtslider->setThumbWidth(10);
00130                 qwtslider->setRange(min,max);
00131                 qwtslider->setFixedWidth(150);
00132 
00133                 QVBoxLayout *vboxlayout = new QVBoxLayout(this);
00134                 vboxlayout->setSpacing(0);
00135                 QHBoxLayout *hboxlayout1 = new QHBoxLayout();
00136                 hboxlayout1->addWidget(new QLabel(QString("<i>double</i> <b>%1</b>").arg(property)));
00137                 hboxlayout1->addStretch();
00138                 hboxlayout1->addWidget(new QLabel(QString("(%1,%2)").arg(min).arg(max)));
00139                 QHBoxLayout *hboxlayout2 = new QHBoxLayout();
00140                 hboxlayout2->addWidget(lineedit);
00141                 hboxlayout2->addStretch();
00142                 hboxlayout2->addWidget(qwtslider);
00143                 vboxlayout->addLayout(hboxlayout1);
00144                 vboxlayout->addLayout(hboxlayout2);
00145 
00146                 qwtslider->setValue(value);
00147                 connect(qwtslider,SIGNAL(valueChanged(double)),this,SLOT(setValue()));
00148                 }
00149         else
00150                 {
00151                 gui_holder->addProperty<double>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00152                 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00153 
00154                 lineedit = new QLineEdit(this);
00155                 lineedit->setFixedWidth(80);
00156 
00157                 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00158                 hboxlayout->addWidget(new QLabel(QString("<i>double</i> <b>%1</b>").arg(property)));
00159                 hboxlayout->addWidget(lineedit);
00160                 hboxlayout->addStretch();
00161                 }
00162 
00163         connect(lineedit,SIGNAL(editingFinished()),this,SLOT(setValue()));
00164         gui_holder->setPropertyValue<double>(property+"_internal_gui",value);
00165         lineedit->setText(QString("%1").arg(value));
00166         emit valueChanged(value);
00167 
00168         }
00169 
00170 void QVDoubleParamWidget::setValue()
00171         {
00172         if(sender() == lineedit)
00173                 {
00174                 bool ok;
00175                 value = lineedit->text().toDouble(&ok);
00176                 if( (not ok) or
00177                         (orig_holder->hasRange(property) and (value<min or value>max) ) )
00178                         value = gui_holder->getPropertyValue<double>(property+"_internal_gui");
00179                 }
00180         else if(sender() == qwtslider) {
00181                 value = qwtslider->value();
00182                 }
00183         else
00184                 value = gui_holder->getPropertyValue<double>(property+"_internal_gui");
00185 
00186         lineedit->setText(QString("%1").arg(value));
00187         if(orig_holder->hasRange(property))
00188                 qwtslider->setValue(value);
00189         gui_holder->setPropertyValue<double>(property+"_internal_gui",value);
00190         emit valueChanged(value);
00191         }
00192 
00193 QVBoolParamWidget::QVBoolParamWidget(QVPropertyContainer *_orig_holder, QVPropertyContainer *_gui_holder, const QString _property, QWidget *parent): QWidget(parent), orig_holder(_orig_holder), gui_holder(_gui_holder), property(_property)
00194         {
00195         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00196         //hboxlayout->setSpacing(0);
00197         QLabel *label = new QLabel(QString("<i>bool</i> <b>%1</b>").arg(property),this);
00198         hboxlayout->addWidget(label);
00199         checkbox = new QCheckBox(this);
00200         hboxlayout->addWidget(checkbox);
00201 
00202         value = orig_holder->getPropertyValue<bool>(property);
00203 
00204         gui_holder->addProperty<bool>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00205 
00206         gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00207 
00208         connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(setValue()));
00209         gui_holder->setPropertyValue<bool>(property+"_internal_gui",value);
00210         if(value)
00211                 checkbox->setCheckState(Qt::Checked);
00212         else
00213                 checkbox->setCheckState(Qt::Unchecked);
00214         emit valueChanged(value);
00215         }
00216 
00217 void QVBoolParamWidget::setValue()
00218         {
00219         if (checkbox->checkState() == Qt::Unchecked)
00220                 value = false;
00221         else if (checkbox->checkState() == Qt::Checked)
00222                 value = true;
00223 
00224         gui_holder->setPropertyValue<bool>(property+"_internal_gui",value);
00225         emit valueChanged(value);
00226         }
00227 
00228 QVStringParamWidget::QVStringParamWidget(QVPropertyContainer *_orig_holder, QVPropertyContainer *_gui_holder, const QString _property, QWidget *parent): QWidget(parent), orig_holder(_orig_holder), gui_holder(_gui_holder), property(_property)
00229         {
00230         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00231         hboxlayout->setSpacing(0);
00232         QLabel *label = new QLabel(QString("<i>string</i> <b>%1</b>").arg(property),this);
00233         hboxlayout->addWidget(label);
00234         lineedit = new QLineEdit(this);
00235         hboxlayout->addWidget(lineedit);
00236 
00237         value = orig_holder->getPropertyValue<QString>(property);
00238 
00239         gui_holder->addProperty<QString>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00240         gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00241 
00242         connect(lineedit,SIGNAL(textChanged(QString)),this,SLOT(setValue()));
00243 
00244         gui_holder->setPropertyValue<QString>(property+"_internal_gui",value);
00245 
00246         emit valueChanged(value);
00247         }
00248 
00249 void QVStringParamWidget::setValue()
00250         {
00251         value = lineedit->text();
00252         gui_holder->setPropertyValue<QString>(property+"_internal_gui",value);
00253         emit valueChanged(value);
00254         }
00255 
00256 
00257 QVStringListParamWidget::QVStringListParamWidget(QVPropertyContainer *_orig_holder, QVPropertyContainer *_gui_holder, const QString _property, QWidget *parent): QWidget(parent), orig_holder(_orig_holder), gui_holder(_gui_holder), property(_property)
00258         {
00259         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00260         hboxlayout->setSpacing(0);
00261         QLabel *label = new QLabel(QString("<i>stringlist</i> <b>%1</b>").arg(property),this);
00262         hboxlayout->addWidget(label);
00263         combobox = new QComboBox(this);
00264         hboxlayout->addWidget(combobox);
00265 
00266         value = orig_holder->getPropertyValue<QVIndexedStringList>(property);
00267 
00268         gui_holder->addProperty<QVIndexedStringList>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00269         gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00270 
00271         connect(combobox,SIGNAL(activated(int)),this,SLOT(setValue()));
00272 
00273         gui_holder->setPropertyValue<QVIndexedStringList>(property+"_internal_gui",value);
00274 
00275         combobox->addItems(value);
00276         combobox->setCurrentIndex(value.getIndex());
00277         emit valueChanged(value);
00278         }
00279 
00280 void QVStringListParamWidget::setValue()
00281         {
00282         value.setIndex(combobox->currentIndex());
00283         gui_holder->setPropertyValue<QVIndexedStringList>(property+"_internal_gui",value);
00284         emit valueChanged(value);
00285         }
00286 
00287 QVWorkerTriggerWidget::QVWorkerTriggerWidget(QVWorker *worker, const QString triggername, QWidget *parent): QWidget(parent), worker(worker), triggername(triggername)
00288         {
00289         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00290         toolbutton = new QToolButton(this);
00291         toolbutton->setText(triggername);
00292         hboxlayout->addWidget(new QLabel(QString("<i>trigger</i> <b>%1</b>").arg(triggername)));
00293 hboxlayout->addStretch();
00294         hboxlayout->addWidget(toolbutton);
00295 
00296         connect(toolbutton,SIGNAL(pressed()),this,SLOT(setValue()));
00297         connect(this,SIGNAL(valueChanged(QString)),worker,SLOT(processTrigger(QString)));
00298         }
00299 
00300 void QVWorkerTriggerWidget::setValue()
00301         {
00302         emit valueChanged(triggername);
00303         }
00304 
00305 /*              doublespinbox->setMinimum(min);
00306                 doublespinbox->setMaximum(max);
00307                 int signif=static_cast<int>(round(log(max-min)/log(10)));
00308                 double val=pow(10,signif);
00309                 std::cout << val << " " << signif << std::endl;
00310                 doublespinbox->setSingleStep(val/100);
00311                 if(signif >= 5)
00312                         doublespinbox->setDecimals(0);
00313                 else
00314                         doublespinbox->setDecimals(5-signif);
00315 */