1 /****************************************************************************
2 * MeshLab                                                           o o     *
3 * An extendible mesh processor                                    o     o   *
4 *                                                                _   O  _   *
5 * Copyright(C) 2005, 2008                                          \/)\/    *
6 * Visual Computing Lab                                            /\/|      *
7 * ISTI - Italian National Research Council                           |      *
8 *                                                                    \      *
9 * All rights reserved.                                                      *
10 *                                                                           *
11 * This program is free software; you can redistribute it and/or modify      *
12 * it under the terms of the GNU General Public License as published by      *
13 * the Free Software Foundation; either version 2 of the License, or         *
14 * (at your option) any later version.                                       *
15 *                                                                           *
16 * This program is distributed in the hope that it will be useful,           *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
20 * for more details.                                                         *
21 *                                                                           *
22 ****************************************************************************/
23 
24 
25 #include "stdpardialog.h"
26 
27 #include <QLabel>
28 #include <QPushButton>
29 #include <QLineEdit>
30 #include <QFileDialog>
31 #include <QDialogButtonBox>
32 #include <QClipboard>
33 #include <QColorDialog>
34 #include <QToolBar>
35 #include "mainwindow.h"
36 
37 
38 using namespace vcg;
39 
StdParFrame(QWidget * p,QWidget * curr_gla)40 StdParFrame::StdParFrame(QWidget *p, QWidget *curr_gla )
41     :QFrame(p)
42 {
43     gla=curr_gla;
44 }
45 
resetValues(RichParameterSet & curParSet)46 void StdParFrame::resetValues(RichParameterSet &curParSet)
47 {
48     QList<RichParameter*> &parList =curParSet.paramList;
49     assert(stdfieldwidgets.size() == parList.size());
50     for(int i = 0; i < parList.count(); i++)
51     {
52         RichParameter* fpi= parList.at(i);
53         if (fpi != NULL)
54             stdfieldwidgets[i]->resetValue();
55     }
56 }
57 
58 /* creates widgets for the standard parameters */
loadFrameContent(RichParameterSet & curParSet,MeshDocument *)59 void StdParFrame::loadFrameContent(RichParameterSet &curParSet,MeshDocument * /*_mdPt*/ )
60 {
61     if(layout()) delete layout();
62     QGridLayout* glay = new QGridLayout();
63     // QGridLayout *vlayout = new QGridLayout(this);
64     //    vLayout->setAlignment(Qt::AlignTop);
65     RichWidgetInterfaceConstructor rwc(this);
66     for(int i = 0; i < curParSet.paramList.count(); i++)
67     {
68         RichParameter* fpi=curParSet.paramList.at(i);
69         fpi->accept(rwc);
70         //vLayout->addWidget(rwc.lastCreated,i,0,1,1,Qt::AlignTop);
71         stdfieldwidgets.push_back(rwc.lastCreated);
72         helpList.push_back(rwc.lastCreated->helpLab);
73         //glay->addItem(rwc.lastCreated->leftItem(),i,0);
74         //glay->addItem(rwc.lastCreated->centralItem(),i,1);
75         //glay->addItem(rwc.lastCreated->rightItem(),i,2);
76         rwc.lastCreated->addWidgetToGridLayout(glay,i);
77 
78     } // end for each parameter
79     setLayout(glay);
80     this->setMinimumSize(glay->sizeHint());
81 	glay->setSizeConstraint(QLayout::SetMinimumSize);
82     this->showNormal();
83     this->adjustSize();
84 }
85 
toggleHelp()86 void StdParFrame::toggleHelp()
87 {
88     for(int i = 0; i < helpList.count(); i++)
89         helpList.at(i)->setVisible(!helpList.at(i)->isVisible()) ;
90     updateGeometry();
91     adjustSize();
92 }
93 
94 //void StdParFrame::readValues(ParameterDeclarationSet &curParSet)
readValues(RichParameterSet & curParSet)95 void StdParFrame::readValues(RichParameterSet &curParSet)
96 {
97     QList<RichParameter*> &parList =curParSet.paramList;
98     assert(parList.size() == stdfieldwidgets.size());
99     QVector<MeshLabWidget*>::iterator it = stdfieldwidgets.begin();
100     for(int i = 0; i < parList.count(); i++)
101     {
102         QString sname = parList.at(i)->name;
103         curParSet.setValue(sname,(*it)->getWidgetValue());
104         ++it;
105     }
106 }
107 
~StdParFrame()108 StdParFrame::~StdParFrame()
109 {
110 
111 }
112 
113 /* click event for the apply button of the standard plugin window */
114 // If the filter has some dynamic parameters
115 // - before applying the filter restore the original state of the mesh.
116 // - after applying the filter reget the state of the mesh.
117 
118 
119 /******************************************/
120 // AbsPercWidget Implementation
121 /******************************************/
122 
123 
124 //QGridLayout(NULL)
AbsPercWidget(QWidget * p,RichAbsPerc * rabs)125 AbsPercWidget::AbsPercWidget(QWidget *p, RichAbsPerc* rabs):MeshLabWidget(p,rabs)
126 
127 {
128     AbsPercDecoration* absd = reinterpret_cast<AbsPercDecoration*>(rp->pd);
129     m_min = absd->min;
130     m_max = absd->max;
131 
132     fieldDesc = new QLabel(rp->pd->fieldDesc + " (abs and %)",this);
133     fieldDesc->setToolTip(rp->pd->tooltip);
134     absSB = new QDoubleSpinBox(this);
135     percSB = new QDoubleSpinBox(this);
136 
137     absSB->setMinimum(m_min-(m_max-m_min));
138     absSB->setMaximum(m_max*2);
139     absSB->setAlignment(Qt::AlignRight);
140 
141     int decimals= 7-ceil(log10(fabs(m_max-m_min)) ) ;
142     //qDebug("range is (%f %f) %f ",m_max,m_min,fabs(m_max-m_min));
143     //qDebug("log range is %f ",log10(fabs(m_max-m_min)));
144     absSB->setDecimals(decimals);
145     absSB->setSingleStep((m_max-m_min)/100.0);
146     float initVal = rp->val->getAbsPerc();
147     absSB->setValue(initVal);
148 
149     percSB->setMinimum(-200);
150     percSB->setMaximum(200);
151     percSB->setAlignment(Qt::AlignRight);
152     percSB->setSingleStep(0.5);
153     percSB->setValue((100*(initVal - m_min))/(m_max - m_min));
154     percSB->setDecimals(3);
155     QLabel *absLab=new QLabel("<i> <small> world unit</small></i>");
156     QLabel *percLab=new QLabel("<i> <small> perc on"+QString("(%1 .. %2)").arg(m_min).arg(m_max)+"</small></i>");
157 
158     //  gridLay->addWidget(fieldDesc,row,0,Qt::AlignHCenter);
159 
160     vlay = new QGridLayout();
161     vlay->addWidget(absLab,0,0,Qt::AlignHCenter);
162     vlay->addWidget(percLab,0,1,Qt::AlignHCenter);
163 
164     vlay->addWidget(absSB,1,0,Qt::AlignTop);
165     vlay->addWidget(percSB,1,1,Qt::AlignTop);
166 
167     //gridLay->addLayout(lay,row,1,Qt::AlignTop);
168 
169     connect(absSB,SIGNAL(valueChanged(double)),this,SLOT(on_absSB_valueChanged(double)));
170     connect(percSB,SIGNAL(valueChanged(double)),this,SLOT(on_percSB_valueChanged(double)));
171     connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
172 }
173 
~AbsPercWidget()174 AbsPercWidget::~AbsPercWidget()
175 {
176     delete absSB;
177     delete percSB;
178     delete fieldDesc;
179 }
180 
181 
on_absSB_valueChanged(double newv)182 void AbsPercWidget::on_absSB_valueChanged(double newv)
183 {
184     disconnect(percSB,SIGNAL(valueChanged(double)),this,SLOT(on_percSB_valueChanged(double)));
185     percSB->setValue((100*(newv - m_min))/(m_max - m_min));
186     connect(percSB,SIGNAL(valueChanged(double)),this,SLOT(on_percSB_valueChanged(double)));
187     emit dialogParamChanged();
188 }
189 
on_percSB_valueChanged(double newv)190 void AbsPercWidget::on_percSB_valueChanged(double newv)
191 {
192     disconnect(absSB,SIGNAL(valueChanged(double)),this,SLOT(on_absSB_valueChanged(double)));
193     absSB->setValue((m_max - m_min)*0.01*newv + m_min);
194     connect(absSB,SIGNAL(valueChanged(double)),this,SLOT(on_absSB_valueChanged(double)));
195     emit dialogParamChanged();
196 }
197 
198 //float AbsPercWidget::getValue()
199 //{
200 //	return float(absSB->value());
201 //}
202 
setValue(float val,float minV,float maxV)203 void AbsPercWidget::setValue(float val, float minV, float maxV)
204 {
205     assert(absSB);
206     absSB->setValue(val);
207     m_min=minV;
208     m_max=maxV;
209 }
210 
collectWidgetValue()211 void AbsPercWidget::collectWidgetValue()
212 {
213     rp->val->set(AbsPercValue(float(absSB->value())));
214 }
215 
resetWidgetValue()216 void AbsPercWidget::resetWidgetValue()
217 {
218     const AbsPercDecoration* absd = reinterpret_cast<const AbsPercDecoration*>(&(rp->pd));
219     setValue(rp->pd->defVal->getAbsPerc(),absd->min,absd->max);
220 }
221 
setWidgetValue(const Value & nv)222 void AbsPercWidget::setWidgetValue( const Value& nv )
223 {
224     const AbsPercDecoration* absd = reinterpret_cast<const AbsPercDecoration*>(&(rp->pd));
225     setValue(nv.getAbsPerc(),absd->min,absd->max);
226 }
227 
addWidgetToGridLayout(QGridLayout * lay,const int r)228 void AbsPercWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
229 {
230     if (lay != NULL)
231     {
232         lay->addWidget(fieldDesc,r,0,Qt::AlignLeft);
233         lay->addLayout(vlay,r,1,Qt::AlignTop);
234     }
235     MeshLabWidget::addWidgetToGridLayout(lay,r);
236 }
237 /******************************************/
238 // Point3fWidget Implementation
239 /******************************************/
240 
241 
242 //QHBoxLayout(NULL)
Point3fWidget(QWidget * p,RichPoint3f * rpf,QWidget * gla_curr)243 Point3fWidget::Point3fWidget(QWidget *p, RichPoint3f* rpf, QWidget *gla_curr): MeshLabWidget(p,rpf)
244 {
245     //qDebug("Creating a Point3fWidget");
246     paramName = rpf->name;
247     //int row = gridLay->rowCount() - 1;
248     descLab = new QLabel(rpf->pd->fieldDesc,this);
249     descLab->setToolTip(rpf->pd->fieldDesc);
250     //gridLay->addWidget(descLab,row,0);
251 
252     vlay = new QHBoxLayout();
253     vlay->setSpacing(0);
254     for(int i =0;i<3;++i)
255     {
256         coordSB[i]= new QLineEdit(this);
257         QFont baseFont=coordSB[i]->font();
258         if(baseFont.pixelSize() != -1) baseFont.setPixelSize(baseFont.pixelSize()*3/4);
259         else baseFont.setPointSize(baseFont.pointSize()*3/4);
260         coordSB[i]->setFont(baseFont);
261         coordSB[i]->setMaximumWidth(coordSB[i]->sizeHint().width()/2);
262         coordSB[i]->setValidator(new QDoubleValidator());
263         coordSB[i]->setAlignment(Qt::AlignRight);
264         coordSB[i]->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
265         vlay->addWidget(coordSB[i]);
266         connect(coordSB[i],SIGNAL(textChanged(QString)),p,SIGNAL(parameterChanged()));
267     }
268     this->setValue(paramName,rp->val->getPoint3f());
269     if(gla_curr) // if we have a connection to the current glarea we can setup the additional button for getting the current view direction.
270     {
271         getPoint3Button = new QPushButton("Get",this);
272         getPoint3Button->setMaximumWidth(getPoint3Button->sizeHint().width()/2);
273 
274         getPoint3Button->setFlat(true);
275         getPoint3Button->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Preferred);
276         //getPoint3Button->setMinimumWidth(getPoint3Button->sizeHint().width());
277         //this->addWidget(getPoint3Button,0,Qt::AlignHCenter);
278         vlay->addWidget(getPoint3Button);
279         QStringList names;
280         names << "View Dir.";
281         names << "View Pos.";
282         names << "Surf. Pos.";
283         names << "Raster Camera Pos.";
284 		names << "Trackball Center";
285 
286         getPoint3Combo = new QComboBox(this);
287         getPoint3Combo->addItems(names);
288         //getPoint3Combo->setMinimumWidth(getPoint3Combo->sizeHint().width());
289         //this->addWidget(getPoint3Combo,0,Qt::AlignHCenter);
290         vlay->addWidget(getPoint3Combo);
291 
292         connect(getPoint3Button,SIGNAL(clicked()),this,SLOT(getPoint()));
293         connect(getPoint3Combo,SIGNAL(currentIndexChanged(int)),this,SLOT(getPoint()));
294         connect(gla_curr,SIGNAL(transmitViewDir(QString,Point3m)),this,SLOT(setValue(QString,Point3m)));
295         connect(gla_curr,SIGNAL(transmitShot(QString,Shotm)),this,SLOT(setShotValue(QString,Shotm)));
296         connect(gla_curr,SIGNAL(transmitSurfacePos(QString,Point3m)),this,SLOT(setValue(QString,Point3m)));
297 		connect(gla_curr,SIGNAL(transmitCameraPos(QString, Point3m)),this,SLOT(setValue(QString, Point3m)));
298 		connect(gla_curr,SIGNAL(transmitTrackballPos(QString, Point3m)),this,SLOT(setValue(QString, Point3m)));
299         connect(this,SIGNAL(askViewDir(QString)),gla_curr,SLOT(sendViewDir(QString)));
300         connect(this,SIGNAL(askViewPos(QString)),gla_curr,SLOT(sendViewerShot(QString)));
301         connect(this,SIGNAL(askSurfacePos(QString)),gla_curr,SLOT(sendSurfacePos(QString)));
302         connect(this,SIGNAL(askCameraPos(QString)),gla_curr,SLOT(sendRasterShot(QString)));
303 		connect(this,SIGNAL(askTrackballPos(QString)),gla_curr,SLOT(sendTrackballPos(QString)));
304     }
305     //gridLay->addLayout(lay,row,1,Qt::AlignTop);
306 }
307 
getPoint()308 void Point3fWidget::getPoint()
309 {
310     int index = getPoint3Combo->currentIndex();
311     //qDebug("Got signal %i",index);
312     switch(index)
313     {
314 		case 0: emit askViewDir(paramName);       break;
315 		case 1: emit askViewPos(paramName);       break;
316 		case 2: emit askSurfacePos(paramName);    break;
317 		case 3: emit askCameraPos(paramName);     break;
318 		case 4: emit askTrackballPos(paramName);  break;
319 		default : assert(0);
320     }
321 }
322 
~Point3fWidget()323 Point3fWidget::~Point3fWidget() {
324     //qDebug("Deallocating a point3fwidget");
325     this->disconnect();
326 }
327 
setValue(QString name,Point3m newVal)328 void Point3fWidget::setValue(QString name,Point3m newVal)
329 {
330     //qDebug("setValue parametername: %s ", qUtf8Printable(name));
331     if(name==paramName)
332     {
333         for(int i =0;i<3;++i)
334             coordSB[i]->setText(QString::number(newVal[i],'g',4));
335     }
336 }
337 
setShotValue(QString name,Shotf newValShot)338 void Point3fWidget::setShotValue(QString name,Shotf newValShot)
339 {
340     Point3f p = newValShot.GetViewPoint();
341     setValue(name,p);
342 }
343 
getValue()344 vcg::Point3f Point3fWidget::getValue()
345 {
346     return Point3f(coordSB[0]->text().toFloat(),coordSB[1]->text().toFloat(),coordSB[2]->text().toFloat());
347 }
348 
collectWidgetValue()349 void Point3fWidget::collectWidgetValue()
350 {
351     rp->val->set(Point3fValue(vcg::Point3f(coordSB[0]->text().toFloat(),coordSB[1]->text().toFloat(),coordSB[2]->text().toFloat())));
352 }
353 
resetWidgetValue()354 void Point3fWidget::resetWidgetValue()
355 {
356     for(unsigned int ii = 0; ii < 3;++ii)
357         coordSB[ii]->setText(QString::number(rp->pd->defVal->getPoint3f()[ii],'g',3));
358 }
359 
setWidgetValue(const Value & nv)360 void Point3fWidget::setWidgetValue( const Value& nv )
361 {
362     for(unsigned int ii = 0; ii < 3;++ii)
363         coordSB[ii]->setText(QString::number(nv.getPoint3f()[ii],'g',3));
364 }
365 
addWidgetToGridLayout(QGridLayout * lay,const int r)366 void Point3fWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
367 {
368     if (lay != NULL)
369     {
370         lay->addWidget(descLab,r,0);
371         lay->addLayout(vlay,r,1);
372     }
373     MeshLabWidget::addWidgetToGridLayout(lay,r);
374 }
375 /******************************************/
376 // Matrix44fWidget Implementation
377 /******************************************/
378 
379 
380 //QHBoxLayout(NULL)
Matrix44fWidget(QWidget * p,RichMatrix44f * rpf,QWidget * gla_curr)381 Matrix44fWidget::Matrix44fWidget(QWidget *p, RichMatrix44f* rpf,  QWidget *gla_curr): MeshLabWidget(p,rpf)
382 {
383     valid = false;
384     m.SetIdentity();
385     paramName = rpf->name;
386     //int row = gridLay->rowCount() - 1;
387 
388     descLab = new QLabel(rpf->pd->fieldDesc,this);
389     descLab->setToolTip(rpf->pd->fieldDesc);
390     //gridLay->addWidget(descLab,row,0,Qt::AlignTop);
391     vlay = new QVBoxLayout();
392     lay44 = new QGridLayout();
393 
394 
395 
396     for(int i =0;i<16;++i)
397     {
398         coordSB[i]= new QLineEdit(p);
399         QFont baseFont=coordSB[i]->font();
400         if(baseFont.pixelSize() != -1) baseFont.setPixelSize(baseFont.pixelSize()*3/4);
401         else baseFont.setPointSize(baseFont.pointSize()*3/4);
402         coordSB[i]->setFont(baseFont);
403         //coordSB[i]->setMinimumWidth(coordSB[i]->sizeHint().width()/4);
404         coordSB[i]->setMinimumWidth(0);
405         coordSB[i]->setMaximumWidth(coordSB[i]->sizeHint().width()/2);
406         //coordSB[i]->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
407         coordSB[i]->setValidator(new QDoubleValidator(p));
408         coordSB[i]->setAlignment(Qt::AlignRight);
409         //this->addWidget(coordSB[i],1,Qt::AlignHCenter);
410         lay44->addWidget(coordSB[i],i/4,i%4);
411         connect(coordSB[i], SIGNAL(textChanged(const QString&)), this, SLOT(invalidateMatrix(const QString&)));
412     }
413     this->setValue(paramName,rp->val->getMatrix44f());
414 
415 	QLabel* headerL = new QLabel("Matrix:", this);
416 	vlay->addWidget(headerL, 0, Qt::AlignTop);
417 
418     vlay->addLayout(lay44);
419 
420     QPushButton     * getMatrixButton = new QPushButton("Read from current layer");
421     vlay->addWidget(getMatrixButton);
422 
423     QPushButton     * pasteMatrixButton = new QPushButton("Paste from clipboard");
424     vlay->addWidget(pasteMatrixButton);
425 
426     //gridLay->addLayout(vlay,row,1,Qt::AlignTop);
427 
428     connect(gla_curr,SIGNAL(transmitMatrix(QString,Matrix44m)),this,SLOT(setValue(QString,Matrix44m)));
429     connect(getMatrixButton,SIGNAL(clicked()),this,SLOT(getMatrix()));
430     connect(pasteMatrixButton,SIGNAL(clicked()),this,SLOT(pasteMatrix()));
431     connect(this,SIGNAL(askMeshMatrix(QString)),  gla_curr,SLOT(sendMeshMatrix(QString)));
432 
433 }
434 
435 
~Matrix44fWidget()436 Matrix44fWidget::~Matrix44fWidget() {}
437 
setValue(QString name,Matrix44m newVal)438 void Matrix44fWidget::setValue(QString name,Matrix44m newVal)
439 {
440     if(name==paramName)
441     {
442         for(int i =0;i<16;++i)
443             coordSB[i]->setText(QString::number(newVal[i/4][i%4],'g',4));
444         valid = true;
445         m = newVal;
446     }
447 }
448 
449 
getValue()450 vcg::Matrix44f Matrix44fWidget::getValue()
451 {
452   if (!valid)
453   {
454     float val[16];
455     for (unsigned int i = 0; i < 16; ++i)
456       val[i] = coordSB[i]->text().toFloat();
457     return Matrix44f(val);
458   }
459   return m;
460 }
461 
getMatrix()462 void Matrix44fWidget::getMatrix()
463 {
464     emit askMeshMatrix(QString("TransformMatrix"));
465 }
466 
pasteMatrix()467 void Matrix44fWidget::pasteMatrix()
468 {
469     QClipboard *clipboard = QApplication::clipboard();
470     QString shotString = clipboard->text().trimmed();
471     if (shotString.contains(' '))
472     {
473       QStringList list1 = shotString.split(" ");
474       if (list1.size() != 16)
475         return;
476       valid = false;
477       int id = 0;
478       for (QStringList::iterator i = list1.begin(); i != list1.end(); ++i, ++id) {
479         bool ok = true;
480         (*i).toFloat(&ok);
481         if (!ok) return;
482       }
483       id = 0;
484       for (QStringList::iterator i = list1.begin(); i != list1.end(); ++i, ++id)
485         coordSB[id]->setText(*i);
486     }
487     else
488     {
489       QByteArray value = QByteArray::fromBase64(shotString.toLocal8Bit());
490       memcpy(m.V(), value.data(), sizeof(Matrix44m::ScalarType) * 16);
491       int id = 0;
492       for (int i = 0; i < 16; ++i, ++id)
493         coordSB[id]->setText(QString::number(m.V()[i]));
494     }
495 }
496 
collectWidgetValue()497 void Matrix44fWidget::collectWidgetValue()
498 {
499   if (!valid)
500   {
501     vcg::Matrix44f  tempM;
502     for (unsigned int i = 0; i < 16; ++i) tempM[i / 4][i % 4] = coordSB[i]->text().toFloat();
503     rp->val->set(Matrix44fValue(tempM));
504   }
505   else
506     rp->val->set(Matrix44fValue(m));
507 }
508 
resetWidgetValue()509 void Matrix44fWidget::resetWidgetValue()
510 {
511   valid = false;
512     vcg::Matrix44f  m; m.SetIdentity();
513     for(unsigned int ii = 0; ii < 16;++ii)
514         coordSB[ii]->setText(QString::number(rp->pd->defVal->getMatrix44f()[ii/4][ii%4],'g',3));
515 }
516 
setWidgetValue(const Value & nv)517 void Matrix44fWidget::setWidgetValue( const Value& nv )
518 {
519   valid = true;
520   m = nv.getMatrix44f();
521     for(unsigned int ii = 0; ii < 16;++ii)
522         coordSB[ii]->setText(QString::number(nv.getMatrix44f()[ii/4][ii%4],'g',3));
523 }
524 
addWidgetToGridLayout(QGridLayout * lay,const int r)525 void Matrix44fWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
526 {
527     if (lay != NULL)
528     {
529         lay->addWidget(descLab,r,0,Qt::AlignTop);
530         lay->addLayout(vlay,r,1,Qt::AlignTop);
531     }
532     MeshLabWidget::addWidgetToGridLayout(lay,r);
533 }
534 
invalidateMatrix(const QString &)535 void Matrix44fWidget::invalidateMatrix(const QString& /*s*/)
536 {
537   valid = false;
538 }
539 
540 /********************/
541 // ShotfWidget Implementation
542 
ShotfWidget(QWidget * p,RichShotf * rpf,QWidget * gla_curr)543 ShotfWidget::ShotfWidget(QWidget *p, RichShotf* rpf, QWidget *gla_curr): MeshLabWidget(p,rpf)
544 {
545 
546     paramName = rpf->name;
547     //int row = gridLay->rowCount() - 1;
548 
549     descLab = new QLabel(rpf->pd->fieldDesc,p);
550     descLab->setToolTip(rpf->pd->fieldDesc);
551     //gridLay->addWidget(descLab,row,0,Qt::AlignTop);
552 
553     hlay = new QHBoxLayout();
554 
555 
556     this->setShotValue(paramName,rp->val->getShotf());
557     if(gla_curr) // if we have a connection to the current glarea we can setup the additional button for getting the current view direction.
558     {
559         getShotButton = new QPushButton("Get shot",this);
560         getShotButton->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
561         hlay->addWidget(getShotButton);
562 
563         QStringList names;
564         names << "Current Trackball";
565         names << "Current Mesh";
566         names << "Current Raster";
567         names << "From File";
568 
569         getShotCombo = new QComboBox(this);
570         getShotCombo->addItems(names);
571         hlay->addWidget(getShotCombo);
572         connect(getShotCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(getShot()));
573         connect(getShotButton,SIGNAL(clicked()),this,SLOT(getShot()));
574         connect(gla_curr,SIGNAL(transmitShot(QString, Shotm)),this,SLOT(setShotValue(QString,Shotm)));
575         connect(this,SIGNAL(askViewerShot(QString)),gla_curr,SLOT(sendViewerShot(QString)));
576         connect(this,SIGNAL(askMeshShot(QString)),  gla_curr,SLOT(sendMeshShot(QString)));
577         connect(this,SIGNAL(askRasterShot(QString)),gla_curr,SLOT(sendRasterShot(QString)));
578     }
579     //gridLay->addLayout(hlay,row,1,Qt::AlignTop);
580 }
581 
getShot()582 void ShotfWidget::getShot()
583 {
584     int index = getShotCombo->currentIndex();
585     switch(index)  {
586     case 0 : emit askViewerShot(paramName); break;
587     case 1 : emit askMeshShot(paramName); break;
588     case 2 : emit askRasterShot(paramName); break;
589     case 3:
590         {
591             QString filename = QFileDialog::getOpenFileName(this, tr("Load xml camera"), "./", tr("Xml Files (*.xml)"));
592             QFile qf(filename);
593             QFileInfo qfInfo(filename);
594 
595             if( !qf.open(QIODevice::ReadOnly ) )
596                 return ;
597 
598             QDomDocument doc("XmlDocument");    //It represents the XML document
599             if(!doc.setContent( &qf ))     return;
600             qf.close();
601 
602             QString type = doc.doctype().name();
603 
604             //TextAlign file project
605             //if(type == "RegProjectML")   loadShotFromTextAlignFile(doc);
606             //View State file
607             //else if(type == "ViewState") loadViewFromViewStateFile(doc);
608 
609             //qDebug("End file reading");
610 
611 
612             // return true;
613         }
614     default : assert(0);
615     }
616 }
617 
~ShotfWidget()618 ShotfWidget::~ShotfWidget() {}
619 
setShotValue(QString name,Shotm newVal)620 void ShotfWidget::setShotValue(QString name,Shotm newVal)
621 {
622     if(name==paramName)
623     {
624         curShot=newVal;
625     }
626 }
627 
getValue()628 vcg::Shotf ShotfWidget::getValue()
629 {
630     return curShot;
631 }
632 
collectWidgetValue()633 void ShotfWidget::collectWidgetValue()
634 {
635     rp->val->set(ShotfValue(curShot));
636 }
637 
resetWidgetValue()638 void ShotfWidget::resetWidgetValue()
639 {
640     curShot = rp->pd->defVal->getShotf();
641 }
642 
setWidgetValue(const Value & nv)643 void ShotfWidget::setWidgetValue( const Value& nv )
644 {
645     curShot = nv.getShotf();
646 }
647 
addWidgetToGridLayout(QGridLayout * lay,const int r)648 void ShotfWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
649 {
650     if (lay != NULL)
651     {
652         lay->addLayout(hlay,r,1);
653         lay->addWidget(descLab,r,0);
654     }
655     MeshLabWidget::addWidgetToGridLayout(lay,r);
656 }
657 /********************/
658 // ComboWidget End Implementation
659 
ComboWidget(QWidget * p,RichParameter * rpar)660 ComboWidget::ComboWidget(QWidget *p, RichParameter* rpar) :MeshLabWidget(p,rpar) {
661 }
662 
Init(QWidget * p,int defaultEnum,QStringList values)663 void ComboWidget::Init(QWidget *p,int defaultEnum, QStringList values)
664 {
665     enumLabel = new QLabel(this);
666     enumLabel->setText(rp->pd->fieldDesc);
667     enumCombo = new QComboBox(this);
668     enumCombo->addItems(values);
669     setIndex(defaultEnum);
670     //int row = gridLay->rowCount() - 1;
671     //gridLay->addWidget(enumLabel,row,0,Qt::AlignTop);
672     //gridLay->addWidget(enumCombo,row,1,Qt::AlignTop);
673     connect(enumCombo,SIGNAL(activated(int)),this,SIGNAL(dialogParamChanged()));
674     connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
675 }
676 
setIndex(int newEnum)677 void ComboWidget::setIndex(int newEnum)
678 {
679     enumCombo->setCurrentIndex(newEnum);
680 }
681 
getIndex()682 int ComboWidget::getIndex()
683 {
684     return enumCombo->currentIndex();
685 }
686 
~ComboWidget()687 ComboWidget::~ComboWidget()
688 {
689     delete enumCombo;
690     delete enumLabel;
691 }
692 
addWidgetToGridLayout(QGridLayout * lay,const int r)693 void ComboWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
694 {
695     if (lay != NULL)
696     {
697         lay->addWidget(enumLabel,r,0);
698         lay->addWidget(enumCombo,r,1);
699     }
700     MeshLabWidget::addWidgetToGridLayout(lay,r);
701 }
702 /******************************************/
703 //EnumWidget Implementation
704 /******************************************/
705 
EnumWidget(QWidget * p,RichEnum * rpar)706 EnumWidget::EnumWidget(QWidget *p, RichEnum* rpar)
707     :ComboWidget(p,rpar)
708 {
709     //you MUST call it!!!!
710     Init(p,rpar->val->getEnum(),reinterpret_cast<EnumDecoration*>(rpar->pd)->enumvalues);
711     //assert(enumCombo != NULL);
712 }
713 
getSize()714 int EnumWidget::getSize()
715 {
716     return enumCombo->count();
717 }
718 
719 
collectWidgetValue()720 void EnumWidget::collectWidgetValue()
721 {
722     rp->val->set(EnumValue(enumCombo->currentIndex()));
723 }
724 
resetWidgetValue()725 void EnumWidget::resetWidgetValue()
726 {
727     //lned->setText(QString::number(rp->val->getFloat(),'g',3));
728     enumCombo->setCurrentIndex(rp->pd->defVal->getEnum());
729 }
730 
setWidgetValue(const Value & nv)731 void EnumWidget::setWidgetValue( const Value& nv )
732 {
733     enumCombo->setCurrentIndex(nv.getEnum());
734 }
735 
736 /******************************************/
737 //MeshEnumWidget Implementation
738 /******************************************/
739 
740 
MeshWidget(QWidget * p,RichMesh * rpar)741 MeshWidget::MeshWidget(QWidget *p, RichMesh* rpar)
742     :ComboWidget(p,rpar)
743 {
744     md=reinterpret_cast<MeshDecoration*>(rp->pd)->meshdoc;
745 
746     QStringList meshNames;
747 
748     //make the default mesh Index be 0
749     //defaultMeshIndex = -1;
750 
751     int currentmeshindex = -1;
752     for(int i=0;i<md->meshList.size();++i)
753     {
754         QString shortName = md->meshList.at(i)->label();
755         meshNames.push_back(shortName);
756         /*  if(md->meshList.at(i) == rp->pd->defVal->getMesh())
757         defaultMeshIndex = i;*/
758         if(md->meshList.at(i) == rp->val->getMesh())
759         {
760             currentmeshindex = i;
761             rpar->meshindex = currentmeshindex;
762         }
763     }
764 
765     //add a blank choice because there is no default available
766     //if(defaultMeshIndex == -1)
767     //{
768     //    meshNames.push_back("");
769     //    defaultMeshIndex = meshNames.size()-1;  //have the blank choice be shown
770     //}
771     Init(p,currentmeshindex,meshNames);
772 }
773 
getMesh()774 MeshModel * MeshWidget::getMesh()
775 {
776     //test to make sure index is in bounds
777     int index = enumCombo->currentIndex();
778     if(index < md->meshList.size() && index > -1)
779     {
780         //RichMesh* rm = reinterpret_cast<RichMesh*>(rp);
781         //rm->meshindex = index;
782         return md->meshList.at(enumCombo->currentIndex());
783     }
784     else return NULL;
785 }
786 
setMesh(MeshModel * newMesh)787 void MeshWidget::setMesh(MeshModel * newMesh)
788 {
789     for(int i=0; i < md->meshList.size(); ++i)
790     {
791         if(md->meshList.at(i) == newMesh)
792             setIndex(i);
793     }
794 }
795 
collectWidgetValue()796 void MeshWidget::collectWidgetValue()
797 {
798     //MeshDecoration* dec = reinterpret_cast<MeshDecoration*>(rp->pd);
799     RichMesh* rm = reinterpret_cast<RichMesh*>(rp);
800     rm->meshindex = enumCombo->currentIndex();
801     rp->val->set(MeshValue(md->meshList.at(rm->meshindex)));
802 }
803 
resetWidgetValue()804 void MeshWidget::resetWidgetValue()
805 {
806     int meshindex = -1;
807     for(int i=0;i<md->meshList.size();++i)
808     {
809         if(md->meshList.at(i) == rp->pd->defVal->getMesh())
810         {
811             meshindex = i;
812             //RichMesh* rm = reinterpret_cast<RichMesh*>(rp);
813             //rm->meshindex = enumCombo->currentIndex();
814         }
815 
816     }
817     enumCombo->setCurrentIndex(meshindex);
818 }
819 
setWidgetValue(const Value & nv)820 void MeshWidget::setWidgetValue( const Value& nv )
821 {
822     //WARNING!!!!! I HAVE TO THINK CAREFULLY ABOUT THIS FUNCTION!!!
823     //assert(0);
824     int meshindex = -1;
825     for(int i=0;i<md->meshList.size();++i)
826     {
827         if(md->meshList.at(i) == nv.getMesh())
828         {
829             meshindex = i;
830             //RichMesh* rm = reinterpret_cast<RichMesh*>(rp);
831             //rm->meshindex = meshindex;
832         }
833     }
834     enumCombo->setCurrentIndex(meshindex);
835 }
836 
837 /******************************************
838 QVariantListWidget Implementation
839 ******************************************/
840 
841 /*
842 QVariantListWidget::QVariantListWidget(QWidget *parent, QList<QVariant> &values)
843 {
844 tableWidget = new QTableWidget(parent);
845 tableWidget->setColumnCount(1);
846 tableWidget->setRowCount(values.size() );
847 tableWidget->setMaximumSize(135, 180);
848 tableWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
849 tableWidget->horizontalHeader()->setDisabled(true);
850 
851 setList(values);
852 
853 this->addWidget(tableWidget);
854 }
855 
856 QList<QVariant> QVariantListWidget::getList()
857 {
858 QList<QVariant> values;
859 
860 for(int i = 0; i < tableWidget->rowCount(); i++)
861 {
862 QString rowValue = tableWidget->item(i,0)->text();
863 
864 //if the row was not blank
865 if("" != rowValue) values.push_back(QVariant(rowValue));
866 }
867 
868 return values;
869 }
870 
871 
872 void QVariantListWidget::setList(QList<QVariant> &values)
873 {
874 tableWidget->clearContents();
875 tableWidget->setRowCount(values.size() );
876 for(int i = 0; i < values.size(); i++)
877 {
878 tableWidget->setItem(i, 0, new QTableWidgetItem(values.at(i).toString()));
879 }
880 }
881 
882 void QVariantListWidget::addRow()
883 {
884 int count = tableWidget->rowCount();
885 
886 //insert a new row at the end
887 tableWidget->insertRow(count);
888 
889 //fill row with something so that it can be removed if left blank... qt forces us to do this
890 tableWidget->setItem(count, 0, new QTableWidgetItem(""));
891 }
892 
893 
894 void QVariantListWidget::removeRow()
895 {
896 QList<QTableWidgetItem *> items = tableWidget->selectedItems();
897 
898 if(items.size() == 0){
899 //remove the last row if none are selected
900 tableWidget->removeRow(tableWidget->rowCount()-1);
901 } else
902 {
903 //remove each selected row
904 for(int i = 0; i < items.size(); i++){
905 tableWidget->removeRow(items.at(i)->row());
906 }
907 }
908 }
909 */
910 
911 /******************************************
912 GetFileNameButton Implementation
913 ******************************************/
914 
915 /*
916 GetFileNameWidget::GetFileNameWidget(QWidget *parent,
917 QString &defaultString, bool getOpenFileName, QString fileExtension) : QVBoxLayout(parent)
918 {
919 _fileName = defaultString;
920 _fileExtension = fileExtension;
921 
922 _getOpenFileName = getOpenFileName;
923 
924 launchFileNameDialogButton = new QPushButton(QString("Get FileName"), parent);
925 fileNameLabel = new QLabel(_fileName, parent);
926 
927 addWidget(launchFileNameDialogButton);
928 addWidget(fileNameLabel);
929 
930 connect(launchFileNameDialogButton, SIGNAL(clicked()), this, SLOT(launchGetFileNameDialog()));
931 
932 }
933 
934 GetFileNameWidget::~GetFileNameWidget()
935 {
936 delete launchFileNameDialogButton;
937 }
938 
939 QString GetFileNameWidget::getFileName()
940 {
941 return _fileName;
942 }
943 
944 void GetFileNameWidget::launchGetFileNameDialog()
945 {
946 QString temp;
947 if(_getOpenFileName){
948 temp = QFileDialog::getOpenFileName(parentWidget(), tr("Select File"),".", "*"+_fileExtension);
949 } else
950 temp = QFileDialog::getSaveFileName(parentWidget(), tr("Select File"),".", "*"+_fileExtension);
951 
952 if(temp != ""){
953 _fileName = temp;
954 fileNameLabel->setText(QFileInfo(_fileName).fileName());
955 }
956 }
957 
958 void GetFileNameWidget::setFileName(QString newName){
959 _fileName = newName;
960 }
961 */
962 
GenericParamDialog(QWidget * p,RichParameterSet * _curParSet,QString title,MeshDocument * _meshDocument)963 GenericParamDialog::GenericParamDialog(QWidget *p, RichParameterSet *_curParSet, QString title, MeshDocument *_meshDocument)
964     : QDialog(p) {
965         stdParFrame=NULL;
966         curParSet=_curParSet;
967         meshDocument = _meshDocument;
968         createFrame();
969         if(!title.isEmpty())
970             setWindowTitle(title);
971 }
972 
973 
974 // update the values of the widgets with the values in the paramlist;
resetValues()975 void GenericParamDialog::resetValues()
976 {
977     stdParFrame->resetValues(*curParSet);
978 }
979 
toggleHelp()980 void GenericParamDialog::toggleHelp()
981 {
982     stdParFrame->toggleHelp();
983     this->updateGeometry();
984     this->adjustSize();
985 }
986 
987 
createFrame()988 void GenericParamDialog::createFrame()
989 {
990     QVBoxLayout *vboxLayout = new QVBoxLayout(this);
991     setLayout(vboxLayout);
992 
993     stdParFrame = new StdParFrame(this);
994     stdParFrame->loadFrameContent(*curParSet, meshDocument);
995     layout()->addWidget(stdParFrame);
996 
997     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok  | QDialogButtonBox::Cancel);
998     //add the reset button so we can get its signals
999     QPushButton *resetButton = buttonBox->addButton(QDialogButtonBox::Reset);
1000     layout()->addWidget(buttonBox);
1001 
1002     connect(buttonBox, SIGNAL(accepted()), this, SLOT(getAccept()));
1003     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
1004     connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(toggleHelp()));
1005     connect(resetButton, SIGNAL(clicked()), this, SLOT(resetValues()));
1006 
1007     setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
1008 
1009     //set the minimum size so it will shrink down to the right size	after the help is toggled
1010     this->setMinimumSize(stdParFrame->sizeHint());
1011     this->showNormal();
1012     this->adjustSize();
1013 }
1014 
1015 
getAccept()1016 void GenericParamDialog::getAccept()
1017 {
1018     stdParFrame->readValues(*curParSet);
1019     accept();
1020 }
1021 
~GenericParamDialog()1022 GenericParamDialog::~GenericParamDialog()
1023 {
1024     delete stdParFrame;
1025 }
1026 
1027 /******************************************/
1028 // DynamicFloatWidget Implementation
1029 /******************************************/
1030 
1031 
1032 //QGridLayout(NULL)
DynamicFloatWidget(QWidget * p,RichDynamicFloat * rdf)1033 DynamicFloatWidget::DynamicFloatWidget(QWidget *p, RichDynamicFloat* rdf):MeshLabWidget(p,rdf)
1034 {
1035     int numbdecimaldigit = 4;
1036     minVal = reinterpret_cast<DynamicFloatDecoration*>(rdf->pd)->min;
1037     maxVal = reinterpret_cast<DynamicFloatDecoration*>(rdf->pd)->max;
1038     valueLE = new QLineEdit(this);
1039     valueLE->setAlignment(Qt::AlignRight);
1040 
1041     valueSlider = new QSlider(Qt::Horizontal,this);
1042     valueSlider->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
1043     fieldDesc = new QLabel(rp->pd->fieldDesc,this);
1044     valueSlider->setMinimum(0);
1045     valueSlider->setMaximum(100);
1046     valueSlider->setValue(floatToInt(rp->val->getFloat()));
1047     const DynamicFloatDecoration* dfd = reinterpret_cast<const DynamicFloatDecoration*>(&(rp->pd));
1048     QFontMetrics fm(valueLE->font());
1049     QSize sz = fm.size(Qt::TextSingleLine,QString::number(0));
1050     valueLE->setValidator(new QDoubleValidator (dfd->min,dfd->max, numbdecimaldigit, valueLE));
1051     valueLE->setText(QString::number(rp->val->getFloat()));
1052     valueLE->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
1053 
1054     //int row = gridLay->rowCount() - 1;
1055     //lay->addWidget(fieldDesc,row,0);
1056 
1057     hlay = new QHBoxLayout();
1058     hlay->addWidget(valueLE);
1059     hlay->addWidget(valueSlider);
1060     int maxlenghtplusdot = 8;//numbmaxvaluedigit + numbdecimaldigit + 1;
1061     valueLE->setMaxLength(maxlenghtplusdot);
1062     valueLE->setMaximumWidth(sz.width() * maxlenghtplusdot);
1063 
1064 
1065     //gridLay->addLayout(hlay,row,1);
1066 
1067     connect(valueLE,SIGNAL(textChanged(const QString &)),this,SLOT(setValue()));
1068     connect(valueSlider,SIGNAL(valueChanged(int)),this,SLOT(setValue(int)));
1069     connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
1070 
1071 }
1072 
~DynamicFloatWidget()1073 DynamicFloatWidget::~DynamicFloatWidget()
1074 {
1075 }
1076 
getValue()1077 float DynamicFloatWidget::getValue()
1078 {
1079     return float(valueLE->text().toDouble());
1080 }
1081 
setValue(float newVal)1082 void DynamicFloatWidget::setValue(float  newVal)
1083 {
1084     if( QString::number(intToFloat(newVal)) != valueLE->text())
1085         valueLE->setText(QString::number(intToFloat(newVal)));
1086 }
1087 
setValue(int newVal)1088 void DynamicFloatWidget::setValue(int  newVal)
1089 {
1090     if(floatToInt(float(valueLE->text().toDouble())) != newVal)
1091     {
1092         valueLE->setText(QString::number(intToFloat(newVal)));
1093     }
1094 }
1095 
setValue()1096 void DynamicFloatWidget::setValue()
1097 {
1098     float newValLE=float(valueLE->text().toDouble());
1099     valueSlider->setValue(floatToInt(newValLE));
1100     emit dialogParamChanged();
1101 }
1102 
intToFloat(int val)1103 float DynamicFloatWidget::intToFloat(int val)
1104 {
1105     return minVal+float(val)/100.0f*(maxVal-minVal);
1106 }
floatToInt(float val)1107 int DynamicFloatWidget::floatToInt(float val)
1108 {
1109     return int (100.0f*(val-minVal)/(maxVal-minVal));
1110 }
1111 
collectWidgetValue()1112 void DynamicFloatWidget::collectWidgetValue()
1113 {
1114     rp->val->set(DynamicFloatValue(valueLE->text().toFloat()));
1115 }
1116 
resetWidgetValue()1117 void DynamicFloatWidget::resetWidgetValue()
1118 {
1119     valueLE->setText(QString::number(rp->pd->defVal->getFloat()));
1120 }
1121 
setWidgetValue(const Value & nv)1122 void DynamicFloatWidget::setWidgetValue( const Value& nv )
1123 {
1124     valueLE->setText(QString::number(nv.getFloat()));
1125 }
1126 
addWidgetToGridLayout(QGridLayout * lay,const int r)1127 void DynamicFloatWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
1128 {
1129     if (lay != NULL)
1130     {
1131         lay->addWidget(fieldDesc,r,0);
1132         lay->addLayout(hlay,r,1);
1133     }
1134     MeshLabWidget::addWidgetToGridLayout(lay,r);
1135 }
1136 /****************************/
getWidgetValue()1137 Value& MeshLabWidget::getWidgetValue()
1138 {
1139     collectWidgetValue();
1140     return *(rp->val);
1141 }
1142 
1143 
resetValue()1144 void MeshLabWidget::resetValue()
1145 {
1146     rp->val->set(*rp->pd->defVal);
1147     resetWidgetValue();
1148 }
1149 
MeshLabWidget(QWidget * p,RichParameter * rpar)1150 MeshLabWidget::MeshLabWidget( QWidget* p,RichParameter* rpar )
1151     :QWidget(p),rp(rpar) // this version of the line caused the very strange error of uncheckabe first bool widget
1152     //:rp(rpar)
1153 {
1154     //setParent(p);
1155     if (rp!= NULL)
1156     {
1157         helpLab = new QLabel("<small>"+rpar->pd->tooltip +"</small>",this);
1158         helpLab->setTextFormat(Qt::RichText);
1159         helpLab->setWordWrap(true);
1160         helpLab->setVisible(false);
1161         helpLab->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1162         helpLab->setMinimumWidth(250);
1163         helpLab->setMaximumWidth(QWIDGETSIZE_MAX);
1164         /*gridLay = qobject_cast<QGridLayout*>(p->layout());
1165         assert(gridLay != 0);
1166         row = gridLay->rowCount();*/
1167         //gridLay->addWidget(helpLab,row,3,1,1,Qt::AlignTop);
1168     }
1169 }
1170 
InitRichParameter(RichParameter * rpar)1171 void MeshLabWidget::InitRichParameter(RichParameter* rpar)
1172 {
1173     rp = rpar;
1174 }
1175 
~MeshLabWidget()1176 MeshLabWidget::~MeshLabWidget()
1177 {
1178     //delete rp;
1179     delete helpLab;
1180 }
1181 
1182 //void MeshLabWidget::setEqualSpaceForEachColumn()
1183 //{
1184 //	int singlewidth = gridLay->geometry().width() / gridLay->columnCount();
1185 //	for (int ii = 0;ii < gridLay->columnCount();++ii)
1186 //		gridLay->setColumnMinimumWidth(ii,singlewidth);
1187 //}
1188 
addWidgetToGridLayout(QGridLayout * lay,const int r)1189 void MeshLabWidget::addWidgetToGridLayout( QGridLayout* lay, const int r)
1190 {
1191 	if (lay != NULL)
1192 	{
1193 		lay->addWidget(helpLab, r, 2, 1, 1, Qt::AlignLeft);
1194 	}
1195 }
1196 
1197 //connect(qcb,SIGNAL(stateChanged(int)),this,SIGNAL(parameterChanged()));
BoolWidget(QWidget * p,RichBool * rb)1198 BoolWidget::BoolWidget(QWidget* p, RichBool* rb )
1199     :MeshLabWidget(p,rb)
1200 {
1201     cb = new QCheckBox(rp->pd->fieldDesc,this);
1202     cb->setToolTip(rp->pd->tooltip);
1203     cb->setChecked(rp->val->getBool());
1204 
1205     connect(cb,SIGNAL(stateChanged(int)),p,SIGNAL(parameterChanged()));
1206 }
1207 
collectWidgetValue()1208 void BoolWidget::collectWidgetValue()
1209 {
1210     rp->val->set(BoolValue(cb->isChecked()));
1211 }
1212 
resetWidgetValue()1213 void BoolWidget::resetWidgetValue()
1214 {
1215     cb->setChecked(rp->pd->defVal->getBool());
1216 }
1217 
~BoolWidget()1218 BoolWidget::~BoolWidget()
1219 {
1220     //delete lab;
1221     delete cb;
1222 }
1223 
setWidgetValue(const Value & nv)1224 void BoolWidget::setWidgetValue( const Value& nv )
1225 {
1226     cb->setChecked(nv.getBool());
1227 }
1228 
addWidgetToGridLayout(QGridLayout * lay,const int r)1229 void BoolWidget::addWidgetToGridLayout(QGridLayout* lay,const int r)
1230 {
1231     if (lay !=NULL)
1232         lay->addWidget(cb,r,0,1,2);
1233     MeshLabWidget::addWidgetToGridLayout(lay,r);
1234 }
1235 
1236 //connect(qle,SIGNAL(editingFinished()),this,SIGNAL(parameterChanged()));
LineEditWidget(QWidget * p,RichParameter * rpar)1237 LineEditWidget::LineEditWidget( QWidget* p,RichParameter* rpar )
1238     :MeshLabWidget(p,rpar)
1239 {
1240     lab = new QLabel(rp->pd->fieldDesc,this);
1241     lned = new QLineEdit(this);
1242     //int row = gridLay->rowCount() -1;
1243 
1244     lab->setToolTip(rp->pd->tooltip);
1245     //gridLay->addWidget(lab,row,0);
1246     //gridLay->addWidget(lned,row,1);
1247     connect(lned,SIGNAL(editingFinished()),this,SLOT(changeChecker()));
1248     connect(this,SIGNAL(lineEditChanged()),p,SIGNAL(parameterChanged()));
1249     lned->setAlignment(Qt::AlignLeft);
1250 }
1251 
~LineEditWidget()1252 LineEditWidget::~LineEditWidget()
1253 {
1254     delete lned;
1255     delete lab;
1256 }
1257 
changeChecker()1258 void LineEditWidget::changeChecker()
1259 {
1260     if(lned->text() != this->lastVal)
1261     {
1262         this->lastVal = lned->text();
1263         if(!this->lastVal.isEmpty())
1264             emit lineEditChanged();
1265     }
1266 }
1267 
addWidgetToGridLayout(QGridLayout * lay,const int r)1268 void LineEditWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
1269 {
1270     if (lay !=NULL)
1271     {
1272         lay->addWidget(lab,r,0);
1273         lay->addWidget(lned,r,1);
1274     }
1275     MeshLabWidget::addWidgetToGridLayout(lay,r);
1276 }
1277 
IntWidget(QWidget * p,RichInt * rpar)1278 IntWidget::IntWidget( QWidget* p,RichInt* rpar )
1279     :LineEditWidget(p,rpar)
1280 {
1281     lned->setText(QString::number(rp->val->getInt()));
1282 }
1283 
collectWidgetValue()1284 void IntWidget::collectWidgetValue()
1285 {
1286     rp->val->set(IntValue(lned->text().toInt()));
1287 }
1288 
resetWidgetValue()1289 void IntWidget::resetWidgetValue()
1290 {
1291     lned->setText(QString::number(rp->pd->defVal->getInt()));
1292 }
1293 
setWidgetValue(const Value & nv)1294 void IntWidget::setWidgetValue( const Value& nv )
1295 {
1296     lned->setText(QString::number(nv.getInt()));
1297 }
1298 //
FloatWidget(QWidget * p,RichFloat * rpar)1299 FloatWidget::FloatWidget( QWidget* p,RichFloat* rpar )
1300     :LineEditWidget(p,rpar)
1301 {
1302     lned->setText(QString::number(rp->val->getFloat(),'g',3));
1303 }
1304 
collectWidgetValue()1305 void FloatWidget::collectWidgetValue()
1306 {
1307     rp->val->set(FloatValue(lned->text().toFloat()));
1308 }
1309 
resetWidgetValue()1310 void FloatWidget::resetWidgetValue()
1311 {
1312     lned->setText(QString::number(rp->pd->defVal->getFloat(),'g',3));
1313 }
1314 
setWidgetValue(const Value & nv)1315 void FloatWidget::setWidgetValue( const Value& nv )
1316 {
1317     lned->setText(QString::number(nv.getFloat(),'g',3));
1318 }
1319 
StringWidget(QWidget * p,RichString * rpar)1320 StringWidget::StringWidget( QWidget* p,RichString* rpar )
1321     :LineEditWidget(p,rpar)
1322 {
1323     lned->setText(rp->val->getString());
1324 }
1325 
collectWidgetValue()1326 void StringWidget::collectWidgetValue()
1327 {
1328     rp->val->set(StringValue(lned->text()));
1329 }
1330 
resetWidgetValue()1331 void StringWidget::resetWidgetValue()
1332 {
1333     lned->setText(rp->pd->defVal->getString());
1334 }
1335 
setWidgetValue(const Value & nv)1336 void StringWidget::setWidgetValue( const Value& nv )
1337 {
1338     lned->setText(nv.getString());
1339 }
1340 
1341 
1342 /******************************************/
1343 // ColorWidget Implementation
1344 /******************************************/
1345 
1346 
ColorWidget(QWidget * p,RichColor * newColor)1347 ColorWidget::ColorWidget(QWidget *p, RichColor* newColor)
1348     :MeshLabWidget(p,newColor),pickcol()
1349 {
1350     colorLabel = new QLabel(this);
1351     descLabel = new QLabel(rp->pd->fieldDesc,this);
1352     colorButton = new QPushButton(this);
1353     colorButton->setAutoFillBackground(true);
1354     colorButton->setFlat(true);
1355     colorButton->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
1356     //const QColor cl = rp->pd->defVal->getColor();
1357     //resetWidgetValue();
1358     initWidgetValue();
1359     //int row = gridLay->rowCount() - 1;
1360     //gridLay->addWidget(descLabel,row,0,Qt::AlignTop);
1361 
1362     vlay = new QHBoxLayout();
1363     QFontMetrics met(colorLabel->font());
1364     QColor black(Qt::black);
1365     QString blackname = "(" + black.name() + ")";
1366     QSize sz = met.size(Qt::TextSingleLine,blackname);
1367     colorLabel->setMaximumWidth(sz.width());
1368     colorLabel->setMinimumWidth(sz.width());
1369     vlay->addWidget(colorLabel,0,Qt::AlignRight);
1370     vlay->addWidget(colorButton);
1371 
1372 
1373     //gridLay->addLayout(lay,row,1,Qt::AlignTop);
1374     pickcol = rp->val->getColor();
1375     connect(colorButton,SIGNAL(clicked()),this,SLOT(pickColor()));
1376     connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
1377 }
1378 
updateColorInfo(const ColorValue & newColor)1379 void ColorWidget::updateColorInfo(const ColorValue& newColor)
1380 {
1381     QColor col = newColor.getColor();
1382     colorLabel->setText("("+col.name()+")");
1383     QPalette palette(col);
1384     colorButton->setPalette(palette);
1385 }
1386 
pickColor()1387 void ColorWidget::pickColor()
1388 {
1389     pickcol =QColorDialog::getColor(pickcol,this->parentWidget(),"Pick a Color",QColorDialog::DontUseNativeDialog|QColorDialog::ShowAlphaChannel);
1390     if(pickcol.isValid())
1391     {
1392         collectWidgetValue();
1393         updateColorInfo(ColorValue(pickcol));
1394     }
1395     emit dialogParamChanged();
1396 }
1397 
initWidgetValue()1398 void ColorWidget::initWidgetValue()
1399 {
1400     QColor cl = rp->val->getColor();
1401     pickcol = cl;
1402     updateColorInfo(cl);
1403 }
1404 
resetWidgetValue()1405 void ColorWidget::resetWidgetValue()
1406 {
1407     QColor cl = rp->pd->defVal->getColor();
1408     pickcol = cl;
1409     updateColorInfo(cl);
1410 }
1411 
collectWidgetValue()1412 void ColorWidget::collectWidgetValue()
1413 {
1414     rp->val->set(ColorValue(pickcol));
1415 }
1416 
~ColorWidget()1417 ColorWidget::~ColorWidget()
1418 {
1419     delete colorButton;
1420     delete colorLabel;
1421     delete descLabel;
1422 }
1423 
setWidgetValue(const Value & nv)1424 void ColorWidget::setWidgetValue( const Value& nv )
1425 {
1426     QColor cl = nv.getColor();
1427     pickcol = cl;
1428     updateColorInfo(cl);
1429 }
1430 
addWidgetToGridLayout(QGridLayout * lay,const int r)1431 void ColorWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
1432 {
1433     if (lay != NULL)
1434     {
1435         lay->addWidget(descLabel,r,0);
1436         lay->addLayout(vlay,r,1);
1437     }
1438     MeshLabWidget::addWidgetToGridLayout(lay,r);
1439 }
1440 /*
1441 void GetFileNameWidget::launchGetFileNameDialog()
1442 {
1443 
1444 }*/
1445 
visit(RichBool & pd)1446 void RichParameterToQTableWidgetItemConstructor::visit( RichBool& pd )
1447 {
1448     if (pd.val->getBool())
1449         lastCreated = new QTableWidgetItem("true"/*,lst*/);
1450     else
1451         lastCreated = new QTableWidgetItem("false"/*,lst*/);
1452 
1453 }
1454 
visit(RichInt & pd)1455 void RichParameterToQTableWidgetItemConstructor::visit( RichInt& pd )
1456 {
1457     lastCreated = new QTableWidgetItem(QString::number(pd.val->getInt())/*,lst*/);
1458 }
1459 
visit(RichFloat & pd)1460 void RichParameterToQTableWidgetItemConstructor::visit( RichFloat& pd )
1461 {
1462     lastCreated = new QTableWidgetItem(QString::number(pd.val->getFloat())/*,lst*/);
1463 }
1464 
visit(RichString & pd)1465 void RichParameterToQTableWidgetItemConstructor::visit( RichString& pd )
1466 {
1467     lastCreated = new QTableWidgetItem(pd.val->getString()/*,lst*/);
1468 }
1469 
visit(RichPoint3f & pd)1470 void RichParameterToQTableWidgetItemConstructor::visit( RichPoint3f& pd )
1471 {
1472     vcg::Point3f pp = pd.val->getPoint3f();
1473     QString pst = "P3(" + QString::number(pp.X()) + "," + QString::number(pp.Y()) + "," + QString::number(pp.Z()) + ")";
1474     lastCreated = new QTableWidgetItem(pst/*,lst*/);
1475 }
1476 
visit(RichShotf &)1477 void RichParameterToQTableWidgetItemConstructor::visit( RichShotf& /*pd*/ )
1478 {
1479     assert(0); ///
1480     lastCreated = new QTableWidgetItem(QString("TODO")/*,lst*/);
1481 }
1482 
visit(RichOpenFile & pd)1483 void RichParameterToQTableWidgetItemConstructor::visit(RichOpenFile& pd)
1484 {
1485     lastCreated = new QTableWidgetItem(pd.val->getFileName()/*,lst*/);
1486 }
1487 
visit(RichColor & pd)1488 void RichParameterToQTableWidgetItemConstructor::visit( RichColor& pd )
1489 {
1490     QPixmap pix(10,10);
1491     pix.fill(pd.val->getColor());
1492     QIcon ic(pix);
1493     lastCreated = new QTableWidgetItem(ic,""/*,lst*/);
1494 }
1495 
visit(RichAbsPerc & pd)1496 void RichParameterToQTableWidgetItemConstructor::visit( RichAbsPerc& pd )
1497 {
1498     lastCreated = new QTableWidgetItem(QString::number(pd.val->getAbsPerc())/*,lst*/);
1499 }
1500 
visit(RichEnum & pd)1501 void RichParameterToQTableWidgetItemConstructor::visit( RichEnum& pd )
1502 {
1503     lastCreated = new QTableWidgetItem(QString::number(pd.val->getEnum())/*,lst*/);
1504 }
1505 
visit(RichDynamicFloat & pd)1506 void RichParameterToQTableWidgetItemConstructor::visit( RichDynamicFloat& pd )
1507 {
1508     lastCreated = new QTableWidgetItem(QString::number(pd.val->getDynamicFloat())/*,lst*/);
1509 }
1510 
IOFileWidget(QWidget * p,RichParameter * rpar)1511 IOFileWidget::IOFileWidget( QWidget* p,RichParameter* rpar )
1512     :MeshLabWidget(p,rpar),fl()
1513 {
1514 	if (rpar != NULL)
1515 		fl = rpar->val->getFileName();
1516 	filename = new QLineEdit(this);
1517     filename->setText(tr(""));
1518     browse = new QPushButton(this);
1519     descLab = new QLabel(rp->pd->fieldDesc,this);
1520     browse->setText("...");
1521     //const QColor cl = rp->pd->defVal->getColor();
1522     //resetWidgetValue();
1523     //int row = gridLay->rowCount() - 1;
1524     //gridLay->addWidget(descLab,row,0,Qt::AlignTop);
1525     hlay = new QHBoxLayout();
1526     hlay->addWidget(filename,2);
1527     hlay->addWidget(browse);
1528 
1529     connect(browse,SIGNAL(clicked()),this,SLOT(selectFile()));
1530     connect(this,SIGNAL(dialogParamChanged()),p,SIGNAL(parameterChanged()));
1531 }
1532 
~IOFileWidget()1533 IOFileWidget::~IOFileWidget()
1534 {
1535     delete filename;
1536     delete browse;
1537     delete descLab;
1538 }
1539 
collectWidgetValue()1540 void IOFileWidget::collectWidgetValue()
1541 {
1542     rp->val->set(FileValue(fl));
1543 }
1544 
resetWidgetValue()1545 void IOFileWidget::resetWidgetValue()
1546 {
1547     QString fle = rp->pd->defVal->getFileName();
1548     fl = fle;
1549     updateFileName(fle);
1550 }
1551 
1552 
setWidgetValue(const Value & nv)1553 void IOFileWidget::setWidgetValue(const Value& nv)
1554 {
1555     QString fle = nv.getFileName();
1556     fl = fle;
1557     updateFileName(QString());
1558 }
1559 
updateFileName(const FileValue & file)1560 void IOFileWidget::updateFileName( const FileValue& file )
1561 {
1562     filename->setText(file.getFileName());
1563 }
1564 
addWidgetToGridLayout(QGridLayout * lay,const int r)1565 void IOFileWidget::addWidgetToGridLayout( QGridLayout* lay,const int r )
1566 {
1567     if (lay != NULL)
1568     {
1569         lay->addWidget(descLab,r,0,Qt::AlignTop);
1570         lay->addLayout(hlay,r,1,Qt::AlignTop);
1571     }
1572     MeshLabWidget::addWidgetToGridLayout(lay,r);
1573 }
1574 
OpenFileWidget(QWidget * p,RichOpenFile * rdf)1575 OpenFileWidget::OpenFileWidget( QWidget *p, RichOpenFile* rdf )
1576     :IOFileWidget(p,rdf)
1577 {
1578 }
1579 
selectFile()1580 void OpenFileWidget::selectFile()
1581 {
1582     OpenFileDecoration* dec = reinterpret_cast<OpenFileDecoration*>(rp->pd);
1583     QString ext;
1584     fl = QFileDialog::getOpenFileName(this,tr("Open"),dec->defVal->getFileName(),dec->exts.join(" "));
1585     collectWidgetValue();
1586     updateFileName(fl);
1587 	FileValue fileName(fl);
1588 	rp->pd->defVal->set(fileName);
1589     emit dialogParamChanged();
1590 }
1591 
1592 
~OpenFileWidget()1593 OpenFileWidget::~OpenFileWidget()
1594 {
1595 }
1596 
1597 
SaveFileWidget(QWidget * p,RichSaveFile * rpar)1598 SaveFileWidget::SaveFileWidget( QWidget* p,RichSaveFile* rpar )
1599     :IOFileWidget(p,rpar)
1600 {
1601     filename->setText(rpar->val->getFileName());
1602 	QString tmp = rp->val->getFileName();
1603 }
1604 
~SaveFileWidget()1605 SaveFileWidget::~SaveFileWidget()
1606 {
1607 }
1608 
selectFile()1609 void SaveFileWidget::selectFile()
1610 {
1611     SaveFileDecoration* dec = reinterpret_cast<SaveFileDecoration*>(rp->pd);
1612     QString ext;
1613     fl = QFileDialog::getSaveFileName(this,tr("Save"),dec->defVal->getFileName(),dec->ext);
1614     collectWidgetValue();
1615     updateFileName(fl);
1616 	FileValue fileName(fl);
1617 	rp->pd->defVal->set(fileName);
1618     emit dialogParamChanged();
1619 }
1620