source: ntrip/trunk/BNC/qwt/qwt_color_map.h@ 8127

Last change on this file since 8127 was 8127, checked in by stoecker, 7 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 4.9 KB
Line 
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 "qwt_global.h"
14#include "qwt_interval.h"
15#include <qcolor.h>
16#include <qvector.h>
17
18/*!
19 \brief QwtColorMap is used to map values into colors.
20
21 For displaying 3D data on a 2D plane the 3rd dimension is often
22 displayed using colors, like f.e in a spectrogram.
23
24 Each color map is optimized to return colors for only one of the
25 following image formats:
26
27 - QImage::Format_Indexed8\n
28 - QImage::Format_ARGB32\n
29
30 \sa QwtPlotSpectrogram, QwtScaleWidget
31*/
32
33class QWT_EXPORT QwtColorMap
34{
35public:
36 /*!
37 Format for color mapping
38 \sa rgb(), colorIndex(), colorTable()
39 */
40
41 enum Format
42 {
43 //! The map is intended to map into RGB values.
44 RGB,
45
46 /*!
47 The map is intended to map into 8 bit values, that
48 are indices into the color table.
49 */
50 Indexed
51 };
52
53 QwtColorMap( Format = QwtColorMap::RGB );
54 virtual ~QwtColorMap();
55
56 Format format() const;
57
58 /*!
59 Map a value of a given interval into a RGB value.
60
61 \param interval Range for the values
62 \param value Value
63 \return RGB value, corresponding to value
64 */
65 virtual QRgb rgb( const QwtInterval &interval,
66 double value ) const = 0;
67
68 /*!
69 Map a value of a given interval into a color index
70
71 \param interval Range for the values
72 \param value Value
73 \return color index, corresponding to value
74 */
75 virtual unsigned char colorIndex(
76 const QwtInterval &interval, double value ) const = 0;
77
78 QColor color( const QwtInterval &, double value ) const;
79 virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
80
81private:
82 Format d_format;
83};
84
85/*!
86 \brief QwtLinearColorMap builds a color map from color stops.
87
88 A color stop is a color at a specific position. The valid
89 range for the positions is [0.0, 1.0]. When mapping a value
90 into a color it is translated into this interval according to mode().
91*/
92class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
93{
94public:
95 /*!
96 Mode of color map
97 \sa setMode(), mode()
98 */
99 enum Mode
100 {
101 //! Return the color from the next lower color stop
102 FixedColors,
103
104 //! Interpolating the colors of the adjacent stops.
105 ScaledColors
106 };
107
108 QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
109 QwtLinearColorMap( const QColor &from, const QColor &to,
110 QwtColorMap::Format = QwtColorMap::RGB );
111
112 virtual ~QwtLinearColorMap();
113
114 void setMode( Mode );
115 Mode mode() const;
116
117 void setColorInterval( const QColor &color1, const QColor &color2 );
118 void addColorStop( double value, const QColor& );
119 QVector<double> colorStops() const;
120
121 QColor color1() const;
122 QColor color2() const;
123
124 virtual QRgb rgb( const QwtInterval &, double value ) const;
125 virtual unsigned char colorIndex(
126 const QwtInterval &, double value ) const;
127
128 class ColorStops;
129
130private:
131 // Disabled copy constructor and operator=
132 QwtLinearColorMap( const QwtLinearColorMap & );
133 QwtLinearColorMap &operator=( const QwtLinearColorMap & );
134
135 class PrivateData;
136 PrivateData *d_data;
137};
138
139/*!
140 \brief QwtAlphaColorMap varies the alpha value of a color
141*/
142class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
143{
144public:
145 QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
146 virtual ~QwtAlphaColorMap();
147
148 void setColor( const QColor & );
149 QColor color() const;
150
151 virtual QRgb rgb( const QwtInterval &, double value ) const;
152
153private:
154 QwtAlphaColorMap( const QwtAlphaColorMap & );
155 QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
156
157 virtual unsigned char colorIndex(
158 const QwtInterval &, double value ) const;
159
160 class PrivateData;
161 PrivateData *d_data;
162};
163
164
165/*!
166 Map a value into a color
167
168 \param interval Valid interval for values
169 \param value Value
170
171 \return Color corresponding to value
172
173 \warning This method is slow for Indexed color maps. If it is
174 necessary to map many values, its better to get the
175 color table once and find the color using colorIndex().
176*/
177inline QColor QwtColorMap::color(
178 const QwtInterval &interval, double value ) const
179{
180 if ( d_format == RGB )
181 {
182 return QColor::fromRgba( rgb( interval, value ) );
183 }
184 else
185 {
186 const unsigned int index = colorIndex( interval, value );
187 return colorTable( interval )[index]; // slow
188 }
189}
190
191/*!
192 \return Intended format of the color map
193 \sa Format
194*/
195inline QwtColorMap::Format QwtColorMap::format() const
196{
197 return d_format;
198}
199
200#endif
Note: See TracBrowser for help on using the repository browser.