Developer documentation | Axl-2.5.1

axlInspectorObjectSphere.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectSphere.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Mar 18 11:19:52 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Apr 3 14:20:40 2012 (+0200)
8  * By: Julien Wintz
9  * Update #: 60
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
22 #include <axlCore/axlSphere.h>
24 
25 #include <dtkGuiSupport/dtkColorButton.h>
26 #include <dtkGuiSupport/dtkSplitter.h>
27 
28 #include <QtGui>
29 
30 class axlInspectorObjectSpherePrivate
31 {
32 public:
33  axlSphere *sphere;
34 
35  QDoubleSpinBox *coordinate_x;
36  QDoubleSpinBox *coordinate_y;
37  QDoubleSpinBox *coordinate_z;
38  QDoubleSpinBox *radius;
39 
40 
41  //QSlider *sliderSize;
42 
43 
44  dtkColorButton *colorButton;
45  QComboBox *comboBoxShader;
46 
47 
48  QCheckBox *checkBoxShader;
49  QLineEdit *lineEditShader;
50  QPushButton *buttonShader;
51 
52  QSlider *sliderOpacity;
53 };
54 
55 axlInspectorObjectSphere::axlInspectorObjectSphere(QWidget *parent) : QFrame(parent), d(new axlInspectorObjectSpherePrivate)
56 {
57  d->coordinate_x = NULL;
58  d->coordinate_y = NULL;
59  d->coordinate_z = NULL;
60  d->radius = NULL;
61 
62 
63  //d->sliderSize = NULL;
64 
65  d->colorButton = NULL;
66  d->comboBoxShader = NULL;
67 
68  d->checkBoxShader = NULL;
69  d->lineEditShader = NULL;
70  d->buttonShader = NULL;
71 
72  d->sliderOpacity = NULL;
73 }
74 
76 {
77  delete d;
78 
79  d = NULL;
80 }
81 
83 {
84  return QSize(300, 300);
85 }
86 
88 {
89  d->sphere = sphere;
90 
91  // connect the modification of the geometry with the widget
92  connect(d->sphere, SIGNAL(modifiedGeometry(void)), this, SLOT( updateValues(void)));
93 
94  initWidget();
95 }
96 
97 void axlInspectorObjectSphere::initWidget()
98 {
99  QVBoxLayout *layoutTop = new QVBoxLayout(this);
100  layoutTop->addWidget(new QLabel("axlInspectorObjectSphere", this));
101 
103 
104  d->coordinate_x = new QDoubleSpinBox(this);
105  d->coordinate_x->setRange(-1000, 1000);
106  d->coordinate_x->setValue(d->sphere->x());
107  d->coordinate_x->setSingleStep(0.1);
108 
109  d->coordinate_y = new QDoubleSpinBox(this);
110  d->coordinate_y->setRange(-1000, 1000);
111  d->coordinate_y->setValue(d->sphere->y());
112  d->coordinate_y->setSingleStep(0.1);
113 
114  d->coordinate_z = new QDoubleSpinBox(this);
115  d->coordinate_z->setRange(-1000, 1000);
116  d->coordinate_z->setValue(d->sphere->z());
117  d->coordinate_z->setSingleStep(0.1);
118 
119  d->radius = new QDoubleSpinBox(this);
120  d->radius->setValue(d->sphere->radius());
121  d->radius->setSingleStep(0.1);
122 
123 
124  QHBoxLayout *layoutCoordinate_x = new QHBoxLayout;
125  layoutCoordinate_x->addWidget(new QLabel("X",this));
126  layoutCoordinate_x->addWidget(d->coordinate_x);
127 
128  QHBoxLayout *layoutCoordinate_y = new QHBoxLayout;
129  layoutCoordinate_y->addWidget(new QLabel("Y",this));
130  layoutCoordinate_y->addWidget(d->coordinate_y);
131 
132  QHBoxLayout *layoutCoordinate_z = new QHBoxLayout;
133  layoutCoordinate_z->addWidget(new QLabel("Z",this));
134  layoutCoordinate_z->addWidget(d->coordinate_z);
135 
136  QHBoxLayout *layoutRadius = new QHBoxLayout;
137  layoutRadius->addWidget(new QLabel("Radius",this));
138  layoutRadius->addWidget(d->radius);
139  d->radius->setValue(d->sphere->radius());
140 
141  // ///////SIZE///////////////
142 
143  // d->sliderSize = new QSlider(Qt::Horizontal, this);
144 
145  // QHBoxLayout *layoutSize = new QHBoxLayout;
146  // layoutSize->addWidget(new QLabel("Size",this));
147  // layoutSize->addWidget(d->sliderSize);
148  // d->sliderSize->setMaximum(1000);
149  // d->sliderSize->setValue(initSizeValue());
150 
152 
153  d->colorButton = new dtkColorButton(this);
154 
155  QHBoxLayout *layoutColorButton = new QHBoxLayout;
156  layoutColorButton->addWidget(new QLabel("Color",this));
157  layoutColorButton->addWidget(d->colorButton);
158  d->colorButton->setColor(this->initColorValue());
159 
161 
162  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
163 
164  QHBoxLayout *layoutOpacity = new QHBoxLayout;
165  layoutOpacity->addWidget(new QLabel("Opacity",this));
166  layoutOpacity->addWidget(d->sliderOpacity);
167  d->sliderOpacity->setMaximum(100);
168  d->sliderOpacity->setValue(initOpacityValue());
169 
171  d->comboBoxShader = new QComboBox(this);
172  d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
173 
174  d->checkBoxShader = new QCheckBox(this);
175  d->lineEditShader = new QLineEdit(this);
176  d->buttonShader = new QPushButton(this);
177  d->buttonShader->setText("open");
178 
179  d->lineEditShader->setText(this->initShaderValue());
180  this->initComboBoxShaderValue();
181 
182  if(d->lineEditShader->text().isEmpty())
183  {
184  d->lineEditShader->setEnabled(false);
185  d->buttonShader->setEnabled(false);
186  d->comboBoxShader->setEnabled(false);
187  }
188  else
189  d->checkBoxShader->setChecked(true);
190 
192 
193  QVBoxLayout *layoutShader = new QVBoxLayout;
194  QHBoxLayout *layoutShader1 = new QHBoxLayout;
195 
196  QLabel *labelShader = new QLabel("Shader",this);
197  layoutShader1->addWidget(labelShader);
198  layoutShader1->addWidget(d->checkBoxShader);
199  layoutShader1->addWidget(d->comboBoxShader);
200  layoutShader1->addWidget(d->buttonShader);
201 
202  layoutShader1->setStretchFactor(labelShader, 2);
203  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
204  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
205  layoutShader1->setStretchFactor(d->buttonShader, 3);
206 
207  layoutShader->addLayout(layoutShader1);
208  layoutShader->addWidget(d->lineEditShader);
209 
210  layoutTop->addLayout(layoutCoordinate_x);
211  layoutTop->addLayout(layoutCoordinate_y);
212  layoutTop->addLayout(layoutCoordinate_z);
213  layoutTop->addLayout(layoutRadius);
214 
215  // layoutTop->addLayout(layoutSize);
216 
217  layoutTop->addLayout(layoutColorButton);
218  layoutTop->addLayout(layoutOpacity);
219  layoutTop->addLayout(layoutShader);
220 
221  QWidget *top = new QWidget(this);
222  top->setMaximumWidth(295);
223 
224  top->setLayout(layoutTop);
225 
226  // dtkSplitter *splitter = new dtkSplitter(this, true);
227  // splitter->setOrientation(Qt::Vertical);
228  // splitter->addWidget(top);
229 
230  //QVBoxLayout *layout = new QVBoxLayout(this);
231  //layout->setContentsMargins(0, 0, 0, 0);
232  //layout->setSpacing(0);
233  //layout->addWidget(splitter);
234 
235 
236  connect(d->coordinate_x, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChanged_x(double)));
237  connect(d->coordinate_y, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChanged_y(double)));
238  connect(d->coordinate_z, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChanged_z(double)));
239  connect(d->radius, SIGNAL(valueChanged(double)), this, SLOT(onRadiusChanged(double)));
240 
241  // connect(d->sliderSize, SIGNAL(valueChanged(int)), this, SLOT(onSizeChanged(int)));
242 
243 
244  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
245 
246  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
247  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
248  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
249  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
250  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
251 
252  //connect(d->sphere, SIGNAL(dataChanged(void)), this, SLOT(onRecievedDataChanged(void)));
253 }
254 
256 {
257  //We need to block signal to don't have a boucle with connection
258  this->blockSignals(true);
259  d->coordinate_x->setValue(d->sphere->x());
260  d->coordinate_y->setValue(d->sphere->y());
261  d->coordinate_z->setValue(d->sphere->z());
262  d->radius->setValue(d->sphere->radius());
263  this->blockSignals(false);
264 
265 }
266 
267 void axlInspectorObjectSphere::initComboBoxShaderValue(void)
268 {
269  if(d->comboBoxShader)
270  {
271  // First add item of axlShader.qrc, then find shader from shader path
272  QDir dirShader( ":axlShader/shader/");
273  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
274 
275  QFileInfoList list = dirShader.entryInfoList();
276  // for (int i = 0; i < list.size(); ++i) {
277  // d->comboBoxShader->addItem(list.at(i).fileName());
278  // }
279 
280  QSettings settings("inria", "dtk");
281  QString defaultPath;
282  settings.beginGroup("shader");
283  QString defaultPathShader = settings.value("path", defaultPath).toString();
284  defaultPathShader.append("/");
285 
286  QDir defaultDirShader(defaultPathShader);
287  QStringList filters;
288  filters << "*.xml";
289  defaultDirShader.setNameFilters(filters);
290  QFileInfoList list2 = defaultDirShader.entryInfoList();
291 
292  list.append(list2);
293 
294  QStringList items;
295 
296  for (int i = 0; i < list.size(); ++i) {
297  if(!items.contains(list.at(i).fileName()))
298  items << list.at(i).fileName();
299  }
300 
301  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
302  int indInitShader = -1;
303  int indCurrentShader = -1;
304 
305 
306  foreach(QString item, items)
307  {
308  indCurrentShader++;
309  d->comboBoxShader->addItem(item);
310 
311  QFileInfo currentFileInfo(d->lineEditShader->text());
312 
313  if(currentFileInfo.exists())
314  {
315  if(item == currentFileInfo.fileName())
316  indInitShader =indCurrentShader;
317  }
318  }
319 
320  //init the value from the lineEditShader.
321  if(indInitShader != -1)
322  d->comboBoxShader->setCurrentIndex(indInitShader);
323 
324  }
325 }
326 
328 {
329  // First add item of axlShader.qrc, then find shader from shader path
330  QDir dirShader( ":axlShader/shader/");
331  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
332 
333  QFileInfo currentFile(dirShader, shader);
334  if(!currentFile.exists())
335  {
336  QSettings settings("inria", "dtk");
337  QString defaultPath;
338  settings.beginGroup("shader");
339  QString defaultPathShader = settings.value("path", defaultPath).toString();
340  defaultPathShader.append("/");
341 
342  QDir defaultDirShader(defaultPathShader);
343  currentFile = QFileInfo(defaultDirShader, shader);
344 
345  }
346 
347  d->lineEditShader->setText(currentFile.absoluteFilePath());
348 }
349 
350 QString axlInspectorObjectSphere::initShaderValue(void)
351 {
352  return d->sphere->shader();
353 }
354 
355 
356 QColor axlInspectorObjectSphere::initColorValue(void)
357 {
358  return d->sphere->color();
359 }
360 
361 
362 int axlInspectorObjectSphere::initOpacityValue(void)
363 {
364  double initOpacity = 0.0;
365  double opacity = d->sphere->opacity();
366  if(opacity > initOpacity)
367  initOpacity = opacity;
368 
369  return 100 * (1.0 - initOpacity);
370 }
371 
373 {
374  if(d->lineEditShader->isEnabled())
375  {
376  QString fileToOpen;
377  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("xml document (*.xml)"));
378  d->lineEditShader->setText(fileToOpen);
379  }
380 }
381 
383 {
384  d->sphere->setShader(shader);
385 
386  //emit dataChangedByShader(d->sphere, d->lineEditShader->text());
387 // emit modifiedProperty(d->sphere, 2);
388 
389 // emit update();
390  d->sphere->touchProperty();
391 }
392 
394 {
395  if(isShader)
396  {
397  d->comboBoxShader->setEnabled(true);
398  d->lineEditShader->setEnabled(true);
399  d->buttonShader->setEnabled(true);
400  onLineEditShaderChanged(d->comboBoxShader->currentText());
401 
402  //emit dataChangedByShader(d->sphere, d->lineEditShader->text());
403  }
404  else
405  {
406  d->comboBoxShader->setEnabled(false);
407  d->lineEditShader->setEnabled(false);
408  d->buttonShader->setEnabled(false);
409 
410  d->sphere->setShader("");
411  //emit dataChangedByShader(d->sphere, "");
412  }
413 // emit modifiedProperty(d->sphere, 2);
414 // emit update();
415  d->sphere->touchProperty();
416 }
417 
419 {
420  d->sphere->onXChanged(x);
421 
422  //emit dataChangedByGeometry(d->sphere);
423  d->sphere->touchGeometry();
424 // emit update();
425 }
426 
428 {
429  d->sphere->onYChanged(y);
430 
431  //emit dataChangedByGeometry(d->sphere);
432  d->sphere->touchGeometry();
433 // emit update();
434 }
435 
437 {
438  d->sphere->onZChanged(z);
439 
440  //emit dataChangedByGeometry(d->sphere);
441  d->sphere->touchGeometry();
442 // emit update();
443 }
444 
446 {
447  d->sphere->setRadius(radius);
448 
449  //emit dataChangedByGeometry(d->sphere);
450  d->sphere->touchGeometry();
451 // emit update();
452 }
453 
455 {
456  QVariant variant = d->sphere->QObject::property("color");
457  if(variant.isValid())
458  {
459  d->sphere->setColor(color);
460 
461  //emit dataChangedByColor(d->sphere, color.redF(), color.greenF(), color.blueF());
462 // emit modifiedProperty(d->sphere, 0);
463  d->sphere->touchProperty();
464  }
465 
466 // emit update();
467 }
468 
469 
471 {
472  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
473 
474  QVariant variant = d->sphere->QObject::property("opacity");
475  if(variant.isValid())
476  {
477  d->sphere->setOpacity(opacity_d);
478 
479  // emit dataChangedByOpacity(d->sphere, opacity_d);
480 // emit modifiedProperty(d->sphere, 1);
481  d->sphere->touchProperty();
482  }
483 
484 // emit update();
485 }
486 
487 
489 {
490  const QSignalBlocker blockerX(d->coordinate_x);
491  const QSignalBlocker blockerY(d->coordinate_y);
492  const QSignalBlocker blockerZ(d->coordinate_z);
493  const QSignalBlocker blockerRadius(d->radius);
494 
495  d->coordinate_x->setValue(d->sphere->x());
496  d->coordinate_y->setValue(d->sphere->y());
497  d->coordinate_z->setValue(d->sphere->z());
498  d->radius->setValue(d->sphere->radius());
499 }
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
axlInspectorObjectSphere(QWidget *parent=0)
void onShaderStateChanged(bool isShader)
Class axlSphere defines 3D spheres.
Definition: axlSphere.h:33
void colorChanged(QColor color, dtkAbstractData *data)