Qwt User's Guide  6.0.2
qwt_color_map.h
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 
33 class QWT_EXPORT QwtColorMap
34 {
35 public:
41  enum Format
42  {
44  RGB,
45 
50  Indexed
51  };
52 
53  QwtColorMap( Format = QwtColorMap::RGB );
54  virtual ~QwtColorMap();
55 
56  Format format() const;
57 
64  virtual QRgb rgb( const QwtInterval &interval,
65  double value ) const = 0;
66 
73  virtual unsigned char colorIndex(
74  const QwtInterval &interval, double value ) const = 0;
75 
76  QColor color( const QwtInterval &, double value ) const;
77  virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
78 
79 private:
80  Format d_format;
81 };
82 
90 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
91 {
92 public:
97  enum Mode
98  {
101 
103  ScaledColors
104  };
105 
107  QwtLinearColorMap( const QColor &from, const QColor &to,
109 
110  virtual ~QwtLinearColorMap();
111 
112  void setMode( Mode );
113  Mode mode() const;
114 
115  void setColorInterval( const QColor &color1, const QColor &color2 );
116  void addColorStop( double value, const QColor& );
117  QVector<double> colorStops() const;
118 
119  QColor color1() const;
120  QColor color2() const;
121 
122  virtual QRgb rgb( const QwtInterval &, double value ) const;
123  virtual unsigned char colorIndex(
124  const QwtInterval &, double value ) const;
125 
126  class ColorStops;
127 
128 private:
129  // Disabled copy constructor and operator=
131  QwtLinearColorMap &operator=( const QwtLinearColorMap & );
132 
133  class PrivateData;
134  PrivateData *d_data;
135 };
136 
140 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
141 {
142 public:
143  QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
144  virtual ~QwtAlphaColorMap();
145 
146  void setColor( const QColor & );
147  QColor color() const;
148 
149  virtual QRgb rgb( const QwtInterval &, double value ) const;
150 
151 private:
153  QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
154 
155  virtual unsigned char colorIndex(
156  const QwtInterval &, double value ) const;
157 
158  class PrivateData;
159  PrivateData *d_data;
160 };
161 
162 
175 inline QColor QwtColorMap::color(
176  const QwtInterval &interval, double value ) const
177 {
178  if ( d_format == RGB )
179  {
180  return QColor( rgb( interval, value ) );
181  }
182  else
183  {
184  const unsigned int index = colorIndex( interval, value );
185  return colorTable( interval )[index]; // slow
186  }
187 }
188 
194 {
195  return d_format;
196 }
197 
198 #endif