Salome HOME
Methods Qtx::scaleColor() and Qtx::scaleColors() were added.
authorstv <stv@opencascade.com>
Mon, 6 Jun 2005 08:18:38 +0000 (08:18 +0000)
committerstv <stv@opencascade.com>
Mon, 6 Jun 2005 08:18:38 +0000 (08:18 +0000)
src/Qtx/Qtx.cxx
src/Qtx/Qtx.h
src/Qtx/QtxColorScale.cxx
src/Qtx/QtxColorScale.h

index f2d31bd8ccaa8c333816c5c4770cf0f084d25bd1..884d811551f094be7cd20ec3a3105070dfb9c3be 100755 (executable)
@@ -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<QColor>& lst )
+{
+  lst.clear();
+  for ( int i = 0; i < num; i++ )
+    lst.append( scaleColor( i, 0, num - 1 ) );
+}
index c0c810e6c7920d18f286839c25e258f67ad34df3..cb3a2062ed8a3c00c31ec325f25929d6d3fc2124 100755 (executable)
@@ -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<QColor>& );
 };
 
 #endif
index 469b7a9e5a4eb52cdcecfa8ebd0070818c5e284e..528e399cd39e3ebd877a8f26984533c4b1b9e17f 100755 (executable)
@@ -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
 
 /*********************************************************************
index cc49d83a70ae688ce5b9af3c57e8c1be1fd6e258..21f838dbc9cadd5375580bcfd53f69cd706748f6 100755 (executable)
@@ -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;