- Main Page
- Related Pages
- Classes
- Files

- File List

# 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 <qglobal.h>
    00014 #include <qcolor.h>
    00015 #if QT_VERSION < 0x040000
    00016 #include <qvaluevector.h>
    00017 #else
    00018 #include <qvector.h>
    00019 #endif
    00020 #include "qwt_array.h"
    00021 #include "qwt_double_interval.h"
    00022
    00023 #if defined(QWT_TEMPLATEDLL)
    00024 // MOC_SKIP_BEGIN
    00025 template class QWT_EXPORT QwtArray<double>;
    00026 // MOC_SKIP_END
    00027 #endif
    00028
    00044 class QWT_EXPORT QwtColorMap
    00045 {
    00046 public:
    00057     enum Format
    00058     {
    00059         RGB,
    00060         Indexed
    00061     };
    00062
    00063     QwtColorMap(Format = QwtColorMap::RGB );
    00064     virtual ~QwtColorMap();
    00065
    00066     inline Format format() const;
    00067
    00069     virtual QwtColorMap *copy() const = 0;
    00070
    00077     virtual QRgb rgb(
    00078         const QwtDoubleInterval &interval, double value) const = 0;
    00079
    00086     virtual unsigned char colorIndex(
    00087         const QwtDoubleInterval &interval, double value) const = 0;
    00088
    00089     QColor color(const QwtDoubleInterval &, double value) const;
    00090 #if QT_VERSION < 0x040000
    00091     virtual QValueVector<QRgb> colorTable(const QwtDoubleInterval &) const;
    00092 #else
    00093     virtual QVector<QRgb> colorTable(const QwtDoubleInterval &) const;
    00094 #endif
    00095
    00096 private:
    00097     Format d_format;
    00098 };
    00099
    00100
    00111 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
    00112 {
    00113 public:
    00118     enum Mode
    00119     {
    00120         FixedColors,
    00121         ScaledColors
    00122     };
    00123
    00124     QwtLinearColorMap(QwtColorMap::Format = QwtColorMap::RGB);
    00125     QwtLinearColorMap( const QColor &from, const QColor &to,
    00126         QwtColorMap::Format = QwtColorMap::RGB);
    00127
    00128     QwtLinearColorMap(const QwtLinearColorMap &);
    00129
    00130     virtual ~QwtLinearColorMap();
    00131
    00132     QwtLinearColorMap &operator=(const QwtLinearColorMap &);
    00133
    00134     virtual QwtColorMap *copy() const;
    00135
    00136     void setMode(Mode);
    00137     Mode mode() const;
    00138
    00139     void setColorInterval(const QColor &color1, const QColor &color2);
    00140     void addColorStop(double value, const QColor&);
    00141     QwtArray<double> colorStops() const;
    00142
    00143     QColor color1() const;
    00144     QColor color2() const;
    00145
    00146     virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
    00147     virtual unsigned char colorIndex(
    00148         const QwtDoubleInterval &, double value) const;
    00149
    00150     class ColorStops;
    00151
    00152 private:
    00153     class PrivateData;
    00154     PrivateData *d_data;
    00155 };
    00156
    00160 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
    00161 {
    00162 public:
    00163     QwtAlphaColorMap(const QColor & = QColor(Qt::gray));
    00164     QwtAlphaColorMap(const QwtAlphaColorMap &);
    00165
    00166     virtual ~QwtAlphaColorMap();
    00167
    00168     QwtAlphaColorMap &operator=(const QwtAlphaColorMap &);
    00169
    00170     virtual QwtColorMap *copy() const;
    00171
    00172     void setColor(const QColor &);
    00173     QColor color() const;
    00174
    00175     virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
    00176
    00177 private:
    00178     virtual unsigned char colorIndex(
    00179         const QwtDoubleInterval &, double value) const;
    00180
    00181     class PrivateData;
    00182     PrivateData *d_data;
    00183 };
    00184
    00185
    00198 inline QColor QwtColorMap::color(
    00199     const QwtDoubleInterval &interval, double value) const
    00200 {
    00201     if ( d_format == RGB )
    00202     {
    00203         return QColor( rgb(interval, value) );
    00204     }
    00205     else
    00206     {
    00207         const unsigned int index = colorIndex(interval, value);
    00208         return colorTable(interval)[index]; // slow
    00209     }
    00210 }
    00211
    00216 inline QwtColorMap::Format QwtColorMap::format() const
    00217 {
    00218     return d_format;
    00219 }
    00220
    00221 #endif