26 #include <dtkGuiSupport/dtkColorButton.h>
27 #include <dtkGuiSupport/dtkSplitter.h>
31 class axlInspectorObjectTorusPrivate {
35 QDoubleSpinBox* coordinateCenter_x;
36 QDoubleSpinBox* coordinateCenter_y;
37 QDoubleSpinBox* coordinateCenter_z;
39 QDoubleSpinBox* coordinateDirection_x;
40 QDoubleSpinBox* coordinateDirection_y;
41 QDoubleSpinBox* coordinateDirection_z;
43 QDoubleSpinBox* ringRadius;
44 QDoubleSpinBox* crossSectionRadius;
46 dtkColorButton *colorButton;
48 QComboBox *comboBoxShader;
50 QCheckBox* checkBoxShader;
51 QLineEdit* lineEditShader;
52 QPushButton* buttonShader;
54 QSlider* sliderOpacity;
59 d(new axlInspectorObjectTorusPrivate) {
61 d->coordinateCenter_x = NULL;
62 d->coordinateCenter_y = NULL;
63 d->coordinateCenter_z = NULL;
65 d->coordinateDirection_x = NULL;
66 d->coordinateDirection_y = NULL;
67 d->coordinateDirection_z = NULL;
70 d->crossSectionRadius = NULL;
72 d->colorButton = NULL;
74 d->comboBoxShader = NULL;
76 d->checkBoxShader = NULL;
77 d->lineEditShader = NULL;
78 d->buttonShader = NULL;
80 d->sliderOpacity = NULL;
89 return QSize(300, 300);
94 connect(d->torus, SIGNAL(modifiedGeometry(
void)),
this, SLOT(
updateValues(
void)));
98 void axlInspectorObjectTorus::initWidget(
void) {
100 QVBoxLayout *layoutTop =
new QVBoxLayout(
this);
101 layoutTop->addWidget(
new QLabel(
"axlInspectorObjectTorus",
this));
104 d->coordinateCenter_x =
new QDoubleSpinBox(
this);
105 d->coordinateCenter_x->setRange(-1000, 1000);
106 d->coordinateCenter_x->setValue(d->torus->centerPoint()->x());
107 d->coordinateCenter_x->setSingleStep(0.1);
109 QHBoxLayout *layoutCenter_x =
new QHBoxLayout;
110 layoutCenter_x->addWidget(
new QLabel(
"X",
this));
111 layoutCenter_x->addWidget(d->coordinateCenter_x);
113 d->coordinateCenter_y =
new QDoubleSpinBox(
this);
114 d->coordinateCenter_y->setRange(-1000, 1000);
115 d->coordinateCenter_y->setValue(d->torus->centerPoint()->y());
116 d->coordinateCenter_y->setSingleStep(0.1);
118 QHBoxLayout *layoutCenter_y =
new QHBoxLayout;
119 layoutCenter_y->addWidget(
new QLabel(
"Y",
this));
120 layoutCenter_y->addWidget(d->coordinateCenter_y);
122 d->coordinateCenter_z =
new QDoubleSpinBox(
this);
123 d->coordinateCenter_z->setRange(-1000, 1000);
124 d->coordinateCenter_z->setValue(d->torus->centerPoint()->z());
125 d->coordinateCenter_z->setSingleStep(0.1);
127 QHBoxLayout *layoutCenter_z =
new QHBoxLayout;
128 layoutCenter_z->addWidget(
new QLabel(
"Z",
this));
129 layoutCenter_z->addWidget(d->coordinateCenter_z);
132 d->coordinateDirection_x =
new QDoubleSpinBox(
this);
133 d->coordinateDirection_x->setRange(-1000, 1000);
134 d->coordinateDirection_x->setValue(d->torus->direction()->x());
135 d->coordinateDirection_x->setSingleStep(0.1);
137 QHBoxLayout *layoutDirection_x =
new QHBoxLayout;
138 layoutDirection_x->addWidget(
new QLabel(
"X",
this));
139 layoutDirection_x->addWidget(d->coordinateDirection_x);
141 d->coordinateDirection_y =
new QDoubleSpinBox(
this);
142 d->coordinateDirection_y->setRange(-1000, 1000);
143 d->coordinateDirection_y->setValue(d->torus->direction()->y());
144 d->coordinateDirection_y->setSingleStep(0.1);
146 QHBoxLayout *layoutDirection_y =
new QHBoxLayout;
147 layoutDirection_y->addWidget(
new QLabel(
"Y",
this));
148 layoutDirection_y->addWidget(d->coordinateDirection_y);
150 d->coordinateDirection_z =
new QDoubleSpinBox(
this);
151 d->coordinateDirection_z->setRange(-1000, 1000);
152 d->coordinateDirection_z->setValue(d->torus->direction()->z());
153 d->coordinateDirection_z->setSingleStep(0.1);
155 QHBoxLayout *layoutDirection_z =
new QHBoxLayout;
156 layoutDirection_z->addWidget(
new QLabel(
"Z",
this));
157 layoutDirection_z->addWidget(d->coordinateDirection_z);
160 d->ringRadius =
new QDoubleSpinBox(
this);
161 d->ringRadius->setValue(d->torus->ringRadius());
162 d->ringRadius->setSingleStep(0.1);
164 QHBoxLayout *layoutRingRadius =
new QHBoxLayout;
165 layoutRingRadius->addWidget(
new QLabel(
"Ring Radius",
this));
166 layoutRingRadius->addWidget(d->ringRadius);
167 d->ringRadius->setValue(d->torus->ringRadius());
170 d->crossSectionRadius =
new QDoubleSpinBox(
this);
171 d->crossSectionRadius->setValue(d->torus->crossSectionRadius());
172 d->crossSectionRadius->setSingleStep(0.1);
174 QHBoxLayout *layoutCrossSectionRadius =
new QHBoxLayout;
175 layoutCrossSectionRadius->addWidget(
new QLabel(
"Cross Section Radius",
this));
176 layoutCrossSectionRadius->addWidget(d->crossSectionRadius);
177 d->crossSectionRadius->setValue(d->torus->crossSectionRadius());
180 d->colorButton =
new dtkColorButton(
this);
182 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
183 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
184 layoutColorButton->addWidget(d->colorButton);
185 d->colorButton->setColor(this->initColorValue());
188 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
190 QHBoxLayout *layoutOpacity =
new QHBoxLayout;
191 layoutOpacity->addWidget(
new QLabel(
"Opacity",
this));
192 layoutOpacity->addWidget(d->sliderOpacity);
193 d->sliderOpacity->setMaximum(100);
194 d->sliderOpacity->setValue(initOpacityValue());
197 d->comboBoxShader =
new QComboBox(
this);
198 d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
200 d->checkBoxShader =
new QCheckBox(
this);
201 d->lineEditShader =
new QLineEdit(
this);
202 d->buttonShader =
new QPushButton(
this);
203 d->buttonShader->setText(
"open");
205 d->lineEditShader->setText(this->initShaderValue());
206 this->initComboBoxShaderValue();
208 if(d->lineEditShader->text().isEmpty())
210 d->lineEditShader->setEnabled(
false);
211 d->buttonShader->setEnabled(
false);
212 d->comboBoxShader->setEnabled(
false);
215 d->checkBoxShader->setChecked(
true);
218 QVBoxLayout *layoutShader =
new QVBoxLayout;
219 QHBoxLayout *layoutShader1 =
new QHBoxLayout;
221 QLabel *labelShader =
new QLabel(
"Shader",
this);
222 layoutShader1->addWidget(labelShader);
223 layoutShader1->addWidget(d->checkBoxShader);
224 layoutShader1->addWidget(d->comboBoxShader);
225 layoutShader1->addWidget(d->buttonShader);
227 layoutShader1->setStretchFactor(labelShader, 2);
228 layoutShader1->setStretchFactor(d->checkBoxShader, 1);
229 layoutShader1->setStretchFactor(d->comboBoxShader, 4);
230 layoutShader1->setStretchFactor(d->buttonShader, 3);
232 layoutShader->addLayout(layoutShader1);
233 layoutShader->addWidget(d->lineEditShader);
236 layoutTop->addWidget(
new QLabel(
"Center:",
this));
237 layoutTop->addLayout(layoutCenter_x);
238 layoutTop->addLayout(layoutCenter_y);
239 layoutTop->addLayout(layoutCenter_z);
241 layoutTop->addWidget(
new QLabel(
"Second point to create direction:",
this));
242 layoutTop->addLayout(layoutDirection_x);
243 layoutTop->addLayout(layoutDirection_y);
244 layoutTop->addLayout(layoutDirection_z);
246 layoutTop->addLayout(layoutRingRadius);
247 layoutTop->addLayout(layoutCrossSectionRadius);
249 layoutTop->addLayout(layoutColorButton);
250 layoutTop->addLayout(layoutOpacity);
251 layoutTop->addLayout(layoutShader);
253 QWidget *top =
new QWidget(
this);
254 top->setLayout(layoutTop);
255 top->setMaximumWidth(295);
257 dtkSplitter *splitter =
new dtkSplitter(
this,
true);
258 splitter->setOrientation(Qt::Vertical);
259 splitter->addWidget(top);
261 QVBoxLayout *layout =
new QVBoxLayout(
this);
262 layout->setContentsMargins(0, 0, 0, 0);
263 layout->setSpacing(0);
264 layout->addWidget(splitter);
274 connect(d->ringRadius, SIGNAL(valueChanged(
double)),
this, SLOT(
onRingRadiusChanged(
double)));
279 connect(d->sliderOpacity, SIGNAL(valueChanged(
int)),
this, SLOT(
onOpacityChanged(
int)));
280 connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)),
this, SLOT(
onLineEditShaderChanged(QString)));
282 connect(d->buttonShader, SIGNAL(clicked()),
this, SLOT(
openShader()));
283 connect(d->lineEditShader, SIGNAL(textChanged(QString)),
this, SLOT(
onShaderChanged(QString)));
286 QString axlInspectorObjectTorus::initShaderValue(
void) {
287 return d->torus->shader();
290 QColor axlInspectorObjectTorus::initColorValue(
void) {
291 return d->torus->color();
294 int axlInspectorObjectTorus::initOpacityValue(
void) {
295 double initOpacity = 0.0;
296 double opacity = d->torus->opacity();
297 if(opacity > initOpacity)
298 initOpacity = opacity;
300 return 100 * (1.0 - initOpacity);
304 if(d->lineEditShader->isEnabled()) {
306 fileToOpen = QFileDialog::getOpenFileName(
this, tr(
"Open shader"),
"", tr(
"xml document (*.xml)"));
307 d->lineEditShader->setText(fileToOpen);
312 d->torus->setShader(shader);
315 d->torus->touchProperty();
321 d->comboBoxShader->setEnabled(
true);
322 d->lineEditShader->setEnabled(
true);
323 d->buttonShader->setEnabled(
true);
328 d->comboBoxShader->setEnabled(
false);
329 d->lineEditShader->setEnabled(
false);
330 d->buttonShader->setEnabled(
false);
332 d->torus->setShader(
"");
337 d->torus->touchProperty();
341 void axlInspectorObjectTorus::initComboBoxShaderValue(
void) {
342 if(d->comboBoxShader) {
344 QDir dirShader(
":axlShader/shader/");
345 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
347 QFileInfoList list = dirShader.entryInfoList();
352 QSettings settings(
"inria",
"dtk");
354 settings.beginGroup(
"shader");
355 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
356 defaultPathShader.append(
"/");
358 QDir defaultDirShader(defaultPathShader);
361 defaultDirShader.setNameFilters(filters);
362 QFileInfoList list2 = defaultDirShader.entryInfoList();
368 for (
int i = 0; i < list.size(); ++i) {
369 if(!items.contains(list.at(i).fileName()))
370 items << list.at(i).fileName();
374 int indInitShader = -1;
375 int indCurrentShader = -1;
378 foreach(QString item, items) {
380 d->comboBoxShader->addItem(item);
382 QFileInfo currentFileInfo(d->lineEditShader->text());
384 if(currentFileInfo.exists()) {
385 if(item == currentFileInfo.fileName())
386 indInitShader = indCurrentShader;
391 if(indInitShader != -1)
392 d->comboBoxShader->setCurrentIndex(indInitShader);
398 QDir dirShader(
":axlShader/shader/");
399 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
401 QFileInfo currentFile(dirShader, shader);
402 if(!currentFile.exists()) {
403 QSettings settings(
"inria",
"dtk");
405 settings.beginGroup(
"shader");
406 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
407 defaultPathShader.append(
"/");
409 QDir defaultDirShader(defaultPathShader);
410 currentFile = QFileInfo(defaultDirShader, shader);
412 d->lineEditShader->setText(currentFile.absoluteFilePath());
416 d->torus->centerPoint()->x() = x;
417 d->torus->touchGeometry();
423 d->torus->centerPoint()->y() = y;
424 d->torus->touchGeometry();
430 d->torus->centerPoint()->z() = z;
431 d->torus->touchGeometry();
437 d->torus->direction()->x() = x;
438 d->torus->touchGeometry();
444 d->torus->direction()->y() = y;
445 d->torus->touchGeometry();
451 d->torus->direction()->z() = z;
452 d->torus->touchGeometry();
458 d->torus->setRingRadius(ringRadius);
459 d->torus->touchGeometry();
465 d->torus->setCrossSectionRadius(crossSectionRadius);
466 d->torus->touchGeometry();
472 QVariant variant = d->torus->QObject::property(
"color");
473 if(variant.isValid()) {
474 d->torus->setColor(color);
477 d->torus->touchProperty();
483 double opacity_d = 1.0 - 0.01 * opacity;
485 QVariant variant = d->torus->QObject::property(
"opacity");
486 if(variant.isValid()) {
487 d->torus->setOpacity(opacity_d);
490 d->torus->touchProperty();
498 const QSignalBlocker blockerCoordCenterX(d->coordinateCenter_x);
499 const QSignalBlocker blockerCoordCenterY(d->coordinateCenter_y);
500 const QSignalBlocker blockerCoordCenterZ(d->coordinateCenter_z);
501 const QSignalBlocker blockerCoordDirectionX(d->coordinateDirection_x);
502 const QSignalBlocker blockerCoordDirectionY(d->coordinateDirection_y);
503 const QSignalBlocker blockerCoordDirectionZ(d->coordinateDirection_z);
504 const QSignalBlocker blockerRingRadius(d->ringRadius);
505 const QSignalBlocker blockerCrossSectionRadius(d->crossSectionRadius);
507 d->coordinateCenter_x->setValue(d->torus->centerPoint()->x());
508 d->coordinateCenter_y->setValue(d->torus->centerPoint()->y());
509 d->coordinateCenter_z->setValue(d->torus->centerPoint()->z());
511 d->coordinateDirection_x->setValue(d->torus->direction()->x());
512 d->coordinateDirection_y->setValue(d->torus->direction()->y());
513 d->coordinateDirection_z->setValue(d->torus->direction()->z());
515 d->ringRadius->setValue(d->torus->ringRadius());
516 d->crossSectionRadius->setValue(d->torus->crossSectionRadius());
void onCoordDataChangedDirection_x(double x)
void onRingRadiusChanged(double ringRadius)
axlInspectorObjectTorus(QWidget *parent=0)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void onColorChanged(QColor color)
void onOpacityChanged(int opacity)
void onCoordDataChangedCenter_z(double z)
void onCrossSectionRadiusChanged(double crossSectionRadius)
void onCoordDataChangedDirection_y(double y)
void onLineEditShaderChanged(QString shader)
virtual ~axlInspectorObjectTorus(void)
void setData(axlTorus *torus)
void onShaderStateChanged(bool isShader)
void onShaderChanged(QString shader)
void onCoordDataChangedCenter_y(double y)
void onCoordDataChangedDirection_z(double z)
void colorChanged(QColor color, dtkAbstractData *data)
void onCoordDataChangedCenter_x(double x)
QSize sizeHint(void) const