[89] | 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
| 2 | * Qwt Widget Library
|
---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
---|
| 5 | *
|
---|
| 6 | * This library is free software; you can redistribute it and/or
|
---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
---|
| 8 | *****************************************************************************/
|
---|
| 9 |
|
---|
| 10 | #ifndef QWT_COLOR_MAP_H
|
---|
| 11 | #define QWT_COLOR_MAP_H
|
---|
| 12 |
|
---|
| 13 | #include <qglobal.h>
|
---|
| 14 | #include <qcolor.h>
|
---|
| 15 | #if QT_VERSION < 0x040000
|
---|
| 16 | #include <qvaluevector.h>
|
---|
| 17 | #else
|
---|
| 18 | #include <qvector.h>
|
---|
| 19 | #endif
|
---|
| 20 | #include "qwt_array.h"
|
---|
| 21 | #include "qwt_double_interval.h"
|
---|
| 22 |
|
---|
| 23 | #if defined(QWT_TEMPLATEDLL)
|
---|
| 24 | // MOC_SKIP_BEGIN
|
---|
| 25 | template class QWT_EXPORT QwtArray<double>;
|
---|
| 26 | // MOC_SKIP_END
|
---|
| 27 | #endif
|
---|
| 28 |
|
---|
| 29 | /*!
|
---|
| 30 | \brief QwtColorMap is used to map values into colors.
|
---|
| 31 |
|
---|
| 32 | For displaying 3D data on a 2D plane the 3rd dimension is often
|
---|
| 33 | displayed using colors, like f.e in a spectrogram.
|
---|
| 34 |
|
---|
| 35 | Each color map is optimized to return colors for only one of the
|
---|
| 36 | following image formats:
|
---|
| 37 |
|
---|
| 38 | - QImage::Format_Indexed8\n
|
---|
| 39 | - QImage::Format_ARGB32\n
|
---|
| 40 |
|
---|
| 41 | \sa QwtPlotSpectrogram, QwtScaleWidget
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | class QWT_EXPORT QwtColorMap
|
---|
| 45 | {
|
---|
| 46 | public:
|
---|
| 47 | /*!
|
---|
| 48 | - RGB\n
|
---|
| 49 | The map is intended to map into QRgb values.
|
---|
| 50 | - Indexed\n
|
---|
| 51 | The map is intended to map into 8 bit values, that
|
---|
| 52 | are indices into the color table.
|
---|
| 53 |
|
---|
| 54 | \sa rgb(), colorIndex(), colorTable()
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | enum Format
|
---|
| 58 | {
|
---|
| 59 | RGB,
|
---|
| 60 | Indexed
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | QwtColorMap(Format = QwtColorMap::RGB );
|
---|
| 64 | virtual ~QwtColorMap();
|
---|
| 65 |
|
---|
| 66 | Format format() const;
|
---|
| 67 |
|
---|
| 68 | //! Clone the color map
|
---|
| 69 | virtual QwtColorMap *copy() const = 0;
|
---|
| 70 |
|
---|
| 71 | /*!
|
---|
| 72 | Map a value of a given interval into a rgb value.
|
---|
| 73 | \param interval Range for the values
|
---|
| 74 | \param value Value
|
---|
| 75 | \return rgb value, corresponding to value
|
---|
| 76 | */
|
---|
| 77 | virtual QRgb rgb(
|
---|
| 78 | const QwtDoubleInterval &interval, double value) const = 0;
|
---|
| 79 |
|
---|
| 80 | /*!
|
---|
| 81 | Map a value of a given interval into a color index
|
---|
| 82 | \param interval Range for the values
|
---|
| 83 | \param value Value
|
---|
| 84 | \return color index, corresponding to value
|
---|
| 85 | */
|
---|
| 86 | virtual unsigned char colorIndex(
|
---|
| 87 | const QwtDoubleInterval &interval, double value) const = 0;
|
---|
| 88 |
|
---|
| 89 | QColor color(const QwtDoubleInterval &, double value) const;
|
---|
| 90 | #if QT_VERSION < 0x040000
|
---|
| 91 | virtual QValueVector<QRgb> colorTable(const QwtDoubleInterval &) const;
|
---|
| 92 | #else
|
---|
| 93 | virtual QVector<QRgb> colorTable(const QwtDoubleInterval &) const;
|
---|
| 94 | #endif
|
---|
| 95 |
|
---|
| 96 | private:
|
---|
| 97 | Format d_format;
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | /*!
|
---|
| 102 | \brief QwtLinearColorMap builds a color map from color stops.
|
---|
| 103 |
|
---|
| 104 | A color stop is a color at a specific position. The valid
|
---|
| 105 | range for the positions is [0.0, 1.0]. When mapping a value
|
---|
| 106 | into a color it is translated into this interval. If
|
---|
| 107 | mode() == FixedColors the color is calculated from the next lower
|
---|
| 108 | color stop. If mode() == ScaledColors the color is calculated
|
---|
| 109 | by interpolating the colors of the adjacent stops.
|
---|
| 110 | */
|
---|
| 111 | class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
|
---|
| 112 | {
|
---|
| 113 | public:
|
---|
| 114 | /*!
|
---|
| 115 | Mode of color map
|
---|
| 116 | \sa setMode(), mode()
|
---|
| 117 | */
|
---|
| 118 | enum Mode
|
---|
| 119 | {
|
---|
| 120 | FixedColors,
|
---|
| 121 | ScaledColors
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | QwtLinearColorMap(QwtColorMap::Format = QwtColorMap::RGB);
|
---|
| 125 | QwtLinearColorMap( const QColor &from, const QColor &to,
|
---|
| 126 | QwtColorMap::Format = QwtColorMap::RGB);
|
---|
| 127 |
|
---|
| 128 | QwtLinearColorMap(const QwtLinearColorMap &);
|
---|
| 129 |
|
---|
| 130 | virtual ~QwtLinearColorMap();
|
---|
| 131 |
|
---|
| 132 | QwtLinearColorMap &operator=(const QwtLinearColorMap &);
|
---|
| 133 |
|
---|
| 134 | virtual QwtColorMap *copy() const;
|
---|
| 135 |
|
---|
| 136 | void setMode(Mode);
|
---|
| 137 | Mode mode() const;
|
---|
| 138 |
|
---|
| 139 | void setColorInterval(const QColor &color1, const QColor &color2);
|
---|
| 140 | void addColorStop(double value, const QColor&);
|
---|
| 141 | QwtArray<double> colorStops() const;
|
---|
| 142 |
|
---|
| 143 | QColor color1() const;
|
---|
| 144 | QColor color2() const;
|
---|
| 145 |
|
---|
| 146 | virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
|
---|
| 147 | virtual unsigned char colorIndex(
|
---|
| 148 | const QwtDoubleInterval &, double value) const;
|
---|
| 149 |
|
---|
| 150 | class ColorStops;
|
---|
| 151 |
|
---|
| 152 | private:
|
---|
| 153 | class PrivateData;
|
---|
| 154 | PrivateData *d_data;
|
---|
| 155 | };
|
---|
| 156 |
|
---|
| 157 | /*!
|
---|
| 158 | \brief QwtAlphaColorMap variies the alpha value of a color
|
---|
| 159 | */
|
---|
| 160 | class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
|
---|
| 161 | {
|
---|
| 162 | public:
|
---|
| 163 | QwtAlphaColorMap(const QColor & = QColor(Qt::gray));
|
---|
| 164 | QwtAlphaColorMap(const QwtAlphaColorMap &);
|
---|
| 165 |
|
---|
| 166 | virtual ~QwtAlphaColorMap();
|
---|
| 167 |
|
---|
| 168 | QwtAlphaColorMap &operator=(const QwtAlphaColorMap &);
|
---|
| 169 |
|
---|
| 170 | virtual QwtColorMap *copy() const;
|
---|
| 171 |
|
---|
| 172 | void setColor(const QColor &);
|
---|
| 173 | QColor color() const;
|
---|
| 174 |
|
---|
| 175 | virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
|
---|
| 176 |
|
---|
| 177 | private:
|
---|
| 178 | virtual unsigned char colorIndex(
|
---|
| 179 | const QwtDoubleInterval &, double value) const;
|
---|
| 180 |
|
---|
| 181 | class PrivateData;
|
---|
| 182 | PrivateData *d_data;
|
---|
| 183 | };
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | /*!
|
---|
| 187 | Map a value into a color
|
---|
| 188 |
|
---|
| 189 | \param interval Valid interval for values
|
---|
| 190 | \param value Value
|
---|
| 191 |
|
---|
| 192 | \return Color corresponding to value
|
---|
| 193 |
|
---|
| 194 | \warning This method is slow for Indexed color maps. If it is
|
---|
| 195 | necessary to map many values, its better to get the
|
---|
| 196 | color table once and find the color using colorIndex().
|
---|
| 197 | */
|
---|
| 198 | inline QColor QwtColorMap::color(
|
---|
| 199 | const QwtDoubleInterval &interval, double value) const
|
---|
| 200 | {
|
---|
| 201 | if ( d_format == RGB )
|
---|
| 202 | {
|
---|
| 203 | return QColor( rgb(interval, value) );
|
---|
| 204 | }
|
---|
| 205 | else
|
---|
| 206 | {
|
---|
| 207 | const unsigned int index = colorIndex(interval, value);
|
---|
| 208 | return colorTable(interval)[index]; // slow
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /*!
|
---|
| 213 | \return Intended format of the color map
|
---|
| 214 | \sa Format
|
---|
| 215 | */
|
---|
| 216 | inline QwtColorMap::Format QwtColorMap::format() const
|
---|
| 217 | {
|
---|
| 218 | return d_format;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | #endif
|
---|