Developer documentation | Axl-2.5.1

axlInspectorObjectComposite.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectComposite.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Fri Mar 18 11:19:52 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Apr 3 14:20:31 2012 (+0200)
8  * By: Julien Wintz
9  * Update #: 60
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 #include "axlParameterSpace.h"
22 
24 #include <dtkCoreSupport/dtkAbstractData.h>
25 
26 #include <dtkGuiSupport/dtkColorButton.h>
27 #include <dtkGuiSupport/dtkSplitter.h>
28 
29 #include <QtGui>
30 
31 
32 
33 class axlInspectorObjectCompositePrivate
34 {
35 public:
37  dtkColorButton *colorButton;
38 
39  QComboBox *comboBoxShader;
40 
41  QCheckBox *checkBoxShader;
42  QLineEdit *lineEditShader;
43  QPushButton *buttonShader;
44 
45  QSlider *sliderOpacity;
46 
47 public:
48  axlParameterSpace *parameter_space;
49 };
50 
51 axlInspectorObjectComposite::axlInspectorObjectComposite(QWidget *parent) : QFrame(parent), d(new axlInspectorObjectCompositePrivate)
52 {
53  d->data = NULL;
54 
55  d->parameter_space = new axlParameterSpace(this);
56 
57  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
58  d->sliderOpacity->setMaximum(100);
59 
60  d->comboBoxShader = new QComboBox(this);
61 
62  d->checkBoxShader = new QCheckBox(this);
63  d->lineEditShader = new QLineEdit(this);
64  d->buttonShader = new QPushButton(this);
65  d->buttonShader->setText("open");
66  d->lineEditShader->setEnabled(false);
67  d->buttonShader->setEnabled(false);
68  d->comboBoxShader->setEnabled(false);
69 
70  d->colorButton = new dtkColorButton(this);
71 
72  QHBoxLayout *layoutColorButton = new QHBoxLayout;
73  layoutColorButton->addWidget(new QLabel("Color",this));
74  layoutColorButton->addWidget(d->colorButton);
75 
76  QHBoxLayout *layoutOpacity = new QHBoxLayout;
77  layoutOpacity->addWidget(new QLabel("Opacity",this));
78  layoutOpacity->addWidget(d->sliderOpacity);
79 
80  QVBoxLayout *layoutShader = new QVBoxLayout;
81  QHBoxLayout *layoutShader1 = new QHBoxLayout;
82  QLabel *labelShader = new QLabel("Shader",this);
83  layoutShader1->addWidget(labelShader);
84  layoutShader1->addWidget(d->checkBoxShader);
85  layoutShader1->addWidget(d->comboBoxShader);
86  layoutShader1->addWidget(d->buttonShader);
87  layoutShader1->setStretchFactor(labelShader, 2);
88  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
89  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
90  layoutShader1->setStretchFactor(d->buttonShader, 3);
91 
92  layoutShader->addLayout(layoutShader1);
93  layoutShader->addWidget(d->lineEditShader);
94 
95  QVBoxLayout *layoutTop = new QVBoxLayout;
96  layoutTop->addWidget(new QLabel("axlInspectorObjectComposite", this));
97  layoutTop->addLayout(layoutColorButton);
98  layoutTop->addLayout(layoutOpacity);
99  layoutTop->addLayout(layoutShader);
100  layoutTop->addStretch(1);
101 
102  QWidget *top = new QWidget(this);
103  top->setMaximumWidth(295);
104  top->setLayout(layoutTop);
105 
106  dtkSplitter *splitter = new dtkSplitter(this, true);
107  splitter->setOrientation(Qt::Vertical);
108  splitter->addWidget(top);
109  splitter->addWidget(d->parameter_space);
110 
111  QVBoxLayout *layout = new QVBoxLayout(this);
112  layout->setContentsMargins(0, 0, 0, 0);
113  layout->setSpacing(0);
114  layout->addWidget(splitter);
115 
116 
117  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
118  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
119 
120 
121  connect(d->parameter_space, SIGNAL(showCurrentPoint(double, double)), this, SLOT(onShowCurrentPoint(double, double)));
122  connect(d->parameter_space, SIGNAL(hideCurrentPoint(double, double)), this, SLOT(onHideCurrentPoint(double, double)));
123  connect(d->parameter_space, SIGNAL(moveCurrentPoint(double, double)), this, SLOT(onMoveCurrentPoint(double, double)));
124  connect(d->parameter_space, SIGNAL(update()), this, SIGNAL(update()));
125 }
126 
128 {
129  delete d;
130 
131  d = NULL;
132 }
133 
135 {
136  return QSize(300, 300);
137 }
138 
140 {
141  d->data = data;
142 
143  axlAbstractDataComposite *object = d->data;
144  QColor color = object->color();
145 
146  d->colorButton->setColor(color);
147  d->sliderOpacity->setValue(100 * (1.0 - d->data->opacity()));
148  d->lineEditShader->setText(d->data->shader());
149  this->initComboBoxShaderValue();
150 
151 
152  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
153 
154  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
155 
156  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
157 
158  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
159  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
160 
161 
162 }
163 
165 {
166  d->data->setColor(color);
167 
168  // emit dataChangedByColor(d->data, color.redF(), color.greenF(), color.blueF());
169  emit modifiedProperty(d->data, 0);
170 
171 // emit update();
172 }
173 
175 {
176  if(d->lineEditShader->isEnabled())
177  {
178  QString fileToOpen;
179  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("vs file (*.vs)"));
180  d->lineEditShader->setText(fileToOpen);
181  }
182 }
183 
184 void axlInspectorObjectComposite::initComboBoxShaderValue(void)
185 {
186  if(d->comboBoxShader) {
187 
188  QStringList filters;
189  filters << "*.vs";
190 
191  // First add item of axlShader.qrc, then find shader from shader path
192  QDir dirShader( ":axlShader/shader/");
193  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
194 
195  dirShader.setNameFilters(filters);
196 
197  QFileInfoList list = dirShader.entryInfoList();
198  // for (int i = 0; i < list.size(); ++i) {
199  // d->comboBoxShader->addItem(list.at(i).fileName());
200  // }
201 
202  QSettings settings("inria", "dtk");
203  QString defaultPath;
204  settings.beginGroup("shader");
205  QString defaultPathShader = settings.value("path", defaultPath).toString();
206  defaultPathShader.append("/");
207 
208  QDir defaultDirShader(defaultPathShader);
209  defaultDirShader.setNameFilters(filters);
210  QFileInfoList list2 = defaultDirShader.entryInfoList();
211 
212  list.append(list2);
213 
214  QStringList items;
215 
216  for (int i = 0; i < list.size(); ++i) {
217  if(!items.contains(list.at(i).fileName()))
218  items << list.at(i).fileName();
219  }
220 
221  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
222  int indInitShader = -1;
223  int indCurrentShader = -1;
224 
225  foreach(QString item, items) {
226  indCurrentShader++;
227  d->comboBoxShader->addItem(item);
228 
229  QFileInfo currentFileInfo(d->lineEditShader->text());
230 
231  if(currentFileInfo.exists())
232  {
233  if(item == currentFileInfo.fileName())
234  indInitShader =indCurrentShader;
235  }
236  }
237 
238  //init the value from the lineEditShader.
239  if(indInitShader != -1)
240  d->comboBoxShader->setCurrentIndex(indInitShader);
241  }
242 }
243 
244 
246 {
247  d->data->setShader(shader);
248 
249  // emit dataChangedByShader(d->data, d->lineEditShader->text());
250  emit modifiedProperty(d->data, 2);
251 
252 // emit update();
253 }
254 
256 {
257  // First add item of axlShader.qrc, then find shader from shader path
258  QDir dirShader( ":axlShader/shader/");
259  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
260 
261  QFileInfo currentFile(dirShader, shader);
262  if(!currentFile.exists())
263  {
264  QSettings settings("inria", "dtk");
265  QString defaultPath;
266  settings.beginGroup("shader");
267  QString defaultPathShader = settings.value("path", defaultPath).toString();
268  defaultPathShader.append("/");
269 
270  QDir defaultDirShader(defaultPathShader);
271  currentFile = QFileInfo(defaultDirShader, shader);
272 
273  }
274 
275  d->lineEditShader->setText(currentFile.absoluteFilePath());
276 }
277 
279 {
280  if(isShader)
281  {
282  d->comboBoxShader->setEnabled(true);
283  d->lineEditShader->setEnabled(true);
284  d->buttonShader->setEnabled(true);
285  onLineEditShaderChanged(d->comboBoxShader->currentText());
286 
287  // emit dataChangedByShader(d->data, d->lineEditShader->text());
288  }
289  else
290  {
291  d->comboBoxShader->setEnabled(false);
292  d->lineEditShader->setEnabled(false);
293  d->buttonShader->setEnabled(false);
294 
295  // emit dataChangedByShader(d->data, "");
296  }
297  emit modifiedProperty(d->data, 2);
298 // emit update();
299 }
300 
302 {
303  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
304  d->data->setOpacity(opacity_d);
305 
306 // emit dataChangedByOpacity(d->data, opacity_d);
307  emit modifiedProperty(d->data, 1);
308 
309 // emit update();
310 }
311 
313 {
314  emit showCurrentPoint(u, v, (dtkAbstractData *)d->data);
315 }
316 
318 {
319  emit moveCurrentPoint(u, v, (dtkAbstractData *)d->data);
320 }
321 
323 {
324  emit hideCurrentPoint(u, v, (dtkAbstractData *)d->data);
325 }
void modifiedProperty(dtkAbstractData *, int)
void moveCurrentPoint(double u, double v, dtkAbstractData *data)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void onShowCurrentPoint(double u, double v)
void hideCurrentPoint(double u, double v, dtkAbstractData *data)
void onMoveCurrentPoint(double u, double v)
void setData(axlAbstractDataComposite *data)
void onHideCurrentPoint(double u, double v)
void showCurrentPoint(double u, double v, dtkAbstractData *data)