Commit d8d0b8cd authored by Dirk Wilden's avatar Dirk Wilden
Browse files

enhanced ColorPlugin and added docu

color presets can now be chosen in the options and are stored in ini files

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5186 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 560819fb
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5151 $
// $Author: moebius $
// $Date: 2009-02-27 17:36:10 +0100 (Fr, 27. Feb 2009) $
//
//=============================================================================
#include "ColorOptions.hh"
ColorOptions::ColorOptions(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5151 $
// $Author: moebius $
// $Date: 2009-02-27 17:36:10 +0100 (Fr, 27. Feb 2009) $
//
//=============================================================================
#include "ui_colorOptions.hh"
#include <QtGui>
class ColorOptions : public QWidget, public Ui::colorOptions
{
Q_OBJECT
public:
ColorOptions(QWidget *parent = 0);
};
...@@ -39,6 +39,39 @@ ...@@ -39,6 +39,39 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
//-----------------------------------------------------------------------------
/** \brief Constructor
*
*/
ColorPlugin::ColorPlugin() : optionsWidget_(0)
{
//set default values for colors
backgroundColorDefault_ = ACG::GLState::default_clear_color;
backgroundColorPaper_ = OpenMesh::Vec4f(1.00, 1.00, 1.00, 1.0);
backgroundColorPresentation_ = OpenMesh::Vec4f(0.0, 0.188, 0.062, 1.0);
baseColorDefault_ = ACG::GLState::default_base_color;
baseColorPaper_ = OpenMesh::Vec4f(0.00, 0.00, 0.00, 1.0);
baseColorPresentation_ = OpenMesh::Vec4f(0.88, 0.88, 0.188, 1.0);
materialColorDefault_ = ACG::GLState::default_diffuse_color;
materialColorPaper_ = OpenMesh::Vec4f(0.12, 0.76, 0.62, 1.0);
materialColorPresentation_ = OpenMesh::Vec4f(0.941, 0.439, 0.31, 1.0);
lineWidthDefault_ = 1.0;
lineWidthPaper_ = 2.0;
lineWidthPresentation_ = 1.0;
}
//-----------------------------------------------------------------------------
/** \brief initialize the toolbar and menubar
*
*/
void ColorPlugin::pluginsInitialized() void ColorPlugin::pluginsInitialized()
{ {
// ============================================================================= // =============================================================================
...@@ -62,13 +95,13 @@ void ColorPlugin::pluginsInitialized() ...@@ -62,13 +95,13 @@ void ColorPlugin::pluginsInitialized()
connect(AC_set_Default_color, SIGNAL(triggered()), this, SLOT(setDefaultColor())); connect(AC_set_Default_color, SIGNAL(triggered()), this, SLOT(setDefaultColor()));
colorMenu->addAction(AC_set_Default_color); colorMenu->addAction(AC_set_Default_color);
QAction* AC_set_Powerpoint_color = new QAction(tr("&Powerpoint colors"), this); QAction* AC_set_Presentation_color = new QAction(tr("&Presentation colors"), this);
AC_set_Powerpoint_color->setStatusTip(tr("Set Powerpoint Colors")); AC_set_Presentation_color->setStatusTip(tr("Set Presentation Colors"));
AC_set_Powerpoint_color->setWhatsThis("Set colors to Powerpoint presentation colors"); AC_set_Presentation_color->setWhatsThis("Set colors to presentation colors");
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-powerpoint.png"); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-powerpoint.png");
AC_set_Powerpoint_color->setIcon(icon); AC_set_Presentation_color->setIcon(icon);
connect(AC_set_Powerpoint_color, SIGNAL(triggered()), this, SLOT(setPowerpointColor())); connect(AC_set_Presentation_color, SIGNAL(triggered()), this, SLOT(setPresentationColor()));
colorMenu->addAction(AC_set_Powerpoint_color); colorMenu->addAction(AC_set_Presentation_color);
QAction* AC_set_Paper_color = new QAction(tr("&Paper colors"), this); QAction* AC_set_Paper_color = new QAction(tr("&Paper colors"), this);
AC_set_Paper_color->setStatusTip(tr("Set Paper Colors")); AC_set_Paper_color->setStatusTip(tr("Set Paper Colors"));
...@@ -84,12 +117,18 @@ void ColorPlugin::pluginsInitialized() ...@@ -84,12 +117,18 @@ void ColorPlugin::pluginsInitialized()
QToolBar* toolbar = new QToolBar("Color Toolbar"); QToolBar* toolbar = new QToolBar("Color Toolbar");
toolbar->addAction(AC_set_Default_color); toolbar->addAction(AC_set_Default_color);
toolbar->addAction(AC_set_Powerpoint_color); toolbar->addAction(AC_set_Presentation_color);
toolbar->addAction(AC_set_Paper_color); toolbar->addAction(AC_set_Paper_color);
emit addToolbar( toolbar ); emit addToolbar( toolbar );
} }
//-----------------------------------------------------------------------------
/** \brief set the defaultColor preset
*
*/
void ColorPlugin::setDefaultColor() { void ColorPlugin::setDefaultColor() {
// ============================================================================= // =============================================================================
...@@ -101,84 +140,81 @@ void ColorPlugin::setDefaultColor() { ...@@ -101,84 +140,81 @@ void ColorPlugin::setDefaultColor() {
// ============================================================================= // =============================================================================
// Define the new colors // Define the new colors
// ============================================================================= // =============================================================================
OpenMesh::Vec4f back_color, OpenMesh::Vec4f ambient_color,
base_color,
ambient_color,
diffuse_color, diffuse_color,
specular_color, specular_color;
mat_color;
float line_width(1.0);
back_color = ACG::GLState::default_clear_color; ambient_color = 0.2f * materialColorDefault_;
base_color = ACG::GLState::default_base_color; diffuse_color = 0.6f * materialColorDefault_;
ambient_color = ACG::GLState::default_ambient_color; specular_color = 0.8f * materialColorDefault_;
diffuse_color = ACG::GLState::default_diffuse_color;
specular_color = ACG::GLState::default_specular_color;
line_width = 1.0;
// Set background color // Set background color
PluginFunctions::setBackColor(back_color); PluginFunctions::setBackColor( backgroundColorDefault_ );
// ============================================================================= // =============================================================================
// Apply to all objects // Apply to all objects
// ============================================================================= // =============================================================================
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
MaterialNode* mat = o_it->materialNode(); MaterialNode* mat = o_it->materialNode();
mat->set_base_color(base_color); mat->set_base_color( baseColorDefault_ );
mat->set_ambient_color(ambient_color); mat->set_ambient_color(ambient_color);
mat->set_diffuse_color(diffuse_color); mat->set_diffuse_color(diffuse_color);
mat->set_specular_color(specular_color); mat->set_specular_color(specular_color);
mat->set_line_width(line_width); mat->set_line_width( lineWidthDefault_ );
} }
emit updateView(); emit updateView();
} }
void ColorPlugin::setPowerpointColor() {
//-----------------------------------------------------------------------------
/** \brief Set the presentation color preset
*
*/
void ColorPlugin::setPresentationColor() {
// ============================================================================= // =============================================================================
// Give user feedback // Give user feedback
// ============================================================================= // =============================================================================
emit scriptInfo( "setPowerpointColor()" ); emit scriptInfo( "setPresentationColor()" );
emit showStatusMessage( "Set to Powerpoint Colors", 4000 ); emit showStatusMessage( "Set to Presentation Colors", 4000 );
// ============================================================================= // =============================================================================
// Define the new colors // Define the new colors
// ============================================================================= // =============================================================================
OpenMesh::Vec4f back_color, OpenMesh::Vec4f ambient_color,
base_color,
ambient_color,
diffuse_color, diffuse_color,
specular_color, specular_color;
mat_color;
float line_width(1.0); ambient_color = 0.2f * materialColorPresentation_;
diffuse_color = 0.6f * materialColorPresentation_;
back_color = OpenMesh::Vec4f(0.0, 0.188, 0.062, 1.0); specular_color = 0.8f * materialColorPresentation_;
base_color = OpenMesh::Vec4f(0.88, 0.88, 0.188, 1.0);
mat_color = OpenMesh::Vec4f(0.941, 0.439, 0.31, 1.0);
ambient_color = 0.2f * mat_color;
diffuse_color = 0.6f * mat_color;
specular_color = 0.8f * mat_color;
line_width = 1.0;
// Set background color // Set background color
PluginFunctions::setBackColor(back_color); PluginFunctions::setBackColor( backgroundColorPresentation_ );
// ============================================================================= // =============================================================================
// Apply to all objects // Apply to all objects
// ============================================================================= // =============================================================================
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
MaterialNode* mat = o_it->materialNode(); MaterialNode* mat = o_it->materialNode();
mat->set_base_color(base_color); mat->set_base_color( baseColorPresentation_ );
mat->set_ambient_color(ambient_color); mat->set_ambient_color(ambient_color);
mat->set_diffuse_color(diffuse_color); mat->set_diffuse_color(diffuse_color);
mat->set_specular_color(specular_color); mat->set_specular_color(specular_color);
mat->set_line_width(line_width); mat->set_line_width( lineWidthPresentation_ );
} }
emit updateView(); emit updateView();
} }
//-----------------------------------------------------------------------------
/** \brief set the paperColor Preset
*
*/
void ColorPlugin::setPaperColor() { void ColorPlugin::setPaperColor() {
// ============================================================================= // =============================================================================
...@@ -190,42 +226,39 @@ void ColorPlugin::setPaperColor() { ...@@ -190,42 +226,39 @@ void ColorPlugin::setPaperColor() {
// ============================================================================= // =============================================================================
// Define the new colors // Define the new colors
// ============================================================================= // =============================================================================
OpenMesh::Vec4f back_color, OpenMesh::Vec4f ambient_color,
base_color,
ambient_color,
diffuse_color, diffuse_color,
specular_color, specular_color;
mat_color;
float line_width(1.0); ambient_color = 0.2f * materialColorPaper_;
diffuse_color = 0.5f * materialColorPaper_;
back_color = OpenMesh::Vec4f(1.00, 1.00, 1.00, 1.0); specular_color = 0.8f * materialColorPaper_;
base_color = OpenMesh::Vec4f(0.00, 0.00, 0.00, 1.0);
mat_color = OpenMesh::Vec4f(0.12, 0.76, 0.62, 1.0);
ambient_color = 0.2f * mat_color;
diffuse_color = 0.5f * mat_color;
specular_color = 0.8f * mat_color;
line_width = 2.0;
// Set background color // Set background color
PluginFunctions::setBackColor(back_color); PluginFunctions::setBackColor( backgroundColorPaper_ );
// ============================================================================= // =============================================================================
// Apply to all objects // Apply to all objects
// ============================================================================= // =============================================================================
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
MaterialNode* mat = o_it->materialNode(); MaterialNode* mat = o_it->materialNode();
mat->set_base_color(base_color); mat->set_base_color( baseColorPaper_ );
mat->set_ambient_color(ambient_color); mat->set_ambient_color(ambient_color);
mat->set_diffuse_color(diffuse_color); mat->set_diffuse_color(diffuse_color);
mat->set_specular_color(specular_color); mat->set_specular_color(specular_color);
mat->set_line_width(line_width); mat->set_line_width( lineWidthPaper_ );
} }
emit updateView(); emit updateView();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** \brief Set the backgroundColor
*
* @param _color a color
*/
void ColorPlugin::setBackgroundColor( Vector _color ) { void ColorPlugin::setBackgroundColor( Vector _color ) {
emit scriptInfo( "setBackgroundColor()" ); emit scriptInfo( "setBackgroundColor()" );
emit showStatusMessage( "Set background color", 4000 ); emit showStatusMessage( "Set background color", 4000 );
...@@ -240,5 +273,281 @@ void ColorPlugin::setBackgroundColor( Vector _color ) { ...@@ -240,5 +273,281 @@ void ColorPlugin::setBackgroundColor( Vector _color ) {
} }
//-----------------------------------------------------------------------------
/** \brief Generate an icon with given color
*
* @param _color a color vector
* @return an icon
*/
QIcon ColorPlugin::generateIcon(OpenMesh::Vec4f _color){
QColor color;
color.setRgbF(_color[0], _color[1], _color[2], _color[3] );
QPixmap pic(32,32);
pic.fill( color );
return QIcon( pic );
}
//-----------------------------------------------------------------------------
/** \brief Generate an icon with given color
*
* @param _color a color
* @return the icon
*/
QIcon ColorPlugin::generateIcon(QRgb _color){
QColor color(_color);
QPixmap pic(32,32);
pic.fill( color );
return QIcon( pic );
}
//-----------------------------------------------------------------------------
/** \brief Get the color of an icon
*
* @param _icon an icon
* @return its color
*/
QRgb ColorPlugin::getIconColor(QIcon _icon){
QRgb rgb = _icon.pixmap(32,32).toImage().pixel(0,0);
return rgb;
}
//-----------------------------------------------------------------------------
/** \brief convert an icons color to a Vec4f
*
* @param _icon an icon
* @param _color reference to a color vector
*/
void ColorPlugin::setNewColor(QIcon _icon, OpenMesh::Vec4f& _color){
QColor color( getIconColor(_icon) );
_color[0] = color.redF();
_color[1] = color.greenF();
_color[2] = color.blueF();
_color[3] = color.alphaF();
}
//-----------------------------------------------------------------------------
/** \brief show a colorDialog and store the chosen value in the icon of the sender()
*
*/
void ColorPlugin::getColorDialog(){
QPushButton* button = dynamic_cast< QPushButton* > ( sender() );
if (button != 0){
bool ok;
QRgb newColor = QColorDialog::getRgba ( getIconColor( button->icon() ) , &ok );
if (ok)
button->setIcon( generateIcon(newColor) );
}
}
//-----------------------------------------------------------------------------
/** \brief generate an optionsWidget to change color presets
*
* @param _widget reference to the generated widget
* @return return true if the widget was successfully generated
*/
bool ColorPlugin::initializeOptionsWidget(QWidget*& _widget){
if (optionsWidget_ == 0){
optionsWidget_ = new ColorOptions();
//connect the signals
connect(optionsWidget_->backgroundDefault, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->backgroundPaper, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->backgroundPresentation, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->baseDefault, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->basePaper, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->basePresentation, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->materialDefault, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->materialPaper, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
connect(optionsWidget_->materialPresentation, SIGNAL( clicked() ), this, SLOT( getColorDialog() ) );
}
//put values into the optionsWidget
optionsWidget_->backgroundDefault->setIcon( generateIcon( backgroundColorDefault_ ) );
optionsWidget_->backgroundPaper->setIcon( generateIcon( backgroundColorPaper_ ) );
optionsWidget_->backgroundPresentation->setIcon( generateIcon( backgroundColorPresentation_ ) );
optionsWidget_->baseDefault->setIcon( generateIcon( baseColorDefault_ ) );
optionsWidget_->basePaper->setIcon( generateIcon( baseColorPaper_ ) );
optionsWidget_->basePresentation->setIcon( generateIcon( baseColorPresentation_ ) );
optionsWidget_->materialDefault->setIcon( generateIcon( materialColorDefault_ ) );
optionsWidget_->materialPaper->setIcon( generateIcon( materialColorPaper_ ) );
optionsWidget_->materialPresentation->setIcon( generateIcon( materialColorPresentation_ ) );
optionsWidget_->lineDefault->setValue( lineWidthDefault_ );
optionsWidget_->linePaper->setValue( lineWidthPaper_ );
optionsWidget_->linePresentation->setValue( lineWidthPresentation_ );
_widget = optionsWidget_;
return true;
}
//-----------------------------------------------------------------------------
/** \brief Store the changed color presets when the apply Button was hit
*
*/
void ColorPlugin::applyOptions(){
setNewColor(optionsWidget_->backgroundDefault->icon(), backgroundColorDefault_);
setNewColor(optionsWidget_->backgroundPaper->icon(), backgroundColorPaper_);
setNewColor(optionsWidget_->backgroundPresentation->icon(), backgroundColorPresentation_);
setNewColor(optionsWidget_->baseDefault->icon(), baseColorDefault_);
setNewColor(optionsWidget_->basePaper->icon(), baseColorPaper_);
setNewColor(optionsWidget_->basePresentation->icon(), baseColorPresentation_);
setNewColor(optionsWidget_->materialDefault->icon(), materialColorDefault_);
setNewColor(optionsWidget_->materialPaper->icon(), materialColorPaper_);
setNewColor(optionsWidget_->materialPresentation->icon(), materialColorPresentation_);
lineWidthDefault_ = optionsWidget_->lineDefault->value();
lineWidthPaper_ = optionsWidget_->linePaper->value();
lineWidthPresentation_ = optionsWidget_->linePresentation->value();
}
//-----------------------------------------------------------------------------
/** \brief convert between uint and Vec4f
*
* @param _color given color
* @param _vector color vector to convert to
*/
void ColorPlugin::convertColor(uint _color, OpenMesh::Vec4f& _vector){
QColor color;
color.setRgba( _color );
_vector[0] = color.redF();
_vector[1] = color.greenF();
_vector[2] = color.blueF();
_vector[3] = color.alphaF();
}
//-----------------------------------------------------------------------------
/** \brief convert between uint and Vec4f
*
* @param _vector reference to a color vector
* @return same color as uint
*/
uint ColorPlugin::convertColor(OpenMesh::Vec4f& _vector){
QColor color;
color.setRgbF(_vector[0], _vector[1], _vector[2], _vector[3] );
return (uint) color.rgba();
}
//-----------------------------------------------------------------------------
/** \brief read color preset from ini file
*
* @param _ini file to read from
*/