47 #include "textureProperties.hh" 52 #include "ImageStorage.hh" 54 #include <QMessageBox> 56 texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
61 connect(buttonBox, SIGNAL( clicked(QAbstractButton*) ),
this , SLOT ( slotButtonBoxClicked(QAbstractButton*) ) );
62 connect(textureList, SIGNAL(itemClicked(QTreeWidgetItem*,
int)),
this, SLOT(textureChanged(QTreeWidgetItem*,
int)) );
63 connect(textureList, SIGNAL(itemPressed(QTreeWidgetItem*,
int)),
this, SLOT(textureAboutToChange(QTreeWidgetItem*,
int)) );
66 connect(repeatBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
67 connect(clampBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
68 connect(centerBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
69 connect(absBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
70 connect(scaleBox, SIGNAL( clicked() ),
this , SLOT ( slotPropertiesChanged() ) );
72 connect(max_val, SIGNAL( valueChanged(
double) ),
this , SLOT ( slotPropertiesChanged(
double) ) );
73 connect(clamp_min, SIGNAL( valueChanged(
double) ),
this , SLOT ( slotPropertiesChanged(
double) ) );
74 connect(clamp_max, SIGNAL( valueChanged(
double) ),
this , SLOT ( slotPropertiesChanged(
double) ) );
76 connect(changeImageButton, SIGNAL( clicked() ),
this, SLOT( slotChangeImage() ) );
82 QGridLayout* layout =
new QGridLayout( originalData);
84 functionPlot_ =
new ACG::QwtFunctionPlot(0);
86 layout->addWidget( functionPlot_ , 0,0 );
92 void texturePropertiesWidget::show(
TextureData* _texData,
int _id, QString _name){
99 QTreeWidgetItem* activeItem = 0;
101 for (
unsigned int i=0; i < texData_->textures().size(); i++) {
102 if ( ! texData_->textures()[i].hidden() ) {
103 if ( texData_->textures()[i].type() != MULTITEXTURE ) {
105 QTreeWidgetItem* item = 0;
107 if ( !texData_->textures()[i].visibleName().isEmpty() )
108 item =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].visibleName() ) );
110 item =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].name() ) );
112 textureList->addTopLevelItem( item );
114 if (texData_->textures()[i].enabled())
118 QTreeWidgetItem* parent = 0;
119 if ( !texData_->textures()[i].visibleName().isEmpty() )
120 parent =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].visibleName() ) );
122 parent =
new QTreeWidgetItem((QTreeWidget*)0, QStringList( texData_->textures()[i].name() ) );
124 textureList->addTopLevelItem( parent ) ;
125 for (
int j = 0 ; j < texData_->textures()[i].multiTextureList.size() ; ++j )
126 textureList->addTopLevelItem(
new QTreeWidgetItem(parent, QStringList(texData_->textures()[i].multiTextureList[j] )) );
128 if (texData_->textures()[i].enabled())
134 if ( textureList->invisibleRootItem()->childCount() == 0 ) {
135 QMessageBox msgBox(
this);
136 msgBox.setText(
"Cannot show Properties. No Textures available!");
142 textureLabel->setText(
"<B>Global Textures</B>");
144 textureLabel->setText(
"<B>Textures for object '" + _name +
"'</B>");
146 propChanged_ =
false;
148 if (activeItem == 0){
150 textureList->setCurrentItem( textureList->topLevelItem(0) );
151 textureChanged( textureList->topLevelItem(0), 0 );
154 textureList->setCurrentItem( activeItem );
155 textureChanged( activeItem, 0 );
161 void texturePropertiesWidget::textureAboutToChange(QTreeWidgetItem* _item,
int _column){
164 QMessageBox msgBox(
this);
165 msgBox.setText(
"The properties of the current texture have been changed.");
166 msgBox.setInformativeText(
"Do you want to apply these changes?");
167 msgBox.setStandardButtons(QMessageBox::Apply | QMessageBox::Discard );
168 msgBox.setDefaultButton(QMessageBox::Apply);
169 int ret = msgBox.exec();
171 if (ret == QMessageBox::Apply){
173 for (
int i=0; i < buttonBox->buttons().count(); i++)
174 if ( buttonBox->standardButton( buttonBox->buttons()[i] ) == QDialogButtonBox::Apply )
175 slotButtonBoxClicked( buttonBox->buttons()[i] );
177 textureList->setCurrentItem( _item );
178 textureChanged( _item,_column );
181 propChanged_ =
false;
183 textureList->setCurrentItem( _item );
184 textureChanged( _item,_column );
189 void texturePropertiesWidget::textureChanged(QTreeWidgetItem* _item,
int _column){
195 textureList->setCurrentItem( curItem_ );
202 if ( !texData_->textureExists( _item->text(_column) ) )
208 textureName_ = _item->text(_column);
246 Texture& texture = texData_->texture(textureName_);
248 repeatBox->setChecked(texture.
parameters.repeat);
249 clampBox->setChecked(texture.
parameters.clamp);
250 centerBox->setChecked(texture.
parameters.center);
253 max_val->setValue( texture.
parameters.repeatMax );
254 clamp_min->setValue( texture.
parameters.clampMin );
255 clamp_max->setValue( texture.
parameters.clampMax );
257 switch (texture.type()) {
259 typeLabel->setText(
"Type: MultiTexture");
260 indexLabel->setEnabled(
true);
261 indexBox->setEnabled(
true);
263 indexBox->addItem(
"TODO");
266 typeLabel->setText(
"Type: HalfedgeBased");
267 indexLabel->setEnabled(
false);
268 indexBox->setEnabled(
false);
272 typeLabel->setText(
"Type: VertexBased");
273 indexLabel->setEnabled(
false);
274 indexBox->setEnabled(
false);
278 typeLabel->setText(
"Type: Environment Map");
279 indexLabel->setEnabled(
false);
280 indexBox->setEnabled(
false);
284 typeLabel->setText(
"Type: Unset");
285 indexLabel->setEnabled(
false);
286 indexBox->setEnabled(
false);
293 imageLabel->setPixmap(QPixmap::fromImage( imageStore().getImage(texture.textureImageId(),&ok) ));
296 std::cerr<< imageStore().error().toStdString();
299 imageLabel->setScaledContents(
true);
301 if ( texture.filename().startsWith(
"/") )
302 fileLabel->setText(
"File: " + texture.filename() );
304 fileLabel->setText(
"File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename() );
306 currentImage_ = texture.filename();
309 if ( texture.dimension() == 1 && id_ != -1) {
313 std::vector< double > coords;
315 emit getCoordinates1D(textureName_, id_, coords);
317 if ( ! coords.empty() ){
319 functionPlot_->setFunction( coords );
321 functionPlot_->setParameters(repeatBox->isChecked(), max_val->value(),
322 clampBox->isChecked(), clamp_min->value(), clamp_max->value(),
323 centerBox->isChecked(),
325 scaleBox->isChecked());
328 image_ = imageStore().getImage(texture.textureImageId(),&ok);
330 std::cerr << imageStore().error().toStdString();
334 functionPlot_->setImage( &image_ );
336 functionPlot_->replot();
342 propChanged_ =
false;
343 curItem_ = textureList->currentItem();
347 void texturePropertiesWidget::slotChangeImage()
350 QString fileName = QFileDialog::getOpenFileName(
this,
352 OpenFlipper::Options::currentTextureDirStr(),
353 tr(
"Images (*.png *.xpm *.jpg *.tga *.tif *.tiff *.bmp);;All Files (*.*)"));
355 if (QFile(fileName).exists()) {
356 QFileInfo fileInfo(fileName);
359 imageLabel->setPixmap(fileName);
360 imageLabel->setScaledContents(
true);
362 fileLabel->setText(
"File: " + fileName);
364 currentImage_ = fileName;
366 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) 367 image_ = imageLabel->pixmap()->toImage();
369 image_ = imageLabel->pixmap(Qt::ReturnByValue).toImage();
373 functionPlot_->setImage(&image_);
374 functionPlot_->replot();
382 void texturePropertiesWidget::slotButtonBoxClicked(QAbstractButton* _button){
384 QDialogButtonBox::StandardButton btn = buttonBox->standardButton(_button);
386 if ( btn == QDialogButtonBox::Apply || btn == QDialogButtonBox::Ok){
389 bool changed =
false;
391 Texture& texture = texData_->texture(textureName_);
393 if ( texture.
parameters.repeat != repeatBox->isChecked() ){
394 texture.
parameters.repeat=repeatBox->isChecked();
397 if ( texture.
parameters.clamp != clampBox->isChecked() ){
398 texture.
parameters.clamp=clampBox->isChecked();
401 if ( texture.
parameters.center != centerBox->isChecked() ){
402 texture.
parameters.center=centerBox->isChecked();
405 if ( texture.
parameters.abs != absBox->isChecked() ){
409 if ( texture.
parameters.scale != scaleBox->isChecked() ){
410 texture.
parameters.scale=scaleBox->isChecked();
414 if ( texture.
parameters.repeatMax != max_val->value() ){
415 texture.
parameters.repeatMax = max_val->value();
419 if ( texture.
parameters.clampMin != clamp_min->value() ){
420 texture.
parameters.clampMin = clamp_min->value();
424 if ( texture.
parameters.clampMax != clamp_max->value() ){
425 texture.
parameters.clampMax = clamp_max->value();
429 if ( texture.filename() != currentImage_ ){
431 texture.filename( currentImage_ );
434 int newImageId = imageStore().addImageFile(currentImage_);
435 texture.textureImageId( newImageId );
436 texData_->addManagedImageId( newImageId );
442 emit applyProperties(texData_, textureName_, id_ );
444 propChanged_ =
false;
447 if ( btn == QDialogButtonBox::Apply )
453 void texturePropertiesWidget::slotPropertiesChanged(
double ){
457 functionPlot_->setParameters(repeatBox->isChecked(), max_val->value(),
458 clampBox->isChecked(), clamp_min->value(), clamp_max->value(),
459 centerBox->isChecked(),
461 scaleBox->isChecked());
463 functionPlot_->replot();
DLLEXPORT void currentTextureDir(QDir _dir)
Sets the Path to the current texture-directory.
TexParameters parameters
Parameters of the texture.