qwt_color_map.h
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_COLOR_MAP_H
#define QWT_COLOR_MAP_H
#include "qwt_global.h"
#include "qwt_interval.h"
#include <qcolor.h>
#include <qvector.h>
class QWT_EXPORT QwtColorMap
{
public:
enum Format
{
RGB,
Indexed
};
QwtColorMap( Format = QwtColorMap::RGB );
virtual ~QwtColorMap();
Format format() const;
virtual QRgb rgb( const QwtInterval &interval,
double value ) const = 0;
virtual unsigned char colorIndex(
const QwtInterval &interval, double value ) const = 0;
QColor color( const QwtInterval &, double value ) const;
virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
private:
Format d_format;
};
class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
{
public:
enum Mode
{
FixedColors,
ScaledColors
};
QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
QwtLinearColorMap( const QColor &color1, const QColor &color2,
QwtColorMap::Format = QwtColorMap::RGB );
virtual ~QwtLinearColorMap();
void setMode( Mode );
Mode mode() const;
void setColorInterval( const QColor &color1, const QColor &color2 );
void addColorStop( double value, const QColor& );
QVector<double> colorStops() const;
QColor color1() const;
QColor color2() const;
virtual QRgb rgb( const QwtInterval &, double value ) const;
virtual unsigned char colorIndex(
const QwtInterval &, double value ) const;
class ColorStops;
private:
// Disabled copy constructor and operator=
QwtLinearColorMap( const QwtLinearColorMap & );
QwtLinearColorMap &operator=( const QwtLinearColorMap & );
class PrivateData;
PrivateData *d_data;
};
class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
{
public:
QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
virtual ~QwtAlphaColorMap();
void setColor( const QColor & );
QColor color() const;
virtual QRgb rgb( const QwtInterval &, double value ) const;
private:
QwtAlphaColorMap( const QwtAlphaColorMap & );
QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
virtual unsigned char colorIndex(
const QwtInterval &, double value ) const;
class PrivateData;
PrivateData *d_data;
};
inline QColor QwtColorMap::color(
const QwtInterval &interval, double value ) const
{
if ( d_format == RGB )
{
return QColor::fromRgba( rgb( interval, value ) );
}
else
{
const unsigned int index = colorIndex( interval, value );
const QVector<QRgb> rgbTable = colorTable( interval );
return rgbTable[index]; // slow
}
}
inline QwtColorMap::Format QwtColorMap::format() const
{
return d_format;
}
#endif
QwtColorMap::RGB
@ RGB
The map is intended to map into RGB values.
Definition: qwt_color_map.h:44
QwtColorMap
QwtColorMap is used to map values into colors.
Definition: qwt_color_map.h:34
QwtLinearColorMap
QwtLinearColorMap builds a color map from color stops.
Definition: qwt_color_map.h:93
QwtLinearColorMap::FixedColors
@ FixedColors
Return the color from the next lower color stop.
Definition: qwt_color_map.h:102
QwtColorMap::color
QColor color(const QwtInterval &, double value) const
Definition: qwt_color_map.h:177
QwtLinearColorMap::Mode
Mode
Definition: qwt_color_map.h:100
QwtColorMap::colorTable
virtual QVector< QRgb > colorTable(const QwtInterval &) const
Definition: qwt_color_map.cpp:219
QwtColorMap::rgb
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
QwtColorMap::format
Format format() const
Definition: qwt_color_map.h:197
QwtColorMap::Format
Format
Definition: qwt_color_map.h:42
QwtColorMap::colorIndex
virtual unsigned char colorIndex(const QwtInterval &interval, double value) const =0
QwtAlphaColorMap
QwtAlphaColorMap varies the alpha value of a color.
Definition: qwt_color_map.h:143
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:27