QtMaterialDialog.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS QtMaterialDialog - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 #include "QtMaterialDialog.hh"
00055 #include "../Scenegraph/MaterialNode.hh"
00056 
00057 #include <QCheckBox>
00058 #include <QLabel>
00059 #include <QPushButton>
00060 #include <QSpinBox>
00061 #include <QLayout>
00062 #include <QVariant>
00063 #include <QToolTip>
00064 #include <QColorDialog>
00065 #include <QSlider>
00066 
00067 
00068 //== NAMESPACES ==============================================================
00069 
00070 
00071 namespace ACG {
00072 namespace QtWidgets {
00073 
00074 
00075 //== IMPLEMENTATION ==========================================================
00076 
00077 
00078 QtMaterialDialog::QtMaterialDialog( QWidget                  * _parent,
00079                                                         SceneGraph::MaterialNode * _node )
00080   : QDialog( _parent ),
00081     node_(_node)
00082 {
00083   ui_.setupUi( this );
00084   //  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
00085 
00086   // get initial values from node
00087   color_           = bak_color_           = node_->base_color();
00088   ambient_         = bak_ambient_         = node_->ambient_color();
00089   diffuse_         = bak_diffuse_         = node_->diffuse_color();
00090   specular_        = bak_specular_        = node_->specular_color();
00091   shine_           = bak_shine_           = node_->shininess();
00092   point_size_      = bak_point_size_      = node_->point_size();
00093   line_width_      = bak_line_width_      = node_->line_width();
00094   round_points_    = bak_round_points_    = node_->round_points();
00095   line_smooth_     = bak_line_smooth_     = node_->line_smooth();
00096   backfaceCulling_ = bak_backfaceCulling_ = node_->backface_culling();
00097   alphaTest_       = bak_alphaTest_       = node_->alpha_test();
00098   alphaValue_      = bak_alphaValue_      = node_->alpha_value();
00099   blending_        = bak_blending_        = node_->blending();
00100   blendParam1_     = bak_blendParam1_     = node_->blending_param1();
00101   blendParam2_     = bak_blendParam2_     = node_->blending_param2();
00102   colorMaterial_   = bak_colorMaterial_   = node_->colorMaterial();
00103   multiSampling_   = bak_multiSampling_   = node_->multiSampling();
00104 
00105   baseColorActive_       = bak_baseColorActive_       = node_->applyProperties() & SceneGraph::MaterialNode::BaseColor;
00106   materialActive_        = bak_materialActive_        = node_->applyProperties() & SceneGraph::MaterialNode::Material;
00107   pointSizeActive_       = bak_pointSizeActive_       = node_->applyProperties() & SceneGraph::MaterialNode::PointSize;
00108   lineWidthActive_       = bak_lineWidthActive_       = node_->applyProperties() & SceneGraph::MaterialNode::LineWidth;
00109   roundPointsActive_     = bak_roundPointsActive_     = node_->applyProperties() & SceneGraph::MaterialNode::RoundPoints;
00110   lineSmoothActive_      = bak_lineSmoothActive_      = node_->applyProperties() & SceneGraph::MaterialNode::LineSmooth;
00111   alphaTestActive_       = bak_alphaTestActive_       = node_->applyProperties() & SceneGraph::MaterialNode::AlphaTest;
00112   blendingActive_        = bak_blendingActive_        = node_->applyProperties() & SceneGraph::MaterialNode::Blending;
00113   backfaceCullingActive_ = bak_backfaceCullingActive_ = node_->applyProperties() & SceneGraph::MaterialNode::BackFaceCulling;
00114   colorMaterialActive_   = bak_colorMaterialActive_   = node_->applyProperties() & SceneGraph::MaterialNode::ColorMaterial;
00115   multiSamplingActive_   = bak_multiSamplingActive_   = node_->applyProperties() & SceneGraph::MaterialNode::MultiSampling;
00116 
00117   setButtonColor( ui_.baseColorButton, color_ );
00118   setButtonColor( ui_.ambientColorButton, ambient_ );
00119   setButtonColor( ui_.diffuseColorButton, diffuse_ );
00120   setButtonColor( ui_.specularColorButton, specular_ );
00121 
00122   ui_.shininessSlider->setValue((int)shine_);
00123   ui_.pointSizeSpinBox->setValue((int)point_size_);
00124   ui_.lineWidthSpinBox->setValue((int)line_width_);
00125   ui_.roundPointsCheckBox->setChecked(round_points_);
00126   ui_.lineSmoothCheckBox->setChecked(line_smooth_);
00127   ui_.backfaceCulling->setChecked( backfaceCulling_ );
00128   ui_.alphaTest->setChecked( alphaTest_ );
00129   ui_.alpha->setValue((int) alphaValue_ * 100.0f );
00130   ui_.colorMaterial->setChecked( colorMaterial_ );
00131   ui_.multiSampling->setChecked( multiSampling_ );
00132   ui_.blending->setChecked( blending_ );
00133 
00134   for (int i=0; i < ui_.blendParam1->count(); i++)
00135     if ( ui_.blendParam1->itemText(i) == paramToStr(blendParam1_) )
00136       ui_.blendParam1->setCurrentIndex( i );
00137 
00138   for (int i=0; i < ui_.blendParam2->count(); i++)
00139     if ( ui_.blendParam2->itemText(i) == paramToStr(blendParam2_) )
00140       ui_.blendParam2->setCurrentIndex( i );
00141 
00142   applyProperties_ = node_->applyProperties();
00143 
00144   ui_.baseColorActive->setChecked( baseColorActive_ );
00145   ui_.materialActive->setChecked( materialActive_ );
00146   ui_.pointSizeActive->setChecked( pointSizeActive_ );
00147   ui_.lineWidthActive->setChecked( lineWidthActive_ );
00148   ui_.roundPointsActive->setChecked( roundPointsActive_ );
00149   ui_.lineSmoothActive->setChecked( lineSmoothActive_ );
00150   ui_.alphaTestActive->setChecked( alphaTestActive_ );
00151   ui_.blendingActive->setChecked( blendingActive_ );
00152   ui_.backfaceCullingActive->setChecked( backfaceCullingActive_ );
00153   ui_.colorMaterialActive->setChecked( colorMaterialActive_ );
00154   ui_.multiSamplingActive->setChecked( multiSamplingActive_ );
00155 
00156   connect( ui_.baseColorButton,     SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
00157   connect( ui_.ambientColorButton,  SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
00158   connect( ui_.diffuseColorButton,  SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
00159   connect( ui_.specularColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
00160   connect( ui_.shininessSlider,     SIGNAL( sliderPressed() ), this, SLOT( enableProperty() ) );
00161   connect( ui_.pointSizeSpinBox,    SIGNAL( valueChanged(int) ), this, SLOT( enableProperty(int) ) );
00162   connect( ui_.lineWidthSpinBox,    SIGNAL( valueChanged(int) ), this, SLOT( enableProperty(int) ) );
00163   connect( ui_.roundPointsCheckBox, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00164   connect( ui_.lineSmoothCheckBox,  SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00165   connect( ui_.backfaceCulling,     SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00166   connect( ui_.alphaTest,           SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00167   connect( ui_.blending,            SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00168   connect( ui_.colorMaterial,       SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00169   connect( ui_.multiSampling,       SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
00170 
00171   connect( ui_.baseColorButton, SIGNAL( clicked() ),
00172            this, SLOT( changeBaseColor() ) );
00173   connect( ui_.ambientColorButton, SIGNAL( clicked() ),
00174            this, SLOT( changeAmbientColor() ) );
00175   connect( ui_.diffuseColorButton, SIGNAL( clicked() ),
00176            this, SLOT( changeDiffuseColor() ) );
00177   connect( ui_.specularColorButton, SIGNAL( clicked() ),
00178            this, SLOT( changeSpecularColor() ) );
00179   connect( ui_.shininessSlider, SIGNAL( sliderMoved(int) ),
00180            this, SLOT( changeShine(int) ) );
00181 
00182   connect( ui_.pointSizeSpinBox, SIGNAL( valueChanged(int) ),
00183            this, SLOT( changePointSize(int) ) );
00184   connect( ui_.lineWidthSpinBox, SIGNAL( valueChanged(int) ),
00185            this, SLOT( changeLineWidth(int) ) );
00186   connect( ui_.roundPointsCheckBox, SIGNAL( toggled(bool) ),
00187            this, SLOT( changeRoundPoints(bool) ) );
00188   connect( ui_.lineSmoothCheckBox, SIGNAL( toggled(bool) ),
00189       this, SLOT( changeLineSmooth(bool) ) );
00190   connect( ui_.backfaceCulling, SIGNAL( toggled(bool) ),
00191      this, SLOT( changeBackfaceCulling(bool) ) );
00192   connect( ui_.alphaTest, SIGNAL( toggled(bool) ),
00193      this, SLOT( changeAlphaTest(bool) ) );
00194   connect( ui_.alpha, SIGNAL( valueChanged(int) ),
00195      this, SLOT( changeAlphaValue(int) ) );
00196   connect( ui_.colorMaterial, SIGNAL( toggled(bool) ),
00197      this, SLOT( changeColorMaterial(bool) ) );
00198   connect( ui_.multiSampling, SIGNAL( toggled(bool) ),
00199      this, SLOT( changeMultiSampling(bool) ) );
00200   connect( ui_.blending, SIGNAL( toggled(bool) ),
00201      this, SLOT( changeBlending(bool) ) );
00202   connect( ui_.blendParam1, SIGNAL( currentIndexChanged(const QString&) ),
00203      this, SLOT( changeBlendingParam1(const QString&) ) );
00204   connect( ui_.blendParam2, SIGNAL( currentIndexChanged(const QString&) ),
00205      this, SLOT( changeBlendingParam2(const QString&) ) );
00206 
00207 
00208   connect( ui_.baseColorActive, SIGNAL( toggled(bool) ),
00209      this, SLOT( changeActive(bool) ) );
00210   connect( ui_.materialActive, SIGNAL( toggled(bool) ),
00211      this, SLOT( changeActive(bool) ) );
00212   connect( ui_.pointSizeActive, SIGNAL( toggled(bool) ),
00213      this, SLOT( changeActive(bool) ) );
00214   connect( ui_.lineWidthActive, SIGNAL( toggled(bool) ),
00215      this, SLOT( changeActive(bool) ) );
00216   connect( ui_.roundPointsActive, SIGNAL( toggled(bool) ),
00217      this, SLOT( changeActive(bool) ) );
00218   connect( ui_.lineSmoothActive, SIGNAL( toggled(bool) ),
00219      this, SLOT( changeActive(bool) ) );
00220   connect( ui_.alphaTestActive, SIGNAL( toggled(bool) ),
00221      this, SLOT( changeActive(bool) ) );
00222   connect( ui_.blendingActive, SIGNAL( toggled(bool) ),
00223      this, SLOT( changeActive(bool) ) );
00224   connect( ui_.backfaceCullingActive, SIGNAL( toggled(bool) ),
00225      this, SLOT( changeActive(bool) ) );
00226   connect( ui_.colorMaterialActive, SIGNAL( toggled(bool) ),
00227      this, SLOT( changeActive(bool) ) );
00228   connect( ui_.multiSamplingActive, SIGNAL( toggled(bool) ),
00229      this, SLOT( changeActive(bool) ) );
00230 
00231   connect( ui_.alphaTest,  SIGNAL( toggled(bool) ),
00232            ui_.alpha,        SLOT( setEnabled(bool) ) );
00233   connect( ui_.blending,  SIGNAL( toggled(bool) ),
00234            ui_.blendParam1,        SLOT( setEnabled(bool) ) );
00235   connect( ui_.blending,  SIGNAL( toggled(bool) ),
00236            ui_.blendParam2,        SLOT( setEnabled(bool) ) );
00237 
00238 
00239   ui_.alpha->setEnabled( ui_.alphaTest->isChecked() );
00240   ui_.blendParam1->setEnabled( ui_.blending->isChecked() );
00241   ui_.blendParam2->setEnabled( ui_.blending->isChecked() );
00242 
00243   ui_.baseColorActive->setChecked(baseColorActive_);
00244   ui_.materialActive->setChecked(materialActive_);
00245   ui_.pointSizeActive->setChecked(pointSizeActive_);
00246   ui_.lineWidthActive->setChecked(lineWidthActive_);
00247   ui_.roundPointsActive->setChecked(roundPointsActive_);
00248   ui_.lineWidthActive->setChecked(lineWidthActive_);
00249   ui_.alphaTestActive->setChecked(alphaTestActive_);
00250   ui_.blendingActive->setChecked(blendingActive_);
00251   ui_.backfaceCullingActive->setChecked(backfaceCullingActive_);
00252   ui_.colorMaterialActive->setChecked(colorMaterialActive_);
00253   ui_.multiSamplingActive->setChecked(multiSamplingActive_);
00254 
00255   connect( ui_.okButton, SIGNAL( clicked() ),
00256            this, SLOT( accept() ) );
00257   connect( ui_.cancelButton, SIGNAL( clicked() ),
00258            this, SLOT( reject() ) );
00259 
00260   layout()->setSizeConstraint( QLayout::SetFixedSize );
00261 }
00262 
00263 
00264 //-----------------------------------------------------------------------------
00265 
00266 
00267 void
00268 QtMaterialDialog::setButtonColor( QPushButton * _button,
00269                                   const Vec4f & _color )
00270 {
00271   QPalette p( _button->palette() );
00272   p.setColor( QPalette::Button, convertColor( _color ) );
00273   _button->setPalette( p );
00274 }
00275 
00276 
00277 //-----------------------------------------------------------------------------
00278 
00279 
00280 QColor
00281 QtMaterialDialog::convertColor( Vec4f _color)
00282 {
00283  return QColor ((int)(_color[0]*255.0),
00284                 (int)(_color[1]*255.0),
00285                 (int)(_color[2]*255.0),
00286                 (int)(_color[3]*255.0));
00287 }
00288 
00289 
00290 //-----------------------------------------------------------------------------
00291 
00292 
00293 Vec4f
00294 QtMaterialDialog::convertColor( QColor _color)
00295 {
00296   return Vec4f (_color.redF(),
00297                           _color.greenF(),
00298                           _color.blueF(),
00299                 _color.alphaF() );
00300 }
00301 
00302 
00303 //-----------------------------------------------------------------------------
00304 
00305 
00306 void QtMaterialDialog::reject()
00307 {
00308   undoChanges();
00309   QDialog::reject();
00310 }
00311 
00312 
00313 //-----------------------------------------------------------------------------
00314 
00315 
00316 void QtMaterialDialog::applyChanges()
00317 {
00318 
00319   unsigned int properties = 0;
00320 
00321   if (baseColorActive_) properties = properties | SceneGraph::MaterialNode::BaseColor;
00322   if (materialActive_) properties = properties | SceneGraph::MaterialNode::Material;
00323   if (pointSizeActive_) properties = properties | SceneGraph::MaterialNode::PointSize;
00324   if (lineWidthActive_) properties = properties | SceneGraph::MaterialNode::LineWidth;
00325   if (roundPointsActive_) properties = properties | SceneGraph::MaterialNode::RoundPoints;
00326   if (lineSmoothActive_) properties = properties | SceneGraph::MaterialNode::LineSmooth;
00327   if (alphaTestActive_) properties = properties | SceneGraph::MaterialNode::AlphaTest;
00328   if (blendingActive_) properties = properties | SceneGraph::MaterialNode::Blending;
00329   if (backfaceCullingActive_) properties = properties | SceneGraph::MaterialNode::BackFaceCulling;
00330   if (colorMaterialActive_) properties = properties | SceneGraph::MaterialNode::ColorMaterial;
00331   if (multiSamplingActive_) properties = properties | SceneGraph::MaterialNode::MultiSampling;
00332 
00333   node_->applyProperties(properties);
00334 
00335   node_->set_base_color(color_);
00336   node_->set_ambient_color(ambient_);
00337   node_->set_diffuse_color(diffuse_);
00338   node_->set_specular_color(specular_);
00339   node_->set_shininess(shine_);
00340   node_->set_point_size(point_size_);
00341   node_->set_line_width(line_width_);
00342   node_->set_round_points(round_points_);
00343   node_->set_line_smooth(line_smooth_);
00344 
00345   if(backfaceCulling_)
00346     node_->enable_backface_culling();
00347   else
00348     node_->disable_backface_culling();
00349 
00350   if(alphaTest_)
00351     node_->enable_alpha_test( alphaValue_ );
00352   else
00353     node_->disable_alpha_test();
00354 
00355   if(blending_)
00356     node_->enable_blending( blendParam1_, blendParam2_ );
00357   else
00358     node_->disable_blending();
00359 
00360   if ( colorMaterial_ )
00361     node_->enable_color_material();
00362   else
00363     node_->disable_color_material();
00364 
00365   if ( multiSampling_ )
00366     node_->enable_multisampling();
00367   else
00368     node_->disable_multisampling();
00369 
00370   // this is not optimal !
00371   if(round_points_ || line_smooth_ )
00372     node_->enable_alpha_test(0.5);
00373   else
00374     node_->disable_alpha_test();
00375 
00376   setButtonColor( ui_.diffuseColorButton, diffuse_ );
00377   setButtonColor( ui_.ambientColorButton, ambient_ );
00378   setButtonColor( ui_.specularColorButton, specular_ );
00379   setButtonColor( ui_.baseColorButton, color_ );
00380 
00381   emit signalNodeChanged(node_);
00382 }
00383 
00384 
00385 //-----------------------------------------------------------------------------
00386 
00387 
00388 void QtMaterialDialog::undoChanges()
00389 {
00390 
00391   unsigned int properties = 0;
00392 
00393   if (bak_baseColorActive_) properties = properties | SceneGraph::MaterialNode::BaseColor;
00394   if (bak_materialActive_) properties = properties | SceneGraph::MaterialNode::Material;
00395   if (bak_pointSizeActive_) properties = properties | SceneGraph::MaterialNode::PointSize;
00396   if (bak_lineWidthActive_) properties = properties | SceneGraph::MaterialNode::LineWidth;
00397   if (bak_roundPointsActive_) properties = properties | SceneGraph::MaterialNode::RoundPoints;
00398   if (bak_lineSmoothActive_) properties = properties | SceneGraph::MaterialNode::LineSmooth;
00399   if (bak_alphaTestActive_) properties = properties | SceneGraph::MaterialNode::AlphaTest;
00400   if (bak_blendingActive_) properties = properties | SceneGraph::MaterialNode::Blending;
00401   if (bak_backfaceCullingActive_) properties = properties | SceneGraph::MaterialNode::BackFaceCulling;
00402   if (bak_colorMaterialActive_) properties = properties | SceneGraph::MaterialNode::ColorMaterial;
00403   if (bak_multiSampling_) properties = properties | SceneGraph::MaterialNode::MultiSampling;
00404 
00405   node_->applyProperties(properties);
00406 
00407   node_->set_base_color(bak_color_);
00408   node_->set_ambient_color(bak_ambient_);
00409   node_->set_diffuse_color(bak_diffuse_);
00410   node_->set_specular_color(bak_specular_);
00411   node_->set_shininess(bak_shine_);
00412   node_->set_point_size(bak_point_size_);
00413   node_->set_line_width(bak_line_width_);
00414   node_->set_round_points(bak_round_points_);
00415   node_->set_line_smooth(bak_line_smooth_);
00416 
00417   if(bak_backfaceCulling_)
00418     node_->enable_backface_culling();
00419   else
00420     node_->disable_backface_culling();
00421 
00422   if(bak_alphaTest_)
00423     node_->enable_alpha_test( bak_alphaValue_ );
00424   else
00425     node_->disable_alpha_test();
00426 
00427   if(bak_blending_)
00428     node_->enable_blending( bak_blendParam1_, bak_blendParam2_ );
00429   else
00430     node_->disable_blending();
00431 
00432   if ( bak_colorMaterial_ )
00433     node_->enable_color_material();
00434   else
00435     node_->disable_color_material();
00436 
00437   if ( bak_multiSampling_ )
00438     node_->enable_multisampling();
00439   else
00440     node_->disable_multisampling();
00441 
00442   setButtonColor( ui_.diffuseColorButton, diffuse_ );
00443   setButtonColor( ui_.ambientColorButton, ambient_ );
00444   setButtonColor( ui_.specularColorButton, specular_ );
00445   setButtonColor( ui_.baseColorButton, color_ );
00446 
00447   emit signalNodeChanged(node_);
00448 }
00449 
00450 
00451 //-----------------------------------------------------------------------------
00452 
00453 
00454 void QtMaterialDialog::changeDiffuseColor()
00455 {
00456   bool* ok = 0;
00457 
00458   QColor newColor = QColor( QColorDialog::getRgba(convertColor(diffuse_).rgba(), ok, this));
00459 
00460   if( newColor.isValid())
00461   {
00462     diffuse_ = convertColor( newColor );
00463     applyChanges();
00464   }
00465 }
00466 
00467 
00468 //-----------------------------------------------------------------------------
00469 
00470 
00471 void QtMaterialDialog::changeAmbientColor()
00472 {
00473   bool* ok = 0;
00474 
00475   QColor newColor = QColor( QColorDialog::getRgba(convertColor(ambient_).rgba(), ok, this));
00476 
00477   if( newColor.isValid())
00478   {
00479     ambient_ = convertColor( newColor );
00480     applyChanges();
00481   }
00482 }
00483 
00484 
00485 //-----------------------------------------------------------------------------
00486 
00487 
00488 void QtMaterialDialog::changeSpecularColor()
00489 {
00490   bool* ok = 0;
00491 
00492   QColor newColor = QColor( QColorDialog::getRgba(convertColor(specular_).rgba(), ok, this));
00493 
00494   if( newColor.isValid())
00495   {
00496     specular_ = convertColor( newColor );
00497     applyChanges();
00498   }
00499 }
00500 
00501 
00502 //-----------------------------------------------------------------------------
00503 
00504 
00505 void QtMaterialDialog::changeBaseColor()
00506 {
00507   bool* ok = 0;
00508 
00509   QColor newColor = QColor( QColorDialog::getRgba(convertColor(color_).rgba(), ok, this));
00510 
00511   if( newColor.isValid())
00512   {
00513     color_ = convertColor( newColor );
00514     applyChanges();
00515   }
00516 }
00517 
00518 
00519 //-----------------------------------------------------------------------------
00520 
00521 
00522 void
00523 QtMaterialDialog::changeShine(int _new)
00524 {
00525   shine_      = _new;
00526   applyChanges();
00527 }
00528 
00529 
00530 //-----------------------------------------------------------------------------
00531 
00532 
00533 void
00534 QtMaterialDialog::changePointSize(int _new)
00535 {
00536   point_size_ = _new;
00537   applyChanges();
00538 }
00539 
00540 
00541 //-----------------------------------------------------------------------------
00542 
00543 
00544 void
00545 QtMaterialDialog::changeLineWidth(int _new)
00546 {
00547   line_width_ = _new;
00548   applyChanges();
00549 }
00550 
00551 
00552 //-----------------------------------------------------------------------------
00553 
00554 
00555 void
00556 QtMaterialDialog::changeRoundPoints(bool _b)
00557 {
00558   round_points_ = (bool)_b;
00559   applyChanges();
00560 }
00561 
00562 //-----------------------------------------------------------------------------
00563 
00564 
00565 void
00566 QtMaterialDialog::changeLineSmooth(bool _b)
00567 {
00568   line_smooth_ = (bool)_b;
00569   applyChanges();
00570 }
00571 
00572 //-----------------------------------------------------------------------------
00573 
00574 
00575 void
00576 QtMaterialDialog::changeBackfaceCulling(bool _b)
00577 {
00578   backfaceCulling_ = (bool)_b;
00579   applyChanges();
00580 }
00581 
00582 //-----------------------------------------------------------------------------
00583 
00584 
00585 void
00586 QtMaterialDialog::changeAlphaTest(bool _b)
00587 {
00588   alphaTest_ = (bool)_b;
00589   applyChanges();
00590 }
00591 
00592 //-----------------------------------------------------------------------------
00593 
00594 void
00595 QtMaterialDialog::changeColorMaterial(bool _b)
00596 {
00597   colorMaterial_ = (bool)_b;
00598   applyChanges();
00599 }
00600 
00601 //-----------------------------------------------------------------------------
00602 
00603 void
00604 QtMaterialDialog::changeMultiSampling(bool _b)
00605 {
00606   multiSampling_ = (bool)_b;
00607   applyChanges();
00608 }
00609 
00610 //-----------------------------------------------------------------------------
00611 
00612 void
00613 QtMaterialDialog::changeAlphaValue(int _new)
00614 {
00615   alphaValue_ = _new / 100.0f;
00616   applyChanges();
00617 }
00618 
00619 //-----------------------------------------------------------------------------
00620 
00621 
00622 void
00623 QtMaterialDialog::changeBlending(bool _b)
00624 {
00625   blending_ = (bool)_b;
00626   applyChanges();
00627 }
00628 
00629 //-----------------------------------------------------------------------------
00630 
00631 void
00632 QtMaterialDialog::changeBlendingParam1(const QString& _name)
00633 {
00634   if      (_name == "GL_ZERO")                     blendParam1_ = GL_ZERO;
00635   else if (_name == "GL_ONE")                      blendParam1_ = GL_ONE;
00636   else if (_name == "GL_SRC_COLOR")                blendParam1_ = GL_SRC_COLOR;
00637   else if (_name == "GL_ONE_MINUS_SRC_COLOR")      blendParam1_ = GL_ONE_MINUS_SRC_COLOR;
00638   else if (_name == "GL_DST_COLOR")                blendParam1_ = GL_DST_COLOR;
00639   else if (_name == "GL_ONE_MINUS_DST_COLOR")      blendParam1_ = GL_ONE_MINUS_DST_COLOR;
00640   else if (_name == "GL_ONE_MINUS_SRC_ALPHA")      blendParam1_ = GL_ONE_MINUS_SRC_ALPHA;
00641   else if (_name == "GL_DST_ALPHA")                blendParam1_ = GL_DST_ALPHA;
00642   else if (_name == "GL_ONE_MINUS_DST_ALPHA")      blendParam1_ = GL_ONE_MINUS_DST_ALPHA;
00643   else if (_name == "GL_CONSTANT_COLOR")           blendParam1_ = GL_CONSTANT_COLOR;
00644   else if (_name == "GL_ONE_MINUS_CONSTANT_COLOR") blendParam1_ = GL_ONE_MINUS_CONSTANT_COLOR;
00645   else if (_name == "GL_CONSTANT_ALPHA")           blendParam1_ = GL_CONSTANT_ALPHA;
00646   else if (_name == "GL_ONE_MINUS_CONSTANT_ALPHA") blendParam1_ = GL_ONE_MINUS_CONSTANT_ALPHA;
00647   else{
00648     std::cerr << "Blending Param unknown!" << std::endl;
00649     return;
00650   }
00651 
00652   applyChanges();
00653 }
00654 
00655 //-----------------------------------------------------------------------------
00656 
00657 void
00658 QtMaterialDialog::changeBlendingParam2(const QString& _name)
00659 {
00660   if      (_name == "GL_ZERO")                     blendParam2_ = GL_ZERO;
00661   else if (_name == "GL_ONE")                      blendParam2_ = GL_ONE;
00662   else if (_name == "GL_SRC_COLOR")                blendParam2_ = GL_SRC_COLOR;
00663   else if (_name == "GL_ONE_MINUS_SRC_COLOR")      blendParam2_ = GL_ONE_MINUS_SRC_COLOR;
00664   else if (_name == "GL_DST_COLOR")                blendParam2_ = GL_DST_COLOR;
00665   else if (_name == "GL_ONE_MINUS_DST_COLOR")      blendParam2_ = GL_ONE_MINUS_DST_COLOR;
00666   else if (_name == "GL_ONE_MINUS_SRC_ALPHA")      blendParam2_ = GL_ONE_MINUS_SRC_ALPHA;
00667   else if (_name == "GL_DST_ALPHA")                blendParam2_ = GL_DST_ALPHA;
00668   else if (_name == "GL_ONE_MINUS_DST_ALPHA")      blendParam2_ = GL_ONE_MINUS_DST_ALPHA;
00669   else if (_name == "GL_CONSTANT_COLOR")           blendParam2_ = GL_CONSTANT_COLOR;
00670   else if (_name == "GL_ONE_MINUS_CONSTANT_COLOR") blendParam2_ = GL_ONE_MINUS_CONSTANT_COLOR;
00671   else if (_name == "GL_CONSTANT_ALPHA")           blendParam2_ = GL_CONSTANT_ALPHA;
00672   else if (_name == "GL_ONE_MINUS_CONSTANT_ALPHA") blendParam2_ = GL_ONE_MINUS_CONSTANT_ALPHA;
00673   else{
00674     std::cerr << "Blending Param unknown!" << std::endl;
00675     return;
00676   }
00677 
00678   applyChanges();
00679 }
00680 
00681 //-----------------------------------------------------------------------------
00682 
00683 void
00684 QtMaterialDialog::changeActive(bool /*toggle*/)
00685 {
00686 
00687   baseColorActive_       = ui_.baseColorActive->isChecked();
00688   materialActive_        = ui_.materialActive->isChecked();
00689   pointSizeActive_       = ui_.pointSizeActive->isChecked();
00690   lineWidthActive_       = ui_.lineWidthActive->isChecked();
00691   roundPointsActive_     = ui_.roundPointsActive->isChecked();
00692   lineSmoothActive_      = ui_.lineSmoothActive->isChecked();
00693   blendingActive_        = ui_.blendingActive->isChecked();
00694   backfaceCullingActive_ = ui_.backfaceCullingActive->isChecked();
00695   colorMaterialActive_   = ui_.colorMaterialActive->isChecked();
00696   multiSamplingActive_   = ui_.multiSamplingActive->isChecked();
00697 
00698   applyChanges();
00699 }
00700 
00701 //-----------------------------------------------------------------------------
00702 
00703 void
00704 QtMaterialDialog::enableProperty(int /*i*/)
00705 {
00706   if      (sender() == ui_.baseColorButton)     ui_.baseColorActive->setChecked( true );
00707   else if (sender() == ui_.ambientColorButton)  ui_.materialActive->setChecked( true );
00708   else if (sender() == ui_.diffuseColorButton)  ui_.materialActive->setChecked( true );
00709   else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked( true );
00710   else if (sender() == ui_.shininessSlider)     ui_.materialActive->setChecked( true );
00711   else if (sender() == ui_.pointSizeSpinBox)    ui_.pointSizeActive->setChecked( true );
00712   else if (sender() == ui_.lineWidthSpinBox)    ui_.lineWidthActive->setChecked( true );
00713   else if (sender() == ui_.roundPointsCheckBox) ui_.roundPointsActive->setChecked( true );
00714   else if (sender() == ui_.lineSmoothCheckBox)  ui_.lineSmoothActive->setChecked( true );
00715   else if (sender() == ui_.backfaceCulling)     ui_.backfaceCullingActive->setChecked( true );
00716   else if (sender() == ui_.alphaTest)           ui_.alphaTestActive->setChecked( true );
00717   else if (sender() == ui_.blending)            ui_.blendingActive->setChecked( true );
00718   else if (sender() == ui_.colorMaterial)       ui_.colorMaterialActive->setChecked( true );
00719   else if (sender() == ui_.multiSampling)       ui_.multiSamplingActive->setChecked( true );
00720 }
00721 
00722 //-----------------------------------------------------------------------------
00723 
00724 void
00725 QtMaterialDialog::enableProperty()
00726 {
00727 
00728   if      (sender() == ui_.baseColorButton)     ui_.baseColorActive->setChecked( true );
00729   else if (sender() == ui_.ambientColorButton)  ui_.materialActive->setChecked( true );
00730   else if (sender() == ui_.diffuseColorButton)  ui_.materialActive->setChecked( true );
00731   else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked( true );
00732   else if (sender() == ui_.shininessSlider)     ui_.materialActive->setChecked( true );
00733   else if (sender() == ui_.pointSizeSpinBox)    ui_.pointSizeActive->setChecked( true );
00734   else if (sender() == ui_.lineWidthSpinBox)    ui_.lineWidthActive->setChecked( true );
00735   else if (sender() == ui_.roundPointsCheckBox) ui_.roundPointsActive->setChecked( true );
00736   else if (sender() == ui_.lineSmoothCheckBox)  ui_.lineSmoothActive->setChecked( true );
00737   else if (sender() == ui_.backfaceCulling)     ui_.backfaceCullingActive->setChecked( true );
00738   else if (sender() == ui_.alphaTest)           ui_.alphaTestActive->setChecked( true );
00739   else if (sender() == ui_.blending)            ui_.blendingActive->setChecked( true );
00740   else if (sender() == ui_.colorMaterial)       ui_.colorMaterialActive->setChecked( true );
00741   else if (sender() == ui_.multiSampling)       ui_.multiSamplingActive->setChecked( true );
00742 
00743 }
00744 
00745 //-----------------------------------------------------------------------------
00746 
00747 QString QtMaterialDialog::paramToStr(GLenum _param)
00748 {
00749   if      (_param == GL_ZERO)                     return "GL_ZERO";
00750   else if (_param == GL_ONE)                      return "GL_ONE";
00751   else if (_param == GL_SRC_COLOR)                return "GL_SRC_COLOR";
00752   else if (_param == GL_ONE_MINUS_SRC_COLOR)      return "GL_ONE_MINUS_SRC_COLOR";
00753   else if (_param == GL_DST_COLOR)                return "GL_DST_COLOR";
00754   else if (_param == GL_ONE_MINUS_DST_COLOR)      return "GL_ONE_MINUS_DST_COLOR";
00755   else if (_param == GL_ONE_MINUS_SRC_ALPHA)      return "GL_ONE_MINUS_SRC_ALPHA";
00756   else if (_param == GL_DST_ALPHA)                return "GL_DST_ALPHA";
00757   else if (_param == GL_ONE_MINUS_DST_ALPHA)      return "GL_ONE_MINUS_DST_ALPHA";
00758   else if (_param == GL_CONSTANT_COLOR)           return "GL_CONSTANT_COLOR";
00759   else if (_param == GL_ONE_MINUS_CONSTANT_COLOR) return "GL_ONE_MINUS_CONSTANT_COLOR";
00760   else if (_param == GL_CONSTANT_ALPHA)           return "GL_CONSTANT_ALPHA";
00761   else if (_param == GL_ONE_MINUS_CONSTANT_ALPHA) return "GL_ONE_MINUS_CONSTANT_ALPHA";
00762   else
00763     return "UNKOWN PARAM";
00764 }
00765 
00766 //=============================================================================
00767 } // namespace QtWidgets
00768 } // namespace ACG
00769 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .