Commit 34980eb7 authored by Dirk Wilden's avatar Dirk Wilden

properties dialog now working again

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5666 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e86dc2a1
......@@ -635,10 +635,8 @@ void TextureControlPlugin::pluginsInitialized() {
// ================================================================================
// TODO : Settings dialog updates required to change global/local textures,...
settingsDialog_ = new texturePropertiesWidget(0);
connect(settingsDialog_->okButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesOk() ) );
connect(settingsDialog_->applyButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesApply() ) );
connect(settingsDialog_->cancelButton,SIGNAL(clicked()), this , SLOT (slotTexturePropertiesCancel() ) );
connect( settingsDialog_, SIGNAL( applyProperties(TextureData*,QString,int) ),
this, SLOT( applyDialogSettings(TextureData*,QString,int) ));
// ================================================================================
// Create action group and menu for global textures
......@@ -666,111 +664,80 @@ void TextureControlPlugin::pluginsInitialized() {
}
void TextureControlPlugin::updateDialog() {
std::cerr << "Not implemented : updateDialog" << std::endl;
// TODO : Check
// if ( textures_.size() == 0 )
// return;
//
// settingsDialog_->repeatBox->setChecked(textures_[textureid].repeat);
// settingsDialog_->clampBox->setChecked(textures_[textureid].clamp);
// settingsDialog_->centerBox->setChecked(textures_[textureid].center);
// settingsDialog_->absBox->setChecked(textures_[textureid].abs);
// QString tmp;
// tmp.setNum(textures_[textureid].max_val);
// settingsDialog_->max_val->setText( tmp );
// tmp.setNum(textures_[textureid].clamp_min);
// settingsDialog_->clamp_min->setText(tmp);
// tmp.setNum(textures_[textureid].clamp_max);
// settingsDialog_->clamp_max->setText(tmp);
//
// // update plot only when dimension is 1
// if ( textures_[textureid].dimension == 1) {
// std::vector< double > x,y;
//
// x.push_back(100.0);
// y.push_back(100.0);
//
// x.push_back(200.0);
// y.push_back(150.0);
//
// x.push_back(300.0);
// y.push_back(10.0);
//
// settingsDialog_->setOriginalData(x,y);
//
// // getOriginalHistogram();
//
// }
}
void TextureControlPlugin::slotSetTextureProperties() {
std::cerr << "Not implemented : slotSetTextureProperties" << std::endl;
// TODO : Check
// updateDialog();
// if ( textures_.size() == 0 )
// return;
//
// settingsDialog_->show();
}
void TextureControlPlugin::applyDialogSettings() {
std::cerr << "Not implemented : applyDialogSettings" << std::endl;
// TODO : Check
// if ( textures_.size() == 0 )
// return;
//
// int textureid = -1;
// for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
// if ( textures_[i].name == activeTexture_ ) {
// textureid = i;
// break;
// }
// }
//
// if (textureid == -1) {
// emit log(LOGERR,"Unable to get active Texture");
// }
//
// textures_[textureid].repeat=settingsDialog_->repeatBox->isChecked();
// textures_[textureid].clamp=settingsDialog_->clampBox->isChecked();
// textures_[textureid].center=settingsDialog_->centerBox->isChecked();
// textures_[textureid].abs=settingsDialog_->absBox->isChecked();
// textures_[textureid].scale=settingsDialog_->scaleBox->isChecked();
//
// QString tmp;
// tmp = settingsDialog_->max_val->text();
// textures_[textureid].max_val = tmp.toDouble();
//
// tmp = settingsDialog_->clamp_min->text();
// textures_[textureid].clamp_min = tmp.toDouble();
//
// tmp = settingsDialog_->clamp_max->text();
// textures_[textureid].clamp_max = tmp.toDouble();
//
// // Update the corresponding meshes
// for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)
// slotTextureUpdated( activeTexture_ , o_it->id() );
//
// emit updateView();
settingsDialog_->show( &globalTextures_, -1);
}
void TextureControlPlugin::slotTexturePropertiesOk() {
// TODO : Check
// applyDialogSettings();
// settingsDialog_->hide();
}
void TextureControlPlugin::applyDialogSettings(TextureData* _texData, QString _textureName, int _id) {
void TextureControlPlugin::slotTexturePropertiesApply() {
// TODO : Check
// applyDialogSettings();
}
if (_id != -1){
//local texture
if ( _texData->isEnabled(_textureName) ){
slotTextureUpdated( _textureName , _id );
emit updateView();
}else
_texData->texture( _textureName ).dirty = true;
void TextureControlPlugin::slotTexturePropertiesCancel() {
// TODO : Check
// settingsDialog_->hide();
}
} else {
// global texture
_texData->texture( _textureName ).dirty = true;
Texture& globalTexture = _texData->texture(_textureName);
// check if the local textures need to be updated
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it){
TextureData* texData = dynamic_cast< TextureData* > ( o_it->objectData(TEXTUREDATA) );
if ( texData != 0 && texData->textureExists(_textureName) ){
//overwrite local parameters
Texture& localTexture = texData->texture(_textureName);
bool changed = false;
if (localTexture.parameters.clamp != globalTexture.parameters.clamp){
localTexture.parameters.clamp = globalTexture.parameters.clamp;
changed = true;
}
if (localTexture.parameters.clamp_max != globalTexture.parameters.clamp_max){
localTexture.parameters.clamp_max = globalTexture.parameters.clamp_max;
changed = true;
}
if (localTexture.parameters.clamp_min != globalTexture.parameters.clamp_min){
localTexture.parameters.clamp_min = globalTexture.parameters.clamp_min;
changed = true;
}
if (localTexture.parameters.max_val != globalTexture.parameters.max_val){
localTexture.parameters.max_val = globalTexture.parameters.max_val;
changed = true;
}
if (localTexture.parameters.repeat != globalTexture.parameters.repeat){
localTexture.parameters.repeat = globalTexture.parameters.repeat;
changed = true;
}
if (localTexture.parameters.center != globalTexture.parameters.center){
localTexture.parameters.center = globalTexture.parameters.center;
changed = true;
}
if (localTexture.parameters.scale != globalTexture.parameters.scale){
localTexture.parameters.scale = globalTexture.parameters.scale;
changed = true;
}
// update if something has changed
if ( changed ){
if ( texData->isEnabled(_textureName) )
slotTextureUpdated( _textureName , o_it->id() );
else
texData->texture( _textureName ).dirty = true;
}
}
}
}
}
void TextureControlPlugin::slotTextureMenu(QAction* _action) {
// call existing function to switch the texture
......@@ -938,20 +905,22 @@ void TextureControlPlugin::slotUpdateContextMenu( int _objectId ) {
connect( actionGroup, SIGNAL( triggered( QAction * ) ),
this, SLOT( slotTextureContextMenu( QAction * ) ) );
QAction* action = actionGroup->addAction( "Texture Settings" );
contextMenu_->addAction( action );
contextMenu_->addSeparator();
for ( uint i = 0 ; i < texData->textures().size() ; ++i ) {
QAction* action = actionGroup->addAction( texData->textures()[i].name );
action = actionGroup->addAction( texData->textures()[i].name );
action->setCheckable(true);
if ( texData->textures()[i].enabled )
action->setChecked(true);
contextMenu_->addAction( action );
}
contextMenu_->addActions(actionGroup->actions());
}
......@@ -963,7 +932,31 @@ void TextureControlPlugin::slotTextureContextMenu( QAction * _action ) {
std::cerr << "TextureControlPlugin::slotTextureContextMenu : " << id << std::endl;
slotSwitchTexture( _action->text() , id );
if (_action->text() == "Texture Settings"){
BaseObjectData* obj;
if (! PluginFunctions::getObject( id , obj ) ) {
emit log(LOGERR,"Unable to get Object for id " + QString::number(id) );
return;
}
TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
if (texData == 0){
QMessageBox msgBox;
msgBox.setText("Cannot show Properties. No Textures available!");
msgBox.exec();
return;
} else {
settingsDialog_->show( texData, id, obj->name() );
}
} else {
slotSwitchTexture( _action->text() , id );
}
}
......
......@@ -163,11 +163,10 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
texturePropertiesWidget* settingsDialog_;
/// Set the active texture values to the values in the dialog box.
void applyDialogSettings();
private slots:
void applyDialogSettings(TextureData* _texData, QString _textureName, int _id);
/// Update the values in the Dialog box to the current ones
void updateDialog();
private:
/// Take a scalar value and return a clamped,... depending on texture settings
inline
......
......@@ -42,7 +42,7 @@ TextureData::TextureData(){
TextureData::~TextureData() {
}
/*
//-----------------------------------------------------------------------------------
/** \brief Check if a texture exists
......@@ -94,6 +94,7 @@ bool TextureData::enableTexture(QString _textureName, bool _exclusive)
textures_[i].enabled = false;
return true;
}
return false;
}
//-----------------------------------------------------------------------------------
......
......@@ -29,6 +29,9 @@
//
//=============================================================================
#ifndef TEXTUREDATA_HH
#define TEXTUREDATA_HH
#include <OpenFlipper/common/perObjectData.hh>
#include <QString>
......@@ -165,3 +168,4 @@ class TextureData : public PerObjectData
};
#endif //TEXTUREDATA_HH
\ No newline at end of file
......@@ -49,6 +49,24 @@ texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
{
setupUi(this);
connect(buttonBox, SIGNAL( clicked(QAbstractButton*) ), this , SLOT ( slotButtonBoxClicked(QAbstractButton*) ) );
connect(textureList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(textureChanged(QListWidgetItem*)) );
connect(textureList, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(textureAboutToChange(QListWidgetItem*)) );
//remember changes
connect(repeatBox, SIGNAL( clicked() ), this , SLOT ( slotPropertiesChanged() ) );
connect(clampBox, SIGNAL( clicked() ), this , SLOT ( slotPropertiesChanged() ) );
connect(centerBox, SIGNAL( clicked() ), this , SLOT ( slotPropertiesChanged() ) );
connect(absBox, SIGNAL( clicked() ), this , SLOT ( slotPropertiesChanged() ) );
connect(scaleBox, SIGNAL( clicked() ), this , SLOT ( slotPropertiesChanged() ) );
connect(max_val, SIGNAL( valueChanged(double) ), this , SLOT ( slotPropertiesChanged(double) ) );
connect(clamp_min, SIGNAL( valueChanged(double) ), this , SLOT ( slotPropertiesChanged(double) ) );
connect(clamp_max, SIGNAL( valueChanged(double) ), this , SLOT ( slotPropertiesChanged(double) ) );
texData_ = 0;
#ifdef QWT
QGridLayout* layout = new QGridLayout( originalData);
......@@ -83,6 +101,110 @@ texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
}
void texturePropertiesWidget::show(TextureData* _texData, int _id, QString _name){
texData_ = _texData;
id_ = _id;
textureList->clear();
for (uint i=0; i < texData_->textures().size(); i++)
textureList->addItem( texData_->textures()[i].name );
if ( textureList->count() == 0){
QMessageBox msgBox(this);
msgBox.setText("Cannot show Properties. No Textures available!");
msgBox.exec();
return;
}
if (id_ == -1)
textureLabel->setText("<B>Global Textures</B>");
else
textureLabel->setText("<B>Textures for object '" + _name + "'</B>");
textureList->setCurrentItem( textureList->item(0) );
textureChanged( textureList->item(0) );
propChanged_ = false;
QDialog::show();
}
void texturePropertiesWidget::textureAboutToChange(QListWidgetItem* _item){
if (propChanged_){
QMessageBox msgBox(this);
msgBox.setText("The properties of the current texture have been changed.");
msgBox.setInformativeText("Do you want to apply these changes?");
msgBox.setStandardButtons(QMessageBox::Apply | QMessageBox::Discard );
msgBox.setDefaultButton(QMessageBox::Apply);
int ret = msgBox.exec();
if (ret == QMessageBox::Apply){
//just hit the applyButton ;)
for (int i=0; i < buttonBox->buttons().count(); i++)
if ( buttonBox->standardButton( buttonBox->buttons()[i] ) == QDialogButtonBox::Apply )
slotButtonBoxClicked( buttonBox->buttons()[i] );
textureList->setCurrentItem( _item );
textureChanged( _item );
} else {
propChanged_ = false;
textureList->setCurrentItem( _item );
textureChanged( _item );
}
}
}
void texturePropertiesWidget::textureChanged(QListWidgetItem* _item){
//open changes for the last texture so switch back
if ( propChanged_ ){
textureList->setCurrentRow( curRow_ );
return;
}
if ( !texData_->textureExists( _item->text() ) )
return; //should not happen
textureName_ = _item->text();
//update the dialog
Texture& texture = texData_->texture(textureName_);
repeatBox->setChecked(texture.parameters.repeat);
clampBox->setChecked(texture.parameters.clamp);
centerBox->setChecked(texture.parameters.center);
absBox->setChecked(texture.parameters.abs);
max_val->setValue( texture.parameters.max_val );
clamp_min->setValue( texture.parameters.clamp_min );
clamp_max->setValue( texture.parameters.clamp_max );
// update plot only when dimension is 1
if ( texture.dimension == 1) {
std::vector< double > x,y;
x.push_back(100.0);
y.push_back(100.0);
x.push_back(200.0);
y.push_back(150.0);
x.push_back(300.0);
y.push_back(10.0);
setOriginalData(x,y);
}
propChanged_ = false;
curRow_ = textureList->currentRow();
}
void texturePropertiesWidget::setOriginalData(std::vector< double > _x, std::vector< double > _y ) {
#ifdef QWT
double minx = FLT_MIN;
......@@ -100,3 +222,67 @@ void texturePropertiesWidget::setOriginalData(std::vector< double > _x, std::vec
originalDataHistogram_->replot();
#endif
}
void texturePropertiesWidget::slotButtonBoxClicked(QAbstractButton* _button){
QDialogButtonBox::StandardButton btn = buttonBox->standardButton(_button);
if ( btn == QDialogButtonBox::Apply || btn == QDialogButtonBox::Ok){
//applySettings
bool changed = false;
Texture& texture = texData_->texture(textureName_);
if ( texture.parameters.repeat != repeatBox->isChecked() ){
texture.parameters.repeat=repeatBox->isChecked();
changed = true;
}
if ( texture.parameters.clamp != clampBox->isChecked() ){
texture.parameters.clamp=clampBox->isChecked();
changed = true;
}
if ( texture.parameters.center != centerBox->isChecked() ){
texture.parameters.center=centerBox->isChecked();
changed = true;
}
if ( texture.parameters.abs != absBox->isChecked() ){
texture.parameters.abs=absBox->isChecked();
changed = true;
}
if ( texture.parameters.scale != scaleBox->isChecked() ){
texture.parameters.scale=scaleBox->isChecked();
changed = true;
}
if ( texture.parameters.max_val != max_val->value() ){
texture.parameters.max_val = max_val->value();
changed = true;
}
if ( texture.parameters.clamp_min != clamp_min->value() ){
texture.parameters.clamp_min = clamp_min->value();
changed = true;
}
if ( texture.parameters.clamp_max != clamp_max->value() ){
texture.parameters.clamp_max = clamp_max->value();
changed = true;
}
//inform the plugin about the update
if (changed)
emit applyProperties(texData_, textureName_, id_ );
propChanged_ = false;
}
if ( btn == QDialogButtonBox::Apply )
return;
else
hide();
}
void texturePropertiesWidget::slotPropertiesChanged(double /*_value*/){
propChanged_ = true;
}
......@@ -33,6 +33,7 @@
#include "ui_textureProperties.hh"
#include "TextureData.hh"
#include <QtGui>
#ifdef QWT
......@@ -43,12 +44,35 @@ class texturePropertiesWidget : public QDialog, public Ui::Dialog
{
Q_OBJECT
signals:
void applyProperties(TextureData* _texData, QString _textureName, int _id);
public:
texturePropertiesWidget(QWidget *parent = 0);
void setOriginalData(std::vector< double > _x, std::vector< double > _y );
void show(TextureData* _texData, int _id, QString _name = "");
private slots:
void textureAboutToChange(QListWidgetItem* _item);
void textureChanged(QListWidgetItem* _item);
void slotButtonBoxClicked(QAbstractButton* _button);
void slotPropertiesChanged(double _value = 0.0);
private:
bool propChanged_;
int curRow_;
TextureData* texData_;
QString textureName_;
int id_;
#ifdef QWT
QwtPlot* originalDataHistogram_;
QwtPlotCurve histogramCurve_;
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>675</width>
<height>359</height>
<width>666</width>
<height>548</height>
</rect>
</property>
<property name="minimumSize" >
......@@ -24,166 +24,138 @@
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<layout class="QVBoxLayout" name="verticalLayout_4" >
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QCheckBox" name="repeatBox" >
<property name="text" >
<string>Repeat Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<widget class="QSplitter" name="splitter" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="" >
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QLabel" name="textureLabel" >
<property name="text" >
<string>Textures:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="textureList" >
<property name="alternatingRowColors" >
<bool>false</bool>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="" >
<layout class="QVBoxLayout" name="verticalLayout_3" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QLabel" name="label_3" >
<widget class="QCheckBox" name="repeatBox" >
<property name="text" >
<string>Max Value</string>
<string>Repeat Texture</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="max_val" />
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Maximum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="max_val" />
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
<widget class="QCheckBox" name="clampBox" >
<property name="text" >
<string>Clamp Texture</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Clamp Min</string>
<string>Minimum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_min" />
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Clamp Max</string>
<string>Maximum:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="clamp_max" />
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
<widget class="QCheckBox" name="centerBox" >
<property name="text" >
<string>Center</string>
</property>
<property name="margin" >
<number>0</number>
</widget>
</item>
<item>
<widget class="QCheckBox" name="absBox" >
<property name="text" >
<string>Use Absolute values</string>
</property>
<item>
<widget class="QLineEdit" name="clamp_min" />
</item>
<item>
<widget class="QLineEdit" name="clamp_max" />
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scaleBox" >
<property name="text" >
<string>Scale</string>
</property>
</widget>
</item>
</layout>
</item>
<item>