25 #include <dtkGuiSupport/dtkColorButton.h>
26 #include <dtkGuiSupport/dtkSplitter.h>
30 class axlInspectorObjectSpherePrivate
35 QDoubleSpinBox *coordinate_x;
36 QDoubleSpinBox *coordinate_y;
37 QDoubleSpinBox *coordinate_z;
38 QDoubleSpinBox *radius;
44 dtkColorButton *colorButton;
45 QComboBox *comboBoxShader;
48 QCheckBox *checkBoxShader;
49 QLineEdit *lineEditShader;
50 QPushButton *buttonShader;
52 QSlider *sliderOpacity;
57 d->coordinate_x = NULL;
58 d->coordinate_y = NULL;
59 d->coordinate_z = NULL;
65 d->colorButton = NULL;
66 d->comboBoxShader = NULL;
68 d->checkBoxShader = NULL;
69 d->lineEditShader = NULL;
70 d->buttonShader = NULL;
72 d->sliderOpacity = NULL;
84 return QSize(300, 300);
92 connect(d->sphere, SIGNAL(modifiedGeometry(
void)),
this, SLOT(
updateValues(
void)));
97 void axlInspectorObjectSphere::initWidget()
99 QVBoxLayout *layoutTop =
new QVBoxLayout(
this);
100 layoutTop->addWidget(
new QLabel(
"axlInspectorObjectSphere",
this));
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);
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);
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);
119 d->radius =
new QDoubleSpinBox(
this);
120 d->radius->setValue(d->sphere->radius());
121 d->radius->setSingleStep(0.1);
124 QHBoxLayout *layoutCoordinate_x =
new QHBoxLayout;
125 layoutCoordinate_x->addWidget(
new QLabel(
"X",
this));
126 layoutCoordinate_x->addWidget(d->coordinate_x);
128 QHBoxLayout *layoutCoordinate_y =
new QHBoxLayout;
129 layoutCoordinate_y->addWidget(
new QLabel(
"Y",
this));
130 layoutCoordinate_y->addWidget(d->coordinate_y);
132 QHBoxLayout *layoutCoordinate_z =
new QHBoxLayout;
133 layoutCoordinate_z->addWidget(
new QLabel(
"Z",
this));
134 layoutCoordinate_z->addWidget(d->coordinate_z);
136 QHBoxLayout *layoutRadius =
new QHBoxLayout;
137 layoutRadius->addWidget(
new QLabel(
"Radius",
this));
138 layoutRadius->addWidget(d->radius);
139 d->radius->setValue(d->sphere->radius());
153 d->colorButton =
new dtkColorButton(
this);
155 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
156 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
157 layoutColorButton->addWidget(d->colorButton);
158 d->colorButton->setColor(this->initColorValue());
162 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
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());
171 d->comboBoxShader =
new QComboBox(
this);
172 d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
174 d->checkBoxShader =
new QCheckBox(
this);
175 d->lineEditShader =
new QLineEdit(
this);
176 d->buttonShader =
new QPushButton(
this);
177 d->buttonShader->setText(
"open");
179 d->lineEditShader->setText(this->initShaderValue());
180 this->initComboBoxShaderValue();
182 if(d->lineEditShader->text().isEmpty())
184 d->lineEditShader->setEnabled(
false);
185 d->buttonShader->setEnabled(
false);
186 d->comboBoxShader->setEnabled(
false);
189 d->checkBoxShader->setChecked(
true);
193 QVBoxLayout *layoutShader =
new QVBoxLayout;
194 QHBoxLayout *layoutShader1 =
new QHBoxLayout;
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);
202 layoutShader1->setStretchFactor(labelShader, 2);
203 layoutShader1->setStretchFactor(d->checkBoxShader, 1);
204 layoutShader1->setStretchFactor(d->comboBoxShader, 4);
205 layoutShader1->setStretchFactor(d->buttonShader, 3);
207 layoutShader->addLayout(layoutShader1);
208 layoutShader->addWidget(d->lineEditShader);
210 layoutTop->addLayout(layoutCoordinate_x);
211 layoutTop->addLayout(layoutCoordinate_y);
212 layoutTop->addLayout(layoutCoordinate_z);
213 layoutTop->addLayout(layoutRadius);
217 layoutTop->addLayout(layoutColorButton);
218 layoutTop->addLayout(layoutOpacity);
219 layoutTop->addLayout(layoutShader);
221 QWidget *top =
new QWidget(
this);
222 top->setMaximumWidth(295);
224 top->setLayout(layoutTop);
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)));
246 connect(d->sliderOpacity, SIGNAL(valueChanged(
int)),
this, SLOT(
onOpacityChanged(
int)));
247 connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)),
this, SLOT(
onLineEditShaderChanged(QString)));
249 connect(d->buttonShader, SIGNAL(clicked()),
this, SLOT(
openShader()));
250 connect(d->lineEditShader, SIGNAL(textChanged(QString)),
this, SLOT(
onShaderChanged(QString)));
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);
267 void axlInspectorObjectSphere::initComboBoxShaderValue(
void)
269 if(d->comboBoxShader)
272 QDir dirShader(
":axlShader/shader/");
273 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
275 QFileInfoList list = dirShader.entryInfoList();
280 QSettings settings(
"inria",
"dtk");
282 settings.beginGroup(
"shader");
283 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
284 defaultPathShader.append(
"/");
286 QDir defaultDirShader(defaultPathShader);
289 defaultDirShader.setNameFilters(filters);
290 QFileInfoList list2 = defaultDirShader.entryInfoList();
296 for (
int i = 0; i < list.size(); ++i) {
297 if(!items.contains(list.at(i).fileName()))
298 items << list.at(i).fileName();
302 int indInitShader = -1;
303 int indCurrentShader = -1;
306 foreach(QString item, items)
309 d->comboBoxShader->addItem(item);
311 QFileInfo currentFileInfo(d->lineEditShader->text());
313 if(currentFileInfo.exists())
315 if(item == currentFileInfo.fileName())
316 indInitShader =indCurrentShader;
321 if(indInitShader != -1)
322 d->comboBoxShader->setCurrentIndex(indInitShader);
330 QDir dirShader(
":axlShader/shader/");
331 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
333 QFileInfo currentFile(dirShader, shader);
334 if(!currentFile.exists())
336 QSettings settings(
"inria",
"dtk");
338 settings.beginGroup(
"shader");
339 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
340 defaultPathShader.append(
"/");
342 QDir defaultDirShader(defaultPathShader);
343 currentFile = QFileInfo(defaultDirShader, shader);
347 d->lineEditShader->setText(currentFile.absoluteFilePath());
350 QString axlInspectorObjectSphere::initShaderValue(
void)
352 return d->sphere->shader();
356 QColor axlInspectorObjectSphere::initColorValue(
void)
358 return d->sphere->color();
362 int axlInspectorObjectSphere::initOpacityValue(
void)
364 double initOpacity = 0.0;
365 double opacity = d->sphere->opacity();
366 if(opacity > initOpacity)
367 initOpacity = opacity;
369 return 100 * (1.0 - initOpacity);
374 if(d->lineEditShader->isEnabled())
377 fileToOpen = QFileDialog::getOpenFileName(
this, tr(
"Open shader"),
"", tr(
"xml document (*.xml)"));
378 d->lineEditShader->setText(fileToOpen);
384 d->sphere->setShader(shader);
390 d->sphere->touchProperty();
397 d->comboBoxShader->setEnabled(
true);
398 d->lineEditShader->setEnabled(
true);
399 d->buttonShader->setEnabled(
true);
406 d->comboBoxShader->setEnabled(
false);
407 d->lineEditShader->setEnabled(
false);
408 d->buttonShader->setEnabled(
false);
410 d->sphere->setShader(
"");
415 d->sphere->touchProperty();
420 d->sphere->onXChanged(x);
423 d->sphere->touchGeometry();
429 d->sphere->onYChanged(y);
432 d->sphere->touchGeometry();
438 d->sphere->onZChanged(z);
441 d->sphere->touchGeometry();
447 d->sphere->setRadius(radius);
450 d->sphere->touchGeometry();
456 QVariant variant = d->sphere->QObject::property(
"color");
457 if(variant.isValid())
459 d->sphere->setColor(color);
463 d->sphere->touchProperty();
472 double opacity_d = 1.0 - 0.01 * opacity;
474 QVariant variant = d->sphere->QObject::property(
"opacity");
475 if(variant.isValid())
477 d->sphere->setOpacity(opacity_d);
481 d->sphere->touchProperty();
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);
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());
void onShaderChanged(QString)
void onColorChanged(QColor color)
QSize sizeHint(void) const
void onCoordDataChanged_y(double y)
void onCoordDataChanged_z(double z)
void setData(axlSphere *point)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
axlInspectorObjectSphere(QWidget *parent=0)
void onRecievedDataChanged(void)
void onShaderStateChanged(bool isShader)
~axlInspectorObjectSphere(void)
void onLineEditShaderChanged(QString)
Class axlSphere defines 3D spheres.
void onOpacityChanged(int opacity)
void onCoordDataChanged_x(double x)
void onRadiusChanged(double radius)
void colorChanged(QColor color, dtkAbstractData *data)