PARP Research Group University of Murcia, Spain


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,QVPropertyContainer::outputFlag,value,"",min,max);
00045                 gui_holder->linkProperty(property,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,QVPropertyContainer::outputFlag,value,"");
00073                 gui_holder->linkProperty(property,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->addStretch();
00081                 hboxlayout->addWidget(lineedit);
00082                 //hboxlayout->addStretch();
00083                 }
00084 
00085         connect(lineedit,SIGNAL(editingFinished()),this,SLOT(setValue()));
00086         gui_holder->setPropertyValue<int>(property,value);
00087         lineedit->setText(QString("%1").arg(value));
00088         emit valueChanged(value);
00089         }
00090 
00091 void QVIntParamWidget::setValue()
00092         {
00093         if(sender() == lineedit)
00094                 {
00095                 bool ok;
00096                 value = lineedit->text().toInt(&ok);
00097                 if( (not ok) or
00098                         (orig_holder->hasRange(property) and (value<min or value>max) ) )
00099                         value = gui_holder->getPropertyValue<int>(property);
00100                 }
00101         else if(sender() == slider) {
00102                 value = slider->value();
00103                 }
00104         else
00105                 value = gui_holder->getPropertyValue<int>(property);
00106 
00107         lineedit->setText(QString("%1").arg(value));
00108         if(orig_holder->hasRange(property))
00109                 slider->setValue(value);
00110         gui_holder->setPropertyValue<int>(property,value);
00111         emit valueChanged(value);
00112         }
00113 
00114 
00115 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)
00116         {
00117 
00118         value = orig_holder->getPropertyValue<double>(property);
00119         if(orig_holder->hasRange(property))
00120                 {
00121                 max = orig_holder->getPropertyMaximum<double>(property);
00122                 min = orig_holder->getPropertyMinimum<double>(property);
00123                 gui_holder->addProperty<double>(property,QVPropertyContainer::outputFlag,value,"",min,max);
00124                 gui_holder->linkProperty(property,orig_holder,property,QVPropertyContainer::AsynchronousLink);
00125 
00126                 lineedit = new QLineEdit(this);
00127                 lineedit->setFixedWidth(80);
00128                 qwtslider = new QwtSlider(this,Qt::Horizontal,QwtSlider::NoScale,QwtSlider::BgSlot);
00129                 qwtslider->setThumbLength(20);
00130                 qwtslider->setThumbWidth(10);
00131                 qwtslider->setRange(min,max);
00132                 qwtslider->setFixedWidth(150);
00133 
00134                 QVBoxLayout *vboxlayout = new QVBoxLayout(this);
00135                 vboxlayout->setSpacing(0);
00136                 QHBoxLayout *hboxlayout1 = new QHBoxLayout();
00137                 hboxlayout1->addWidget(new QLabel(QString("<i>double</i> <b>%1</b>").arg(property)));
00138                 hboxlayout1->addStretch();
00139                 hboxlayout1->addWidget(new QLabel(QString("(%1,%2)").arg(min).arg(max)));
00140                 QHBoxLayout *hboxlayout2 = new QHBoxLayout();
00141                 hboxlayout2->addWidget(lineedit);
00142                 hboxlayout2->addStretch();
00143                 hboxlayout2->addWidget(qwtslider);
00144                 vboxlayout->addLayout(hboxlayout1);
00145                 vboxlayout->addLayout(hboxlayout2);
00146 
00147                 qwtslider->setValue(value);
00148                 connect(qwtslider,SIGNAL(valueChanged(double)),this,SLOT(setValue()));
00149                 }
00150         else
00151                 {
00152                 gui_holder->addProperty<double>(property,QVPropertyContainer::outputFlag,value,"");
00153                 gui_holder->linkProperty(property,orig_holder,property,QVPropertyContainer::AsynchronousLink);
00154 
00155                 lineedit = new QLineEdit(this);
00156                 lineedit->setFixedWidth(80);
00157 
00158                 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00159                 hboxlayout->addWidget(new QLabel(QString("<i>double</i> <b>%1</b>").arg(property)));
00160                 hboxlayout->addStretch();
00161                 hboxlayout->addWidget(lineedit);
00162                 //hboxlayout->addStretch();
00163                 }
00164 
00165         connect(lineedit,SIGNAL(editingFinished()),this,SLOT(setValue()));
00166         gui_holder->setPropertyValue<double>(property,value);
00167         lineedit->setText(QString("%1").arg(value));
00168         emit valueChanged(value);
00169 
00170         }
00171 
00172 void QVDoubleParamWidget::setValue()
00173         {
00174         if(sender() == lineedit)
00175                 {
00176                 bool ok;
00177                 value = lineedit->text().toDouble(&ok);
00178                 if( (not ok) or
00179                         (orig_holder->hasRange(property) and (value<min or value>max) ) )
00180                         value = gui_holder->getPropertyValue<double>(property);
00181                 }
00182         else if(sender() == qwtslider) {
00183                 value = qwtslider->value();
00184                 }
00185         else
00186                 value = gui_holder->getPropertyValue<double>(property);
00187 
00188         lineedit->setText(QString("%1").arg(value));
00189         if(orig_holder->hasRange(property))
00190                 qwtslider->setValue(value);
00191         gui_holder->setPropertyValue<double>(property,value);
00192         emit valueChanged(value);
00193         }
00194 
00195 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)
00196         {
00197         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00198         //hboxlayout->setSpacing(0);
00199         QLabel *label = new QLabel(QString("<i>bool</i> <b>%1</b>").arg(property),this);
00200         hboxlayout->addWidget(label);
00201         hboxlayout->addStretch();
00202         checkbox = new QCheckBox(this);
00203         hboxlayout->addWidget(checkbox);
00204 
00205         value = orig_holder->getPropertyValue<bool>(property);
00206 
00207         gui_holder->addProperty<bool>(property,QVPropertyContainer::outputFlag,value,"");
00208 
00209         gui_holder->linkProperty(property,orig_holder,property,QVPropertyContainer::AsynchronousLink);
00210 
00211         connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(setValue()));
00212         gui_holder->setPropertyValue<bool>(property,value);
00213         if(value)
00214                 checkbox->setCheckState(Qt::Checked);
00215         else
00216                 checkbox->setCheckState(Qt::Unchecked);
00217         emit valueChanged(value);
00218         }
00219 
00220 void QVBoolParamWidget::setValue()
00221         {
00222         if (checkbox->checkState() == Qt::Unchecked)
00223                 value = false;
00224         else if (checkbox->checkState() == Qt::Checked)
00225                 value = true;
00226 
00227         gui_holder->setPropertyValue<bool>(property,value);
00228         emit valueChanged(value);
00229         }
00230 
00231 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)
00232         {
00233         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00234         hboxlayout->setSpacing(0);
00235         QLabel *label = new QLabel(QString("<i>string</i> <b>%1</b>").arg(property),this);
00236         hboxlayout->addWidget(label);
00237         lineedit = new QLineEdit(this);
00238         hboxlayout->addWidget(lineedit);
00239 
00240         value = orig_holder->getPropertyValue<QString>(property);
00241         lineedit->setText(value);
00242 
00243         gui_holder->addProperty<QString>(property,QVPropertyContainer::outputFlag,value,"");
00244         gui_holder->linkProperty(property,orig_holder,property,QVPropertyContainer::AsynchronousLink);
00245 
00246         connect(lineedit,SIGNAL(textChanged(QString)),this,SLOT(setValue()));
00247 
00248         gui_holder->setPropertyValue<QString>(property,value);
00249 
00250         emit valueChanged(value);
00251         }
00252 
00253 void QVStringParamWidget::setValue()
00254         {
00255         value = lineedit->text();
00256         gui_holder->setPropertyValue<QString>(property,value);
00257         emit valueChanged(value);
00258         }
00259 
00260 
00261 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)
00262         {
00263         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00264         hboxlayout->setSpacing(0);
00265         QLabel *label = new QLabel(QString("<i>stringlist</i> <b>%1</b>").arg(property),this);
00266         hboxlayout->addWidget(label);
00267         combobox = new QComboBox(this);
00268         hboxlayout->addWidget(combobox);
00269 
00270         value = orig_holder->getPropertyValue<QVIndexedStringList>(property);
00271 
00272         gui_holder->addProperty<QVIndexedStringList>(property,QVPropertyContainer::outputFlag,value,"");
00273         gui_holder->linkProperty(property,orig_holder,property,QVPropertyContainer::AsynchronousLink);
00274 
00275         connect(combobox,SIGNAL(activated(int)),this,SLOT(setValue()));
00276 
00277         gui_holder->setPropertyValue<QVIndexedStringList>(property,value);
00278 
00279         combobox->addItems(value);
00280         combobox->setCurrentIndex(value.getIndex());
00281         emit valueChanged(value);
00282         }
00283 
00284 void QVStringListParamWidget::setValue()
00285         {
00286         value.setIndex(combobox->currentIndex());
00287         gui_holder->setPropertyValue<QVIndexedStringList>(property,value);
00288         emit valueChanged(value);
00289         }
00290 
00291 QVWorkerTriggerWidget::QVWorkerTriggerWidget(QVWorker *worker, const QString triggername, QWidget *parent): QWidget(parent), worker(worker), triggername(triggername)
00292         {
00293         QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00294         toolbutton = new QToolButton(this);
00295         toolbutton->setText(triggername);
00296         hboxlayout->addWidget(new QLabel(QString("<i>trigger</i> <b>%1</b>").arg(triggername)));
00297 hboxlayout->addStretch();
00298         hboxlayout->addWidget(toolbutton);
00299 
00300         connect(toolbutton,SIGNAL(pressed()),this,SLOT(setValue()));
00301         connect(this,SIGNAL(valueChanged(QString)),worker,SLOT(processTrigger(QString)),Qt::QueuedConnection);
00302         }
00303 
00304 void QVWorkerTriggerWidget::setValue()
00305         {
00306         emit valueChanged(triggername);
00307         }
00308 
00309 /*              doublespinbox->setMinimum(min);
00310                 doublespinbox->setMaximum(max);
00311                 int signif=static_cast<int>(round(log(max-min)/log(10)));
00312                 double val=pow(10,signif);
00313                 std::cout << val << " " << signif << std::endl;
00314                 doublespinbox->setSingleStep(val/100);
00315                 if(signif >= 5)
00316                         doublespinbox->setDecimals(0);
00317                 else
00318                         doublespinbox->setDecimals(5-signif);
00319 */
00320 
00321 // -- QVColorParamWidget
00322 QVColorParamWidget::QVColorParamWidget(QVPropertyContainer *_orig_holder, QVPropertyContainer *_gui_holder, const QString _property, QWidget *parent): QWidget(parent), orig_holder(_orig_holder), gui_holder(_gui_holder), property(_property)
00323         {
00324         const int max = 255, min = 0;
00325         value = orig_holder->getPropertyValue<QColor>(property);
00326 
00327         gui_holder->addProperty<QColor>(property,QVPropertyContainer::outputFlag,value,"");
00328         gui_holder->linkProperty(property,orig_holder,property,QVPropertyContainer::AsynchronousLink);
00329 
00330         lineeditR = new QLineEdit(this);
00331         lineeditR->setFixedWidth(80);
00332         lineeditG = new QLineEdit(this);
00333         lineeditG->setFixedWidth(80);
00334         lineeditB = new QLineEdit(this);
00335         lineeditB->setFixedWidth(80);
00336 
00337         sliderR = new QSlider(Qt::Horizontal,this);
00338         sliderR->setMinimum(min);
00339         sliderR->setMaximum(max);
00340         sliderR->setFixedWidth(150);
00341 
00342         sliderG = new QSlider(Qt::Horizontal,this);
00343         sliderG->setMinimum(min);
00344         sliderG->setMaximum(max);
00345         sliderG->setFixedWidth(150);
00346 
00347         sliderB = new QSlider(Qt::Horizontal,this);
00348         sliderB->setMinimum(min);
00349         sliderB->setMaximum(max);
00350         sliderB->setFixedWidth(150);
00351 
00352         QVBoxLayout *vboxlayout = new QVBoxLayout(this);
00353         vboxlayout->setSpacing(0);
00354         QHBoxLayout *hboxlayout1 = new QHBoxLayout();
00355         hboxlayout1->addWidget(new QLabel(QString("<i>int</i> <b>%1</b>").arg(property)));
00356         hboxlayout1->addStretch();
00357         hboxlayout1->addWidget(new QLabel(QString("(%1,%2)").arg(min).arg(max)));
00358 
00359         QHBoxLayout *hboxlayoutR = new QHBoxLayout();
00360         hboxlayoutR->addWidget(lineeditR);
00361         hboxlayoutR->addStretch();
00362         hboxlayoutR->addWidget(sliderR);
00363 
00364         QHBoxLayout *hboxlayoutG = new QHBoxLayout();
00365         hboxlayoutG->addWidget(lineeditG);
00366         hboxlayoutG->addStretch();
00367         hboxlayoutG->addWidget(sliderG);
00368 
00369         QHBoxLayout *hboxlayoutB = new QHBoxLayout();
00370         hboxlayoutB->addWidget(lineeditB);
00371         hboxlayoutB->addStretch();
00372         hboxlayoutB->addWidget(sliderB);
00373         vboxlayout->addLayout(hboxlayout1);
00374         vboxlayout->addLayout(hboxlayoutR);
00375         vboxlayout->addLayout(hboxlayoutG);
00376         vboxlayout->addLayout(hboxlayoutB);
00377 
00378         sliderR->setValue(value.red());
00379         sliderG->setValue(value.green());
00380         sliderB->setValue(value.blue());
00381         connect(sliderR,SIGNAL(valueChanged(int)),this,SLOT(setValue()));
00382         connect(sliderG,SIGNAL(valueChanged(int)),this,SLOT(setValue()));
00383         connect(sliderB,SIGNAL(valueChanged(int)),this,SLOT(setValue()));
00384 
00385         connect(lineeditR,SIGNAL(editingFinished()),this,SLOT(setValue()));
00386         connect(lineeditG,SIGNAL(editingFinished()),this,SLOT(setValue()));
00387         connect(lineeditB,SIGNAL(editingFinished()),this,SLOT(setValue()));
00388         gui_holder->setPropertyValue<QColor>(property,value);
00389         lineeditR->setText(QString("%1").arg(value.red()));
00390         lineeditG->setText(QString("%1").arg(value.green()));
00391         lineeditB->setText(QString("%1").arg(value.blue()));
00392         emit valueChanged(value);
00393         }
00394 
00395 void QVColorParamWidget::setValue()
00396         {
00397         if(sender() == lineeditR || sender() == lineeditG || sender() == lineeditB)
00398                 value = QColor( lineeditR->text().toInt(), lineeditG->text().toInt(), lineeditB->text().toInt() );
00399         else if(sender() == sliderR || sender() == sliderG || sender() == sliderB)
00400                 value = QColor( sliderR->value(), sliderG->value(), sliderB->value() );
00401         else
00402                 value = gui_holder->getPropertyValue<QColor>(property);
00403 
00404         lineeditR->setText(QString("%1").arg(value.red()));
00405         lineeditG->setText(QString("%1").arg(value.green()));
00406         lineeditB->setText(QString("%1").arg(value.blue()));
00407 
00408         sliderR->setValue(value.red());
00409         sliderG->setValue(value.green());
00410         sliderB->setValue(value.blue());
00411 
00412         std::cout << "Setting color to " << value.red() << ", " << value.green() << ", "  << value.blue()
00413                 << std::endl;  
00414         gui_holder->setPropertyValue<QColor>(property,value);
00415         emit valueChanged(value);
00416         }



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