00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00038
00039
00040 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)
00041 {
00042 value = orig_holder->getPropertyValue<int>(property);
00043 if(orig_holder->hasRange(property))
00044 {
00045 max = orig_holder->getPropertyMaximum<int>(property);
00046 min = orig_holder->getPropertyMinimum<int>(property);
00047 gui_holder->addProperty<int>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"",min,max);
00048 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00049
00050 lineedit = new QLineEdit(this);
00051 lineedit->setFixedWidth(80);
00052 slider = new QSlider(Qt::Horizontal,this);
00053 slider->setMinimum(min);
00054 slider->setMaximum(max);
00055 slider->setFixedWidth(150);
00056
00057 QVBoxLayout *vboxlayout = new QVBoxLayout(this);
00058 vboxlayout->setSpacing(0);
00059 QHBoxLayout *hboxlayout1 = new QHBoxLayout();
00060 hboxlayout1->addWidget(new QLabel(QString("<i>int</i> <b>%1</b>").arg(property)));
00061 hboxlayout1->addStretch();
00062 hboxlayout1->addWidget(new QLabel(QString("(%1,%2)").arg(min).arg(max)));
00063 QHBoxLayout *hboxlayout2 = new QHBoxLayout();
00064 hboxlayout2->addWidget(lineedit);
00065 hboxlayout2->addStretch();
00066 hboxlayout2->addWidget(slider);
00067 vboxlayout->addLayout(hboxlayout1);
00068 vboxlayout->addLayout(hboxlayout2);
00069
00070 slider->setValue(value);
00071 connect(slider,SIGNAL(valueChanged(int)),this,SLOT(setValue()));
00072 }
00073 else
00074 {
00075 gui_holder->addProperty<int>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00076 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00077
00078 lineedit = new QLineEdit(this);
00079 lineedit->setFixedWidth(80);
00080
00081 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00082 hboxlayout->addWidget(new QLabel(QString("<i>int</i> <b>%1</b>").arg(property)));
00083 hboxlayout->addWidget(lineedit);
00084 hboxlayout->addStretch();
00085 }
00086
00087 connect(lineedit,SIGNAL(editingFinished()),this,SLOT(setValue()));
00088 gui_holder->setPropertyValue<int>(property+"_internal_gui",value);
00089 lineedit->setText(QString("%1").arg(value));
00090 emit valueChanged(value);
00091 }
00092
00093 void QVIntParamWidget::setValue()
00094 {
00095 if(sender() == lineedit)
00096 {
00097 bool ok;
00098 value = lineedit->text().toInt(&ok);
00099 if( (not ok) or
00100 (orig_holder->hasRange(property) and (value<min or value>max) ) )
00101 value = gui_holder->getPropertyValue<int>(property+"_internal_gui");
00102 }
00103 else if(sender() == slider) {
00104 value = slider->value();
00105 }
00106 else
00107 value = gui_holder->getPropertyValue<int>(property+"_internal_gui");
00108
00109 lineedit->setText(QString("%1").arg(value));
00110 if(orig_holder->hasRange(property))
00111 slider->setValue(value);
00112 gui_holder->setPropertyValue<int>(property+"_internal_gui",value);
00113 emit valueChanged(value);
00114 }
00115
00116
00117 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)
00118 {
00119
00120 value = orig_holder->getPropertyValue<double>(property);
00121 if(orig_holder->hasRange(property))
00122 {
00123 max = orig_holder->getPropertyMaximum<double>(property);
00124 min = orig_holder->getPropertyMinimum<double>(property);
00125 gui_holder->addProperty<double>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"",min,max);
00126 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00127
00128 lineedit = new QLineEdit(this);
00129 lineedit->setFixedWidth(80);
00130 qwtslider = new QwtSlider(this,Qt::Horizontal,QwtSlider::NoScale,QwtSlider::BgSlot);
00131 qwtslider->setThumbLength(20);
00132 qwtslider->setThumbWidth(10);
00133 qwtslider->setRange(min,max);
00134 qwtslider->setFixedWidth(150);
00135
00136 QVBoxLayout *vboxlayout = new QVBoxLayout(this);
00137 vboxlayout->setSpacing(0);
00138 QHBoxLayout *hboxlayout1 = new QHBoxLayout();
00139 hboxlayout1->addWidget(new QLabel(QString("<i>double</i> <b>%1</b>").arg(property)));
00140 hboxlayout1->addStretch();
00141 hboxlayout1->addWidget(new QLabel(QString("(%1,%2)").arg(min).arg(max)));
00142 QHBoxLayout *hboxlayout2 = new QHBoxLayout();
00143 hboxlayout2->addWidget(lineedit);
00144 hboxlayout2->addStretch();
00145 hboxlayout2->addWidget(qwtslider);
00146 vboxlayout->addLayout(hboxlayout1);
00147 vboxlayout->addLayout(hboxlayout2);
00148
00149 qwtslider->setValue(value);
00150 connect(qwtslider,SIGNAL(valueChanged(double)),this,SLOT(setValue()));
00151 }
00152 else
00153 {
00154 gui_holder->addProperty<double>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00155 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00156
00157 lineedit = new QLineEdit(this);
00158 lineedit->setFixedWidth(80);
00159
00160 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00161 hboxlayout->addWidget(new QLabel(QString("<i>double</i> <b>%1</b>").arg(property)));
00162 hboxlayout->addWidget(lineedit);
00163 hboxlayout->addStretch();
00164 }
00165
00166 connect(lineedit,SIGNAL(editingFinished()),this,SLOT(setValue()));
00167 gui_holder->setPropertyValue<double>(property+"_internal_gui",value);
00168 lineedit->setText(QString("%1").arg(value));
00169 emit valueChanged(value);
00170
00171 }
00172
00173 void QVDoubleParamWidget::setValue()
00174 {
00175 if(sender() == lineedit)
00176 {
00177 bool ok;
00178 value = lineedit->text().toDouble(&ok);
00179 if( (not ok) or
00180 (orig_holder->hasRange(property) and (value<min or value>max) ) )
00181 value = gui_holder->getPropertyValue<double>(property+"_internal_gui");
00182 }
00183 else if(sender() == qwtslider) {
00184 value = qwtslider->value();
00185 }
00186 else
00187 value = gui_holder->getPropertyValue<double>(property+"_internal_gui");
00188
00189 lineedit->setText(QString("%1").arg(value));
00190 if(orig_holder->hasRange(property))
00191 qwtslider->setValue(value);
00192 gui_holder->setPropertyValue<double>(property+"_internal_gui",value);
00193 emit valueChanged(value);
00194 }
00195
00196 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)
00197 {
00198 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00199
00200 QLabel *label = new QLabel(QString("<i>bool</i> <b>%1</b>").arg(property),this);
00201 hboxlayout->addWidget(label);
00202 checkbox = new QCheckBox(this);
00203 hboxlayout->addWidget(checkbox);
00204
00205 value = orig_holder->getPropertyValue<bool>(property);
00206
00207 gui_holder->addProperty<bool>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00208
00209 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00210
00211 connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(setValue()));
00212 gui_holder->setPropertyValue<bool>(property+"_internal_gui",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+"_internal_gui",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
00242 gui_holder->addProperty<QString>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00243 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00244
00245 connect(lineedit,SIGNAL(textChanged(QString)),this,SLOT(setValue()));
00246
00247 gui_holder->setPropertyValue<QString>(property+"_internal_gui",value);
00248
00249 emit valueChanged(value);
00250 }
00251
00252 void QVStringParamWidget::setValue()
00253 {
00254 value = lineedit->text();
00255 gui_holder->setPropertyValue<QString>(property+"_internal_gui",value);
00256 emit valueChanged(value);
00257 }
00258
00259
00260 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)
00261 {
00262 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00263 hboxlayout->setSpacing(0);
00264 QLabel *label = new QLabel(QString("<i>stringlist</i> <b>%1</b>").arg(property),this);
00265 hboxlayout->addWidget(label);
00266 combobox = new QComboBox(this);
00267 hboxlayout->addWidget(combobox);
00268
00269 value = orig_holder->getPropertyValue<QVIndexedStringList>(property);
00270
00271 gui_holder->addProperty<QVIndexedStringList>(property+"_internal_gui",QVPropertyContainer::outputFlag,value,"");
00272 gui_holder->linkProperty(property+"_internal_gui",orig_holder,property,QVPropertyContainer::AsynchronousLink);
00273
00274 connect(combobox,SIGNAL(activated(int)),this,SLOT(setValue()));
00275
00276 gui_holder->setPropertyValue<QVIndexedStringList>(property+"_internal_gui",value);
00277
00278 combobox->addItems(value);
00279 combobox->setCurrentIndex(value.getIndex());
00280 emit valueChanged(value);
00281 }
00282
00283 void QVStringListParamWidget::setValue()
00284 {
00285 value.setIndex(combobox->currentIndex());
00286 gui_holder->setPropertyValue<QVIndexedStringList>(property+"_internal_gui",value);
00287 emit valueChanged(value);
00288 }
00289
00290 QVWorkerTriggerWidget::QVWorkerTriggerWidget(QVWorker *worker, const QString triggername, QWidget *parent): QWidget(parent), worker(worker), triggername(triggername)
00291 {
00292 QHBoxLayout *hboxlayout = new QHBoxLayout(this);
00293 toolbutton = new QToolButton(this);
00294 toolbutton->setText(triggername);
00295 hboxlayout->addWidget(new QLabel(QString("<i>trigger</i> <b>%1</b>").arg(triggername)));
00296 hboxlayout->addStretch();
00297 hboxlayout->addWidget(toolbutton);
00298
00299 connect(toolbutton,SIGNAL(pressed()),this,SLOT(setValue()));
00300 connect(this,SIGNAL(valueChanged(QString)),worker,SLOT(processTrigger(QString)));
00301 }
00302
00303 void QVWorkerTriggerWidget::setValue()
00304 {
00305 emit valueChanged(triggername);
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318