25 #include <dtkGuiSupport/dtkColorButton.h>
26 #include <dtkGuiSupport/dtkSplitter.h>
30 class axlInspectorObjectSurfaceParametricOffsetPrivate
35 QDoubleSpinBox *offset;
40 dtkColorButton *colorButton;
41 QComboBox *comboBoxShader;
43 QCheckBox *checkBoxShader;
44 QLineEdit *lineEditShader;
45 QPushButton *buttonShader;
47 QSlider *sliderOpacity;
56 d->colorButton = NULL;
57 d->comboBoxShader = NULL;
59 d->checkBoxShader = NULL;
60 d->lineEditShader = NULL;
61 d->buttonShader = NULL;
63 d->sliderOpacity = NULL;
75 return QSize(300, 300);
84 void axlInspectorObjectSurfaceParametricOffset::initWidget()
86 QVBoxLayout *layoutTop =
new QVBoxLayout(
this);
87 layoutTop->addWidget(
new QLabel(
"axlInspectorObjectSurfaceParametricOffset",
this));
91 d->offset =
new QDoubleSpinBox(
this);
92 d->offset->setRange(-1000, 1000);
93 d->offset->setValue(d->surface->offset());
94 d->offset->setSingleStep(0.1);
96 QHBoxLayout *layoutoffset =
new QHBoxLayout;
97 layoutoffset->addWidget(
new QLabel(
"offset",
this));
98 layoutoffset->addWidget(d->offset);
103 d->sliderSize =
new QSlider(Qt::Horizontal,
this);
105 QHBoxLayout *layoutSize =
new QHBoxLayout;
106 layoutSize->addWidget(
new QLabel(
"Size",
this));
107 layoutSize->addWidget(d->sliderSize);
108 d->sliderSize->setMinimum(-800);
109 d->sliderSize->setMaximum(500);
110 d->sliderSize->setValue(initSizeValue());
114 d->colorButton =
new dtkColorButton(
this);
116 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
117 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
118 layoutColorButton->addWidget(d->colorButton);
119 d->colorButton->setColor(this->initColorValue());
123 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
125 QHBoxLayout *layoutOpacity =
new QHBoxLayout;
126 layoutOpacity->addWidget(
new QLabel(
"Opacity",
this));
127 layoutOpacity->addWidget(d->sliderOpacity);
128 d->sliderOpacity->setMaximum(100);
129 d->sliderOpacity->setValue(initOpacityValue());
132 d->comboBoxShader =
new QComboBox(
this);
133 d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
135 d->checkBoxShader =
new QCheckBox(
this);
136 d->lineEditShader =
new QLineEdit(
this);
137 d->buttonShader =
new QPushButton(
this);
138 d->buttonShader->setText(
"open");
140 d->lineEditShader->setText(this->initShaderValue());
141 this->initComboBoxShaderValue();
143 if(d->lineEditShader->text().isEmpty())
145 d->lineEditShader->setEnabled(
false);
146 d->buttonShader->setEnabled(
false);
147 d->comboBoxShader->setEnabled(
false);
150 d->checkBoxShader->setChecked(
true);
155 QVBoxLayout *layoutShader =
new QVBoxLayout;
156 QHBoxLayout *layoutShader1 =
new QHBoxLayout;
158 QLabel *labelShader =
new QLabel(
"Shader",
this);
159 layoutShader1->addWidget(labelShader);
160 layoutShader1->addWidget(d->checkBoxShader);
161 layoutShader1->addWidget(d->comboBoxShader);
162 layoutShader1->addWidget(d->buttonShader);
164 layoutShader1->setStretchFactor(labelShader, 2);
165 layoutShader1->setStretchFactor(d->checkBoxShader, 1);
166 layoutShader1->setStretchFactor(d->comboBoxShader, 4);
167 layoutShader1->setStretchFactor(d->buttonShader, 3);
169 layoutShader->addLayout(layoutShader1);
170 layoutShader->addWidget(d->lineEditShader);
172 layoutTop->addLayout(layoutoffset);
173 layoutTop->addWidget(
new QLabel(d->surface->surfaceParam()->description(),
this));
176 layoutTop->addLayout(layoutSize);
178 layoutTop->addLayout(layoutColorButton);
179 layoutTop->addLayout(layoutOpacity);
180 layoutTop->addLayout(layoutShader);
182 QWidget *top =
new QWidget(
this);
183 top->setMaximumWidth(295);
185 top->setLayout(layoutTop);
197 connect(d->offset, SIGNAL(valueChanged(
double)),
this, SLOT(
onOffsetChanged(
double)));
199 connect(d->sliderSize, SIGNAL(valueChanged(
int)),
this, SLOT(
onSizeChanged(
int)));
204 connect(d->sliderOpacity, SIGNAL(valueChanged(
int)),
this, SLOT(
onOpacityChanged(
int)));
205 connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)),
this, SLOT(
onLineEditShaderChanged(QString)));
207 connect(d->buttonShader, SIGNAL(clicked()),
this, SLOT(
openShader()));
208 connect(d->lineEditShader, SIGNAL(textChanged(QString)),
this, SLOT(
onShaderChanged(QString)));
213 int axlInspectorObjectSurfaceParametricOffset::initSizeValue(
void)
215 double initSize = 100.0*(log(d->surface->size()/0.125))/log(2.0);
224 void axlInspectorObjectSurfaceParametricOffset::initComboBoxShaderValue(
void)
226 if(d->comboBoxShader)
229 QDir dirShader(
":axlShader/shader/");
230 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
232 QFileInfoList list = dirShader.entryInfoList();
237 QSettings settings(
"inria",
"dtk");
239 settings.beginGroup(
"shader");
240 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
241 defaultPathShader.append(
"/");
243 QDir defaultDirShader(defaultPathShader);
246 defaultDirShader.setNameFilters(filters);
247 QFileInfoList list2 = defaultDirShader.entryInfoList();
253 for (
int i = 0; i < list.size(); ++i) {
254 if(!items.contains(list.at(i).fileName()))
255 items << list.at(i).fileName();
259 int indInitShader = -1;
260 int indCurrentShader = -1;
263 foreach(QString item, items)
266 d->comboBoxShader->addItem(item);
268 QFileInfo currentFileInfo(d->lineEditShader->text());
270 if(currentFileInfo.exists())
272 if(item == currentFileInfo.fileName())
273 indInitShader =indCurrentShader;
278 if(indInitShader != -1)
279 d->comboBoxShader->setCurrentIndex(indInitShader);
287 QDir dirShader(
":axlShader/shader/");
288 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
290 QFileInfo currentFile(dirShader, shader);
291 if(!currentFile.exists())
293 QSettings settings(
"inria",
"dtk");
295 settings.beginGroup(
"shader");
296 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
297 defaultPathShader.append(
"/");
299 QDir defaultDirShader(defaultPathShader);
300 currentFile = QFileInfo(defaultDirShader, shader);
304 d->lineEditShader->setText(currentFile.absoluteFilePath());
307 QString axlInspectorObjectSurfaceParametricOffset::initShaderValue(
void)
309 return d->surface->shader();
313 QColor axlInspectorObjectSurfaceParametricOffset::initColorValue(
void)
315 return d->surface->color();
319 int axlInspectorObjectSurfaceParametricOffset::initOpacityValue(
void)
321 double initOpacity = 0.0;
322 double opacity = d->surface->opacity();
323 if(opacity > initOpacity)
324 initOpacity = opacity;
326 return 100 * (1.0 - initOpacity);
331 if(d->lineEditShader->isEnabled())
334 fileToOpen = QFileDialog::getOpenFileName(
this, tr(
"Open shader"),
"", tr(
"xml document (*.xml)"));
335 d->lineEditShader->setText(fileToOpen);
341 d->surface->setShader(shader);
352 d->comboBoxShader->setEnabled(
true);
353 d->lineEditShader->setEnabled(
true);
354 d->buttonShader->setEnabled(
true);
361 d->comboBoxShader->setEnabled(
false);
362 d->lineEditShader->setEnabled(
false);
363 d->buttonShader->setEnabled(
false);
373 d->surface->setOffset(offset);
382 QVariant variant = d->surface->QObject::property(
"color");
383 if(variant.isValid())
385 d->surface->setColor(color);
396 double size_d = pow(2.0, size/100.0 - 3.0);
398 QVariant variant = d->surface->QObject::property(
"size");
399 if(variant.isValid())
401 d->surface->setSize(size_d);
411 double opacity_d = 1.0 - 0.01 * opacity;
413 QVariant variant = d->surface->QObject::property(
"opacity");
414 if(variant.isValid())
416 d->surface->setOpacity(opacity_d);
void onShaderStateChanged(bool isShader)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void onSizeChanged(int size)
void onLineEditShaderChanged(QString)
void dataChangedByGeometry(dtkAbstractData *data)
axlInspectorObjectSurfaceParametricOffset(QWidget *parent=0)
void dataChangedByOpacity(dtkAbstractData *data, double opacity)
~axlInspectorObjectSurfaceParametricOffset(void)
QSize sizeHint(void) const
Class axlSurfaceParametricOffset defines offset of axlAbstractSurfaceParametric.
void colorChanged(QColor color, dtkAbstractData *data)
void setData(axlSurfaceParametricOffset *surface)
void dataChangedByShader(dtkAbstractData *data, QString isophoteShaderXml)
void onOpacityChanged(int opacity)
void onShaderChanged(QString)
void onColorChanged(QColor color)
void onOffsetChanged(double offset)
void dataChangedByColor(dtkAbstractData *data, double red, double green, double blue)