29 #include <dtkCoreSupport/dtkAbstractData.h>
31 #include <dtkGuiSupport/dtkColorButton.h>
32 #include <dtkGuiSupport/dtkSplitter.h>
36 class axlInspectorObjectSetPrivate
39 QList<dtkAbstractData *> dataSet;
41 QSpinBox *spinBoxSampling_u;
42 QSpinBox *spinBoxSampling_v;
46 dtkColorButton *colorButton;
47 QComboBox *comboBoxShader;
49 QCheckBox *checkBoxShader;
50 QLineEdit *lineEditShader;
51 QPushButton *buttonShader;
53 QSlider *sliderOpacity;
55 bool tagSpinBoxSampling_u;
56 bool tagSpinBoxSampling_v;
59 bool tagOpacitySlider;
60 bool tagCheckBoxShader;
65 d->spinBoxSampling_u = NULL;
66 d->spinBoxSampling_v = NULL;
70 d->colorButton = NULL;
71 d->comboBoxShader = NULL;
73 d->checkBoxShader = NULL;
74 d->lineEditShader = NULL;
75 d->buttonShader = NULL;
77 d->sliderOpacity = NULL;
79 d->tagSpinBoxSampling_u =
true;
80 d->tagSpinBoxSampling_v =
true;
81 d->tagSizeSlider =
true;
82 d->tagColorButton =
true;
83 d->tagCheckBoxShader =
true;
84 d->tagOpacitySlider =
true;
96 return QSize(300, 300);
101 d->dataSet = dataSet;
106 void axlInspectorObjectSet::initTag()
108 foreach(dtkAbstractData *data, d->dataSet)
110 if (dynamic_cast<axlAbstractSurfaceBSpline *>(data))
114 else if (dynamic_cast<axlAbstractCurveBSpline *>(data))
116 d->tagSpinBoxSampling_v =
false;
120 d->tagSpinBoxSampling_u =
false;
121 d->tagSpinBoxSampling_v =
false;
126 void axlInspectorObjectSet::initWidget()
129 QVBoxLayout *layoutTop =
new QVBoxLayout;
130 layoutTop->addWidget(
new QLabel(
"axlInspectorObjectSet",
this));
132 if( d->tagSpinBoxSampling_u)
134 d->spinBoxSampling_u =
new QSpinBox(
this);
135 d->spinBoxSampling_u->setMaximum(10000);
136 d->spinBoxSampling_u->setMinimum(1);
137 d->spinBoxSampling_u->setValue(40);
139 QHBoxLayout *layoutSampling_u =
new QHBoxLayout;
140 layoutSampling_u->addWidget(
new QLabel(
"Sampling U",
this));
141 layoutSampling_u->addWidget(d->spinBoxSampling_u);
143 layoutTop->addLayout(layoutSampling_u);
149 if(d->tagSpinBoxSampling_v)
151 d->spinBoxSampling_v =
new QSpinBox(
this);
152 d->spinBoxSampling_v->setMaximum(10000);
153 d->spinBoxSampling_v->setMinimum(1);
154 d->spinBoxSampling_v->setValue(40);
156 QHBoxLayout *layoutSampling_v =
new QHBoxLayout;
157 layoutSampling_v->addWidget(
new QLabel(
"Sampling V",
this));
158 layoutSampling_v->addWidget(d->spinBoxSampling_v);
160 layoutTop->addLayout(layoutSampling_v);
169 d->sliderSize =
new QSlider(Qt::Horizontal,
this);
171 QHBoxLayout *layoutSize =
new QHBoxLayout;
172 layoutSize->addWidget(
new QLabel(
"Size",
this));
173 layoutSize->addWidget(d->sliderSize);
174 d->sliderSize->setMinimum(-800);
175 d->sliderSize->setMaximum(500);
176 d->sliderSize->setValue(initSizeValue());
178 layoutTop->addLayout(layoutSize);
180 connect(d->sliderSize, SIGNAL(valueChanged(
int)),
this, SLOT(
onSizeChanged(
int)));
185 if(d->tagColorButton)
187 d->colorButton =
new dtkColorButton(
this);
189 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
190 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
191 layoutColorButton->addWidget(d->colorButton);
193 layoutTop->addLayout(layoutColorButton);
199 if(d->tagOpacitySlider)
201 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
203 QHBoxLayout *layoutOpacity =
new QHBoxLayout;
204 layoutOpacity->addWidget(
new QLabel(
"Opacity",
this));
205 layoutOpacity->addWidget(d->sliderOpacity);
206 d->sliderOpacity->setMaximum(100);
207 d->sliderOpacity->setValue(initOpacityValue());
209 layoutTop->addLayout(layoutOpacity);
211 connect(d->sliderOpacity, SIGNAL(valueChanged(
int)),
this, SLOT(
onOpacityChanged(
int)));
215 if(d->tagCheckBoxShader)
217 d->comboBoxShader =
new QComboBox(
this);
218 d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
219 d->checkBoxShader =
new QCheckBox(
this);
220 d->lineEditShader =
new QLineEdit(
this);
221 d->buttonShader =
new QPushButton(
this);
222 d->buttonShader->setText(
"open");
223 this->initComboBoxShaderValue();
225 connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)),
this, SLOT(
onLineEditShaderChanged(QString)));
227 connect(d->buttonShader, SIGNAL(clicked()),
this, SLOT(
openShader()));
228 connect(d->lineEditShader, SIGNAL(textChanged(QString)),
this, SLOT(
onShaderChanged(QString)));
231 d->lineEditShader->setEnabled(
false);
232 d->buttonShader->setEnabled(
false);
233 d->comboBoxShader->setEnabled(
false);
237 QVBoxLayout *layoutShader =
new QVBoxLayout;
238 QHBoxLayout *layoutShader1 =
new QHBoxLayout;
240 QLabel *labelShader =
new QLabel(
"Shader",
this);
241 layoutShader1->addWidget(labelShader);
242 layoutShader1->addWidget(d->checkBoxShader);
243 layoutShader1->addWidget(d->comboBoxShader);
244 layoutShader1->addWidget(d->buttonShader);
246 layoutShader1->setStretchFactor(labelShader, 2);
247 layoutShader1->setStretchFactor(d->checkBoxShader, 1);
248 layoutShader1->setStretchFactor(d->comboBoxShader, 4);
249 layoutShader1->setStretchFactor(d->buttonShader, 3);
251 layoutShader->addLayout(layoutShader1);
252 layoutShader->addWidget(d->lineEditShader);
254 layoutTop->addLayout(layoutShader);
257 layoutTop->addStretch(1);
259 QWidget *top =
new QWidget(
this);
260 top->setMaximumWidth(295);
262 top->setLayout(layoutTop);
264 dtkSplitter *splitter =
new dtkSplitter(
this,
true);
265 splitter->setOrientation(Qt::Vertical);
266 splitter->addWidget(top);
268 QVBoxLayout *layout =
new QVBoxLayout(
this);
269 layout->setContentsMargins(0, 0, 0, 0);
270 layout->setSpacing(0);
271 layout->addWidget(splitter);
275 int axlInspectorObjectSet::initSizeValue()
277 double initSize = 0.0;
278 foreach(dtkAbstractData *data, d->dataSet)
283 double size = axlData->size();
290 return 100.0 * (log(initSize / 0.125)) / log(2.0);
293 int axlInspectorObjectSet::initOpacityValue()
295 double initOpacity = 0.0;
296 foreach(dtkAbstractData *data, d->dataSet)
301 double opacity = axlData->opacity();
302 if(opacity > initOpacity)
303 initOpacity = opacity;
308 return 100 * (1.0 - initOpacity);
311 void axlInspectorObjectSet::initComboBoxShaderValue(
void)
313 if(d->comboBoxShader)
316 QDir dirShader(
":axlShader/shader/");
317 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
319 QFileInfoList list = dirShader.entryInfoList();
324 QSettings settings(
"inria",
"dtk");
326 settings.beginGroup(
"shader");
327 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
328 defaultPathShader.append(
"/");
330 QDir defaultDirShader(defaultPathShader);
333 defaultDirShader.setNameFilters(filters);
334 QFileInfoList list2 = defaultDirShader.entryInfoList();
340 for (
int i = 0; i < list.size(); ++i) {
341 if(!items.contains(list.at(i).fileName()))
342 items << list.at(i).fileName();
346 int indInitShader = -1;
347 int indCurrentShader = -1;
350 foreach(QString item, items)
353 d->comboBoxShader->addItem(item);
355 QFileInfo currentFileInfo(d->lineEditShader->text());
357 if(currentFileInfo.exists())
359 if(item == currentFileInfo.fileName())
360 indInitShader =indCurrentShader;
365 if(indInitShader != -1)
366 d->comboBoxShader->setCurrentIndex(indInitShader);
374 QDir dirShader(
":axlShader/shader/");
375 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
377 QFileInfo currentFile(dirShader, shader);
378 if(!currentFile.exists())
380 QSettings settings(
"inria",
"dtk");
382 settings.beginGroup(
"shader");
383 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
384 defaultPathShader.append(
"/");
386 QDir defaultDirShader(defaultPathShader);
387 currentFile = QFileInfo(defaultDirShader, shader);
391 d->lineEditShader->setText(currentFile.absoluteFilePath());
396 if(d->lineEditShader->isEnabled())
399 fileToOpen = QFileDialog::getOpenFileName(
this, tr(
"Open shader"),
"", tr(
"xml document (*.xml)"));
400 d->lineEditShader->setText(fileToOpen);
406 foreach(dtkAbstractData *data, d->dataSet)
410 QVariant variant = axlData->QObject::property(
"shader");
411 if(variant.isValid())
412 axlData->setShader(shader);
426 d->comboBoxShader->setEnabled(
true);
427 d->lineEditShader->setEnabled(
true);
428 d->buttonShader->setEnabled(
true);
432 d->comboBoxShader->setEnabled(
false);
433 d->lineEditShader->setEnabled(
false);
434 d->buttonShader->setEnabled(
false);
440 foreach(dtkAbstractData *data, d->dataSet)
444 spline_curve->setNumSamples(numSamples);
449 spline_surface->setNumSamples_u(numSamples);
458 foreach(dtkAbstractData *data, d->dataSet)
462 spline_surface->setNumSamples_v(numSamples);
471 double size_d = pow(2.0, size / 100.0 - 3.0);
473 foreach(dtkAbstractData *data, d->dataSet)
477 QVariant variant = data->QObject::property(
"size");
478 if(variant.isValid())
479 axlData->setSize(size_d);
493 foreach(dtkAbstractData *data, d->dataSet)
497 QVariant variant = data->QObject::property(
"color");
498 if(variant.isValid())
499 axlData->setColor(color);
512 double opacity_d = 1.0 - 0.01 * opacity;
514 foreach(dtkAbstractData *data, d->dataSet)
518 QVariant variant = axlData->QObject::property(
"opacity");
519 if(variant.isValid())
520 axlData->setOpacity(opacity_d);
void onSamplingDataChanged_v(int numSamples)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void setData(QList< dtkAbstractData * > dataSet)
void onOpacityChanged(int opacity)
void onShaderStateChanged(bool isShader)
QSize sizeHint(void) const
void onSizeChanged(int size)
void modifiedProperty(dtkAbstractData *, int)
void onLineEditShaderChanged(QString)
void onSamplingDataChanged_u(int numSamples)
void onShaderChanged(QString)
axlInspectorObjectSet(QWidget *parent=0)
~axlInspectorObjectSet(void)
void colorChanged(QColor color, dtkAbstractData *data)
void onColorChanged(QColor color)
Class axlAbstractData defines an API for all type of axel data.