1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
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
*****************************************************************************/
10
#ifndef QWT_COLOR_MAP_H
11
#define QWT_COLOR_MAP_H
15
#if QT_VERSION < 0x040000
16
#include <qvaluevector.h>
20
#include "qwt_array.h"
21
#include "qwt_double_interval.h"
23
#if defined(QWT_TEMPLATEDLL)
25
template class QWT_EXPORT QwtArray<double>;
30
\brief QwtColorMap is used to map values into colors.
32
For displaying 3D data on a 2D plane the 3rd dimension is often
33
displayed using colors, like f.e in a spectrogram.
35
Each color map is optimized to return colors for only one of the
36
following image formats:
38
- QImage::Format_Indexed8\n
39
- QImage::Format_ARGB32\n
41
\sa QwtPlotSpectrogram, QwtScaleWidget
44
class QWT_EXPORT QwtColorMap
49
The map is intended to map into QRgb values.
51
The map is intended to map into 8 bit values, that
52
are indices into the color table.
54
\sa rgb(), colorIndex(), colorTable()
63
QwtColorMap(Format = QwtColorMap::RGB );
64
virtual ~QwtColorMap();
66
inline Format format() const;
68
//! Clone the color map
69
virtual QwtColorMap *copy() const = 0;
72
Map a value of a given interval into a rgb value.
73
\param interval Range for the values
75
\return rgb value, corresponding to value
78
const QwtDoubleInterval &interval, double value) const = 0;
81
Map a value of a given interval into a color index
82
\param interval Range for the values
84
\return color index, corresponding to value
86
virtual unsigned char colorIndex(
87
const QwtDoubleInterval &interval, double value) const = 0;
89
QColor color(const QwtDoubleInterval &, double value) const;
90
#if QT_VERSION < 0x040000
91
virtual QValueVector<QRgb> colorTable(const QwtDoubleInterval &) const;
93
virtual QVector<QRgb> colorTable(const QwtDoubleInterval &) const;
102
\brief QwtLinearColorMap builds a color map from color stops.
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.
111
class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
116
\sa setMode(), mode()
124
QwtLinearColorMap(QwtColorMap::Format = QwtColorMap::RGB);
125
QwtLinearColorMap( const QColor &from, const QColor &to,
126
QwtColorMap::Format = QwtColorMap::RGB);
128
QwtLinearColorMap(const QwtLinearColorMap &);
130
virtual ~QwtLinearColorMap();
132
QwtLinearColorMap &operator=(const QwtLinearColorMap &);
134
virtual QwtColorMap *copy() const;
139
void setColorInterval(const QColor &color1, const QColor &color2);
140
void addColorStop(double value, const QColor&);
141
QwtArray<double> colorStops() const;
143
QColor color1() const;
144
QColor color2() const;
146
virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
147
virtual unsigned char colorIndex(
148
const QwtDoubleInterval &, double value) const;
158
\brief QwtAlphaColorMap variies the alpha value of a color
160
class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
163
QwtAlphaColorMap(const QColor & = QColor(Qt::gray));
164
QwtAlphaColorMap(const QwtAlphaColorMap &);
166
virtual ~QwtAlphaColorMap();
168
QwtAlphaColorMap &operator=(const QwtAlphaColorMap &);
170
virtual QwtColorMap *copy() const;
172
void setColor(const QColor &);
173
QColor color() const;
175
virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
178
virtual unsigned char colorIndex(
179
const QwtDoubleInterval &, double value) const;
187
Map a value into a color
189
\param interval Valid interval for values
192
\return Color corresponding to value
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().
198
inline QColor QwtColorMap::color(
199
const QwtDoubleInterval &interval, double value) const
201
if ( d_format == RGB )
203
return QColor( rgb(interval, value) );
207
const unsigned int index = colorIndex(interval, value);
208
return colorTable(interval)[index]; // slow
213
\return Intended format of the color map
216
inline QwtColorMap::Format QwtColorMap::format() const