Developer documentation | Axl-2.5.1

axlInspectorObjectSurfaceParametricOffset.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectSurfaceParametricOffset.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 
24 
25 #include <dtkGuiSupport/dtkColorButton.h>
26 #include <dtkGuiSupport/dtkSplitter.h>
27 
28 #include <QtGui>
29 
30 class axlInspectorObjectSurfaceParametricOffsetPrivate
31 {
32 public:
34 
35  QDoubleSpinBox *offset;
36 
37  QSlider *sliderSize;
38 
39 
40  dtkColorButton *colorButton;
41  QComboBox *comboBoxShader;
42 
43  QCheckBox *checkBoxShader;
44  QLineEdit *lineEditShader;
45  QPushButton *buttonShader;
46 
47  QSlider *sliderOpacity;
48 };
49 
50 axlInspectorObjectSurfaceParametricOffset::axlInspectorObjectSurfaceParametricOffset(QWidget *parent) : QFrame(parent), d(new axlInspectorObjectSurfaceParametricOffsetPrivate)
51 {
52  d->offset = NULL;
53 
54  d->sliderSize = NULL;
55 
56  d->colorButton = NULL;
57  d->comboBoxShader = NULL;
58 
59  d->checkBoxShader = NULL;
60  d->lineEditShader = NULL;
61  d->buttonShader = NULL;
62 
63  d->sliderOpacity = NULL;
64 }
65 
67 {
68  delete d;
69 
70  d = NULL;
71 }
72 
74 {
75  return QSize(300, 300);
76 }
77 
79 {
80  d->surface = surface;
81  initWidget();
82 }
83 
84 void axlInspectorObjectSurfaceParametricOffset::initWidget()
85 {
86  QVBoxLayout *layoutTop = new QVBoxLayout(this);
87  layoutTop->addWidget(new QLabel("axlInspectorObjectSurfaceParametricOffset", this));
88 
90 
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);
95 
96  QHBoxLayout *layoutoffset = new QHBoxLayout;
97  layoutoffset->addWidget(new QLabel("offset",this));
98  layoutoffset->addWidget(d->offset);
99 
100 
102 
103  d->sliderSize = new QSlider(Qt::Horizontal, this);
104 
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());
111 
113 
114  d->colorButton = new dtkColorButton(this);
115 
116  QHBoxLayout *layoutColorButton = new QHBoxLayout;
117  layoutColorButton->addWidget(new QLabel("Color",this));
118  layoutColorButton->addWidget(d->colorButton);
119  d->colorButton->setColor(this->initColorValue());
120 
122 
123  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
124 
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());
130 
132  d->comboBoxShader = new QComboBox(this);
133  d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
134 
135  d->checkBoxShader = new QCheckBox(this);
136  d->lineEditShader = new QLineEdit(this);
137  d->buttonShader = new QPushButton(this);
138  d->buttonShader->setText("open");
139 
140  d->lineEditShader->setText(this->initShaderValue());
141  this->initComboBoxShaderValue();
142 
143  if(d->lineEditShader->text().isEmpty())
144  {
145  d->lineEditShader->setEnabled(false);
146  d->buttonShader->setEnabled(false);
147  d->comboBoxShader->setEnabled(false);
148  }
149  else
150  d->checkBoxShader->setChecked(true);
151 
152 
154 
155  QVBoxLayout *layoutShader = new QVBoxLayout;
156  QHBoxLayout *layoutShader1 = new QHBoxLayout;
157 
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);
163 
164  layoutShader1->setStretchFactor(labelShader, 2);
165  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
166  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
167  layoutShader1->setStretchFactor(d->buttonShader, 3);
168 
169  layoutShader->addLayout(layoutShader1);
170  layoutShader->addWidget(d->lineEditShader);
171 
172  layoutTop->addLayout(layoutoffset);
173  layoutTop->addWidget(new QLabel(d->surface->surfaceParam()->description(), this));
174 
175 
176  layoutTop->addLayout(layoutSize);
177 
178  layoutTop->addLayout(layoutColorButton);
179  layoutTop->addLayout(layoutOpacity);
180  layoutTop->addLayout(layoutShader);
181 
182  QWidget *top = new QWidget(this);
183  top->setMaximumWidth(295);
184 
185  top->setLayout(layoutTop);
186 
187  // dtkSplitter *splitter = new dtkSplitter(this, true);
188  // splitter->setOrientation(Qt::Vertical);
189  // splitter->addWidget(top);
190 
191  //QVBoxLayout *layout = new QVBoxLayout(this);
192  //layout->setContentsMargins(0, 0, 0, 0);
193  //layout->setSpacing(0);
194  //layout->addWidget(splitter);
195 
196 
197  connect(d->offset, SIGNAL(valueChanged(double)), this, SLOT(onOffsetChanged(double)));
198 
199  connect(d->sliderSize, SIGNAL(valueChanged(int)), this, SLOT(onSizeChanged(int)));
200 
201 
202  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
203 
204  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
205  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
206  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
207  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
208  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
209 
210 }
211 
212 
213 int axlInspectorObjectSurfaceParametricOffset::initSizeValue(void)
214 {
215  double initSize = 100.0*(log(d->surface->size()/0.125))/log(2.0);
216 // if(initSize > 10.0)
217 // initSize = 10;
218 // else if(initSize < 0.0)
219 // initSize = 0;
220 
221  return initSize;
222 }
223 
224 void axlInspectorObjectSurfaceParametricOffset::initComboBoxShaderValue(void)
225 {
226  if(d->comboBoxShader)
227  {
228  // First add item of axlShader.qrc, then find shader from shader path
229  QDir dirShader( ":axlShader/shader/");
230  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
231 
232  QFileInfoList list = dirShader.entryInfoList();
233  // for (int i = 0; i < list.size(); ++i) {
234  // d->comboBoxShader->addItem(list.at(i).fileName());
235  // }
236 
237  QSettings settings("inria", "dtk");
238  QString defaultPath;
239  settings.beginGroup("shader");
240  QString defaultPathShader = settings.value("path", defaultPath).toString();
241  defaultPathShader.append("/");
242 
243  QDir defaultDirShader(defaultPathShader);
244  QStringList filters;
245  filters << "*.xml";
246  defaultDirShader.setNameFilters(filters);
247  QFileInfoList list2 = defaultDirShader.entryInfoList();
248 
249  list.append(list2);
250 
251  QStringList items;
252 
253  for (int i = 0; i < list.size(); ++i) {
254  if(!items.contains(list.at(i).fileName()))
255  items << list.at(i).fileName();
256  }
257 
258  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
259  int indInitShader = -1;
260  int indCurrentShader = -1;
261 
262 
263  foreach(QString item, items)
264  {
265  indCurrentShader++;
266  d->comboBoxShader->addItem(item);
267 
268  QFileInfo currentFileInfo(d->lineEditShader->text());
269 
270  if(currentFileInfo.exists())
271  {
272  if(item == currentFileInfo.fileName())
273  indInitShader =indCurrentShader;
274  }
275  }
276 
277  //init the value from the lineEditShader.
278  if(indInitShader != -1)
279  d->comboBoxShader->setCurrentIndex(indInitShader);
280 
281  }
282 }
283 
285 {
286  // First add item of axlShader.qrc, then find shader from shader path
287  QDir dirShader( ":axlShader/shader/");
288  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
289 
290  QFileInfo currentFile(dirShader, shader);
291  if(!currentFile.exists())
292  {
293  QSettings settings("inria", "dtk");
294  QString defaultPath;
295  settings.beginGroup("shader");
296  QString defaultPathShader = settings.value("path", defaultPath).toString();
297  defaultPathShader.append("/");
298 
299  QDir defaultDirShader(defaultPathShader);
300  currentFile = QFileInfo(defaultDirShader, shader);
301 
302  }
303 
304  d->lineEditShader->setText(currentFile.absoluteFilePath());
305 }
306 
307 QString axlInspectorObjectSurfaceParametricOffset::initShaderValue(void)
308 {
309  return d->surface->shader();
310 }
311 
312 
313 QColor axlInspectorObjectSurfaceParametricOffset::initColorValue(void)
314 {
315  return d->surface->color();
316 }
317 
318 
319 int axlInspectorObjectSurfaceParametricOffset::initOpacityValue(void)
320 {
321  double initOpacity = 0.0;
322  double opacity = d->surface->opacity();
323  if(opacity > initOpacity)
324  initOpacity = opacity;
325 
326  return 100 * (1.0 - initOpacity);
327 }
328 
330 {
331  if(d->lineEditShader->isEnabled())
332  {
333  QString fileToOpen;
334  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("xml document (*.xml)"));
335  d->lineEditShader->setText(fileToOpen);
336  }
337 }
338 
340 {
341  d->surface->setShader(shader);
342 
343  emit dataChangedByShader(d->surface, d->lineEditShader->text());
344 
345  emit update();
346 }
347 
349 {
350  if(isShader)
351  {
352  d->comboBoxShader->setEnabled(true);
353  d->lineEditShader->setEnabled(true);
354  d->buttonShader->setEnabled(true);
355  onLineEditShaderChanged(d->comboBoxShader->currentText());
356 
357  emit dataChangedByShader(d->surface, d->lineEditShader->text());
358  }
359  else
360  {
361  d->comboBoxShader->setEnabled(false);
362  d->lineEditShader->setEnabled(false);
363  d->buttonShader->setEnabled(false);
364 
365  emit dataChangedByShader(d->surface, "");
366  }
367 
368  emit update();
369 }
370 
372 {
373  d->surface->setOffset(offset);
374 
375  emit dataChangedByGeometry(d->surface);
376 
377  emit update();
378 }
379 
381 {
382  QVariant variant = d->surface->QObject::property("color");
383  if(variant.isValid())
384  {
385  d->surface->setColor(color);
386 
387  emit dataChangedByColor(d->surface, color.redF(), color.greenF(), color.blueF());
388  }
389 
390  emit update();
391 }
392 
393 
395 {
396  double size_d = pow(2.0, size/100.0 - 3.0); // range from 0.00 to 10.00
397 
398  QVariant variant = d->surface->QObject::property("size");
399  if(variant.isValid())
400  {
401  d->surface->setSize(size_d);
402 
403  emit dataChangedByGeometry(d->surface);
404  }
405 
406  emit update();
407 }
408 
410 {
411  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
412 
413  QVariant variant = d->surface->QObject::property("opacity");
414  if(variant.isValid())
415  {
416  d->surface->setOpacity(opacity_d);
417 
418  emit dataChangedByOpacity(d->surface, opacity_d);
419  }
420 
421  emit update();
422 }
423 
424 
425 
426 
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void dataChangedByGeometry(dtkAbstractData *data)
void dataChangedByOpacity(dtkAbstractData *data, double opacity)
Class axlSurfaceParametricOffset defines offset of axlAbstractSurfaceParametric.
void colorChanged(QColor color, dtkAbstractData *data)
void dataChangedByShader(dtkAbstractData *data, QString isophoteShaderXml)
void dataChangedByColor(dtkAbstractData *data, double red, double green, double blue)