Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/color.h
00001 /**********************************************************************
00002   Color - Base class for handling color changes in OpenGL
00003 
00004     Copyright (c) 2006-2008 Benoit Jacob
00005     Copyright (c) 2007-2009 Geoff Hutchison
00006     Copyright (c) 2007-2008 Donald Ephraim Curtis
00007     Copyright (c) 2007 Carsten Niehaus
00008     Copyright (c) 2007-2009 Marcus D. Hanwell
00009 
00010   This file is part of the Avogadro molecular editor project.
00011   For more information, see <http://avogadro.openmolecules.net/>
00012 
00013   Avogadro is free software; you can redistribute it and/or modify
00014   it under the terms of the GNU General Public License as published by
00015   the Free Software Foundation; either version 2 of the License, or
00016   (at your option) any later version.
00017 
00018   Avogadro is distributed in the hope that it will be useful,
00019   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021   GNU General Public License for more details.
00022 
00023   You should have received a copy of the GNU General Public License
00024   along with this program; if not, write to the Free Software
00025   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00026   02110-1301, USA.
00027  **********************************************************************/
00028 
00029 #ifndef COLOR_H
00030 #define COLOR_H
00031 
00032 #include <avogadro/global.h>
00033 #include <avogadro/plugin.h>
00034 
00035 #include <QColor> // for returning QColor
00036 
00037 #define AVOGADRO_COLOR(i, t, d)                 \
00038   public: \
00039     static QString staticIdentifier() { return i; }          \
00040     QString identifier() const { return i; }                 \
00041     static QString staticName() { return t; }                \
00042     QString name() const { if (m_name.isEmpty()) return t; else return m_name; } \
00043     static QString staticDescription() { return d; }         \
00044     QString description() const { return d; }
00045 
00046 #define AVOGADRO_COLOR_FACTORY(c)         \
00047   public: \
00048     Avogadro::Plugin *createInstance(QObject *parent = 0) { Q_UNUSED(parent); return new c(); } \
00049     Avogadro::Plugin::Type type() const { return Avogadro::Plugin::ColorType; }; \
00050     QString identifier() const { return c::staticIdentifier(); } \
00051     QString name() const { return c::staticName(); }         \
00052     QString description() const { return c::staticDescription(); }
00053 
00054 namespace Avogadro {
00055 
00056   class Primitive;
00057   class ColorPrivate; // for future expansion
00058 
00068   class A_EXPORT Color : public Plugin
00069   {
00070     Q_OBJECT
00071   public:
00072     Color();
00073     virtual ~Color();
00074 
00087     Color(float red, float green, float blue, float alpha = 1.0 );
00088 
00094     Color( const Primitive *p);
00095 
00107     virtual void setFromPrimitive(const Primitive *p);
00108 
00113     virtual void setFromIndex(const unsigned int index);
00114 
00122     virtual void setFromGradient(const double value, const double lo,
00123                                  const double mid, const double hi);
00125 
00142     virtual void setFromRgba(float red, float green,float blue,
00143                              float alpha = 1.0);
00144 
00150     virtual void setFromQColor(const QColor &color);
00151 
00156     virtual void setToSelectionColor();
00157 
00164     virtual void setAlpha(double alpha);
00166 
00171     virtual void apply();
00177     virtual void applyAsMaterials();
00178 
00182     virtual void applyAsFlatMaterials();
00183 
00187     inline QColor color() const
00188     { QColor returnColor;
00189       returnColor.setRgbF(m_channels[0],
00190                           m_channels[1],
00191                           m_channels[2],
00192                           m_channels[3]);
00193         return returnColor; }
00194 
00198     inline float red() const { return m_channels[0]; }
00202     inline float green() const { return m_channels[1]; }
00206     inline float blue() const { return m_channels[2]; }
00210     inline float alpha() const { return m_channels[3]; }
00211 
00215     virtual void setName(const QString& name);
00219     virtual QString name() const;
00223     virtual QString identifier() const;
00227     virtual Plugin::Type type() const { return Plugin::ColorType; }
00228 
00229   Q_SIGNALS:
00234       void changed();
00235 
00236   protected:
00241     float m_channels[4];
00242 
00246     QString m_name;
00247 
00251     ColorPrivate *d;
00252   };
00253 
00254 }
00255 
00256 #endif