# qwt_color_map.h

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2002   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 #ifndef QWT_COLOR_MAP_H
    00011 #define QWT_COLOR_MAP_H
    00012
    00013 #include "qwt_global.h"
    00014 #include "qwt_interval.h"
    00015 #include <qcolor.h>
    00016 #include <qvector.h>
    00017
    00033 class QWT_EXPORT QwtColorMap
    00034 {
    00035 public:
    00041     enum Format
    00042     {
    00044         RGB,
    00045
    00050         Indexed
    00051     };
    00052
    00053     QwtColorMap( Format = QwtColorMap::RGB );
    00054     virtual ~QwtColorMap();
    00055
    00056     Format format() const;
    00057
    00064     virtual QRgb rgb( const QwtInterval &interval,
    00065         double value ) const = 0;
    00066
    00073     virtual unsigned char colorIndex(
    00074         const QwtInterval &interval, double value ) const = 0;
    00075
    00076     QColor color( const QwtInterval &, double value ) const;
    00077     virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
    00078
    00079 private:
    00080     Format d_format;
    00081 };
    00082
    00090 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
    00091 {
    00092 public:
    00097     enum Mode
    00098     {
    00100         FixedColors,
    00101
    00103         ScaledColors
    00104     };
    00105
    00106     QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
    00107     QwtLinearColorMap( const QColor &from, const QColor &to,
    00108         QwtColorMap::Format = QwtColorMap::RGB );
    00109
    00110     virtual ~QwtLinearColorMap();
    00111
    00112     void setMode( Mode );
    00113     Mode mode() const;
    00114
    00115     void setColorInterval( const QColor &color1, const QColor &color2 );
    00116     void addColorStop( double value, const QColor& );
    00117     QVector<double> colorStops() const;
    00118
    00119     QColor color1() const;
    00120     QColor color2() const;
    00121
    00122     virtual QRgb rgb( const QwtInterval &, double value ) const;
    00123     virtual unsigned char colorIndex(
    00124         const QwtInterval &, double value ) const;
    00125
    00126     class ColorStops;
    00127
    00128 private:
    00129     // Disabled copy constructor and operator=
    00130     QwtLinearColorMap( const QwtLinearColorMap & );
    00131     QwtLinearColorMap &operator=( const QwtLinearColorMap & );
    00132
    00133     class PrivateData;
    00134     PrivateData *d_data;
    00135 };
    00136
    00140 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
    00141 {
    00142 public:
    00143     QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
    00144     virtual ~QwtAlphaColorMap();
    00145
    00146     void setColor( const QColor & );
    00147     QColor color() const;
    00148
    00149     virtual QRgb rgb( const QwtInterval &, double value ) const;
    00150
    00151 private:
    00152     QwtAlphaColorMap( const QwtAlphaColorMap & );
    00153     QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
    00154
    00155     virtual unsigned char colorIndex(
    00156         const QwtInterval &, double value ) const;
    00157
    00158     class PrivateData;
    00159     PrivateData *d_data;
    00160 };
    00161
    00162
    00175 inline QColor QwtColorMap::color(
    00176     const QwtInterval &interval, double value ) const
    00177 {
    00178     if ( d_format == RGB )
    00179     {
    00180         return QColor( rgb( interval, value ) );
    00181     }
    00182     else
    00183     {
    00184         const unsigned int index = colorIndex( interval, value );
    00185         return colorTable( interval )[index]; // slow
    00186     }
    00187 }
    00188
    00193 inline QwtColorMap::Format QwtColorMap::format() const
    00194 {
    00195     return d_format;
    00196 }
    00197
    00198 #endif