53 #include "textureProperties.hh" 58 #include "ImageStorage.hh" 60 texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
65 connect(buttonBox, SIGNAL( clicked(QAbstractButton*) ),
this , SLOT ( slotButtonBoxClicked(QAbstractButton*) ) );
66 connect(textureList, SIGNAL(itemClicked(QTreeWidgetItem*,
int)),
this, SLOT(textureChanged(QTreeWidgetItem*,
int)) );
67 connect(textureList, SIGNAL(itemPressed(QTreeWidgetItem*,
int)),
this, SLOT(textureAboutToChange(QTreeWidgetItem*,
int)) );
70 connect(repeatBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
71 connect(clampBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
72 connect(centerBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
73 connect(absBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
74 connect(scaleBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
76 connect(max_val, SIGNAL( valueChanged(
double) ),
this , SLOT ( slotPropertiesChanged(
double) ) );
77 connect(clamp_min, SIGNAL( valueChanged(
double) ),
this , SLOT ( slotPropertiesChanged(
double) ) );
78 connect(clamp_max, SIGNAL( valueChanged(
double) ),
this , SLOT ( slotPropertiesChanged(
double) ) );
80 connect(changeImageButton, SIGNAL( clicked() ),
this, SLOT( slotChangeImage() ) );
86 QGridLayout* layout =
new QGridLayout( originalData);
88 functionPlot_ =
new ACG::QwtFunctionPlot(0);
90 layout->addWidget( functionPlot_ , 0,0 );
96 void texturePropertiesWidget::show(
TextureData* _texData,
int _id, QString _name){
101 textureList->clear();
103 QTreeWidgetItem* activeItem = 0;
105 for (
unsigned int i=0; i < texData_->textures().size(); i++) {
106 if ( ! texData_->textures()[i].hidden() ) {
107 if ( texData_->textures()[i].type() != MULTITEXTURE ) {
109 QTreeWidgetItem* item = 0;
111 if ( !texData_->textures()[i].visibleName().isEmpty() )
112 item =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].visibleName() ) );
114 item =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].name() ) );
116 textureList->addTopLevelItem( item );
118 if (texData_->textures()[i].enabled())
122 QTreeWidgetItem* parent = 0;
123 if ( !texData_->textures()[i].visibleName().isEmpty() )
124 parent =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].visibleName() ) );
126 parent =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].name() ) );
128 textureList->addTopLevelItem( parent ) ;
129 for (
int j = 0 ; j < texData_->textures()[i].multiTextureList.size() ; ++j )
130 textureList->addTopLevelItem(
new QTreeWidgetItem(parent, QStringList(texData_->textures()[i].multiTextureList[j] )) );
132 if (texData_->textures()[i].enabled())
138 if ( textureList->invisibleRootItem()->childCount() == 0 ) {
139 QMessageBox msgBox(
this);
140 msgBox.setText(
"Cannot show Properties. No Textures available!");
146 textureLabel->setText(
"<B>Global Textures</B>");
148 textureLabel->setText(
"<B>Textures for object '" + _name +
"'</B>");
150 propChanged_ =
false;
152 if (activeItem == 0){
154 textureList->setCurrentItem( textureList->topLevelItem(0) );
155 textureChanged( textureList->topLevelItem(0), 0 );
158 textureList->setCurrentItem( activeItem );
159 textureChanged( activeItem, 0 );
165 void texturePropertiesWidget::textureAboutToChange(QTreeWidgetItem* _item,
int _column){
168 QMessageBox msgBox(
this);
169 msgBox.setText(
"The properties of the current texture have been changed.");
170 msgBox.setInformativeText(
"Do you want to apply these changes?");
171 msgBox.setStandardButtons(QMessageBox::Apply | QMessageBox::Discard );
172 msgBox.setDefaultButton(QMessageBox::Apply);
173 int ret = msgBox.exec();
175 if (ret == QMessageBox::Apply){
177 for (
int i=0; i < buttonBox->buttons().count(); i++)
178 if ( buttonBox->standardButton( buttonBox->buttons()[i] ) == QDialogButtonBox::Apply )
179 slotButtonBoxClicked( buttonBox->buttons()[i] );
181 textureList->setCurrentItem( _item );
182 textureChanged( _item,_column );
185 propChanged_ =
false;
187 textureList->setCurrentItem( _item );
188 textureChanged( _item,_column );
193 void texturePropertiesWidget::textureChanged(QTreeWidgetItem* _item,
int _column){
199 textureList->setCurrentItem( curItem_ );
206 if ( !texData_->textureExists( _item->text(_column) ) )
212 textureName_ = _item->text(_column);
250 Texture& texture = texData_->texture(textureName_);
252 repeatBox->setChecked(texture.
parameters.repeat);
253 clampBox->setChecked(texture.
parameters.clamp);
254 centerBox->setChecked(texture.
parameters.center);
257 max_val->setValue( texture.
parameters.repeatMax );
258 clamp_min->setValue( texture.
parameters.clampMin );
259 clamp_max->setValue( texture.
parameters.clampMax );
261 switch (texture.type()) {
263 typeLabel->setText(
"Type: MultiTexture");
264 indexLabel->setEnabled(
true);
265 indexBox->setEnabled(
true);
267 indexBox->addItem(
"TODO");
270 typeLabel->setText(
"Type: HalfedgeBased");
271 indexLabel->setEnabled(
false);
272 indexBox->setEnabled(
false);
276 typeLabel->setText(
"Type: VertexBased");
277 indexLabel->setEnabled(
false);
278 indexBox->setEnabled(
false);
282 typeLabel->setText(
"Type: Environment Map");
283 indexLabel->setEnabled(
false);
284 indexBox->setEnabled(
false);
288 typeLabel->setText(
"Type: Unset");
289 indexLabel->setEnabled(
false);
290 indexBox->setEnabled(
false);
297 imageLabel->setPixmap(QPixmap::fromImage( imageStore().getImage(texture.textureImageId(),&ok) ));
300 std::cerr<< imageStore().error().toStdString();
303 imageLabel->setScaledContents(
true);
305 if ( texture.filename().startsWith(
"/") )
306 fileLabel->setText(
"File: " + texture.filename() );
308 fileLabel->setText(
"File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename() );
310 currentImage_ = texture.filename();
313 if ( texture.dimension() == 1 && id_ != -1) {
317 std::vector< double > coords;
319 emit getCoordinates1D(textureName_, id_, coords);
321 if ( ! coords.empty() ){
323 functionPlot_->setFunction( coords );
325 functionPlot_->setParameters(repeatBox->isChecked(), max_val->value(),
326 clampBox->isChecked(), clamp_min->value(), clamp_max->value(),
327 centerBox->isChecked(),
329 scaleBox->isChecked());
332 image_ = imageStore().getImage(texture.textureImageId(),&ok);
334 std::cerr << imageStore().error().toStdString();
338 functionPlot_->setImage( &image_ );
340 functionPlot_->replot();
346 propChanged_ =
false;
347 curItem_ = textureList->currentItem();
351 void texturePropertiesWidget::slotChangeImage()
354 QString fileName = QFileDialog::getOpenFileName(
this,
356 OpenFlipper::Options::currentTextureDirStr(),
357 tr(
"Images (*.png *.xpm *.jpg *.tga *.tif *.tiff *.bmp);;All Files (*.*)"));
359 if (QFile(fileName).exists()) {
360 QFileInfo fileInfo(fileName);
363 imageLabel->setPixmap(fileName);
364 imageLabel->setScaledContents(
true);
366 fileLabel->setText(
"File: " + fileName);
368 currentImage_ = fileName;
369 image_ = imageLabel->pixmap()->toImage();
372 functionPlot_->setImage(&image_);
373 functionPlot_->replot();
381 void texturePropertiesWidget::slotButtonBoxClicked(QAbstractButton* _button){
383 QDialogButtonBox::StandardButton btn = buttonBox->standardButton(_button);
385 if ( btn == QDialogButtonBox::Apply || btn == QDialogButtonBox::Ok){
388 bool changed =
false;
390 Texture& texture = texData_->texture(textureName_);
392 if ( texture.
parameters.repeat != repeatBox->isChecked() ){
393 texture.
parameters.repeat=repeatBox->isChecked();
396 if ( texture.
parameters.clamp != clampBox->isChecked() ){
397 texture.
parameters.clamp=clampBox->isChecked();
400 if ( texture.
parameters.center != centerBox->isChecked() ){
401 texture.
parameters.center=centerBox->isChecked();
404 if ( texture.
parameters.abs != absBox->isChecked() ){
408 if ( texture.
parameters.scale != scaleBox->isChecked() ){
409 texture.
parameters.scale=scaleBox->isChecked();
413 if ( texture.
parameters.repeatMax != max_val->value() ){
414 texture.
parameters.repeatMax = max_val->value();
418 if ( texture.
parameters.clampMin != clamp_min->value() ){
419 texture.
parameters.clampMin = clamp_min->value();
423 if ( texture.
parameters.clampMax != clamp_max->value() ){
424 texture.
parameters.clampMax = clamp_max->value();
428 if ( texture.filename() != currentImage_ ){
430 texture.filename( currentImage_ );
433 texture.textureImageId( imageStore().addImageFile(currentImage_) );
440 emit applyProperties(texData_, textureName_, id_ );
442 propChanged_ =
false;
445 if ( btn == QDialogButtonBox::Apply )
451 void texturePropertiesWidget::slotPropertiesChanged(
double ){
455 functionPlot_->setParameters(repeatBox->isChecked(), max_val->value(),
456 clampBox->isChecked(), clamp_min->value(), clamp_max->value(),
457 centerBox->isChecked(),
459 scaleBox->isChecked());
461 functionPlot_->replot();
TexParameters parameters
Parameters of the texture.
DLLEXPORT void currentTextureDir(QDir _dir)
Sets the Path to the current texture-directory.