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 &from, const QColor &to,
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 );
return colorTable( interval )[index]; // slow
}
}
inline QwtColorMap::Format QwtColorMap::format() const
{
return d_format;
}
#endif
QwtLinearColorMap
QwtLinearColorMap builds a color map from color stops.
Definition: qwt_color_map.h:92
QwtColorMap::RGB
The map is intended to map into RGB values.
Definition: qwt_color_map.h:44
QwtLinearColorMap::Mode
Mode
Definition: qwt_color_map.h:99
QwtColorMap::Format
Format
Definition: qwt_color_map.h:41
QwtLinearColorMap::FixedColors
Return the color from the next lower color stop.
Definition: qwt_color_map.h:102
QwtColorMap::colorTable
virtual QVector< QRgb > colorTable(const QwtInterval &) const
Definition: qwt_color_map.cpp:219
QwtColorMap::colorIndex
virtual unsigned char colorIndex(const QwtInterval &interval, double value) const =0
QwtColorMap
QwtColorMap is used to map values into colors.
Definition: qwt_color_map.h:33
QwtColorMap::color
QColor color(const QwtInterval &, double value) const
Definition: qwt_color_map.h:177
QwtColorMap::format
Format format() const
Definition: qwt_color_map.h:195
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:26
QwtColorMap::rgb
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
QwtAlphaColorMap
QwtAlphaColorMap varies the alpha value of a color.
Definition: qwt_color_map.h:142