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 (uint 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())
137 if ( textureList->invisibleRootItem()->childCount() == 0 ) {
138 QMessageBox msgBox(
this);
139 msgBox.setText(
"Cannot show Properties. No Textures available!");
145 textureLabel->setText(
"<B>Global Textures</B>");
147 textureLabel->setText(
"<B>Textures for object '" + _name +
"'</B>");
149 propChanged_ =
false;
151 if (activeItem == 0){
153 textureList->setCurrentItem( textureList->topLevelItem(0) );
154 textureChanged( textureList->topLevelItem(0), 0 );
157 textureList->setCurrentItem( activeItem );
158 textureChanged( activeItem, 0 );
164 void texturePropertiesWidget::textureAboutToChange(QTreeWidgetItem* _item,
int _column){
167 QMessageBox msgBox(
this);
168 msgBox.setText(
"The properties of the current texture have been changed.");
169 msgBox.setInformativeText(
"Do you want to apply these changes?");
170 msgBox.setStandardButtons(QMessageBox::Apply | QMessageBox::Discard );
171 msgBox.setDefaultButton(QMessageBox::Apply);
172 int ret = msgBox.exec();
174 if (ret == QMessageBox::Apply){
176 for (
int i=0; i < buttonBox->buttons().count(); i++)
177 if ( buttonBox->standardButton( buttonBox->buttons()[i] ) == QDialogButtonBox::Apply )
178 slotButtonBoxClicked( buttonBox->buttons()[i] );
180 textureList->setCurrentItem( _item );
181 textureChanged( _item,_column );
184 propChanged_ =
false;
186 textureList->setCurrentItem( _item );
187 textureChanged( _item,_column );
192 void texturePropertiesWidget::textureChanged(QTreeWidgetItem* _item,
int _column){
198 textureList->setCurrentItem( curItem_ );
211 textureName_ = _item->text(_column);
251 repeatBox->setChecked(texture.
parameters.repeat);
252 clampBox->setChecked(texture.
parameters.clamp);
253 centerBox->setChecked(texture.
parameters.center);
256 max_val->setValue( texture.
parameters.repeatMax );
257 clamp_min->setValue( texture.
parameters.clampMin );
258 clamp_max->setValue( texture.
parameters.clampMax );
260 switch (texture.type()) {
262 typeLabel->setText(
"Type: MultiTexture");
263 indexLabel->setEnabled(
true);
264 indexBox->setEnabled(
true);
266 indexBox->addItem(
"TODO");
269 typeLabel->setText(
"Type: HalfedgeBased");
270 indexLabel->setEnabled(
false);
271 indexBox->setEnabled(
false);
275 typeLabel->setText(
"Type: VertexBased");
276 indexLabel->setEnabled(
false);
277 indexBox->setEnabled(
false);
281 typeLabel->setText(
"Type: Environment Map");
282 indexLabel->setEnabled(
false);
283 indexBox->setEnabled(
false);
287 typeLabel->setText(
"Type: Unset");
288 indexLabel->setEnabled(
false);
289 indexBox->setEnabled(
false);
296 imageLabel->setPixmap(QPixmap::fromImage( imageStore().getImage(texture.textureImageId(),&ok) ));
299 std::cerr<< imageStore().error().toStdString();
302 imageLabel->setScaledContents(
true);
304 if ( texture.filename().startsWith(
"/") )
305 fileLabel->setText(
"File: " + texture.filename() );
307 fileLabel->setText(
"File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename() );
309 currentImage_ = texture.filename();
312 if ( texture.dimension() == 1 && id_ != -1) {
316 std::vector< double > coords;
318 emit getCoordinates1D(textureName_, id_, coords);
320 if ( ! coords.empty() ){
322 functionPlot_->setFunction( coords );
324 functionPlot_->setParameters(repeatBox->isChecked(), max_val->value(),
325 clampBox->isChecked(), clamp_min->value(), clamp_max->value(),
326 centerBox->isChecked(),
328 scaleBox->isChecked());
331 image_ = imageStore().getImage(texture.textureImageId(),&ok);
333 std::cerr << imageStore().error().toStdString();
337 functionPlot_->setImage( &image_ );
339 functionPlot_->replot();
345 propChanged_ =
false;
346 curItem_ = textureList->currentItem();
350 void texturePropertiesWidget::slotChangeImage()
353 QString fileName = QFileDialog::getOpenFileName(
this,
355 OpenFlipper::Options::currentTextureDirStr(),
356 tr(
"Images (*.png *.xpm *.jpg *.tga *.tif *.tiff *.bmp);;All Files (*.*)"));
358 if (QFile(fileName).exists()) {
359 QFileInfo fileInfo(fileName);
360 OpenFlipper::Options::currentTextureDir(fileInfo.absolutePath());
362 imageLabel->setPixmap(fileName);
363 imageLabel->setScaledContents(
true);
365 fileLabel->setText(
"File: " + fileName);
367 currentImage_ = fileName;
368 image_ = imageLabel->pixmap()->toImage();
371 functionPlot_->setImage(&image_);
372 functionPlot_->replot();
380 void texturePropertiesWidget::slotButtonBoxClicked(QAbstractButton* _button){
382 QDialogButtonBox::StandardButton btn = buttonBox->standardButton(_button);
384 if ( btn == QDialogButtonBox::Apply || btn == QDialogButtonBox::Ok){
387 bool changed =
false;
391 if ( texture.
parameters.repeat != repeatBox->isChecked() ){
392 texture.
parameters.repeat=repeatBox->isChecked();
395 if ( texture.
parameters.clamp != clampBox->isChecked() ){
396 texture.
parameters.clamp=clampBox->isChecked();
399 if ( texture.
parameters.center != centerBox->isChecked() ){
400 texture.
parameters.center=centerBox->isChecked();
403 if ( texture.
parameters.abs != absBox->isChecked() ){
407 if ( texture.
parameters.scale != scaleBox->isChecked() ){
408 texture.
parameters.scale=scaleBox->isChecked();
412 if ( texture.
parameters.repeatMax != max_val->value() ){
413 texture.
parameters.repeatMax = max_val->value();
417 if ( texture.
parameters.clampMin != clamp_min->value() ){
418 texture.
parameters.clampMin = clamp_min->value();
422 if ( texture.
parameters.clampMax != clamp_max->value() ){
423 texture.
parameters.clampMax = clamp_max->value();
427 if ( texture.filename() != currentImage_ ){
429 texture.filename( currentImage_ );
432 texture.textureImageId( imageStore().addImageFile(currentImage_) );
439 emit applyProperties(texData_, textureName_, id_ );
441 propChanged_ =
false;
444 if ( btn == QDialogButtonBox::Apply )
450 void texturePropertiesWidget::slotPropertiesChanged(
double ){
454 functionPlot_->setParameters(repeatBox->isChecked(), max_val->value(),
455 clampBox->isChecked(), clamp_min->value(), clamp_max->value(),
456 centerBox->isChecked(),
458 scaleBox->isChecked());
460 functionPlot_->replot();
std::vector< Texture > & textures()
Get reference to the texture vector.
TexParameters parameters
Parameters of the texture.
Texture & texture(QString _textureName)
Get the texture object.
bool textureExists(QString _textureName)
Check if a texture exists.