QWT 7.0.1
Loading...
Searching...
No Matches
qwt_color_map.h
1/******************************************************************************
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 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_COLOR_MAP_H
28#define QWT_COLOR_MAP_H
29
30#include "qwt_global.h"
31#include <qcolor.h>
32
33class QwtInterval;
34
35#if QT_VERSION < 0x060000
36template< typename T >
37class QVector;
38#endif
39
55class QWT_EXPORT QwtColorMap
56{
57public:
63 enum Format
64 {
67
78 Indexed
79 };
80
81 explicit QwtColorMap(Format = QwtColorMap::RGB);
82 virtual ~QwtColorMap();
83
84 void setFormat(Format);
85 Format format() const;
86
94 virtual QRgb rgb(const QwtInterval& interval, double value) const = 0;
95
96 virtual uint colorIndex(int numColors, const QwtInterval& interval, double value) const;
97
98 QColor color(const QwtInterval&, double value) const;
99 virtual QVector< QRgb > colorTable(int numColors) const;
100 virtual QVector< QRgb > colorTable256() const;
101
102private:
103 Q_DISABLE_COPY(QwtColorMap)
104
105 Format m_format;
106};
107
115class QWT_EXPORT QwtLinearColorMap : public QwtColorMap
116{
117public:
122 enum Mode
123 {
126
128 ScaledColors
129 };
130
132
133 QwtLinearColorMap(const QColor& from, const QColor& to, QwtColorMap::Format = QwtColorMap::RGB);
134
135 virtual ~QwtLinearColorMap();
136
137 void setMode(Mode);
138 Mode mode() const;
139
140 void setColorInterval(const QColor& color1, const QColor& color2);
141 void addColorStop(double value, const QColor&);
142 QVector< double > stopPos() const;
143 QVector< QColor > stopColors() const;
144 QColor color1() const;
145 QColor color2() const;
146
147 virtual QRgb rgb(const QwtInterval&, double value) const QWT_OVERRIDE;
148
149 virtual uint colorIndex(int numColors, const QwtInterval&, double value) const QWT_OVERRIDE;
150
151 class ColorStops;
152
153private:
154 class PrivateData;
155 PrivateData* m_data;
156};
157
161class QWT_EXPORT QwtAlphaColorMap : public QwtColorMap
162{
163public:
164 explicit QwtAlphaColorMap(const QColor& = QColor(Qt::gray));
165 virtual ~QwtAlphaColorMap();
166
167 void setAlphaInterval(int alpha1, int alpha2);
168
169 int alpha1() const;
170 int alpha2() const;
171
172 void setColor(const QColor&);
173 QColor color() const;
174
175 virtual QRgb rgb(const QwtInterval&, double value) const QWT_OVERRIDE;
176
177private:
178 class PrivateData;
179 PrivateData* m_data;
180};
181
193class QWT_EXPORT QwtHueColorMap : public QwtColorMap
194{
195public:
197 virtual ~QwtHueColorMap();
198
199 void setHueInterval(int hue1, int hue2); // direction ?
200 void setSaturation(int saturation);
201 void setValue(int value);
202 void setAlpha(int alpha);
203
204 int hue1() const;
205 int hue2() const;
206 int saturation() const;
207 int value() const;
208 int alpha() const;
209
210 virtual QRgb rgb(const QwtInterval&, double value) const QWT_OVERRIDE;
211
212private:
213 class PrivateData;
214 PrivateData* m_data;
215};
216
227{
228public:
231
232 void setHue(int hue);
233 void setSaturationInterval(int sat1, int sat2);
234 void setValueInterval(int value1, int value2);
235 void setAlpha(int alpha);
236
237 int hue() const;
238 int saturation1() const;
239 int saturation2() const;
240 int value1() const;
241 int value2() const;
242 int alpha() const;
243
244 virtual QRgb rgb(const QwtInterval&, double value) const QWT_OVERRIDE;
245
246private:
247 class PrivateData;
248 PrivateData* m_data;
249};
250
259inline QColor QwtColorMap::color(const QwtInterval& interval, double value) const
260{
261 return QColor::fromRgba(rgb(interval, value));
262}
263
269{
270 return m_format;
271}
272
273#endif
Definition qwt_clipper.h:40
QwtAlphaColorMap varies the alpha value of a color.
Definition qwt_color_map.h:162
QwtColorMap is used to map values into colors.
Definition qwt_color_map.h:56
Format format() const
Definition qwt_color_map.h:268
QColor color(const QwtInterval &, double value) const
Map a value into a color.
Definition qwt_color_map.h:259
Format
Format for color mapping.
Definition qwt_color_map.h:64
@ RGB
The map is intended to map into RGB values.
Definition qwt_color_map.h:66
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
Map a value of a given interval into a RGB value.
QwtHueColorMap varies the hue value of the HSV color model.
Definition qwt_color_map.h:194
A class representing an interval.
Definition qwt_interval.h:40
QwtLinearColorMap builds a color map from color stops.
Definition qwt_color_map.h:116
Mode
Mode of color map.
Definition qwt_color_map.h:123
@ FixedColors
Return the color from the next lower color stop.
Definition qwt_color_map.h:125
QwtSaturationValueColorMap varies the saturation and/or value for a given hue in the HSV color model.
Definition qwt_color_map.h:227