00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_COLOR_MAP_H
00011 #define QWT_COLOR_MAP_H
00012
00013 #include "qwt_global.h"
00014 #include "qwt_double_interval.h"
00015 #include <qcolor.h>
00016 #include <qvector.h>
00017
00033 class QWT_EXPORT QwtColorMap
00034 {
00035 public:
00046 enum Format
00047 {
00048 RGB,
00049 Indexed
00050 };
00051
00052 QwtColorMap(Format = QwtColorMap::RGB );
00053 virtual ~QwtColorMap();
00054
00055 Format format() const;
00056
00058 virtual QwtColorMap *copy() const = 0;
00059
00066 virtual QRgb rgb(
00067 const QwtDoubleInterval &interval, double value) const = 0;
00068
00075 virtual unsigned char colorIndex(
00076 const QwtDoubleInterval &interval, double value) const = 0;
00077
00078 QColor color(const QwtDoubleInterval &, double value) const;
00079 virtual QVector<QRgb> colorTable(const QwtDoubleInterval &) const;
00080
00081 private:
00082 Format d_format;
00083 };
00084
00085
00096 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
00097 {
00098 public:
00103 enum Mode
00104 {
00105 FixedColors,
00106 ScaledColors
00107 };
00108
00109 QwtLinearColorMap(QwtColorMap::Format = QwtColorMap::RGB);
00110 QwtLinearColorMap( const QColor &from, const QColor &to,
00111 QwtColorMap::Format = QwtColorMap::RGB);
00112
00113 QwtLinearColorMap(const QwtLinearColorMap &);
00114
00115 virtual ~QwtLinearColorMap();
00116
00117 QwtLinearColorMap &operator=(const QwtLinearColorMap &);
00118
00119 virtual QwtColorMap *copy() const;
00120
00121 void setMode(Mode);
00122 Mode mode() const;
00123
00124 void setColorInterval(const QColor &color1, const QColor &color2);
00125 void addColorStop(double value, const QColor&);
00126 QVector<double> colorStops() const;
00127
00128 QColor color1() const;
00129 QColor color2() const;
00130
00131 virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
00132 virtual unsigned char colorIndex(
00133 const QwtDoubleInterval &, double value) const;
00134
00135 class ColorStops;
00136
00137 private:
00138 class PrivateData;
00139 PrivateData *d_data;
00140 };
00141
00145 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
00146 {
00147 public:
00148 QwtAlphaColorMap(const QColor & = QColor(Qt::gray));
00149 QwtAlphaColorMap(const QwtAlphaColorMap &);
00150
00151 virtual ~QwtAlphaColorMap();
00152
00153 QwtAlphaColorMap &operator=(const QwtAlphaColorMap &);
00154
00155 virtual QwtColorMap *copy() const;
00156
00157 void setColor(const QColor &);
00158 QColor color() const;
00159
00160 virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
00161
00162 private:
00163 virtual unsigned char colorIndex(
00164 const QwtDoubleInterval &, double value) const;
00165
00166 class PrivateData;
00167 PrivateData *d_data;
00168 };
00169
00170
00183 inline QColor QwtColorMap::color(
00184 const QwtDoubleInterval &interval, double value) const
00185 {
00186 if ( d_format == RGB )
00187 {
00188 return QColor( rgb(interval, value) );
00189 }
00190 else
00191 {
00192 const unsigned int index = colorIndex(interval, value);
00193 return colorTable(interval)[index];
00194 }
00195 }
00196
00201 inline QwtColorMap::Format QwtColorMap::format() const
00202 {
00203 return d_format;
00204 }
00205
00206 #endif