From 853edb23512e9e7c180134be3ddb29c37601a8b3 Mon Sep 17 00:00:00 2001 From: stv Date: Mon, 6 Jun 2005 08:18:38 +0000 Subject: [PATCH] Methods Qtx::scaleColor() and Qtx::scaleColors() were added. --- src/Qtx/Qtx.cxx | 39 +++++++++++++++++++++++++++++++++++++++ src/Qtx/Qtx.h | 3 +++ src/Qtx/QtxColorScale.cxx | 27 +-------------------------- src/Qtx/QtxColorScale.h | 1 - 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index f2d31bd8c..884d81155 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -499,3 +499,42 @@ void Qtx::rgbSet( const int rgb, int& r, int& g, int& b ) g = ( rgb >> 8 ) & 0xff; b = rgb & 0xff; } + +/*! + Name: scaleColor [static public] + Desc: Returns the color specified by the index between min (blue) and max (red). +*/ +QColor Qtx::scaleColor( const int index, const int min, const int max ) +{ + static const int HUE[10] = {230, 210, 195, 180, 160, 80, 60, 50, 30, 0}; + + int hue = HUE[0]; + + if ( min != max ) + { + double aPosition = 9.0 * ( index - min ) / ( max - min ); + if ( aPosition > 0.0 ) + { + if ( aPosition >= 9.0 ) + hue = HUE[9]; + else + { + int idx = (int)aPosition; + hue = HUE[idx] + int( ( aPosition - idx ) * ( HUE[idx + 1] - HUE[idx] ) ); + } + } + } + + return QColor( hue, 255, 255, QColor::Hsv ); +} + +/*! + Name: scaleColors [static public] + Desc: Returns the 'num' number of colors from blue to red. +*/ +void Qtx::scaleColors( const int num, QValueList& lst ) +{ + lst.clear(); + for ( int i = 0; i < num; i++ ) + lst.append( scaleColor( i, 0, num - 1 ) ); +} diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index c0c810e6c..cb3a2062e 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -106,6 +106,9 @@ public: static void rgbSet( const int, QColor& ); static void rgbSet( const int, int&, int&, int& ); + + static QColor scaleColor( const int, const int, const int ); + static void scaleColors( const int, QValueList& ); }; #endif diff --git a/src/Qtx/QtxColorScale.cxx b/src/Qtx/QtxColorScale.cxx index 469b7a9e5..528e399cd 100755 --- a/src/Qtx/QtxColorScale.cxx +++ b/src/Qtx/QtxColorScale.cxx @@ -1055,7 +1055,7 @@ QColor QtxColorScale::getColor( const int idx ) const if ( colorMode() == User ) res = color( idx ); else - res = QColor( hueFromValue( idx, 0, intervalsNumber() - 1 ), 255, 255, QColor::Hsv ); + res = Qtx::scaleColor( idx, 0, intervalsNumber() - 1 ); return res; } @@ -1121,31 +1121,6 @@ QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const return srt; } -//================================================================ -// Function : hueFromValue -// Purpose : -//================================================================ - -int QtxColorScale::hueFromValue( const int value, const int min, const int max ) const -{ - static const int HUE[10] = {230, 210, 195, 180, 160, 80, 60, 50, 30, 0}; - - if ( min == max ) - return HUE[0]; - - double aPosition = 9.0 * ( value - min ) / ( max - min ); - - if ( aPosition <= 0. ) - return HUE[0]; - - if ( aPosition >= 9. ) - return HUE[9]; - - int idx = (int)aPosition; - - return HUE[idx] + int( ( aPosition - idx ) * ( HUE[idx + 1] - HUE[idx] ) ); -} - #if QT_VER == 3 /********************************************************************* diff --git a/src/Qtx/QtxColorScale.h b/src/Qtx/QtxColorScale.h index cc49d83a7..21f838dbc 100755 --- a/src/Qtx/QtxColorScale.h +++ b/src/Qtx/QtxColorScale.h @@ -133,7 +133,6 @@ private: const bool, const bool, const bool ) const; QSize calculateSize( const bool, const int, const bool, const bool, const bool ) const; - int hueFromValue( const int, const int, const int ) const; friend class Dock; -- 2.39.2